blob: 3c33c281407914e1aa326a82d6fa252f4924ad6e [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
6# Install required Python packages
7pip install -r requirements.txt
8
9# TF-M repositories
10TFM_URL=https://git.trustedfirmware.org/TF-M/trusted-firmware-m.git
11TFM_TESTS_URL=https://git.trustedfirmware.org/TF-M/tf-m-tests.git
12
13# TF-M tag
14TFM_TAG=TF-Mv1.2.0
15
16# External repositories
17MCUBOOT_URL=https://github.com/mcu-tools/mcuboot.git
18MCUBOOT_TAG=v1.7.0
19
20# Clone TF-M repository
21git clone $TFM_URL --branch $TFM_TAG --single-branch
22errorlevel=$?
23if [ $errorlevel -gt 0 ]
24 then
25 echo "Error: Cloning TF-M repository failed"
26 echo " "
27 exit
28fi
29
30# Clone TF-M tests repository
31git clone $TFM_TESTS_URL --branch $TFM_TAG --single-branch
32errorlevel=$?
33if [ $errorlevel -gt 0 ]
34 then
35 echo "Error: Cloning TF-M tests repository failed"
36 echo " "
37 exit
38fi
39
40# Clone MCUboot repository
41git clone $MCUBOOT_URL --branch $MCUBOOT_TAG --single-branch
42errorlevel=$?
43if [ $errorlevel -gt 0 ]
44 then
45 echo "Error: Cloning MCUboot repository failed"
46 echo " "
47 exit
48fi
49
50# Copy files from MCUboot to TF-M
51mkdir -p ./trusted-firmware-m/lib/ext/mcuboot/boot
52cp -vr ./mcuboot/boot/bootutil ./trusted-firmware-m/lib/ext/mcuboot/boot/
53
54# Create MCUboot config file (from template)
55pushd ./trusted-firmware-m/bl2/ext/mcuboot/include/mcuboot_config
56cp -v mcuboot_config.h.in mcuboot_config.h
57# Remove defines which are already defined in bl2_config.h
58sed -i 's/#cmakedefine/\/\/#define/' mcuboot_config.h
59sed -i 's/#define MCUBOOT_LOG_LEVEL/\/\/#define MCUBOOT_LOG_LEVEL/' mcuboot_config.h
60unix2dos -q mcuboot_config.h
61popd
62
63# Create TF-M Mbed Crypto config file (from default config)
64pushd ./trusted-firmware-m/lib/ext/mbedcrypto/mbedcrypto_config
65cp -v tfm_mbedcrypto_config_default.h tfm_mbedcrypto_config.h
66popd
67
68# Apply patches to TF-M
69cd trusted-firmware-m
70for f in ../trusted-firmware-m_patch/*.patch
71 do
72 git apply -v $f
73done
74cd ..
75
76# Apply patches to TF-M tests
77cd tf-m-tests
78for f in ../tf-m-tests_patch/*.patch
79 do
80 git apply -v $f
81done
82cd ..
83
84# Generate files from templates
85export TFM_TEST_PATH="${PWD}/tf-m-tests/test"
86python ./trusted-firmware-m/tools/tfm_parse_manifest_list.py \
87 -o ./trusted-firmware-m \
88 -m ./trusted-firmware-m/tools/tfm_manifest_list.yaml \
89 -f ./trusted-firmware-m/tools/tfm_generated_file_list.yaml \
90 ./trusted-firmware-m/platform/ext/target/mps2/an521/generated_file_list.yaml
91
92# Copy generated files for TF-M tests
93cp -vr ./trusted-firmware-m/test/test_services ./tf-m-tests/test
94
95# Update linker scripts (TFM_IRQ_TEST_1_LINKER: tfm_enable_irq/tfm_disable_irq)
96pushd ./trusted-firmware-m/platform/ext/common/armclang
97for f in tfm_common_s.sct tfm_isolation_l3.sct
98do
99 sed -i '/TFM_IRQ_TEST_1_ATTR_FN/i*(:gdef:tfm_enable_irq)' $f
100 sed -i '/TFM_IRQ_TEST_1_ATTR_FN/i*(:gdef:tfm_disable_irq)' $f
101 unix2dos -q $f
102done
103popd
104
105# Move files from TF-M tests to TF-M
106mv -v ./tf-m-tests/app/os_wrapper_cmsis_rtos_v2.c ./trusted-firmware-m/interface/src/
107
108# Copy files from TF-M tests to TF-M (for building doxygen based documentation)
109cp -vr ./tf-m-tests/test ./trusted-firmware-m
110
111# Move/copy files from TF-M to TF-M tests
112mkdir -p ./tf-m-tests/interface/include
113mkdir -p ./tf-m-tests/interface/src
114mkdir -p ./tf-m-tests/platform/ext/common
115mkdir -p ./tf-m-tests/platform/include
116mv -v ./trusted-firmware-m/interface/include/tfm_ns_svc.h ./tf-m-tests/interface/include/
117mv -v ./trusted-firmware-m/interface/include/tfm_nspm_svc_handler.h ./tf-m-tests/interface/include/
118mv -v ./trusted-firmware-m/interface/src/tfm_nspm_api.c ./tf-m-tests/interface/src/
119mv -v ./trusted-firmware-m/interface/src/tfm_nspm_svc_handler.c ./tf-m-tests/interface/src/
120cp -v ./trusted-firmware-m/secure_fw/spm/include/tfm_boot_status.h ./tf-m-tests/interface/include/
121cp -v ./trusted-firmware-m/platform/ext/common/uart_stdout.c ./tf-m-tests/platform/ext/common/
122cp -v ./trusted-firmware-m/platform/ext/common/uart_stdout.h ./tf-m-tests/platform/ext/common/
123cp -v ./trusted-firmware-m/platform/include/region.h ./tf-m-tests/platform/include/
124cp -v ./trusted-firmware-m/platform/include/tfm_plat_crypto_keys.h ./tf-m-tests/platform/include/
125cp -v ./trusted-firmware-m/platform/include/tfm_plat_defs.h ./tf-m-tests/platform/include/
126cp -v ./trusted-firmware-m/platform/include/tfm_plat_ns.h ./tf-m-tests/platform/include/
127cp -v ./trusted-firmware-m/platform/include/tfm_plat_test.h ./tf-m-tests/platform/include/
128cp -v ./trusted-firmware-m/secure_fw/partitions/audit_logging/audit_core.h ./tf-m-tests/test/suites/audit/non_secure/
129cp -v ./trusted-firmware-m/secure_fw/partitions/initial_attestation/attest.h ./tf-m-tests/test/suites/attestation/
130cp -v ./trusted-firmware-m/secure_fw/partitions/initial_attestation/attest_eat_defines.h ./tf-m-tests/test/suites/attestation/
131cp -v ./trusted-firmware-m/secure_fw/partitions/initial_attestation/attest_token.h ./tf-m-tests/test/suites/attestation/
132
133# Copy TF-M pack addon files
134cp -vr ./trusted-firmware-m_addon/* ./trusted-firmware-m/
135
136# Copy TF-M test pack addon files
137cp -vr ./tf-m-tests_addon/* ./tf-m-tests/