1# Normally this makefile shouldn't be called directly and we expect the output 2# path to be on a certain location to fit together with the other OP-TEE 3# gits and helper scripts. 4 5include ../../scripts/common.mk 6out-dir := $(call strip-trailing-slashes-and-dots,$(O)) 7ifeq ($(out-dir),) 8$(error invalid output directory (O=$(O))) 9endif 10 11include $(TA_DEV_KIT_DIR)/host_include/conf.mk 12 13# By default we expect optee_client exported folder to be on a certain relative 14# path, but if the client specifies the OPTEE_CLIENT_EXPORT then that path will 15# be used instead. 16OPTEE_CLIENT_EXPORT ?= ../../../optee_client/out/export 17 18CC ?= $(CROSS_COMPILE)gcc 19CPP ?= $(CROSS_COMPILE)cpp 20LD ?= $(CROSS_COMPILE)ld 21AR ?= $(CROSS_COMPILE)ar 22NM ?= $(CROSS_COMPILE)nm 23OBJCOPY ?= $(CROSS_COMPILE)objcopy 24OBJDUMP ?= $(CROSS_COMPILE)objdump 25READELF ?= $(CROSS_COMPILE)readelf 26 27# Macros to detect the targeted architecture (e.g., arm-linux-gnueabihf or 28# aarch64-linux-gnu) and the corresponding bit size (32 or 64). 29define cc-arch 30$(shell $(1) -v 2>&1 | grep Target | sed 's/Target: \([^-]*\).*/\1/') 31endef 32define cc-bits 33$(if $(filter arm, $(1)),32,$(if $(filter aarch64, $(1)),64,unknown-arch)) 34endef 35 36CFLAGS += -D__OPTEE_CORE_API_COMPAT_1_1=1 37 38# OpenSSL is used by: 39# - GP tests series 8500 40# - Mbed TLS test 8103 41# - User/group login tests 1027 and 1028 42WITH_OPENSSL ?= y 43ifeq ($(WITH_OPENSSL),y) 44CFLAGS += -DOPENSSL_FOUND=1 45ifneq ($(OPTEE_OPENSSL_EXPORT),) 46LDFLAGS += -lcrypto 47CFLAGS += -I$(OPTEE_OPENSSL_EXPORT) 48else #OPTEE_OPENSSL_EXPORT 49CFLAGS += -I../openssl/include 50ifeq ($(call cc-bits, $(call cc-arch, $(CC))),32) 51LDFLAGS += ../openssl/lib/arm/libcrypto.a -ldl 52else 53LDFLAGS += ../openssl/lib/aarch64/libcrypto.a -ldl 54endif 55endif #OPTEE_OPENSSL_EXPORT 56endif #require OpenSSL 57 58srcs := regression_1000.c 59 60ifeq ($(CFG_GP_SOCKETS),y) 61srcs += regression_2000.c \ 62 sock_server.c \ 63 rand_stream.c 64endif 65 66srcs += adbg/src/adbg_case.c \ 67 adbg/src/adbg_enum.c \ 68 adbg/src/adbg_expect.c \ 69 adbg/src/adbg_log.c \ 70 adbg/src/adbg_run.c \ 71 adbg/src/security_utils_hex.c \ 72 aes_perf.c \ 73 benchmark_1000.c \ 74 benchmark_2000.c \ 75 regression_4000.c \ 76 regression_4100.c \ 77 regression_5000.c \ 78 regression_6000.c \ 79 regression_8000.c \ 80 regression_8100.c \ 81 hash_perf.c \ 82 stats.c \ 83 xtest_helpers.c \ 84 xtest_main.c \ 85 xtest_test.c \ 86 xtest_uuid_helpers.c 87 88ifeq ($(CFG_SECURE_PARTITION)-$(CFG_SPMC_TESTS),y-y) 89srcs += ffa_spmc_1000.c 90endif 91 92ifeq ($(CFG_SECSTOR_TA_MGMT_PTA),y) 93srcs += install_ta.c 94endif 95 96ifeq ($(CFG_SECURE_DATA_PATH),y) 97srcs += sdp_basic.c 98endif 99 100ifeq ($(CFG_PKCS11_TA),y) 101srcs += pkcs11_1000.c 102endif 103 104objs := $(patsubst %.c,$(out-dir)/xtest/%.o, $(srcs)) 105 106ifeq ($(CFG_PKCS11_TA),y) 107CFLAGS += -DCFG_PKCS11_TA 108endif 109 110ifeq ($(CFG_CRYPTO_SE05X),y) 111CFLAGS += -DCFG_CRYPTO_SE05X 112endif 113 114CFLAGS += -I./ 115CFLAGS += -I./adbg/include 116CFLAGS += -I../supp_plugin/include 117CFLAGS += -I$(out-dir)/xtest 118 119CFLAGS += -I$(OPTEE_CLIENT_EXPORT)/include 120CFLAGS += -I$(TA_DEV_KIT_DIR)/host_include 121 122CFLAGS += -I../../ta/include 123CFLAGS += -I../../ta/create_fail_test/include 124CFLAGS += -I../../ta/crypt/include 125CFLAGS += -I../../ta/enc_fs/include 126CFLAGS += -I../../ta/os_test/include 127CFLAGS += -I../../ta/rpc_test/include 128CFLAGS += -I../../ta/sims/include 129CFLAGS += -I../../ta/miss/include 130CFLAGS += -I../../ta/sims_keepalive/include 131CFLAGS += -I../../ta/storage_benchmark/include 132CFLAGS += -I../../ta/concurrent/include 133CFLAGS += -I../../ta/concurrent_large/include 134CFLAGS += -I../../ta/hash_perf/include 135CFLAGS += -I../../ta/aes_perf/include 136CFLAGS += -I../../ta/socket/include 137CFLAGS += -I../../ta/sdp_basic/include 138CFLAGS += -I../../ta/tpm_log_test/include 139CFLAGS += -I../../ta/large/include 140CFLAGS += -I../../ta/supp_plugin/include 141CFLAGS += -I../../ta/bti_test/include 142CFLAGS += -I../../ta/subkey1/include 143CFLAGS += -I../../ta/subkey2/include 144 145TA_DIR ?= /lib/optee_armtz 146CFLAGS += -DTA_DIR=\"$(TA_DIR)\" 147 148# Include configuration file generated by OP-TEE OS (CFG_* macros) 149CFLAGS += -include conf.h 150 151CFLAGS += -Wall -Wcast-align -Werror \ 152 -Werror-implicit-function-declaration -Wextra -Wfloat-equal \ 153 -Wformat-nonliteral -Wformat-security -Wformat=2 -Winit-self \ 154 -Wmissing-declarations -Wmissing-format-attribute \ 155 -Wmissing-include-dirs \ 156 -Wmissing-prototypes -Wnested-externs -Wpointer-arith \ 157 -Wshadow -Wstrict-prototypes -Wswitch-default \ 158 -Wwrite-strings -Wno-unused-parameter \ 159 -Wno-declaration-after-statement \ 160 -Wno-missing-field-initializers -Wno-format-zero-length 161 162CFLAGS += -g3 163 164LDFLAGS += -L$(OPTEE_CLIENT_EXPORT)/lib -lteec 165ifeq ($(CFG_PKCS11_TA),y) 166LDFLAGS += -lckteec 167endif 168LDFLAGS += -lpthread -lm 169 170.PHONY: all 171all: xtest 172 173xtest: $(objs) 174 @echo " LD $(out-dir)/xtest/$@" 175 $(q)$(CC) -o $(out-dir)/xtest/$@ $+ $(LDFLAGS) 176 177$(out-dir)/xtest/%.o: $(CURDIR)/%.c 178 $(q)mkdir -p $(out-dir)/xtest/adbg/src 179 @echo ' CC $<' 180 $(q)$(CC) $(CFLAGS) -c $< -o $@ 181 182RMDIR := rmdir --ignore-fail-on-non-empty 183define rm-build-dirs 184 $(q)for d in $1; do $(RMDIR) $(out-dir)/xtest/$$d 2> /dev/null; true; done 185 $(q)$(RMDIR) $(out-dir)/xtest 2> /dev/null; true 186 $(q)$(RMDIR) $(out-dir) 2> /dev/null; true 187endef 188 189ifeq ($(CFG_GCM_NIST_VECTORS),y) 190GCM_NIST_VECTORS_DECRYPT = gcmDecrypt128 gcmDecrypt192 gcmDecrypt256 191GCM_NIST_VECTORS_ENCRYPT = gcmEncryptExtIV128 gcmEncryptExtIV192 \ 192 gcmEncryptExtIV256 193 194cleanfiles += $(out-dir)/gcmtestvectors.zip 195$(out-dir)/gcmtestvectors.zip: 196 @echo ' DL $@' 197 $(q)curl https://csrc.nist.gov/csrc/media/projects/cryptographic-algorithm-validation-program/documents/mac/gcmtestvectors.zip -o $@ 198 199define create-nist-gcm-vectors 200cleanfiles += $(out-dir)/xtest/$(1).h $(out-dir)/$(1).rsp 201 202$(out-dir)/$(1).rsp: $(out-dir)/gcmtestvectors.zip 203 @echo ' UNZIP $$@' 204 $(q)unzip -o $$< $$(notdir $$@) -d $$(dir $$@) 205 $(q)touch $$@ 206 207 208$(out-dir)/xtest/$(1).h: $(out-dir)/$(1).rsp 209 @echo ' GEN $$@' 210 $(q)$(PYTHON3) ../../scripts/rsp_to_gcm_test.py --inf $$< --outf $$@ --mode=$(2) \ 211 $(if $(filter y,$(CFG_GCM_NIST_VECTORS_LIMITED)),--limited) 212 213$(CURDIR)/regression_4000.c: $(out-dir)/xtest/$(1).h 214endef 215 216$(foreach v, $(GCM_NIST_VECTORS_DECRYPT), $(eval $(call \ 217 create-nist-gcm-vectors,$v,decrypt))) 218$(foreach v, $(GCM_NIST_VECTORS_ENCRYPT), $(eval $(call \ 219 create-nist-gcm-vectors,$v,encrypt))) 220endif 221 222define embed-file 223cleanfiles += $(out-dir)/xtest/$(1).h 224 225$(out-dir)/xtest/$(1).h: $(2) 226 $(q)mkdir -p $(out-dir)/xtest/ 227 @echo ' GEN $$@' 228 $(q)$(PYTHON3) ../../scripts/file_to_c.py --inf $$< --out $$@ --name $(1) 229 230$(CURDIR)/regression_8100.c: $(out-dir)/xtest/$(1).h 231endef 232 233$(eval $(call embed-file,regression_8100_ca_crt,../../cert/ca.crt)) 234$(eval $(call embed-file,regression_8100_mid_crt,../../cert/mid.crt)) 235$(eval $(call embed-file,regression_8100_my_crt,../../cert/my.crt)) 236$(eval $(call embed-file,regression_8100_my_csr,../../cert/my.csr)) 237 238.PHONY: clean 239clean: 240 @echo ' CLEAN $(out-dir)' 241 $(q)rm -f $(out-dir)/xtest/xtest 242 $(q)$(foreach obj,$(objs), rm -f $(obj)) 243 $(q)rm -f $(cleanfiles) 244 $(call rm-build-dirs,adbg/src adbg) 245