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