blob: f103c2ad5a011618dd288b9713f0d3d1a7d9e9f3 [file] [log] [blame]
Robert Rostohar85056ab2021-01-25 17:01:11 +01001#!/bin/bash
2# Copyright (c) 2020, Arm Limited. All rights reserved.
3# SPDX-License-Identifier: BSD-3-Clause
4# Setup TF-M for building CMSIS-Packs
5
Robert Rostoharc25fc5f2021-02-18 14:59:06 +01006# Check Python installation
7PYTHON=$(which python3 2> /dev/null)
8if [ -z "${PYTHON}" ]; then
9 echo "No python3 executable found!"
10 echo "Fall-back to python ..."
11 PYTHON=$(which python 2> /dev/null)
12 if [ -z "${PYTHON}" ]; then
13 echo "No python executable found!"
14 exit
15 fi
16fi
17
Robert Rostohar85056ab2021-01-25 17:01:11 +010018# Install required Python packages
Robert Rostoharc25fc5f2021-02-18 14:59:06 +010019${PYTHON} -m pip install -r requirements.txt
Robert Rostohar85056ab2021-01-25 17:01:11 +010020
21# TF-M repositories
22TFM_URL=https://git.trustedfirmware.org/TF-M/trusted-firmware-m.git
23TFM_TESTS_URL=https://git.trustedfirmware.org/TF-M/tf-m-tests.git
24
25# TF-M tag
26TFM_TAG=TF-Mv1.2.0
27
28# External repositories
29MCUBOOT_URL=https://github.com/mcu-tools/mcuboot.git
30MCUBOOT_TAG=v1.7.0
31
32# Clone TF-M repository
33git clone $TFM_URL --branch $TFM_TAG --single-branch
34errorlevel=$?
Robert Rostoharc25fc5f2021-02-18 14:59:06 +010035if [ $errorlevel -gt 0 ]; then
Robert Rostohar85056ab2021-01-25 17:01:11 +010036 echo "Error: Cloning TF-M repository failed"
37 echo " "
38 exit
39fi
40
41# Clone TF-M tests repository
42git clone $TFM_TESTS_URL --branch $TFM_TAG --single-branch
43errorlevel=$?
Robert Rostoharc25fc5f2021-02-18 14:59:06 +010044if [ $errorlevel -gt 0 ]; then
Robert Rostohar85056ab2021-01-25 17:01:11 +010045 echo "Error: Cloning TF-M tests repository failed"
46 echo " "
47 exit
48fi
49
50# Clone MCUboot repository
51git clone $MCUBOOT_URL --branch $MCUBOOT_TAG --single-branch
52errorlevel=$?
Robert Rostoharc25fc5f2021-02-18 14:59:06 +010053if [ $errorlevel -gt 0 ]; then
Robert Rostohar85056ab2021-01-25 17:01:11 +010054 echo "Error: Cloning MCUboot repository failed"
55 echo " "
56 exit
57fi
58
59# Copy files from MCUboot to TF-M
60mkdir -p ./trusted-firmware-m/lib/ext/mcuboot/boot
61cp -vr ./mcuboot/boot/bootutil ./trusted-firmware-m/lib/ext/mcuboot/boot/
62
63# Create MCUboot config file (from template)
64pushd ./trusted-firmware-m/bl2/ext/mcuboot/include/mcuboot_config
65cp -v mcuboot_config.h.in mcuboot_config.h
66# Remove defines which are already defined in bl2_config.h
Robert Rostoharc25fc5f2021-02-18 14:59:06 +010067sed -b -i 's/#cmakedefine/\/\/#define/' mcuboot_config.h
68sed -b -i 's/#define MCUBOOT_LOG_LEVEL/\/\/#define MCUBOOT_LOG_LEVEL/' mcuboot_config.h
Robert Rostohar85056ab2021-01-25 17:01:11 +010069popd
70
71# Create TF-M Mbed Crypto config file (from default config)
72pushd ./trusted-firmware-m/lib/ext/mbedcrypto/mbedcrypto_config
73cp -v tfm_mbedcrypto_config_default.h tfm_mbedcrypto_config.h
74popd
75
76# Apply patches to TF-M
77cd trusted-firmware-m
78for f in ../trusted-firmware-m_patch/*.patch
79 do
80 git apply -v $f
81done
82cd ..
83
84# Apply patches to TF-M tests
85cd tf-m-tests
86for f in ../tf-m-tests_patch/*.patch
87 do
88 git apply -v $f
89done
90cd ..
91
92# Generate files from templates
93export TFM_TEST_PATH="${PWD}/tf-m-tests/test"
Robert Rostoharc25fc5f2021-02-18 14:59:06 +010094${PYTHON} ./trusted-firmware-m/tools/tfm_parse_manifest_list.py \
Robert Rostohar85056ab2021-01-25 17:01:11 +010095 -o ./trusted-firmware-m \
96 -m ./trusted-firmware-m/tools/tfm_manifest_list.yaml \
97 -f ./trusted-firmware-m/tools/tfm_generated_file_list.yaml \
98 ./trusted-firmware-m/platform/ext/target/mps2/an521/generated_file_list.yaml
99
100# Copy generated files for TF-M tests
101cp -vr ./trusted-firmware-m/test/test_services ./tf-m-tests/test
102
103# Update linker scripts (TFM_IRQ_TEST_1_LINKER: tfm_enable_irq/tfm_disable_irq)
104pushd ./trusted-firmware-m/platform/ext/common/armclang
105for f in tfm_common_s.sct tfm_isolation_l3.sct
106do
Robert Rostoharc25fc5f2021-02-18 14:59:06 +0100107 sed -b -i '/TFM_IRQ_TEST_1_ATTR_FN/i*(:gdef:tfm_enable_irq)\r' $f
108 sed -b -i '/TFM_IRQ_TEST_1_ATTR_FN/i*(:gdef:tfm_disable_irq)\r' $f
Robert Rostohar85056ab2021-01-25 17:01:11 +0100109done
110popd
111
112# Move files from TF-M tests to TF-M
113mv -v ./tf-m-tests/app/os_wrapper_cmsis_rtos_v2.c ./trusted-firmware-m/interface/src/
114
115# Copy files from TF-M tests to TF-M (for building doxygen based documentation)
116cp -vr ./tf-m-tests/test ./trusted-firmware-m
117
118# Move/copy files from TF-M to TF-M tests
119mkdir -p ./tf-m-tests/interface/include
120mkdir -p ./tf-m-tests/interface/src
121mkdir -p ./tf-m-tests/platform/ext/common
122mkdir -p ./tf-m-tests/platform/include
123mv -v ./trusted-firmware-m/interface/include/tfm_ns_svc.h ./tf-m-tests/interface/include/
124mv -v ./trusted-firmware-m/interface/include/tfm_nspm_svc_handler.h ./tf-m-tests/interface/include/
125mv -v ./trusted-firmware-m/interface/src/tfm_nspm_api.c ./tf-m-tests/interface/src/
126mv -v ./trusted-firmware-m/interface/src/tfm_nspm_svc_handler.c ./tf-m-tests/interface/src/
127cp -v ./trusted-firmware-m/secure_fw/spm/include/tfm_boot_status.h ./tf-m-tests/interface/include/
128cp -v ./trusted-firmware-m/platform/ext/common/uart_stdout.c ./tf-m-tests/platform/ext/common/
129cp -v ./trusted-firmware-m/platform/ext/common/uart_stdout.h ./tf-m-tests/platform/ext/common/
130cp -v ./trusted-firmware-m/platform/include/region.h ./tf-m-tests/platform/include/
131cp -v ./trusted-firmware-m/platform/include/tfm_plat_crypto_keys.h ./tf-m-tests/platform/include/
132cp -v ./trusted-firmware-m/platform/include/tfm_plat_defs.h ./tf-m-tests/platform/include/
133cp -v ./trusted-firmware-m/platform/include/tfm_plat_ns.h ./tf-m-tests/platform/include/
134cp -v ./trusted-firmware-m/platform/include/tfm_plat_test.h ./tf-m-tests/platform/include/
135cp -v ./trusted-firmware-m/secure_fw/partitions/audit_logging/audit_core.h ./tf-m-tests/test/suites/audit/non_secure/
136cp -v ./trusted-firmware-m/secure_fw/partitions/initial_attestation/attest.h ./tf-m-tests/test/suites/attestation/
137cp -v ./trusted-firmware-m/secure_fw/partitions/initial_attestation/attest_eat_defines.h ./tf-m-tests/test/suites/attestation/
138cp -v ./trusted-firmware-m/secure_fw/partitions/initial_attestation/attest_token.h ./tf-m-tests/test/suites/attestation/
139
140# Copy TF-M pack addon files
141cp -vr ./trusted-firmware-m_addon/* ./trusted-firmware-m/
142
143# Copy TF-M test pack addon files
144cp -vr ./tf-m-tests_addon/* ./tf-m-tests/