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