xref: /optee_os/ta/ta.mk (revision df24e6517b6454cf906c16979ea0e7546c5c99d5)
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_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
53ifeq ($(ta-target),ta_arm32)
54arm32-user-sysreg-txt = lib/libutee/arch/arm/arm32_user_sysreg.txt
55arm32-user-sysregs-$(arm32-user-sysreg-txt)-h := arm32_user_sysreg.h
56arm32-user-sysregs += $(arm32-user-sysreg-txt)
57
58arm32-user-sysregs-out := $(out-dir)/include/generated
59
60define process-arm32-user-sysreg
61FORCE-GENSRC$(sm): $$(arm32-user-sysregs-out)/$$(arm32-user-sysregs-$(1)-h)
62cleanfiles := $$(cleanfiles) \
63		 $$(arm32-user-sysregs-out)/$$(arm32-user-sysregs-$(1)-h)
64
65$$(arm32-user-sysregs-out)/$$(arm32-user-sysregs-$(1)-h): \
66		$(1) scripts/arm32_sysreg.py
67	@$(cmd-echo-silent) '  GEN     $$@'
68	$(q)mkdir -p $$(dir $$@)
69	$(q)scripts/arm32_sysreg.py --guard __$$(arm32-user-sysregs-$(1)-h) \
70		< $$< > $$@
71
72endef #process-arm32-user-sysreg
73
74$(foreach sr, $(arm32-user-sysregs), \
75	 $(eval $(call process-arm32-user-sysreg,$(sr))))
76
77cppflags$(sm)	+= -I$(arm32-user-sysregs-out)
78endif
79
80base-prefix := $(sm)-
81
82libname = utils
83libdir = lib/libutils
84libuuid = 71855bba-6055-4293-a63f-b0963a737360
85include mk/lib.mk
86
87CFG_TA_MBEDTLS_MPI ?= y
88ifeq ($(CFG_TA_MBEDTLS_MPI),y)
89mplib-for-utee = mbedtls
90$(call force,CFG_TA_MBEDTLS,y)
91else
92mplib-for-utee = mpa
93libname = mpa
94libdir = lib/libmpa
95libuuid = 39b498d9-1e1f-4ae0-a9e1-6d1caf8ec731
96libl = utils
97include mk/lib.mk
98endif
99
100ifeq ($(CFG_TA_MBEDTLS),y)
101libname = mbedtls
102libdir = lib/libmbedtls
103libuuid = 87bb6ae8-4b1d-49fe-9986-2b966132c309
104libl = utils
105include mk/lib.mk
106ta-mk-file-export-vars-$(sm) += CFG_TA_MBEDTLS
107endif
108
109libname = utee
110libdir = lib/libutee
111libuuid = 527f1a47-b92c-4a74-95bd-72f19f4a6f74
112libl = $(mplib-for-utee) utils
113include mk/lib.mk
114
115libname = dl
116libdir = lib/libdl
117libuuid = be807bbd-81e1-4dc4-bd99-3d363f240ece
118libl = utee utils
119include mk/lib.mk
120
121base-prefix :=
122
123incdirs-host := $(filter-out lib/libutils%, $(incdirs$(sm)))
124incfiles-extra-host := lib/libutils/ext/include/compiler.h
125incfiles-extra-host += lib/libutils/ext/include/util.h
126incfiles-extra-host += lib/libutils/ext/include/types_ext.h
127incfiles-extra-host += $(conf-file)
128incfiles-extra-host += $(conf-mk-file)
129incfiles-extra-host += $(conf-cmake-file)
130incfiles-extra-host += core/include/tee/tee_fs_key_manager.h
131incfiles-extra-host += core/include/tee/fs_htree.h
132incfiles-extra-host += core/include/signed_hdr.h
133ifeq ($(ta-target),ta_arm32)
134incfiles-extra-host += $(out-dir)/include/generated/arm32_user_sysreg.h
135endif
136
137#
138# Copy lib files and exported headers from each lib
139#
140
141define copy-file
142$2/$$(notdir $1): $1
143	@set -e; \
144	mkdir -p $$(dir $$@) ; \
145	$(cmd-echo-silent) '  INSTALL $$@' ; \
146	cp -P $$< $$@
147
148cleanfiles += $2/$$(notdir $1)
149ta_dev_kit: $2/$$(notdir $1)
150ta_dev_kit-files += $2/$$(notdir $1)
151ta_dev_kit-files-$3 += $2/$$(notdir $1)
152endef
153
154# Copy the .a files
155$(foreach f, $(libfiles), \
156	$(eval $(call copy-file, $(f), $(out-dir)/export-$(sm)/lib,lib)))
157
158# Copy .mk files
159ta-mkfiles = mk/compile.mk mk/subdir.mk mk/gcc.mk mk/clang.mk mk/cleandirs.mk \
160	ta/arch/$(ARCH)/link.mk ta/arch/$(ARCH)/link_shlib.mk \
161	ta/mk/ta_dev_kit.mk
162
163$(foreach f, $(ta-mkfiles), \
164	$(eval $(call copy-file, $(f), $(out-dir)/export-$(sm)/mk)))
165
166# Copy the .h files for TAs
167define copy-incdir
168sf := $(subst $1/, , $(shell find $1 -name "*.[hS]"))
169$$(foreach h, $$(sf), $$(eval $$(call copy-file, $1/$$(h), \
170	$$(patsubst %/,%,$$(subst /./,/,$2/$$(dir $$(h)))),$3)))
171endef
172$(foreach d, $(incdirs$(sm)), \
173	$(eval $(call copy-incdir,$(d),$(out-dir)/export-$(sm)/include,include)))
174
175# Copy the .h files needed by host
176$(foreach d, $(incdirs-host), \
177	$(eval $(call copy-incdir, $(d), $(out-dir)/export-$(sm)/host_include)))
178$(foreach f, $(incfiles-extra-host), \
179	$(eval $(call copy-file, $(f), $(out-dir)/export-$(sm)/host_include)))
180
181# Copy the src files
182ta-srcfiles = ta/arch/$(ARCH)/user_ta_header.c ta/arch/$(ARCH)/ta.ld.S
183ifeq ($(ta-target),ta_arm32)
184ta-srcfiles += ta/arch/$(ARCH)/ta_entry_a32.S
185endif
186$(foreach f, $(ta-srcfiles), \
187	$(eval $(call copy-file, $(f), $(out-dir)/export-$(sm)/src)))
188
189# Copy keys
190ta-keys = keys/default_ta.pem
191$(foreach f, $(ta-keys), \
192	$(eval $(call copy-file, $(f), $(out-dir)/export-$(sm)/keys)))
193
194# Copy the scripts
195ta-scripts = scripts/sign_encrypt.py scripts/symbolize.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)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