Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1 | ARM Trusted Firmware Porting Guide |
| 2 | ================================== |
| 3 | |
| 4 | Contents |
| 5 | -------- |
| 6 | |
Joakim Bech | 14a5b34 | 2014-11-25 10:55:26 +0100 | [diff] [blame] | 7 | 1. [Introduction](#1--introduction) |
| 8 | 2. [Common Modifications](#2--common-modifications) |
| 9 | * [Common mandatory modifications](#21-common-mandatory-modifications) |
| 10 | * [Handling reset](#22-handling-reset) |
| 11 | * [Common optional modifications](#23-common-optional-modifications) |
| 12 | 3. [Boot Loader stage specific modifications](#3--modifications-specific-to-a-boot-loader-stage) |
| 13 | * [Boot Loader stage 1 (BL1)](#31-boot-loader-stage-1-bl1) |
| 14 | * [Boot Loader stage 2 (BL2)](#32-boot-loader-stage-2-bl2) |
| 15 | * [Boot Loader stage 3-1 (BL3-1)](#32-boot-loader-stage-3-1-bl3-1) |
| 16 | * [PSCI implementation (in BL3-1)](#33-power-state-coordination-interface-in-bl3-1) |
| 17 | * [Interrupt Management framework (in BL3-1)](#34--interrupt-management-framework-in-bl3-1) |
| 18 | * [Crash Reporting mechanism (in BL3-1)](#35--crash-reporting-mechanism-in-bl3-1) |
| 19 | 4. [Build flags](#4--build-flags) |
| 20 | 5. [C Library](#5--c-library) |
| 21 | 6. [Storage abstraction layer](#6--storage-abstraction-layer) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 22 | |
| 23 | - - - - - - - - - - - - - - - - - - |
| 24 | |
| 25 | 1. Introduction |
| 26 | ---------------- |
| 27 | |
| 28 | Porting the ARM Trusted Firmware to a new platform involves making some |
| 29 | mandatory and optional modifications for both the cold and warm boot paths. |
| 30 | Modifications consist of: |
| 31 | |
| 32 | * Implementing a platform-specific function or variable, |
| 33 | * Setting up the execution context in a certain way, or |
| 34 | * Defining certain constants (for example #defines). |
| 35 | |
Dan Handley | b68954c | 2014-05-29 12:30:24 +0100 | [diff] [blame] | 36 | The platform-specific functions and variables are all declared in |
| 37 | [include/plat/common/platform.h]. The firmware provides a default implementation |
| 38 | of variables and functions to fulfill the optional requirements. These |
| 39 | implementations are all weakly defined; they are provided to ease the porting |
| 40 | effort. Each platform port can override them with its own implementation if the |
| 41 | default implementation is inadequate. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 42 | |
| 43 | Some modifications are common to all Boot Loader (BL) stages. Section 2 |
| 44 | discusses these in detail. The subsequent sections discuss the remaining |
| 45 | modifications for each BL stage in detail. |
| 46 | |
| 47 | This document should be read in conjunction with the ARM Trusted Firmware |
| 48 | [User Guide]. |
| 49 | |
| 50 | |
| 51 | 2. Common modifications |
| 52 | ------------------------ |
| 53 | |
| 54 | This section covers the modifications that should be made by the platform for |
| 55 | each BL stage to correctly port the firmware stack. They are categorized as |
| 56 | either mandatory or optional. |
| 57 | |
| 58 | |
| 59 | 2.1 Common mandatory modifications |
| 60 | ---------------------------------- |
| 61 | A platform port must enable the Memory Management Unit (MMU) with identity |
| 62 | mapped page tables, and enable both the instruction and data caches for each BL |
| 63 | stage. In the ARM FVP port, each BL stage configures the MMU in its platform- |
| 64 | specific architecture setup function, for example `blX_plat_arch_setup()`. |
| 65 | |
Soby Mathew | ab8707e | 2015-01-08 18:02:44 +0000 | [diff] [blame] | 66 | If the build option `USE_COHERENT_MEM` is enabled, each platform must allocate a |
| 67 | block of identity mapped secure memory with Device-nGnRE attributes aligned to |
| 68 | page boundary (4K) for each BL stage. This memory is identified by the section |
| 69 | name `tzfw_coherent_mem` so that its possible for the firmware to place |
| 70 | variables in it using the following C code directive: |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 71 | |
| 72 | __attribute__ ((section("tzfw_coherent_mem"))) |
| 73 | |
| 74 | Or alternatively the following assembler code directive: |
| 75 | |
| 76 | .section tzfw_coherent_mem |
| 77 | |
| 78 | The `tzfw_coherent_mem` section is used to allocate any data structures that are |
| 79 | accessed both when a CPU is executing with its MMU and caches enabled, and when |
| 80 | it's running with its MMU and caches disabled. Examples are given below. |
| 81 | |
| 82 | The following variables, functions and constants must be defined by the platform |
| 83 | for the firmware to work correctly. |
| 84 | |
| 85 | |
Dan Handley | b68954c | 2014-05-29 12:30:24 +0100 | [diff] [blame] | 86 | ### File : platform_def.h [mandatory] |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 87 | |
Dan Handley | b68954c | 2014-05-29 12:30:24 +0100 | [diff] [blame] | 88 | Each platform must ensure that a header file of this name is in the system |
| 89 | include path with the following constants defined. This may require updating the |
| 90 | list of `PLAT_INCLUDES` in the `platform.mk` file. In the ARM FVP port, this |
| 91 | file is found in [plat/fvp/include/platform_def.h]. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 92 | |
James Morrissey | ba3155b | 2013-10-29 10:56:46 +0000 | [diff] [blame] | 93 | * **#define : PLATFORM_LINKER_FORMAT** |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 94 | |
| 95 | Defines the linker format used by the platform, for example |
| 96 | `elf64-littleaarch64` used by the FVP. |
| 97 | |
James Morrissey | ba3155b | 2013-10-29 10:56:46 +0000 | [diff] [blame] | 98 | * **#define : PLATFORM_LINKER_ARCH** |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 99 | |
| 100 | Defines the processor architecture for the linker by the platform, for |
| 101 | example `aarch64` used by the FVP. |
| 102 | |
James Morrissey | ba3155b | 2013-10-29 10:56:46 +0000 | [diff] [blame] | 103 | * **#define : PLATFORM_STACK_SIZE** |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 104 | |
| 105 | Defines the normal stack memory available to each CPU. This constant is used |
Andrew Thoelke | 2bf28e6 | 2014-03-20 10:48:23 +0000 | [diff] [blame] | 106 | by [plat/common/aarch64/platform_mp_stack.S] and |
| 107 | [plat/common/aarch64/platform_up_stack.S]. |
| 108 | |
James Morrissey | ba3155b | 2013-10-29 10:56:46 +0000 | [diff] [blame] | 109 | * **#define : FIRMWARE_WELCOME_STR** |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 110 | |
| 111 | Defines the character string printed by BL1 upon entry into the `bl1_main()` |
| 112 | function. |
| 113 | |
James Morrissey | ba3155b | 2013-10-29 10:56:46 +0000 | [diff] [blame] | 114 | * **#define : BL2_IMAGE_NAME** |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 115 | |
| 116 | Name of the BL2 binary image on the host file-system. This name is used by |
Harry Liebel | d265bd7 | 2014-01-31 19:04:10 +0000 | [diff] [blame] | 117 | BL1 to load BL2 into secure memory from non-volatile storage. |
| 118 | |
| 119 | * **#define : BL31_IMAGE_NAME** |
| 120 | |
| 121 | Name of the BL3-1 binary image on the host file-system. This name is used by |
| 122 | BL2 to load BL3-1 into secure memory from platform storage. |
| 123 | |
| 124 | * **#define : BL33_IMAGE_NAME** |
| 125 | |
| 126 | Name of the BL3-3 binary image on the host file-system. This name is used by |
| 127 | BL2 to load BL3-3 into non-secure memory from platform storage. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 128 | |
Achin Gupta | 8d35f61 | 2015-01-25 22:44:23 +0000 | [diff] [blame] | 129 | * **#define : BL2_CERT_NAME** |
| 130 | |
| 131 | Name of the BL2 content certificate on the host file-system (mandatory when |
| 132 | Trusted Board Boot is enabled). |
| 133 | |
| 134 | * **#define : TRUSTED_KEY_CERT_NAME** |
| 135 | |
| 136 | Name of the Trusted Key certificate on the host file-system (mandatory when |
| 137 | Trusted Board Boot is enabled). |
| 138 | |
| 139 | * **#define : BL31_KEY_CERT_NAME** |
| 140 | |
| 141 | Name of the BL3-1 Key certificate on the host file-system (mandatory when |
| 142 | Trusted Board Boot is enabled). |
| 143 | |
| 144 | * **#define : BL31_CERT_NAME** |
| 145 | |
| 146 | Name of the BL3-1 Content certificate on the host file-system (mandatory |
| 147 | when Trusted Board Boot is enabled). |
| 148 | |
| 149 | * **#define : BL33_KEY_CERT_NAME** |
| 150 | |
| 151 | Name of the BL3-3 Key certificate on the host file-system (mandatory when |
| 152 | Trusted Board Boot is enabled). |
| 153 | |
| 154 | * **#define : BL33_CERT_NAME** |
| 155 | |
| 156 | Name of the BL3-3 Content certificate on the host file-system (mandatory |
| 157 | when Trusted Board Boot is enabled). |
| 158 | |
James Morrissey | ba3155b | 2013-10-29 10:56:46 +0000 | [diff] [blame] | 159 | * **#define : PLATFORM_CACHE_LINE_SIZE** |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 160 | |
| 161 | Defines the size (in bytes) of the largest cache line across all the cache |
| 162 | levels in the platform. |
| 163 | |
James Morrissey | ba3155b | 2013-10-29 10:56:46 +0000 | [diff] [blame] | 164 | * **#define : PLATFORM_CLUSTER_COUNT** |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 165 | |
| 166 | Defines the total number of clusters implemented by the platform in the |
| 167 | system. |
| 168 | |
James Morrissey | ba3155b | 2013-10-29 10:56:46 +0000 | [diff] [blame] | 169 | * **#define : PLATFORM_CORE_COUNT** |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 170 | |
| 171 | Defines the total number of CPUs implemented by the platform across all |
| 172 | clusters in the system. |
| 173 | |
James Morrissey | ba3155b | 2013-10-29 10:56:46 +0000 | [diff] [blame] | 174 | * **#define : PLATFORM_MAX_CPUS_PER_CLUSTER** |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 175 | |
| 176 | Defines the maximum number of CPUs that can be implemented within a cluster |
| 177 | on the platform. |
| 178 | |
Andrew Thoelke | 6c0b45d | 2014-06-20 00:36:14 +0100 | [diff] [blame] | 179 | * **#define : PLATFORM_NUM_AFFS** |
| 180 | |
| 181 | Defines the total number of nodes in the affinity heirarchy at all affinity |
| 182 | levels used by the platform. |
| 183 | |
Soby Mathew | 8c32bc2 | 2015-02-12 14:45:02 +0000 | [diff] [blame] | 184 | * **#define : PLATFORM_MAX_AFFLVL** |
| 185 | |
| 186 | Defines the maximum affinity level that the power management operations |
| 187 | should apply to. ARMv8-A has support for 4 affinity levels. It is likely |
| 188 | that hardware will implement fewer affinity levels. This macro allows the |
| 189 | PSCI implementation to consider only those affinity levels in the system |
| 190 | that the platform implements. For example, the Base AEM FVP implements two |
| 191 | clusters with a configurable number of CPUs. It reports the maximum |
| 192 | affinity level as 1, resulting in PSCI power control up to the cluster |
| 193 | level. |
| 194 | |
Sandrine Bailleux | 638363e | 2014-05-21 17:08:26 +0100 | [diff] [blame] | 195 | * **#define : BL1_RO_BASE** |
| 196 | |
| 197 | Defines the base address in secure ROM where BL1 originally lives. Must be |
| 198 | aligned on a page-size boundary. |
| 199 | |
| 200 | * **#define : BL1_RO_LIMIT** |
| 201 | |
| 202 | Defines the maximum address in secure ROM that BL1's actual content (i.e. |
| 203 | excluding any data section allocated at runtime) can occupy. |
| 204 | |
| 205 | * **#define : BL1_RW_BASE** |
| 206 | |
| 207 | Defines the base address in secure RAM where BL1's read-write data will live |
| 208 | at runtime. Must be aligned on a page-size boundary. |
| 209 | |
| 210 | * **#define : BL1_RW_LIMIT** |
| 211 | |
| 212 | Defines the maximum address in secure RAM that BL1's read-write data can |
| 213 | occupy at runtime. |
| 214 | |
James Morrissey | ba3155b | 2013-10-29 10:56:46 +0000 | [diff] [blame] | 215 | * **#define : BL2_BASE** |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 216 | |
| 217 | Defines the base address in secure RAM where BL1 loads the BL2 binary image. |
Sandrine Bailleux | cd29b0a | 2013-11-27 10:32:17 +0000 | [diff] [blame] | 218 | Must be aligned on a page-size boundary. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 219 | |
Sandrine Bailleux | 638363e | 2014-05-21 17:08:26 +0100 | [diff] [blame] | 220 | * **#define : BL2_LIMIT** |
| 221 | |
| 222 | Defines the maximum address in secure RAM that the BL2 image can occupy. |
| 223 | |
James Morrissey | ba3155b | 2013-10-29 10:56:46 +0000 | [diff] [blame] | 224 | * **#define : BL31_BASE** |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 225 | |
| 226 | Defines the base address in secure RAM where BL2 loads the BL3-1 binary |
Sandrine Bailleux | cd29b0a | 2013-11-27 10:32:17 +0000 | [diff] [blame] | 227 | image. Must be aligned on a page-size boundary. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 228 | |
Sandrine Bailleux | 638363e | 2014-05-21 17:08:26 +0100 | [diff] [blame] | 229 | * **#define : BL31_LIMIT** |
| 230 | |
| 231 | Defines the maximum address in secure RAM that the BL3-1 image can occupy. |
| 232 | |
Harry Liebel | d265bd7 | 2014-01-31 19:04:10 +0000 | [diff] [blame] | 233 | * **#define : NS_IMAGE_OFFSET** |
Sandrine Bailleux | 2467f70 | 2014-05-20 17:22:24 +0100 | [diff] [blame] | 234 | |
Harry Liebel | d265bd7 | 2014-01-31 19:04:10 +0000 | [diff] [blame] | 235 | Defines the base address in non-secure DRAM where BL2 loads the BL3-3 binary |
| 236 | image. Must be aligned on a page-size boundary. |
| 237 | |
Achin Gupta | 8d35f61 | 2015-01-25 22:44:23 +0000 | [diff] [blame] | 238 | If a BL3-0 image is supported by the platform, the following constants must |
| 239 | also be defined: |
| 240 | |
| 241 | * **#define : BL30_IMAGE_NAME** |
| 242 | |
| 243 | Name of the BL3-0 binary image on the host file-system. This name is used by |
| 244 | BL2 to load BL3-0 into secure memory from platform storage before being |
| 245 | transfered to the SCP. |
| 246 | |
| 247 | * **#define : BL30_KEY_CERT_NAME** |
| 248 | |
| 249 | Name of the BL3-0 Key certificate on the host file-system (mandatory when |
| 250 | Trusted Board Boot is enabled). |
| 251 | |
| 252 | * **#define : BL30_CERT_NAME** |
| 253 | |
| 254 | Name of the BL3-0 Content certificate on the host file-system (mandatory |
| 255 | when Trusted Board Boot is enabled). |
| 256 | |
Dan Handley | 5a06bb7 | 2014-08-04 11:41:20 +0100 | [diff] [blame] | 257 | If a BL3-2 image is supported by the platform, the following constants must |
| 258 | also be defined: |
Sandrine Bailleux | 2467f70 | 2014-05-20 17:22:24 +0100 | [diff] [blame] | 259 | |
Dan Handley | 5a06bb7 | 2014-08-04 11:41:20 +0100 | [diff] [blame] | 260 | * **#define : BL32_IMAGE_NAME** |
Sandrine Bailleux | 2467f70 | 2014-05-20 17:22:24 +0100 | [diff] [blame] | 261 | |
Dan Handley | 5a06bb7 | 2014-08-04 11:41:20 +0100 | [diff] [blame] | 262 | Name of the BL3-2 binary image on the host file-system. This name is used by |
| 263 | BL2 to load BL3-2 into secure memory from platform storage. |
Sandrine Bailleux | 2467f70 | 2014-05-20 17:22:24 +0100 | [diff] [blame] | 264 | |
Achin Gupta | 8d35f61 | 2015-01-25 22:44:23 +0000 | [diff] [blame] | 265 | * **#define : BL32_KEY_CERT_NAME** |
| 266 | |
| 267 | Name of the BL3-2 Key certificate on the host file-system (mandatory when |
| 268 | Trusted Board Boot is enabled). |
| 269 | |
| 270 | * **#define : BL32_CERT_NAME** |
| 271 | |
| 272 | Name of the BL3-2 Content certificate on the host file-system (mandatory |
| 273 | when Trusted Board Boot is enabled). |
| 274 | |
Sandrine Bailleux | 2467f70 | 2014-05-20 17:22:24 +0100 | [diff] [blame] | 275 | * **#define : BL32_BASE** |
| 276 | |
| 277 | Defines the base address in secure memory where BL2 loads the BL3-2 binary |
Dan Handley | 5a06bb7 | 2014-08-04 11:41:20 +0100 | [diff] [blame] | 278 | image. Must be aligned on a page-size boundary. |
Sandrine Bailleux | 2467f70 | 2014-05-20 17:22:24 +0100 | [diff] [blame] | 279 | |
| 280 | * **#define : BL32_LIMIT** |
| 281 | |
Dan Handley | 5a06bb7 | 2014-08-04 11:41:20 +0100 | [diff] [blame] | 282 | Defines the maximum address that the BL3-2 image can occupy. |
| 283 | |
| 284 | If the Test Secure-EL1 Payload (TSP) instantiation of BL3-2 is supported by the |
| 285 | platform, the following constants must also be defined: |
| 286 | |
| 287 | * **#define : TSP_SEC_MEM_BASE** |
| 288 | |
| 289 | Defines the base address of the secure memory used by the TSP image on the |
| 290 | platform. This must be at the same address or below `BL32_BASE`. |
| 291 | |
| 292 | * **#define : TSP_SEC_MEM_SIZE** |
| 293 | |
| 294 | Defines the size of the secure memory used by the BL3-2 image on the |
| 295 | platform. `TSP_SEC_MEM_BASE` and `TSP_SEC_MEM_SIZE` must fully accomodate |
| 296 | the memory required by the BL3-2 image, defined by `BL32_BASE` and |
| 297 | `BL32_LIMIT`. |
| 298 | |
| 299 | * **#define : TSP_IRQ_SEC_PHY_TIMER** |
| 300 | |
| 301 | Defines the ID of the secure physical generic timer interrupt used by the |
| 302 | TSP's interrupt handling code. |
Sandrine Bailleux | 2467f70 | 2014-05-20 17:22:24 +0100 | [diff] [blame] | 303 | |
Dan Handley | 6d16ce0 | 2014-08-04 18:31:43 +0100 | [diff] [blame] | 304 | If the platform port uses the IO storage framework, the following constants |
| 305 | must also be defined: |
| 306 | |
| 307 | * **#define : MAX_IO_DEVICES** |
| 308 | |
| 309 | Defines the maximum number of registered IO devices. Attempting to register |
| 310 | more devices than this value using `io_register_device()` will fail with |
| 311 | IO_RESOURCES_EXHAUSTED. |
| 312 | |
| 313 | * **#define : MAX_IO_HANDLES** |
| 314 | |
| 315 | Defines the maximum number of open IO handles. Attempting to open more IO |
| 316 | entities than this value using `io_open()` will fail with |
| 317 | IO_RESOURCES_EXHAUSTED. |
| 318 | |
Soby Mathew | ab8707e | 2015-01-08 18:02:44 +0000 | [diff] [blame] | 319 | If the platform needs to allocate data within the per-cpu data framework in |
| 320 | BL3-1, it should define the following macro. Currently this is only required if |
| 321 | the platform decides not to use the coherent memory section by undefining the |
| 322 | USE_COHERENT_MEM build flag. In this case, the framework allocates the required |
| 323 | memory within the the per-cpu data to minimize wastage. |
| 324 | |
| 325 | * **#define : PLAT_PCPU_DATA_SIZE** |
| 326 | |
| 327 | Defines the memory (in bytes) to be reserved within the per-cpu data |
| 328 | structure for use by the platform layer. |
| 329 | |
Sandrine Bailleux | 46d49f63 | 2014-06-23 17:00:23 +0100 | [diff] [blame] | 330 | The following constants are optional. They should be defined when the platform |
| 331 | memory layout implies some image overlaying like on FVP. |
| 332 | |
| 333 | * **#define : BL31_PROGBITS_LIMIT** |
| 334 | |
| 335 | Defines the maximum address in secure RAM that the BL3-1's progbits sections |
| 336 | can occupy. |
| 337 | |
Dan Handley | 5a06bb7 | 2014-08-04 11:41:20 +0100 | [diff] [blame] | 338 | * **#define : TSP_PROGBITS_LIMIT** |
Sandrine Bailleux | 46d49f63 | 2014-06-23 17:00:23 +0100 | [diff] [blame] | 339 | |
| 340 | Defines the maximum address that the TSP's progbits sections can occupy. |
Sandrine Bailleux | 2467f70 | 2014-05-20 17:22:24 +0100 | [diff] [blame] | 341 | |
Dan Handley | b68954c | 2014-05-29 12:30:24 +0100 | [diff] [blame] | 342 | ### File : plat_macros.S [mandatory] |
Soby Mathew | a43d431 | 2014-04-07 15:28:55 +0100 | [diff] [blame] | 343 | |
Dan Handley | b68954c | 2014-05-29 12:30:24 +0100 | [diff] [blame] | 344 | Each platform must ensure a file of this name is in the system include path with |
| 345 | the following macro defined. In the ARM FVP port, this file is found in |
| 346 | [plat/fvp/include/plat_macros.S]. |
Soby Mathew | a43d431 | 2014-04-07 15:28:55 +0100 | [diff] [blame] | 347 | |
| 348 | * **Macro : plat_print_gic_regs** |
| 349 | |
| 350 | This macro allows the crash reporting routine to print GIC registers |
Soby Mathew | 8c10690 | 2014-07-16 09:23:52 +0100 | [diff] [blame] | 351 | in case of an unhandled exception in BL3-1. This aids in debugging and |
Soby Mathew | a43d431 | 2014-04-07 15:28:55 +0100 | [diff] [blame] | 352 | this macro can be defined to be empty in case GIC register reporting is |
| 353 | not desired. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 354 | |
Soby Mathew | 8c10690 | 2014-07-16 09:23:52 +0100 | [diff] [blame] | 355 | * **Macro : plat_print_interconnect_regs** |
| 356 | |
| 357 | This macro allows the crash reporting routine to print interconnect registers |
| 358 | in case of an unhandled exception in BL3-1. This aids in debugging and |
| 359 | this macro can be defined to be empty in case interconnect register reporting |
| 360 | is not desired. In the ARM FVP port, the CCI snoop control registers are |
| 361 | reported. |
| 362 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 363 | ### Other mandatory modifications |
| 364 | |
James Morrissey | ba3155b | 2013-10-29 10:56:46 +0000 | [diff] [blame] | 365 | The following mandatory modifications may be implemented in any file |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 366 | the implementer chooses. In the ARM FVP port, they are implemented in |
Andrew Thoelke | 2bf28e6 | 2014-03-20 10:48:23 +0000 | [diff] [blame] | 367 | [plat/fvp/aarch64/plat_common.c]. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 368 | |
Sandrine Bailleux | 9e86490 | 2014-03-31 11:25:18 +0100 | [diff] [blame] | 369 | * **Function : uint64_t plat_get_syscnt_freq(void)** |
| 370 | |
| 371 | This function is used by the architecture setup code to retrieve the |
| 372 | counter frequency for the CPU's generic timer. This value will be |
| 373 | programmed into the `CNTFRQ_EL0` register. |
| 374 | In the ARM FVP port, it returns the base frequency of the system counter, |
| 375 | which is retrieved from the first entry in the frequency modes table. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 376 | |
Andrew Thoelke | 2bf28e6 | 2014-03-20 10:48:23 +0000 | [diff] [blame] | 377 | |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 378 | 2.2 Handling Reset |
| 379 | ------------------ |
| 380 | |
| 381 | BL1 by default implements the reset vector where execution starts from a cold |
| 382 | or warm boot. BL3-1 can be optionally set as a reset vector using the |
| 383 | RESET_TO_BL31 make variable. |
| 384 | |
| 385 | For each CPU, the reset vector code is responsible for the following tasks: |
| 386 | |
| 387 | 1. Distinguishing between a cold boot and a warm boot. |
| 388 | |
| 389 | 2. In the case of a cold boot and the CPU being a secondary CPU, ensuring that |
| 390 | the CPU is placed in a platform-specific state until the primary CPU |
| 391 | performs the necessary steps to remove it from this state. |
| 392 | |
| 393 | 3. In the case of a warm boot, ensuring that the CPU jumps to a platform- |
| 394 | specific address in the BL3-1 image in the same processor mode as it was |
| 395 | when released from reset. |
| 396 | |
| 397 | The following functions need to be implemented by the platform port to enable |
| 398 | reset vector code to perform the above tasks. |
| 399 | |
| 400 | |
| 401 | ### Function : platform_get_entrypoint() [mandatory] |
| 402 | |
| 403 | Argument : unsigned long |
| 404 | Return : unsigned int |
| 405 | |
| 406 | This function is called with the `SCTLR.M` and `SCTLR.C` bits disabled. The CPU |
| 407 | is identified by its `MPIDR`, which is passed as the argument. The function is |
| 408 | responsible for distinguishing between a warm and cold reset using platform- |
| 409 | specific means. If it's a warm reset then it returns the entrypoint into the |
| 410 | BL3-1 image that the CPU must jump to. If it's a cold reset then this function |
| 411 | must return zero. |
| 412 | |
| 413 | This function is also responsible for implementing a platform-specific mechanism |
| 414 | to handle the condition where the CPU has been warm reset but there is no |
| 415 | entrypoint to jump to. |
| 416 | |
| 417 | This function does not follow the Procedure Call Standard used by the |
| 418 | Application Binary Interface for the ARM 64-bit architecture. The caller should |
| 419 | not assume that callee saved registers are preserved across a call to this |
| 420 | function. |
| 421 | |
| 422 | This function fulfills requirement 1 and 3 listed above. |
| 423 | |
| 424 | |
| 425 | ### Function : plat_secondary_cold_boot_setup() [mandatory] |
| 426 | |
| 427 | Argument : void |
| 428 | Return : void |
| 429 | |
| 430 | This function is called with the MMU and data caches disabled. It is responsible |
| 431 | for placing the executing secondary CPU in a platform-specific state until the |
| 432 | primary CPU performs the necessary actions to bring it out of that state and |
| 433 | allow entry into the OS. |
| 434 | |
| 435 | In the ARM FVP port, each secondary CPU powers itself off. The primary CPU is |
| 436 | responsible for powering up the secondary CPU when normal world software |
| 437 | requires them. |
| 438 | |
| 439 | This function fulfills requirement 2 above. |
| 440 | |
| 441 | |
Juan Castillo | 53fdceb | 2014-07-16 15:53:43 +0100 | [diff] [blame] | 442 | ### Function : platform_is_primary_cpu() [mandatory] |
| 443 | |
| 444 | Argument : unsigned long |
| 445 | Return : unsigned int |
| 446 | |
| 447 | This function identifies a CPU by its `MPIDR`, which is passed as the argument, |
| 448 | to determine whether this CPU is the primary CPU or a secondary CPU. A return |
| 449 | value of zero indicates that the CPU is not the primary CPU, while a non-zero |
| 450 | return value indicates that the CPU is the primary CPU. |
| 451 | |
| 452 | |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 453 | ### Function : platform_mem_init() [mandatory] |
| 454 | |
| 455 | Argument : void |
| 456 | Return : void |
| 457 | |
| 458 | This function is called before any access to data is made by the firmware, in |
| 459 | order to carry out any essential memory initialization. |
| 460 | |
| 461 | The ARM FVP port uses this function to initialize the mailbox memory used for |
| 462 | providing the warm-boot entry-point addresses. |
| 463 | |
| 464 | |
Juan Castillo | 6eadf76 | 2015-01-07 10:39:25 +0000 | [diff] [blame] | 465 | ### Function: plat_match_rotpk() |
| 466 | |
| 467 | Argument : const unsigned char *, unsigned int |
| 468 | Return : int |
| 469 | |
| 470 | This function is mandatory when Trusted Board Boot is enabled. It receives a |
| 471 | pointer to a buffer containing a signing key and its size as parameters and |
| 472 | returns 0 (success) if that key matches the ROT (Root Of Trust) key stored in |
| 473 | the platform. Any other return value means a mismatch. |
| 474 | |
| 475 | |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 476 | |
| 477 | 2.3 Common optional modifications |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 478 | --------------------------------- |
| 479 | |
| 480 | The following are helper functions implemented by the firmware that perform |
| 481 | common platform-specific tasks. A platform may choose to override these |
| 482 | definitions. |
| 483 | |
| 484 | |
| 485 | ### Function : platform_get_core_pos() |
| 486 | |
| 487 | Argument : unsigned long |
| 488 | Return : int |
| 489 | |
| 490 | A platform may need to convert the `MPIDR` of a CPU to an absolute number, which |
| 491 | can be used as a CPU-specific linear index into blocks of memory (for example |
| 492 | while allocating per-CPU stacks). This routine contains a simple mechanism |
| 493 | to perform this conversion, using the assumption that each cluster contains a |
| 494 | maximum of 4 CPUs: |
| 495 | |
| 496 | linear index = cpu_id + (cluster_id * 4) |
| 497 | |
| 498 | cpu_id = 8-bit value in MPIDR at affinity level 0 |
| 499 | cluster_id = 8-bit value in MPIDR at affinity level 1 |
| 500 | |
| 501 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 502 | ### Function : platform_set_stack() |
| 503 | |
| 504 | Argument : unsigned long |
| 505 | Return : void |
| 506 | |
Andrew Thoelke | 2bf28e6 | 2014-03-20 10:48:23 +0000 | [diff] [blame] | 507 | This function sets the current stack pointer to the normal memory stack that |
| 508 | has been allocated for the CPU specificed by MPIDR. For BL images that only |
| 509 | require a stack for the primary CPU the parameter is ignored. The size of |
| 510 | the stack allocated to each CPU is specified by the platform defined constant |
| 511 | `PLATFORM_STACK_SIZE`. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 512 | |
Andrew Thoelke | 2bf28e6 | 2014-03-20 10:48:23 +0000 | [diff] [blame] | 513 | Common implementations of this function for the UP and MP BL images are |
| 514 | provided in [plat/common/aarch64/platform_up_stack.S] and |
| 515 | [plat/common/aarch64/platform_mp_stack.S] |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 516 | |
| 517 | |
Achin Gupta | c8afc78 | 2013-11-25 18:45:02 +0000 | [diff] [blame] | 518 | ### Function : platform_get_stack() |
| 519 | |
| 520 | Argument : unsigned long |
| 521 | Return : unsigned long |
| 522 | |
Andrew Thoelke | 2bf28e6 | 2014-03-20 10:48:23 +0000 | [diff] [blame] | 523 | This function returns the base address of the normal memory stack that |
| 524 | has been allocated for the CPU specificed by MPIDR. For BL images that only |
| 525 | require a stack for the primary CPU the parameter is ignored. The size of |
| 526 | the stack allocated to each CPU is specified by the platform defined constant |
| 527 | `PLATFORM_STACK_SIZE`. |
Achin Gupta | c8afc78 | 2013-11-25 18:45:02 +0000 | [diff] [blame] | 528 | |
Andrew Thoelke | 2bf28e6 | 2014-03-20 10:48:23 +0000 | [diff] [blame] | 529 | Common implementations of this function for the UP and MP BL images are |
| 530 | provided in [plat/common/aarch64/platform_up_stack.S] and |
| 531 | [plat/common/aarch64/platform_mp_stack.S] |
Achin Gupta | c8afc78 | 2013-11-25 18:45:02 +0000 | [diff] [blame] | 532 | |
| 533 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 534 | ### Function : plat_report_exception() |
| 535 | |
| 536 | Argument : unsigned int |
| 537 | Return : void |
| 538 | |
| 539 | A platform may need to report various information about its status when an |
| 540 | exception is taken, for example the current exception level, the CPU security |
| 541 | state (secure/non-secure), the exception type, and so on. This function is |
| 542 | called in the following circumstances: |
| 543 | |
| 544 | * In BL1, whenever an exception is taken. |
| 545 | * In BL2, whenever an exception is taken. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 546 | |
| 547 | The default implementation doesn't do anything, to avoid making assumptions |
| 548 | about the way the platform displays its status information. |
| 549 | |
| 550 | This function receives the exception type as its argument. Possible values for |
Andrew Thoelke | 2bf28e6 | 2014-03-20 10:48:23 +0000 | [diff] [blame] | 551 | exceptions types are listed in the [include/runtime_svc.h] header file. Note |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 552 | that these constants are not related to any architectural exception code; they |
| 553 | are just an ARM Trusted Firmware convention. |
| 554 | |
| 555 | |
Soby Mathew | 24fb838 | 2014-08-14 12:22:32 +0100 | [diff] [blame] | 556 | ### Function : plat_reset_handler() |
| 557 | |
| 558 | Argument : void |
| 559 | Return : void |
| 560 | |
| 561 | A platform may need to do additional initialization after reset. This function |
| 562 | allows the platform to do the platform specific intializations. Platform |
| 563 | specific errata workarounds could also be implemented here. The api should |
Soby Mathew | 683f788 | 2015-01-29 12:00:58 +0000 | [diff] [blame] | 564 | preserve the values of callee saved registers x19 to x29. |
Soby Mathew | 24fb838 | 2014-08-14 12:22:32 +0100 | [diff] [blame] | 565 | |
Yatharth Kochar | 79a97b2 | 2014-11-20 18:09:41 +0000 | [diff] [blame] | 566 | The default implementation doesn't do anything. If a platform needs to override |
| 567 | the default implementation, refer to the [Firmware Design Guide] for general |
| 568 | guidelines regarding placement of code in a reset handler. |
Soby Mathew | 24fb838 | 2014-08-14 12:22:32 +0100 | [diff] [blame] | 569 | |
Soby Mathew | add4035 | 2014-08-14 12:49:05 +0100 | [diff] [blame] | 570 | ### Function : plat_disable_acp() |
| 571 | |
| 572 | Argument : void |
| 573 | Return : void |
| 574 | |
| 575 | This api allows a platform to disable the Accelerator Coherency Port (if |
| 576 | present) during a cluster power down sequence. The default weak implementation |
| 577 | doesn't do anything. Since this api is called during the power down sequence, |
| 578 | it has restrictions for stack usage and it can use the registers x0 - x17 as |
| 579 | scratch registers. It should preserve the value in x18 register as it is used |
| 580 | by the caller to store the return address. |
| 581 | |
Soby Mathew | 24fb838 | 2014-08-14 12:22:32 +0100 | [diff] [blame] | 582 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 583 | 3. Modifications specific to a Boot Loader stage |
| 584 | ------------------------------------------------- |
| 585 | |
| 586 | 3.1 Boot Loader Stage 1 (BL1) |
| 587 | ----------------------------- |
| 588 | |
| 589 | BL1 implements the reset vector where execution starts from after a cold or |
| 590 | warm boot. For each CPU, BL1 is responsible for the following tasks: |
| 591 | |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 592 | 1. Handling the reset as described in section 2.2 |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 593 | |
| 594 | 2. In the case of a cold boot and the CPU being the primary CPU, ensuring that |
| 595 | only this CPU executes the remaining BL1 code, including loading and passing |
| 596 | control to the BL2 stage. |
| 597 | |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 598 | 3. Loading the BL2 image from non-volatile storage into secure memory at the |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 599 | address specified by the platform defined constant `BL2_BASE`. |
| 600 | |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 601 | 4. Populating a `meminfo` structure with the following information in memory, |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 602 | accessible by BL2 immediately upon entry. |
| 603 | |
| 604 | meminfo.total_base = Base address of secure RAM visible to BL2 |
| 605 | meminfo.total_size = Size of secure RAM visible to BL2 |
| 606 | meminfo.free_base = Base address of secure RAM available for |
| 607 | allocation to BL2 |
| 608 | meminfo.free_size = Size of secure RAM available for allocation to BL2 |
| 609 | |
| 610 | BL1 places this `meminfo` structure at the beginning of the free memory |
| 611 | available for its use. Since BL1 cannot allocate memory dynamically at the |
| 612 | moment, its free memory will be available for BL2's use as-is. However, this |
| 613 | means that BL2 must read the `meminfo` structure before it starts using its |
| 614 | free memory (this is discussed in Section 3.2). |
| 615 | |
| 616 | In future releases of the ARM Trusted Firmware it will be possible for |
| 617 | the platform to decide where it wants to place the `meminfo` structure for |
| 618 | BL2. |
| 619 | |
Sandrine Bailleux | 8f55dfb | 2014-06-24 14:02:34 +0100 | [diff] [blame] | 620 | BL1 implements the `bl1_init_bl2_mem_layout()` function to populate the |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 621 | BL2 `meminfo` structure. The platform may override this implementation, for |
| 622 | example if the platform wants to restrict the amount of memory visible to |
| 623 | BL2. Details of how to do this are given below. |
| 624 | |
| 625 | The following functions need to be implemented by the platform port to enable |
| 626 | BL1 to perform the above tasks. |
| 627 | |
| 628 | |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 629 | ### Function : bl1_plat_arch_setup() [mandatory] |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 630 | |
| 631 | Argument : void |
| 632 | Return : void |
| 633 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 634 | This function performs any platform-specific and architectural setup that the |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 635 | platform requires. Platform-specific setup might include configuration of |
| 636 | memory controllers, configuration of the interconnect to allow the cluster |
| 637 | to service cache snoop requests from another cluster, and so on. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 638 | |
| 639 | In the ARM FVP port, this function enables CCI snoops into the cluster that the |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 640 | primary CPU is part of. It also enables the MMU. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 641 | |
| 642 | This function helps fulfill requirement 2 above. |
| 643 | |
| 644 | |
| 645 | ### Function : bl1_platform_setup() [mandatory] |
| 646 | |
| 647 | Argument : void |
| 648 | Return : void |
| 649 | |
| 650 | This function executes with the MMU and data caches enabled. It is responsible |
| 651 | for performing any remaining platform-specific setup that can occur after the |
| 652 | MMU and data cache have been enabled. |
| 653 | |
Harry Liebel | d265bd7 | 2014-01-31 19:04:10 +0000 | [diff] [blame] | 654 | This function is also responsible for initializing the storage abstraction layer |
| 655 | which is used to load further bootloader images. |
| 656 | |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 657 | This function helps fulfill requirement 3 above. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 658 | |
| 659 | |
Sandrine Bailleux | ee12f6f | 2013-11-28 14:55:58 +0000 | [diff] [blame] | 660 | ### Function : bl1_plat_sec_mem_layout() [mandatory] |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 661 | |
| 662 | Argument : void |
Sandrine Bailleux | ee12f6f | 2013-11-28 14:55:58 +0000 | [diff] [blame] | 663 | Return : meminfo * |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 664 | |
Sandrine Bailleux | ee12f6f | 2013-11-28 14:55:58 +0000 | [diff] [blame] | 665 | This function should only be called on the cold boot path. It executes with the |
| 666 | MMU and data caches enabled. The pointer returned by this function must point to |
| 667 | a `meminfo` structure containing the extents and availability of secure RAM for |
| 668 | the BL1 stage. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 669 | |
| 670 | meminfo.total_base = Base address of secure RAM visible to BL1 |
| 671 | meminfo.total_size = Size of secure RAM visible to BL1 |
| 672 | meminfo.free_base = Base address of secure RAM available for allocation |
| 673 | to BL1 |
| 674 | meminfo.free_size = Size of secure RAM available for allocation to BL1 |
| 675 | |
| 676 | This information is used by BL1 to load the BL2 image in secure RAM. BL1 also |
| 677 | populates a similar structure to tell BL2 the extents of memory available for |
| 678 | its own use. |
| 679 | |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 680 | This function helps fulfill requirement 3 above. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 681 | |
| 682 | |
Sandrine Bailleux | 8f55dfb | 2014-06-24 14:02:34 +0100 | [diff] [blame] | 683 | ### Function : bl1_init_bl2_mem_layout() [optional] |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 684 | |
| 685 | Argument : meminfo *, meminfo *, unsigned int, unsigned long |
| 686 | Return : void |
| 687 | |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 688 | BL1 needs to tell the next stage the amount of secure RAM available |
| 689 | for it to use. This information is populated in a `meminfo` |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 690 | structure. |
| 691 | |
| 692 | Depending upon where BL2 has been loaded in secure RAM (determined by |
| 693 | `BL2_BASE`), BL1 calculates the amount of free memory available for BL2 to use. |
| 694 | BL1 also ensures that its data sections resident in secure RAM are not visible |
| 695 | to BL2. An illustration of how this is done in the ARM FVP port is given in the |
| 696 | [User Guide], in the Section "Memory layout on Base FVP". |
| 697 | |
| 698 | |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 699 | ### Function : bl1_plat_set_bl2_ep_info() [mandatory] |
| 700 | |
| 701 | Argument : image_info *, entry_point_info * |
| 702 | Return : void |
| 703 | |
| 704 | This function is called after loading BL2 image and it can be used to overwrite |
| 705 | the entry point set by loader and also set the security state and SPSR which |
| 706 | represents the entry point system state for BL2. |
| 707 | |
| 708 | On FVP, we are setting the security state and the SPSR for the BL2 entrypoint |
| 709 | |
| 710 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 711 | 3.2 Boot Loader Stage 2 (BL2) |
| 712 | ----------------------------- |
| 713 | |
| 714 | The BL2 stage is executed only by the primary CPU, which is determined in BL1 |
| 715 | using the `platform_is_primary_cpu()` function. BL1 passed control to BL2 at |
| 716 | `BL2_BASE`. BL2 executes in Secure EL1 and is responsible for: |
| 717 | |
Sandrine Bailleux | 93d81d6 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 718 | 1. (Optional) Loading the BL3-0 binary image (if present) from platform |
| 719 | provided non-volatile storage. To load the BL3-0 image, BL2 makes use of |
| 720 | the `meminfo` returned by the `bl2_plat_get_bl30_meminfo()` function. |
| 721 | The platform also defines the address in memory where BL3-0 is loaded |
| 722 | through the optional constant `BL30_BASE`. BL2 uses this information |
| 723 | to determine if there is enough memory to load the BL3-0 image. |
| 724 | Subsequent handling of the BL3-0 image is platform-specific and is |
| 725 | implemented in the `bl2_plat_handle_bl30()` function. |
| 726 | If `BL30_BASE` is not defined then this step is not performed. |
| 727 | |
| 728 | 2. Loading the BL3-1 binary image into secure RAM from non-volatile storage. To |
Harry Liebel | d265bd7 | 2014-01-31 19:04:10 +0000 | [diff] [blame] | 729 | load the BL3-1 image, BL2 makes use of the `meminfo` structure passed to it |
| 730 | by BL1. This structure allows BL2 to calculate how much secure RAM is |
| 731 | available for its use. The platform also defines the address in secure RAM |
| 732 | where BL3-1 is loaded through the constant `BL31_BASE`. BL2 uses this |
| 733 | information to determine if there is enough memory to load the BL3-1 image. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 734 | |
Sandrine Bailleux | 93d81d6 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 735 | 3. (Optional) Loading the BL3-2 binary image (if present) from platform |
Dan Handley | 1151c82 | 2014-04-15 11:38:38 +0100 | [diff] [blame] | 736 | provided non-volatile storage. To load the BL3-2 image, BL2 makes use of |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 737 | the `meminfo` returned by the `bl2_plat_get_bl32_meminfo()` function. |
| 738 | The platform also defines the address in memory where BL3-2 is loaded |
| 739 | through the optional constant `BL32_BASE`. BL2 uses this information |
| 740 | to determine if there is enough memory to load the BL3-2 image. |
| 741 | If `BL32_BASE` is not defined then this and the next step is not performed. |
Achin Gupta | a3050ed | 2014-02-19 17:52:35 +0000 | [diff] [blame] | 742 | |
Sandrine Bailleux | 93d81d6 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 743 | 4. (Optional) Arranging to pass control to the BL3-2 image (if present) that |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 744 | has been pre-loaded at `BL32_BASE`. BL2 populates an `entry_point_info` |
Dan Handley | 1151c82 | 2014-04-15 11:38:38 +0100 | [diff] [blame] | 745 | structure in memory provided by the platform with information about how |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 746 | BL3-1 should pass control to the BL3-2 image. |
Achin Gupta | a3050ed | 2014-02-19 17:52:35 +0000 | [diff] [blame] | 747 | |
Sandrine Bailleux | 93d81d6 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 748 | 5. Loading the normal world BL3-3 binary image into non-secure DRAM from |
| 749 | platform storage and arranging for BL3-1 to pass control to this image. This |
| 750 | address is determined using the `plat_get_ns_image_entrypoint()` function |
| 751 | described below. |
| 752 | |
| 753 | 6. BL2 populates an `entry_point_info` structure in memory provided by the |
| 754 | platform with information about how BL3-1 should pass control to the |
| 755 | other BL images. |
| 756 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 757 | The following functions must be implemented by the platform port to enable BL2 |
| 758 | to perform the above tasks. |
| 759 | |
| 760 | |
| 761 | ### Function : bl2_early_platform_setup() [mandatory] |
| 762 | |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 763 | Argument : meminfo * |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 764 | Return : void |
| 765 | |
| 766 | This function executes with the MMU and data caches disabled. It is only called |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 767 | by the primary CPU. The arguments to this function is the address of the |
| 768 | `meminfo` structure populated by BL1. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 769 | |
| 770 | The platform must copy the contents of the `meminfo` structure into a private |
| 771 | variable as the original memory may be subsequently overwritten by BL2. The |
| 772 | copied structure is made available to all BL2 code through the |
Achin Gupta | e4d084e | 2014-02-19 17:18:23 +0000 | [diff] [blame] | 773 | `bl2_plat_sec_mem_layout()` function. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 774 | |
| 775 | |
| 776 | ### Function : bl2_plat_arch_setup() [mandatory] |
| 777 | |
| 778 | Argument : void |
| 779 | Return : void |
| 780 | |
| 781 | This function executes with the MMU and data caches disabled. It is only called |
| 782 | by the primary CPU. |
| 783 | |
| 784 | The purpose of this function is to perform any architectural initialization |
| 785 | that varies across platforms, for example enabling the MMU (since the memory |
| 786 | map differs across platforms). |
| 787 | |
| 788 | |
| 789 | ### Function : bl2_platform_setup() [mandatory] |
| 790 | |
| 791 | Argument : void |
| 792 | Return : void |
| 793 | |
| 794 | This function may execute with the MMU and data caches enabled if the platform |
| 795 | port does the necessary initialization in `bl2_plat_arch_setup()`. It is only |
| 796 | called by the primary CPU. |
| 797 | |
Achin Gupta | e4d084e | 2014-02-19 17:18:23 +0000 | [diff] [blame] | 798 | The purpose of this function is to perform any platform initialization |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 799 | specific to BL2. Platform security components are configured if required. |
| 800 | For the Base FVP the TZC-400 TrustZone controller is configured to only |
| 801 | grant non-secure access to DRAM. This avoids aliasing between secure and |
| 802 | non-secure accesses in the TLB and cache - secure execution states can use |
| 803 | the NS attributes in the MMU translation tables to access the DRAM. |
Harry Liebel | ce19cf1 | 2014-04-01 19:28:07 +0100 | [diff] [blame] | 804 | |
Harry Liebel | d265bd7 | 2014-01-31 19:04:10 +0000 | [diff] [blame] | 805 | This function is also responsible for initializing the storage abstraction layer |
| 806 | which is used to load further bootloader images. |
| 807 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 808 | |
Sandrine Bailleux | ee12f6f | 2013-11-28 14:55:58 +0000 | [diff] [blame] | 809 | ### Function : bl2_plat_sec_mem_layout() [mandatory] |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 810 | |
| 811 | Argument : void |
Sandrine Bailleux | ee12f6f | 2013-11-28 14:55:58 +0000 | [diff] [blame] | 812 | Return : meminfo * |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 813 | |
Sandrine Bailleux | ee12f6f | 2013-11-28 14:55:58 +0000 | [diff] [blame] | 814 | This function should only be called on the cold boot path. It may execute with |
| 815 | the MMU and data caches enabled if the platform port does the necessary |
| 816 | initialization in `bl2_plat_arch_setup()`. It is only called by the primary CPU. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 817 | |
Sandrine Bailleux | ee12f6f | 2013-11-28 14:55:58 +0000 | [diff] [blame] | 818 | The purpose of this function is to return a pointer to a `meminfo` structure |
| 819 | populated with the extents of secure RAM available for BL2 to use. See |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 820 | `bl2_early_platform_setup()` above. |
| 821 | |
| 822 | |
Sandrine Bailleux | 93d81d6 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 823 | ### Function : bl2_plat_get_bl30_meminfo() [mandatory] |
| 824 | |
| 825 | Argument : meminfo * |
| 826 | Return : void |
| 827 | |
| 828 | This function is used to get the memory limits where BL2 can load the |
| 829 | BL3-0 image. The meminfo provided by this is used by load_image() to |
| 830 | validate whether the BL3-0 image can be loaded within the given |
| 831 | memory from the given base. |
| 832 | |
| 833 | |
| 834 | ### Function : bl2_plat_handle_bl30() [mandatory] |
| 835 | |
| 836 | Argument : image_info * |
| 837 | Return : int |
| 838 | |
| 839 | This function is called after loading BL3-0 image and it is used to perform any |
| 840 | platform-specific actions required to handle the SCP firmware. Typically it |
| 841 | transfers the image into SCP memory using a platform-specific protocol and waits |
| 842 | until SCP executes it and signals to the Application Processor (AP) for BL2 |
| 843 | execution to continue. |
| 844 | |
| 845 | This function returns 0 on success, a negative error code otherwise. |
| 846 | |
| 847 | |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 848 | ### Function : bl2_plat_get_bl31_params() [mandatory] |
Harry Liebel | d265bd7 | 2014-01-31 19:04:10 +0000 | [diff] [blame] | 849 | |
| 850 | Argument : void |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 851 | Return : bl31_params * |
Harry Liebel | d265bd7 | 2014-01-31 19:04:10 +0000 | [diff] [blame] | 852 | |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 853 | BL2 platform code needs to return a pointer to a `bl31_params` structure it |
| 854 | will use for passing information to BL3-1. The `bl31_params` structure carries |
| 855 | the following information. |
| 856 | - Header describing the version information for interpreting the bl31_param |
| 857 | structure |
| 858 | - Information about executing the BL3-3 image in the `bl33_ep_info` field |
| 859 | - Information about executing the BL3-2 image in the `bl32_ep_info` field |
| 860 | - Information about the type and extents of BL3-1 image in the |
| 861 | `bl31_image_info` field |
| 862 | - Information about the type and extents of BL3-2 image in the |
| 863 | `bl32_image_info` field |
| 864 | - Information about the type and extents of BL3-3 image in the |
| 865 | `bl33_image_info` field |
| 866 | |
| 867 | The memory pointed by this structure and its sub-structures should be |
| 868 | accessible from BL3-1 initialisation code. BL3-1 might choose to copy the |
| 869 | necessary content, or maintain the structures until BL3-3 is initialised. |
Harry Liebel | d265bd7 | 2014-01-31 19:04:10 +0000 | [diff] [blame] | 870 | |
| 871 | |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 872 | ### Funtion : bl2_plat_get_bl31_ep_info() [mandatory] |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 873 | |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 874 | Argument : void |
| 875 | Return : entry_point_info * |
| 876 | |
| 877 | BL2 platform code returns a pointer which is used to populate the entry point |
| 878 | information for BL3-1 entry point. The location pointed by it should be |
| 879 | accessible from BL1 while processing the synchronous exception to run to BL3-1. |
| 880 | |
| 881 | On FVP this is allocated inside an bl2_to_bl31_params_mem structure which |
| 882 | is allocated at an address pointed by PARAMS_BASE. |
| 883 | |
| 884 | |
| 885 | ### Function : bl2_plat_set_bl31_ep_info() [mandatory] |
| 886 | |
| 887 | Argument : image_info *, entry_point_info * |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 888 | Return : void |
| 889 | |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 890 | This function is called after loading BL3-1 image and it can be used to |
| 891 | overwrite the entry point set by loader and also set the security state |
| 892 | and SPSR which represents the entry point system state for BL3-1. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 893 | |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 894 | On FVP, we are setting the security state and the SPSR for the BL3-1 |
| 895 | entrypoint. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 896 | |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 897 | ### Function : bl2_plat_set_bl32_ep_info() [mandatory] |
| 898 | |
| 899 | Argument : image_info *, entry_point_info * |
| 900 | Return : void |
| 901 | |
| 902 | This function is called after loading BL3-2 image and it can be used to |
| 903 | overwrite the entry point set by loader and also set the security state |
| 904 | and SPSR which represents the entry point system state for BL3-2. |
| 905 | |
| 906 | On FVP, we are setting the security state and the SPSR for the BL3-2 |
| 907 | entrypoint |
| 908 | |
| 909 | ### Function : bl2_plat_set_bl33_ep_info() [mandatory] |
| 910 | |
| 911 | Argument : image_info *, entry_point_info * |
| 912 | Return : void |
| 913 | |
| 914 | This function is called after loading BL3-3 image and it can be used to |
| 915 | overwrite the entry point set by loader and also set the security state |
| 916 | and SPSR which represents the entry point system state for BL3-3. |
| 917 | |
| 918 | On FVP, we are setting the security state and the SPSR for the BL3-3 |
| 919 | entrypoint |
| 920 | |
| 921 | ### Function : bl2_plat_get_bl32_meminfo() [mandatory] |
| 922 | |
| 923 | Argument : meminfo * |
| 924 | Return : void |
| 925 | |
| 926 | This function is used to get the memory limits where BL2 can load the |
| 927 | BL3-2 image. The meminfo provided by this is used by load_image() to |
| 928 | validate whether the BL3-2 image can be loaded with in the given |
| 929 | memory from the given base. |
| 930 | |
| 931 | ### Function : bl2_plat_get_bl33_meminfo() [mandatory] |
| 932 | |
| 933 | Argument : meminfo * |
| 934 | Return : void |
| 935 | |
| 936 | This function is used to get the memory limits where BL2 can load the |
| 937 | BL3-3 image. The meminfo provided by this is used by load_image() to |
| 938 | validate whether the BL3-3 image can be loaded with in the given |
| 939 | memory from the given base. |
| 940 | |
| 941 | ### Function : bl2_plat_flush_bl31_params() [mandatory] |
| 942 | |
| 943 | Argument : void |
| 944 | Return : void |
| 945 | |
| 946 | Once BL2 has populated all the structures that needs to be read by BL1 |
| 947 | and BL3-1 including the bl31_params structures and its sub-structures, |
| 948 | the bl31_ep_info structure and any platform specific data. It flushes |
| 949 | all these data to the main memory so that it is available when we jump to |
| 950 | later Bootloader stages with MMU off |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 951 | |
| 952 | ### Function : plat_get_ns_image_entrypoint() [mandatory] |
| 953 | |
| 954 | Argument : void |
| 955 | Return : unsigned long |
| 956 | |
| 957 | As previously described, BL2 is responsible for arranging for control to be |
| 958 | passed to a normal world BL image through BL3-1. This function returns the |
| 959 | entrypoint of that image, which BL3-1 uses to jump to it. |
| 960 | |
Harry Liebel | d265bd7 | 2014-01-31 19:04:10 +0000 | [diff] [blame] | 961 | BL2 is responsible for loading the normal world BL3-3 image (e.g. UEFI). |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 962 | |
| 963 | |
| 964 | 3.2 Boot Loader Stage 3-1 (BL3-1) |
| 965 | --------------------------------- |
| 966 | |
| 967 | During cold boot, the BL3-1 stage is executed only by the primary CPU. This is |
| 968 | determined in BL1 using the `platform_is_primary_cpu()` function. BL1 passes |
| 969 | control to BL3-1 at `BL31_BASE`. During warm boot, BL3-1 is executed by all |
| 970 | CPUs. BL3-1 executes at EL3 and is responsible for: |
| 971 | |
| 972 | 1. Re-initializing all architectural and platform state. Although BL1 performs |
| 973 | some of this initialization, BL3-1 remains resident in EL3 and must ensure |
| 974 | that EL3 architectural and platform state is completely initialized. It |
| 975 | should make no assumptions about the system state when it receives control. |
| 976 | |
| 977 | 2. Passing control to a normal world BL image, pre-loaded at a platform- |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 978 | specific address by BL2. BL3-1 uses the `entry_point_info` structure that BL2 |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 979 | populated in memory to do this. |
| 980 | |
| 981 | 3. Providing runtime firmware services. Currently, BL3-1 only implements a |
| 982 | subset of the Power State Coordination Interface (PSCI) API as a runtime |
| 983 | service. See Section 3.3 below for details of porting the PSCI |
| 984 | implementation. |
| 985 | |
Achin Gupta | 35ca351 | 2014-02-19 17:58:33 +0000 | [diff] [blame] | 986 | 4. Optionally passing control to the BL3-2 image, pre-loaded at a platform- |
| 987 | specific address by BL2. BL3-1 exports a set of apis that allow runtime |
| 988 | services to specify the security state in which the next image should be |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 989 | executed and run the corresponding image. BL3-1 uses the `entry_point_info` |
| 990 | structure populated by BL2 to do this. |
| 991 | |
| 992 | If BL3-1 is a reset vector, It also needs to handle the reset as specified in |
| 993 | section 2.2 before the tasks described above. |
Achin Gupta | 35ca351 | 2014-02-19 17:58:33 +0000 | [diff] [blame] | 994 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 995 | The following functions must be implemented by the platform port to enable BL3-1 |
| 996 | to perform the above tasks. |
| 997 | |
| 998 | |
| 999 | ### Function : bl31_early_platform_setup() [mandatory] |
| 1000 | |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 1001 | Argument : bl31_params *, void * |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1002 | Return : void |
| 1003 | |
| 1004 | This function executes with the MMU and data caches disabled. It is only called |
| 1005 | by the primary CPU. The arguments to this function are: |
| 1006 | |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 1007 | * The address of the `bl31_params` structure populated by BL2. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1008 | * An opaque pointer that the platform may use as needed. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1009 | |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 1010 | The platform can copy the contents of the `bl31_params` structure and its |
| 1011 | sub-structures into private variables if the original memory may be |
| 1012 | subsequently overwritten by BL3-1 and similarly the `void *` pointing |
| 1013 | to the platform data also needs to be saved. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1014 | |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 1015 | On the ARM FVP port, BL2 passes a pointer to a `bl31_params` structure populated |
| 1016 | in the secure DRAM at address `0x6000000` in the bl31_params * argument and it |
| 1017 | does not use opaque pointer mentioned earlier. BL3-1 does not copy this |
| 1018 | information to internal data structures as it guarantees that the secure |
| 1019 | DRAM memory will not be overwritten. It maintains an internal reference to this |
| 1020 | information in the `bl2_to_bl31_params` variable. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1021 | |
| 1022 | ### Function : bl31_plat_arch_setup() [mandatory] |
| 1023 | |
| 1024 | Argument : void |
| 1025 | Return : void |
| 1026 | |
| 1027 | This function executes with the MMU and data caches disabled. It is only called |
| 1028 | by the primary CPU. |
| 1029 | |
| 1030 | The purpose of this function is to perform any architectural initialization |
| 1031 | that varies across platforms, for example enabling the MMU (since the memory |
| 1032 | map differs across platforms). |
| 1033 | |
| 1034 | |
| 1035 | ### Function : bl31_platform_setup() [mandatory] |
| 1036 | |
| 1037 | Argument : void |
| 1038 | Return : void |
| 1039 | |
| 1040 | This function may execute with the MMU and data caches enabled if the platform |
| 1041 | port does the necessary initialization in `bl31_plat_arch_setup()`. It is only |
| 1042 | called by the primary CPU. |
| 1043 | |
| 1044 | The purpose of this function is to complete platform initialization so that both |
| 1045 | BL3-1 runtime services and normal world software can function correctly. |
| 1046 | |
| 1047 | The ARM FVP port does the following: |
| 1048 | * Initializes the generic interrupt controller. |
| 1049 | * Configures the CLCD controller. |
Sandrine Bailleux | 9e86490 | 2014-03-31 11:25:18 +0100 | [diff] [blame] | 1050 | * Enables system-level implementation of the generic timer counter. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1051 | * Grants access to the system counter timer module |
| 1052 | * Initializes the FVP power controller device |
| 1053 | * Detects the system topology. |
| 1054 | |
| 1055 | |
| 1056 | ### Function : bl31_get_next_image_info() [mandatory] |
| 1057 | |
Achin Gupta | 35ca351 | 2014-02-19 17:58:33 +0000 | [diff] [blame] | 1058 | Argument : unsigned int |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 1059 | Return : entry_point_info * |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1060 | |
| 1061 | This function may execute with the MMU and data caches enabled if the platform |
| 1062 | port does the necessary initializations in `bl31_plat_arch_setup()`. |
| 1063 | |
| 1064 | This function is called by `bl31_main()` to retrieve information provided by |
Achin Gupta | 35ca351 | 2014-02-19 17:58:33 +0000 | [diff] [blame] | 1065 | BL2 for the next image in the security state specified by the argument. BL3-1 |
| 1066 | uses this information to pass control to that image in the specified security |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 1067 | state. This function must return a pointer to the `entry_point_info` structure |
Achin Gupta | 35ca351 | 2014-02-19 17:58:33 +0000 | [diff] [blame] | 1068 | (that was copied during `bl31_early_platform_setup()`) if the image exists. It |
| 1069 | should return NULL otherwise. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1070 | |
| 1071 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1072 | 3.3 Power State Coordination Interface (in BL3-1) |
| 1073 | ------------------------------------------------ |
| 1074 | |
| 1075 | The ARM Trusted Firmware's implementation of the PSCI API is based around the |
| 1076 | concept of an _affinity instance_. Each _affinity instance_ can be uniquely |
| 1077 | identified in a system by a CPU ID (the processor `MPIDR` is used in the PSCI |
| 1078 | interface) and an _affinity level_. A processing element (for example, a |
| 1079 | CPU) is at level 0. If the CPUs in the system are described in a tree where the |
| 1080 | node above a CPU is a logical grouping of CPUs that share some state, then |
| 1081 | affinity level 1 is that group of CPUs (for example, a cluster), and affinity |
| 1082 | level 2 is a group of clusters (for example, the system). The implementation |
| 1083 | assumes that the affinity level 1 ID can be computed from the affinity level 0 |
| 1084 | ID (for example, a unique cluster ID can be computed from the CPU ID). The |
| 1085 | current implementation computes this on the basis of the recommended use of |
| 1086 | `MPIDR` affinity fields in the ARM Architecture Reference Manual. |
| 1087 | |
| 1088 | BL3-1's platform initialization code exports a pointer to the platform-specific |
| 1089 | power management operations required for the PSCI implementation to function |
| 1090 | correctly. This information is populated in the `plat_pm_ops` structure. The |
| 1091 | PSCI implementation calls members of the `plat_pm_ops` structure for performing |
| 1092 | power management operations for each affinity instance. For example, the target |
| 1093 | CPU is specified by its `MPIDR` in a PSCI `CPU_ON` call. The `affinst_on()` |
| 1094 | handler (if present) is called for each affinity instance as the PSCI |
| 1095 | implementation powers up each affinity level implemented in the `MPIDR` (for |
| 1096 | example, CPU, cluster and system). |
| 1097 | |
| 1098 | The following functions must be implemented to initialize PSCI functionality in |
| 1099 | the ARM Trusted Firmware. |
| 1100 | |
| 1101 | |
| 1102 | ### Function : plat_get_aff_count() [mandatory] |
| 1103 | |
| 1104 | Argument : unsigned int, unsigned long |
| 1105 | Return : unsigned int |
| 1106 | |
| 1107 | This function may execute with the MMU and data caches enabled if the platform |
| 1108 | port does the necessary initializations in `bl31_plat_arch_setup()`. It is only |
| 1109 | called by the primary CPU. |
| 1110 | |
| 1111 | This function is called by the PSCI initialization code to detect the system |
| 1112 | topology. Its purpose is to return the number of affinity instances implemented |
| 1113 | at a given `affinity level` (specified by the first argument) and a given |
| 1114 | `MPIDR` (specified by the second argument). For example, on a dual-cluster |
| 1115 | system where first cluster implements 2 CPUs and the second cluster implements 4 |
| 1116 | CPUs, a call to this function with an `MPIDR` corresponding to the first cluster |
| 1117 | (`0x0`) and affinity level 0, would return 2. A call to this function with an |
| 1118 | `MPIDR` corresponding to the second cluster (`0x100`) and affinity level 0, |
| 1119 | would return 4. |
| 1120 | |
| 1121 | |
| 1122 | ### Function : plat_get_aff_state() [mandatory] |
| 1123 | |
| 1124 | Argument : unsigned int, unsigned long |
| 1125 | Return : unsigned int |
| 1126 | |
| 1127 | This function may execute with the MMU and data caches enabled if the platform |
| 1128 | port does the necessary initializations in `bl31_plat_arch_setup()`. It is only |
| 1129 | called by the primary CPU. |
| 1130 | |
| 1131 | This function is called by the PSCI initialization code. Its purpose is to |
| 1132 | return the state of an affinity instance. The affinity instance is determined by |
| 1133 | the affinity ID at a given `affinity level` (specified by the first argument) |
| 1134 | and an `MPIDR` (specified by the second argument). The state can be one of |
| 1135 | `PSCI_AFF_PRESENT` or `PSCI_AFF_ABSENT`. The latter state is used to cater for |
| 1136 | system topologies where certain affinity instances are unimplemented. For |
| 1137 | example, consider a platform that implements a single cluster with 4 CPUs and |
| 1138 | another CPU implemented directly on the interconnect with the cluster. The |
| 1139 | `MPIDR`s of the cluster would range from `0x0-0x3`. The `MPIDR` of the single |
| 1140 | CPU would be 0x100 to indicate that it does not belong to cluster 0. Cluster 1 |
| 1141 | is missing but needs to be accounted for to reach this single CPU in the |
| 1142 | topology tree. Hence it is marked as `PSCI_AFF_ABSENT`. |
| 1143 | |
| 1144 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1145 | ### Function : platform_setup_pm() [mandatory] |
| 1146 | |
Sandrine Bailleux | 4480425 | 2014-08-06 11:27:23 +0100 | [diff] [blame] | 1147 | Argument : const plat_pm_ops ** |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1148 | Return : int |
| 1149 | |
| 1150 | This function may execute with the MMU and data caches enabled if the platform |
| 1151 | port does the necessary initializations in `bl31_plat_arch_setup()`. It is only |
| 1152 | called by the primary CPU. |
| 1153 | |
| 1154 | This function is called by PSCI initialization code. Its purpose is to export |
| 1155 | handler routines for platform-specific power management actions by populating |
| 1156 | the passed pointer with a pointer to BL3-1's private `plat_pm_ops` structure. |
| 1157 | |
| 1158 | A description of each member of this structure is given below. Please refer to |
Sandrine Bailleux | 4480425 | 2014-08-06 11:27:23 +0100 | [diff] [blame] | 1159 | the ARM FVP specific implementation of these handlers in [plat/fvp/fvp_pm.c] |
Soby Mathew | 539dced | 2014-10-02 16:56:51 +0100 | [diff] [blame] | 1160 | as an example. A platform port is expected to implement these handlers if the |
| 1161 | corresponding PSCI operation is to be supported and these handlers are expected |
| 1162 | to succeed if the return type is `void`. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1163 | |
| 1164 | #### plat_pm_ops.affinst_standby() |
| 1165 | |
| 1166 | Perform the platform-specific setup to enter the standby state indicated by the |
Soby Mathew | 539dced | 2014-10-02 16:56:51 +0100 | [diff] [blame] | 1167 | passed argument. The generic code expects the handler to succeed. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1168 | |
| 1169 | #### plat_pm_ops.affinst_on() |
| 1170 | |
| 1171 | Perform the platform specific setup to power on an affinity instance, specified |
Soby Mathew | e146f4c | 2014-09-26 15:08:52 +0100 | [diff] [blame] | 1172 | by the `MPIDR` (first argument) and `affinity level` (third argument). The |
| 1173 | `state` (fourth argument) contains the current state of that affinity instance |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1174 | (ON or OFF). This is useful to determine whether any action must be taken. For |
| 1175 | example, while powering on a CPU, the cluster that contains this CPU might |
| 1176 | already be in the ON state. The platform decides what actions must be taken to |
| 1177 | transition from the current state to the target state (indicated by the power |
Soby Mathew | 539dced | 2014-10-02 16:56:51 +0100 | [diff] [blame] | 1178 | management operation). The generic code expects the platform to return |
| 1179 | E_SUCCESS on success or E_INTERN_FAIL for any failure. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1180 | |
| 1181 | #### plat_pm_ops.affinst_off() |
| 1182 | |
Soby Mathew | e146f4c | 2014-09-26 15:08:52 +0100 | [diff] [blame] | 1183 | Perform the platform specific setup to power off an affinity instance of the |
| 1184 | calling CPU. It is called by the PSCI `CPU_OFF` API implementation. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1185 | |
Soby Mathew | e146f4c | 2014-09-26 15:08:52 +0100 | [diff] [blame] | 1186 | The `affinity level` (first argument) and `state` (second argument) have |
| 1187 | a similar meaning as described in the `affinst_on()` operation. They are |
| 1188 | used to identify the affinity instance on which the call is made and its |
| 1189 | current state. This gives the platform port an indication of the |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1190 | state transition it must make to perform the requested action. For example, if |
| 1191 | the calling CPU is the last powered on CPU in the cluster, after powering down |
| 1192 | affinity level 0 (CPU), the platform port should power down affinity level 1 |
Soby Mathew | 539dced | 2014-10-02 16:56:51 +0100 | [diff] [blame] | 1193 | (the cluster) as well. The generic code expects the handler to succeed. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1194 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1195 | #### plat_pm_ops.affinst_suspend() |
| 1196 | |
Soby Mathew | e146f4c | 2014-09-26 15:08:52 +0100 | [diff] [blame] | 1197 | Perform the platform specific setup to power off an affinity instance of the |
| 1198 | calling CPU. It is called by the PSCI `CPU_SUSPEND` API |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1199 | implementation. |
| 1200 | |
Soby Mathew | e146f4c | 2014-09-26 15:08:52 +0100 | [diff] [blame] | 1201 | The `affinity level` (second argument) and `state` (third argument) have a |
| 1202 | similar meaning as described in the `affinst_on()` operation. They are used to |
| 1203 | identify the affinity instance on which the call is made and its current state. |
| 1204 | This gives the platform port an indication of the state transition it must |
| 1205 | make to perform the requested action. For example, if the calling CPU is the |
| 1206 | last powered on CPU in the cluster, after powering down affinity level 0 (CPU), |
| 1207 | the platform port should power down affinity level 1 (the cluster) as well. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1208 | |
| 1209 | The difference between turning an affinity instance off versus suspending it |
| 1210 | is that in the former case, the affinity instance is expected to re-initialize |
| 1211 | its state when its next powered on (see `affinst_on_finish()`). In the latter |
| 1212 | case, the affinity instance is expected to save enough state so that it can |
| 1213 | resume execution by restoring this state when its powered on (see |
Soby Mathew | 539dced | 2014-10-02 16:56:51 +0100 | [diff] [blame] | 1214 | `affinst_suspend_finish()`).The generic code expects the handler to succeed. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1215 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1216 | #### plat_pm_ops.affinst_on_finish() |
| 1217 | |
| 1218 | This function is called by the PSCI implementation after the calling CPU is |
| 1219 | powered on and released from reset in response to an earlier PSCI `CPU_ON` call. |
| 1220 | It performs the platform-specific setup required to initialize enough state for |
| 1221 | this CPU to enter the normal world and also provide secure runtime firmware |
| 1222 | services. |
| 1223 | |
Soby Mathew | e146f4c | 2014-09-26 15:08:52 +0100 | [diff] [blame] | 1224 | The `affinity level` (first argument) and `state` (second argument) have a |
Soby Mathew | 539dced | 2014-10-02 16:56:51 +0100 | [diff] [blame] | 1225 | similar meaning as described in the previous operations. The generic code |
| 1226 | expects the handler to succeed. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1227 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1228 | #### plat_pm_ops.affinst_on_suspend() |
| 1229 | |
| 1230 | This function is called by the PSCI implementation after the calling CPU is |
| 1231 | powered on and released from reset in response to an asynchronous wakeup |
| 1232 | event, for example a timer interrupt that was programmed by the CPU during the |
| 1233 | `CPU_SUSPEND` call. It performs the platform-specific setup required to |
| 1234 | restore the saved state for this CPU to resume execution in the normal world |
| 1235 | and also provide secure runtime firmware services. |
| 1236 | |
Soby Mathew | e146f4c | 2014-09-26 15:08:52 +0100 | [diff] [blame] | 1237 | The `affinity level` (first argument) and `state` (second argument) have a |
Soby Mathew | 539dced | 2014-10-02 16:56:51 +0100 | [diff] [blame] | 1238 | similar meaning as described in the previous operations. The generic code |
| 1239 | expects the platform to succeed. |
| 1240 | |
| 1241 | #### plat_pm_ops.validate_power_state() |
| 1242 | |
| 1243 | This function is called by the PSCI implementation during the `CPU_SUSPEND` |
| 1244 | call to validate the `power_state` parameter of the PSCI API. If the |
| 1245 | `power_state` is known to be invalid, the platform must return |
| 1246 | PSCI_E_INVALID_PARAMS as error, which is propagated back to the normal |
| 1247 | world PSCI client. |
| 1248 | |
| 1249 | #### plat_pm_ops.validate_ns_entrypoint() |
| 1250 | |
| 1251 | This function is called by the PSCI implementation during the `CPU_SUSPEND` |
| 1252 | and `CPU_ON` calls to validate the non-secure `entry_point` parameter passed |
| 1253 | by the normal world. If the `entry_point` is known to be invalid, the platform |
| 1254 | must return PSCI_E_INVALID_PARAMS as error, which is propagated back to the |
| 1255 | normal world PSCI client. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1256 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1257 | BL3-1 platform initialization code must also detect the system topology and |
| 1258 | the state of each affinity instance in the topology. This information is |
| 1259 | critical for the PSCI runtime service to function correctly. More details are |
| 1260 | provided in the description of the `plat_get_aff_count()` and |
| 1261 | `plat_get_aff_state()` functions above. |
| 1262 | |
Achin Gupta | a4fa3cb | 2014-06-02 22:27:36 +0100 | [diff] [blame] | 1263 | 3.4 Interrupt Management framework (in BL3-1) |
| 1264 | ---------------------------------------------- |
| 1265 | BL3-1 implements an Interrupt Management Framework (IMF) to manage interrupts |
| 1266 | generated in either security state and targeted to EL1 or EL2 in the non-secure |
| 1267 | state or EL3/S-EL1 in the secure state. The design of this framework is |
| 1268 | described in the [IMF Design Guide] |
| 1269 | |
| 1270 | A platform should export the following APIs to support the IMF. The following |
| 1271 | text briefly describes each api and its implementation on the FVP port. The API |
| 1272 | implementation depends upon the type of interrupt controller present in the |
| 1273 | platform. The FVP implements an ARM Generic Interrupt Controller (ARM GIC) as |
| 1274 | per the version 2.0 of the [ARM GIC Architecture Specification] |
| 1275 | |
| 1276 | ### Function : plat_interrupt_type_to_line() [mandatory] |
| 1277 | |
| 1278 | Argument : uint32_t, uint32_t |
| 1279 | Return : uint32_t |
| 1280 | |
| 1281 | The ARM processor signals an interrupt exception either through the IRQ or FIQ |
| 1282 | interrupt line. The specific line that is signaled depends on how the interrupt |
| 1283 | controller (IC) reports different interrupt types from an execution context in |
| 1284 | either security state. The IMF uses this API to determine which interrupt line |
| 1285 | the platform IC uses to signal each type of interrupt supported by the framework |
| 1286 | from a given security state. |
| 1287 | |
| 1288 | The first parameter will be one of the `INTR_TYPE_*` values (see [IMF Design |
| 1289 | Guide]) indicating the target type of the interrupt, the second parameter is the |
| 1290 | security state of the originating execution context. The return result is the |
| 1291 | bit position in the `SCR_EL3` register of the respective interrupt trap: IRQ=1, |
| 1292 | FIQ=2. |
| 1293 | |
| 1294 | The FVP port configures the ARM GIC to signal S-EL1 interrupts as FIQs and |
| 1295 | Non-secure interrupts as IRQs from either security state. |
| 1296 | |
| 1297 | |
| 1298 | ### Function : plat_ic_get_pending_interrupt_type() [mandatory] |
| 1299 | |
| 1300 | Argument : void |
| 1301 | Return : uint32_t |
| 1302 | |
| 1303 | This API returns the type of the highest priority pending interrupt at the |
| 1304 | platform IC. The IMF uses the interrupt type to retrieve the corresponding |
| 1305 | handler function. `INTR_TYPE_INVAL` is returned when there is no interrupt |
| 1306 | pending. The valid interrupt types that can be returned are `INTR_TYPE_EL3`, |
| 1307 | `INTR_TYPE_S_EL1` and `INTR_TYPE_NS`. |
| 1308 | |
| 1309 | The FVP port reads the _Highest Priority Pending Interrupt Register_ |
| 1310 | (`GICC_HPPIR`) to determine the id of the pending interrupt. The type of interrupt |
| 1311 | depends upon the id value as follows. |
| 1312 | |
| 1313 | 1. id < 1022 is reported as a S-EL1 interrupt |
| 1314 | 2. id = 1022 is reported as a Non-secure interrupt. |
| 1315 | 3. id = 1023 is reported as an invalid interrupt type. |
| 1316 | |
| 1317 | |
| 1318 | ### Function : plat_ic_get_pending_interrupt_id() [mandatory] |
| 1319 | |
| 1320 | Argument : void |
| 1321 | Return : uint32_t |
| 1322 | |
| 1323 | This API returns the id of the highest priority pending interrupt at the |
| 1324 | platform IC. The IMF passes the id returned by this API to the registered |
| 1325 | handler for the pending interrupt if the `IMF_READ_INTERRUPT_ID` build time flag |
| 1326 | is set. INTR_ID_UNAVAILABLE is returned when there is no interrupt pending. |
| 1327 | |
| 1328 | The FVP port reads the _Highest Priority Pending Interrupt Register_ |
| 1329 | (`GICC_HPPIR`) to determine the id of the pending interrupt. The id that is |
| 1330 | returned by API depends upon the value of the id read from the interrupt |
| 1331 | controller as follows. |
| 1332 | |
| 1333 | 1. id < 1022. id is returned as is. |
| 1334 | 2. id = 1022. The _Aliased Highest Priority Pending Interrupt Register_ |
| 1335 | (`GICC_AHPPIR`) is read to determine the id of the non-secure interrupt. This |
| 1336 | id is returned by the API. |
| 1337 | 3. id = 1023. `INTR_ID_UNAVAILABLE` is returned. |
| 1338 | |
| 1339 | |
| 1340 | ### Function : plat_ic_acknowledge_interrupt() [mandatory] |
| 1341 | |
| 1342 | Argument : void |
| 1343 | Return : uint32_t |
| 1344 | |
| 1345 | This API is used by the CPU to indicate to the platform IC that processing of |
| 1346 | the highest pending interrupt has begun. It should return the id of the |
| 1347 | interrupt which is being processed. |
| 1348 | |
| 1349 | The FVP port reads the _Interrupt Acknowledge Register_ (`GICC_IAR`). This |
| 1350 | changes the state of the highest priority pending interrupt from pending to |
| 1351 | active in the interrupt controller. It returns the value read from the |
| 1352 | `GICC_IAR`. This value is the id of the interrupt whose state has been changed. |
| 1353 | |
| 1354 | The TSP uses this API to start processing of the secure physical timer |
| 1355 | interrupt. |
| 1356 | |
| 1357 | |
| 1358 | ### Function : plat_ic_end_of_interrupt() [mandatory] |
| 1359 | |
| 1360 | Argument : uint32_t |
| 1361 | Return : void |
| 1362 | |
| 1363 | This API is used by the CPU to indicate to the platform IC that processing of |
| 1364 | the interrupt corresponding to the id (passed as the parameter) has |
| 1365 | finished. The id should be the same as the id returned by the |
| 1366 | `plat_ic_acknowledge_interrupt()` API. |
| 1367 | |
| 1368 | The FVP port writes the id to the _End of Interrupt Register_ |
| 1369 | (`GICC_EOIR`). This deactivates the corresponding interrupt in the interrupt |
| 1370 | controller. |
| 1371 | |
| 1372 | The TSP uses this API to finish processing of the secure physical timer |
| 1373 | interrupt. |
| 1374 | |
| 1375 | |
| 1376 | ### Function : plat_ic_get_interrupt_type() [mandatory] |
| 1377 | |
| 1378 | Argument : uint32_t |
| 1379 | Return : uint32_t |
| 1380 | |
| 1381 | This API returns the type of the interrupt id passed as the parameter. |
| 1382 | `INTR_TYPE_INVAL` is returned if the id is invalid. If the id is valid, a valid |
| 1383 | interrupt type (one of `INTR_TYPE_EL3`, `INTR_TYPE_S_EL1` and `INTR_TYPE_NS`) is |
| 1384 | returned depending upon how the interrupt has been configured by the platform |
| 1385 | IC. |
| 1386 | |
| 1387 | The FVP port configures S-EL1 interrupts as Group0 interrupts and Non-secure |
| 1388 | interrupts as Group1 interrupts. It reads the group value corresponding to the |
| 1389 | interrupt id from the relevant _Interrupt Group Register_ (`GICD_IGROUPRn`). It |
| 1390 | uses the group value to determine the type of interrupt. |
| 1391 | |
Soby Mathew | c67b09b | 2014-07-14 16:57:23 +0100 | [diff] [blame] | 1392 | 3.5 Crash Reporting mechanism (in BL3-1) |
| 1393 | ---------------------------------------------- |
| 1394 | BL3-1 implements a crash reporting mechanism which prints the various registers |
Sandrine Bailleux | 4480425 | 2014-08-06 11:27:23 +0100 | [diff] [blame] | 1395 | of the CPU to enable quick crash analysis and debugging. It requires that a |
| 1396 | console is designated as the crash console by the platform which will be used to |
| 1397 | print the register dump. |
Soby Mathew | c67b09b | 2014-07-14 16:57:23 +0100 | [diff] [blame] | 1398 | |
Sandrine Bailleux | 4480425 | 2014-08-06 11:27:23 +0100 | [diff] [blame] | 1399 | The following functions must be implemented by the platform if it wants crash |
| 1400 | reporting mechanism in BL3-1. The functions are implemented in assembly so that |
| 1401 | they can be invoked without a C Runtime stack. |
Soby Mathew | c67b09b | 2014-07-14 16:57:23 +0100 | [diff] [blame] | 1402 | |
| 1403 | ### Function : plat_crash_console_init |
| 1404 | |
| 1405 | Argument : void |
| 1406 | Return : int |
| 1407 | |
Sandrine Bailleux | 4480425 | 2014-08-06 11:27:23 +0100 | [diff] [blame] | 1408 | This API is used by the crash reporting mechanism to initialize the crash |
| 1409 | console. It should only use the general purpose registers x0 to x2 to do the |
| 1410 | initialization and returns 1 on success. |
Soby Mathew | c67b09b | 2014-07-14 16:57:23 +0100 | [diff] [blame] | 1411 | |
Sandrine Bailleux | 4480425 | 2014-08-06 11:27:23 +0100 | [diff] [blame] | 1412 | The FVP port designates the `PL011_UART0` as the crash console and calls the |
Soby Mathew | c67b09b | 2014-07-14 16:57:23 +0100 | [diff] [blame] | 1413 | console_core_init() to initialize the console. |
| 1414 | |
| 1415 | ### Function : plat_crash_console_putc |
| 1416 | |
| 1417 | Argument : int |
| 1418 | Return : int |
| 1419 | |
| 1420 | This API is used by the crash reporting mechanism to print a character on the |
| 1421 | designated crash console. It should only use general purpose registers x1 and |
| 1422 | x2 to do its work. The parameter and the return value are in general purpose |
| 1423 | register x0. |
| 1424 | |
Sandrine Bailleux | 4480425 | 2014-08-06 11:27:23 +0100 | [diff] [blame] | 1425 | The FVP port designates the `PL011_UART0` as the crash console and calls the |
Soby Mathew | c67b09b | 2014-07-14 16:57:23 +0100 | [diff] [blame] | 1426 | console_core_putc() to print the character on the console. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1427 | |
Soby Mathew | 27713fb | 2014-09-08 17:51:01 +0100 | [diff] [blame] | 1428 | 4. Build flags |
| 1429 | --------------- |
| 1430 | |
| 1431 | There are some build flags which can be defined by the platform to control |
| 1432 | inclusion or exclusion of certain BL stages from the FIP image. These flags |
| 1433 | need to be defined in the platform makefile which will get included by the |
| 1434 | build system. |
| 1435 | |
| 1436 | * **NEED_BL30** |
| 1437 | This flag if defined by the platform mandates that a BL3-0 binary should |
| 1438 | be included in the FIP image. The path to the BL3-0 binary can be specified |
| 1439 | by the `BL30` build option (see build options in the [User Guide]). |
| 1440 | |
| 1441 | * **NEED_BL33** |
| 1442 | By default, this flag is defined `yes` by the build system and `BL33` |
| 1443 | build option should be supplied as a build option. The platform has the option |
| 1444 | of excluding the BL3-3 image in the `fip` image by defining this flag to |
| 1445 | `no`. |
| 1446 | |
| 1447 | 5. C Library |
Harry Liebel | a960f28 | 2013-12-12 16:03:44 +0000 | [diff] [blame] | 1448 | ------------- |
| 1449 | |
| 1450 | To avoid subtle toolchain behavioral dependencies, the header files provided |
| 1451 | by the compiler are not used. The software is built with the `-nostdinc` flag |
| 1452 | to ensure no headers are included from the toolchain inadvertently. Instead the |
| 1453 | required headers are included in the ARM Trusted Firmware source tree. The |
| 1454 | library only contains those C library definitions required by the local |
| 1455 | implementation. If more functionality is required, the needed library functions |
| 1456 | will need to be added to the local implementation. |
| 1457 | |
| 1458 | Versions of [FreeBSD] headers can be found in `include/stdlib`. Some of these |
| 1459 | headers have been cut down in order to simplify the implementation. In order to |
| 1460 | minimize changes to the header files, the [FreeBSD] layout has been maintained. |
| 1461 | The generic C library definitions can be found in `include/stdlib` with more |
| 1462 | system and machine specific declarations in `include/stdlib/sys` and |
| 1463 | `include/stdlib/machine`. |
| 1464 | |
| 1465 | The local C library implementations can be found in `lib/stdlib`. In order to |
| 1466 | extend the C library these files may need to be modified. It is recommended to |
| 1467 | use a release version of [FreeBSD] as a starting point. |
| 1468 | |
| 1469 | The C library header files in the [FreeBSD] source tree are located in the |
| 1470 | `include` and `sys/sys` directories. [FreeBSD] machine specific definitions |
| 1471 | can be found in the `sys/<machine-type>` directories. These files define things |
| 1472 | like 'the size of a pointer' and 'the range of an integer'. Since an AArch64 |
| 1473 | port for [FreeBSD] does not yet exist, the machine specific definitions are |
| 1474 | based on existing machine types with similar properties (for example SPARC64). |
| 1475 | |
| 1476 | Where possible, C library function implementations were taken from [FreeBSD] |
| 1477 | as found in the `lib/libc` directory. |
| 1478 | |
| 1479 | A copy of the [FreeBSD] sources can be downloaded with `git`. |
| 1480 | |
| 1481 | git clone git://github.com/freebsd/freebsd.git -b origin/release/9.2.0 |
| 1482 | |
| 1483 | |
Soby Mathew | 27713fb | 2014-09-08 17:51:01 +0100 | [diff] [blame] | 1484 | 6. Storage abstraction layer |
Harry Liebel | d265bd7 | 2014-01-31 19:04:10 +0000 | [diff] [blame] | 1485 | ----------------------------- |
| 1486 | |
| 1487 | In order to improve platform independence and portability an storage abstraction |
| 1488 | layer is used to load data from non-volatile platform storage. |
| 1489 | |
| 1490 | Each platform should register devices and their drivers via the Storage layer. |
| 1491 | These drivers then need to be initialized by bootloader phases as |
| 1492 | required in their respective `blx_platform_setup()` functions. Currently |
| 1493 | storage access is only required by BL1 and BL2 phases. The `load_image()` |
| 1494 | function uses the storage layer to access non-volatile platform storage. |
| 1495 | |
| 1496 | It is mandatory to implement at least one storage driver. For the FVP the |
| 1497 | Firmware Image Package(FIP) driver is provided as the default means to load data |
| 1498 | from storage (see the "Firmware Image Package" section in the [User Guide]). |
Sandrine Bailleux | 121f2ae | 2015-01-28 10:11:48 +0000 | [diff] [blame] | 1499 | The storage layer is described in the header file |
| 1500 | `include/drivers/io/io_storage.h`. The implementation of the common library |
| 1501 | is in `drivers/io/io_storage.c` and the driver files are located in |
| 1502 | `drivers/io/`. |
Harry Liebel | d265bd7 | 2014-01-31 19:04:10 +0000 | [diff] [blame] | 1503 | |
| 1504 | Each IO driver must provide `io_dev_*` structures, as described in |
| 1505 | `drivers/io/io_driver.h`. These are returned via a mandatory registration |
| 1506 | function that is called on platform initialization. The semi-hosting driver |
| 1507 | implementation in `io_semihosting.c` can be used as an example. |
| 1508 | |
| 1509 | The Storage layer provides mechanisms to initialize storage devices before |
| 1510 | IO operations are called. The basic operations supported by the layer |
| 1511 | include `open()`, `close()`, `read()`, `write()`, `size()` and `seek()`. |
| 1512 | Drivers do not have to implement all operations, but each platform must |
| 1513 | provide at least one driver for a device capable of supporting generic |
| 1514 | operations such as loading a bootloader image. |
| 1515 | |
| 1516 | The current implementation only allows for known images to be loaded by the |
Dan Handley | b68954c | 2014-05-29 12:30:24 +0100 | [diff] [blame] | 1517 | firmware. These images are specified by using their names, as defined in |
| 1518 | [include/plat/common/platform.h]. The platform layer (`plat_get_image_source()`) |
| 1519 | then returns a reference to a device and a driver-specific `spec` which will be |
| 1520 | understood by the driver to allow access to the image data. |
Harry Liebel | d265bd7 | 2014-01-31 19:04:10 +0000 | [diff] [blame] | 1521 | |
| 1522 | The layer is designed in such a way that is it possible to chain drivers with |
| 1523 | other drivers. For example, file-system drivers may be implemented on top of |
| 1524 | physical block devices, both represented by IO devices with corresponding |
| 1525 | drivers. In such a case, the file-system "binding" with the block device may |
| 1526 | be deferred until the file-system device is initialised. |
| 1527 | |
| 1528 | The abstraction currently depends on structures being statically allocated |
| 1529 | by the drivers and callers, as the system does not yet provide a means of |
| 1530 | dynamically allocating memory. This may also have the affect of limiting the |
| 1531 | amount of open resources per driver. |
| 1532 | |
| 1533 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1534 | - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 1535 | |
Dan Handley | e83b0ca | 2014-01-14 18:17:09 +0000 | [diff] [blame] | 1536 | _Copyright (c) 2013-2014, ARM Limited and Contributors. All rights reserved._ |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1537 | |
| 1538 | |
Achin Gupta | a4fa3cb | 2014-06-02 22:27:36 +0100 | [diff] [blame] | 1539 | [ARM GIC Architecture Specification]: http://arminfo.emea.arm.com/help/topic/com.arm.doc.ihi0048b/IHI0048B_gic_architecture_specification.pdf |
| 1540 | [IMF Design Guide]: interrupt-framework-design.md |
| 1541 | [User Guide]: user-guide.md |
| 1542 | [FreeBSD]: http://www.freebsd.org |
Yatharth Kochar | 79a97b2 | 2014-11-20 18:09:41 +0000 | [diff] [blame] | 1543 | [Firmware Design Guide]: firmware-design.md |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1544 | |
Andrew Thoelke | 2bf28e6 | 2014-03-20 10:48:23 +0000 | [diff] [blame] | 1545 | [plat/common/aarch64/platform_mp_stack.S]: ../plat/common/aarch64/platform_mp_stack.S |
| 1546 | [plat/common/aarch64/platform_up_stack.S]: ../plat/common/aarch64/platform_up_stack.S |
Dan Handley | b68954c | 2014-05-29 12:30:24 +0100 | [diff] [blame] | 1547 | [plat/fvp/include/platform_def.h]: ../plat/fvp/include/platform_def.h |
| 1548 | [plat/fvp/include/plat_macros.S]: ../plat/fvp/include/plat_macros.S |
Andrew Thoelke | 2bf28e6 | 2014-03-20 10:48:23 +0000 | [diff] [blame] | 1549 | [plat/fvp/aarch64/plat_common.c]: ../plat/fvp/aarch64/plat_common.c |
| 1550 | [plat/fvp/plat_pm.c]: ../plat/fvp/plat_pm.c |
| 1551 | [include/runtime_svc.h]: ../include/runtime_svc.h |
Dan Handley | b68954c | 2014-05-29 12:30:24 +0100 | [diff] [blame] | 1552 | [include/plat/common/platform.h]: ../include/plat/common/platform.h |