blob: f605d76a77bb2c69b13614b165de373d00e1a1a2 [file] [log] [blame]
Jelle Selsb2ccc052022-01-19 15:49:28 +01001# Select which SPMC version to use. Possible values:
2# - github: up-stream version from master branch
3# - tforg: trustedfirmware.org fork (integration or psa-development branch)
4SPMC_VERSION ?= github
5
6# Trusted Services build configs. SP_COMMON_FLAGS is passed to each Trusted
7# Services SP.
8SP_COMMON_FLAGS ?=
9#PSA SP specific build configs:
10ifeq (tforg, $(SPMC_VERSION))
11DTS_CONFIG ?= -DLINUX_SP_DEFINITION
12PSA_CRYPTO_EXTRA_FLAGS ?=
13else
14PSA_CRYPTO_EXTRA_FLAGS ?= -DTS_PLATFORM=ts/mock
15DTS_CONFIG ?=
16endif
17PSA_ITS_EXTRA_FLAGS ?=
18PSA_PROTECTED_STORAGE_EXTRA_FLAGS ?=
19PSA_ATTESTATION_EXTRA_FLAGS ?=
20PSA_SMM_GATEWAY_EXTRA_FLAGS ?=
21
Balint Dobszayd777a3e2020-07-15 15:53:05 +020022DTS ?= optee_ffa
23DTS_PATH ?= $(BUILD_PATH)/fvp
24USE_FVP_BASE_PLAT ?= 1
25
Balint Dobszayd520b002021-03-29 18:54:30 +020026# Use "embedded" or "fip"
27SP_PACKAGING_METHOD ?= embedded
28
Balint Dobszayd777a3e2020-07-15 15:53:05 +020029OPTEE_OS_COMMON_EXTRA_FLAGS += CFG_CORE_SEL1_SPMC=y CFG_CORE_FFA=y
Gyorgy Szingf3a67122021-06-28 17:47:14 +020030OPTEE_OS_COMMON_EXTRA_FLAGS += CFG_CORE_HEAP_SIZE=131072
Balint Dobszayd777a3e2020-07-15 15:53:05 +020031OPTEE_OS_COMMON_EXTRA_FLAGS += O=out/arm
Jelle Selsb2ccc052022-01-19 15:49:28 +010032ifeq (tforg, $(SPMC_VERSION))
33OPTEE_OS_COMMON_EXTRA_FLAGS += CFG_WITH_SP=y
Jelle Selsd58d0272021-06-04 10:36:22 +020034SP_EVENT_LOG ?=y
Jelle Selsb2ccc052022-01-19 15:49:28 +010035else
36SP_EVENT_LOG ?=n
37OPTEE_OS_COMMON_EXTRA_FLAGS += CFG_SECURE_PARTITION=y
38endif
39
Jelle Selsd58d0272021-06-04 10:36:22 +020040ifeq (y,$(SP_EVENT_LOG))
41TF_A_FLAGS ?= \
42 ARM_TSP_RAM_LOCATION=tdram \
43 BL32=$(OPTEE_OS_PAGER_V2_BIN) \
44 BL33=$(EDK2_BIN) \
45 DEBUG=0 \
46 PLAT=fvp \
47 SPMD_SPM_AT_SEL2=0 \
48 MBEDTLS_DIR=$(ROOT)/mbedtls \
49 ARM_ROTPK_LOCATION=devel_rsa \
50 ARM_TSP_RAM_LOCATION=tdram \
51 FVP_USE_GIC_DRIVER=FVP_GICV3 \
52 GENERATE_COT=1 \
53 MEASURED_BOOT=1 \
54 PLAT=fvp \
55 ROT_KEY=plat/arm/board/common/rotpk/arm_rotprivk_rsa.pem \
56 TPM_HASH_ALG=sha256 \
57 TRUSTED_BOARD_BOOT=1 \
58 EVENT_LOG_LEVEL=20 \
59 BL2_optee=y \
60 SPD=spmd
61else
Balint Dobszayd777a3e2020-07-15 15:53:05 +020062TF_A_FLAGS ?= \
63 ARM_TSP_RAM_LOCATION=tdram \
64 BL32=$(OPTEE_OS_PAGER_V2_BIN) \
65 BL33=$(EDK2_BIN) \
66 DEBUG=$(DEBUG) \
67 PLAT=fvp \
68 SPD=spmd \
69 SPMD_SPM_AT_SEL2=0
Jelle Selsd58d0272021-06-04 10:36:22 +020070endif
Balint Dobszayd777a3e2020-07-15 15:53:05 +020071include fvp.mk
Gyorgy Szing0a5029d2020-11-06 00:33:49 +010072
Jelle Selsd58d0272021-06-04 10:36:22 +020073TF_A_FLAGS+=ARM_SPMC_MANIFEST_DTS=$(CURDIR)/fvp/spmc_manifest.dts
Gyorgy Szing0a5029d2020-11-06 00:33:49 +010074TS_INSTALL_PREFIX:=$(CURDIR)/../out-ts
75
76# Add machinery allowing to build secure partitions from Trusted Services.
77#
Jelle Selse6f96332022-01-19 15:45:37 +010078# build-sp <sp-name>,<uuid>,<TS build flags>
Gyorgy Szing0a5029d2020-11-06 00:33:49 +010079# <sp name> The name of the SP.
80#
81# When called build and clean targets for the SP will be defined as:
82#
83# ffa-<sp name>-sp - Build the SP with cmake, and include the SP
84# export makefile to make the SP binary part
85# of the OP-TEE OS image.
86# ffa-<sp name>-sp-clean - run make clean on the cmake project
87# ffa-<sp name>-sp-realclean - remove all cmake output
88#
Balint Dobszayd520b002021-03-29 18:54:30 +020089# To run these for each SP in one step, the "ffa-sp-all", "ffa-sp-all-clean" and
90# "ffa-sp-all-realclean" targets are defined.
91#
Gyorgy Szing0a5029d2020-11-06 00:33:49 +010092# The build and the clean target are added to the dependency tree of common
93# op-tee targets.
94#
Jelle Selse6f96332022-01-19 15:45:37 +010095#example:
96#$(eval $(call build-sp,crypto,d9df52d5-16a2-4bb2-9aa4-d26d3b84e8c0, -DTS_PLATFORM=ts/mock))
97#This wil build the crypto_sp with the mock platorm as it backend.
98#Don't add spaces between the ',' and the uuid and name.
Gyorgy Szing0a5029d2020-11-06 00:33:49 +010099
Balint Dobszayd520b002021-03-29 18:54:30 +0200100.PHONY: ffa-sp-all
101.PHONY: ffa-sp-all-clean
102.PHONY: ffa-sp-all-realclean
103
104optee-os-common: ffa-sp-all
105optee-os-clean: ffa-sp-all-clean
106
107ffa-sp-all-realclean:
108 rm -rf $(TS_INSTALL_PREFIX)/opteesp
109
Jelle Selsb2ccc052022-01-19 15:49:28 +0100110ifeq (tforg-fip, $(SPMC_VERSION)-$(SP_PACKAGING_METHOD))
Balint Dobszayd520b002021-03-29 18:54:30 +0200111# If FIP packaging method is selected, TF-A requires a number of config options:
112# - ARM_BL2_SP_LIST_DTS: This file will be included into the TB_FW_CONFIG DT
113# of TF-A. It contains the UUID and load address of SP
114# packages present in the FIP, BL2 will load them based
115# on this information.
116# - ARM_SPMC_MANIFEST_DTS: Contains information about the SPMC: consumed by the
117# SPMD at SPMC init. And about the SP packages: the
118# SPMC can only know where the packages were loaded by
119# BL2 based on this file.
120# - SP_LAYOUT_FILE: JSON file which describes the corresponding SP image
121# and SP manifest DT pairs, TF-A will create the SP
122# packages based on this. However, the TS build
123# provides a separate JSON file for each SP. A Python
124# snippet is used to merge these JSONs into one file.
Jelle Selse6f96332022-01-19 15:45:37 +0100125define include_sp
126 TS_SP_JSON_LIST+=${TS_INSTALL_PREFIX}/opteesp/json/$1.json
127endef
Balint Dobszayd520b002021-03-29 18:54:30 +0200128SP_LAYOUT_FILE := $(TS_INSTALL_PREFIX)/opteesp/json/sp_layout.json
129
130TF_A_FLAGS+=SP_LAYOUT_FILE=$(SP_LAYOUT_FILE)
131TF_A_FLAGS+=ARM_BL2_SP_LIST_DTS=$(CURDIR)/fvp/bl2_sp_images.dtsi
Balint Dobszayd520b002021-03-29 18:54:30 +0200132OPTEE_OS_COMMON_EXTRA_FLAGS+=CFG_FIP_SP=y
133
134MERGE_JSON_PY := import json, sys
135MERGE_JSON_PY += \ncombined = {}
136MERGE_JSON_PY += \nfor path in sys.stdin.read().split():
137MERGE_JSON_PY += \n with open(path) as f:
138MERGE_JSON_PY += \n current = json.load(f)
139MERGE_JSON_PY += \n combined = {**combined, **current}
140MERGE_JSON_PY += \nprint(json.dumps(combined, indent=4))
141
142$(SP_LAYOUT_FILE): ffa-sp-all
143 @echo $(TS_SP_JSON_LIST) | python3 -c "$$(echo -e '$(MERGE_JSON_PY)')" > $(SP_LAYOUT_FILE)
144
145.PHONY: ffa-sp-layout-clean
146ffa-sp-layout-clean:
147 @rm -f $(SP_LAYOUT_FILE)
148
149arm-tf: $(SP_LAYOUT_FILE)
150ffa-sp-all-clean: ffa-sp-layout-clean
151endif
Balint Dobszay77001092021-02-15 13:52:55 +0100152
Jelle Selsb2ccc052022-01-19 15:49:28 +0100153ifeq (embedded, $(SP_PACKAGING_METHOD))
Balint Dobszay5c7c0582021-04-13 13:02:22 +0200154# If embedded packaging method is selected, the SP manifest files from TS have
155# to be merged into a common DTS file, which is passed to OP-TEE as the embedded
156# DT file. For each SP a dtsi file is exported from TS, which contains a single
157# node, representing that SP.
158# The TS_SP_DTSI_LIST parameter contains a line like this for each SP:
159#
160# #include "<absolute_path_to_dtsi>/<sp_uuid>.dtsi"
161#
Jelle Selse6f96332022-01-19 15:45:37 +0100162define include_sp
Jelle Selsb2ccc052022-01-19 15:49:28 +0100163 ifeq (tforg, $(SPMC_VERSION))
164 OPTEE_OS_COMMON_EXTRA_FLAGS+=EARLY_TA_PATHS+=${TS_INSTALL_PREFIX}/opteesp/bin/$1.stripped.elf
165 TS_SP_DTSI_LIST+="\\n\#include \"${TS_INSTALL_PREFIX}/opteesp/manifest/$1.dtsi\""
166 else
167 OPTEE_OS_COMMON_EXTRA_FLAGS+=SP_PATHS+=${TS_INSTALL_PREFIX}/opteesp/bin/$1.stripped.elf
168 endif
Jelle Selse6f96332022-01-19 15:45:37 +0100169endef
170
Jelle Selsb2ccc052022-01-19 15:49:28 +0100171ifeq (tforg, $(SPMC_VERSION))
Balint Dobszay5c7c0582021-04-13 13:02:22 +0200172SP_MANIFEST_FILE := $(OUT_PATH)/sp_manifest.dts
173OPTEE_OS_COMMON_EXTRA_FLAGS+=CFG_EMBED_DTB_SOURCE_FILE=$(SP_MANIFEST_FILE)
174
175$(SP_MANIFEST_FILE): ffa-sp-all
176 @echo -e "/dts-v1/;\n/ {$(TS_SP_DTSI_LIST)\n};" > $(SP_MANIFEST_FILE)
177
Jelle Selse6f96332022-01-19 15:45:37 +0100178optee-os-common: $(SP_MANIFEST_FILE)
179
Balint Dobszay5c7c0582021-04-13 13:02:22 +0200180.PHONY: ffa-sp-manifest-clean
181ffa-sp-manifest-clean:
182 @rm -f $(SP_MANIFEST_FILE)
Balint Dobszay5c7c0582021-04-13 13:02:22 +0200183ffa-sp-all-clean: ffa-sp-manifest-clean
184endif
Jelle Selsb2ccc052022-01-19 15:49:28 +0100185endif
Balint Dobszay5c7c0582021-04-13 13:02:22 +0200186
Jelle Selse6f96332022-01-19 15:45:37 +0100187define build-sp
188.PHONY: ffa-$1-sp
189ffa-$1-sp:
190 $(eval $(call include_sp,$2))
191 CROSS_COMPILE="$$(AARCH64_CROSS_COMPILE)" cmake -G"Unix Makefiles" -DCMAKE_INSTALL_PREFIX=$${TS_INSTALL_PREFIX} \
Jelle Selsb2ccc052022-01-19 15:49:28 +0100192 -S $$(CURDIR)/../trusted-services/deployments/$1/opteesp -B $$(CURDIR)/../ts-build/$1 \
193 ${SP_COMMON_FLAGS} $3
Jelle Selse6f96332022-01-19 15:45:37 +0100194 cmake --build $$(CURDIR)/../ts-build/$1 -- -j$$(nproc)
195 cmake --install $$(CURDIR)/../ts-build/$1
196
197.PHONY: ffa-$1-sp-clean
198ffa-$1-sp-clean:
199 cmake --build $$(CURDIR)/../ts-build/$1 -- clean -j$$(nproc)
200
201.PHONY: ffa-$1-sp-realclean
202ffa-$1-sp-realclean:
203 rm -rf $$(CURDIR)/../ts-build/$1
204
205ffa-sp-all: ffa-$1-sp
206ffa-sp-all-clean: ffa-$1-sp-clean
207ffa-sp-all-realclean: ffa-$1-sp-realclean
208endef
209
Jelle Selsb2ccc052022-01-19 15:49:28 +0100210$(eval $(call build-sp,internal-trusted-storage,dc1eef48-b17a-4ccf-ac8b-dfcff7711b14, ${PSA_ITS_EXTRA_FLAGS}))
211$(eval $(call build-sp,protected-storage,751bf801-3dde-4768-a514-0f10aeed1790, ${PSA_PROTECTED_STORAGE_EXTRA_FLAGS}))
212$(eval $(call build-sp,crypto,d9df52d5-16a2-4bb2-9aa4-d26d3b84e8c0, ${PSA_CRYPTO_EXTRA_FLAGS}))
213ifeq (tforg, $(SPMC_VERSION))
214$(eval $(call build-sp,attestation,a1baf155-8876-4695-8f7c-54955e8db974, ${PSA_ATTESTATION_EXTRA_FLAGS}))
215$(eval $(call build-sp,smm-gateway,ed32d533-99e6-4209-9cc0-2d72cdd998a7, ${PSA_SMM_GATEWAY_EXTRA_FLAGS}))
216endif
Jelle Selse6f96332022-01-19 15:45:37 +0100217
218.PHONY: sp_uuid_list
219sp_uuid_list: $(SHARED_DIR)/sp_uuid_list.txt
220
221.PHONY: sp_uuid_list_clean
222sp_uuid_list_clean:
223 rm -rf $(SHARED_DIR)/sp_uuid_list.txt
224
225ffa-sp-all-clean: sp_uuid_list_clean
226
227$(SHARED_DIR)/sp_uuid_list.txt: ffa-sp-all
Balint Dobszay1cd203b2021-04-28 13:24:12 +0200228 find $(TS_INSTALL_PREFIX)/opteesp/bin -name "[0-9a-f-]*.elf" -type f | \
229 sed -n "s@.*/\(.*\).stripped.elf@\1@gp" | tr '\n' ',' | \
230 head -c -1 > $(SHARED_DIR)/sp_uuid_list.txt
Gyorgy Szing7d8a64b2020-11-10 15:54:01 +0100231
Jelle Selse6f96332022-01-19 15:45:37 +0100232# Add targets to build the "arm_ffa_user" Linux Kernel module.
233arm_ffa_user: sp_uuid_list linux
234 $(eval ROOT:=$(CURDIR)/..)
235 make -C $(CURDIR)/../linux_poc $(LINUX_COMMON_FLAGS) install
236
Gyorgy Szing7d8a64b2020-11-10 15:54:01 +0100237arm_ffa_user_clean:
238 make -C $(CURDIR)/../linux_poc clean
239
240all: arm_ffa_user