xref: /optee_os/ta/ta.mk (revision 9403c583381528e7fb391e3769644cc9653cfbb6)
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
8CROSS_COMPILE_$(sm)	?= $(CROSS_COMPILE)
9COMPILER_$(sm)		?= $(COMPILER)
10include mk/$(COMPILER_$(sm)).mk
11
12include ta/arch/$(ARCH)/$(ARCH).mk
13
14# Expand platform flags here as $(sm) will change if we have several TA
15# targets. Platform flags should not change after inclusion of ta/ta.mk.
16cppflags$(sm)	:= $(platform-cppflags) $($(sm)-platform-cppflags)
17cflags$(sm)	:= $(platform-cflags) $($(sm)-platform-cflags)
18aflags$(sm)	:= $(platform-aflags) $($(sm)-platform-aflags)
19
20# Config flags from mk/config.mk
21cppflags$(sm) += -DTRACE_LEVEL=$(CFG_TEE_TA_LOG_LEVEL)
22cppflags$(sm) += -DCFG_TEE_CORE_USER_MEM_DEBUG=$(CFG_TEE_CORE_USER_MEM_DEBUG)
23ifeq ($(CFG_TEE_TA_MALLOC_DEBUG),y)
24cppflags$(sm) += -DENABLE_MDBG=1
25endif
26
27base-prefix := $(sm)-
28
29libname = utils
30libdir = lib/libutils
31include mk/lib.mk
32
33libname = mpa
34libdir = lib/libmpa
35include mk/lib.mk
36
37libname = utee
38libdir = lib/libutee
39include mk/lib.mk
40
41base-prefix :=
42
43incdirs-host := $(filter-out lib/libutils%, $(incdirs$(sm)))
44incfiles-extra-host := lib/libutils/ext/include/compiler.h
45incfiles-extra-host += lib/libutils/ext/include/util.h
46incfiles-extra-host += $(out-dir)/core/include/generated/conf.h
47incfiles-extra-host += $(out-dir)/core/conf.mk
48incfiles-extra-host += core/include/tee/tee_fs_key_manager.h
49incfiles-extra-host += core/include/signed_hdr.h
50
51#
52# Copy lib files and exported headers from each lib
53#
54
55define copy-file
56$2/$$(notdir $1): $1
57	@set -e; \
58	mkdir -p $$(dir $$@) ; \
59	$(cmd-echo-silent) '  INSTALL $$@' ; \
60	cp $$< $$@
61
62cleanfiles += $2/$$(notdir $1)
63all: $2/$$(notdir $1)
64endef
65
66# Copy the .a files
67$(foreach f, $(libfiles), \
68	$(eval $(call copy-file, $(f), $(out-dir)/export-$(sm)/lib)))
69
70# Copy .mk files
71ta-mkfiles = mk/compile.mk mk/subdir.mk mk/gcc.mk \
72	$(wildcard core/arch/$(ARCH)/plat-$(PLATFORM)/platform_flags.mk) \
73	$(wildcard ta/arch/$(ARCH)/link.mk) \
74	ta/mk/ta_dev_kit.mk
75
76$(foreach f, $(ta-mkfiles), \
77	$(eval $(call copy-file, $(f), $(out-dir)/export-$(sm)/mk)))
78
79# Special treatment for ta/arch/$(ARCH)/$(ARCH).mk
80arch-arch-mk := $(out-dir)/export-$(sm)/mk/arch.mk
81$(arch-arch-mk): ta/arch/$(ARCH)/$(ARCH).mk
82	@set -e; \
83	mkdir -p $(dir $@) ; \
84	$(cmd-echo-silent) '  INSTALL $@' ; \
85	cp $< $@
86
87cleanfiles += $(arch-arch-mk)
88all: $(arch-arch-mk)
89
90# Copy the .h files for TAs
91define copy-incdir
92sf := $(subst $1/, , $(shell find $1 -name "*.h"))
93$$(foreach h, $$(sf), $$(eval $$(call copy-file, $1/$$(h), \
94	$$(patsubst %/,%,$$(subst /./,/,$2/$$(dir $$(h)))))))
95endef
96$(foreach d, $(incdirs$(sm)), \
97	$(eval $(call copy-incdir, $(d), $(out-dir)/export-$(sm)/include)))
98
99# Copy the .h files needed by host
100$(foreach d, $(incdirs-host), \
101	$(eval $(call copy-incdir, $(d), $(out-dir)/export-$(sm)/host_include)))
102$(foreach f, $(incfiles-extra-host), \
103	$(eval $(call copy-file, $(f), $(out-dir)/export-$(sm)/host_include)))
104
105# Copy the src files
106ta-srcfiles = ta/arch/$(ARCH)/user_ta_header.c \
107	$(wildcard ta/arch/$(ARCH)/ta.ld.S)
108$(foreach f, $(ta-srcfiles), \
109	$(eval $(call copy-file, $(f), $(out-dir)/export-$(sm)/src)))
110
111# Copy keys
112ta-keys = keys/default_ta.pem
113$(foreach f, $(ta-keys), \
114	$(eval $(call copy-file, $(f), $(out-dir)/export-$(sm)/keys)))
115
116# Copy the scripts
117ta-scripts = $(wildcard scripts/sign.py)
118$(foreach f, $(ta-scripts), \
119	$(eval $(call copy-file, $(f), $(out-dir)/export-$(sm)/scripts)))
120
121# Create config file
122conf-file := $(out-dir)/export-$(sm)/mk/conf.mk
123sm-$(conf-file) := $(sm)
124# The file is only created if it doesn't exist, this is currently OK as the
125# content of the file is static for a given TA dev kit.
126$(conf-file):
127	@$(cmd-echo-silent) '  GEN    ' $@
128	$(q)echo sm := $(sm-$(@)) > $@
129	$(q)echo sm-$(sm-$(@)) := y >> $@
130	$(q)echo CFG_ARM32_$(sm-$(@)) := $(CFG_ARM32_$(sm-$(@))) >> $@
131	$(q)echo CFG_ARM64_$(sm-$(@)) := $(CFG_ARM64_$(sm-$(@))) >> $@
132
133cleanfiles := $(cleanfiles) $(conf-file)
134all: $(conf-file)
135