xref: /optee_os/ta/ta.mk (revision d1911a85142da16fef5ebdcdac0348d29ce37cd8)
1include mk/cleanvars.mk
2
3# Set current submodule (used for module specific flags compile result etc)
4sm := $(ta-target)
5sm-$(sm) := y
6
7# Setup compiler for this sub module
8COMPILER_$(sm)		?= $(COMPILER)
9include mk/$(COMPILER_$(sm)).mk
10
11#
12# Config flags from mk/config.mk
13#
14
15ifeq ($(CFG_TA_MBEDTLS_SELF_TEST),y)
16$(sm)-platform-cppflags += -DMBEDTLS_SELF_TEST
17endif
18
19ifeq ($(CFG_TEE_TA_MALLOC_DEBUG),y)
20# Build malloc debug code into libutils: (mdbg_malloc(), mdbg_free(),
21# mdbg_check(), etc.).
22$(sm)-platform-cppflags += -DENABLE_MDBG=1
23endif
24
25# Keep CFG_TA_DYNLINK for backwards compatibility
26$(call force,CFG_TA_DYNLINK,y)
27
28# Config variables to be explicitly exported to the dev kit conf.mk
29ta-mk-file-export-vars-$(sm) += CFG_TA_FLOAT_SUPPORT
30ta-mk-file-export-vars-$(sm) += CFG_CACHE_API
31ta-mk-file-export-vars-$(sm) += CFG_SECURE_DATA_PATH
32ta-mk-file-export-vars-$(sm) += CFG_TA_MBEDTLS_SELF_TEST
33ta-mk-file-export-vars-$(sm) += CFG_TA_MBEDTLS
34ta-mk-file-export-vars-$(sm) += CFG_TA_MBEDTLS_MPI
35ta-mk-file-export-vars-$(sm) += CFG_SYSTEM_PTA
36ta-mk-file-export-vars-$(sm) += CFG_TA_DYNLINK
37ta-mk-file-export-vars-$(sm) += CFG_TEE_TA_LOG_LEVEL
38ta-mk-file-export-vars-$(sm) += CFG_TA_FTRACE_SUPPORT
39ta-mk-file-export-vars-$(sm) += CFG_UNWIND
40
41# Expand platform flags here as $(sm) will change if we have several TA
42# targets. Platform flags should not change after inclusion of ta/ta.mk.
43cppflags$(sm)	:= $(platform-cppflags) $($(sm)-platform-cppflags)
44cflags$(sm)	:= $(platform-cflags) $($(sm)-platform-cflags)
45aflags$(sm)	:= $(platform-aflags) $($(sm)-platform-aflags)
46
47# Changes to cppflags$(sm) will only affect how TA dev kit libraries are
48# compiled, these flags are not propagated to the TA
49cppflags$(sm)	+= -include $(conf-file)
50cppflags$(sm) += -DTRACE_LEVEL=$(CFG_TEE_TA_LOG_LEVEL)
51
52base-prefix := $(sm)-
53
54libname = utils
55libdir = lib/libutils
56libuuid = 71855bba-6055-4293-a63f-b0963a737360
57include mk/lib.mk
58
59CFG_TA_MBEDTLS_MPI ?= y
60ifeq ($(CFG_TA_MBEDTLS_MPI),y)
61mplib-for-utee = mbedtls
62$(call force,CFG_TA_MBEDTLS,y)
63else
64mplib-for-utee = mpa
65libname = mpa
66libdir = lib/libmpa
67libuuid = 39b498d9-1e1f-4ae0-a9e1-6d1caf8ec731
68libl = utils
69include mk/lib.mk
70endif
71
72ifeq ($(CFG_TA_MBEDTLS),y)
73libname = mbedtls
74libdir = lib/libmbedtls
75libuuid = 87bb6ae8-4b1d-49fe-9986-2b966132c309
76libl = utils
77include mk/lib.mk
78ta-mk-file-export-vars-$(sm) += CFG_TA_MBEDTLS
79endif
80
81libname = utee
82libdir = lib/libutee
83libuuid = 527f1a47-b92c-4a74-95bd-72f19f4a6f74
84libl = $(mplib-for-utee) utils
85include mk/lib.mk
86
87base-prefix :=
88
89incdirs-host := $(filter-out lib/libutils%, $(incdirs$(sm)))
90incfiles-extra-host := lib/libutils/ext/include/compiler.h
91incfiles-extra-host += lib/libutils/ext/include/util.h
92incfiles-extra-host += lib/libutils/ext/include/types_ext.h
93incfiles-extra-host += $(conf-file)
94incfiles-extra-host += $(conf-mk-file)
95incfiles-extra-host += $(conf-cmake-file)
96incfiles-extra-host += core/include/tee/tee_fs_key_manager.h
97incfiles-extra-host += core/include/tee/fs_htree.h
98incfiles-extra-host += core/include/signed_hdr.h
99
100#
101# Copy lib files and exported headers from each lib
102#
103
104define copy-file
105$2/$$(notdir $1): $1
106	@set -e; \
107	mkdir -p $$(dir $$@) ; \
108	$(cmd-echo-silent) '  INSTALL $$@' ; \
109	cp -P $$< $$@
110
111cleanfiles += $2/$$(notdir $1)
112ta_dev_kit: $2/$$(notdir $1)
113ta_dev_kit-files += $2/$$(notdir $1)
114endef
115
116# Copy the .a files
117$(foreach f, $(libfiles), \
118	$(eval $(call copy-file, $(f), $(out-dir)/export-$(sm)/lib)))
119
120# Copy .mk files
121ta-mkfiles = mk/compile.mk mk/subdir.mk mk/gcc.mk mk/cleandirs.mk \
122	ta/arch/$(ARCH)/link.mk ta/arch/$(ARCH)/link_shlib.mk \
123	ta/mk/ta_dev_kit.mk
124
125$(foreach f, $(ta-mkfiles), \
126	$(eval $(call copy-file, $(f), $(out-dir)/export-$(sm)/mk)))
127
128# Copy the .h files for TAs
129define copy-incdir
130sf := $(subst $1/, , $(shell find $1 -name "*.h"))
131$$(foreach h, $$(sf), $$(eval $$(call copy-file, $1/$$(h), \
132	$$(patsubst %/,%,$$(subst /./,/,$2/$$(dir $$(h)))))))
133endef
134$(foreach d, $(incdirs$(sm)), \
135	$(eval $(call copy-incdir, $(d), $(out-dir)/export-$(sm)/include)))
136
137# Copy the .h files needed by host
138$(foreach d, $(incdirs-host), \
139	$(eval $(call copy-incdir, $(d), $(out-dir)/export-$(sm)/host_include)))
140$(foreach f, $(incfiles-extra-host), \
141	$(eval $(call copy-file, $(f), $(out-dir)/export-$(sm)/host_include)))
142
143# Copy the src files
144ta-srcfiles = ta/arch/$(ARCH)/user_ta_header.c ta/arch/$(ARCH)/ta.ld.S
145$(foreach f, $(ta-srcfiles), \
146	$(eval $(call copy-file, $(f), $(out-dir)/export-$(sm)/src)))
147
148# Copy keys
149ta-keys = keys/default_ta.pem
150$(foreach f, $(ta-keys), \
151	$(eval $(call copy-file, $(f), $(out-dir)/export-$(sm)/keys)))
152
153# Copy the scripts
154ta-scripts = scripts/sign.py scripts/symbolize.py
155$(foreach f, $(ta-scripts), \
156	$(eval $(call copy-file, $(f), $(out-dir)/export-$(sm)/scripts)))
157
158# Create config file
159conf-mk-file-export := $(out-dir)/export-$(sm)/mk/conf.mk
160sm-$(conf-mk-file-export) := $(sm)
161define mk-file-export
162.PHONY: $(conf-mk-file-export)
163$(conf-mk-file-export):
164	@$$(cmd-echo-silent) '  CHK    ' $$@
165	$(q)echo sm := $$(sm-$(conf-mk-file-export)) > $$@.tmp
166	$(q)echo sm-$$(sm-$(conf-mk-file-export)) := y >> $$@.tmp
167	$(q)($$(foreach v, $$(ta-mk-file-export-vars-$$(sm-$(conf-mk-file-export))), \
168		$$(if $$($$(v)),echo $$(v) := $$($$(v));,))) >> $$@.tmp
169	$(q)echo '$$(ta-mk-file-export-add-$$(sm-$(conf-mk-file-export)))' | sed 's/_nl_ */\n/g' >> $$@.tmp
170	$(q)$(call mv-if-changed,$$@.tmp,$$@)
171endef
172$(eval $(mk-file-export))
173
174cleanfiles := $(cleanfiles) $(conf-mk-file-export)
175ta_dev_kit: $(conf-mk-file-export)
176
177all: ta_dev_kit
178