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