xref: /optee_os/ta/ta.mk (revision d3ec4328a0704e16b30fde84d7458ef8e83eb79d)
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, that is, record allocation
26# location and extra sanity checks.
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 = 4b3d937e-d57e-418b-8673-1c04f2420226
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
128#
129# Copy lib files and exported headers from each lib
130#
131
132define copy-file
133$2/$$(notdir $1): $1
134	@set -e; \
135	mkdir -p $$(dir $$@) ; \
136	$(cmd-echo-silent) '  INSTALL $$@' ; \
137	cp -P $$< $$@
138
139cleanfiles += $2/$$(notdir $1)
140ta_dev_kit: $2/$$(notdir $1)
141ta_dev_kit-files += $2/$$(notdir $1)
142ta_dev_kit-files-$3 += $2/$$(notdir $1)
143endef
144
145# Copy the .a files
146$(foreach f, $(libfiles), \
147	$(eval $(call copy-file, $(f), $(out-dir)/export-$(sm)/lib,lib)))
148
149# Copy .mk files
150ta-mkfiles = mk/compile.mk mk/subdir.mk mk/gcc.mk mk/clang.mk mk/cleandirs.mk \
151	mk/cc-option.mk mk/macros.mk \
152	ta/link.mk ta/link_shlib.mk \
153	ta/mk/ta_dev_kit.mk
154
155$(foreach f, $(ta-mkfiles), \
156	$(eval $(call copy-file, $(f), $(out-dir)/export-$(sm)/mk)))
157
158# Copy the .h files for TAs
159define copy-incdir
160sf := $(subst $1/, , $(shell find $1 -name "*.[hS]"))
161$$(foreach h, $$(sf), $$(eval $$(call copy-file, $1/$$(h), \
162	$$(patsubst %/,%,$$(subst /./,/,$2/$$(dir $$(h)))),$3)))
163endef
164$(foreach d, $(incdirs$(sm)), \
165	$(eval $(call copy-incdir,$(d),$(out-dir)/export-$(sm)/include,include)))
166
167# Copy the .h files needed by host
168$(foreach d, $(incdirs-host), \
169	$(eval $(call copy-incdir, $(d), $(out-dir)/export-$(sm)/host_include)))
170$(foreach f, $(incfiles-extra-host), \
171	$(eval $(call copy-file, $(f), $(out-dir)/export-$(sm)/host_include)))
172
173# Copy the src files
174ta-srcfiles = ta/user_ta_header.c ta/arch/$(ARCH)/ta.ld.S
175ifeq ($(ta-target),ta_arm32)
176ta-srcfiles += ta/arch/$(ARCH)/ta_entry_a32.S
177endif
178$(foreach f, $(ta-srcfiles), \
179	$(eval $(call copy-file, $(f), $(out-dir)/export-$(sm)/src)))
180
181# Copy keys
182ta-keys := $(TA_SIGN_KEY)
183# default_ta.pem is a symlink to default.pem, for backwards compatibility.
184# If default_ta.pem is used, copy both files.
185ifeq ($(TA_SIGN_KEY),keys/default_ta.pem)
186ta-keys += keys/default.pem
187endif
188
189$(foreach f, $(ta-keys), \
190	$(eval $(call copy-file, $(f), $(out-dir)/export-$(sm)/keys)))
191
192# Copy the scripts
193ta-scripts = scripts/sign_encrypt.py scripts/symbolize.py \
194       scripts/sign_rproc_fw.py scripts/ftrace_format.py
195$(foreach f, $(ta-scripts), \
196	$(eval $(call copy-file, $(f), $(out-dir)/export-$(sm)/scripts)))
197
198# Create config file
199conf-mk-file-export := $(out-dir)/export-$(sm)/mk/conf.mk
200sm-$(conf-mk-file-export) := $(sm)
201define mk-file-export
202.PHONY: $(conf-mk-file-export)
203$(conf-mk-file-export):
204	@$$(cmd-echo-silent) '  CHK    ' $$@
205	$(q)mkdir -p $$(dir $$@)
206	$(q)echo sm := $$(sm-$(conf-mk-file-export)) > $$@.tmp
207	$(q)echo sm-$$(sm-$(conf-mk-file-export)) := y >> $$@.tmp
208	$(q)($$(foreach v, $$(ta-mk-file-export-vars-$$(sm-$(conf-mk-file-export))), \
209		$$(if $$($$(v)),echo $$(v) := $$($$(v));,))) >> $$@.tmp
210	$(q)echo '$$(ta-mk-file-export-add-$$(sm-$(conf-mk-file-export)))' | sed 's/_nl_ */\n/g' >> $$@.tmp
211	$(q)$(call mv-if-changed,$$@.tmp,$$@)
212endef
213$(eval $(mk-file-export))
214
215cleanfiles := $(cleanfiles) $(conf-mk-file-export)
216ta_dev_kit: $(conf-mk-file-export)
217
218all: ta_dev_kit
219