Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 1 | Trusted Firmware-A design |
| 2 | ========================= |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 3 | |
| 4 | |
| 5 | .. section-numbering:: |
| 6 | :suffix: . |
| 7 | |
| 8 | .. contents:: |
| 9 | |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 10 | Trusted Firmware-A (TF-A) implements a subset of the Trusted Board Boot |
| 11 | Requirements (TBBR) Platform Design Document (PDD) [1]_ for Arm reference |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 12 | platforms. The TBB sequence starts when the platform is powered on and runs up |
| 13 | to the stage where it hands-off control to firmware running in the normal |
| 14 | world in DRAM. This is the cold boot path. |
| 15 | |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 16 | TF-A also implements the Power State Coordination Interface PDD [2]_ as a |
| 17 | runtime service. PSCI is the interface from normal world software to firmware |
| 18 | implementing power management use-cases (for example, secondary CPU boot, |
| 19 | hotplug and idle). Normal world software can access TF-A runtime services via |
| 20 | the Arm SMC (Secure Monitor Call) instruction. The SMC instruction must be |
| 21 | used as mandated by the SMC Calling Convention [3]_. |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 22 | |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 23 | TF-A implements a framework for configuring and managing interrupts generated |
| 24 | in either security state. The details of the interrupt management framework |
| 25 | and its design can be found in TF-A Interrupt Management Design guide [4]_. |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 26 | |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 27 | TF-A also implements a library for setting up and managing the translation |
| 28 | tables. The details of this library can be found in `Xlat_tables design`_. |
Antonio Nino Diaz | b5d6809 | 2017-05-23 11:49:22 +0100 | [diff] [blame] | 29 | |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 30 | TF-A can be built to support either AArch64 or AArch32 execution state. |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 31 | |
| 32 | Cold boot |
| 33 | --------- |
| 34 | |
| 35 | The cold boot path starts when the platform is physically turned on. If |
| 36 | ``COLD_BOOT_SINGLE_CPU=0``, one of the CPUs released from reset is chosen as the |
| 37 | primary CPU, and the remaining CPUs are considered secondary CPUs. The primary |
| 38 | CPU is chosen through platform-specific means. The cold boot path is mainly |
| 39 | executed by the primary CPU, other than essential CPU initialization executed by |
| 40 | all CPUs. The secondary CPUs are kept in a safe platform-specific state until |
| 41 | the primary CPU has performed enough initialization to boot them. |
| 42 | |
| 43 | Refer to the `Reset Design`_ for more information on the effect of the |
| 44 | ``COLD_BOOT_SINGLE_CPU`` platform build option. |
| 45 | |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 46 | The cold boot path in this implementation of TF-A depends on the execution |
| 47 | state. For AArch64, it is divided into five steps (in order of execution): |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 48 | |
| 49 | - Boot Loader stage 1 (BL1) *AP Trusted ROM* |
| 50 | - Boot Loader stage 2 (BL2) *Trusted Boot Firmware* |
| 51 | - Boot Loader stage 3-1 (BL31) *EL3 Runtime Software* |
| 52 | - Boot Loader stage 3-2 (BL32) *Secure-EL1 Payload* (optional) |
| 53 | - Boot Loader stage 3-3 (BL33) *Non-trusted Firmware* |
| 54 | |
| 55 | For AArch32, it is divided into four steps (in order of execution): |
| 56 | |
| 57 | - Boot Loader stage 1 (BL1) *AP Trusted ROM* |
| 58 | - Boot Loader stage 2 (BL2) *Trusted Boot Firmware* |
| 59 | - Boot Loader stage 3-2 (BL32) *EL3 Runtime Software* |
| 60 | - Boot Loader stage 3-3 (BL33) *Non-trusted Firmware* |
| 61 | |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 62 | Arm development platforms (Fixed Virtual Platforms (FVPs) and Juno) implement a |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 63 | combination of the following types of memory regions. Each bootloader stage uses |
| 64 | one or more of these memory regions. |
| 65 | |
| 66 | - Regions accessible from both non-secure and secure states. For example, |
| 67 | non-trusted SRAM, ROM and DRAM. |
| 68 | - Regions accessible from only the secure state. For example, trusted SRAM and |
| 69 | ROM. The FVPs also implement the trusted DRAM which is statically |
| 70 | configured. Additionally, the Base FVPs and Juno development platform |
| 71 | configure the TrustZone Controller (TZC) to create a region in the DRAM |
| 72 | which is accessible only from the secure state. |
| 73 | |
| 74 | The sections below provide the following details: |
| 75 | |
Soby Mathew | b1bf044 | 2018-02-16 14:52:52 +0000 | [diff] [blame] | 76 | - dynamic configuration of Boot Loader stages |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 77 | - initialization and execution of the first three stages during cold boot |
| 78 | - specification of the EL3 Runtime Software (BL31 for AArch64 and BL32 for |
| 79 | AArch32) entrypoint requirements for use by alternative Trusted Boot |
| 80 | Firmware in place of the provided BL1 and BL2 |
| 81 | |
Soby Mathew | b1bf044 | 2018-02-16 14:52:52 +0000 | [diff] [blame] | 82 | Dynamic Configuration during cold boot |
| 83 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 84 | |
| 85 | Each of the Boot Loader stages may be dynamically configured if required by the |
| 86 | platform. The Boot Loader stage may optionally specify a firmware |
| 87 | configuration file and/or hardware configuration file as listed below: |
| 88 | |
| 89 | - HW_CONFIG - The hardware configuration file. Can be shared by all Boot Loader |
| 90 | stages and also by the Normal World Rich OS. |
| 91 | - TB_FW_CONFIG - Trusted Boot Firmware configuration file. Shared between BL1 |
| 92 | and BL2. |
| 93 | - SOC_FW_CONFIG - SoC Firmware configuration file. Used by BL31. |
| 94 | - TOS_FW_CONFIG - Trusted OS Firmware configuration file. Used by Trusted OS |
| 95 | (BL32). |
| 96 | - NT_FW_CONFIG - Non Trusted Firmware configuration file. Used by Non-trusted |
| 97 | firmware (BL33). |
| 98 | |
| 99 | The Arm development platforms use the Flattened Device Tree format for the |
| 100 | dynamic configuration files. |
| 101 | |
| 102 | Each Boot Loader stage can pass up to 4 arguments via registers to the next |
| 103 | stage. BL2 passes the list of the next images to execute to the *EL3 Runtime |
| 104 | Software* (BL31 for AArch64 and BL32 for AArch32) via `arg0`. All the other |
| 105 | arguments are platform defined. The Arm development platforms use the following |
| 106 | convention: |
| 107 | |
| 108 | - BL1 passes the address of a meminfo_t structure to BL2 via ``arg1``. This |
| 109 | structure contains the memory layout available to BL2. |
| 110 | - When dynamic configuration files are present, the firmware configuration for |
| 111 | the next Boot Loader stage is populated in the first available argument and |
| 112 | the generic hardware configuration is passed the next available argument. |
| 113 | For example, |
| 114 | |
| 115 | - If TB_FW_CONFIG is loaded by BL1, then its address is passed in ``arg0`` |
| 116 | to BL2. |
| 117 | - If HW_CONFIG is loaded by BL1, then its address is passed in ``arg2`` to |
| 118 | BL2. Note, ``arg1`` is already used for meminfo_t. |
| 119 | - If SOC_FW_CONFIG is loaded by BL2, then its address is passed in ``arg1`` |
| 120 | to BL31. Note, ``arg0`` is used to pass the list of executable images. |
| 121 | - Similarly, if HW_CONFIG is loaded by BL1 or BL2, then its address is |
| 122 | passed in ``arg2`` to BL31. |
| 123 | - For other BL3x images, if the firmware configuration file is loaded by |
| 124 | BL2, then its address is passed in ``arg0`` and if HW_CONFIG is loaded |
| 125 | then its address is passed in ``arg1``. |
| 126 | |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 127 | BL1 |
| 128 | ~~~ |
| 129 | |
| 130 | This stage begins execution from the platform's reset vector at EL3. The reset |
| 131 | address is platform dependent but it is usually located in a Trusted ROM area. |
| 132 | The BL1 data section is copied to trusted SRAM at runtime. |
| 133 | |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 134 | On the Arm development platforms, BL1 code starts execution from the reset |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 135 | vector defined by the constant ``BL1_RO_BASE``. The BL1 data section is copied |
| 136 | to the top of trusted SRAM as defined by the constant ``BL1_RW_BASE``. |
| 137 | |
| 138 | The functionality implemented by this stage is as follows. |
| 139 | |
| 140 | Determination of boot path |
| 141 | ^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 142 | |
| 143 | Whenever a CPU is released from reset, BL1 needs to distinguish between a warm |
| 144 | boot and a cold boot. This is done using platform-specific mechanisms (see the |
| 145 | ``plat_get_my_entrypoint()`` function in the `Porting Guide`_). In the case of a |
| 146 | warm boot, a CPU is expected to continue execution from a separate |
| 147 | entrypoint. In the case of a cold boot, the secondary CPUs are placed in a safe |
| 148 | platform-specific state (see the ``plat_secondary_cold_boot_setup()`` function in |
| 149 | the `Porting Guide`_) while the primary CPU executes the remaining cold boot path |
| 150 | as described in the following sections. |
| 151 | |
| 152 | This step only applies when ``PROGRAMMABLE_RESET_ADDRESS=0``. Refer to the |
| 153 | `Reset Design`_ for more information on the effect of the |
| 154 | ``PROGRAMMABLE_RESET_ADDRESS`` platform build option. |
| 155 | |
| 156 | Architectural initialization |
| 157 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 158 | |
| 159 | BL1 performs minimal architectural initialization as follows. |
| 160 | |
| 161 | - Exception vectors |
| 162 | |
| 163 | BL1 sets up simple exception vectors for both synchronous and asynchronous |
| 164 | exceptions. The default behavior upon receiving an exception is to populate |
| 165 | a status code in the general purpose register ``X0/R0`` and call the |
| 166 | ``plat_report_exception()`` function (see the `Porting Guide`_). The status |
| 167 | code is one of: |
| 168 | |
| 169 | For AArch64: |
| 170 | |
| 171 | :: |
| 172 | |
| 173 | 0x0 : Synchronous exception from Current EL with SP_EL0 |
| 174 | 0x1 : IRQ exception from Current EL with SP_EL0 |
| 175 | 0x2 : FIQ exception from Current EL with SP_EL0 |
| 176 | 0x3 : System Error exception from Current EL with SP_EL0 |
| 177 | 0x4 : Synchronous exception from Current EL with SP_ELx |
| 178 | 0x5 : IRQ exception from Current EL with SP_ELx |
| 179 | 0x6 : FIQ exception from Current EL with SP_ELx |
| 180 | 0x7 : System Error exception from Current EL with SP_ELx |
| 181 | 0x8 : Synchronous exception from Lower EL using aarch64 |
| 182 | 0x9 : IRQ exception from Lower EL using aarch64 |
| 183 | 0xa : FIQ exception from Lower EL using aarch64 |
| 184 | 0xb : System Error exception from Lower EL using aarch64 |
| 185 | 0xc : Synchronous exception from Lower EL using aarch32 |
| 186 | 0xd : IRQ exception from Lower EL using aarch32 |
| 187 | 0xe : FIQ exception from Lower EL using aarch32 |
| 188 | 0xf : System Error exception from Lower EL using aarch32 |
| 189 | |
| 190 | For AArch32: |
| 191 | |
| 192 | :: |
| 193 | |
| 194 | 0x10 : User mode |
| 195 | 0x11 : FIQ mode |
| 196 | 0x12 : IRQ mode |
| 197 | 0x13 : SVC mode |
| 198 | 0x16 : Monitor mode |
| 199 | 0x17 : Abort mode |
| 200 | 0x1a : Hypervisor mode |
| 201 | 0x1b : Undefined mode |
| 202 | 0x1f : System mode |
| 203 | |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 204 | The ``plat_report_exception()`` implementation on the Arm FVP port programs |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 205 | the Versatile Express System LED register in the following format to |
| 206 | indicate the occurence of an unexpected exception: |
| 207 | |
| 208 | :: |
| 209 | |
| 210 | SYS_LED[0] - Security state (Secure=0/Non-Secure=1) |
| 211 | SYS_LED[2:1] - Exception Level (EL3=0x3, EL2=0x2, EL1=0x1, EL0=0x0) |
| 212 | For AArch32 it is always 0x0 |
| 213 | SYS_LED[7:3] - Exception Class (Sync/Async & origin). This is the value |
| 214 | of the status code |
| 215 | |
| 216 | A write to the LED register reflects in the System LEDs (S6LED0..7) in the |
| 217 | CLCD window of the FVP. |
| 218 | |
| 219 | BL1 does not expect to receive any exceptions other than the SMC exception. |
| 220 | For the latter, BL1 installs a simple stub. The stub expects to receive a |
| 221 | limited set of SMC types (determined by their function IDs in the general |
| 222 | purpose register ``X0/R0``): |
| 223 | |
| 224 | - ``BL1_SMC_RUN_IMAGE``: This SMC is raised by BL2 to make BL1 pass control |
| 225 | to EL3 Runtime Software. |
| 226 | - All SMCs listed in section "BL1 SMC Interface" in the `Firmware Update`_ |
| 227 | Design Guide are supported for AArch64 only. These SMCs are currently |
| 228 | not supported when BL1 is built for AArch32. |
| 229 | |
| 230 | Any other SMC leads to an assertion failure. |
| 231 | |
| 232 | - CPU initialization |
| 233 | |
| 234 | BL1 calls the ``reset_handler()`` function which in turn calls the CPU |
| 235 | specific reset handler function (see the section: "CPU specific operations |
| 236 | framework"). |
| 237 | |
| 238 | - Control register setup (for AArch64) |
| 239 | |
| 240 | - ``SCTLR_EL3``. Instruction cache is enabled by setting the ``SCTLR_EL3.I`` |
| 241 | bit. Alignment and stack alignment checking is enabled by setting the |
| 242 | ``SCTLR_EL3.A`` and ``SCTLR_EL3.SA`` bits. Exception endianness is set to |
| 243 | little-endian by clearing the ``SCTLR_EL3.EE`` bit. |
| 244 | |
| 245 | - ``SCR_EL3``. The register width of the next lower exception level is set |
| 246 | to AArch64 by setting the ``SCR.RW`` bit. The ``SCR.EA`` bit is set to trap |
| 247 | both External Aborts and SError Interrupts in EL3. The ``SCR.SIF`` bit is |
| 248 | also set to disable instruction fetches from Non-secure memory when in |
| 249 | secure state. |
| 250 | |
| 251 | - ``CPTR_EL3``. Accesses to the ``CPACR_EL1`` register from EL1 or EL2, or the |
| 252 | ``CPTR_EL2`` register from EL2 are configured to not trap to EL3 by |
| 253 | clearing the ``CPTR_EL3.TCPAC`` bit. Access to the trace functionality is |
| 254 | configured not to trap to EL3 by clearing the ``CPTR_EL3.TTA`` bit. |
| 255 | Instructions that access the registers associated with Floating Point |
| 256 | and Advanced SIMD execution are configured to not trap to EL3 by |
| 257 | clearing the ``CPTR_EL3.TFP`` bit. |
| 258 | |
| 259 | - ``DAIF``. The SError interrupt is enabled by clearing the SError interrupt |
| 260 | mask bit. |
| 261 | |
| 262 | - ``MDCR_EL3``. The trap controls, ``MDCR_EL3.TDOSA``, ``MDCR_EL3.TDA`` and |
| 263 | ``MDCR_EL3.TPM``, are set so that accesses to the registers they control |
| 264 | do not trap to EL3. AArch64 Secure self-hosted debug is disabled by |
| 265 | setting the ``MDCR_EL3.SDD`` bit. Also ``MDCR_EL3.SPD32`` is set to |
| 266 | disable AArch32 Secure self-hosted privileged debug from S-EL1. |
| 267 | |
| 268 | - Control register setup (for AArch32) |
| 269 | |
| 270 | - ``SCTLR``. Instruction cache is enabled by setting the ``SCTLR.I`` bit. |
| 271 | Alignment checking is enabled by setting the ``SCTLR.A`` bit. |
| 272 | Exception endianness is set to little-endian by clearing the |
| 273 | ``SCTLR.EE`` bit. |
| 274 | |
| 275 | - ``SCR``. The ``SCR.SIF`` bit is set to disable instruction fetches from |
| 276 | Non-secure memory when in secure state. |
| 277 | |
| 278 | - ``CPACR``. Allow execution of Advanced SIMD instructions at PL0 and PL1, |
| 279 | by clearing the ``CPACR.ASEDIS`` bit. Access to the trace functionality |
| 280 | is configured not to trap to undefined mode by clearing the |
| 281 | ``CPACR.TRCDIS`` bit. |
| 282 | |
| 283 | - ``NSACR``. Enable non-secure access to Advanced SIMD functionality and |
| 284 | system register access to implemented trace registers. |
| 285 | |
| 286 | - ``FPEXC``. Enable access to the Advanced SIMD and floating-point |
| 287 | functionality from all Exception levels. |
| 288 | |
| 289 | - ``CPSR.A``. The Asynchronous data abort interrupt is enabled by clearing |
| 290 | the Asynchronous data abort interrupt mask bit. |
| 291 | |
| 292 | - ``SDCR``. The ``SDCR.SPD`` field is set to disable AArch32 Secure |
| 293 | self-hosted privileged debug. |
| 294 | |
| 295 | Platform initialization |
| 296 | ^^^^^^^^^^^^^^^^^^^^^^^ |
| 297 | |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 298 | On Arm platforms, BL1 performs the following platform initializations: |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 299 | |
| 300 | - Enable the Trusted Watchdog. |
| 301 | - Initialize the console. |
| 302 | - Configure the Interconnect to enable hardware coherency. |
| 303 | - Enable the MMU and map the memory it needs to access. |
| 304 | - Configure any required platform storage to load the next bootloader image |
| 305 | (BL2). |
Soby Mathew | b1bf044 | 2018-02-16 14:52:52 +0000 | [diff] [blame] | 306 | - If the BL1 dynamic configuration file, ``TB_FW_CONFIG``, is available, then |
| 307 | load it to the platform defined address and make it available to BL2 via |
| 308 | ``arg0``. |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 309 | |
| 310 | Firmware Update detection and execution |
| 311 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 312 | |
| 313 | After performing platform setup, BL1 common code calls |
| 314 | ``bl1_plat_get_next_image_id()`` to determine if `Firmware Update`_ is required or |
| 315 | to proceed with the normal boot process. If the platform code returns |
| 316 | ``BL2_IMAGE_ID`` then the normal boot sequence is executed as described in the |
| 317 | next section, else BL1 assumes that `Firmware Update`_ is required and execution |
| 318 | passes to the first image in the `Firmware Update`_ process. In either case, BL1 |
| 319 | retrieves a descriptor of the next image by calling ``bl1_plat_get_image_desc()``. |
| 320 | The image descriptor contains an ``entry_point_info_t`` structure, which BL1 |
| 321 | uses to initialize the execution state of the next image. |
| 322 | |
| 323 | BL2 image load and execution |
| 324 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 325 | |
| 326 | In the normal boot flow, BL1 execution continues as follows: |
| 327 | |
| 328 | #. BL1 prints the following string from the primary CPU to indicate successful |
| 329 | execution of the BL1 stage: |
| 330 | |
| 331 | :: |
| 332 | |
| 333 | "Booting Trusted Firmware" |
| 334 | |
Soby Mathew | b1bf044 | 2018-02-16 14:52:52 +0000 | [diff] [blame] | 335 | #. BL1 loads a BL2 raw binary image from platform storage, at a |
| 336 | platform-specific base address. Prior to the load, BL1 invokes |
| 337 | ``bl1_plat_handle_pre_image_load()`` which allows the platform to update or |
| 338 | use the image information. If the BL2 image file is not present or if |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 339 | there is not enough free trusted SRAM the following error message is |
| 340 | printed: |
| 341 | |
| 342 | :: |
| 343 | |
| 344 | "Failed to load BL2 firmware." |
| 345 | |
Soby Mathew | b1bf044 | 2018-02-16 14:52:52 +0000 | [diff] [blame] | 346 | #. BL1 invokes ``bl1_plat_handle_post_image_load()`` which again is intended |
| 347 | for platforms to take further action after image load. This function must |
| 348 | populate the necessary arguments for BL2, which may also include the memory |
| 349 | layout. Further description of the memory layout can be found later |
| 350 | in this document. |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 351 | |
| 352 | #. BL1 passes control to the BL2 image at Secure EL1 (for AArch64) or at |
| 353 | Secure SVC mode (for AArch32), starting from its load address. |
| 354 | |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 355 | BL2 |
| 356 | ~~~ |
| 357 | |
| 358 | BL1 loads and passes control to BL2 at Secure-EL1 (for AArch64) or at Secure |
| 359 | SVC mode (for AArch32) . BL2 is linked against and loaded at a platform-specific |
| 360 | base address (more information can be found later in this document). |
| 361 | The functionality implemented by BL2 is as follows. |
| 362 | |
| 363 | Architectural initialization |
| 364 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 365 | |
| 366 | For AArch64, BL2 performs the minimal architectural initialization required |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 367 | for subsequent stages of TF-A and normal world software. EL1 and EL0 are given |
| 368 | access to Floating Point and Advanced SIMD registers by clearing the |
| 369 | ``CPACR.FPEN`` bits. |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 370 | |
| 371 | For AArch32, the minimal architectural initialization required for subsequent |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 372 | stages of TF-A and normal world software is taken care of in BL1 as both BL1 |
| 373 | and BL2 execute at PL1. |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 374 | |
| 375 | Platform initialization |
| 376 | ^^^^^^^^^^^^^^^^^^^^^^^ |
| 377 | |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 378 | On Arm platforms, BL2 performs the following platform initializations: |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 379 | |
| 380 | - Initialize the console. |
| 381 | - Configure any required platform storage to allow loading further bootloader |
| 382 | images. |
| 383 | - Enable the MMU and map the memory it needs to access. |
| 384 | - Perform platform security setup to allow access to controlled components. |
| 385 | - Reserve some memory for passing information to the next bootloader image |
| 386 | EL3 Runtime Software and populate it. |
| 387 | - Define the extents of memory available for loading each subsequent |
| 388 | bootloader image. |
Soby Mathew | b1bf044 | 2018-02-16 14:52:52 +0000 | [diff] [blame] | 389 | - If BL1 has passed TB_FW_CONFIG dynamic configuration file in ``arg0``, |
| 390 | then parse it. |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 391 | |
| 392 | Image loading in BL2 |
| 393 | ^^^^^^^^^^^^^^^^^^^^ |
| 394 | |
| 395 | Image loading scheme in BL2 depends on ``LOAD_IMAGE_V2`` build option. If the |
| 396 | flag is disabled, the BLxx images are loaded, by calling the respective |
| 397 | load\_blxx() function from BL2 generic code. If the flag is enabled, the BL2 |
| 398 | generic code loads the images based on the list of loadable images provided |
| 399 | by the platform. BL2 passes the list of executable images provided by the |
| 400 | platform to the next handover BL image. By default, this flag is disabled for |
| 401 | AArch64 and the AArch32 build is supported only if this flag is enabled. |
| 402 | |
Soby Mathew | b1bf044 | 2018-02-16 14:52:52 +0000 | [diff] [blame] | 403 | The list of loadable images provided by the platform may also contain |
| 404 | dynamic configuration files. The files are loaded and can be parsed as |
| 405 | needed in the ``bl2_plat_handle_post_image_load()`` function. These |
| 406 | configuration files can be passed to next Boot Loader stages as arguments |
| 407 | by updating the corresponding entrypoint information in this function. |
| 408 | |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 409 | SCP\_BL2 (System Control Processor Firmware) image load |
| 410 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 411 | |
| 412 | Some systems have a separate System Control Processor (SCP) for power, clock, |
| 413 | reset and system control. BL2 loads the optional SCP\_BL2 image from platform |
| 414 | storage into a platform-specific region of secure memory. The subsequent |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 415 | handling of SCP\_BL2 is platform specific. For example, on the Juno Arm |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 416 | development platform port the image is transferred into SCP's internal memory |
| 417 | using the Boot Over MHU (BOM) protocol after being loaded in the trusted SRAM |
| 418 | memory. The SCP executes SCP\_BL2 and signals to the Application Processor (AP) |
| 419 | for BL2 execution to continue. |
| 420 | |
| 421 | EL3 Runtime Software image load |
| 422 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 423 | |
| 424 | BL2 loads the EL3 Runtime Software image from platform storage into a platform- |
| 425 | specific address in trusted SRAM. If there is not enough memory to load the |
| 426 | image or image is missing it leads to an assertion failure. If ``LOAD_IMAGE_V2`` |
| 427 | is disabled and if image loads successfully, BL2 updates the amount of trusted |
| 428 | SRAM used and available for use by EL3 Runtime Software. This information is |
| 429 | populated at a platform-specific memory address. |
| 430 | |
| 431 | AArch64 BL32 (Secure-EL1 Payload) image load |
| 432 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 433 | |
| 434 | BL2 loads the optional BL32 image from platform storage into a platform- |
| 435 | specific region of secure memory. The image executes in the secure world. BL2 |
| 436 | relies on BL31 to pass control to the BL32 image, if present. Hence, BL2 |
| 437 | populates a platform-specific area of memory with the entrypoint/load-address |
| 438 | of the BL32 image. The value of the Saved Processor Status Register (``SPSR``) |
| 439 | for entry into BL32 is not determined by BL2, it is initialized by the |
| 440 | Secure-EL1 Payload Dispatcher (see later) within BL31, which is responsible for |
| 441 | managing interaction with BL32. This information is passed to BL31. |
| 442 | |
| 443 | BL33 (Non-trusted Firmware) image load |
| 444 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 445 | |
| 446 | BL2 loads the BL33 image (e.g. UEFI or other test or boot software) from |
| 447 | platform storage into non-secure memory as defined by the platform. |
| 448 | |
| 449 | BL2 relies on EL3 Runtime Software to pass control to BL33 once secure state |
| 450 | initialization is complete. Hence, BL2 populates a platform-specific area of |
| 451 | memory with the entrypoint and Saved Program Status Register (``SPSR``) of the |
| 452 | normal world software image. The entrypoint is the load address of the BL33 |
| 453 | image. The ``SPSR`` is determined as specified in Section 5.13 of the |
| 454 | `PSCI PDD`_. This information is passed to the EL3 Runtime Software. |
| 455 | |
| 456 | AArch64 BL31 (EL3 Runtime Software) execution |
| 457 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 458 | |
| 459 | BL2 execution continues as follows: |
| 460 | |
| 461 | #. BL2 passes control back to BL1 by raising an SMC, providing BL1 with the |
| 462 | BL31 entrypoint. The exception is handled by the SMC exception handler |
| 463 | installed by BL1. |
| 464 | |
| 465 | #. BL1 turns off the MMU and flushes the caches. It clears the |
| 466 | ``SCTLR_EL3.M/I/C`` bits, flushes the data cache to the point of coherency |
| 467 | and invalidates the TLBs. |
| 468 | |
| 469 | #. BL1 passes control to BL31 at the specified entrypoint at EL3. |
| 470 | |
Roberto Vargas | b158427 | 2017-11-20 13:36:10 +0000 | [diff] [blame] | 471 | Running BL2 at EL3 execution level |
| 472 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 473 | |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 474 | Some platforms have a non-TF-A Boot ROM that expects the next boot stage |
| 475 | to execute at EL3. On these platforms, TF-A BL1 is a waste of memory |
| 476 | as its only purpose is to ensure TF-A BL2 is entered at S-EL1. To avoid |
Roberto Vargas | b158427 | 2017-11-20 13:36:10 +0000 | [diff] [blame] | 477 | this waste, a special mode enables BL2 to execute at EL3, which allows |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 478 | a non-TF-A Boot ROM to load and jump directly to BL2. This mode is selected |
Roberto Vargas | b158427 | 2017-11-20 13:36:10 +0000 | [diff] [blame] | 479 | when the build flag BL2_AT_EL3 is enabled. The main differences in this |
| 480 | mode are: |
| 481 | |
| 482 | #. BL2 includes the reset code and the mailbox mechanism to differentiate |
| 483 | cold boot and warm boot. It runs at EL3 doing the arch |
| 484 | initialization required for EL3. |
| 485 | |
| 486 | #. BL2 does not receive the meminfo information from BL1 anymore. This |
| 487 | information can be passed by the Boot ROM or be internal to the |
| 488 | BL2 image. |
| 489 | |
| 490 | #. Since BL2 executes at EL3, BL2 jumps directly to the next image, |
| 491 | instead of invoking the RUN_IMAGE SMC call. |
| 492 | |
| 493 | |
| 494 | We assume 3 different types of BootROM support on the platform: |
| 495 | |
| 496 | #. The Boot ROM always jumps to the same address, for both cold |
| 497 | and warm boot. In this case, we will need to keep a resident part |
| 498 | of BL2 whose memory cannot be reclaimed by any other image. The |
| 499 | linker script defines the symbols __TEXT_RESIDENT_START__ and |
| 500 | __TEXT_RESIDENT_END__ that allows the platform to configure |
| 501 | correctly the memory map. |
| 502 | #. The platform has some mechanism to indicate the jump address to the |
| 503 | Boot ROM. Platform code can then program the jump address with |
| 504 | psci_warmboot_entrypoint during cold boot. |
| 505 | #. The platform has some mechanism to program the reset address using |
| 506 | the PROGRAMMABLE_RESET_ADDRESS feature. Platform code can then |
| 507 | program the reset address with psci_warmboot_entrypoint during |
| 508 | cold boot, bypassing the boot ROM for warm boot. |
| 509 | |
| 510 | In the last 2 cases, no part of BL2 needs to remain resident at |
| 511 | runtime. In the first 2 cases, we expect the Boot ROM to be able to |
| 512 | differentiate between warm and cold boot, to avoid loading BL2 again |
| 513 | during warm boot. |
| 514 | |
| 515 | This functionality can be tested with FVP loading the image directly |
| 516 | in memory and changing the address where the system jumps at reset. |
| 517 | For example: |
| 518 | |
Dimitris Papastamos | 2583649 | 2018-06-11 11:07:58 +0100 | [diff] [blame] | 519 | -C cluster0.cpu0.RVBAR=0x4022000 |
| 520 | --data cluster0.cpu0=bl2.bin@0x4022000 |
Roberto Vargas | b158427 | 2017-11-20 13:36:10 +0000 | [diff] [blame] | 521 | |
| 522 | With this configuration, FVP is like a platform of the first case, |
| 523 | where the Boot ROM jumps always to the same address. For simplification, |
| 524 | BL32 is loaded in DRAM in this case, to avoid other images reclaiming |
| 525 | BL2 memory. |
| 526 | |
| 527 | |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 528 | AArch64 BL31 |
| 529 | ~~~~~~~~~~~~ |
| 530 | |
| 531 | The image for this stage is loaded by BL2 and BL1 passes control to BL31 at |
| 532 | EL3. BL31 executes solely in trusted SRAM. BL31 is linked against and |
| 533 | loaded at a platform-specific base address (more information can be found later |
| 534 | in this document). The functionality implemented by BL31 is as follows. |
| 535 | |
| 536 | Architectural initialization |
| 537 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 538 | |
| 539 | Currently, BL31 performs a similar architectural initialization to BL1 as |
| 540 | far as system register settings are concerned. Since BL1 code resides in ROM, |
| 541 | architectural initialization in BL31 allows override of any previous |
| 542 | initialization done by BL1. |
| 543 | |
| 544 | BL31 initializes the per-CPU data framework, which provides a cache of |
| 545 | frequently accessed per-CPU data optimised for fast, concurrent manipulation |
| 546 | on different CPUs. This buffer includes pointers to per-CPU contexts, crash |
| 547 | buffer, CPU reset and power down operations, PSCI data, platform data and so on. |
| 548 | |
| 549 | It then replaces the exception vectors populated by BL1 with its own. BL31 |
| 550 | exception vectors implement more elaborate support for handling SMCs since this |
| 551 | is the only mechanism to access the runtime services implemented by BL31 (PSCI |
| 552 | for example). BL31 checks each SMC for validity as specified by the |
| 553 | `SMC calling convention PDD`_ before passing control to the required SMC |
| 554 | handler routine. |
| 555 | |
| 556 | BL31 programs the ``CNTFRQ_EL0`` register with the clock frequency of the system |
| 557 | counter, which is provided by the platform. |
| 558 | |
| 559 | Platform initialization |
| 560 | ^^^^^^^^^^^^^^^^^^^^^^^ |
| 561 | |
| 562 | BL31 performs detailed platform initialization, which enables normal world |
| 563 | software to function correctly. |
| 564 | |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 565 | On Arm platforms, this consists of the following: |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 566 | |
| 567 | - Initialize the console. |
| 568 | - Configure the Interconnect to enable hardware coherency. |
| 569 | - Enable the MMU and map the memory it needs to access. |
| 570 | - Initialize the generic interrupt controller. |
| 571 | - Initialize the power controller device. |
| 572 | - Detect the system topology. |
| 573 | |
| 574 | Runtime services initialization |
| 575 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 576 | |
| 577 | BL31 is responsible for initializing the runtime services. One of them is PSCI. |
| 578 | |
| 579 | As part of the PSCI initializations, BL31 detects the system topology. It also |
| 580 | initializes the data structures that implement the state machine used to track |
| 581 | the state of power domain nodes. The state can be one of ``OFF``, ``RUN`` or |
| 582 | ``RETENTION``. All secondary CPUs are initially in the ``OFF`` state. The cluster |
| 583 | that the primary CPU belongs to is ``ON``; any other cluster is ``OFF``. It also |
| 584 | initializes the locks that protect them. BL31 accesses the state of a CPU or |
| 585 | cluster immediately after reset and before the data cache is enabled in the |
| 586 | warm boot path. It is not currently possible to use 'exclusive' based spinlocks, |
| 587 | therefore BL31 uses locks based on Lamport's Bakery algorithm instead. |
| 588 | |
| 589 | The runtime service framework and its initialization is described in more |
| 590 | detail in the "EL3 runtime services framework" section below. |
| 591 | |
| 592 | Details about the status of the PSCI implementation are provided in the |
| 593 | "Power State Coordination Interface" section below. |
| 594 | |
| 595 | AArch64 BL32 (Secure-EL1 Payload) image initialization |
| 596 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 597 | |
| 598 | If a BL32 image is present then there must be a matching Secure-EL1 Payload |
| 599 | Dispatcher (SPD) service (see later for details). During initialization |
| 600 | that service must register a function to carry out initialization of BL32 |
| 601 | once the runtime services are fully initialized. BL31 invokes such a |
| 602 | registered function to initialize BL32 before running BL33. This initialization |
| 603 | is not necessary for AArch32 SPs. |
| 604 | |
| 605 | Details on BL32 initialization and the SPD's role are described in the |
| 606 | "Secure-EL1 Payloads and Dispatchers" section below. |
| 607 | |
| 608 | BL33 (Non-trusted Firmware) execution |
| 609 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 610 | |
| 611 | EL3 Runtime Software initializes the EL2 or EL1 processor context for normal- |
| 612 | world cold boot, ensuring that no secure state information finds its way into |
| 613 | the non-secure execution state. EL3 Runtime Software uses the entrypoint |
| 614 | information provided by BL2 to jump to the Non-trusted firmware image (BL33) |
| 615 | at the highest available Exception Level (EL2 if available, otherwise EL1). |
| 616 | |
| 617 | Using alternative Trusted Boot Firmware in place of BL1 & BL2 (AArch64 only) |
| 618 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 619 | |
| 620 | Some platforms have existing implementations of Trusted Boot Firmware that |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 621 | would like to use TF-A BL31 for the EL3 Runtime Software. To enable this |
| 622 | firmware architecture it is important to provide a fully documented and stable |
| 623 | interface between the Trusted Boot Firmware and BL31. |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 624 | |
| 625 | Future changes to the BL31 interface will be done in a backwards compatible |
| 626 | way, and this enables these firmware components to be independently enhanced/ |
| 627 | updated to develop and exploit new functionality. |
| 628 | |
| 629 | Required CPU state when calling ``bl31_entrypoint()`` during cold boot |
| 630 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 631 | |
| 632 | This function must only be called by the primary CPU. |
| 633 | |
| 634 | On entry to this function the calling primary CPU must be executing in AArch64 |
| 635 | EL3, little-endian data access, and all interrupt sources masked: |
| 636 | |
| 637 | :: |
| 638 | |
| 639 | PSTATE.EL = 3 |
| 640 | PSTATE.RW = 1 |
| 641 | PSTATE.DAIF = 0xf |
| 642 | SCTLR_EL3.EE = 0 |
| 643 | |
| 644 | X0 and X1 can be used to pass information from the Trusted Boot Firmware to the |
| 645 | platform code in BL31: |
| 646 | |
| 647 | :: |
| 648 | |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 649 | X0 : Reserved for common TF-A information |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 650 | X1 : Platform specific information |
| 651 | |
| 652 | BL31 zero-init sections (e.g. ``.bss``) should not contain valid data on entry, |
| 653 | these will be zero filled prior to invoking platform setup code. |
| 654 | |
| 655 | Use of the X0 and X1 parameters |
| 656 | ''''''''''''''''''''''''''''''' |
| 657 | |
| 658 | The parameters are platform specific and passed from ``bl31_entrypoint()`` to |
| 659 | ``bl31_early_platform_setup()``. The value of these parameters is never directly |
| 660 | used by the common BL31 code. |
| 661 | |
| 662 | The convention is that ``X0`` conveys information regarding the BL31, BL32 and |
| 663 | BL33 images from the Trusted Boot firmware and ``X1`` can be used for other |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 664 | platform specific purpose. This convention allows platforms which use TF-A's |
| 665 | BL1 and BL2 images to transfer additional platform specific information from |
| 666 | Secure Boot without conflicting with future evolution of TF-A using ``X0`` to |
| 667 | pass a ``bl31_params`` structure. |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 668 | |
| 669 | BL31 common and SPD initialization code depends on image and entrypoint |
| 670 | information about BL33 and BL32, which is provided via BL31 platform APIs. |
| 671 | This information is required until the start of execution of BL33. This |
| 672 | information can be provided in a platform defined manner, e.g. compiled into |
| 673 | the platform code in BL31, or provided in a platform defined memory location |
| 674 | by the Trusted Boot firmware, or passed from the Trusted Boot Firmware via the |
| 675 | Cold boot Initialization parameters. This data may need to be cleaned out of |
| 676 | the CPU caches if it is provided by an earlier boot stage and then accessed by |
| 677 | BL31 platform code before the caches are enabled. |
| 678 | |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 679 | TF-A's BL2 implementation passes a ``bl31_params`` structure in |
| 680 | ``X0`` and the Arm development platforms interpret this in the BL31 platform |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 681 | code. |
| 682 | |
| 683 | MMU, Data caches & Coherency |
| 684 | '''''''''''''''''''''''''''' |
| 685 | |
| 686 | BL31 does not depend on the enabled state of the MMU, data caches or |
| 687 | interconnect coherency on entry to ``bl31_entrypoint()``. If these are disabled |
| 688 | on entry, these should be enabled during ``bl31_plat_arch_setup()``. |
| 689 | |
| 690 | Data structures used in the BL31 cold boot interface |
| 691 | '''''''''''''''''''''''''''''''''''''''''''''''''''' |
| 692 | |
| 693 | These structures are designed to support compatibility and independent |
| 694 | evolution of the structures and the firmware images. For example, a version of |
| 695 | BL31 that can interpret the BL3x image information from different versions of |
| 696 | BL2, a platform that uses an extended entry\_point\_info structure to convey |
| 697 | additional register information to BL31, or a ELF image loader that can convey |
| 698 | more details about the firmware images. |
| 699 | |
| 700 | To support these scenarios the structures are versioned and sized, which enables |
| 701 | BL31 to detect which information is present and respond appropriately. The |
| 702 | ``param_header`` is defined to capture this information: |
| 703 | |
| 704 | .. code:: c |
| 705 | |
| 706 | typedef struct param_header { |
| 707 | uint8_t type; /* type of the structure */ |
| 708 | uint8_t version; /* version of this structure */ |
| 709 | uint16_t size; /* size of this structure in bytes */ |
| 710 | uint32_t attr; /* attributes: unused bits SBZ */ |
| 711 | } param_header_t; |
| 712 | |
| 713 | The structures using this format are ``entry_point_info``, ``image_info`` and |
| 714 | ``bl31_params``. The code that allocates and populates these structures must set |
| 715 | the header fields appropriately, and the ``SET_PARAM_HEAD()`` a macro is defined |
| 716 | to simplify this action. |
| 717 | |
| 718 | Required CPU state for BL31 Warm boot initialization |
| 719 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 720 | |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 721 | When requesting a CPU power-on, or suspending a running CPU, TF-A provides |
| 722 | the platform power management code with a Warm boot initialization |
| 723 | entry-point, to be invoked by the CPU immediately after the reset handler. |
| 724 | On entry to the Warm boot initialization function the calling CPU must be in |
| 725 | AArch64 EL3, little-endian data access and all interrupt sources masked: |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 726 | |
| 727 | :: |
| 728 | |
| 729 | PSTATE.EL = 3 |
| 730 | PSTATE.RW = 1 |
| 731 | PSTATE.DAIF = 0xf |
| 732 | SCTLR_EL3.EE = 0 |
| 733 | |
| 734 | The PSCI implementation will initialize the processor state and ensure that the |
| 735 | platform power management code is then invoked as required to initialize all |
| 736 | necessary system, cluster and CPU resources. |
| 737 | |
| 738 | AArch32 EL3 Runtime Software entrypoint interface |
| 739 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 740 | |
| 741 | To enable this firmware architecture it is important to provide a fully |
| 742 | documented and stable interface between the Trusted Boot Firmware and the |
| 743 | AArch32 EL3 Runtime Software. |
| 744 | |
| 745 | Future changes to the entrypoint interface will be done in a backwards |
| 746 | compatible way, and this enables these firmware components to be independently |
| 747 | enhanced/updated to develop and exploit new functionality. |
| 748 | |
| 749 | Required CPU state when entering during cold boot |
| 750 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 751 | |
| 752 | This function must only be called by the primary CPU. |
| 753 | |
| 754 | On entry to this function the calling primary CPU must be executing in AArch32 |
| 755 | EL3, little-endian data access, and all interrupt sources masked: |
| 756 | |
| 757 | :: |
| 758 | |
| 759 | PSTATE.AIF = 0x7 |
| 760 | SCTLR.EE = 0 |
| 761 | |
| 762 | R0 and R1 are used to pass information from the Trusted Boot Firmware to the |
| 763 | platform code in AArch32 EL3 Runtime Software: |
| 764 | |
| 765 | :: |
| 766 | |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 767 | R0 : Reserved for common TF-A information |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 768 | R1 : Platform specific information |
| 769 | |
| 770 | Use of the R0 and R1 parameters |
| 771 | ''''''''''''''''''''''''''''''' |
| 772 | |
| 773 | The parameters are platform specific and the convention is that ``R0`` conveys |
| 774 | information regarding the BL3x images from the Trusted Boot firmware and ``R1`` |
| 775 | can be used for other platform specific purpose. This convention allows |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 776 | platforms which use TF-A's BL1 and BL2 images to transfer additional platform |
| 777 | specific information from Secure Boot without conflicting with future |
| 778 | evolution of TF-A using ``R0`` to pass a ``bl_params`` structure. |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 779 | |
| 780 | The AArch32 EL3 Runtime Software is responsible for entry into BL33. This |
| 781 | information can be obtained in a platform defined manner, e.g. compiled into |
| 782 | the AArch32 EL3 Runtime Software, or provided in a platform defined memory |
| 783 | location by the Trusted Boot firmware, or passed from the Trusted Boot Firmware |
| 784 | via the Cold boot Initialization parameters. This data may need to be cleaned |
| 785 | out of the CPU caches if it is provided by an earlier boot stage and then |
| 786 | accessed by AArch32 EL3 Runtime Software before the caches are enabled. |
| 787 | |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 788 | When using AArch32 EL3 Runtime Software, the Arm development platforms pass a |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 789 | ``bl_params`` structure in ``R0`` from BL2 to be interpreted by AArch32 EL3 Runtime |
| 790 | Software platform code. |
| 791 | |
| 792 | MMU, Data caches & Coherency |
| 793 | '''''''''''''''''''''''''''' |
| 794 | |
| 795 | AArch32 EL3 Runtime Software must not depend on the enabled state of the MMU, |
| 796 | data caches or interconnect coherency in its entrypoint. They must be explicitly |
| 797 | enabled if required. |
| 798 | |
| 799 | Data structures used in cold boot interface |
| 800 | ''''''''''''''''''''''''''''''''''''''''''' |
| 801 | |
| 802 | The AArch32 EL3 Runtime Software cold boot interface uses ``bl_params`` instead |
| 803 | of ``bl31_params``. The ``bl_params`` structure is based on the convention |
| 804 | described in AArch64 BL31 cold boot interface section. |
| 805 | |
| 806 | Required CPU state for warm boot initialization |
| 807 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 808 | |
| 809 | When requesting a CPU power-on, or suspending a running CPU, AArch32 EL3 |
| 810 | Runtime Software must ensure execution of a warm boot initialization entrypoint. |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 811 | If TF-A BL1 is used and the PROGRAMMABLE\_RESET\_ADDRESS build flag is false, |
| 812 | then AArch32 EL3 Runtime Software must ensure that BL1 branches to the warm |
| 813 | boot entrypoint by arranging for the BL1 platform function, |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 814 | plat\_get\_my\_entrypoint(), to return a non-zero value. |
| 815 | |
| 816 | In this case, the warm boot entrypoint must be in AArch32 EL3, little-endian |
| 817 | data access and all interrupt sources masked: |
| 818 | |
| 819 | :: |
| 820 | |
| 821 | PSTATE.AIF = 0x7 |
| 822 | SCTLR.EE = 0 |
| 823 | |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 824 | The warm boot entrypoint may be implemented by using TF-A |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 825 | ``psci_warmboot_entrypoint()`` function. In that case, the platform must fulfil |
| 826 | the pre-requisites mentioned in the `PSCI Library integration guide`_. |
| 827 | |
| 828 | EL3 runtime services framework |
| 829 | ------------------------------ |
| 830 | |
| 831 | Software executing in the non-secure state and in the secure state at exception |
| 832 | levels lower than EL3 will request runtime services using the Secure Monitor |
| 833 | Call (SMC) instruction. These requests will follow the convention described in |
| 834 | the SMC Calling Convention PDD (`SMCCC`_). The `SMCCC`_ assigns function |
| 835 | identifiers to each SMC request and describes how arguments are passed and |
| 836 | returned. |
| 837 | |
| 838 | The EL3 runtime services framework enables the development of services by |
| 839 | different providers that can be easily integrated into final product firmware. |
| 840 | The following sections describe the framework which facilitates the |
| 841 | registration, initialization and use of runtime services in EL3 Runtime |
| 842 | Software (BL31). |
| 843 | |
| 844 | The design of the runtime services depends heavily on the concepts and |
| 845 | definitions described in the `SMCCC`_, in particular SMC Function IDs, Owning |
| 846 | Entity Numbers (OEN), Fast and Yielding calls, and the SMC32 and SMC64 calling |
| 847 | conventions. Please refer to that document for more detailed explanation of |
| 848 | these terms. |
| 849 | |
| 850 | The following runtime services are expected to be implemented first. They have |
| 851 | not all been instantiated in the current implementation. |
| 852 | |
| 853 | #. Standard service calls |
| 854 | |
| 855 | This service is for management of the entire system. The Power State |
| 856 | Coordination Interface (`PSCI`_) is the first set of standard service calls |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 857 | defined by Arm (see PSCI section later). |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 858 | |
| 859 | #. Secure-EL1 Payload Dispatcher service |
| 860 | |
| 861 | If a system runs a Trusted OS or other Secure-EL1 Payload (SP) then |
| 862 | it also requires a *Secure Monitor* at EL3 to switch the EL1 processor |
| 863 | context between the normal world (EL1/EL2) and trusted world (Secure-EL1). |
| 864 | The Secure Monitor will make these world switches in response to SMCs. The |
| 865 | `SMCCC`_ provides for such SMCs with the Trusted OS Call and Trusted |
| 866 | Application Call OEN ranges. |
| 867 | |
| 868 | The interface between the EL3 Runtime Software and the Secure-EL1 Payload is |
| 869 | not defined by the `SMCCC`_ or any other standard. As a result, each |
| 870 | Secure-EL1 Payload requires a specific Secure Monitor that runs as a runtime |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 871 | service - within TF-A this service is referred to as the Secure-EL1 Payload |
| 872 | Dispatcher (SPD). |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 873 | |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 874 | TF-A provides a Test Secure-EL1 Payload (TSP) and its associated Dispatcher |
| 875 | (TSPD). Details of SPD design and TSP/TSPD operation are described in the |
| 876 | "Secure-EL1 Payloads and Dispatchers" section below. |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 877 | |
| 878 | #. CPU implementation service |
| 879 | |
| 880 | This service will provide an interface to CPU implementation specific |
| 881 | services for a given platform e.g. access to processor errata workarounds. |
| 882 | This service is currently unimplemented. |
| 883 | |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 884 | Additional services for Arm Architecture, SiP and OEM calls can be implemented. |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 885 | Each implemented service handles a range of SMC function identifiers as |
| 886 | described in the `SMCCC`_. |
| 887 | |
| 888 | Registration |
| 889 | ~~~~~~~~~~~~ |
| 890 | |
| 891 | A runtime service is registered using the ``DECLARE_RT_SVC()`` macro, specifying |
| 892 | the name of the service, the range of OENs covered, the type of service and |
| 893 | initialization and call handler functions. This macro instantiates a ``const struct rt_svc_desc`` for the service with these details (see ``runtime_svc.h``). |
| 894 | This structure is allocated in a special ELF section ``rt_svc_descs``, enabling |
| 895 | the framework to find all service descriptors included into BL31. |
| 896 | |
| 897 | The specific service for a SMC Function is selected based on the OEN and call |
| 898 | type of the Function ID, and the framework uses that information in the service |
| 899 | descriptor to identify the handler for the SMC Call. |
| 900 | |
| 901 | The service descriptors do not include information to identify the precise set |
| 902 | of SMC function identifiers supported by this service implementation, the |
| 903 | security state from which such calls are valid nor the capability to support |
| 904 | 64-bit and/or 32-bit callers (using SMC32 or SMC64). Responding appropriately |
| 905 | to these aspects of a SMC call is the responsibility of the service |
| 906 | implementation, the framework is focused on integration of services from |
| 907 | different providers and minimizing the time taken by the framework before the |
| 908 | service handler is invoked. |
| 909 | |
| 910 | Details of the parameters, requirements and behavior of the initialization and |
| 911 | call handling functions are provided in the following sections. |
| 912 | |
| 913 | Initialization |
| 914 | ~~~~~~~~~~~~~~ |
| 915 | |
| 916 | ``runtime_svc_init()`` in ``runtime_svc.c`` initializes the runtime services |
| 917 | framework running on the primary CPU during cold boot as part of the BL31 |
| 918 | initialization. This happens prior to initializing a Trusted OS and running |
| 919 | Normal world boot firmware that might in turn use these services. |
| 920 | Initialization involves validating each of the declared runtime service |
| 921 | descriptors, calling the service initialization function and populating the |
| 922 | index used for runtime lookup of the service. |
| 923 | |
| 924 | The BL31 linker script collects all of the declared service descriptors into a |
| 925 | single array and defines symbols that allow the framework to locate and traverse |
| 926 | the array, and determine its size. |
| 927 | |
| 928 | The framework does basic validation of each descriptor to halt firmware |
| 929 | initialization if service declaration errors are detected. The framework does |
| 930 | not check descriptors for the following error conditions, and may behave in an |
| 931 | unpredictable manner under such scenarios: |
| 932 | |
| 933 | #. Overlapping OEN ranges |
| 934 | #. Multiple descriptors for the same range of OENs and ``call_type`` |
| 935 | #. Incorrect range of owning entity numbers for a given ``call_type`` |
| 936 | |
| 937 | Once validated, the service ``init()`` callback is invoked. This function carries |
| 938 | out any essential EL3 initialization before servicing requests. The ``init()`` |
| 939 | function is only invoked on the primary CPU during cold boot. If the service |
| 940 | uses per-CPU data this must either be initialized for all CPUs during this call, |
| 941 | or be done lazily when a CPU first issues an SMC call to that service. If |
| 942 | ``init()`` returns anything other than ``0``, this is treated as an initialization |
| 943 | error and the service is ignored: this does not cause the firmware to halt. |
| 944 | |
| 945 | The OEN and call type fields present in the SMC Function ID cover a total of |
| 946 | 128 distinct services, but in practice a single descriptor can cover a range of |
| 947 | OENs, e.g. SMCs to call a Trusted OS function. To optimize the lookup of a |
| 948 | service handler, the framework uses an array of 128 indices that map every |
| 949 | distinct OEN/call-type combination either to one of the declared services or to |
| 950 | indicate the service is not handled. This ``rt_svc_descs_indices[]`` array is |
| 951 | populated for all of the OENs covered by a service after the service ``init()`` |
| 952 | function has reported success. So a service that fails to initialize will never |
| 953 | have it's ``handle()`` function invoked. |
| 954 | |
| 955 | The following figure shows how the ``rt_svc_descs_indices[]`` index maps the SMC |
| 956 | Function ID call type and OEN onto a specific service handler in the |
| 957 | ``rt_svc_descs[]`` array. |
| 958 | |
| 959 | |Image 1| |
| 960 | |
| 961 | Handling an SMC |
| 962 | ~~~~~~~~~~~~~~~ |
| 963 | |
| 964 | When the EL3 runtime services framework receives a Secure Monitor Call, the SMC |
| 965 | Function ID is passed in W0 from the lower exception level (as per the |
| 966 | `SMCCC`_). If the calling register width is AArch32, it is invalid to invoke an |
| 967 | SMC Function which indicates the SMC64 calling convention: such calls are |
| 968 | ignored and return the Unknown SMC Function Identifier result code ``0xFFFFFFFF`` |
| 969 | in R0/X0. |
| 970 | |
| 971 | Bit[31] (fast/yielding call) and bits[29:24] (owning entity number) of the SMC |
| 972 | Function ID are combined to index into the ``rt_svc_descs_indices[]`` array. The |
| 973 | resulting value might indicate a service that has no handler, in this case the |
| 974 | framework will also report an Unknown SMC Function ID. Otherwise, the value is |
| 975 | used as a further index into the ``rt_svc_descs[]`` array to locate the required |
| 976 | service and handler. |
| 977 | |
| 978 | The service's ``handle()`` callback is provided with five of the SMC parameters |
| 979 | directly, the others are saved into memory for retrieval (if needed) by the |
| 980 | handler. The handler is also provided with an opaque ``handle`` for use with the |
| 981 | supporting library for parameter retrieval, setting return values and context |
| 982 | manipulation; and with ``flags`` indicating the security state of the caller. The |
| 983 | framework finally sets up the execution stack for the handler, and invokes the |
| 984 | services ``handle()`` function. |
| 985 | |
| 986 | On return from the handler the result registers are populated in X0-X3 before |
| 987 | restoring the stack and CPU state and returning from the original SMC. |
| 988 | |
| 989 | Power State Coordination Interface |
| 990 | ---------------------------------- |
| 991 | |
| 992 | TODO: Provide design walkthrough of PSCI implementation. |
| 993 | |
Roberto Vargas | d963e3e | 2017-09-12 10:28:35 +0100 | [diff] [blame] | 994 | The PSCI v1.1 specification categorizes APIs as optional and mandatory. All the |
| 995 | mandatory APIs in PSCI v1.1, PSCI v1.0 and in PSCI v0.2 draft specification |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 996 | `Power State Coordination Interface PDD`_ are implemented. The table lists |
Roberto Vargas | d963e3e | 2017-09-12 10:28:35 +0100 | [diff] [blame] | 997 | the PSCI v1.1 APIs and their support in generic code. |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 998 | |
| 999 | An API implementation might have a dependency on platform code e.g. CPU\_SUSPEND |
| 1000 | requires the platform to export a part of the implementation. Hence the level |
| 1001 | of support of the mandatory APIs depends upon the support exported by the |
| 1002 | platform port as well. The Juno and FVP (all variants) platforms export all the |
| 1003 | required support. |
| 1004 | |
| 1005 | +-----------------------------+-------------+-------------------------------+ |
Roberto Vargas | d963e3e | 2017-09-12 10:28:35 +0100 | [diff] [blame] | 1006 | | PSCI v1.1 API | Supported | Comments | |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 1007 | +=============================+=============+===============================+ |
Roberto Vargas | d963e3e | 2017-09-12 10:28:35 +0100 | [diff] [blame] | 1008 | | ``PSCI_VERSION`` | Yes | The version returned is 1.1 | |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 1009 | +-----------------------------+-------------+-------------------------------+ |
| 1010 | | ``CPU_SUSPEND`` | Yes\* | | |
| 1011 | +-----------------------------+-------------+-------------------------------+ |
| 1012 | | ``CPU_OFF`` | Yes\* | | |
| 1013 | +-----------------------------+-------------+-------------------------------+ |
| 1014 | | ``CPU_ON`` | Yes\* | | |
| 1015 | +-----------------------------+-------------+-------------------------------+ |
| 1016 | | ``AFFINITY_INFO`` | Yes | | |
| 1017 | +-----------------------------+-------------+-------------------------------+ |
| 1018 | | ``MIGRATE`` | Yes\*\* | | |
| 1019 | +-----------------------------+-------------+-------------------------------+ |
| 1020 | | ``MIGRATE_INFO_TYPE`` | Yes\*\* | | |
| 1021 | +-----------------------------+-------------+-------------------------------+ |
| 1022 | | ``MIGRATE_INFO_CPU`` | Yes\*\* | | |
| 1023 | +-----------------------------+-------------+-------------------------------+ |
| 1024 | | ``SYSTEM_OFF`` | Yes\* | | |
| 1025 | +-----------------------------+-------------+-------------------------------+ |
| 1026 | | ``SYSTEM_RESET`` | Yes\* | | |
| 1027 | +-----------------------------+-------------+-------------------------------+ |
| 1028 | | ``PSCI_FEATURES`` | Yes | | |
| 1029 | +-----------------------------+-------------+-------------------------------+ |
| 1030 | | ``CPU_FREEZE`` | No | | |
| 1031 | +-----------------------------+-------------+-------------------------------+ |
| 1032 | | ``CPU_DEFAULT_SUSPEND`` | No | | |
| 1033 | +-----------------------------+-------------+-------------------------------+ |
| 1034 | | ``NODE_HW_STATE`` | Yes\* | | |
| 1035 | +-----------------------------+-------------+-------------------------------+ |
| 1036 | | ``SYSTEM_SUSPEND`` | Yes\* | | |
| 1037 | +-----------------------------+-------------+-------------------------------+ |
| 1038 | | ``PSCI_SET_SUSPEND_MODE`` | No | | |
| 1039 | +-----------------------------+-------------+-------------------------------+ |
| 1040 | | ``PSCI_STAT_RESIDENCY`` | Yes\* | | |
| 1041 | +-----------------------------+-------------+-------------------------------+ |
| 1042 | | ``PSCI_STAT_COUNT`` | Yes\* | | |
| 1043 | +-----------------------------+-------------+-------------------------------+ |
Roberto Vargas | d963e3e | 2017-09-12 10:28:35 +0100 | [diff] [blame] | 1044 | | ``SYSTEM_RESET2`` | Yes\* | | |
| 1045 | +-----------------------------+-------------+-------------------------------+ |
| 1046 | | ``MEM_PROTECT`` | Yes\* | | |
| 1047 | +-----------------------------+-------------+-------------------------------+ |
| 1048 | | ``MEM_PROTECT_CHECK_RANGE`` | Yes\* | | |
| 1049 | +-----------------------------+-------------+-------------------------------+ |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 1050 | |
| 1051 | \*Note : These PSCI APIs require platform power management hooks to be |
| 1052 | registered with the generic PSCI code to be supported. |
| 1053 | |
| 1054 | \*\*Note : These PSCI APIs require appropriate Secure Payload Dispatcher |
| 1055 | hooks to be registered with the generic PSCI code to be supported. |
| 1056 | |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 1057 | The PSCI implementation in TF-A is a library which can be integrated with |
| 1058 | AArch64 or AArch32 EL3 Runtime Software for Armv8-A systems. A guide to |
| 1059 | integrating PSCI library with AArch32 EL3 Runtime Software can be found |
| 1060 | `here`_. |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 1061 | |
| 1062 | Secure-EL1 Payloads and Dispatchers |
| 1063 | ----------------------------------- |
| 1064 | |
| 1065 | On a production system that includes a Trusted OS running in Secure-EL1/EL0, |
| 1066 | the Trusted OS is coupled with a companion runtime service in the BL31 |
| 1067 | firmware. This service is responsible for the initialisation of the Trusted |
| 1068 | OS and all communications with it. The Trusted OS is the BL32 stage of the |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 1069 | boot flow in TF-A. The firmware will attempt to locate, load and execute a |
| 1070 | BL32 image. |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 1071 | |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 1072 | TF-A uses a more general term for the BL32 software that runs at Secure-EL1 - |
| 1073 | the *Secure-EL1 Payload* - as it is not always a Trusted OS. |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 1074 | |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 1075 | TF-A provides a Test Secure-EL1 Payload (TSP) and a Test Secure-EL1 Payload |
| 1076 | Dispatcher (TSPD) service as an example of how a Trusted OS is supported on a |
| 1077 | production system using the Runtime Services Framework. On such a system, the |
| 1078 | Test BL32 image and service are replaced by the Trusted OS and its dispatcher |
| 1079 | service. The TF-A build system expects that the dispatcher will define the |
| 1080 | build flag ``NEED_BL32`` to enable it to include the BL32 in the build either |
| 1081 | as a binary or to compile from source depending on whether the ``BL32`` build |
| 1082 | option is specified or not. |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 1083 | |
| 1084 | The TSP runs in Secure-EL1. It is designed to demonstrate synchronous |
| 1085 | communication with the normal-world software running in EL1/EL2. Communication |
| 1086 | is initiated by the normal-world software |
| 1087 | |
| 1088 | - either directly through a Fast SMC (as defined in the `SMCCC`_) |
| 1089 | |
| 1090 | - or indirectly through a `PSCI`_ SMC. The `PSCI`_ implementation in turn |
| 1091 | informs the TSPD about the requested power management operation. This allows |
| 1092 | the TSP to prepare for or respond to the power state change |
| 1093 | |
| 1094 | The TSPD service is responsible for. |
| 1095 | |
| 1096 | - Initializing the TSP |
| 1097 | |
| 1098 | - Routing requests and responses between the secure and the non-secure |
| 1099 | states during the two types of communications just described |
| 1100 | |
| 1101 | Initializing a BL32 Image |
| 1102 | ~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 1103 | |
| 1104 | The Secure-EL1 Payload Dispatcher (SPD) service is responsible for initializing |
| 1105 | the BL32 image. It needs access to the information passed by BL2 to BL31 to do |
| 1106 | so. This is provided by: |
| 1107 | |
| 1108 | .. code:: c |
| 1109 | |
| 1110 | entry_point_info_t *bl31_plat_get_next_image_ep_info(uint32_t); |
| 1111 | |
| 1112 | which returns a reference to the ``entry_point_info`` structure corresponding to |
| 1113 | the image which will be run in the specified security state. The SPD uses this |
| 1114 | API to get entry point information for the SECURE image, BL32. |
| 1115 | |
| 1116 | In the absence of a BL32 image, BL31 passes control to the normal world |
| 1117 | bootloader image (BL33). When the BL32 image is present, it is typical |
| 1118 | that the SPD wants control to be passed to BL32 first and then later to BL33. |
| 1119 | |
| 1120 | To do this the SPD has to register a BL32 initialization function during |
| 1121 | initialization of the SPD service. The BL32 initialization function has this |
| 1122 | prototype: |
| 1123 | |
| 1124 | .. code:: c |
| 1125 | |
| 1126 | int32_t init(void); |
| 1127 | |
| 1128 | and is registered using the ``bl31_register_bl32_init()`` function. |
| 1129 | |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 1130 | TF-A supports two approaches for the SPD to pass control to BL32 before |
| 1131 | returning through EL3 and running the non-trusted firmware (BL33): |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 1132 | |
| 1133 | #. In the BL32 setup function, use ``bl31_set_next_image_type()`` to |
| 1134 | request that the exit from ``bl31_main()`` is to the BL32 entrypoint in |
| 1135 | Secure-EL1. BL31 will exit to BL32 using the asynchronous method by |
| 1136 | calling ``bl31_prepare_next_image_entry()`` and ``el3_exit()``. |
| 1137 | |
| 1138 | When the BL32 has completed initialization at Secure-EL1, it returns to |
| 1139 | BL31 by issuing an SMC, using a Function ID allocated to the SPD. On |
| 1140 | receipt of this SMC, the SPD service handler should switch the CPU context |
| 1141 | from trusted to normal world and use the ``bl31_set_next_image_type()`` and |
| 1142 | ``bl31_prepare_next_image_entry()`` functions to set up the initial return to |
| 1143 | the normal world firmware BL33. On return from the handler the framework |
| 1144 | will exit to EL2 and run BL33. |
| 1145 | |
| 1146 | #. The BL32 setup function registers an initialization function using |
| 1147 | ``bl31_register_bl32_init()`` which provides a SPD-defined mechanism to |
| 1148 | invoke a 'world-switch synchronous call' to Secure-EL1 to run the BL32 |
| 1149 | entrypoint. |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 1150 | NOTE: The Test SPD service included with TF-A provides one implementation |
| 1151 | of such a mechanism. |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 1152 | |
| 1153 | On completion BL32 returns control to BL31 via a SMC, and on receipt the |
| 1154 | SPD service handler invokes the synchronous call return mechanism to return |
| 1155 | to the BL32 initialization function. On return from this function, |
| 1156 | ``bl31_main()`` will set up the return to the normal world firmware BL33 and |
| 1157 | continue the boot process in the normal world. |
| 1158 | |
Jeenu Viswambharan | b60420a | 2017-08-24 15:43:44 +0100 | [diff] [blame] | 1159 | Crash Reporting in BL31 |
| 1160 | ----------------------- |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 1161 | |
| 1162 | BL31 implements a scheme for reporting the processor state when an unhandled |
| 1163 | exception is encountered. The reporting mechanism attempts to preserve all the |
| 1164 | register contents and report it via a dedicated UART (PL011 console). BL31 |
| 1165 | reports the general purpose, EL3, Secure EL1 and some EL2 state registers. |
| 1166 | |
| 1167 | A dedicated per-CPU crash stack is maintained by BL31 and this is retrieved via |
| 1168 | the per-CPU pointer cache. The implementation attempts to minimise the memory |
| 1169 | required for this feature. The file ``crash_reporting.S`` contains the |
| 1170 | implementation for crash reporting. |
| 1171 | |
| 1172 | The sample crash output is shown below. |
| 1173 | |
| 1174 | :: |
| 1175 | |
| 1176 | x0 :0x000000004F00007C |
| 1177 | x1 :0x0000000007FFFFFF |
| 1178 | x2 :0x0000000004014D50 |
| 1179 | x3 :0x0000000000000000 |
| 1180 | x4 :0x0000000088007998 |
| 1181 | x5 :0x00000000001343AC |
| 1182 | x6 :0x0000000000000016 |
| 1183 | x7 :0x00000000000B8A38 |
| 1184 | x8 :0x00000000001343AC |
| 1185 | x9 :0x00000000000101A8 |
| 1186 | x10 :0x0000000000000002 |
| 1187 | x11 :0x000000000000011C |
| 1188 | x12 :0x00000000FEFDC644 |
| 1189 | x13 :0x00000000FED93FFC |
| 1190 | x14 :0x0000000000247950 |
| 1191 | x15 :0x00000000000007A2 |
| 1192 | x16 :0x00000000000007A4 |
| 1193 | x17 :0x0000000000247950 |
| 1194 | x18 :0x0000000000000000 |
| 1195 | x19 :0x00000000FFFFFFFF |
| 1196 | x20 :0x0000000004014D50 |
| 1197 | x21 :0x000000000400A38C |
| 1198 | x22 :0x0000000000247950 |
| 1199 | x23 :0x0000000000000010 |
| 1200 | x24 :0x0000000000000024 |
| 1201 | x25 :0x00000000FEFDC868 |
| 1202 | x26 :0x00000000FEFDC86A |
| 1203 | x27 :0x00000000019EDEDC |
| 1204 | x28 :0x000000000A7CFDAA |
| 1205 | x29 :0x0000000004010780 |
| 1206 | x30 :0x000000000400F004 |
| 1207 | scr_el3 :0x0000000000000D3D |
| 1208 | sctlr_el3 :0x0000000000C8181F |
| 1209 | cptr_el3 :0x0000000000000000 |
| 1210 | tcr_el3 :0x0000000080803520 |
| 1211 | daif :0x00000000000003C0 |
| 1212 | mair_el3 :0x00000000000004FF |
| 1213 | spsr_el3 :0x00000000800003CC |
| 1214 | elr_el3 :0x000000000400C0CC |
| 1215 | ttbr0_el3 :0x00000000040172A0 |
| 1216 | esr_el3 :0x0000000096000210 |
| 1217 | sp_el3 :0x0000000004014D50 |
| 1218 | far_el3 :0x000000004F00007C |
| 1219 | spsr_el1 :0x0000000000000000 |
| 1220 | elr_el1 :0x0000000000000000 |
| 1221 | spsr_abt :0x0000000000000000 |
| 1222 | spsr_und :0x0000000000000000 |
| 1223 | spsr_irq :0x0000000000000000 |
| 1224 | spsr_fiq :0x0000000000000000 |
| 1225 | sctlr_el1 :0x0000000030C81807 |
| 1226 | actlr_el1 :0x0000000000000000 |
| 1227 | cpacr_el1 :0x0000000000300000 |
| 1228 | csselr_el1 :0x0000000000000002 |
| 1229 | sp_el1 :0x0000000004028800 |
| 1230 | esr_el1 :0x0000000000000000 |
| 1231 | ttbr0_el1 :0x000000000402C200 |
| 1232 | ttbr1_el1 :0x0000000000000000 |
| 1233 | mair_el1 :0x00000000000004FF |
| 1234 | amair_el1 :0x0000000000000000 |
| 1235 | tcr_el1 :0x0000000000003520 |
| 1236 | tpidr_el1 :0x0000000000000000 |
| 1237 | tpidr_el0 :0x0000000000000000 |
| 1238 | tpidrro_el0 :0x0000000000000000 |
| 1239 | dacr32_el2 :0x0000000000000000 |
| 1240 | ifsr32_el2 :0x0000000000000000 |
| 1241 | par_el1 :0x0000000000000000 |
| 1242 | far_el1 :0x0000000000000000 |
| 1243 | afsr0_el1 :0x0000000000000000 |
| 1244 | afsr1_el1 :0x0000000000000000 |
| 1245 | contextidr_el1 :0x0000000000000000 |
| 1246 | vbar_el1 :0x0000000004027000 |
| 1247 | cntp_ctl_el0 :0x0000000000000000 |
| 1248 | cntp_cval_el0 :0x0000000000000000 |
| 1249 | cntv_ctl_el0 :0x0000000000000000 |
| 1250 | cntv_cval_el0 :0x0000000000000000 |
| 1251 | cntkctl_el1 :0x0000000000000000 |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 1252 | sp_el0 :0x0000000004010780 |
| 1253 | |
| 1254 | Guidelines for Reset Handlers |
| 1255 | ----------------------------- |
| 1256 | |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 1257 | TF-A implements a framework that allows CPU and platform ports to perform |
| 1258 | actions very early after a CPU is released from reset in both the cold and warm |
| 1259 | boot paths. This is done by calling the ``reset_handler()`` function in both |
| 1260 | the BL1 and BL31 images. It in turn calls the platform and CPU specific reset |
| 1261 | handling functions. |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 1262 | |
| 1263 | Details for implementing a CPU specific reset handler can be found in |
| 1264 | Section 8. Details for implementing a platform specific reset handler can be |
| 1265 | found in the `Porting Guide`_ (see the ``plat_reset_handler()`` function). |
| 1266 | |
| 1267 | When adding functionality to a reset handler, keep in mind that if a different |
| 1268 | reset handling behavior is required between the first and the subsequent |
| 1269 | invocations of the reset handling code, this should be detected at runtime. |
| 1270 | In other words, the reset handler should be able to detect whether an action has |
| 1271 | already been performed and act as appropriate. Possible courses of actions are, |
| 1272 | e.g. skip the action the second time, or undo/redo it. |
| 1273 | |
Jeenu Viswambharan | aeb267c | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 1274 | Configuring secure interrupts |
| 1275 | ----------------------------- |
| 1276 | |
| 1277 | The GIC driver is responsible for performing initial configuration of secure |
| 1278 | interrupts on the platform. To this end, the platform is expected to provide the |
| 1279 | GIC driver (either GICv2 or GICv3, as selected by the platform) with the |
| 1280 | interrupt configuration during the driver initialisation. |
| 1281 | |
| 1282 | There are two ways to specify secure interrupt configuration: |
| 1283 | |
| 1284 | #. Array of secure interrupt properties: In this scheme, in both GICv2 and GICv3 |
| 1285 | driver data structures, the ``interrupt_props`` member points to an array of |
| 1286 | interrupt properties. Each element of the array specifies the interrupt |
| 1287 | number and its configuration, viz. priority, group, configuration. Each |
| 1288 | element of the array shall be populated by the macro ``INTR_PROP_DESC()``. |
| 1289 | The macro takes the following arguments: |
| 1290 | |
| 1291 | - 10-bit interrupt number, |
| 1292 | |
| 1293 | - 8-bit interrupt priority, |
| 1294 | |
| 1295 | - Interrupt type (one of ``INTR_TYPE_EL3``, ``INTR_TYPE_S_EL1``, |
| 1296 | ``INTR_TYPE_NS``), |
| 1297 | |
| 1298 | - Interrupt configuration (either ``GIC_INTR_CFG_LEVEL`` or |
| 1299 | ``GIC_INTR_CFG_EDGE``). |
| 1300 | |
| 1301 | #. Array of secure interrupts: In this scheme, the GIC driver is provided an |
| 1302 | array of secure interrupt numbers. The GIC driver, at the time of |
| 1303 | initialisation, iterates through the array and assigns each interrupt |
| 1304 | the appropriate group. |
| 1305 | |
| 1306 | - For the GICv2 driver, in ``gicv2_driver_data`` structure, the |
| 1307 | ``g0_interrupt_array`` member of the should point to the array of |
| 1308 | interrupts to be assigned to *Group 0*, and the ``g0_interrupt_num`` |
| 1309 | member of the should be set to the number of interrupts in the array. |
| 1310 | |
| 1311 | - For the GICv3 driver, in ``gicv3_driver_data`` structure: |
| 1312 | |
| 1313 | - The ``g0_interrupt_array`` member of the should point to the array of |
| 1314 | interrupts to be assigned to *Group 0*, and the ``g0_interrupt_num`` |
| 1315 | member of the should be set to the number of interrupts in the array. |
| 1316 | |
| 1317 | - The ``g1s_interrupt_array`` member of the should point to the array of |
| 1318 | interrupts to be assigned to *Group 1 Secure*, and the |
| 1319 | ``g1s_interrupt_num`` member of the should be set to the number of |
| 1320 | interrupts in the array. |
| 1321 | |
| 1322 | **Note that this scheme is deprecated.** |
| 1323 | |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 1324 | CPU specific operations framework |
| 1325 | --------------------------------- |
| 1326 | |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 1327 | Certain aspects of the Armv8-A architecture are implementation defined, |
| 1328 | that is, certain behaviours are not architecturally defined, but must be |
| 1329 | defined and documented by individual processor implementations. TF-A |
| 1330 | implements a framework which categorises the common implementation defined |
| 1331 | behaviours and allows a processor to export its implementation of that |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 1332 | behaviour. The categories are: |
| 1333 | |
| 1334 | #. Processor specific reset sequence. |
| 1335 | |
| 1336 | #. Processor specific power down sequences. |
| 1337 | |
| 1338 | #. Processor specific register dumping as a part of crash reporting. |
| 1339 | |
| 1340 | #. Errata status reporting. |
| 1341 | |
| 1342 | Each of the above categories fulfils a different requirement. |
| 1343 | |
| 1344 | #. allows any processor specific initialization before the caches and MMU |
| 1345 | are turned on, like implementation of errata workarounds, entry into |
| 1346 | the intra-cluster coherency domain etc. |
| 1347 | |
| 1348 | #. allows each processor to implement the power down sequence mandated in |
| 1349 | its Technical Reference Manual (TRM). |
| 1350 | |
| 1351 | #. allows a processor to provide additional information to the developer |
| 1352 | in the event of a crash, for example Cortex-A53 has registers which |
| 1353 | can expose the data cache contents. |
| 1354 | |
| 1355 | #. allows a processor to define a function that inspects and reports the status |
| 1356 | of all errata workarounds on that processor. |
| 1357 | |
| 1358 | Please note that only 2. is mandated by the TRM. |
| 1359 | |
| 1360 | The CPU specific operations framework scales to accommodate a large number of |
| 1361 | different CPUs during power down and reset handling. The platform can specify |
| 1362 | any CPU optimization it wants to enable for each CPU. It can also specify |
| 1363 | the CPU errata workarounds to be applied for each CPU type during reset |
| 1364 | handling by defining CPU errata compile time macros. Details on these macros |
| 1365 | can be found in the `cpu-specific-build-macros.rst`_ file. |
| 1366 | |
| 1367 | The CPU specific operations framework depends on the ``cpu_ops`` structure which |
| 1368 | needs to be exported for each type of CPU in the platform. It is defined in |
| 1369 | ``include/lib/cpus/aarch64/cpu_macros.S`` and has the following fields : ``midr``, |
| 1370 | ``reset_func()``, ``cpu_pwr_down_ops`` (array of power down functions) and |
| 1371 | ``cpu_reg_dump()``. |
| 1372 | |
| 1373 | The CPU specific files in ``lib/cpus`` export a ``cpu_ops`` data structure with |
| 1374 | suitable handlers for that CPU. For example, ``lib/cpus/aarch64/cortex_a53.S`` |
| 1375 | exports the ``cpu_ops`` for Cortex-A53 CPU. According to the platform |
| 1376 | configuration, these CPU specific files must be included in the build by |
| 1377 | the platform makefile. The generic CPU specific operations framework code exists |
| 1378 | in ``lib/cpus/aarch64/cpu_helpers.S``. |
| 1379 | |
| 1380 | CPU specific Reset Handling |
| 1381 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 1382 | |
| 1383 | After a reset, the state of the CPU when it calls generic reset handler is: |
| 1384 | MMU turned off, both instruction and data caches turned off and not part |
| 1385 | of any coherency domain. |
| 1386 | |
| 1387 | The BL entrypoint code first invokes the ``plat_reset_handler()`` to allow |
| 1388 | the platform to perform any system initialization required and any system |
| 1389 | errata workarounds that needs to be applied. The ``get_cpu_ops_ptr()`` reads |
| 1390 | the current CPU midr, finds the matching ``cpu_ops`` entry in the ``cpu_ops`` |
| 1391 | array and returns it. Note that only the part number and implementer fields |
| 1392 | in midr are used to find the matching ``cpu_ops`` entry. The ``reset_func()`` in |
| 1393 | the returned ``cpu_ops`` is then invoked which executes the required reset |
| 1394 | handling for that CPU and also any errata workarounds enabled by the platform. |
| 1395 | This function must preserve the values of general purpose registers x20 to x29. |
| 1396 | |
| 1397 | Refer to Section "Guidelines for Reset Handlers" for general guidelines |
| 1398 | regarding placement of code in a reset handler. |
| 1399 | |
| 1400 | CPU specific power down sequence |
| 1401 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 1402 | |
| 1403 | During the BL31 initialization sequence, the pointer to the matching ``cpu_ops`` |
| 1404 | entry is stored in per-CPU data by ``init_cpu_ops()`` so that it can be quickly |
| 1405 | retrieved during power down sequences. |
| 1406 | |
| 1407 | Various CPU drivers register handlers to perform power down at certain power |
| 1408 | levels for that specific CPU. The PSCI service, upon receiving a power down |
| 1409 | request, determines the highest power level at which to execute power down |
| 1410 | sequence for a particular CPU. It uses the ``prepare_cpu_pwr_dwn()`` function to |
| 1411 | pick the right power down handler for the requested level. The function |
| 1412 | retrieves ``cpu_ops`` pointer member of per-CPU data, and from that, further |
| 1413 | retrieves ``cpu_pwr_down_ops`` array, and indexes into the required level. If the |
| 1414 | requested power level is higher than what a CPU driver supports, the handler |
| 1415 | registered for highest level is invoked. |
| 1416 | |
| 1417 | At runtime the platform hooks for power down are invoked by the PSCI service to |
| 1418 | perform platform specific operations during a power down sequence, for example |
| 1419 | turning off CCI coherency during a cluster power down. |
| 1420 | |
| 1421 | CPU specific register reporting during crash |
| 1422 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 1423 | |
| 1424 | If the crash reporting is enabled in BL31, when a crash occurs, the crash |
| 1425 | reporting framework calls ``do_cpu_reg_dump`` which retrieves the matching |
| 1426 | ``cpu_ops`` using ``get_cpu_ops_ptr()`` function. The ``cpu_reg_dump()`` in |
| 1427 | ``cpu_ops`` is invoked, which then returns the CPU specific register values to |
| 1428 | be reported and a pointer to the ASCII list of register names in a format |
| 1429 | expected by the crash reporting framework. |
| 1430 | |
| 1431 | CPU errata status reporting |
| 1432 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 1433 | |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 1434 | Errata workarounds for CPUs supported in TF-A are applied during both cold and |
| 1435 | warm boots, shortly after reset. Individual Errata workarounds are enabled as |
| 1436 | build options. Some errata workarounds have potential run-time implications; |
| 1437 | therefore some are enabled by default, others not. Platform ports shall |
| 1438 | override build options to enable or disable errata as appropriate. The CPU |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 1439 | drivers take care of applying errata workarounds that are enabled and applicable |
| 1440 | to a given CPU. Refer to the section titled *CPU Errata Workarounds* in `CPUBM`_ |
| 1441 | for more information. |
| 1442 | |
| 1443 | Functions in CPU drivers that apply errata workaround must follow the |
| 1444 | conventions listed below. |
| 1445 | |
| 1446 | The errata workaround must be authored as two separate functions: |
| 1447 | |
| 1448 | - One that checks for errata. This function must determine whether that errata |
| 1449 | applies to the current CPU. Typically this involves matching the current |
| 1450 | CPUs revision and variant against a value that's known to be affected by the |
| 1451 | errata. If the function determines that the errata applies to this CPU, it |
| 1452 | must return ``ERRATA_APPLIES``; otherwise, it must return |
| 1453 | ``ERRATA_NOT_APPLIES``. The utility functions ``cpu_get_rev_var`` and |
| 1454 | ``cpu_rev_var_ls`` functions may come in handy for this purpose. |
| 1455 | |
| 1456 | For an errata identified as ``E``, the check function must be named |
| 1457 | ``check_errata_E``. |
| 1458 | |
| 1459 | This function will be invoked at different times, both from assembly and from |
| 1460 | C run time. Therefore it must follow AAPCS, and must not use stack. |
| 1461 | |
| 1462 | - Another one that applies the errata workaround. This function would call the |
| 1463 | check function described above, and applies errata workaround if required. |
| 1464 | |
| 1465 | CPU drivers that apply errata workaround can optionally implement an assembly |
| 1466 | function that report the status of errata workarounds pertaining to that CPU. |
| 1467 | For a driver that registers the CPU, for example, ``cpux`` via. ``declare_cpu_ops`` |
| 1468 | macro, the errata reporting function, if it exists, must be named |
| 1469 | ``cpux_errata_report``. This function will always be called with MMU enabled; it |
| 1470 | must follow AAPCS and may use stack. |
| 1471 | |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 1472 | In a debug build of TF-A, on a CPU that comes out of reset, both BL1 and the |
| 1473 | runtime firmware (BL31 in AArch64, and BL32 in AArch32) will invoke errata |
| 1474 | status reporting function, if one exists, for that type of CPU. |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 1475 | |
| 1476 | To report the status of each errata workaround, the function shall use the |
| 1477 | assembler macro ``report_errata``, passing it: |
| 1478 | |
| 1479 | - The build option that enables the errata; |
| 1480 | |
| 1481 | - The name of the CPU: this must be the same identifier that CPU driver |
| 1482 | registered itself with, using ``declare_cpu_ops``; |
| 1483 | |
| 1484 | - And the errata identifier: the identifier must match what's used in the |
| 1485 | errata's check function described above. |
| 1486 | |
| 1487 | The errata status reporting function will be called once per CPU type/errata |
| 1488 | combination during the software's active life time. |
| 1489 | |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 1490 | It's expected that whenever an errata workaround is submitted to TF-A, the |
| 1491 | errata reporting function is appropriately extended to report its status as |
| 1492 | well. |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 1493 | |
| 1494 | Reporting the status of errata workaround is for informational purpose only; it |
| 1495 | has no functional significance. |
| 1496 | |
| 1497 | Memory layout of BL images |
| 1498 | -------------------------- |
| 1499 | |
| 1500 | Each bootloader image can be divided in 2 parts: |
| 1501 | |
| 1502 | - the static contents of the image. These are data actually stored in the |
| 1503 | binary on the disk. In the ELF terminology, they are called ``PROGBITS`` |
| 1504 | sections; |
| 1505 | |
| 1506 | - the run-time contents of the image. These are data that don't occupy any |
| 1507 | space in the binary on the disk. The ELF binary just contains some |
| 1508 | metadata indicating where these data will be stored at run-time and the |
| 1509 | corresponding sections need to be allocated and initialized at run-time. |
| 1510 | In the ELF terminology, they are called ``NOBITS`` sections. |
| 1511 | |
| 1512 | All PROGBITS sections are grouped together at the beginning of the image, |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 1513 | followed by all NOBITS sections. This is true for all TF-A images and it is |
| 1514 | governed by the linker scripts. This ensures that the raw binary images are |
| 1515 | as small as possible. If a NOBITS section was inserted in between PROGBITS |
| 1516 | sections then the resulting binary file would contain zero bytes in place of |
| 1517 | this NOBITS section, making the image unnecessarily bigger. Smaller images |
| 1518 | allow faster loading from the FIP to the main memory. |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 1519 | |
| 1520 | Linker scripts and symbols |
| 1521 | ~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 1522 | |
| 1523 | Each bootloader stage image layout is described by its own linker script. The |
| 1524 | linker scripts export some symbols into the program symbol table. Their values |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 1525 | correspond to particular addresses. TF-A code can refer to these symbols to |
| 1526 | figure out the image memory layout. |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 1527 | |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 1528 | Linker symbols follow the following naming convention in TF-A. |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 1529 | |
| 1530 | - ``__<SECTION>_START__`` |
| 1531 | |
| 1532 | Start address of a given section named ``<SECTION>``. |
| 1533 | |
| 1534 | - ``__<SECTION>_END__`` |
| 1535 | |
| 1536 | End address of a given section named ``<SECTION>``. If there is an alignment |
| 1537 | constraint on the section's end address then ``__<SECTION>_END__`` corresponds |
| 1538 | to the end address of the section's actual contents, rounded up to the right |
| 1539 | boundary. Refer to the value of ``__<SECTION>_UNALIGNED_END__`` to know the |
| 1540 | actual end address of the section's contents. |
| 1541 | |
| 1542 | - ``__<SECTION>_UNALIGNED_END__`` |
| 1543 | |
| 1544 | End address of a given section named ``<SECTION>`` without any padding or |
| 1545 | rounding up due to some alignment constraint. |
| 1546 | |
| 1547 | - ``__<SECTION>_SIZE__`` |
| 1548 | |
| 1549 | Size (in bytes) of a given section named ``<SECTION>``. If there is an |
| 1550 | alignment constraint on the section's end address then ``__<SECTION>_SIZE__`` |
| 1551 | corresponds to the size of the section's actual contents, rounded up to the |
| 1552 | right boundary. In other words, ``__<SECTION>_SIZE__ = __<SECTION>_END__ - _<SECTION>_START__``. Refer to the value of ``__<SECTION>_UNALIGNED_SIZE__`` |
| 1553 | to know the actual size of the section's contents. |
| 1554 | |
| 1555 | - ``__<SECTION>_UNALIGNED_SIZE__`` |
| 1556 | |
| 1557 | Size (in bytes) of a given section named ``<SECTION>`` without any padding or |
| 1558 | rounding up due to some alignment constraint. In other words, |
| 1559 | ``__<SECTION>_UNALIGNED_SIZE__ = __<SECTION>_UNALIGNED_END__ - __<SECTION>_START__``. |
| 1560 | |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 1561 | Some of the linker symbols are mandatory as TF-A code relies on them to be |
| 1562 | defined. They are listed in the following subsections. Some of them must be |
| 1563 | provided for each bootloader stage and some are specific to a given bootloader |
| 1564 | stage. |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 1565 | |
| 1566 | The linker scripts define some extra, optional symbols. They are not actually |
| 1567 | used by any code but they help in understanding the bootloader images' memory |
| 1568 | layout as they are easy to spot in the link map files. |
| 1569 | |
| 1570 | Common linker symbols |
| 1571 | ^^^^^^^^^^^^^^^^^^^^^ |
| 1572 | |
| 1573 | All BL images share the following requirements: |
| 1574 | |
| 1575 | - The BSS section must be zero-initialised before executing any C code. |
| 1576 | - The coherent memory section (if enabled) must be zero-initialised as well. |
| 1577 | - The MMU setup code needs to know the extents of the coherent and read-only |
| 1578 | memory regions to set the right memory attributes. When |
| 1579 | ``SEPARATE_CODE_AND_RODATA=1``, it needs to know more specifically how the |
| 1580 | read-only memory region is divided between code and data. |
| 1581 | |
| 1582 | The following linker symbols are defined for this purpose: |
| 1583 | |
| 1584 | - ``__BSS_START__`` |
| 1585 | - ``__BSS_SIZE__`` |
| 1586 | - ``__COHERENT_RAM_START__`` Must be aligned on a page-size boundary. |
| 1587 | - ``__COHERENT_RAM_END__`` Must be aligned on a page-size boundary. |
| 1588 | - ``__COHERENT_RAM_UNALIGNED_SIZE__`` |
| 1589 | - ``__RO_START__`` |
| 1590 | - ``__RO_END__`` |
| 1591 | - ``__TEXT_START__`` |
| 1592 | - ``__TEXT_END__`` |
| 1593 | - ``__RODATA_START__`` |
| 1594 | - ``__RODATA_END__`` |
| 1595 | |
| 1596 | BL1's linker symbols |
| 1597 | ^^^^^^^^^^^^^^^^^^^^ |
| 1598 | |
| 1599 | BL1 being the ROM image, it has additional requirements. BL1 resides in ROM and |
| 1600 | it is entirely executed in place but it needs some read-write memory for its |
| 1601 | mutable data. Its ``.data`` section (i.e. its allocated read-write data) must be |
| 1602 | relocated from ROM to RAM before executing any C code. |
| 1603 | |
| 1604 | The following additional linker symbols are defined for BL1: |
| 1605 | |
| 1606 | - ``__BL1_ROM_END__`` End address of BL1's ROM contents, covering its code |
| 1607 | and ``.data`` section in ROM. |
| 1608 | - ``__DATA_ROM_START__`` Start address of the ``.data`` section in ROM. Must be |
| 1609 | aligned on a 16-byte boundary. |
| 1610 | - ``__DATA_RAM_START__`` Address in RAM where the ``.data`` section should be |
| 1611 | copied over. Must be aligned on a 16-byte boundary. |
| 1612 | - ``__DATA_SIZE__`` Size of the ``.data`` section (in ROM or RAM). |
| 1613 | - ``__BL1_RAM_START__`` Start address of BL1 read-write data. |
| 1614 | - ``__BL1_RAM_END__`` End address of BL1 read-write data. |
| 1615 | |
| 1616 | How to choose the right base addresses for each bootloader stage image |
| 1617 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 1618 | |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 1619 | There is currently no support for dynamic image loading in TF-A. This means |
| 1620 | that all bootloader images need to be linked against their ultimate runtime |
| 1621 | locations and the base addresses of each image must be chosen carefully such |
| 1622 | that images don't overlap each other in an undesired way. As the code grows, |
| 1623 | the base addresses might need adjustments to cope with the new memory layout. |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 1624 | |
| 1625 | The memory layout is completely specific to the platform and so there is no |
| 1626 | general recipe for choosing the right base addresses for each bootloader image. |
| 1627 | However, there are tools to aid in understanding the memory layout. These are |
| 1628 | the link map files: ``build/<platform>/<build-type>/bl<x>/bl<x>.map``, with ``<x>`` |
| 1629 | being the stage bootloader. They provide a detailed view of the memory usage of |
| 1630 | each image. Among other useful information, they provide the end address of |
| 1631 | each image. |
| 1632 | |
| 1633 | - ``bl1.map`` link map file provides ``__BL1_RAM_END__`` address. |
| 1634 | - ``bl2.map`` link map file provides ``__BL2_END__`` address. |
| 1635 | - ``bl31.map`` link map file provides ``__BL31_END__`` address. |
| 1636 | - ``bl32.map`` link map file provides ``__BL32_END__`` address. |
| 1637 | |
| 1638 | For each bootloader image, the platform code must provide its start address |
| 1639 | as well as a limit address that it must not overstep. The latter is used in the |
| 1640 | linker scripts to check that the image doesn't grow past that address. If that |
| 1641 | happens, the linker will issue a message similar to the following: |
| 1642 | |
| 1643 | :: |
| 1644 | |
| 1645 | aarch64-none-elf-ld: BLx has exceeded its limit. |
| 1646 | |
| 1647 | Additionally, if the platform memory layout implies some image overlaying like |
| 1648 | on FVP, BL31 and TSP need to know the limit address that their PROGBITS |
| 1649 | sections must not overstep. The platform code must provide those. |
| 1650 | |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 1651 | When LOAD\_IMAGE\_V2 is disabled, TF-A provides a mechanism to verify at boot |
| 1652 | time that the memory to load a new image is free to prevent overwriting a |
| 1653 | previously loaded image. For this mechanism to work, the platform must specify |
| 1654 | the memory available in the system as regions, where each region consists of |
| 1655 | base address, total size and the free area within it (as defined in the |
| 1656 | ``meminfo_t`` structure). TF-A retrieves these memory regions by calling the |
| 1657 | corresponding platform API: |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 1658 | |
| 1659 | - ``meminfo_t *bl1_plat_sec_mem_layout(void)`` |
| 1660 | - ``meminfo_t *bl2_plat_sec_mem_layout(void)`` |
| 1661 | - ``void bl2_plat_get_scp_bl2_meminfo(meminfo_t *scp_bl2_meminfo)`` |
| 1662 | - ``void bl2_plat_get_bl32_meminfo(meminfo_t *bl32_meminfo)`` |
| 1663 | - ``void bl2_plat_get_bl33_meminfo(meminfo_t *bl33_meminfo)`` |
| 1664 | |
| 1665 | For example, in the case of BL1 loading BL2, ``bl1_plat_sec_mem_layout()`` will |
| 1666 | return the region defined by the platform where BL1 intends to load BL2. The |
| 1667 | ``load_image()`` function will check that the memory where BL2 will be loaded is |
| 1668 | within the specified region and marked as free. |
| 1669 | |
| 1670 | The actual number of regions and their base addresses and sizes is platform |
| 1671 | specific. The platform may return the same region or define a different one for |
| 1672 | each API. However, the overlap verification mechanism applies only to a single |
| 1673 | region. Hence, it is the platform responsibility to guarantee that different |
| 1674 | regions do not overlap, or that if they do, the overlapping images are not |
| 1675 | accessed at the same time. This could be used, for example, to load temporary |
| 1676 | images (e.g. certificates) or firmware images prior to being transfered to its |
| 1677 | corresponding processor (e.g. the SCP BL2 image). |
| 1678 | |
| 1679 | To reduce fragmentation and simplify the tracking of free memory, all the free |
| 1680 | memory within a region is always located in one single buffer defined by its |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 1681 | base address and size. TF-A implements a top/bottom load approach: |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 1682 | after a new image is loaded, it checks how much memory remains free above and |
| 1683 | below the image. The smallest area is marked as unavailable, while the larger |
| 1684 | area becomes the new free memory buffer. Platforms should take this behaviour |
| 1685 | into account when defining the base address for each of the images. For example, |
| 1686 | if an image is loaded near the middle of the region, small changes in image size |
| 1687 | could cause a flip between a top load and a bottom load, which may result in an |
| 1688 | unexpected memory layout. |
| 1689 | |
| 1690 | The following diagram is an example of an image loaded in the bottom part of |
| 1691 | the memory region. The region is initially free (nothing has been loaded yet): |
| 1692 | |
| 1693 | :: |
| 1694 | |
| 1695 | Memory region |
| 1696 | +----------+ |
| 1697 | | | |
| 1698 | | | <<<<<<<<<<<<< Free |
| 1699 | | | |
| 1700 | |----------| +------------+ |
| 1701 | | image | <<<<<<<<<<<<< | image | |
| 1702 | |----------| +------------+ |
| 1703 | | xxxxxxxx | <<<<<<<<<<<<< Marked as unavailable |
| 1704 | +----------+ |
| 1705 | |
| 1706 | And the following diagram is an example of an image loaded in the top part: |
| 1707 | |
| 1708 | :: |
| 1709 | |
| 1710 | Memory region |
| 1711 | +----------+ |
| 1712 | | xxxxxxxx | <<<<<<<<<<<<< Marked as unavailable |
| 1713 | |----------| +------------+ |
| 1714 | | image | <<<<<<<<<<<<< | image | |
| 1715 | |----------| +------------+ |
| 1716 | | | |
| 1717 | | | <<<<<<<<<<<<< Free |
| 1718 | | | |
| 1719 | +----------+ |
| 1720 | |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 1721 | When LOAD\_IMAGE\_V2 is enabled, TF-A does not provide any mechanism to verify |
| 1722 | at boot time that the memory to load a new image is free to prevent overwriting |
| 1723 | a previously loaded image. The platform must specify the memory available in |
| 1724 | the system for all the relevant BL images to be loaded. |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 1725 | |
| 1726 | For example, in the case of BL1 loading BL2, ``bl1_plat_sec_mem_layout()`` will |
| 1727 | return the region defined by the platform where BL1 intends to load BL2. The |
| 1728 | ``load_image()`` function performs bounds check for the image size based on the |
| 1729 | base and maximum image size provided by the platforms. Platforms must take |
| 1730 | this behaviour into account when defining the base/size for each of the images. |
| 1731 | |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 1732 | Memory layout on Arm development platforms |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 1733 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 1734 | |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 1735 | The following list describes the memory layout on the Arm development platforms: |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 1736 | |
| 1737 | - A 4KB page of shared memory is used for communication between Trusted |
| 1738 | Firmware and the platform's power controller. This is located at the base of |
| 1739 | Trusted SRAM. The amount of Trusted SRAM available to load the bootloader |
| 1740 | images is reduced by the size of the shared memory. |
| 1741 | |
| 1742 | The shared memory is used to store the CPUs' entrypoint mailbox. On Juno, |
| 1743 | this is also used for the MHU payload when passing messages to and from the |
| 1744 | SCP. |
| 1745 | |
Soby Mathew | 492e245 | 2018-06-06 16:03:10 +0100 | [diff] [blame] | 1746 | - Another 4 KB page is reserved for passing memory layout between BL1 and BL2 |
| 1747 | and also the dynamic firmware configurations. |
| 1748 | |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 1749 | - On FVP, BL1 is originally sitting in the Trusted ROM at address ``0x0``. On |
| 1750 | Juno, BL1 resides in flash memory at address ``0x0BEC0000``. BL1 read-write |
| 1751 | data are relocated to the top of Trusted SRAM at runtime. |
| 1752 | |
Soby Mathew | 492e245 | 2018-06-06 16:03:10 +0100 | [diff] [blame] | 1753 | - BL2 is loaded below BL1 RW |
| 1754 | |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 1755 | - EL3 Runtime Software, BL31 for AArch64 and BL32 for AArch32 (e.g. SP\_MIN), |
| 1756 | is loaded at the top of the Trusted SRAM, such that its NOBITS sections will |
Soby Mathew | 492e245 | 2018-06-06 16:03:10 +0100 | [diff] [blame] | 1757 | overwrite BL1 R/W data and BL2. This implies that BL1 global variables |
| 1758 | remain valid only until execution reaches the EL3 Runtime Software entry |
| 1759 | point during a cold boot. |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 1760 | |
| 1761 | - On Juno, SCP\_BL2 is loaded temporarily into the EL3 Runtime Software memory |
| 1762 | region and transfered to the SCP before being overwritten by EL3 Runtime |
| 1763 | Software. |
| 1764 | |
| 1765 | - BL32 (for AArch64) can be loaded in one of the following locations: |
| 1766 | |
| 1767 | - Trusted SRAM |
| 1768 | - Trusted DRAM (FVP only) |
| 1769 | - Secure region of DRAM (top 16MB of DRAM configured by the TrustZone |
| 1770 | controller) |
| 1771 | |
Soby Mathew | 492e245 | 2018-06-06 16:03:10 +0100 | [diff] [blame] | 1772 | When BL32 (for AArch64) is loaded into Trusted SRAM, it is loaded below |
| 1773 | BL31. |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 1774 | |
| 1775 | When LOAD\_IMAGE\_V2 is disabled the memory regions for the overlap detection |
| 1776 | mechanism at boot time are defined as follows (shown per API): |
| 1777 | |
| 1778 | - ``meminfo_t *bl1_plat_sec_mem_layout(void)`` |
| 1779 | |
| 1780 | This region corresponds to the whole Trusted SRAM except for the shared |
| 1781 | memory at the base. This region is initially free. At boot time, BL1 will |
| 1782 | mark the BL1(rw) section within this region as occupied. The BL1(rw) section |
| 1783 | is placed at the top of Trusted SRAM. |
| 1784 | |
| 1785 | - ``meminfo_t *bl2_plat_sec_mem_layout(void)`` |
| 1786 | |
| 1787 | This region corresponds to the whole Trusted SRAM as defined by |
| 1788 | ``bl1_plat_sec_mem_layout()``, but with the BL1(rw) section marked as |
| 1789 | occupied. This memory region is used to check that BL2 and BL31 do not |
| 1790 | overlap with each other. BL2\_BASE and BL1\_RW\_BASE are carefully chosen so |
| 1791 | that the memory for BL31 is top loaded above BL2. |
| 1792 | |
| 1793 | - ``void bl2_plat_get_scp_bl2_meminfo(meminfo_t *scp_bl2_meminfo)`` |
| 1794 | |
| 1795 | This region is an exact copy of the region defined by |
| 1796 | ``bl2_plat_sec_mem_layout()``. Being a disconnected copy means that all the |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 1797 | changes made to this region by the TF-A will not be propagated. This |
| 1798 | approach is valid because the SCP BL2 image is loaded temporarily while it |
| 1799 | is being transferred to the SCP, so this memory is reused afterwards. |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 1800 | |
| 1801 | - ``void bl2_plat_get_bl32_meminfo(meminfo_t *bl32_meminfo)`` |
| 1802 | |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 1803 | This region depends on the location of the BL32 image. Currently, Arm |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 1804 | platforms support three different locations (detailed below): Trusted SRAM, |
| 1805 | Trusted DRAM and the TZC-Secured DRAM. |
| 1806 | |
| 1807 | - ``void bl2_plat_get_bl33_meminfo(meminfo_t *bl33_meminfo)`` |
| 1808 | |
| 1809 | This region corresponds to the Non-Secure DDR-DRAM, excluding the |
| 1810 | TZC-Secured area. |
| 1811 | |
| 1812 | The location of the BL32 image will result in different memory maps. This is |
| 1813 | illustrated for both FVP and Juno in the following diagrams, using the TSP as |
| 1814 | an example. |
| 1815 | |
| 1816 | Note: Loading the BL32 image in TZC secured DRAM doesn't change the memory |
| 1817 | layout of the other images in Trusted SRAM. |
| 1818 | |
Soby Mathew | 492e245 | 2018-06-06 16:03:10 +0100 | [diff] [blame] | 1819 | **FVP with TSP in Trusted SRAM with firmware configs :** |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 1820 | (These diagrams only cover the AArch64 case) |
| 1821 | |
| 1822 | :: |
| 1823 | |
Soby Mathew | 492e245 | 2018-06-06 16:03:10 +0100 | [diff] [blame] | 1824 | DRAM |
| 1825 | 0xffffffff +----------+ |
| 1826 | : : |
| 1827 | |----------| |
| 1828 | |HW_CONFIG | |
| 1829 | 0x83000000 |----------| (non-secure) |
| 1830 | | | |
| 1831 | 0x80000000 +----------+ |
| 1832 | |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 1833 | Trusted SRAM |
Soby Mathew | 492e245 | 2018-06-06 16:03:10 +0100 | [diff] [blame] | 1834 | 0x04040000 +----------+ loaded by BL2 +----------------+ |
| 1835 | | BL1 (rw) | <<<<<<<<<<<<< | | |
| 1836 | |----------| <<<<<<<<<<<<< | BL31 NOBITS | |
| 1837 | | BL2 | <<<<<<<<<<<<< | | |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 1838 | |----------| <<<<<<<<<<<<< |----------------| |
| 1839 | | | <<<<<<<<<<<<< | BL31 PROGBITS | |
Soby Mathew | 492e245 | 2018-06-06 16:03:10 +0100 | [diff] [blame] | 1840 | | | <<<<<<<<<<<<< |----------------| |
| 1841 | | | <<<<<<<<<<<<< | BL32 | |
| 1842 | 0x04002000 +----------+ +----------------+ |
| 1843 | |fw_configs| |
| 1844 | 0x04001000 +----------+ |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 1845 | | Shared | |
| 1846 | 0x04000000 +----------+ |
| 1847 | |
| 1848 | Trusted ROM |
| 1849 | 0x04000000 +----------+ |
| 1850 | | BL1 (ro) | |
| 1851 | 0x00000000 +----------+ |
| 1852 | |
Soby Mathew | 492e245 | 2018-06-06 16:03:10 +0100 | [diff] [blame] | 1853 | **FVP with TSP in Trusted DRAM with firmware configs (default option):** |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 1854 | |
| 1855 | :: |
| 1856 | |
Soby Mathew | b1bf044 | 2018-02-16 14:52:52 +0000 | [diff] [blame] | 1857 | DRAM |
| 1858 | 0xffffffff +--------------+ |
| 1859 | : : |
| 1860 | |--------------| |
| 1861 | | HW_CONFIG | |
| 1862 | 0x83000000 |--------------| (non-secure) |
| 1863 | | | |
| 1864 | 0x80000000 +--------------+ |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 1865 | |
Soby Mathew | b1bf044 | 2018-02-16 14:52:52 +0000 | [diff] [blame] | 1866 | Trusted DRAM |
| 1867 | 0x08000000 +--------------+ |
| 1868 | | BL32 | |
| 1869 | 0x06000000 +--------------+ |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 1870 | |
Soby Mathew | b1bf044 | 2018-02-16 14:52:52 +0000 | [diff] [blame] | 1871 | Trusted SRAM |
Soby Mathew | 492e245 | 2018-06-06 16:03:10 +0100 | [diff] [blame] | 1872 | 0x04040000 +--------------+ loaded by BL2 +----------------+ |
| 1873 | | BL1 (rw) | <<<<<<<<<<<<< | | |
| 1874 | |--------------| <<<<<<<<<<<<< | BL31 NOBITS | |
| 1875 | | BL2 | <<<<<<<<<<<<< | | |
Soby Mathew | b1bf044 | 2018-02-16 14:52:52 +0000 | [diff] [blame] | 1876 | |--------------| <<<<<<<<<<<<< |----------------| |
| 1877 | | | <<<<<<<<<<<<< | BL31 PROGBITS | |
Soby Mathew | 492e245 | 2018-06-06 16:03:10 +0100 | [diff] [blame] | 1878 | | | +----------------+ |
| 1879 | +--------------+ |
| 1880 | | fw_configs | |
Soby Mathew | b1bf044 | 2018-02-16 14:52:52 +0000 | [diff] [blame] | 1881 | 0x04001000 +--------------+ |
| 1882 | | Shared | |
| 1883 | 0x04000000 +--------------+ |
| 1884 | |
| 1885 | Trusted ROM |
| 1886 | 0x04000000 +--------------+ |
| 1887 | | BL1 (ro) | |
| 1888 | 0x00000000 +--------------+ |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 1889 | |
Soby Mathew | 492e245 | 2018-06-06 16:03:10 +0100 | [diff] [blame] | 1890 | **FVP with TSP in TZC-Secured DRAM with firmware configs :** |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 1891 | |
| 1892 | :: |
| 1893 | |
| 1894 | DRAM |
| 1895 | 0xffffffff +----------+ |
Soby Mathew | b1bf044 | 2018-02-16 14:52:52 +0000 | [diff] [blame] | 1896 | | BL32 | (secure) |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 1897 | 0xff000000 +----------+ |
| 1898 | | | |
Soby Mathew | 492e245 | 2018-06-06 16:03:10 +0100 | [diff] [blame] | 1899 | |----------| |
| 1900 | |HW_CONFIG | |
| 1901 | 0x83000000 |----------| (non-secure) |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 1902 | | | |
| 1903 | 0x80000000 +----------+ |
| 1904 | |
| 1905 | Trusted SRAM |
Soby Mathew | 492e245 | 2018-06-06 16:03:10 +0100 | [diff] [blame] | 1906 | 0x04040000 +----------+ loaded by BL2 +----------------+ |
| 1907 | | BL1 (rw) | <<<<<<<<<<<<< | | |
| 1908 | |----------| <<<<<<<<<<<<< | BL31 NOBITS | |
| 1909 | | BL2 | <<<<<<<<<<<<< | | |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 1910 | |----------| <<<<<<<<<<<<< |----------------| |
| 1911 | | | <<<<<<<<<<<<< | BL31 PROGBITS | |
Soby Mathew | 492e245 | 2018-06-06 16:03:10 +0100 | [diff] [blame] | 1912 | | | +----------------+ |
| 1913 | 0x04002000 +----------+ |
| 1914 | |fw_configs| |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 1915 | 0x04001000 +----------+ |
| 1916 | | Shared | |
| 1917 | 0x04000000 +----------+ |
| 1918 | |
| 1919 | Trusted ROM |
| 1920 | 0x04000000 +----------+ |
| 1921 | | BL1 (ro) | |
| 1922 | 0x00000000 +----------+ |
| 1923 | |
Soby Mathew | 492e245 | 2018-06-06 16:03:10 +0100 | [diff] [blame] | 1924 | **Juno with BL32 in Trusted SRAM :** |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 1925 | |
| 1926 | :: |
| 1927 | |
| 1928 | Flash0 |
| 1929 | 0x0C000000 +----------+ |
| 1930 | : : |
| 1931 | 0x0BED0000 |----------| |
| 1932 | | BL1 (ro) | |
| 1933 | 0x0BEC0000 |----------| |
| 1934 | : : |
| 1935 | 0x08000000 +----------+ BL31 is loaded |
| 1936 | after SCP_BL2 has |
| 1937 | Trusted SRAM been sent to SCP |
Soby Mathew | 492e245 | 2018-06-06 16:03:10 +0100 | [diff] [blame] | 1938 | 0x04040000 +----------+ loaded by BL2 +----------------+ |
| 1939 | | BL1 (rw) | <<<<<<<<<<<<< | | |
| 1940 | |----------| <<<<<<<<<<<<< | BL31 NOBITS | |
| 1941 | | BL2 | <<<<<<<<<<<<< | | |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 1942 | |----------| <<<<<<<<<<<<< |----------------| |
| 1943 | | SCP_BL2 | <<<<<<<<<<<<< | BL31 PROGBITS | |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 1944 | |----------| <<<<<<<<<<<<< |----------------| |
Soby Mathew | 492e245 | 2018-06-06 16:03:10 +0100 | [diff] [blame] | 1945 | | | <<<<<<<<<<<<< | BL32 | |
| 1946 | | | +----------------+ |
| 1947 | | | |
| 1948 | 0x04001000 +----------+ |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 1949 | | MHU | |
| 1950 | 0x04000000 +----------+ |
| 1951 | |
Soby Mathew | 492e245 | 2018-06-06 16:03:10 +0100 | [diff] [blame] | 1952 | **Juno with BL32 in TZC-secured DRAM :** |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 1953 | |
| 1954 | :: |
| 1955 | |
| 1956 | DRAM |
| 1957 | 0xFFE00000 +----------+ |
Soby Mathew | b1bf044 | 2018-02-16 14:52:52 +0000 | [diff] [blame] | 1958 | | BL32 | (secure) |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 1959 | 0xFF000000 |----------| |
| 1960 | | | |
| 1961 | : : (non-secure) |
| 1962 | | | |
| 1963 | 0x80000000 +----------+ |
| 1964 | |
| 1965 | Flash0 |
| 1966 | 0x0C000000 +----------+ |
| 1967 | : : |
| 1968 | 0x0BED0000 |----------| |
| 1969 | | BL1 (ro) | |
| 1970 | 0x0BEC0000 |----------| |
| 1971 | : : |
| 1972 | 0x08000000 +----------+ BL31 is loaded |
| 1973 | after SCP_BL2 has |
| 1974 | Trusted SRAM been sent to SCP |
Soby Mathew | 492e245 | 2018-06-06 16:03:10 +0100 | [diff] [blame] | 1975 | 0x04040000 +----------+ loaded by BL2 +----------------+ |
| 1976 | | BL1 (rw) | <<<<<<<<<<<<< | | |
| 1977 | |----------| <<<<<<<<<<<<< | BL31 NOBITS | |
| 1978 | | BL2 | <<<<<<<<<<<<< | | |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 1979 | |----------| <<<<<<<<<<<<< |----------------| |
| 1980 | | SCP_BL2 | <<<<<<<<<<<<< | BL31 PROGBITS | |
Soby Mathew | 492e245 | 2018-06-06 16:03:10 +0100 | [diff] [blame] | 1981 | |----------| +----------------+ |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 1982 | 0x04001000 +----------+ |
| 1983 | | MHU | |
| 1984 | 0x04000000 +----------+ |
| 1985 | |
| 1986 | Firmware Image Package (FIP) |
| 1987 | ---------------------------- |
| 1988 | |
| 1989 | Using a Firmware Image Package (FIP) allows for packing bootloader images (and |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 1990 | potentially other payloads) into a single archive that can be loaded by TF-A |
| 1991 | from non-volatile platform storage. A driver to load images from a FIP has |
| 1992 | been added to the storage layer and allows a package to be read from supported |
| 1993 | platform storage. A tool to create Firmware Image Packages is also provided |
| 1994 | and described below. |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 1995 | |
| 1996 | Firmware Image Package layout |
| 1997 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 1998 | |
| 1999 | The FIP layout consists of a table of contents (ToC) followed by payload data. |
| 2000 | The ToC itself has a header followed by one or more table entries. The ToC is |
Jett Zhou | 7556610 | 2017-11-24 16:03:58 +0800 | [diff] [blame] | 2001 | terminated by an end marker entry, and since the size of the ToC is 0 bytes, |
| 2002 | the offset equals the total size of the FIP file. All ToC entries describe some |
| 2003 | payload data that has been appended to the end of the binary package. With the |
| 2004 | information provided in the ToC entry the corresponding payload data can be |
| 2005 | retrieved. |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 2006 | |
| 2007 | :: |
| 2008 | |
| 2009 | ------------------ |
| 2010 | | ToC Header | |
| 2011 | |----------------| |
| 2012 | | ToC Entry 0 | |
| 2013 | |----------------| |
| 2014 | | ToC Entry 1 | |
| 2015 | |----------------| |
| 2016 | | ToC End Marker | |
| 2017 | |----------------| |
| 2018 | | | |
| 2019 | | Data 0 | |
| 2020 | | | |
| 2021 | |----------------| |
| 2022 | | | |
| 2023 | | Data 1 | |
| 2024 | | | |
| 2025 | ------------------ |
| 2026 | |
| 2027 | The ToC header and entry formats are described in the header file |
| 2028 | ``include/tools_share/firmware_image_package.h``. This file is used by both the |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 2029 | tool and TF-A. |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 2030 | |
| 2031 | The ToC header has the following fields: |
| 2032 | |
| 2033 | :: |
| 2034 | |
| 2035 | `name`: The name of the ToC. This is currently used to validate the header. |
| 2036 | `serial_number`: A non-zero number provided by the creation tool |
| 2037 | `flags`: Flags associated with this data. |
| 2038 | Bits 0-31: Reserved |
| 2039 | Bits 32-47: Platform defined |
| 2040 | Bits 48-63: Reserved |
| 2041 | |
| 2042 | A ToC entry has the following fields: |
| 2043 | |
| 2044 | :: |
| 2045 | |
| 2046 | `uuid`: All files are referred to by a pre-defined Universally Unique |
| 2047 | IDentifier [UUID] . The UUIDs are defined in |
| 2048 | `include/tools_share/firmware_image_package.h`. The platform translates |
| 2049 | the requested image name into the corresponding UUID when accessing the |
| 2050 | package. |
| 2051 | `offset_address`: The offset address at which the corresponding payload data |
| 2052 | can be found. The offset is calculated from the ToC base address. |
| 2053 | `size`: The size of the corresponding payload data in bytes. |
Etienne Carriere | 7421bf1 | 2017-08-23 15:43:33 +0200 | [diff] [blame] | 2054 | `flags`: Flags associated with this entry. None are yet defined. |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 2055 | |
| 2056 | Firmware Image Package creation tool |
| 2057 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 2058 | |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 2059 | The FIP creation tool can be used to pack specified images into a binary |
| 2060 | package that can be loaded by TF-A from platform storage. The tool currently |
| 2061 | only supports packing bootloader images. Additional image definitions can be |
| 2062 | added to the tool as required. |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 2063 | |
| 2064 | The tool can be found in ``tools/fiptool``. |
| 2065 | |
| 2066 | Loading from a Firmware Image Package (FIP) |
| 2067 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 2068 | |
| 2069 | The Firmware Image Package (FIP) driver can load images from a binary package on |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 2070 | non-volatile platform storage. For the Arm development platforms, this is |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 2071 | currently NOR FLASH. |
| 2072 | |
| 2073 | Bootloader images are loaded according to the platform policy as specified by |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 2074 | the function ``plat_get_image_source()``. For the Arm development platforms, this |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 2075 | means the platform will attempt to load images from a Firmware Image Package |
| 2076 | located at the start of NOR FLASH0. |
| 2077 | |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 2078 | The Arm development platforms' policy is to only allow loading of a known set of |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 2079 | images. The platform policy can be modified to allow additional images. |
| 2080 | |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 2081 | Use of coherent memory in TF-A |
| 2082 | ------------------------------ |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 2083 | |
| 2084 | There might be loss of coherency when physical memory with mismatched |
| 2085 | shareability, cacheability and memory attributes is accessed by multiple CPUs |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 2086 | (refer to section B2.9 of `Arm ARM`_ for more details). This possibility occurs |
| 2087 | in TF-A during power up/down sequences when coherency, MMU and caches are |
| 2088 | turned on/off incrementally. |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 2089 | |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 2090 | TF-A defines coherent memory as a region of memory with Device nGnRE attributes |
| 2091 | in the translation tables. The translation granule size in TF-A is 4KB. This |
| 2092 | is the smallest possible size of the coherent memory region. |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 2093 | |
| 2094 | By default, all data structures which are susceptible to accesses with |
| 2095 | mismatched attributes from various CPUs are allocated in a coherent memory |
| 2096 | region (refer to section 2.1 of `Porting Guide`_). The coherent memory region |
| 2097 | accesses are Outer Shareable, non-cacheable and they can be accessed |
| 2098 | with the Device nGnRE attributes when the MMU is turned on. Hence, at the |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 2099 | expense of at least an extra page of memory, TF-A is able to work around |
| 2100 | coherency issues due to mismatched memory attributes. |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 2101 | |
| 2102 | The alternative to the above approach is to allocate the susceptible data |
| 2103 | structures in Normal WriteBack WriteAllocate Inner shareable memory. This |
| 2104 | approach requires the data structures to be designed so that it is possible to |
| 2105 | work around the issue of mismatched memory attributes by performing software |
| 2106 | cache maintenance on them. |
| 2107 | |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 2108 | Disabling the use of coherent memory in TF-A |
| 2109 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 2110 | |
| 2111 | It might be desirable to avoid the cost of allocating coherent memory on |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 2112 | platforms which are memory constrained. TF-A enables inclusion of coherent |
| 2113 | memory in firmware images through the build flag ``USE_COHERENT_MEM``. |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 2114 | This flag is enabled by default. It can be disabled to choose the second |
| 2115 | approach described above. |
| 2116 | |
| 2117 | The below sections analyze the data structures allocated in the coherent memory |
| 2118 | region and the changes required to allocate them in normal memory. |
| 2119 | |
| 2120 | Coherent memory usage in PSCI implementation |
| 2121 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 2122 | |
| 2123 | The ``psci_non_cpu_pd_nodes`` data structure stores the platform's power domain |
| 2124 | tree information for state management of power domains. By default, this data |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 2125 | structure is allocated in the coherent memory region in TF-A because it can be |
| 2126 | accessed by multple CPUs, either with caches enabled or disabled. |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 2127 | |
| 2128 | .. code:: c |
| 2129 | |
| 2130 | typedef struct non_cpu_pwr_domain_node { |
| 2131 | /* |
| 2132 | * Index of the first CPU power domain node level 0 which has this node |
| 2133 | * as its parent. |
| 2134 | */ |
| 2135 | unsigned int cpu_start_idx; |
| 2136 | |
| 2137 | /* |
| 2138 | * Number of CPU power domains which are siblings of the domain indexed |
| 2139 | * by 'cpu_start_idx' i.e. all the domains in the range 'cpu_start_idx |
| 2140 | * -> cpu_start_idx + ncpus' have this node as their parent. |
| 2141 | */ |
| 2142 | unsigned int ncpus; |
| 2143 | |
| 2144 | /* |
| 2145 | * Index of the parent power domain node. |
| 2146 | * TODO: Figure out whether to whether using pointer is more efficient. |
| 2147 | */ |
| 2148 | unsigned int parent_node; |
| 2149 | |
| 2150 | plat_local_state_t local_state; |
| 2151 | |
| 2152 | unsigned char level; |
| 2153 | |
| 2154 | /* For indexing the psci_lock array*/ |
| 2155 | unsigned char lock_index; |
| 2156 | } non_cpu_pd_node_t; |
| 2157 | |
| 2158 | In order to move this data structure to normal memory, the use of each of its |
| 2159 | fields must be analyzed. Fields like ``cpu_start_idx``, ``ncpus``, ``parent_node`` |
| 2160 | ``level`` and ``lock_index`` are only written once during cold boot. Hence removing |
| 2161 | them from coherent memory involves only doing a clean and invalidate of the |
| 2162 | cache lines after these fields are written. |
| 2163 | |
| 2164 | The field ``local_state`` can be concurrently accessed by multiple CPUs in |
| 2165 | different cache states. A Lamport's Bakery lock ``psci_locks`` is used to ensure |
| 2166 | mutual exlusion to this field and a clean and invalidate is needed after it |
| 2167 | is written. |
| 2168 | |
| 2169 | Bakery lock data |
| 2170 | ~~~~~~~~~~~~~~~~ |
| 2171 | |
| 2172 | The bakery lock data structure ``bakery_lock_t`` is allocated in coherent memory |
| 2173 | and is accessed by multiple CPUs with mismatched attributes. ``bakery_lock_t`` is |
| 2174 | defined as follows: |
| 2175 | |
| 2176 | .. code:: c |
| 2177 | |
| 2178 | typedef struct bakery_lock { |
| 2179 | /* |
| 2180 | * The lock_data is a bit-field of 2 members: |
| 2181 | * Bit[0] : choosing. This field is set when the CPU is |
| 2182 | * choosing its bakery number. |
| 2183 | * Bits[1 - 15] : number. This is the bakery number allocated. |
| 2184 | */ |
| 2185 | volatile uint16_t lock_data[BAKERY_LOCK_MAX_CPUS]; |
| 2186 | } bakery_lock_t; |
| 2187 | |
| 2188 | It is a characteristic of Lamport's Bakery algorithm that the volatile per-CPU |
| 2189 | fields can be read by all CPUs but only written to by the owning CPU. |
| 2190 | |
| 2191 | Depending upon the data cache line size, the per-CPU fields of the |
| 2192 | ``bakery_lock_t`` structure for multiple CPUs may exist on a single cache line. |
| 2193 | These per-CPU fields can be read and written during lock contention by multiple |
| 2194 | CPUs with mismatched memory attributes. Since these fields are a part of the |
| 2195 | lock implementation, they do not have access to any other locking primitive to |
| 2196 | safeguard against the resulting coherency issues. As a result, simple software |
| 2197 | cache maintenance is not enough to allocate them in coherent memory. Consider |
| 2198 | the following example. |
| 2199 | |
| 2200 | CPU0 updates its per-CPU field with data cache enabled. This write updates a |
| 2201 | local cache line which contains a copy of the fields for other CPUs as well. Now |
| 2202 | CPU1 updates its per-CPU field of the ``bakery_lock_t`` structure with data cache |
| 2203 | disabled. CPU1 then issues a DCIVAC operation to invalidate any stale copies of |
| 2204 | its field in any other cache line in the system. This operation will invalidate |
| 2205 | the update made by CPU0 as well. |
| 2206 | |
| 2207 | To use bakery locks when ``USE_COHERENT_MEM`` is disabled, the lock data structure |
| 2208 | has been redesigned. The changes utilise the characteristic of Lamport's Bakery |
| 2209 | algorithm mentioned earlier. The bakery\_lock structure only allocates the memory |
| 2210 | for a single CPU. The macro ``DEFINE_BAKERY_LOCK`` allocates all the bakery locks |
| 2211 | needed for a CPU into a section ``bakery_lock``. The linker allocates the memory |
| 2212 | for other cores by using the total size allocated for the bakery\_lock section |
| 2213 | and multiplying it with (PLATFORM\_CORE\_COUNT - 1). This enables software to |
| 2214 | perform software cache maintenance on the lock data structure without running |
| 2215 | into coherency issues associated with mismatched attributes. |
| 2216 | |
| 2217 | The bakery lock data structure ``bakery_info_t`` is defined for use when |
| 2218 | ``USE_COHERENT_MEM`` is disabled as follows: |
| 2219 | |
| 2220 | .. code:: c |
| 2221 | |
| 2222 | typedef struct bakery_info { |
| 2223 | /* |
| 2224 | * The lock_data is a bit-field of 2 members: |
| 2225 | * Bit[0] : choosing. This field is set when the CPU is |
| 2226 | * choosing its bakery number. |
| 2227 | * Bits[1 - 15] : number. This is the bakery number allocated. |
| 2228 | */ |
| 2229 | volatile uint16_t lock_data; |
| 2230 | } bakery_info_t; |
| 2231 | |
| 2232 | The ``bakery_info_t`` represents a single per-CPU field of one lock and |
| 2233 | the combination of corresponding ``bakery_info_t`` structures for all CPUs in the |
| 2234 | system represents the complete bakery lock. The view in memory for a system |
| 2235 | with n bakery locks are: |
| 2236 | |
| 2237 | :: |
| 2238 | |
| 2239 | bakery_lock section start |
| 2240 | |----------------| |
| 2241 | | `bakery_info_t`| <-- Lock_0 per-CPU field |
| 2242 | | Lock_0 | for CPU0 |
| 2243 | |----------------| |
| 2244 | | `bakery_info_t`| <-- Lock_1 per-CPU field |
| 2245 | | Lock_1 | for CPU0 |
| 2246 | |----------------| |
| 2247 | | .... | |
| 2248 | |----------------| |
| 2249 | | `bakery_info_t`| <-- Lock_N per-CPU field |
| 2250 | | Lock_N | for CPU0 |
| 2251 | ------------------ |
| 2252 | | XXXXX | |
| 2253 | | Padding to | |
| 2254 | | next Cache WB | <--- Calculate PERCPU_BAKERY_LOCK_SIZE, allocate |
| 2255 | | Granule | continuous memory for remaining CPUs. |
| 2256 | ------------------ |
| 2257 | | `bakery_info_t`| <-- Lock_0 per-CPU field |
| 2258 | | Lock_0 | for CPU1 |
| 2259 | |----------------| |
| 2260 | | `bakery_info_t`| <-- Lock_1 per-CPU field |
| 2261 | | Lock_1 | for CPU1 |
| 2262 | |----------------| |
| 2263 | | .... | |
| 2264 | |----------------| |
| 2265 | | `bakery_info_t`| <-- Lock_N per-CPU field |
| 2266 | | Lock_N | for CPU1 |
| 2267 | ------------------ |
| 2268 | | XXXXX | |
| 2269 | | Padding to | |
| 2270 | | next Cache WB | |
| 2271 | | Granule | |
| 2272 | ------------------ |
| 2273 | |
| 2274 | Consider a system of 2 CPUs with 'N' bakery locks as shown above. For an |
| 2275 | operation on Lock\_N, the corresponding ``bakery_info_t`` in both CPU0 and CPU1 |
| 2276 | ``bakery_lock`` section need to be fetched and appropriate cache operations need |
| 2277 | to be performed for each access. |
| 2278 | |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 2279 | On Arm Platforms, bakery locks are used in psci (``psci_locks``) and power controller |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 2280 | driver (``arm_lock``). |
| 2281 | |
| 2282 | Non Functional Impact of removing coherent memory |
| 2283 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 2284 | |
| 2285 | Removal of the coherent memory region leads to the additional software overhead |
| 2286 | of performing cache maintenance for the affected data structures. However, since |
| 2287 | the memory where the data structures are allocated is cacheable, the overhead is |
| 2288 | mostly mitigated by an increase in performance. |
| 2289 | |
| 2290 | There is however a performance impact for bakery locks, due to: |
| 2291 | |
| 2292 | - Additional cache maintenance operations, and |
| 2293 | - Multiple cache line reads for each lock operation, since the bakery locks |
| 2294 | for each CPU are distributed across different cache lines. |
| 2295 | |
| 2296 | The implementation has been optimized to minimize this additional overhead. |
| 2297 | Measurements indicate that when bakery locks are allocated in Normal memory, the |
| 2298 | minimum latency of acquiring a lock is on an average 3-4 micro seconds whereas |
| 2299 | in Device memory the same is 2 micro seconds. The measurements were done on the |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 2300 | Juno Arm development platform. |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 2301 | |
| 2302 | As mentioned earlier, almost a page of memory can be saved by disabling |
| 2303 | ``USE_COHERENT_MEM``. Each platform needs to consider these trade-offs to decide |
| 2304 | whether coherent memory should be used. If a platform disables |
| 2305 | ``USE_COHERENT_MEM`` and needs to use bakery locks in the porting layer, it can |
| 2306 | optionally define macro ``PLAT_PERCPU_BAKERY_LOCK_SIZE`` (see the |
| 2307 | `Porting Guide`_). Refer to the reference platform code for examples. |
| 2308 | |
| 2309 | Isolating code and read-only data on separate memory pages |
| 2310 | ---------------------------------------------------------- |
| 2311 | |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 2312 | In the Armv8-A VMSA, translation table entries include fields that define the |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 2313 | properties of the target memory region, such as its access permissions. The |
| 2314 | smallest unit of memory that can be addressed by a translation table entry is |
| 2315 | a memory page. Therefore, if software needs to set different permissions on two |
| 2316 | memory regions then it needs to map them using different memory pages. |
| 2317 | |
| 2318 | The default memory layout for each BL image is as follows: |
| 2319 | |
| 2320 | :: |
| 2321 | |
| 2322 | | ... | |
| 2323 | +-------------------+ |
| 2324 | | Read-write data | |
| 2325 | +-------------------+ Page boundary |
| 2326 | | <Padding> | |
| 2327 | +-------------------+ |
| 2328 | | Exception vectors | |
| 2329 | +-------------------+ 2 KB boundary |
| 2330 | | <Padding> | |
| 2331 | +-------------------+ |
| 2332 | | Read-only data | |
| 2333 | +-------------------+ |
| 2334 | | Code | |
| 2335 | +-------------------+ BLx_BASE |
| 2336 | |
| 2337 | Note: The 2KB alignment for the exception vectors is an architectural |
| 2338 | requirement. |
| 2339 | |
| 2340 | The read-write data start on a new memory page so that they can be mapped with |
| 2341 | read-write permissions, whereas the code and read-only data below are configured |
| 2342 | as read-only. |
| 2343 | |
| 2344 | However, the read-only data are not aligned on a page boundary. They are |
| 2345 | contiguous to the code. Therefore, the end of the code section and the beginning |
| 2346 | of the read-only data one might share a memory page. This forces both to be |
| 2347 | mapped with the same memory attributes. As the code needs to be executable, this |
| 2348 | means that the read-only data stored on the same memory page as the code are |
| 2349 | executable as well. This could potentially be exploited as part of a security |
| 2350 | attack. |
| 2351 | |
| 2352 | TF provides the build flag ``SEPARATE_CODE_AND_RODATA`` to isolate the code and |
| 2353 | read-only data on separate memory pages. This in turn allows independent control |
| 2354 | of the access permissions for the code and read-only data. In this case, |
| 2355 | platform code gets a finer-grained view of the image layout and can |
| 2356 | appropriately map the code region as executable and the read-only data as |
| 2357 | execute-never. |
| 2358 | |
| 2359 | This has an impact on memory footprint, as padding bytes need to be introduced |
| 2360 | between the code and read-only data to ensure the segragation of the two. To |
| 2361 | limit the memory cost, this flag also changes the memory layout such that the |
| 2362 | code and exception vectors are now contiguous, like so: |
| 2363 | |
| 2364 | :: |
| 2365 | |
| 2366 | | ... | |
| 2367 | +-------------------+ |
| 2368 | | Read-write data | |
| 2369 | +-------------------+ Page boundary |
| 2370 | | <Padding> | |
| 2371 | +-------------------+ |
| 2372 | | Read-only data | |
| 2373 | +-------------------+ Page boundary |
| 2374 | | <Padding> | |
| 2375 | +-------------------+ |
| 2376 | | Exception vectors | |
| 2377 | +-------------------+ 2 KB boundary |
| 2378 | | <Padding> | |
| 2379 | +-------------------+ |
| 2380 | | Code | |
| 2381 | +-------------------+ BLx_BASE |
| 2382 | |
| 2383 | With this more condensed memory layout, the separation of read-only data will |
| 2384 | add zero or one page to the memory footprint of each BL image. Each platform |
| 2385 | should consider the trade-off between memory footprint and security. |
| 2386 | |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 2387 | This build flag is disabled by default, minimising memory footprint. On Arm |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 2388 | platforms, it is enabled. |
| 2389 | |
Jeenu Viswambharan | e3f2200 | 2017-09-22 08:32:10 +0100 | [diff] [blame] | 2390 | Publish and Subscribe Framework |
| 2391 | ------------------------------- |
| 2392 | |
| 2393 | The Publish and Subscribe Framework allows EL3 components to define and publish |
| 2394 | events, to which other EL3 components can subscribe. |
| 2395 | |
| 2396 | The following macros are provided by the framework: |
| 2397 | |
| 2398 | - ``REGISTER_PUBSUB_EVENT(event)``: Defines an event, and takes one argument, |
| 2399 | the event name, which must be a valid C identifier. All calls to |
| 2400 | ``REGISTER_PUBSUB_EVENT`` macro must be placed in the file |
| 2401 | ``pubsub_events.h``. |
| 2402 | |
| 2403 | - ``PUBLISH_EVENT_ARG(event, arg)``: Publishes a defined event, by iterating |
| 2404 | subscribed handlers and calling them in turn. The handlers will be passed the |
| 2405 | parameter ``arg``. The expected use-case is to broadcast an event. |
| 2406 | |
| 2407 | - ``PUBLISH_EVENT(event)``: Like ``PUBLISH_EVENT_ARG``, except that the value |
| 2408 | ``NULL`` is passed to subscribed handlers. |
| 2409 | |
| 2410 | - ``SUBSCRIBE_TO_EVENT(event, handler)``: Registers the ``handler`` to |
| 2411 | subscribe to ``event``. The handler will be executed whenever the ``event`` |
| 2412 | is published. |
| 2413 | |
| 2414 | - ``for_each_subscriber(event, subscriber)``: Iterates through all handlers |
| 2415 | subscribed for ``event``. ``subscriber`` must be a local variable of type |
| 2416 | ``pubsub_cb_t *``, and will point to each subscribed handler in turn during |
| 2417 | iteration. This macro can be used for those patterns that none of the |
| 2418 | ``PUBLISH_EVENT_*()`` macros cover. |
| 2419 | |
| 2420 | Publishing an event that wasn't defined using ``REGISTER_PUBSUB_EVENT`` will |
| 2421 | result in build error. Subscribing to an undefined event however won't. |
| 2422 | |
| 2423 | Subscribed handlers must be of type ``pubsub_cb_t``, with following function |
| 2424 | signature: |
| 2425 | |
| 2426 | :: |
| 2427 | |
| 2428 | typedef void* (*pubsub_cb_t)(const void *arg); |
| 2429 | |
| 2430 | There may be arbitrary number of handlers registered to the same event. The |
| 2431 | order in which subscribed handlers are notified when that event is published is |
| 2432 | not defined. Subscribed handlers may be executed in any order; handlers should |
| 2433 | not assume any relative ordering amongst them. |
| 2434 | |
| 2435 | Publishing an event on a PE will result in subscribed handlers executing on that |
| 2436 | PE only; it won't cause handlers to execute on a different PE. |
| 2437 | |
| 2438 | Note that publishing an event on a PE blocks until all the subscribed handlers |
| 2439 | finish executing on the PE. |
| 2440 | |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 2441 | TF-A generic code publishes and subscribes to some events within. Platform |
| 2442 | ports are discouraged from subscribing to them. These events may be withdrawn, |
| 2443 | renamed, or have their semantics altered in the future. Platforms may however |
| 2444 | register, publish, and subscribe to platform-specific events. |
Dimitris Papastamos | a7921b9 | 2017-10-13 15:27:58 +0100 | [diff] [blame] | 2445 | |
Jeenu Viswambharan | e3f2200 | 2017-09-22 08:32:10 +0100 | [diff] [blame] | 2446 | Publish and Subscribe Example |
| 2447 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 2448 | |
| 2449 | A publisher that wants to publish event ``foo`` would: |
| 2450 | |
| 2451 | - Define the event ``foo`` in the ``pubsub_events.h``. |
| 2452 | |
| 2453 | :: |
| 2454 | |
| 2455 | REGISTER_PUBSUB_EVENT(foo); |
| 2456 | |
| 2457 | - Depending on the nature of event, use one of ``PUBLISH_EVENT_*()`` macros to |
| 2458 | publish the event at the appropriate path and time of execution. |
| 2459 | |
| 2460 | A subscriber that wants to subscribe to event ``foo`` published above would |
| 2461 | implement: |
| 2462 | |
| 2463 | :: |
| 2464 | |
| 2465 | void *foo_handler(const void *arg) |
| 2466 | { |
| 2467 | void *result; |
| 2468 | |
| 2469 | /* Do handling ... */ |
| 2470 | |
| 2471 | return result; |
| 2472 | } |
| 2473 | |
| 2474 | SUBSCRIBE_TO_EVENT(foo, foo_handler); |
| 2475 | |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 2476 | Performance Measurement Framework |
| 2477 | --------------------------------- |
| 2478 | |
| 2479 | The Performance Measurement Framework (PMF) facilitates collection of |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 2480 | timestamps by registered services and provides interfaces to retrieve them |
| 2481 | from within TF-A. A platform can choose to expose appropriate SMCs to |
| 2482 | retrieve these collected timestamps. |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 2483 | |
| 2484 | By default, the global physical counter is used for the timestamp |
| 2485 | value and is read via ``CNTPCT_EL0``. The framework allows to retrieve |
| 2486 | timestamps captured by other CPUs. |
| 2487 | |
| 2488 | Timestamp identifier format |
| 2489 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 2490 | |
| 2491 | A PMF timestamp is uniquely identified across the system via the |
| 2492 | timestamp ID or ``tid``. The ``tid`` is composed as follows: |
| 2493 | |
| 2494 | :: |
| 2495 | |
| 2496 | Bits 0-7: The local timestamp identifier. |
| 2497 | Bits 8-9: Reserved. |
| 2498 | Bits 10-15: The service identifier. |
| 2499 | Bits 16-31: Reserved. |
| 2500 | |
| 2501 | #. The service identifier. Each PMF service is identified by a |
| 2502 | service name and a service identifier. Both the service name and |
| 2503 | identifier are unique within the system as a whole. |
| 2504 | |
| 2505 | #. The local timestamp identifier. This identifier is unique within a given |
| 2506 | service. |
| 2507 | |
| 2508 | Registering a PMF service |
| 2509 | ~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 2510 | |
| 2511 | To register a PMF service, the ``PMF_REGISTER_SERVICE()`` macro from ``pmf.h`` |
| 2512 | is used. The arguments required are the service name, the service ID, |
| 2513 | the total number of local timestamps to be captured and a set of flags. |
| 2514 | |
| 2515 | The ``flags`` field can be specified as a bitwise-OR of the following values: |
| 2516 | |
| 2517 | :: |
| 2518 | |
| 2519 | PMF_STORE_ENABLE: The timestamp is stored in memory for later retrieval. |
| 2520 | PMF_DUMP_ENABLE: The timestamp is dumped on the serial console. |
| 2521 | |
| 2522 | The ``PMF_REGISTER_SERVICE()`` reserves memory to store captured |
| 2523 | timestamps in a PMF specific linker section at build time. |
| 2524 | Additionally, it defines necessary functions to capture and |
| 2525 | retrieve a particular timestamp for the given service at runtime. |
| 2526 | |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 2527 | The macro ``PMF_REGISTER_SERVICE()`` only enables capturing PMF timestamps |
| 2528 | from within TF-A. In order to retrieve timestamps from outside of TF-A, the |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 2529 | ``PMF_REGISTER_SERVICE_SMC()`` macro must be used instead. This macro |
| 2530 | accepts the same set of arguments as the ``PMF_REGISTER_SERVICE()`` |
| 2531 | macro but additionally supports retrieving timestamps using SMCs. |
| 2532 | |
| 2533 | Capturing a timestamp |
| 2534 | ~~~~~~~~~~~~~~~~~~~~~ |
| 2535 | |
| 2536 | PMF timestamps are stored in a per-service timestamp region. On a |
| 2537 | system with multiple CPUs, each timestamp is captured and stored |
| 2538 | in a per-CPU cache line aligned memory region. |
| 2539 | |
| 2540 | Having registered the service, the ``PMF_CAPTURE_TIMESTAMP()`` macro can be |
| 2541 | used to capture a timestamp at the location where it is used. The macro |
| 2542 | takes the service name, a local timestamp identifier and a flag as arguments. |
| 2543 | |
| 2544 | The ``flags`` field argument can be zero, or ``PMF_CACHE_MAINT`` which |
| 2545 | instructs PMF to do cache maintenance following the capture. Cache |
| 2546 | maintenance is required if any of the service's timestamps are captured |
| 2547 | with data cache disabled. |
| 2548 | |
| 2549 | To capture a timestamp in assembly code, the caller should use |
| 2550 | ``pmf_calc_timestamp_addr`` macro (defined in ``pmf_asm_macros.S``) to |
| 2551 | calculate the address of where the timestamp would be stored. The |
| 2552 | caller should then read ``CNTPCT_EL0`` register to obtain the timestamp |
| 2553 | and store it at the determined address for later retrieval. |
| 2554 | |
| 2555 | Retrieving a timestamp |
| 2556 | ~~~~~~~~~~~~~~~~~~~~~~ |
| 2557 | |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 2558 | From within TF-A, timestamps for individual CPUs can be retrieved using either |
| 2559 | ``PMF_GET_TIMESTAMP_BY_MPIDR()`` or ``PMF_GET_TIMESTAMP_BY_INDEX()`` macros. |
| 2560 | These macros accept the CPU's MPIDR value, or its ordinal position |
| 2561 | respectively. |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 2562 | |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 2563 | From outside TF-A, timestamps for individual CPUs can be retrieved by calling |
| 2564 | into ``pmf_smc_handler()``. |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 2565 | |
| 2566 | .. code:: c |
| 2567 | |
| 2568 | Interface : pmf_smc_handler() |
| 2569 | Argument : unsigned int smc_fid, u_register_t x1, |
| 2570 | u_register_t x2, u_register_t x3, |
| 2571 | u_register_t x4, void *cookie, |
| 2572 | void *handle, u_register_t flags |
| 2573 | Return : uintptr_t |
| 2574 | |
| 2575 | smc_fid: Holds the SMC identifier which is either `PMF_SMC_GET_TIMESTAMP_32` |
| 2576 | when the caller of the SMC is running in AArch32 mode |
| 2577 | or `PMF_SMC_GET_TIMESTAMP_64` when the caller is running in AArch64 mode. |
| 2578 | x1: Timestamp identifier. |
| 2579 | x2: The `mpidr` of the CPU for which the timestamp has to be retrieved. |
| 2580 | This can be the `mpidr` of a different core to the one initiating |
| 2581 | the SMC. In that case, service specific cache maintenance may be |
| 2582 | required to ensure the updated copy of the timestamp is returned. |
| 2583 | x3: A flags value that is either 0 or `PMF_CACHE_MAINT`. If |
| 2584 | `PMF_CACHE_MAINT` is passed, then the PMF code will perform a |
| 2585 | cache invalidate before reading the timestamp. This ensures |
| 2586 | an updated copy is returned. |
| 2587 | |
| 2588 | The remaining arguments, ``x4``, ``cookie``, ``handle`` and ``flags`` are unused |
| 2589 | in this implementation. |
| 2590 | |
| 2591 | PMF code structure |
| 2592 | ~~~~~~~~~~~~~~~~~~ |
| 2593 | |
| 2594 | #. ``pmf_main.c`` consists of core functions that implement service registration, |
| 2595 | initialization, storing, dumping and retrieving timestamps. |
| 2596 | |
| 2597 | #. ``pmf_smc.c`` contains the SMC handling for registered PMF services. |
| 2598 | |
| 2599 | #. ``pmf.h`` contains the public interface to Performance Measurement Framework. |
| 2600 | |
| 2601 | #. ``pmf_asm_macros.S`` consists of macros to facilitate capturing timestamps in |
| 2602 | assembly code. |
| 2603 | |
| 2604 | #. ``pmf_helpers.h`` is an internal header used by ``pmf.h``. |
| 2605 | |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 2606 | Armv8-A Architecture Extensions |
| 2607 | ------------------------------- |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 2608 | |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 2609 | TF-A makes use of Armv8-A Architecture Extensions where applicable. This |
| 2610 | section lists the usage of Architecture Extensions, and build flags |
| 2611 | controlling them. |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 2612 | |
| 2613 | In general, and unless individually mentioned, the build options |
| 2614 | ``ARM_ARCH_MAJOR`` and ``ARM_ARCH_MINOR`` selects the Architecture Extension to |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 2615 | target when building TF-A. Subsequent Arm Architecture Extensions are backward |
| 2616 | compatible with previous versions. |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 2617 | |
| 2618 | The build system only requires that ``ARM_ARCH_MAJOR`` and ``ARM_ARCH_MINOR`` have a |
| 2619 | valid numeric value. These build options only control whether or not |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 2620 | Architecture Extension-specific code is included in the build. Otherwise, TF-A |
| 2621 | targets the base Armv8.0-A architecture; i.e. as if ``ARM_ARCH_MAJOR`` == 8 |
| 2622 | and ``ARM_ARCH_MINOR`` == 0, which are also their respective default values. |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 2623 | |
| 2624 | See also the *Summary of build options* in `User Guide`_. |
| 2625 | |
| 2626 | For details on the Architecture Extension and available features, please refer |
| 2627 | to the respective Architecture Extension Supplement. |
| 2628 | |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 2629 | Armv8.1-A |
| 2630 | ~~~~~~~~~ |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 2631 | |
| 2632 | This Architecture Extension is targeted when ``ARM_ARCH_MAJOR`` >= 8, or when |
| 2633 | ``ARM_ARCH_MAJOR`` == 8 and ``ARM_ARCH_MINOR`` >= 1. |
| 2634 | |
| 2635 | - The Compare and Swap instruction is used to implement spinlocks. Otherwise, |
| 2636 | the load-/store-exclusive instruction pair is used. |
| 2637 | |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 2638 | Armv8.2-A |
| 2639 | ~~~~~~~~~ |
Isla Mitchell | c4a1a07 | 2017-08-07 11:20:13 +0100 | [diff] [blame] | 2640 | |
| 2641 | This Architecture Extension is targeted when ``ARM_ARCH_MAJOR`` == 8 and |
| 2642 | ``ARM_ARCH_MINOR`` >= 2. |
| 2643 | |
| 2644 | - The Common not Private (CnP) bit is enabled to indicate that multiple |
Sandrine Bailleux | fee6e26 | 2018-01-29 14:48:15 +0100 | [diff] [blame] | 2645 | Processing Elements in the same Inner Shareable domain use the same |
| 2646 | translation table entries for a given stage of translation for a particular |
| 2647 | translation regime. |
Isla Mitchell | c4a1a07 | 2017-08-07 11:20:13 +0100 | [diff] [blame] | 2648 | |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 2649 | Armv7-A |
| 2650 | ~~~~~~~ |
Etienne Carriere | 1374fcb | 2017-11-08 13:48:40 +0100 | [diff] [blame] | 2651 | |
| 2652 | This Architecture Extension is targeted when ``ARM_ARCH_MAJOR`` == 7. |
| 2653 | |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 2654 | There are several Armv7-A extensions available. Obviously the TrustZone |
| 2655 | extension is mandatory to support the TF-A bootloader and runtime services. |
Etienne Carriere | 1374fcb | 2017-11-08 13:48:40 +0100 | [diff] [blame] | 2656 | |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 2657 | Platform implementing an Armv7-A system can to define from its target |
Etienne Carriere | 1374fcb | 2017-11-08 13:48:40 +0100 | [diff] [blame] | 2658 | Cortex-A architecture through ``ARM_CORTEX_A<X> = yes`` in their |
| 2659 | ``plaform.mk`` script. For example ``ARM_CORTEX_A15=yes`` for a |
| 2660 | Cortex-A15 target. |
| 2661 | |
| 2662 | Platform can also set ``ARM_WITH_NEON=yes`` to enable neon support. |
| 2663 | Note that using neon at runtime has constraints on non secure wolrd context. |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 2664 | TF-A does not yet provide VFP context management. |
Etienne Carriere | 1374fcb | 2017-11-08 13:48:40 +0100 | [diff] [blame] | 2665 | |
| 2666 | Directive ``ARM_CORTEX_A<x>`` and ``ARM_WITH_NEON`` are used to set |
| 2667 | the toolchain target architecture directive. |
| 2668 | |
| 2669 | Platform may choose to not define straight the toolchain target architecture |
| 2670 | directive by defining ``MARCH32_DIRECTIVE``. |
| 2671 | I.e: |
| 2672 | |
| 2673 | :: |
| 2674 | |
| 2675 | MARCH32_DIRECTIVE := -mach=armv7-a |
| 2676 | |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 2677 | Code Structure |
| 2678 | -------------- |
| 2679 | |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 2680 | TF-A code is logically divided between the three boot loader stages mentioned |
| 2681 | in the previous sections. The code is also divided into the following |
| 2682 | categories (present as directories in the source code): |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 2683 | |
| 2684 | - **Platform specific.** Choice of architecture specific code depends upon |
| 2685 | the platform. |
| 2686 | - **Common code.** This is platform and architecture agnostic code. |
| 2687 | - **Library code.** This code comprises of functionality commonly used by all |
| 2688 | other code. The PSCI implementation and other EL3 runtime frameworks reside |
| 2689 | as Library components. |
| 2690 | - **Stage specific.** Code specific to a boot stage. |
| 2691 | - **Drivers.** |
| 2692 | - **Services.** EL3 runtime services (eg: SPD). Specific SPD services |
| 2693 | reside in the ``services/spd`` directory (e.g. ``services/spd/tspd``). |
| 2694 | |
| 2695 | Each boot loader stage uses code from one or more of the above mentioned |
| 2696 | categories. Based upon the above, the code layout looks like this: |
| 2697 | |
| 2698 | :: |
| 2699 | |
| 2700 | Directory Used by BL1? Used by BL2? Used by BL31? |
| 2701 | bl1 Yes No No |
| 2702 | bl2 No Yes No |
| 2703 | bl31 No No Yes |
| 2704 | plat Yes Yes Yes |
| 2705 | drivers Yes No Yes |
| 2706 | common Yes Yes Yes |
| 2707 | lib Yes Yes Yes |
| 2708 | services No No Yes |
| 2709 | |
| 2710 | The build system provides a non configurable build option IMAGE\_BLx for each |
| 2711 | boot loader stage (where x = BL stage). e.g. for BL1 , IMAGE\_BL1 will be |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 2712 | defined by the build system. This enables TF-A to compile certain code only |
| 2713 | for specific boot loader stages |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 2714 | |
| 2715 | All assembler files have the ``.S`` extension. The linker source files for each |
| 2716 | boot stage have the extension ``.ld.S``. These are processed by GCC to create the |
| 2717 | linker scripts which have the extension ``.ld``. |
| 2718 | |
| 2719 | FDTs provide a description of the hardware platform and are used by the Linux |
| 2720 | kernel at boot time. These can be found in the ``fdts`` directory. |
| 2721 | |
| 2722 | References |
| 2723 | ---------- |
| 2724 | |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 2725 | .. [#] Trusted Board Boot Requirements CLIENT PDD (Arm DEN0006C-1). Available |
| 2726 | under NDA through your Arm account representative. |
Douglas Raillard | 30d7b36 | 2017-06-28 16:14:55 +0100 | [diff] [blame] | 2727 | .. [#] `Power State Coordination Interface PDD`_ |
| 2728 | .. [#] `SMC Calling Convention PDD`_ |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 2729 | .. [#] `TF-A Interrupt Management Design guide`_. |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 2730 | |
| 2731 | -------------- |
| 2732 | |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 2733 | *Copyright (c) 2013-2018, Arm Limited and Contributors. All rights reserved.* |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 2734 | |
| 2735 | .. _Reset Design: ./reset-design.rst |
| 2736 | .. _Porting Guide: ./porting-guide.rst |
| 2737 | .. _Firmware Update: ./firmware-update.rst |
| 2738 | .. _PSCI PDD: http://infocenter.arm.com/help/topic/com.arm.doc.den0022d/Power_State_Coordination_Interface_PDD_v1_1_DEN0022D.pdf |
| 2739 | .. _SMC calling convention PDD: http://infocenter.arm.com/help/topic/com.arm.doc.den0028b/ARM_DEN0028B_SMC_Calling_Convention.pdf |
| 2740 | .. _PSCI Library integration guide: ./psci-lib-integration-guide.rst |
| 2741 | .. _SMCCC: http://infocenter.arm.com/help/topic/com.arm.doc.den0028b/ARM_DEN0028B_SMC_Calling_Convention.pdf |
| 2742 | .. _PSCI: http://infocenter.arm.com/help/topic/com.arm.doc.den0022d/Power_State_Coordination_Interface_PDD_v1_1_DEN0022D.pdf |
| 2743 | .. _Power State Coordination Interface PDD: http://infocenter.arm.com/help/topic/com.arm.doc.den0022d/Power_State_Coordination_Interface_PDD_v1_1_DEN0022D.pdf |
| 2744 | .. _here: ./psci-lib-integration-guide.rst |
| 2745 | .. _cpu-specific-build-macros.rst: ./cpu-specific-build-macros.rst |
| 2746 | .. _CPUBM: ./cpu-specific-build-macros.rst |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 2747 | .. _Arm ARM: http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0487a.e/index.html |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 2748 | .. _User Guide: ./user-guide.rst |
| 2749 | .. _SMC Calling Convention PDD: http://infocenter.arm.com/help/topic/com.arm.doc.den0028b/ARM_DEN0028B_SMC_Calling_Convention.pdf |
Dan Handley | 610e7e1 | 2018-03-01 18:44:00 +0000 | [diff] [blame] | 2750 | .. _TF-A Interrupt Management Design guide: ./interrupt-framework-design.rst |
Antonio Nino Diaz | b5d6809 | 2017-05-23 11:49:22 +0100 | [diff] [blame] | 2751 | .. _Xlat_tables design: xlat-tables-lib-v2-design.rst |
Douglas Raillard | d7c21b7 | 2017-06-28 15:23:03 +0100 | [diff] [blame] | 2752 | |
| 2753 | .. |Image 1| image:: diagrams/rt-svc-descs-layout.png?raw=true |