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