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