Jamie Fox | f6424c5 | 2023-11-14 17:12:43 +0000 | [diff] [blame] | 1 | Runtime Security Engine (RSE) |
| 2 | ============================= |
Jamie Fox | 519cc4b | 2022-06-07 12:07:28 +0100 | [diff] [blame] | 3 | |
| 4 | Introduction |
| 5 | ------------ |
| 6 | |
Jamie Fox | ea90cbd | 2024-06-19 18:10:58 +0100 | [diff] [blame] | 7 | Runtime Security Engine (RSE) is an Arm subsystem that serves as a hardware |
| 8 | root-of-trust and isolated attestation enclave in A-profile compute subsystems. |
| 9 | RSE provides a physically-isolated execution environment for security-critical |
| 10 | assets and services, which can be configured according to use case. In systems |
| 11 | that implement the `Arm Confidential Compute Architecture (CCA) |
| 12 | <https://www.arm.com/architecture/security-features/arm-confidential-compute-architecture>`_, |
| 13 | RSE fulfils the requirements of the HES Host. In `DICE |
| 14 | <https://trustedcomputinggroup.org/work-groups/dice-architectures/>`_ |
| 15 | attestation schemes, RSE provides a DICE Protection Environment (DPE) |
| 16 | implementation. |
Jamie Fox | 519cc4b | 2022-06-07 12:07:28 +0100 | [diff] [blame] | 17 | |
Jamie Fox | ea90cbd | 2024-06-19 18:10:58 +0100 | [diff] [blame] | 18 | RSE initially boots from immutable code :doc:`(BL1_1) </design_docs/booting/bl1>` |
| 19 | in its internal ROM, before jumping to BL1_2, which is provisioned and |
| 20 | hash-locked in RSE OTP. The updatable MCUBoot BL2 boot stage is loaded from host |
| 21 | system flash into RSE SRAM, where it is authenticated using the LMS stateful |
| 22 | hash-based signature scheme. :doc:`BL2 </design_docs/booting/tfm_secure_boot>` |
| 23 | loads and authenticates the TF-M runtime and RSE NS image (if applicable) into |
| 24 | RSE SRAM from host flash. BL2 is also responsible for loading initial boot code |
| 25 | into other subsystems within the host. |
Jamie Fox | 519cc4b | 2022-06-07 12:07:28 +0100 | [diff] [blame] | 26 | |
Jamie Fox | ea90cbd | 2024-06-19 18:10:58 +0100 | [diff] [blame] | 27 | The TF-M runtime for RSE supports the TF-M Crypto, ADAC (Authenticated Debug |
| 28 | Access Control) and Platform services, along with the Measured Boot, Initial |
| 29 | Attestation and Delegated Attestation services in the CCA HES use case and the |
| 30 | DICE Protection Environment service in the DICE use case. It supports the TF-M |
| 31 | IPC model with Isolation Level 1 and 2. At runtime, RSE can receive service |
| 32 | requests from the RSE NSPE via the TF-M TrustZone interface and from other |
| 33 | processing elements in the system over MHU using the |
| 34 | :doc:`RSE comms protocol </platform/arm/rse/rse_comms>`. |
Jamie Fox | 519cc4b | 2022-06-07 12:07:28 +0100 | [diff] [blame] | 35 | |
| 36 | Building TF-M |
| 37 | ------------- |
| 38 | |
Anton Komlev | 0dbe8f1 | 2022-06-17 16:48:12 +0100 | [diff] [blame] | 39 | Follow the instructions in :doc:`Build instructions </building/tfm_build_instruction>`. |
Jamie Fox | cad6539 | 2024-02-19 14:09:20 +0000 | [diff] [blame] | 40 | Build TF-M with platform name: `arm/rse/<rse platform name>` |
Jamie Fox | 519cc4b | 2022-06-07 12:07:28 +0100 | [diff] [blame] | 41 | |
Jackson Cooper-Driver | af041c0 | 2024-10-28 09:44:20 +0000 | [diff] [blame^] | 42 | For example, to build RSE for the Total Compute TC3 platform use: |
| 43 | ``-DTFM_PLATFORM=arm/rse/tc/tc3`` |
Jamie Fox | 519cc4b | 2022-06-07 12:07:28 +0100 | [diff] [blame] | 44 | |
| 45 | Signing host images |
| 46 | ------------------- |
| 47 | |
Jamie Fox | f6424c5 | 2023-11-14 17:12:43 +0000 | [diff] [blame] | 48 | RSE BL2 can load boot images into other subsystems within the host system. It |
Jamie Fox | 519cc4b | 2022-06-07 12:07:28 +0100 | [diff] [blame] | 49 | expects images to be signed, with the signatures attached to the images in the |
| 50 | MCUBoot metadata format. |
| 51 | |
| 52 | The `imgtool Python package <https://pypi.org/project/imgtool/>`_ can be used to |
| 53 | sign images in the required format. To sign a host image using the development |
| 54 | key distributed with TF-M, use the following command:: |
| 55 | |
| 56 | imgtool sign \ |
Jamie Fox | c97891c | 2024-08-12 15:00:22 +0100 | [diff] [blame] | 57 | -k <TF-M base directory>/bl2/ext/mcuboot/root-EC-P256.pem \ |
Jamie Fox | 519cc4b | 2022-06-07 12:07:28 +0100 | [diff] [blame] | 58 | --public-key-format full \ |
| 59 | --max-align 8 \ |
| 60 | --align 1 \ |
| 61 | -v "0.0.1" \ |
| 62 | -s 1 \ |
Raef Coles | 00f1d20 | 2023-04-25 14:34:29 +0100 | [diff] [blame] | 63 | -H 0x2000 \ |
Jamie Fox | 519cc4b | 2022-06-07 12:07:28 +0100 | [diff] [blame] | 64 | --pad-header \ |
| 65 | -S 0x80000 \ |
| 66 | --pad \ |
Jamie Fox | 519cc4b | 2022-06-07 12:07:28 +0100 | [diff] [blame] | 67 | -L <load address> \ |
| 68 | <binary infile> \ |
| 69 | <signed binary outfile> |
| 70 | |
Jamie Fox | f6424c5 | 2023-11-14 17:12:43 +0000 | [diff] [blame] | 71 | The ``load address`` is the logical address in the RSE memory map to which BL2 |
| 72 | will load the image. RSE FW expects the first host image to be loaded to address |
| 73 | ``0x70000000`` (the beginning of the RSE ATU host access region), and each |
Jamie Fox | d6aec21 | 2023-08-01 16:30:54 +0100 | [diff] [blame] | 74 | subsequent host image to be loaded at an offset of ``0x1000000`` from the |
Jamie Fox | f6424c5 | 2023-11-14 17:12:43 +0000 | [diff] [blame] | 75 | previous image. The RSE ATU should be configured to map these logical addresses |
Jamie Fox | a1e8602 | 2022-07-12 17:58:02 +0100 | [diff] [blame] | 76 | to the physical addresses in the host system that the images need to be loaded |
| 77 | to. |
Jamie Fox | 519cc4b | 2022-06-07 12:07:28 +0100 | [diff] [blame] | 78 | |
Jamie Fox | c97891c | 2024-08-12 15:00:22 +0100 | [diff] [blame] | 79 | The development key ``root-EC-P256.pem`` corresponds to the default BL2 |
| 80 | signature scheme of ECDSA-P256 used by RSE. |
| 81 | |
Jamie Fox | 519cc4b | 2022-06-07 12:07:28 +0100 | [diff] [blame] | 82 | For more information on the ``imgtool`` parameters, see the MCUBoot |
| 83 | `imgtool documentation <https://docs.mcuboot.com/imgtool.html>`_. |
| 84 | |
| 85 | .. warning:: |
| 86 | |
Jamie Fox | c97891c | 2024-08-12 15:00:22 +0100 | [diff] [blame] | 87 | The TF-M development key must never be used in production. See the |
| 88 | :doc:`RSE integration guide </platform/arm/rse/rse_integration_guide>` for |
| 89 | more information about key management. |
Jamie Fox | 519cc4b | 2022-06-07 12:07:28 +0100 | [diff] [blame] | 90 | |
| 91 | Running the code |
| 92 | ---------------- |
| 93 | |
Raef Coles | 078f6b0 | 2023-07-12 14:38:13 +0100 | [diff] [blame] | 94 | To run the built images, first the ROM image must be created from the bl1_1 |
| 95 | binary and the ROM DMA Initial Command Sequence (ICS).:: |
| 96 | |
| 97 | srec_cat \ |
Jamie Fox | ea90cbd | 2024-06-19 18:10:58 +0100 | [diff] [blame] | 98 | bl1_1.bin -Binary -offset 0x0 \ |
| 99 | rom_dma_ics.bin -Binary -offset 0x1F000 -fill 0x00 0x1F000 0x20000 \ |
| 100 | -o rom.bin -Binary |
Raef Coles | 078f6b0 | 2023-07-12 14:38:13 +0100 | [diff] [blame] | 101 | |
| 102 | Then, the flash image must be created by concatenating the images that are |
| 103 | output from the build. To create the flash image, the following ``fiptool`` |
| 104 | command should be run. ``fiptool`` documentation can be found `here |
Jamie Fox | ea90cbd | 2024-06-19 18:10:58 +0100 | [diff] [blame] | 105 | <https://trustedfirmware-a.readthedocs.io/en/latest/getting_started/tools-build.html#building-and-using-the-fip-tool>`_. |
Jamie Fox | f6424c5 | 2023-11-14 17:12:43 +0000 | [diff] [blame] | 106 | Note that an up-to-date fiptool that supports the RSE UUIDs must be used.:: |
Raef Coles | cb866c3 | 2022-11-30 10:57:18 +0000 | [diff] [blame] | 107 | |
| 108 | fiptool create \ |
Jamie Fox | ea90cbd | 2024-06-19 18:10:58 +0100 | [diff] [blame] | 109 | --align 8192 --rse-bl2 bl2_signed.bin \ |
| 110 | --align 8192 --rse-ns tfm_ns_signed.bin \ |
| 111 | --align 8192 --rse-s tfm_s_signed.bin \ |
| 112 | --align 8192 --rse-scp-bl1 <signed Host SCP BL1 image> \ |
| 113 | --align 8192 --rse-ap-bl1 <signed Host AP BL1 image> \ |
Raef Coles | cb866c3 | 2022-11-30 10:57:18 +0000 | [diff] [blame] | 114 | fip.bin |
| 115 | |
Jamie Fox | f6424c5 | 2023-11-14 17:12:43 +0000 | [diff] [blame] | 116 | If you already have a ``fip.bin`` containing host firmware images, RSE FIP |
Raef Coles | cb866c3 | 2022-11-30 10:57:18 +0000 | [diff] [blame] | 117 | images can be patched in:: |
| 118 | |
Jamie Fox | ea90cbd | 2024-06-19 18:10:58 +0100 | [diff] [blame] | 119 | fiptool update --align 8192 --rse-bl2 bl2_signed.bin fip.bin |
| 120 | fiptool update --align 8192 --rse-ns tfm_ns.bin fip.bin |
| 121 | fiptool update --align 8192 --rse-s tfm_s.bin fip.bin |
Raef Coles | cb866c3 | 2022-11-30 10:57:18 +0000 | [diff] [blame] | 122 | |
| 123 | If XIP mode is enabled, the following ``fiptool`` command should be run to |
Raef Coles | 7763a47 | 2022-11-10 17:11:40 +0000 | [diff] [blame] | 124 | create the flash image:: |
| 125 | |
Raef Coles | cb866c3 | 2022-11-30 10:57:18 +0000 | [diff] [blame] | 126 | fiptool create \ |
Jamie Fox | ea90cbd | 2024-06-19 18:10:58 +0100 | [diff] [blame] | 127 | --align 8192 --rse-bl2 bl2_signed.bin \ |
| 128 | --align 8192 --rse-ns tfm_ns_encrypted.bin \ |
| 129 | --align 8192 --rse-s tfm_s_encrypted.bin \ |
| 130 | --align 8192 --rse-sic-tables-ns tfm_ns_sic_tables_signed.bin \ |
| 131 | --align 8192 --rse-sic-tables-s tfm_s_sic_tables_signed.bin \ |
| 132 | --align 8192 --rse-scp-bl1 <signed Host SCP BL1 image> \ |
| 133 | --align 8192 --rse-ap-bl1 <signed Host AP BL1 image> \ |
Raef Coles | cb866c3 | 2022-11-30 10:57:18 +0000 | [diff] [blame] | 134 | fip.bin |
Raef Coles | 45b4f2a | 2022-11-10 16:43:39 +0000 | [diff] [blame] | 135 | |
Raef Coles | cb866c3 | 2022-11-30 10:57:18 +0000 | [diff] [blame] | 136 | Once the FIP is prepared, a host flash image can be created using ``srec_cat``:: |
Raef Coles | 45b4f2a | 2022-11-10 16:43:39 +0000 | [diff] [blame] | 137 | |
| 138 | srec_cat \ |
Raef Coles | cb866c3 | 2022-11-30 10:57:18 +0000 | [diff] [blame] | 139 | fip.bin -Binary -offset 0x0 \ |
Raef Coles | 45b4f2a | 2022-11-10 16:43:39 +0000 | [diff] [blame] | 140 | -o host_flash.bin -Binary |
| 141 | |
Raef Coles | cb866c3 | 2022-11-30 10:57:18 +0000 | [diff] [blame] | 142 | If GPT support is enabled, and a host ``fip.bin`` and ``fip_gpt.bin`` has been |
Jamie Fox | f6424c5 | 2023-11-14 17:12:43 +0000 | [diff] [blame] | 143 | obtained, RSE images can be inserted by first patching the host FIP and then |
Raef Coles | cb866c3 | 2022-11-30 10:57:18 +0000 | [diff] [blame] | 144 | inserting that patched FIP into the GPT image:: |
| 145 | |
| 146 | sector_size=$(gdisk -l fip_gpt.bin | grep -i "sector size (logical):" | \ |
| 147 | sed 's/.*logical): \([0-9]*\) bytes/\1/') |
| 148 | |
| 149 | fip_label=" FIP_A$" |
| 150 | fip_start_sector=$(gdisk -l fip_gpt.bin | grep "$fip_label" | awk '{print $2}') |
| 151 | fip_sector_am=$(gdisk -l fip_gpt.bin | grep "$fip_label" | awk '{print $3 - $2}') |
| 152 | |
| 153 | dd if=fip.bin of=fip_gpt.bin bs=$sector_size seek=$fip_start_sector \ |
| 154 | count=$fip_sector_am conv=notrunc |
| 155 | |
Jamie Fox | ea90cbd | 2024-06-19 18:10:58 +0100 | [diff] [blame] | 156 | fip_label=" FIP_B$" |
| 157 | fip_start_sector=$(gdisk -l fip_gpt.bin | grep "$fip_label" | awk '{print $2}') |
| 158 | fip_sector_am=$(gdisk -l fip_gpt.bin | grep "$fip_label" | awk '{print $3 - $2}') |
Raef Coles | cb866c3 | 2022-11-30 10:57:18 +0000 | [diff] [blame] | 159 | |
| 160 | dd if=fip.bin of=fip_gpt.bin bs=$sector_size seek=$fip_start_sector \ |
| 161 | count=$fip_sector_am conv=notrunc |
| 162 | |
| 163 | To patch a ``fip_gpt.bin`` without having an initial ``fip.bin``, the FIP can be |
| 164 | extracted from the GPT image using the following commands (and can then be |
| 165 | patched and reinserted using the above commands):: |
| 166 | |
| 167 | sector_size=$(gdisk -l fip_gpt.bin | grep -i "sector size (logical):" | \ |
| 168 | sed 's/.*logical): \([0-9]*\) bytes/\1/') |
| 169 | |
| 170 | fip_label=" FIP_A$" |
| 171 | fip_start_sector=$(gdisk -l fip_gpt.bin | grep "$fip_label" | awk '{print $2}') |
| 172 | fip_sector_am=$(gdisk -l fip_gpt.bin | grep "$fip_label" | awk '{print $3 - $2}') |
| 173 | |
| 174 | dd if=fip_gpt.bin of=fip.bin bs=$sector_size skip=$fip_start_sector \ |
| 175 | count=$fip_sector_am conv=notrunc |
| 176 | |
| 177 | Once the ``fip_gpt.bin`` is prepared, it is placed at the base of the host flash |
| 178 | image:: |
| 179 | |
| 180 | srec_cat \ |
| 181 | fip_gpt.bin -Binary -offset 0x0 \ |
| 182 | -o host_flash.bin -Binary |
Jamie Fox | 519cc4b | 2022-06-07 12:07:28 +0100 | [diff] [blame] | 183 | |
Jamie Fox | f6424c5 | 2023-11-14 17:12:43 +0000 | [diff] [blame] | 184 | The RSE ROM binary should be placed in RSE ROM at ``0x11000000`` and the host |
Raef Coles | 00f1d20 | 2023-04-25 14:34:29 +0100 | [diff] [blame] | 185 | flash binary should be placed at the base of the host flash. For the TC |
| 186 | platform, this is at ``0x80000000``. |
Jamie Fox | 519cc4b | 2022-06-07 12:07:28 +0100 | [diff] [blame] | 187 | |
Jamie Fox | f6424c5 | 2023-11-14 17:12:43 +0000 | [diff] [blame] | 188 | The RSE OTP must be provisioned. On a development platform with |
Jamie Fox | d6aec21 | 2023-08-01 16:30:54 +0100 | [diff] [blame] | 189 | ``TFM_DUMMY_PROVISIONING`` enabled, BL1_1 expects provisioning bundles to be |
Jamie Fox | ea90cbd | 2024-06-19 18:10:58 +0100 | [diff] [blame] | 190 | preloaded into RSE SRAM. Preload ``encrypted_cm_provisioning_bundle_0.bin`` to |
| 191 | offset ``0x400`` from the base of VM0, and |
| 192 | ``encrypted_dm_provisioning_bundle_0.bin`` to the base of VM1. |
Jamie Fox | d6aec21 | 2023-08-01 16:30:54 +0100 | [diff] [blame] | 193 | |
| 194 | If ``TFM_DUMMY_PROVISIONING`` is disabled and provisioning is required, then |
| 195 | BL1_1 will first wait for the TP mode to be set by a debugger (setting the |
| 196 | ``tp_mode`` variable in the current stack frame is easiest). BL1_1 will then |
| 197 | wait for provisioning bundles to be loaded to VM0 and VM1 in the same way as |
| 198 | when ``TFM_DUMMY_PROVISIONING`` is enabled, except that it will not |
| 199 | automatically perform the reset once each provisioning state is complete. For |
| 200 | more details about provisioning flows, see |
Jamie Fox | cad6539 | 2024-02-19 14:09:20 +0000 | [diff] [blame] | 201 | :doc:`RSE provisioning </platform/arm/rse/rse_provisioning>`. |
Jamie Fox | d6aec21 | 2023-08-01 16:30:54 +0100 | [diff] [blame] | 202 | |
Jamie Fox | 519cc4b | 2022-06-07 12:07:28 +0100 | [diff] [blame] | 203 | -------------- |
| 204 | |
Jamie Fox | ea90cbd | 2024-06-19 18:10:58 +0100 | [diff] [blame] | 205 | *Copyright (c) 2022-2024, Arm Limited. All rights reserved.* |