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