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