1*54fd6939SJiyong Park 2*54fd6939SJiyong ParkRealm Management Extension (RME) 3*54fd6939SJiyong Park==================================== 4*54fd6939SJiyong Park 5*54fd6939SJiyong ParkFEAT_RME (or RME for short) is an Armv9-A extension and is one component of the 6*54fd6939SJiyong Park`Arm Confidential Compute Architecture (Arm CCA)`_. TF-A supports RME starting 7*54fd6939SJiyong Parkfrom version 2.6. This chapter discusses the changes to TF-A to support RME and 8*54fd6939SJiyong Parkprovides instructions on how to build and run TF-A with RME. 9*54fd6939SJiyong Park 10*54fd6939SJiyong ParkRME support in TF-A 11*54fd6939SJiyong Park--------------------- 12*54fd6939SJiyong Park 13*54fd6939SJiyong ParkThe following diagram shows an Arm CCA software architecture with TF-A as the 14*54fd6939SJiyong ParkEL3 firmware. In the Arm CCA architecture there are two additional security 15*54fd6939SJiyong Parkstates and address spaces: ``Root`` and ``Realm``. TF-A firmware runs in the 16*54fd6939SJiyong ParkRoot world. In the realm world, a Realm Management Monitor firmware (RMM) 17*54fd6939SJiyong Parkmanages the execution of Realm VMs and their interaction with the hypervisor. 18*54fd6939SJiyong Park 19*54fd6939SJiyong Park.. image:: ../resources/diagrams/arm-cca-software-arch.png 20*54fd6939SJiyong Park 21*54fd6939SJiyong ParkRME is the hardware extension to support Arm CCA. To support RME, various 22*54fd6939SJiyong Parkchanges have been introduced to TF-A. We discuss those changes below. 23*54fd6939SJiyong Park 24*54fd6939SJiyong ParkChanges to translation tables library 25*54fd6939SJiyong Park*************************************** 26*54fd6939SJiyong ParkRME adds Root and Realm Physical address spaces. To support this, two new 27*54fd6939SJiyong Parkmemory type macros, ``MT_ROOT`` and ``MT_REALM``, have been added to the 28*54fd6939SJiyong Park:ref:`Translation (XLAT) Tables Library`. These macros are used to configure 29*54fd6939SJiyong Parkmemory regions as Root or Realm respectively. 30*54fd6939SJiyong Park 31*54fd6939SJiyong Park.. note:: 32*54fd6939SJiyong Park 33*54fd6939SJiyong Park Only version 2 of the translation tables library supports the new memory 34*54fd6939SJiyong Park types. 35*54fd6939SJiyong Park 36*54fd6939SJiyong ParkChanges to context management 37*54fd6939SJiyong Park******************************* 38*54fd6939SJiyong ParkA new CPU context for the Realm world has been added. The existing 39*54fd6939SJiyong Park:ref:`CPU context management API<PSCI Library Integration guide for Armv8-A 40*54fd6939SJiyong ParkAArch32 systems>` can be used to manage Realm context. 41*54fd6939SJiyong Park 42*54fd6939SJiyong ParkBoot flow changes 43*54fd6939SJiyong Park******************* 44*54fd6939SJiyong ParkIn a typical TF-A boot flow, BL2 runs at Secure-EL1. However when RME is 45*54fd6939SJiyong Parkenabled, TF-A runs in the Root world at EL3. Therefore, the boot flow is 46*54fd6939SJiyong Parkmodified to run BL2 at EL3 when RME is enabled. In addition to this, a 47*54fd6939SJiyong ParkRealm-world firmware (RMM) is loaded by BL2 in the Realm physical address 48*54fd6939SJiyong Parkspace. 49*54fd6939SJiyong Park 50*54fd6939SJiyong ParkThe boot flow when RME is enabled looks like the following: 51*54fd6939SJiyong Park 52*54fd6939SJiyong Park1. BL1 loads and executes BL2 at EL3 53*54fd6939SJiyong Park2. BL2 loads images including RMM 54*54fd6939SJiyong Park3. BL2 transfers control to BL31 55*54fd6939SJiyong Park4. BL31 initializes SPM (if SPM is enabled) 56*54fd6939SJiyong Park5. BL31 initializes RMM 57*54fd6939SJiyong Park6. BL31 transfers control to Normal-world software 58*54fd6939SJiyong Park 59*54fd6939SJiyong ParkGranule Protection Tables (GPT) library 60*54fd6939SJiyong Park***************************************** 61*54fd6939SJiyong ParkIsolation between the four physical address spaces is enforced by a process 62*54fd6939SJiyong Parkcalled Granule Protection Check (GPC) performed by the MMU downstream any 63*54fd6939SJiyong Parkaddress translation. GPC makes use of Granule Protection Table (GPT) in the 64*54fd6939SJiyong ParkRoot world that describes the physical address space assignment of every 65*54fd6939SJiyong Parkpage (granule). A GPT library that provides APIs to initialize GPTs and to 66*54fd6939SJiyong Parktransition granules between different physical address spaces has been added. 67*54fd6939SJiyong ParkMore information about the GPT library can be found in the 68*54fd6939SJiyong Park:ref:`Granule Protection Tables Library` chapter. 69*54fd6939SJiyong Park 70*54fd6939SJiyong ParkRMM Dispatcher (RMMD) 71*54fd6939SJiyong Park************************ 72*54fd6939SJiyong ParkRMMD is a new standard runtime service that handles the switch to the Realm 73*54fd6939SJiyong Parkworld. It initializes the RMM and handles Realm Management Interface (RMI) 74*54fd6939SJiyong ParkSMC calls from Non-secure and Realm worlds. 75*54fd6939SJiyong Park 76*54fd6939SJiyong ParkTest Realm Payload (TRP) 77*54fd6939SJiyong Park************************* 78*54fd6939SJiyong ParkTRP is a small test payload that runs at R-EL2 and implements a subset of 79*54fd6939SJiyong Parkthe Realm Management Interface (RMI) commands to primarily test EL3 firmware 80*54fd6939SJiyong Parkand the interface between R-EL2 and EL3. When building TF-A with RME enabled, 81*54fd6939SJiyong Parkif a path to an RMM image is not provided, TF-A builds the TRP by default 82*54fd6939SJiyong Parkand uses it as RMM image. 83*54fd6939SJiyong Park 84*54fd6939SJiyong ParkBuilding and running TF-A with RME 85*54fd6939SJiyong Park------------------------------------ 86*54fd6939SJiyong Park 87*54fd6939SJiyong ParkThis section describes how you can build and run TF-A with RME enabled. 88*54fd6939SJiyong ParkWe assume you have all the :ref:`Prerequisites` to build TF-A. 89*54fd6939SJiyong Park 90*54fd6939SJiyong ParkTo enable RME, you need to set the ENABLE_RME build flag when building 91*54fd6939SJiyong ParkTF-A. Currently, this feature is only supported for the FVP platform. 92*54fd6939SJiyong Park 93*54fd6939SJiyong ParkThe following instructions show you how to build and run TF-A with RME 94*54fd6939SJiyong Parkfor two scenarios: TF-A with TF-A Tests, and four-world execution with 95*54fd6939SJiyong ParkHafnium and TF-A Tests. The instructions assume you have already obtained 96*54fd6939SJiyong ParkTF-A. You can use the following command to clone TF-A. 97*54fd6939SJiyong Park 98*54fd6939SJiyong Park.. code:: shell 99*54fd6939SJiyong Park 100*54fd6939SJiyong Park git clone https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git 101*54fd6939SJiyong Park 102*54fd6939SJiyong ParkTo run the tests, you need an FVP model. Please use the :ref:`latest version 103*54fd6939SJiyong Park<Arm Fixed Virtual Platforms (FVP)>` of *FVP_Base_RevC-2xAEMvA* model. 104*54fd6939SJiyong Park 105*54fd6939SJiyong Park.. note:: 106*54fd6939SJiyong Park 107*54fd6939SJiyong Park ENABLE_RME build option is currently experimental. 108*54fd6939SJiyong Park 109*54fd6939SJiyong ParkBuilding TF-A with TF-A Tests 110*54fd6939SJiyong Park******************************************** 111*54fd6939SJiyong ParkUse the following instructions to build TF-A with `TF-A Tests`_ as the 112*54fd6939SJiyong Parknon-secure payload (BL33). 113*54fd6939SJiyong Park 114*54fd6939SJiyong Park**1. Obtain and build TF-A Tests** 115*54fd6939SJiyong Park 116*54fd6939SJiyong Park.. code:: shell 117*54fd6939SJiyong Park 118*54fd6939SJiyong Park git clone https://git.trustedfirmware.org/TF-A/tf-a-tests.git 119*54fd6939SJiyong Park cd tf-a-tests 120*54fd6939SJiyong Park make CROSS_COMPILE=aarch64-none-elf- PLAT=fvp DEBUG=1 121*54fd6939SJiyong Park 122*54fd6939SJiyong ParkThis produces a TF-A Tests binary (*tftf.bin*) in the *build/fvp/debug* directory. 123*54fd6939SJiyong Park 124*54fd6939SJiyong Park**2. Build TF-A** 125*54fd6939SJiyong Park 126*54fd6939SJiyong Park.. code:: shell 127*54fd6939SJiyong Park 128*54fd6939SJiyong Park cd trusted-firmware-a 129*54fd6939SJiyong Park make CROSS_COMPILE=aarch64-none-elf- \ 130*54fd6939SJiyong Park PLAT=fvp \ 131*54fd6939SJiyong Park ENABLE_RME=1 \ 132*54fd6939SJiyong Park FVP_HW_CONFIG_DTS=fdts/fvp-base-gicv3-psci-1t.dts \ 133*54fd6939SJiyong Park DEBUG=1 \ 134*54fd6939SJiyong Park BL33=<path/to/tftf.bin> \ 135*54fd6939SJiyong Park all fip 136*54fd6939SJiyong Park 137*54fd6939SJiyong ParkThis produces *bl1.bin* and *fip.bin* binaries in the *build/fvp/debug* directory. 138*54fd6939SJiyong ParkThe above command also builds TRP. The TRP binary is packaged in *fip.bin*. 139*54fd6939SJiyong Park 140*54fd6939SJiyong ParkFour-world execution with Hafnium and TF-A Tests 141*54fd6939SJiyong Park**************************************************** 142*54fd6939SJiyong ParkFour-world execution involves software components at each security state: root, 143*54fd6939SJiyong Parksecure, realm and non-secure. This section describes how to build TF-A 144*54fd6939SJiyong Parkwith four-world support. We use TF-A as the root firmware, `Hafnium`_ as the 145*54fd6939SJiyong Parksecure component, TRP as the realm-world firmware and TF-A Tests as the 146*54fd6939SJiyong Parknon-secure payload. 147*54fd6939SJiyong Park 148*54fd6939SJiyong ParkBefore building TF-A, you first need to build the other software components. 149*54fd6939SJiyong ParkYou can find instructions on how to get and build TF-A Tests above. 150*54fd6939SJiyong Park 151*54fd6939SJiyong Park**1. Obtain and build Hafnium** 152*54fd6939SJiyong Park 153*54fd6939SJiyong Park.. code:: shell 154*54fd6939SJiyong Park 155*54fd6939SJiyong Park git clone --recurse-submodules https://git.trustedfirmware.org/hafnium/hafnium.git 156*54fd6939SJiyong Park cd hafnium 157*54fd6939SJiyong Park make PROJECT=reference 158*54fd6939SJiyong Park 159*54fd6939SJiyong ParkThe Hafnium binary should be located at 160*54fd6939SJiyong Park*out/reference/secure_aem_v8a_fvp_clang/hafnium.bin* 161*54fd6939SJiyong Park 162*54fd6939SJiyong Park**2. Build TF-A** 163*54fd6939SJiyong Park 164*54fd6939SJiyong ParkBuild TF-A with RME as well as SPM enabled. 165*54fd6939SJiyong Park 166*54fd6939SJiyong Park.. code:: shell 167*54fd6939SJiyong Park 168*54fd6939SJiyong Park make CROSS_COMPILE=aarch64-none-elf- \ 169*54fd6939SJiyong Park PLAT=fvp \ 170*54fd6939SJiyong Park ENABLE_RME=1 \ 171*54fd6939SJiyong Park FVP_HW_CONFIG_DTS=fdts/fvp-base-gicv3-psci-1t.dts \ 172*54fd6939SJiyong Park SPD=spmd \ 173*54fd6939SJiyong Park SPMD_SPM_AT_SEL2=1 \ 174*54fd6939SJiyong Park BRANCH_PROTECTION=1 \ 175*54fd6939SJiyong Park CTX_INCLUDE_PAUTH_REGS=1 \ 176*54fd6939SJiyong Park DEBUG=1 \ 177*54fd6939SJiyong Park SP_LAYOUT_FILE=<path/to/tf-a-tests>/build/fvp/debug/sp_layout.json> \ 178*54fd6939SJiyong Park BL32=<path/to/hafnium.bin> \ 179*54fd6939SJiyong Park BL33=<path/to/tftf.bin> \ 180*54fd6939SJiyong Park all fip 181*54fd6939SJiyong Park 182*54fd6939SJiyong ParkRunning the tests 183*54fd6939SJiyong Park********************* 184*54fd6939SJiyong ParkUse the following command to run the tests on FVP. TF-A Tests should boot 185*54fd6939SJiyong Parkand run the default tests including RME tests. 186*54fd6939SJiyong Park 187*54fd6939SJiyong Park.. code:: shell 188*54fd6939SJiyong Park 189*54fd6939SJiyong Park FVP_Base_RevC-2xAEMvA \ 190*54fd6939SJiyong Park -C bp.flashloader0.fname=<path/to/fip.bin> \ 191*54fd6939SJiyong Park -C bp.secureflashloader.fname=<path/to/bl1.bin> \ 192*54fd6939SJiyong Park -C bp.refcounter.non_arch_start_at_default=1 \ 193*54fd6939SJiyong Park -C bp.refcounter.use_real_time=0 \ 194*54fd6939SJiyong Park -C bp.ve_sysregs.exit_on_shutdown=1 \ 195*54fd6939SJiyong Park -C cache_state_modelled=1 \ 196*54fd6939SJiyong Park -C cluster0.NUM_CORES=4 \ 197*54fd6939SJiyong Park -C cluster0.PA_SIZE=48 \ 198*54fd6939SJiyong Park -C cluster0.ecv_support_level=2 \ 199*54fd6939SJiyong Park -C cluster0.gicv3.cpuintf-mmap-access-level=2 \ 200*54fd6939SJiyong Park -C cluster0.gicv3.without-DS-support=1 \ 201*54fd6939SJiyong Park -C cluster0.gicv4.mask-virtual-interrupt=1 \ 202*54fd6939SJiyong Park -C cluster0.has_arm_v8-6=1 \ 203*54fd6939SJiyong Park -C cluster0.has_branch_target_exception=1 \ 204*54fd6939SJiyong Park -C cluster0.has_rme=1 \ 205*54fd6939SJiyong Park -C cluster0.has_rndr=1 \ 206*54fd6939SJiyong Park -C cluster0.has_amu=1 \ 207*54fd6939SJiyong Park -C cluster0.has_v8_7_pmu_extension=2 \ 208*54fd6939SJiyong Park -C cluster0.max_32bit_el=-1 \ 209*54fd6939SJiyong Park -C cluster0.restriction_on_speculative_execution=2 \ 210*54fd6939SJiyong Park -C cluster0.restriction_on_speculative_execution_aarch32=2 \ 211*54fd6939SJiyong Park -C cluster1.NUM_CORES=4 \ 212*54fd6939SJiyong Park -C cluster1.PA_SIZE=48 \ 213*54fd6939SJiyong Park -C cluster1.ecv_support_level=2 \ 214*54fd6939SJiyong Park -C cluster1.gicv3.cpuintf-mmap-access-level=2 \ 215*54fd6939SJiyong Park -C cluster1.gicv3.without-DS-support=1 \ 216*54fd6939SJiyong Park -C cluster1.gicv4.mask-virtual-interrupt=1 \ 217*54fd6939SJiyong Park -C cluster1.has_arm_v8-6=1 \ 218*54fd6939SJiyong Park -C cluster1.has_branch_target_exception=1 \ 219*54fd6939SJiyong Park -C cluster1.has_rme=1 \ 220*54fd6939SJiyong Park -C cluster1.has_rndr=1 \ 221*54fd6939SJiyong Park -C cluster1.has_amu=1 \ 222*54fd6939SJiyong Park -C cluster1.has_v8_7_pmu_extension=2 \ 223*54fd6939SJiyong Park -C cluster1.max_32bit_el=-1 \ 224*54fd6939SJiyong Park -C cluster1.restriction_on_speculative_execution=2 \ 225*54fd6939SJiyong Park -C cluster1.restriction_on_speculative_execution_aarch32=2 \ 226*54fd6939SJiyong Park -C pci.pci_smmuv3.mmu.SMMU_AIDR=2 \ 227*54fd6939SJiyong Park -C pci.pci_smmuv3.mmu.SMMU_IDR0=0x0046123B \ 228*54fd6939SJiyong Park -C pci.pci_smmuv3.mmu.SMMU_IDR1=0x00600002 \ 229*54fd6939SJiyong Park -C pci.pci_smmuv3.mmu.SMMU_IDR3=0x1714 \ 230*54fd6939SJiyong Park -C pci.pci_smmuv3.mmu.SMMU_IDR5=0xFFFF0475 \ 231*54fd6939SJiyong Park -C pci.pci_smmuv3.mmu.SMMU_S_IDR1=0xA0000002 \ 232*54fd6939SJiyong Park -C pci.pci_smmuv3.mmu.SMMU_S_IDR2=0 \ 233*54fd6939SJiyong Park -C pci.pci_smmuv3.mmu.SMMU_S_IDR3=0 \ 234*54fd6939SJiyong Park -C bp.pl011_uart0.out_file=uart0.log \ 235*54fd6939SJiyong Park -C bp.pl011_uart1.out_file=uart1.log \ 236*54fd6939SJiyong Park -C bp.pl011_uart2.out_file=uart2.log \ 237*54fd6939SJiyong Park -C pctl.startup=0.0.0.0 \ 238*54fd6939SJiyong Park -Q 1000 \ 239*54fd6939SJiyong Park "$@" 240*54fd6939SJiyong Park 241*54fd6939SJiyong ParkThe bottom of the output from *uart0* should look something like the following. 242*54fd6939SJiyong Park 243*54fd6939SJiyong Park.. code-block:: shell 244*54fd6939SJiyong Park 245*54fd6939SJiyong Park ... 246*54fd6939SJiyong Park 247*54fd6939SJiyong Park > Test suite 'FF-A Interrupt' 248*54fd6939SJiyong Park Passed 249*54fd6939SJiyong Park > Test suite 'SMMUv3 tests' 250*54fd6939SJiyong Park Passed 251*54fd6939SJiyong Park > Test suite 'PMU Leakage' 252*54fd6939SJiyong Park Passed 253*54fd6939SJiyong Park > Test suite 'DebugFS' 254*54fd6939SJiyong Park Passed 255*54fd6939SJiyong Park > Test suite 'Realm payload tests' 256*54fd6939SJiyong Park Passed 257*54fd6939SJiyong Park ... 258*54fd6939SJiyong Park 259*54fd6939SJiyong Park 260*54fd6939SJiyong Park.. _Arm Confidential Compute Architecture (Arm CCA): https://www.arm.com/why-arm/architecture/security-features/arm-confidential-compute-architecture 261*54fd6939SJiyong Park.. _Arm Architecture Models website: https://developer.arm.com/tools-and-software/simulation-models/fixed-virtual-platforms/arm-ecosystem-models 262*54fd6939SJiyong Park.. _TF-A Tests: https://trustedfirmware-a-tests.readthedocs.io/en/latest 263*54fd6939SJiyong Park.. _Hafnium: https://www.trustedfirmware.org/projects/hafnium 264