xref: /optee_os/ta/ta.mk (revision c2ce4186edb0412c8a0069ff4ee2eb2ec66d09fe)
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_TA_DYNLINK
34ta-mk-file-export-vars-$(sm) += CFG_TEE_TA_LOG_LEVEL
35
36# Expand platform flags here as $(sm) will change if we have several TA
37# targets. Platform flags should not change after inclusion of ta/ta.mk.
38cppflags$(sm)	:= $(platform-cppflags) $($(sm)-platform-cppflags)
39cflags$(sm)	:= $(platform-cflags) $($(sm)-platform-cflags)
40aflags$(sm)	:= $(platform-aflags) $($(sm)-platform-aflags)
41
42# Changes to cppflags$(sm) will only affect how TA dev kit libraries are
43# compiled, these flags are not propagated to the TA
44cppflags$(sm)	+= -include $(conf-file)
45cppflags$(sm) += -DTRACE_LEVEL=$(CFG_TEE_TA_LOG_LEVEL)
46
47base-prefix := $(sm)-
48
49libname = utils
50libdir = lib/libutils
51libuuid = 71855bba-6055-4293-a63f-b0963a737360
52include mk/lib.mk
53
54CFG_TA_MBEDTLS_MPI ?= y
55ifeq ($(CFG_TA_MBEDTLS_MPI),y)
56mplib-for-utee = mbedtls
57$(call force,CFG_TA_MBEDTLS,y)
58else
59mplib-for-utee = mpa
60libname = mpa
61libdir = lib/libmpa
62libuuid = 39b498d9-1e1f-4ae0-a9e1-6d1caf8ec731
63libl = utils
64include mk/lib.mk
65endif
66
67ifeq ($(CFG_TA_MBEDTLS),y)
68libname = mbedtls
69libdir = lib/libmbedtls
70libuuid = 87bb6ae8-4b1d-49fe-9986-2b966132c309
71libl = utils
72include mk/lib.mk
73ta-mk-file-export-vars-$(sm) += CFG_TA_MBEDTLS
74endif
75
76libname = utee
77libdir = lib/libutee
78libuuid = 527f1a47-b92c-4a74-95bd-72f19f4a6f74
79libl = $(mplib-for-utee) utils
80include mk/lib.mk
81
82base-prefix :=
83
84incdirs-host := $(filter-out lib/libutils%, $(incdirs$(sm)))
85incfiles-extra-host := lib/libutils/ext/include/compiler.h
86incfiles-extra-host += lib/libutils/ext/include/util.h
87incfiles-extra-host += lib/libutils/ext/include/types_ext.h
88incfiles-extra-host += $(conf-file)
89incfiles-extra-host += $(conf-mk-file)
90incfiles-extra-host += $(conf-cmake-file)
91incfiles-extra-host += core/include/tee/tee_fs_key_manager.h
92incfiles-extra-host += core/include/tee/fs_htree.h
93incfiles-extra-host += core/include/signed_hdr.h
94
95#
96# Copy lib files and exported headers from each lib
97#
98
99define copy-file
100$2/$$(notdir $1): $1
101	@set -e; \
102	mkdir -p $$(dir $$@) ; \
103	$(cmd-echo-silent) '  INSTALL $$@' ; \
104	cp -P $$< $$@
105
106cleanfiles += $2/$$(notdir $1)
107ta_dev_kit: $2/$$(notdir $1)
108ta_dev_kit-files += $2/$$(notdir $1)
109endef
110
111# Copy the .a files
112$(foreach f, $(libfiles), \
113	$(eval $(call copy-file, $(f), $(out-dir)/export-$(sm)/lib)))
114
115# Copy .mk files
116ta-mkfiles = mk/compile.mk mk/subdir.mk mk/gcc.mk mk/cleandirs.mk \
117	ta/arch/$(ARCH)/link.mk ta/arch/$(ARCH)/link_shlib.mk \
118	ta/mk/ta_dev_kit.mk
119
120$(foreach f, $(ta-mkfiles), \
121	$(eval $(call copy-file, $(f), $(out-dir)/export-$(sm)/mk)))
122
123# Copy the .h files for TAs
124define copy-incdir
125sf := $(subst $1/, , $(shell find $1 -name "*.h"))
126$$(foreach h, $$(sf), $$(eval $$(call copy-file, $1/$$(h), \
127	$$(patsubst %/,%,$$(subst /./,/,$2/$$(dir $$(h)))))))
128endef
129$(foreach d, $(incdirs$(sm)), \
130	$(eval $(call copy-incdir, $(d), $(out-dir)/export-$(sm)/include)))
131
132# Copy the .h files needed by host
133$(foreach d, $(incdirs-host), \
134	$(eval $(call copy-incdir, $(d), $(out-dir)/export-$(sm)/host_include)))
135$(foreach f, $(incfiles-extra-host), \
136	$(eval $(call copy-file, $(f), $(out-dir)/export-$(sm)/host_include)))
137
138# Copy the src files
139ta-srcfiles = ta/arch/$(ARCH)/user_ta_header.c ta/arch/$(ARCH)/ta.ld.S
140$(foreach f, $(ta-srcfiles), \
141	$(eval $(call copy-file, $(f), $(out-dir)/export-$(sm)/src)))
142
143# Copy keys
144ta-keys = keys/default_ta.pem
145$(foreach f, $(ta-keys), \
146	$(eval $(call copy-file, $(f), $(out-dir)/export-$(sm)/keys)))
147
148# Copy the scripts
149ta-scripts = scripts/sign.py scripts/symbolize.py
150$(foreach f, $(ta-scripts), \
151	$(eval $(call copy-file, $(f), $(out-dir)/export-$(sm)/scripts)))
152
153# Create config file
154conf-mk-file-export := $(out-dir)/export-$(sm)/mk/conf.mk
155sm-$(conf-mk-file-export) := $(sm)
156define mk-file-export
157.PHONY: $(conf-mk-file-export)
158$(conf-mk-file-export):
159	@$$(cmd-echo-silent) '  CHK    ' $$@
160	$(q)echo sm := $$(sm-$(conf-mk-file-export)) > $$@.tmp
161	$(q)echo sm-$$(sm-$(conf-mk-file-export)) := y >> $$@.tmp
162	$(q)($$(foreach v, $$(ta-mk-file-export-vars-$$(sm-$(conf-mk-file-export))), \
163		$$(if $$($$(v)),echo $$(v) := $$($$(v));,))) >> $$@.tmp
164	$(q)echo '$$(ta-mk-file-export-add-$$(sm-$(conf-mk-file-export)))' | sed 's/_nl_ */\n/g' >> $$@.tmp
165	$(q)$(call mv-if-changed,$$@.tmp,$$@)
166endef
167$(eval $(mk-file-export))
168
169cleanfiles := $(cleanfiles) $(conf-mk-file-export)
170ta_dev_kit: $(conf-mk-file-export)
171
172all: ta_dev_kit
173