Robert Rostohar | 85056ab | 2021-01-25 17:01:11 +0100 | [diff] [blame] | 1 | #!/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 Rostohar | c25fc5f | 2021-02-18 14:59:06 +0100 | [diff] [blame] | 6 | # Check Python installation |
| 7 | PYTHON=$(which python3 2> /dev/null) |
| 8 | if [ -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 |
| 16 | fi |
| 17 | |
Robert Rostohar | 85056ab | 2021-01-25 17:01:11 +0100 | [diff] [blame] | 18 | # Install required Python packages |
Robert Rostohar | c25fc5f | 2021-02-18 14:59:06 +0100 | [diff] [blame] | 19 | ${PYTHON} -m pip install -r requirements.txt |
Robert Rostohar | 85056ab | 2021-01-25 17:01:11 +0100 | [diff] [blame] | 20 | |
| 21 | # TF-M repositories |
| 22 | TFM_URL=https://git.trustedfirmware.org/TF-M/trusted-firmware-m.git |
| 23 | TFM_TESTS_URL=https://git.trustedfirmware.org/TF-M/tf-m-tests.git |
| 24 | |
| 25 | # TF-M tag |
| 26 | TFM_TAG=TF-Mv1.2.0 |
| 27 | |
| 28 | # External repositories |
| 29 | MCUBOOT_URL=https://github.com/mcu-tools/mcuboot.git |
| 30 | MCUBOOT_TAG=v1.7.0 |
| 31 | |
| 32 | # Clone TF-M repository |
| 33 | git clone $TFM_URL --branch $TFM_TAG --single-branch |
| 34 | errorlevel=$? |
Robert Rostohar | c25fc5f | 2021-02-18 14:59:06 +0100 | [diff] [blame] | 35 | if [ $errorlevel -gt 0 ]; then |
Robert Rostohar | 85056ab | 2021-01-25 17:01:11 +0100 | [diff] [blame] | 36 | echo "Error: Cloning TF-M repository failed" |
| 37 | echo " " |
| 38 | exit |
| 39 | fi |
| 40 | |
| 41 | # Clone TF-M tests repository |
| 42 | git clone $TFM_TESTS_URL --branch $TFM_TAG --single-branch |
| 43 | errorlevel=$? |
Robert Rostohar | c25fc5f | 2021-02-18 14:59:06 +0100 | [diff] [blame] | 44 | if [ $errorlevel -gt 0 ]; then |
Robert Rostohar | 85056ab | 2021-01-25 17:01:11 +0100 | [diff] [blame] | 45 | echo "Error: Cloning TF-M tests repository failed" |
| 46 | echo " " |
| 47 | exit |
| 48 | fi |
| 49 | |
| 50 | # Clone MCUboot repository |
| 51 | git clone $MCUBOOT_URL --branch $MCUBOOT_TAG --single-branch |
| 52 | errorlevel=$? |
Robert Rostohar | c25fc5f | 2021-02-18 14:59:06 +0100 | [diff] [blame] | 53 | if [ $errorlevel -gt 0 ]; then |
Robert Rostohar | 85056ab | 2021-01-25 17:01:11 +0100 | [diff] [blame] | 54 | echo "Error: Cloning MCUboot repository failed" |
| 55 | echo " " |
| 56 | exit |
| 57 | fi |
| 58 | |
| 59 | # Copy files from MCUboot to TF-M |
| 60 | mkdir -p ./trusted-firmware-m/lib/ext/mcuboot/boot |
| 61 | cp -vr ./mcuboot/boot/bootutil ./trusted-firmware-m/lib/ext/mcuboot/boot/ |
| 62 | |
| 63 | # Create MCUboot config file (from template) |
| 64 | pushd ./trusted-firmware-m/bl2/ext/mcuboot/include/mcuboot_config |
| 65 | cp -v mcuboot_config.h.in mcuboot_config.h |
| 66 | # Remove defines which are already defined in bl2_config.h |
Robert Rostohar | c25fc5f | 2021-02-18 14:59:06 +0100 | [diff] [blame] | 67 | sed -b -i 's/#cmakedefine/\/\/#define/' mcuboot_config.h |
| 68 | sed -b -i 's/#define MCUBOOT_LOG_LEVEL/\/\/#define MCUBOOT_LOG_LEVEL/' mcuboot_config.h |
Robert Rostohar | 85056ab | 2021-01-25 17:01:11 +0100 | [diff] [blame] | 69 | popd |
| 70 | |
| 71 | # Create TF-M Mbed Crypto config file (from default config) |
| 72 | pushd ./trusted-firmware-m/lib/ext/mbedcrypto/mbedcrypto_config |
| 73 | cp -v tfm_mbedcrypto_config_default.h tfm_mbedcrypto_config.h |
| 74 | popd |
| 75 | |
| 76 | # Apply patches to TF-M |
| 77 | cd trusted-firmware-m |
| 78 | for f in ../trusted-firmware-m_patch/*.patch |
| 79 | do |
| 80 | git apply -v $f |
| 81 | done |
| 82 | cd .. |
| 83 | |
| 84 | # Apply patches to TF-M tests |
| 85 | cd tf-m-tests |
| 86 | for f in ../tf-m-tests_patch/*.patch |
| 87 | do |
| 88 | git apply -v $f |
| 89 | done |
| 90 | cd .. |
| 91 | |
| 92 | # Generate files from templates |
| 93 | export TFM_TEST_PATH="${PWD}/tf-m-tests/test" |
Robert Rostohar | c25fc5f | 2021-02-18 14:59:06 +0100 | [diff] [blame] | 94 | ${PYTHON} ./trusted-firmware-m/tools/tfm_parse_manifest_list.py \ |
Robert Rostohar | 85056ab | 2021-01-25 17:01:11 +0100 | [diff] [blame] | 95 | -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 |
| 101 | cp -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) |
| 104 | pushd ./trusted-firmware-m/platform/ext/common/armclang |
| 105 | for f in tfm_common_s.sct tfm_isolation_l3.sct |
| 106 | do |
Robert Rostohar | c25fc5f | 2021-02-18 14:59:06 +0100 | [diff] [blame] | 107 | 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 Rostohar | 85056ab | 2021-01-25 17:01:11 +0100 | [diff] [blame] | 109 | done |
| 110 | popd |
| 111 | |
| 112 | # Move files from TF-M tests to TF-M |
| 113 | mv -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) |
| 116 | cp -vr ./tf-m-tests/test ./trusted-firmware-m |
| 117 | |
| 118 | # Move/copy files from TF-M to TF-M tests |
| 119 | mkdir -p ./tf-m-tests/interface/include |
| 120 | mkdir -p ./tf-m-tests/interface/src |
| 121 | mkdir -p ./tf-m-tests/platform/ext/common |
| 122 | mkdir -p ./tf-m-tests/platform/include |
| 123 | mv -v ./trusted-firmware-m/interface/include/tfm_ns_svc.h ./tf-m-tests/interface/include/ |
| 124 | mv -v ./trusted-firmware-m/interface/include/tfm_nspm_svc_handler.h ./tf-m-tests/interface/include/ |
| 125 | mv -v ./trusted-firmware-m/interface/src/tfm_nspm_api.c ./tf-m-tests/interface/src/ |
| 126 | mv -v ./trusted-firmware-m/interface/src/tfm_nspm_svc_handler.c ./tf-m-tests/interface/src/ |
| 127 | cp -v ./trusted-firmware-m/secure_fw/spm/include/tfm_boot_status.h ./tf-m-tests/interface/include/ |
| 128 | cp -v ./trusted-firmware-m/platform/ext/common/uart_stdout.c ./tf-m-tests/platform/ext/common/ |
| 129 | cp -v ./trusted-firmware-m/platform/ext/common/uart_stdout.h ./tf-m-tests/platform/ext/common/ |
| 130 | cp -v ./trusted-firmware-m/platform/include/region.h ./tf-m-tests/platform/include/ |
| 131 | cp -v ./trusted-firmware-m/platform/include/tfm_plat_crypto_keys.h ./tf-m-tests/platform/include/ |
| 132 | cp -v ./trusted-firmware-m/platform/include/tfm_plat_defs.h ./tf-m-tests/platform/include/ |
| 133 | cp -v ./trusted-firmware-m/platform/include/tfm_plat_ns.h ./tf-m-tests/platform/include/ |
| 134 | cp -v ./trusted-firmware-m/platform/include/tfm_plat_test.h ./tf-m-tests/platform/include/ |
| 135 | cp -v ./trusted-firmware-m/secure_fw/partitions/audit_logging/audit_core.h ./tf-m-tests/test/suites/audit/non_secure/ |
| 136 | cp -v ./trusted-firmware-m/secure_fw/partitions/initial_attestation/attest.h ./tf-m-tests/test/suites/attestation/ |
| 137 | cp -v ./trusted-firmware-m/secure_fw/partitions/initial_attestation/attest_eat_defines.h ./tf-m-tests/test/suites/attestation/ |
| 138 | cp -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 |
| 141 | cp -vr ./trusted-firmware-m_addon/* ./trusted-firmware-m/ |
| 142 | |
| 143 | # Copy TF-M test pack addon files |
| 144 | cp -vr ./tf-m-tests_addon/* ./tf-m-tests/ |