David Vincze | d8ed562 | 2024-02-23 17:00:12 +0100 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | # |
| 3 | # Copyright (c) 2023-2024, Arm Limited. All rights reserved. |
| 4 | # |
| 5 | # SPDX-License-Identifier: BSD-3-Clause |
| 6 | # |
| 7 | |
| 8 | sign_image() { |
| 9 | # $1 ... host binary name to sign |
| 10 | # $2 ... image load address |
| 11 | # $3 ... signed bin size |
| 12 | |
| 13 | local tmpdir="$(mktempdir)" |
| 14 | host_bin="`basename ${1}`" |
| 15 | signed_bin="signed_`basename ${1}`" |
| 16 | host_binary_layout="`basename -s .bin ${1}`_ns" |
| 17 | |
| 18 | # development PEM containing a key - use same key which is used for SCP BL1 in pre-built image |
David Vincze | 3a79332 | 2024-10-31 16:34:02 +0000 | [diff] [blame] | 19 | if [ $plat_variant -eq 3 ]; then |
David Vincze | 9d68908 | 2024-10-21 16:23:19 +0000 | [diff] [blame] | 20 | url="$tc_prebuilts/tc$plat_variant/root-EC-P256.pem" saveas="root-EC-P256.pem" fetch_file |
| 21 | archive_file "root-EC-P256.pem" |
| 22 | RSE_SIGN_PRIVATE_KEY=$archive/root-EC-P256.pem |
| 23 | fi |
David Vincze | d8ed562 | 2024-02-23 17:00:12 +0100 | [diff] [blame] | 24 | |
David Vincze | d8ed562 | 2024-02-23 17:00:12 +0100 | [diff] [blame] | 25 | RSE_SEC_CNTR_INIT_VAL=1 |
David Vincze | 9d68908 | 2024-10-21 16:23:19 +0000 | [diff] [blame] | 26 | RSE_LAYOUT_WRAPPER_VERSION="2.1.0" |
David Vincze | d8ed562 | 2024-02-23 17:00:12 +0100 | [diff] [blame] | 27 | |
| 28 | cat << EOF > $tmpdir/$host_binary_layout |
| 29 | enum image_attributes { |
| 30 | RE_IMAGE_LOAD_ADDRESS = $2, |
| 31 | RE_SIGN_BIN_SIZE = $3, |
| 32 | }; |
| 33 | EOF |
| 34 | |
| 35 | if [ ! -f $archive/$host_bin ]; then |
| 36 | echo "$archive/$host_bin does not exist. Aborting...!" |
| 37 | exit 1 |
| 38 | fi |
| 39 | |
| 40 | echo "Signing `basename ${1}`" |
| 41 | # Get mcuboot |
| 42 | git clone "https://github.com/mcu-tools/mcuboot.git" $tmpdir/mcuboot |
| 43 | # Fetch wrapper script |
| 44 | saveas="$tmpdir" url="$tc_prebuilts/tc$plat_variant/wrapper_scripts" fetch_directory |
| 45 | |
| 46 | echo "Installing dependencies..." |
| 47 | pip3 install cryptography cbor2 intelhex pyyaml |
| 48 | |
| 49 | pushd $tmpdir/mcuboot/scripts |
| 50 | python3 $tmpdir/wrapper_scripts/wrapper/wrapper.py \ |
| 51 | -v $RSE_LAYOUT_WRAPPER_VERSION \ |
| 52 | --layout $tmpdir/$host_binary_layout \ |
| 53 | -k $RSE_SIGN_PRIVATE_KEY \ |
| 54 | --public-key-format full \ |
| 55 | --align 1 \ |
| 56 | --pad \ |
| 57 | --pad-header \ |
| 58 | -H 0x2000 \ |
| 59 | -s $RSE_SEC_CNTR_INIT_VAL \ |
| 60 | $archive/$host_bin \ |
| 61 | $tmpdir/$signed_bin |
| 62 | |
| 63 | echo "created signed_`basename ${1}`" |
| 64 | url="$tmpdir/$signed_bin" saveas="$signed_bin" fetch_file |
| 65 | archive_file "$signed_bin" |
| 66 | popd |
| 67 | } |
| 68 | |
| 69 | update_fip() { |
| 70 | local prebuild_prefix=$tc_prebuilts/tc$plat_variant/$rse_revision |
| 71 | |
| 72 | # Get pre-built rse rom |
| 73 | url="$prebuild_prefix/rse_rom.bin" fetch_file |
| 74 | archive_file "rse_rom.bin" |
| 75 | |
| 76 | # Get pre-built rse bl2 signed bin |
| 77 | url="$prebuild_prefix/rse_bl2_signed.bin" fetch_file |
| 78 | archive_file "rse_bl2_signed.bin" |
| 79 | |
| 80 | # Get pre-built rse TF-M S signed bin |
David Vincze | 3a79332 | 2024-10-31 16:34:02 +0000 | [diff] [blame] | 81 | if [ $plat_variant -eq 3 ]; then |
Leo Yan | 7d0aa2c | 2024-07-03 21:18:38 +0100 | [diff] [blame] | 82 | url="$prebuild_prefix/rse_s_encrypted.bin" fetch_file |
| 83 | archive_file "rse_s_encrypted.bin" |
| 84 | url="$prebuild_prefix/rse_s_sic_tables_signed.bin" fetch_file |
| 85 | archive_file "rse_s_sic_tables_signed.bin" |
| 86 | fi |
David Vincze | d8ed562 | 2024-02-23 17:00:12 +0100 | [diff] [blame] | 87 | |
| 88 | # Get pre-built SCP signed bin |
| 89 | url="$prebuild_prefix/signed_scp_romfw.bin" fetch_file |
| 90 | archive_file "signed_scp_romfw.bin" |
| 91 | |
| 92 | # Create FIP layout |
David Vincze | 3a79332 | 2024-10-31 16:34:02 +0000 | [diff] [blame] | 93 | if [ $plat_variant -eq 3 ]; then |
Leo Yan | 7d0aa2c | 2024-07-03 21:18:38 +0100 | [diff] [blame] | 94 | "$fiptool" update \ |
| 95 | --align 8192 --rse-bl2 "$archive/rse_bl2_signed.bin" \ |
| 96 | --align 8192 --rse-scp-bl1 "$archive/signed_scp_romfw.bin" \ |
| 97 | --align 8192 --rse-ap-bl1 "$archive/$signed_bin" \ |
| 98 | --align 8192 --rse-s "$archive/rse_s_encrypted.bin" \ |
| 99 | --align 8192 --rse-sic-tables-s "$archive/rse_s_sic_tables_signed.bin" \ |
| 100 | --out "host_flash_fip.bin" \ |
| 101 | "$archive/fip.bin" |
| 102 | fi |
David Vincze | d8ed562 | 2024-02-23 17:00:12 +0100 | [diff] [blame] | 103 | archive_file "host_flash_fip.bin" |
| 104 | } |
| 105 | |
| 106 | get_rse_prov_bins() { |
| 107 | local prebuild_prefix=$tc_prebuilts/tc$plat_variant/$rse_revision |
| 108 | |
| 109 | # Get pre-built rse rse_encrypted_cm_provisioning_bundle_0 bin |
| 110 | url="$prebuild_prefix/rse_encrypted_cm_provisioning_bundle_0.bin" fetch_file |
| 111 | archive_file "rse_encrypted_cm_provisioning_bundle_0.bin" |
| 112 | |
| 113 | # Get pre-built rse rse_encrypted_dm_provisioning_bundle bin |
| 114 | url="$prebuild_prefix/rse_encrypted_dm_provisioning_bundle.bin" fetch_file |
| 115 | archive_file "rse_encrypted_dm_provisioning_bundle.bin" |
| 116 | } |