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