blob: 6a4687a69e40a3e646f4ebee47369ba163106392 [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
Imre Kisb35567d2022-03-02 13:52:34 +01006# Select SP deployment type. Possible values:
7# - opteesp: legacy OP-TEE specific ELF format
8# - sp: generic binary SP, fip packaging method is forced by this option
9SP_DEPLOYMENT_TYPE ?= opteesp
10
Jelle Selsb2ccc052022-01-19 15:49:28 +010011# Trusted Services build configs. SP_COMMON_FLAGS is passed to each Trusted
12# Services SP.
13SP_COMMON_FLAGS ?=
14#PSA SP specific build configs:
Balint Dobszay5cd72692022-04-20 10:08:18 +020015ifeq (github, $(SPMC_VERSION))
Imre Kisb35567d2022-03-02 13:52:34 +010016ifeq (fip, $(SP_PACKAGING_METHOD))
17$(error Invalid packaging method for github version)
18endif
19ifeq (sp, $(SP_DEPLOYMENT_TYPE))
20$(error Unsupported deployment type for github version)
21endif
Jelle Selsb2ccc052022-01-19 15:49:28 +010022endif
23PSA_ITS_EXTRA_FLAGS ?=
24PSA_PROTECTED_STORAGE_EXTRA_FLAGS ?=
Balint Dobszay5cd72692022-04-20 10:08:18 +020025PSA_CRYPTO_EXTRA_FLAGS ?=
Jelle Selsb2ccc052022-01-19 15:49:28 +010026PSA_ATTESTATION_EXTRA_FLAGS ?=
27PSA_SMM_GATEWAY_EXTRA_FLAGS ?=
28
Balint Dobszay4ee874b2022-04-20 10:01:58 +020029DTS_CONFIG ?=
Balint Dobszayd777a3e2020-07-15 15:53:05 +020030DTS ?= optee_ffa
31DTS_PATH ?= $(BUILD_PATH)/fvp
32USE_FVP_BASE_PLAT ?= 1
33
Imre Kisb35567d2022-03-02 13:52:34 +010034ifeq (opteesp, $(SP_DEPLOYMENT_TYPE))
35SP_FILE_EXTENSION=stripped.elf
36else ifeq (sp, $(SP_DEPLOYMENT_TYPE))
37SP_FILE_EXTENSION=bin
38SP_PACKAGING_METHOD=fip
39else
40$(error Invalid SP deployment type $(SP_DEPLOYMENT_TYPE))
41endif
42
Balint Dobszayd520b002021-03-29 18:54:30 +020043# Use "embedded" or "fip"
44SP_PACKAGING_METHOD ?= embedded
45
Balint Dobszayd777a3e2020-07-15 15:53:05 +020046OPTEE_OS_COMMON_EXTRA_FLAGS += CFG_CORE_SEL1_SPMC=y CFG_CORE_FFA=y
Gyorgy Szingf3a67122021-06-28 17:47:14 +020047OPTEE_OS_COMMON_EXTRA_FLAGS += CFG_CORE_HEAP_SIZE=131072
Balint Dobszayd777a3e2020-07-15 15:53:05 +020048OPTEE_OS_COMMON_EXTRA_FLAGS += O=out/arm
Jelle Selsb2ccc052022-01-19 15:49:28 +010049ifeq (tforg, $(SPMC_VERSION))
50OPTEE_OS_COMMON_EXTRA_FLAGS += CFG_WITH_SP=y
Jelle Selsb2ccc052022-01-19 15:49:28 +010051else
Jelle Selsb2ccc052022-01-19 15:49:28 +010052OPTEE_OS_COMMON_EXTRA_FLAGS += CFG_SECURE_PARTITION=y
53endif
54
Balint Dobszay5cd72692022-04-20 10:08:18 +020055SP_EVENT_LOG ?= y
56
Jelle Selsd58d0272021-06-04 10:36:22 +020057ifeq (y,$(SP_EVENT_LOG))
58TF_A_FLAGS ?= \
59 ARM_TSP_RAM_LOCATION=tdram \
60 BL32=$(OPTEE_OS_PAGER_V2_BIN) \
61 BL33=$(EDK2_BIN) \
62 DEBUG=0 \
63 PLAT=fvp \
64 SPMD_SPM_AT_SEL2=0 \
65 MBEDTLS_DIR=$(ROOT)/mbedtls \
66 ARM_ROTPK_LOCATION=devel_rsa \
67 ARM_TSP_RAM_LOCATION=tdram \
68 FVP_USE_GIC_DRIVER=FVP_GICV3 \
69 GENERATE_COT=1 \
70 MEASURED_BOOT=1 \
71 PLAT=fvp \
72 ROT_KEY=plat/arm/board/common/rotpk/arm_rotprivk_rsa.pem \
73 TPM_HASH_ALG=sha256 \
74 TRUSTED_BOARD_BOOT=1 \
75 EVENT_LOG_LEVEL=20 \
76 BL2_optee=y \
77 SPD=spmd
78else
Balint Dobszayd777a3e2020-07-15 15:53:05 +020079TF_A_FLAGS ?= \
80 ARM_TSP_RAM_LOCATION=tdram \
81 BL32=$(OPTEE_OS_PAGER_V2_BIN) \
82 BL33=$(EDK2_BIN) \
83 DEBUG=$(DEBUG) \
84 PLAT=fvp \
85 SPD=spmd \
86 SPMD_SPM_AT_SEL2=0
Jelle Selsd58d0272021-06-04 10:36:22 +020087endif
Balint Dobszayd777a3e2020-07-15 15:53:05 +020088include fvp.mk
Gyorgy Szing0a5029d2020-11-06 00:33:49 +010089
Jelle Selsd58d0272021-06-04 10:36:22 +020090TF_A_FLAGS+=ARM_SPMC_MANIFEST_DTS=$(CURDIR)/fvp/spmc_manifest.dts
Gyorgy Szing0a5029d2020-11-06 00:33:49 +010091TS_INSTALL_PREFIX:=$(CURDIR)/../out-ts
92
93# Add machinery allowing to build secure partitions from Trusted Services.
94#
Jelle Selse6f96332022-01-19 15:45:37 +010095# build-sp <sp-name>,<uuid>,<TS build flags>
Gyorgy Szing0a5029d2020-11-06 00:33:49 +010096# <sp name> The name of the SP.
97#
98# When called build and clean targets for the SP will be defined as:
99#
100# ffa-<sp name>-sp - Build the SP with cmake, and include the SP
101# export makefile to make the SP binary part
102# of the OP-TEE OS image.
103# ffa-<sp name>-sp-clean - run make clean on the cmake project
104# ffa-<sp name>-sp-realclean - remove all cmake output
105#
Balint Dobszayd520b002021-03-29 18:54:30 +0200106# To run these for each SP in one step, the "ffa-sp-all", "ffa-sp-all-clean" and
107# "ffa-sp-all-realclean" targets are defined.
108#
Gyorgy Szing0a5029d2020-11-06 00:33:49 +0100109# The build and the clean target are added to the dependency tree of common
110# op-tee targets.
111#
Jelle Selse6f96332022-01-19 15:45:37 +0100112#example:
113#$(eval $(call build-sp,crypto,d9df52d5-16a2-4bb2-9aa4-d26d3b84e8c0, -DTS_PLATFORM=ts/mock))
114#This wil build the crypto_sp with the mock platorm as it backend.
115#Don't add spaces between the ',' and the uuid and name.
Gyorgy Szing0a5029d2020-11-06 00:33:49 +0100116
Balint Dobszayd520b002021-03-29 18:54:30 +0200117.PHONY: ffa-sp-all
118.PHONY: ffa-sp-all-clean
119.PHONY: ffa-sp-all-realclean
120
121optee-os-common: ffa-sp-all
122optee-os-clean: ffa-sp-all-clean
123
124ffa-sp-all-realclean:
Imre Kisb35567d2022-03-02 13:52:34 +0100125 rm -rf $(TS_INSTALL_PREFIX)/$(SP_DEPLOYMENT_TYPE)
Balint Dobszayd520b002021-03-29 18:54:30 +0200126
Jelle Selsb2ccc052022-01-19 15:49:28 +0100127ifeq (tforg-fip, $(SPMC_VERSION)-$(SP_PACKAGING_METHOD))
Balint Dobszayd520b002021-03-29 18:54:30 +0200128# If FIP packaging method is selected, TF-A requires a number of config options:
129# - ARM_BL2_SP_LIST_DTS: This file will be included into the TB_FW_CONFIG DT
130# of TF-A. It contains the UUID and load address of SP
131# packages present in the FIP, BL2 will load them based
132# on this information.
133# - ARM_SPMC_MANIFEST_DTS: Contains information about the SPMC: consumed by the
134# SPMD at SPMC init. And about the SP packages: the
135# SPMC can only know where the packages were loaded by
136# BL2 based on this file.
137# - SP_LAYOUT_FILE: JSON file which describes the corresponding SP image
138# and SP manifest DT pairs, TF-A will create the SP
139# packages based on this. However, the TS build
140# provides a separate JSON file for each SP. A Python
141# snippet is used to merge these JSONs into one file.
Jelle Selse6f96332022-01-19 15:45:37 +0100142define include_sp
Imre Kisb35567d2022-03-02 13:52:34 +0100143 TS_SP_JSON_LIST+=${TS_INSTALL_PREFIX}/$(SP_DEPLOYMENT_TYPE)/json/$1.json
Jelle Selse6f96332022-01-19 15:45:37 +0100144endef
Imre Kisb35567d2022-03-02 13:52:34 +0100145SP_LAYOUT_FILE := $(TS_INSTALL_PREFIX)/$(SP_DEPLOYMENT_TYPE)/json/sp_layout.json
Balint Dobszayd520b002021-03-29 18:54:30 +0200146
147TF_A_FLAGS+=SP_LAYOUT_FILE=$(SP_LAYOUT_FILE)
148TF_A_FLAGS+=ARM_BL2_SP_LIST_DTS=$(CURDIR)/fvp/bl2_sp_images.dtsi
Balint Dobszayd520b002021-03-29 18:54:30 +0200149OPTEE_OS_COMMON_EXTRA_FLAGS+=CFG_FIP_SP=y
150
151MERGE_JSON_PY := import json, sys
152MERGE_JSON_PY += \ncombined = {}
153MERGE_JSON_PY += \nfor path in sys.stdin.read().split():
154MERGE_JSON_PY += \n with open(path) as f:
155MERGE_JSON_PY += \n current = json.load(f)
156MERGE_JSON_PY += \n combined = {**combined, **current}
157MERGE_JSON_PY += \nprint(json.dumps(combined, indent=4))
158
159$(SP_LAYOUT_FILE): ffa-sp-all
160 @echo $(TS_SP_JSON_LIST) | python3 -c "$$(echo -e '$(MERGE_JSON_PY)')" > $(SP_LAYOUT_FILE)
161
162.PHONY: ffa-sp-layout-clean
163ffa-sp-layout-clean:
164 @rm -f $(SP_LAYOUT_FILE)
165
166arm-tf: $(SP_LAYOUT_FILE)
167ffa-sp-all-clean: ffa-sp-layout-clean
168endif
Balint Dobszay77001092021-02-15 13:52:55 +0100169
Jelle Selsb2ccc052022-01-19 15:49:28 +0100170ifeq (embedded, $(SP_PACKAGING_METHOD))
Jelle Sels4c1375b2022-02-24 14:00:00 +0100171
172# build_fdt converts the SP manifest dts file to have the proper
173# UUID format and builds the fdt into a dtb file which can be used by
174# OP-TEE.
175define build_fdt
176ffa-$1-dts: ffa-$1-sp
177 python3 fvp/fdt_uuid_conversion.py --fdt ${TS_INSTALL_PREFIX}/opteesp/manifest/$2.dts
178 dtc -I dts -O dtb -o ${TS_INSTALL_PREFIX}/opteesp/manifest/$2.dtb ${TS_INSTALL_PREFIX}/opteesp/manifest/$2.dts
179ffa-sp-all: ffa-$1-dts
180endef
181
182
183# If the SPMC version is tforg and embedded packaging method is selected then
184# the SP manifest files from TS have to be merged into a common DTS file, which
185# is passed to OP-TEE as the embedded DT file. For each SP a dtsi file is
186# exported from TS, which contains a single node, representing that SP.
Balint Dobszay5c7c0582021-04-13 13:02:22 +0200187# The TS_SP_DTSI_LIST parameter contains a line like this for each SP:
188#
189# #include "<absolute_path_to_dtsi>/<sp_uuid>.dtsi"
190#
Jelle Selse6f96332022-01-19 15:45:37 +0100191define include_sp
Jelle Selsb2ccc052022-01-19 15:49:28 +0100192 ifeq (tforg, $(SPMC_VERSION))
Imre Kisb35567d2022-03-02 13:52:34 +0100193 OPTEE_OS_COMMON_EXTRA_FLAGS+=EARLY_TA_PATHS+=${TS_INSTALL_PREFIX}/$(SP_DEPLOYMENT_TYPE)/bin/$2.$(SP_FILE_EXTENSION)
194 TS_SP_DTSI_LIST+="\\n\#include \"${TS_INSTALL_PREFIX}/$(SP_DEPLOYMENT_TYPE)/manifest/$2.dtsi\""
Jelle Selsb2ccc052022-01-19 15:49:28 +0100195 else
Imre Kisb35567d2022-03-02 13:52:34 +0100196 OPTEE_OS_COMMON_EXTRA_FLAGS+=SP_PATHS+=${TS_INSTALL_PREFIX}/$(SP_DEPLOYMENT_TYPE)/bin/$2.$(SP_FILE_EXTENSION)
Jelle Sels4c1375b2022-02-24 14:00:00 +0100197 $(eval $(call build_fdt,$1,$2))
Jelle Selsb2ccc052022-01-19 15:49:28 +0100198 endif
Jelle Selse6f96332022-01-19 15:45:37 +0100199endef
200
Jelle Selsb2ccc052022-01-19 15:49:28 +0100201ifeq (tforg, $(SPMC_VERSION))
Balint Dobszay5c7c0582021-04-13 13:02:22 +0200202SP_MANIFEST_FILE := $(OUT_PATH)/sp_manifest.dts
203OPTEE_OS_COMMON_EXTRA_FLAGS+=CFG_EMBED_DTB_SOURCE_FILE=$(SP_MANIFEST_FILE)
204
205$(SP_MANIFEST_FILE): ffa-sp-all
206 @echo -e "/dts-v1/;\n/ {$(TS_SP_DTSI_LIST)\n};" > $(SP_MANIFEST_FILE)
207
Jelle Selse6f96332022-01-19 15:45:37 +0100208optee-os-common: $(SP_MANIFEST_FILE)
209
Balint Dobszay5c7c0582021-04-13 13:02:22 +0200210.PHONY: ffa-sp-manifest-clean
211ffa-sp-manifest-clean:
212 @rm -f $(SP_MANIFEST_FILE)
Balint Dobszay5c7c0582021-04-13 13:02:22 +0200213ffa-sp-all-clean: ffa-sp-manifest-clean
214endif
Jelle Selsb2ccc052022-01-19 15:49:28 +0100215endif
Balint Dobszay5c7c0582021-04-13 13:02:22 +0200216
Jelle Selse6f96332022-01-19 15:45:37 +0100217define build-sp
218.PHONY: ffa-$1-sp
219ffa-$1-sp:
Jelle Selse6f96332022-01-19 15:45:37 +0100220 CROSS_COMPILE="$$(AARCH64_CROSS_COMPILE)" cmake -G"Unix Makefiles" -DCMAKE_INSTALL_PREFIX=$${TS_INSTALL_PREFIX} \
Imre Kisb35567d2022-03-02 13:52:34 +0100221 -S $$(CURDIR)/../trusted-services/deployments/$1/$(SP_DEPLOYMENT_TYPE) -B $$(CURDIR)/../ts-build/$1 \
Jelle Selsb2ccc052022-01-19 15:49:28 +0100222 ${SP_COMMON_FLAGS} $3
Jelle Selse6f96332022-01-19 15:45:37 +0100223 cmake --build $$(CURDIR)/../ts-build/$1 -- -j$$(nproc)
224 cmake --install $$(CURDIR)/../ts-build/$1
Jelle Sels4c1375b2022-02-24 14:00:00 +0100225 $(eval $(call include_sp,$1,$2))
226
Jelle Selse6f96332022-01-19 15:45:37 +0100227
228.PHONY: ffa-$1-sp-clean
229ffa-$1-sp-clean:
230 cmake --build $$(CURDIR)/../ts-build/$1 -- clean -j$$(nproc)
231
232.PHONY: ffa-$1-sp-realclean
233ffa-$1-sp-realclean:
234 rm -rf $$(CURDIR)/../ts-build/$1
235
236ffa-sp-all: ffa-$1-sp
237ffa-sp-all-clean: ffa-$1-sp-clean
238ffa-sp-all-realclean: ffa-$1-sp-realclean
239endef
240
Jelle Selsb2ccc052022-01-19 15:49:28 +0100241$(eval $(call build-sp,internal-trusted-storage,dc1eef48-b17a-4ccf-ac8b-dfcff7711b14, ${PSA_ITS_EXTRA_FLAGS}))
242$(eval $(call build-sp,protected-storage,751bf801-3dde-4768-a514-0f10aeed1790, ${PSA_PROTECTED_STORAGE_EXTRA_FLAGS}))
243$(eval $(call build-sp,crypto,d9df52d5-16a2-4bb2-9aa4-d26d3b84e8c0, ${PSA_CRYPTO_EXTRA_FLAGS}))
Jelle Selsb2ccc052022-01-19 15:49:28 +0100244$(eval $(call build-sp,attestation,a1baf155-8876-4695-8f7c-54955e8db974, ${PSA_ATTESTATION_EXTRA_FLAGS}))
Balint Dobszay5cd72692022-04-20 10:08:18 +0200245ifeq (tforg, $(SPMC_VERSION))
Jelle Selsb2ccc052022-01-19 15:49:28 +0100246$(eval $(call build-sp,smm-gateway,ed32d533-99e6-4209-9cc0-2d72cdd998a7, ${PSA_SMM_GATEWAY_EXTRA_FLAGS}))
247endif
Jelle Selse6f96332022-01-19 15:45:37 +0100248
249.PHONY: sp_uuid_list
250sp_uuid_list: $(SHARED_DIR)/sp_uuid_list.txt
251
252.PHONY: sp_uuid_list_clean
253sp_uuid_list_clean:
254 rm -rf $(SHARED_DIR)/sp_uuid_list.txt
255
256ffa-sp-all-clean: sp_uuid_list_clean
257
Gyorgy Szingd2d555a2022-05-11 11:34:51 +0200258$(SHARED_DIR)/sp_uuid_list.txt: ffa-sp-all | shared_directory
Imre Kisb35567d2022-03-02 13:52:34 +0100259 find $(TS_INSTALL_PREFIX)/$(SP_DEPLOYMENT_TYPE)/bin -name "[0-9a-f-]*.$(SP_FILE_EXTENSION)" -type f | \
260 sed -n "s@.*/\(.*\).$(SP_FILE_EXTENSION)@\1@gp" | tr '\n' ',' | \
Balint Dobszay1cd203b2021-04-28 13:24:12 +0200261 head -c -1 > $(SHARED_DIR)/sp_uuid_list.txt
Gyorgy Szing7d8a64b2020-11-10 15:54:01 +0100262
Jelle Selse6f96332022-01-19 15:45:37 +0100263# Add targets to build the "arm_ffa_user" Linux Kernel module.
Gyorgy Szing17239372022-05-11 11:53:15 +0200264arm_ffa_user: sp_uuid_list linux | $(OUT_PATH)
Jelle Selse6f96332022-01-19 15:45:37 +0100265 $(eval ROOT:=$(CURDIR)/..)
Gyorgy Szing17239372022-05-11 11:53:15 +0200266 mkdir -p $(OUT_PATH)/arm_ffa_user
267 make -C $(CURDIR)/../linux_poc $(LINUX_COMMON_FLAGS) install TARGET_DIR=$(OUT_PATH)/arm_ffa_user
Jelle Selse6f96332022-01-19 15:45:37 +0100268
Gyorgy Szing7d8a64b2020-11-10 15:54:01 +0100269arm_ffa_user_clean:
270 make -C $(CURDIR)/../linux_poc clean
271
Gyorgy Szing17239372022-05-11 11:53:15 +0200272arm_ffa_tee: linux | $(OUT_PATH)
273 $(eval ROOT:=$(CURDIR)/..)
274 mkdir -p $(OUT_PATH)/arm_ffa_tee
275 make -C $(CURDIR)/../linux_tee $(LINUX_COMMON_FLAGS) install TARGET_DIR=$(OUT_PATH)/arm_ffa_tee
276
277arm_ffa_tee_clean:
278 make -C $(CURDIR)/../linux_tee clean
279
280# Copy out-of-tree kernel modules to shared directory and concatenate module load scripts.
281arm_ffa_drivers: arm_ffa_tee arm_ffa_user | shared_directory
282 cat $(OUT_PATH)/arm_ffa_tee/load_module.sh $(OUT_PATH)/arm_ffa_user/load_module.sh > $(SHARED_DIR)/load_module.sh
283 chmod 775 $(SHARED_DIR)/load_module.sh
284 cp -u $(OUT_PATH)/arm_ffa_tee/arm-ffa-tee.ko $(SHARED_DIR)
285 cp -u $(OUT_PATH)/arm_ffa_user/arm-ffa-user.ko $(SHARED_DIR)
286
287all: arm_ffa_drivers
Gyorgy Szingc3408cd2022-05-11 11:42:50 +0200288
289# Disable CONFIG_STRICT_DEVMEM option in the Linux kernel config. This allows userspace access to
290# the whole NS physical address space through /dev/mem.
291linux-defconfig:
292 cd $(LINUX_PATH) && ./scripts/config --disable CONFIG_STRICT_DEVMEM