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