blob: 6f2ed98fe716f2cf591d3f64704d59aeb209458e [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 \
Jamie Foxc97891c2024-08-12 15:00:22 +010057 -k <TF-M base directory>/bl2/ext/mcuboot/root-EC-P256.pem \
Jamie Fox519cc4b2022-06-07 12:07:28 +010058 --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
Jamie Foxc97891c2024-08-12 15:00:22 +010079The development key ``root-EC-P256.pem`` corresponds to the default BL2
80signature scheme of ECDSA-P256 used by RSE.
81
Jamie Fox519cc4b2022-06-07 12:07:28 +010082For more information on the ``imgtool`` parameters, see the MCUBoot
83`imgtool documentation <https://docs.mcuboot.com/imgtool.html>`_.
84
85.. warning::
86
Jamie Foxc97891c2024-08-12 15:00:22 +010087 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 Fox519cc4b2022-06-07 12:07:28 +010090
91Running the code
92----------------
93
Raef Coles078f6b02023-07-12 14:38:13 +010094To run the built images, first the ROM image must be created from the bl1_1
95binary and the ROM DMA Initial Command Sequence (ICS).::
96
97 srec_cat \
Jamie Foxea90cbd2024-06-19 18:10:58 +010098 bl1_1.bin -Binary -offset 0x0 \
99 rom_dma_ics.bin -Binary -offset 0x1F000 -fill 0x00 0x1F000 0x20000 \
100 -o rom.bin -Binary
Raef Coles078f6b02023-07-12 14:38:13 +0100101
102Then, the flash image must be created by concatenating the images that are
103output from the build. To create the flash image, the following ``fiptool``
104command should be run. ``fiptool`` documentation can be found `here
Jamie Foxea90cbd2024-06-19 18:10:58 +0100105<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 +0000106Note that an up-to-date fiptool that supports the RSE UUIDs must be used.::
Raef Colescb866c32022-11-30 10:57:18 +0000107
108 fiptool create \
Jamie Foxea90cbd2024-06-19 18:10:58 +0100109 --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 Colescb866c32022-11-30 10:57:18 +0000114 fip.bin
115
Jamie Foxf6424c52023-11-14 17:12:43 +0000116If you already have a ``fip.bin`` containing host firmware images, RSE FIP
Raef Colescb866c32022-11-30 10:57:18 +0000117images can be patched in::
118
Jamie Foxea90cbd2024-06-19 18:10:58 +0100119 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 Colescb866c32022-11-30 10:57:18 +0000122
123If XIP mode is enabled, the following ``fiptool`` command should be run to
Raef Coles7763a472022-11-10 17:11:40 +0000124create the flash image::
125
Raef Colescb866c32022-11-30 10:57:18 +0000126 fiptool create \
Jamie Foxea90cbd2024-06-19 18:10:58 +0100127 --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 Colescb866c32022-11-30 10:57:18 +0000134 fip.bin
Raef Coles45b4f2a2022-11-10 16:43:39 +0000135
Raef Colescb866c32022-11-30 10:57:18 +0000136Once the FIP is prepared, a host flash image can be created using ``srec_cat``::
Raef Coles45b4f2a2022-11-10 16:43:39 +0000137
138 srec_cat \
Raef Colescb866c32022-11-30 10:57:18 +0000139 fip.bin -Binary -offset 0x0 \
Raef Coles45b4f2a2022-11-10 16:43:39 +0000140 -o host_flash.bin -Binary
141
Raef Colescb866c32022-11-30 10:57:18 +0000142If GPT support is enabled, and a host ``fip.bin`` and ``fip_gpt.bin`` has been
Jamie Foxf6424c52023-11-14 17:12:43 +0000143obtained, RSE images can be inserted by first patching the host FIP and then
Raef Colescb866c32022-11-30 10:57:18 +0000144inserting 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 Foxea90cbd2024-06-19 18:10:58 +0100156 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 Colescb866c32022-11-30 10:57:18 +0000159
160 dd if=fip.bin of=fip_gpt.bin bs=$sector_size seek=$fip_start_sector \
161 count=$fip_sector_am conv=notrunc
162
163To patch a ``fip_gpt.bin`` without having an initial ``fip.bin``, the FIP can be
164extracted from the GPT image using the following commands (and can then be
165patched 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
177Once the ``fip_gpt.bin`` is prepared, it is placed at the base of the host flash
178image::
179
180 srec_cat \
181 fip_gpt.bin -Binary -offset 0x0 \
182 -o host_flash.bin -Binary
Jamie Fox519cc4b2022-06-07 12:07:28 +0100183
Jamie Foxf6424c52023-11-14 17:12:43 +0000184The RSE ROM binary should be placed in RSE ROM at ``0x11000000`` and the host
Raef Coles00f1d202023-04-25 14:34:29 +0100185flash binary should be placed at the base of the host flash. For the TC
186platform, this is at ``0x80000000``.
Jamie Fox519cc4b2022-06-07 12:07:28 +0100187
Jamie Foxf6424c52023-11-14 17:12:43 +0000188The RSE OTP must be provisioned. On a development platform with
Jamie Foxd6aec212023-08-01 16:30:54 +0100189``TFM_DUMMY_PROVISIONING`` enabled, BL1_1 expects provisioning bundles to be
Jamie Foxea90cbd2024-06-19 18:10:58 +0100190preloaded into RSE SRAM. Preload ``encrypted_cm_provisioning_bundle_0.bin`` to
191offset ``0x400`` from the base of VM0, and
192``encrypted_dm_provisioning_bundle_0.bin`` to the base of VM1.
Jamie Foxd6aec212023-08-01 16:30:54 +0100193
194If ``TFM_DUMMY_PROVISIONING`` is disabled and provisioning is required, then
195BL1_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
197wait for provisioning bundles to be loaded to VM0 and VM1 in the same way as
198when ``TFM_DUMMY_PROVISIONING`` is enabled, except that it will not
199automatically perform the reset once each provisioning state is complete. For
200more details about provisioning flows, see
Jamie Foxcad65392024-02-19 14:09:20 +0000201:doc:`RSE provisioning </platform/arm/rse/rse_provisioning>`.
Jamie Foxd6aec212023-08-01 16:30:54 +0100202
Jamie Fox519cc4b2022-06-07 12:07:28 +0100203--------------
204
Jamie Foxea90cbd2024-06-19 18:10:58 +0100205*Copyright (c) 2022-2024, Arm Limited. All rights reserved.*