13cfa3497SZelalem Aweke 23cfa3497SZelalem AwekeRealm Management Extension (RME) 33cfa3497SZelalem Aweke==================================== 43cfa3497SZelalem Aweke 53cfa3497SZelalem AwekeFEAT_RME (or RME for short) is an Armv9-A extension and is one component of the 63cfa3497SZelalem Aweke`Arm Confidential Compute Architecture (Arm CCA)`_. TF-A supports RME starting 77446c266SZelalem Awekefrom version 2.6. This chapter discusses the changes to TF-A to support RME and 87446c266SZelalem Awekeprovides instructions on how to build and run TF-A with RME. 97446c266SZelalem Aweke 107446c266SZelalem AwekeRME support in TF-A 117446c266SZelalem Aweke--------------------- 127446c266SZelalem Aweke 137446c266SZelalem AwekeThe following diagram shows an Arm CCA software architecture with TF-A as the 147446c266SZelalem AwekeEL3 firmware. In the Arm CCA architecture there are two additional security 157446c266SZelalem Awekestates and address spaces: ``Root`` and ``Realm``. TF-A firmware runs in the 167446c266SZelalem AwekeRoot world. In the realm world, a Realm Management Monitor firmware (RMM) 177446c266SZelalem Awekemanages the execution of Realm VMs and their interaction with the hypervisor. 187446c266SZelalem Aweke 197446c266SZelalem Aweke.. image:: ../resources/diagrams/arm-cca-software-arch.png 207446c266SZelalem Aweke 217446c266SZelalem AwekeRME is the hardware extension to support Arm CCA. To support RME, various 227446c266SZelalem Awekechanges have been introduced to TF-A. We discuss those changes below. 237446c266SZelalem Aweke 247446c266SZelalem AwekeChanges to translation tables library 257446c266SZelalem Aweke*************************************** 267446c266SZelalem AwekeRME adds Root and Realm Physical address spaces. To support this, two new 277446c266SZelalem Awekememory type macros, ``MT_ROOT`` and ``MT_REALM``, have been added to the 287446c266SZelalem Aweke:ref:`Translation (XLAT) Tables Library`. These macros are used to configure 297446c266SZelalem Awekememory regions as Root or Realm respectively. 307446c266SZelalem Aweke 317446c266SZelalem Aweke.. note:: 327446c266SZelalem Aweke 337446c266SZelalem Aweke Only version 2 of the translation tables library supports the new memory 347446c266SZelalem Aweke types. 357446c266SZelalem Aweke 367446c266SZelalem AwekeChanges to context management 377446c266SZelalem Aweke******************************* 387446c266SZelalem AwekeA new CPU context for the Realm world has been added. The existing 397446c266SZelalem Aweke:ref:`CPU context management API<PSCI Library Integration guide for Armv8-A 407446c266SZelalem AwekeAArch32 systems>` can be used to manage Realm context. 417446c266SZelalem Aweke 427446c266SZelalem AwekeBoot flow changes 437446c266SZelalem Aweke******************* 447446c266SZelalem AwekeIn a typical TF-A boot flow, BL2 runs at Secure-EL1. However when RME is 457446c266SZelalem Awekeenabled, TF-A runs in the Root world at EL3. Therefore, the boot flow is 467446c266SZelalem Awekemodified to run BL2 at EL3 when RME is enabled. In addition to this, a 477446c266SZelalem AwekeRealm-world firmware (RMM) is loaded by BL2 in the Realm physical address 487446c266SZelalem Awekespace. 497446c266SZelalem Aweke 507446c266SZelalem AwekeThe boot flow when RME is enabled looks like the following: 517446c266SZelalem Aweke 527446c266SZelalem Aweke1. BL1 loads and executes BL2 at EL3 537446c266SZelalem Aweke2. BL2 loads images including RMM 547446c266SZelalem Aweke3. BL2 transfers control to BL31 557446c266SZelalem Aweke4. BL31 initializes SPM (if SPM is enabled) 567446c266SZelalem Aweke5. BL31 initializes RMM 577446c266SZelalem Aweke6. BL31 transfers control to Normal-world software 587446c266SZelalem Aweke 597446c266SZelalem AwekeGranule Protection Tables (GPT) library 607446c266SZelalem Aweke***************************************** 617446c266SZelalem AwekeIsolation between the four physical address spaces is enforced by a process 627446c266SZelalem Awekecalled Granule Protection Check (GPC) performed by the MMU downstream any 637446c266SZelalem Awekeaddress translation. GPC makes use of Granule Protection Table (GPT) in the 647446c266SZelalem AwekeRoot world that describes the physical address space assignment of every 657446c266SZelalem Awekepage (granule). A GPT library that provides APIs to initialize GPTs and to 667446c266SZelalem Aweketransition granules between different physical address spaces has been added. 677446c266SZelalem AwekeMore information about the GPT library can be found in the 687446c266SZelalem Aweke:ref:`Granule Protection Tables Library` chapter. 697446c266SZelalem Aweke 707446c266SZelalem AwekeRMM Dispatcher (RMMD) 717446c266SZelalem Aweke************************ 727446c266SZelalem AwekeRMMD is a new standard runtime service that handles the switch to the Realm 737446c266SZelalem Awekeworld. It initializes the RMM and handles Realm Management Interface (RMI) 747446c266SZelalem AwekeSMC calls from Non-secure and Realm worlds. 757446c266SZelalem Aweke 76*69447290SJavier Almansa SobrinoThere is a contract between RMM and RMMD that defines the arguments that the 77*69447290SJavier Almansa Sobrinoformer needs to take in order to initialize and also the possible return values. 78*69447290SJavier Almansa SobrinoThis contract is defined in the RMM Boot Interface, which can be found at 79*69447290SJavier Almansa Sobrino:ref:`rmm_el3_boot_interface`. 80*69447290SJavier Almansa Sobrino 81*69447290SJavier Almansa SobrinoThere is also a specification of the runtime services provided by TF-A 82*69447290SJavier Almansa Sobrinoto RMM. This can be found at :ref:`runtime_services_and_interface`. 83*69447290SJavier Almansa Sobrino 847446c266SZelalem AwekeTest Realm Payload (TRP) 857446c266SZelalem Aweke************************* 867446c266SZelalem AwekeTRP is a small test payload that runs at R-EL2 and implements a subset of 877446c266SZelalem Awekethe Realm Management Interface (RMI) commands to primarily test EL3 firmware 887446c266SZelalem Awekeand the interface between R-EL2 and EL3. When building TF-A with RME enabled, 897446c266SZelalem Awekeif a path to an RMM image is not provided, TF-A builds the TRP by default 907446c266SZelalem Awekeand uses it as RMM image. 913cfa3497SZelalem Aweke 923cfa3497SZelalem AwekeBuilding and running TF-A with RME 933cfa3497SZelalem Aweke------------------------------------ 943cfa3497SZelalem Aweke 953cfa3497SZelalem AwekeThis section describes how you can build and run TF-A with RME enabled. 963cfa3497SZelalem AwekeWe assume you have all the :ref:`Prerequisites` to build TF-A. 973cfa3497SZelalem Aweke 983cfa3497SZelalem AwekeTo enable RME, you need to set the ENABLE_RME build flag when building 993cfa3497SZelalem AwekeTF-A. Currently, this feature is only supported for the FVP platform. 1003cfa3497SZelalem Aweke 1013cfa3497SZelalem AwekeThe following instructions show you how to build and run TF-A with RME 1023cfa3497SZelalem Awekefor two scenarios: TF-A with TF-A Tests, and four-world execution with 1033cfa3497SZelalem AwekeHafnium and TF-A Tests. The instructions assume you have already obtained 1043cfa3497SZelalem AwekeTF-A. You can use the following command to clone TF-A. 1053cfa3497SZelalem Aweke 1063cfa3497SZelalem Aweke.. code:: shell 1073cfa3497SZelalem Aweke 1083cfa3497SZelalem Aweke git clone https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git 1093cfa3497SZelalem Aweke 1107446c266SZelalem AwekeTo run the tests, you need an FVP model. Please use the :ref:`latest version 1117446c266SZelalem Aweke<Arm Fixed Virtual Platforms (FVP)>` of *FVP_Base_RevC-2xAEMvA* model. 1123cfa3497SZelalem Aweke 1133cfa3497SZelalem Aweke.. note:: 1143cfa3497SZelalem Aweke 1153cfa3497SZelalem Aweke ENABLE_RME build option is currently experimental. 1163cfa3497SZelalem Aweke 1173cfa3497SZelalem AwekeBuilding TF-A with TF-A Tests 1183cfa3497SZelalem Aweke******************************************** 1193cfa3497SZelalem AwekeUse the following instructions to build TF-A with `TF-A Tests`_ as the 1203cfa3497SZelalem Awekenon-secure payload (BL33). 1213cfa3497SZelalem Aweke 1223cfa3497SZelalem Aweke**1. Obtain and build TF-A Tests** 1233cfa3497SZelalem Aweke 1243cfa3497SZelalem Aweke.. code:: shell 1253cfa3497SZelalem Aweke 1263cfa3497SZelalem Aweke git clone https://git.trustedfirmware.org/TF-A/tf-a-tests.git 1273cfa3497SZelalem Aweke cd tf-a-tests 1283cfa3497SZelalem Aweke make CROSS_COMPILE=aarch64-none-elf- PLAT=fvp DEBUG=1 1293cfa3497SZelalem Aweke 1303cfa3497SZelalem AwekeThis produces a TF-A Tests binary (*tftf.bin*) in the *build/fvp/debug* directory. 1313cfa3497SZelalem Aweke 1323cfa3497SZelalem Aweke**2. Build TF-A** 1333cfa3497SZelalem Aweke 1343cfa3497SZelalem Aweke.. code:: shell 1353cfa3497SZelalem Aweke 1363cfa3497SZelalem Aweke cd trusted-firmware-a 1373cfa3497SZelalem Aweke make CROSS_COMPILE=aarch64-none-elf- \ 1383cfa3497SZelalem Aweke PLAT=fvp \ 1393cfa3497SZelalem Aweke ENABLE_RME=1 \ 1403cfa3497SZelalem Aweke FVP_HW_CONFIG_DTS=fdts/fvp-base-gicv3-psci-1t.dts \ 1413cfa3497SZelalem Aweke DEBUG=1 \ 1423cfa3497SZelalem Aweke BL33=<path/to/tftf.bin> \ 1433cfa3497SZelalem Aweke all fip 1443cfa3497SZelalem Aweke 1453cfa3497SZelalem AwekeThis produces *bl1.bin* and *fip.bin* binaries in the *build/fvp/debug* directory. 1467446c266SZelalem AwekeThe above command also builds TRP. The TRP binary is packaged in *fip.bin*. 1473cfa3497SZelalem Aweke 1483cfa3497SZelalem AwekeFour-world execution with Hafnium and TF-A Tests 1493cfa3497SZelalem Aweke**************************************************** 1503cfa3497SZelalem AwekeFour-world execution involves software components at each security state: root, 1513cfa3497SZelalem Awekesecure, realm and non-secure. This section describes how to build TF-A 1523cfa3497SZelalem Awekewith four-world support. We use TF-A as the root firmware, `Hafnium`_ as the 1533cfa3497SZelalem Awekesecure component, TRP as the realm-world firmware and TF-A Tests as the 1543cfa3497SZelalem Awekenon-secure payload. 1553cfa3497SZelalem Aweke 1563cfa3497SZelalem AwekeBefore building TF-A, you first need to build the other software components. 1573cfa3497SZelalem AwekeYou can find instructions on how to get and build TF-A Tests above. 1583cfa3497SZelalem Aweke 1593cfa3497SZelalem Aweke**1. Obtain and build Hafnium** 1603cfa3497SZelalem Aweke 1613cfa3497SZelalem Aweke.. code:: shell 1623cfa3497SZelalem Aweke 1633cfa3497SZelalem Aweke git clone --recurse-submodules https://git.trustedfirmware.org/hafnium/hafnium.git 1643cfa3497SZelalem Aweke cd hafnium 1651dd4bafbSManish Pandey # Use the default prebuilt LLVM/clang toolchain 1661dd4bafbSManish Pandey PATH=$PWD/prebuilts/linux-x64/clang/bin:$PWD/prebuilts/linux-x64/dtc:$PATH 1673cfa3497SZelalem Aweke make PROJECT=reference 1683cfa3497SZelalem Aweke 1693cfa3497SZelalem AwekeThe Hafnium binary should be located at 1703cfa3497SZelalem Aweke*out/reference/secure_aem_v8a_fvp_clang/hafnium.bin* 1713cfa3497SZelalem Aweke 1723cfa3497SZelalem Aweke**2. Build TF-A** 1733cfa3497SZelalem Aweke 1743cfa3497SZelalem AwekeBuild TF-A with RME as well as SPM enabled. 1753cfa3497SZelalem Aweke 1763cfa3497SZelalem Aweke.. code:: shell 1773cfa3497SZelalem Aweke 1783cfa3497SZelalem Aweke make CROSS_COMPILE=aarch64-none-elf- \ 1793cfa3497SZelalem Aweke PLAT=fvp \ 1803cfa3497SZelalem Aweke ENABLE_RME=1 \ 1813cfa3497SZelalem Aweke FVP_HW_CONFIG_DTS=fdts/fvp-base-gicv3-psci-1t.dts \ 1823cfa3497SZelalem Aweke SPD=spmd \ 1833cfa3497SZelalem Aweke SPMD_SPM_AT_SEL2=1 \ 1843cfa3497SZelalem Aweke BRANCH_PROTECTION=1 \ 1853cfa3497SZelalem Aweke CTX_INCLUDE_PAUTH_REGS=1 \ 1863cfa3497SZelalem Aweke DEBUG=1 \ 1873cfa3497SZelalem Aweke SP_LAYOUT_FILE=<path/to/tf-a-tests>/build/fvp/debug/sp_layout.json> \ 1883cfa3497SZelalem Aweke BL32=<path/to/hafnium.bin> \ 1893cfa3497SZelalem Aweke BL33=<path/to/tftf.bin> \ 1903cfa3497SZelalem Aweke all fip 1913cfa3497SZelalem Aweke 1923cfa3497SZelalem AwekeRunning the tests 1933cfa3497SZelalem Aweke********************* 1943cfa3497SZelalem AwekeUse the following command to run the tests on FVP. TF-A Tests should boot 1953cfa3497SZelalem Awekeand run the default tests including RME tests. 1963cfa3497SZelalem Aweke 1973cfa3497SZelalem Aweke.. code:: shell 1983cfa3497SZelalem Aweke 1993cfa3497SZelalem Aweke FVP_Base_RevC-2xAEMvA \ 2003cfa3497SZelalem Aweke -C bp.flashloader0.fname=<path/to/fip.bin> \ 2013cfa3497SZelalem Aweke -C bp.secureflashloader.fname=<path/to/bl1.bin> \ 2023cfa3497SZelalem Aweke -C bp.refcounter.non_arch_start_at_default=1 \ 2033cfa3497SZelalem Aweke -C bp.refcounter.use_real_time=0 \ 2043cfa3497SZelalem Aweke -C bp.ve_sysregs.exit_on_shutdown=1 \ 2053cfa3497SZelalem Aweke -C cache_state_modelled=1 \ 2063cfa3497SZelalem Aweke -C cluster0.NUM_CORES=4 \ 2073cfa3497SZelalem Aweke -C cluster0.PA_SIZE=48 \ 2083cfa3497SZelalem Aweke -C cluster0.ecv_support_level=2 \ 2093cfa3497SZelalem Aweke -C cluster0.gicv3.cpuintf-mmap-access-level=2 \ 2103cfa3497SZelalem Aweke -C cluster0.gicv3.without-DS-support=1 \ 2113cfa3497SZelalem Aweke -C cluster0.gicv4.mask-virtual-interrupt=1 \ 2123cfa3497SZelalem Aweke -C cluster0.has_arm_v8-6=1 \ 2133cfa3497SZelalem Aweke -C cluster0.has_branch_target_exception=1 \ 2143cfa3497SZelalem Aweke -C cluster0.has_rme=1 \ 2153cfa3497SZelalem Aweke -C cluster0.has_rndr=1 \ 2163cfa3497SZelalem Aweke -C cluster0.has_amu=1 \ 2173cfa3497SZelalem Aweke -C cluster0.has_v8_7_pmu_extension=2 \ 2183cfa3497SZelalem Aweke -C cluster0.max_32bit_el=-1 \ 2193cfa3497SZelalem Aweke -C cluster0.restriction_on_speculative_execution=2 \ 2203cfa3497SZelalem Aweke -C cluster0.restriction_on_speculative_execution_aarch32=2 \ 2213cfa3497SZelalem Aweke -C cluster1.NUM_CORES=4 \ 2223cfa3497SZelalem Aweke -C cluster1.PA_SIZE=48 \ 2233cfa3497SZelalem Aweke -C cluster1.ecv_support_level=2 \ 2243cfa3497SZelalem Aweke -C cluster1.gicv3.cpuintf-mmap-access-level=2 \ 2253cfa3497SZelalem Aweke -C cluster1.gicv3.without-DS-support=1 \ 2263cfa3497SZelalem Aweke -C cluster1.gicv4.mask-virtual-interrupt=1 \ 2273cfa3497SZelalem Aweke -C cluster1.has_arm_v8-6=1 \ 2283cfa3497SZelalem Aweke -C cluster1.has_branch_target_exception=1 \ 2293cfa3497SZelalem Aweke -C cluster1.has_rme=1 \ 2303cfa3497SZelalem Aweke -C cluster1.has_rndr=1 \ 2313cfa3497SZelalem Aweke -C cluster1.has_amu=1 \ 2323cfa3497SZelalem Aweke -C cluster1.has_v8_7_pmu_extension=2 \ 2333cfa3497SZelalem Aweke -C cluster1.max_32bit_el=-1 \ 2343cfa3497SZelalem Aweke -C cluster1.restriction_on_speculative_execution=2 \ 2353cfa3497SZelalem Aweke -C cluster1.restriction_on_speculative_execution_aarch32=2 \ 2363cfa3497SZelalem Aweke -C pci.pci_smmuv3.mmu.SMMU_AIDR=2 \ 2373cfa3497SZelalem Aweke -C pci.pci_smmuv3.mmu.SMMU_IDR0=0x0046123B \ 2383cfa3497SZelalem Aweke -C pci.pci_smmuv3.mmu.SMMU_IDR1=0x00600002 \ 2393cfa3497SZelalem Aweke -C pci.pci_smmuv3.mmu.SMMU_IDR3=0x1714 \ 2403cfa3497SZelalem Aweke -C pci.pci_smmuv3.mmu.SMMU_IDR5=0xFFFF0475 \ 2413cfa3497SZelalem Aweke -C pci.pci_smmuv3.mmu.SMMU_S_IDR1=0xA0000002 \ 2423cfa3497SZelalem Aweke -C pci.pci_smmuv3.mmu.SMMU_S_IDR2=0 \ 2433cfa3497SZelalem Aweke -C pci.pci_smmuv3.mmu.SMMU_S_IDR3=0 \ 2443cfa3497SZelalem Aweke -C bp.pl011_uart0.out_file=uart0.log \ 2453cfa3497SZelalem Aweke -C bp.pl011_uart1.out_file=uart1.log \ 2463cfa3497SZelalem Aweke -C bp.pl011_uart2.out_file=uart2.log \ 2473cfa3497SZelalem Aweke -C pctl.startup=0.0.0.0 \ 2483cfa3497SZelalem Aweke -Q 1000 \ 2493cfa3497SZelalem Aweke "$@" 2503cfa3497SZelalem Aweke 2513cfa3497SZelalem AwekeThe bottom of the output from *uart0* should look something like the following. 2523cfa3497SZelalem Aweke 2533cfa3497SZelalem Aweke.. code-block:: shell 2543cfa3497SZelalem Aweke 2553cfa3497SZelalem Aweke ... 2563cfa3497SZelalem Aweke 2573cfa3497SZelalem Aweke > Test suite 'FF-A Interrupt' 2583cfa3497SZelalem Aweke Passed 2593cfa3497SZelalem Aweke > Test suite 'SMMUv3 tests' 2603cfa3497SZelalem Aweke Passed 2613cfa3497SZelalem Aweke > Test suite 'PMU Leakage' 2623cfa3497SZelalem Aweke Passed 2633cfa3497SZelalem Aweke > Test suite 'DebugFS' 2643cfa3497SZelalem Aweke Passed 2653cfa3497SZelalem Aweke > Test suite 'Realm payload tests' 2663cfa3497SZelalem Aweke Passed 2671dd4bafbSManish Pandey > Test suite 'Invalid memory access' 2681dd4bafbSManish Pandey Passed 2693cfa3497SZelalem Aweke ... 2703cfa3497SZelalem Aweke 2713cfa3497SZelalem Aweke 2723cfa3497SZelalem Aweke.. _Arm Confidential Compute Architecture (Arm CCA): https://www.arm.com/why-arm/architecture/security-features/arm-confidential-compute-architecture 2733cfa3497SZelalem Aweke.. _Arm Architecture Models website: https://developer.arm.com/tools-and-software/simulation-models/fixed-virtual-platforms/arm-ecosystem-models 2743cfa3497SZelalem Aweke.. _TF-A Tests: https://trustedfirmware-a-tests.readthedocs.io/en/latest 2753cfa3497SZelalem Aweke.. _Hafnium: https://www.trustedfirmware.org/projects/hafnium 276