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