blob: 40e0315be802e8a23da69d5fd3f3e9dc762bd9b0 [file] [log] [blame]
Jamie Foxf6424c52023-11-14 17:12:43 +00001Runtime Security Engine (RSE)
2=============================
Jamie Fox519cc4b2022-06-07 12:07:28 +01003
4Introduction
5------------
6
Jamie Foxea90cbd2024-06-19 18:10:58 +01007Runtime Security Engine (RSE) is an Arm subsystem that serves as a hardware
8root-of-trust and isolated attestation enclave in A-profile compute subsystems.
9RSE provides a physically-isolated execution environment for security-critical
10assets and services, which can be configured according to use case. In systems
11that implement the `Arm Confidential Compute Architecture (CCA)
12<https://www.arm.com/architecture/security-features/arm-confidential-compute-architecture>`_,
13RSE fulfils the requirements of the HES Host. In `DICE
14<https://trustedcomputinggroup.org/work-groups/dice-architectures/>`_
15attestation schemes, RSE provides a DICE Protection Environment (DPE)
16implementation.
Jamie Fox519cc4b2022-06-07 12:07:28 +010017
Jamie Foxea90cbd2024-06-19 18:10:58 +010018RSE initially boots from immutable code :doc:`(BL1_1) </design_docs/booting/bl1>`
19in its internal ROM, before jumping to BL1_2, which is provisioned and
20hash-locked in RSE OTP. The updatable MCUBoot BL2 boot stage is loaded from host
21system flash into RSE SRAM, where it is authenticated using the LMS stateful
22hash-based signature scheme. :doc:`BL2 </design_docs/booting/tfm_secure_boot>`
23loads and authenticates the TF-M runtime and RSE NS image (if applicable) into
24RSE SRAM from host flash. BL2 is also responsible for loading initial boot code
25into other subsystems within the host.
Jamie Fox519cc4b2022-06-07 12:07:28 +010026
Jamie Foxea90cbd2024-06-19 18:10:58 +010027The TF-M runtime for RSE supports the TF-M Crypto, ADAC (Authenticated Debug
28Access Control) and Platform services, along with the Measured Boot, Initial
29Attestation and Delegated Attestation services in the CCA HES use case and the
30DICE Protection Environment service in the DICE use case. It supports the TF-M
31IPC model with Isolation Level 1 and 2. At runtime, RSE can receive service
32requests from the RSE NSPE via the TF-M TrustZone interface and from other
33processing elements in the system over MHU using the
34:doc:`RSE comms protocol </platform/arm/rse/rse_comms>`.
Jamie Fox519cc4b2022-06-07 12:07:28 +010035
36Building TF-M
37-------------
38
Anton Komlev0dbe8f12022-06-17 16:48:12 +010039Follow the instructions in :doc:`Build instructions </building/tfm_build_instruction>`.
Jamie Foxcad65392024-02-19 14:09:20 +000040Build TF-M with platform name: `arm/rse/<rse platform name>`
Jamie Fox519cc4b2022-06-07 12:07:28 +010041
Jamie Foxea90cbd2024-06-19 18:10:58 +010042For example, to build RSE for the Total Compute TC2 platform use:
43``-DTFM_PLATFORM=arm/rse/tc/tc2``
Jamie Fox519cc4b2022-06-07 12:07:28 +010044
45Signing host images
46-------------------
47
Jamie Foxf6424c52023-11-14 17:12:43 +000048RSE BL2 can load boot images into other subsystems within the host system. It
Jamie Fox519cc4b2022-06-07 12:07:28 +010049expects images to be signed, with the signatures attached to the images in the
50MCUBoot metadata format.
51
52The `imgtool Python package <https://pypi.org/project/imgtool/>`_ can be used to
53sign images in the required format. To sign a host image using the development
54key distributed with TF-M, use the following command::
55
56 imgtool sign \
57 -k <TF-M base directory>/bl2/ext/mcuboot/root-RSA-3072.pem \
58 --public-key-format full \
59 --max-align 8 \
60 --align 1 \
61 -v "0.0.1" \
62 -s 1 \
Raef Coles00f1d202023-04-25 14:34:29 +010063 -H 0x2000 \
Jamie Fox519cc4b2022-06-07 12:07:28 +010064 --pad-header \
65 -S 0x80000 \
66 --pad \
Jamie Fox519cc4b2022-06-07 12:07:28 +010067 -L <load address> \
68 <binary infile> \
69 <signed binary outfile>
70
Jamie Foxf6424c52023-11-14 17:12:43 +000071The ``load address`` is the logical address in the RSE memory map to which BL2
72will 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 Foxd6aec212023-08-01 16:30:54 +010074subsequent host image to be loaded at an offset of ``0x1000000`` from the
Jamie Foxf6424c52023-11-14 17:12:43 +000075previous image. The RSE ATU should be configured to map these logical addresses
Jamie Foxa1e86022022-07-12 17:58:02 +010076to the physical addresses in the host system that the images need to be loaded
77to.
Jamie Fox519cc4b2022-06-07 12:07:28 +010078
79For more information on the ``imgtool`` parameters, see the MCUBoot
80`imgtool documentation <https://docs.mcuboot.com/imgtool.html>`_.
81
82.. warning::
83
84 The TF-M development key must never be used in production. To generate a
85 production key, follow the imgtool documentation.
86
87Running the code
88----------------
89
Raef Coles078f6b02023-07-12 14:38:13 +010090To run the built images, first the ROM image must be created from the bl1_1
91binary and the ROM DMA Initial Command Sequence (ICS).::
92
93 srec_cat \
Jamie Foxea90cbd2024-06-19 18:10:58 +010094 bl1_1.bin -Binary -offset 0x0 \
95 rom_dma_ics.bin -Binary -offset 0x1F000 -fill 0x00 0x1F000 0x20000 \
96 -o rom.bin -Binary
Raef Coles078f6b02023-07-12 14:38:13 +010097
98Then, the flash image must be created by concatenating the images that are
99output from the build. To create the flash image, the following ``fiptool``
100command should be run. ``fiptool`` documentation can be found `here
Jamie Foxea90cbd2024-06-19 18:10:58 +0100101<https://trustedfirmware-a.readthedocs.io/en/latest/getting_started/tools-build.html#building-and-using-the-fip-tool>`_.
Jamie Foxf6424c52023-11-14 17:12:43 +0000102Note that an up-to-date fiptool that supports the RSE UUIDs must be used.::
Raef Colescb866c32022-11-30 10:57:18 +0000103
104 fiptool create \
Jamie Foxea90cbd2024-06-19 18:10:58 +0100105 --align 8192 --rse-bl2 bl2_signed.bin \
106 --align 8192 --rse-ns tfm_ns_signed.bin \
107 --align 8192 --rse-s tfm_s_signed.bin \
108 --align 8192 --rse-scp-bl1 <signed Host SCP BL1 image> \
109 --align 8192 --rse-ap-bl1 <signed Host AP BL1 image> \
Raef Colescb866c32022-11-30 10:57:18 +0000110 fip.bin
111
Jamie Foxf6424c52023-11-14 17:12:43 +0000112If you already have a ``fip.bin`` containing host firmware images, RSE FIP
Raef Colescb866c32022-11-30 10:57:18 +0000113images can be patched in::
114
Jamie Foxea90cbd2024-06-19 18:10:58 +0100115 fiptool update --align 8192 --rse-bl2 bl2_signed.bin fip.bin
116 fiptool update --align 8192 --rse-ns tfm_ns.bin fip.bin
117 fiptool update --align 8192 --rse-s tfm_s.bin fip.bin
Raef Colescb866c32022-11-30 10:57:18 +0000118
119If XIP mode is enabled, the following ``fiptool`` command should be run to
Raef Coles7763a472022-11-10 17:11:40 +0000120create the flash image::
121
Raef Colescb866c32022-11-30 10:57:18 +0000122 fiptool create \
Jamie Foxea90cbd2024-06-19 18:10:58 +0100123 --align 8192 --rse-bl2 bl2_signed.bin \
124 --align 8192 --rse-ns tfm_ns_encrypted.bin \
125 --align 8192 --rse-s tfm_s_encrypted.bin \
126 --align 8192 --rse-sic-tables-ns tfm_ns_sic_tables_signed.bin \
127 --align 8192 --rse-sic-tables-s tfm_s_sic_tables_signed.bin \
128 --align 8192 --rse-scp-bl1 <signed Host SCP BL1 image> \
129 --align 8192 --rse-ap-bl1 <signed Host AP BL1 image> \
Raef Colescb866c32022-11-30 10:57:18 +0000130 fip.bin
Raef Coles45b4f2a2022-11-10 16:43:39 +0000131
Raef Colescb866c32022-11-30 10:57:18 +0000132Once the FIP is prepared, a host flash image can be created using ``srec_cat``::
Raef Coles45b4f2a2022-11-10 16:43:39 +0000133
134 srec_cat \
Raef Colescb866c32022-11-30 10:57:18 +0000135 fip.bin -Binary -offset 0x0 \
Raef Coles45b4f2a2022-11-10 16:43:39 +0000136 -o host_flash.bin -Binary
137
Raef Colescb866c32022-11-30 10:57:18 +0000138If GPT support is enabled, and a host ``fip.bin`` and ``fip_gpt.bin`` has been
Jamie Foxf6424c52023-11-14 17:12:43 +0000139obtained, RSE images can be inserted by first patching the host FIP and then
Raef Colescb866c32022-11-30 10:57:18 +0000140inserting that patched FIP into the GPT image::
141
142 sector_size=$(gdisk -l fip_gpt.bin | grep -i "sector size (logical):" | \
143 sed 's/.*logical): \([0-9]*\) bytes/\1/')
144
145 fip_label=" FIP_A$"
146 fip_start_sector=$(gdisk -l fip_gpt.bin | grep "$fip_label" | awk '{print $2}')
147 fip_sector_am=$(gdisk -l fip_gpt.bin | grep "$fip_label" | awk '{print $3 - $2}')
148
149 dd if=fip.bin of=fip_gpt.bin bs=$sector_size seek=$fip_start_sector \
150 count=$fip_sector_am conv=notrunc
151
Jamie Foxea90cbd2024-06-19 18:10:58 +0100152 fip_label=" FIP_B$"
153 fip_start_sector=$(gdisk -l fip_gpt.bin | grep "$fip_label" | awk '{print $2}')
154 fip_sector_am=$(gdisk -l fip_gpt.bin | grep "$fip_label" | awk '{print $3 - $2}')
Raef Colescb866c32022-11-30 10:57:18 +0000155
156 dd if=fip.bin of=fip_gpt.bin bs=$sector_size seek=$fip_start_sector \
157 count=$fip_sector_am conv=notrunc
158
159To patch a ``fip_gpt.bin`` without having an initial ``fip.bin``, the FIP can be
160extracted from the GPT image using the following commands (and can then be
161patched and reinserted using the above commands)::
162
163 sector_size=$(gdisk -l fip_gpt.bin | grep -i "sector size (logical):" | \
164 sed 's/.*logical): \([0-9]*\) bytes/\1/')
165
166 fip_label=" FIP_A$"
167 fip_start_sector=$(gdisk -l fip_gpt.bin | grep "$fip_label" | awk '{print $2}')
168 fip_sector_am=$(gdisk -l fip_gpt.bin | grep "$fip_label" | awk '{print $3 - $2}')
169
170 dd if=fip_gpt.bin of=fip.bin bs=$sector_size skip=$fip_start_sector \
171 count=$fip_sector_am conv=notrunc
172
173Once the ``fip_gpt.bin`` is prepared, it is placed at the base of the host flash
174image::
175
176 srec_cat \
177 fip_gpt.bin -Binary -offset 0x0 \
178 -o host_flash.bin -Binary
Jamie Fox519cc4b2022-06-07 12:07:28 +0100179
Jamie Foxf6424c52023-11-14 17:12:43 +0000180The RSE ROM binary should be placed in RSE ROM at ``0x11000000`` and the host
Raef Coles00f1d202023-04-25 14:34:29 +0100181flash binary should be placed at the base of the host flash. For the TC
182platform, this is at ``0x80000000``.
Jamie Fox519cc4b2022-06-07 12:07:28 +0100183
Jamie Foxf6424c52023-11-14 17:12:43 +0000184The RSE OTP must be provisioned. On a development platform with
Jamie Foxd6aec212023-08-01 16:30:54 +0100185``TFM_DUMMY_PROVISIONING`` enabled, BL1_1 expects provisioning bundles to be
Jamie Foxea90cbd2024-06-19 18:10:58 +0100186preloaded into RSE SRAM. Preload ``encrypted_cm_provisioning_bundle_0.bin`` to
187offset ``0x400`` from the base of VM0, and
188``encrypted_dm_provisioning_bundle_0.bin`` to the base of VM1.
Jamie Foxd6aec212023-08-01 16:30:54 +0100189
190If ``TFM_DUMMY_PROVISIONING`` is disabled and provisioning is required, then
191BL1_1 will first wait for the TP mode to be set by a debugger (setting the
192``tp_mode`` variable in the current stack frame is easiest). BL1_1 will then
193wait for provisioning bundles to be loaded to VM0 and VM1 in the same way as
194when ``TFM_DUMMY_PROVISIONING`` is enabled, except that it will not
195automatically perform the reset once each provisioning state is complete. For
196more details about provisioning flows, see
Jamie Foxcad65392024-02-19 14:09:20 +0000197:doc:`RSE provisioning </platform/arm/rse/rse_provisioning>`.
Jamie Foxd6aec212023-08-01 16:30:54 +0100198
Jamie Fox519cc4b2022-06-07 12:07:28 +0100199--------------
200
Jamie Foxea90cbd2024-06-19 18:10:58 +0100201*Copyright (c) 2022-2024, Arm Limited. All rights reserved.*