blob: 05a99758b7b8c4860f7c0713b1889ff07a5010fa [file] [log] [blame] [view]
Achin Gupta4f6ad662013-10-25 09:08:21 +01001ARM Trusted Firmware Porting Guide
2==================================
3
4Contents
5--------
6
Joakim Bech14a5b342014-11-25 10:55:26 +010071. [Introduction](#1--introduction)
82. [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)
123. [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)
194. [Build flags](#4--build-flags)
205. [C Library](#5--c-library)
216. [Storage abstraction layer](#6--storage-abstraction-layer)
Achin Gupta4f6ad662013-10-25 09:08:21 +010022
23- - - - - - - - - - - - - - - - - -
24
251. Introduction
26----------------
27
28Porting the ARM Trusted Firmware to a new platform involves making some
29mandatory and optional modifications for both the cold and warm boot paths.
30Modifications 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 Handley4a75b842015-03-19 19:24:43 +000036The platform-specific functions and variables are declared in
Dan Handleyb68954c2014-05-29 12:30:24 +010037[include/plat/common/platform.h]. The firmware provides a default implementation
38of variables and functions to fulfill the optional requirements. These
39implementations are all weakly defined; they are provided to ease the porting
40effort. Each platform port can override them with its own implementation if the
41default implementation is inadequate.
Achin Gupta4f6ad662013-10-25 09:08:21 +010042
Dan Handley4a75b842015-03-19 19:24:43 +000043Platform ports that want to be aligned with standard ARM platforms (for example
44FVP and Juno) may also use [include/plat/arm/common/plat_arm.h] and the
45corresponding source files in `plat/arm/common/`. These provide standard
46implementations for some of the required platform porting functions. However,
47using these functions requires the platform port to implement additional
48ARM standard platform porting functions. These additional functions are not
49documented here.
50
Achin Gupta4f6ad662013-10-25 09:08:21 +010051Some modifications are common to all Boot Loader (BL) stages. Section 2
52discusses these in detail. The subsequent sections discuss the remaining
53modifications for each BL stage in detail.
54
55This document should be read in conjunction with the ARM Trusted Firmware
56[User Guide].
57
58
592. Common modifications
60------------------------
61
62This section covers the modifications that should be made by the platform for
63each BL stage to correctly port the firmware stack. They are categorized as
64either mandatory or optional.
65
66
672.1 Common mandatory modifications
68----------------------------------
69A platform port must enable the Memory Management Unit (MMU) with identity
70mapped page tables, and enable both the instruction and data caches for each BL
Dan Handley4a75b842015-03-19 19:24:43 +000071stage. In ARM standard platforms, each BL stage configures the MMU in
72the platform-specific architecture setup function, `blX_plat_arch_setup()`.
Achin Gupta4f6ad662013-10-25 09:08:21 +010073
Soby Mathewab8707e2015-01-08 18:02:44 +000074If the build option `USE_COHERENT_MEM` is enabled, each platform must allocate a
75block of identity mapped secure memory with Device-nGnRE attributes aligned to
76page boundary (4K) for each BL stage. This memory is identified by the section
77name `tzfw_coherent_mem` so that its possible for the firmware to place
78variables in it using the following C code directive:
Achin Gupta4f6ad662013-10-25 09:08:21 +010079
80 __attribute__ ((section("tzfw_coherent_mem")))
81
82Or alternatively the following assembler code directive:
83
84 .section tzfw_coherent_mem
85
86The `tzfw_coherent_mem` section is used to allocate any data structures that are
87accessed both when a CPU is executing with its MMU and caches enabled, and when
88it's running with its MMU and caches disabled. Examples are given below.
89
90The following variables, functions and constants must be defined by the platform
91for the firmware to work correctly.
92
93
Dan Handleyb68954c2014-05-29 12:30:24 +010094### File : platform_def.h [mandatory]
Achin Gupta4f6ad662013-10-25 09:08:21 +010095
Dan Handleyb68954c2014-05-29 12:30:24 +010096Each platform must ensure that a header file of this name is in the system
97include path with the following constants defined. This may require updating the
Dan Handley4a75b842015-03-19 19:24:43 +000098list of `PLAT_INCLUDES` in the `platform.mk` file. In the ARM development
99platforms, this file is found in `plat/arm/board/<plat_name>/include/`.
100
101Platform ports may optionally use the file [include/plat/common/common_def.h],
102which provides typical values for some of the constants below. These values are
103likely to be suitable for all platform ports.
104
105Platform ports that want to be aligned with standard ARM platforms (for example
106FVP and Juno) may also use [include/plat/arm/common/arm_def.h], which provides
107standard values for some of the constants below. However, this requires the
108platform port to define additional platform porting constants in
109`platform_def.h`. These additional constants are not documented here.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100110
James Morrisseyba3155b2013-10-29 10:56:46 +0000111* **#define : PLATFORM_LINKER_FORMAT**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100112
113 Defines the linker format used by the platform, for example
Dan Handley4a75b842015-03-19 19:24:43 +0000114 `elf64-littleaarch64`.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100115
James Morrisseyba3155b2013-10-29 10:56:46 +0000116* **#define : PLATFORM_LINKER_ARCH**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100117
118 Defines the processor architecture for the linker by the platform, for
Dan Handley4a75b842015-03-19 19:24:43 +0000119 example `aarch64`.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100120
James Morrisseyba3155b2013-10-29 10:56:46 +0000121* **#define : PLATFORM_STACK_SIZE**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100122
123 Defines the normal stack memory available to each CPU. This constant is used
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000124 by [plat/common/aarch64/platform_mp_stack.S] and
125 [plat/common/aarch64/platform_up_stack.S].
126
Dan Handley4a75b842015-03-19 19:24:43 +0000127* **define : CACHE_WRITEBACK_GRANULE**
128
129 Defines the size in bits of the largest cache line across all the cache
130 levels in the platform.
131
James Morrisseyba3155b2013-10-29 10:56:46 +0000132* **#define : FIRMWARE_WELCOME_STR**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100133
134 Defines the character string printed by BL1 upon entry into the `bl1_main()`
135 function.
136
James Morrisseyba3155b2013-10-29 10:56:46 +0000137* **#define : BL2_IMAGE_NAME**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100138
139 Name of the BL2 binary image on the host file-system. This name is used by
Harry Liebeld265bd72014-01-31 19:04:10 +0000140 BL1 to load BL2 into secure memory from non-volatile storage.
141
142* **#define : BL31_IMAGE_NAME**
143
144 Name of the BL3-1 binary image on the host file-system. This name is used by
145 BL2 to load BL3-1 into secure memory from platform storage.
146
147* **#define : BL33_IMAGE_NAME**
148
149 Name of the BL3-3 binary image on the host file-system. This name is used by
150 BL2 to load BL3-3 into non-secure memory from platform storage.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100151
Achin Gupta8d35f612015-01-25 22:44:23 +0000152* **#define : BL2_CERT_NAME**
153
154 Name of the BL2 content certificate on the host file-system (mandatory when
155 Trusted Board Boot is enabled).
156
157* **#define : TRUSTED_KEY_CERT_NAME**
158
159 Name of the Trusted Key certificate on the host file-system (mandatory when
160 Trusted Board Boot is enabled).
161
162* **#define : BL31_KEY_CERT_NAME**
163
164 Name of the BL3-1 Key certificate on the host file-system (mandatory when
165 Trusted Board Boot is enabled).
166
167* **#define : BL31_CERT_NAME**
168
169 Name of the BL3-1 Content certificate on the host file-system (mandatory
170 when Trusted Board Boot is enabled).
171
172* **#define : BL33_KEY_CERT_NAME**
173
174 Name of the BL3-3 Key certificate on the host file-system (mandatory when
175 Trusted Board Boot is enabled).
176
177* **#define : BL33_CERT_NAME**
178
179 Name of the BL3-3 Content certificate on the host file-system (mandatory
180 when Trusted Board Boot is enabled).
181
James Morrisseyba3155b2013-10-29 10:56:46 +0000182* **#define : PLATFORM_CORE_COUNT**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100183
184 Defines the total number of CPUs implemented by the platform across all
185 clusters in the system.
186
Andrew Thoelke6c0b45d2014-06-20 00:36:14 +0100187* **#define : PLATFORM_NUM_AFFS**
188
189 Defines the total number of nodes in the affinity heirarchy at all affinity
190 levels used by the platform.
191
Soby Mathew8c32bc22015-02-12 14:45:02 +0000192* **#define : PLATFORM_MAX_AFFLVL**
193
194 Defines the maximum affinity level that the power management operations
195 should apply to. ARMv8-A has support for 4 affinity levels. It is likely
196 that hardware will implement fewer affinity levels. This macro allows the
197 PSCI implementation to consider only those affinity levels in the system
198 that the platform implements. For example, the Base AEM FVP implements two
199 clusters with a configurable number of CPUs. It reports the maximum
200 affinity level as 1, resulting in PSCI power control up to the cluster
201 level.
202
Sandrine Bailleux638363e2014-05-21 17:08:26 +0100203* **#define : BL1_RO_BASE**
204
205 Defines the base address in secure ROM where BL1 originally lives. Must be
206 aligned on a page-size boundary.
207
208* **#define : BL1_RO_LIMIT**
209
210 Defines the maximum address in secure ROM that BL1's actual content (i.e.
211 excluding any data section allocated at runtime) can occupy.
212
213* **#define : BL1_RW_BASE**
214
215 Defines the base address in secure RAM where BL1's read-write data will live
216 at runtime. Must be aligned on a page-size boundary.
217
218* **#define : BL1_RW_LIMIT**
219
220 Defines the maximum address in secure RAM that BL1's read-write data can
221 occupy at runtime.
222
James Morrisseyba3155b2013-10-29 10:56:46 +0000223* **#define : BL2_BASE**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100224
225 Defines the base address in secure RAM where BL1 loads the BL2 binary image.
Sandrine Bailleuxcd29b0a2013-11-27 10:32:17 +0000226 Must be aligned on a page-size boundary.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100227
Sandrine Bailleux638363e2014-05-21 17:08:26 +0100228* **#define : BL2_LIMIT**
229
230 Defines the maximum address in secure RAM that the BL2 image can occupy.
231
James Morrisseyba3155b2013-10-29 10:56:46 +0000232* **#define : BL31_BASE**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100233
234 Defines the base address in secure RAM where BL2 loads the BL3-1 binary
Sandrine Bailleuxcd29b0a2013-11-27 10:32:17 +0000235 image. Must be aligned on a page-size boundary.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100236
Sandrine Bailleux638363e2014-05-21 17:08:26 +0100237* **#define : BL31_LIMIT**
238
239 Defines the maximum address in secure RAM that the BL3-1 image can occupy.
240
Harry Liebeld265bd72014-01-31 19:04:10 +0000241* **#define : NS_IMAGE_OFFSET**
Sandrine Bailleux2467f702014-05-20 17:22:24 +0100242
Harry Liebeld265bd72014-01-31 19:04:10 +0000243 Defines the base address in non-secure DRAM where BL2 loads the BL3-3 binary
244 image. Must be aligned on a page-size boundary.
245
Achin Gupta8d35f612015-01-25 22:44:23 +0000246If a BL3-0 image is supported by the platform, the following constants must
247also be defined:
248
249* **#define : BL30_IMAGE_NAME**
250
251 Name of the BL3-0 binary image on the host file-system. This name is used by
252 BL2 to load BL3-0 into secure memory from platform storage before being
253 transfered to the SCP.
254
255* **#define : BL30_KEY_CERT_NAME**
256
257 Name of the BL3-0 Key certificate on the host file-system (mandatory when
258 Trusted Board Boot is enabled).
259
260* **#define : BL30_CERT_NAME**
261
262 Name of the BL3-0 Content certificate on the host file-system (mandatory
263 when Trusted Board Boot is enabled).
264
Dan Handley5a06bb72014-08-04 11:41:20 +0100265If a BL3-2 image is supported by the platform, the following constants must
266also be defined:
Sandrine Bailleux2467f702014-05-20 17:22:24 +0100267
Dan Handley5a06bb72014-08-04 11:41:20 +0100268* **#define : BL32_IMAGE_NAME**
Sandrine Bailleux2467f702014-05-20 17:22:24 +0100269
Dan Handley5a06bb72014-08-04 11:41:20 +0100270 Name of the BL3-2 binary image on the host file-system. This name is used by
271 BL2 to load BL3-2 into secure memory from platform storage.
Sandrine Bailleux2467f702014-05-20 17:22:24 +0100272
Achin Gupta8d35f612015-01-25 22:44:23 +0000273* **#define : BL32_KEY_CERT_NAME**
274
275 Name of the BL3-2 Key certificate on the host file-system (mandatory when
276 Trusted Board Boot is enabled).
277
278* **#define : BL32_CERT_NAME**
279
280 Name of the BL3-2 Content certificate on the host file-system (mandatory
281 when Trusted Board Boot is enabled).
282
Sandrine Bailleux2467f702014-05-20 17:22:24 +0100283* **#define : BL32_BASE**
284
285 Defines the base address in secure memory where BL2 loads the BL3-2 binary
Dan Handley5a06bb72014-08-04 11:41:20 +0100286 image. Must be aligned on a page-size boundary.
Sandrine Bailleux2467f702014-05-20 17:22:24 +0100287
288* **#define : BL32_LIMIT**
289
Dan Handley5a06bb72014-08-04 11:41:20 +0100290 Defines the maximum address that the BL3-2 image can occupy.
291
292If the Test Secure-EL1 Payload (TSP) instantiation of BL3-2 is supported by the
293platform, the following constants must also be defined:
294
295* **#define : TSP_SEC_MEM_BASE**
296
297 Defines the base address of the secure memory used by the TSP image on the
298 platform. This must be at the same address or below `BL32_BASE`.
299
300* **#define : TSP_SEC_MEM_SIZE**
301
302 Defines the size of the secure memory used by the BL3-2 image on the
303 platform. `TSP_SEC_MEM_BASE` and `TSP_SEC_MEM_SIZE` must fully accomodate
304 the memory required by the BL3-2 image, defined by `BL32_BASE` and
305 `BL32_LIMIT`.
306
307* **#define : TSP_IRQ_SEC_PHY_TIMER**
308
309 Defines the ID of the secure physical generic timer interrupt used by the
310 TSP's interrupt handling code.
Sandrine Bailleux2467f702014-05-20 17:22:24 +0100311
Dan Handley4a75b842015-03-19 19:24:43 +0000312If the platform port uses the translation table library code, the following
313constant must also be defined:
314
315* **#define : MAX_XLAT_TABLES**
316
317 Defines the maximum number of translation tables that are allocated by the
318 translation table library code. To minimize the amount of runtime memory
319 used, choose the smallest value needed to map the required virtual addresses
320 for each BL stage.
321
Dan Handley6d16ce02014-08-04 18:31:43 +0100322If the platform port uses the IO storage framework, the following constants
323must also be defined:
324
325* **#define : MAX_IO_DEVICES**
326
327 Defines the maximum number of registered IO devices. Attempting to register
328 more devices than this value using `io_register_device()` will fail with
329 IO_RESOURCES_EXHAUSTED.
330
331* **#define : MAX_IO_HANDLES**
332
333 Defines the maximum number of open IO handles. Attempting to open more IO
334 entities than this value using `io_open()` will fail with
335 IO_RESOURCES_EXHAUSTED.
336
Soby Mathewab8707e2015-01-08 18:02:44 +0000337If the platform needs to allocate data within the per-cpu data framework in
338BL3-1, it should define the following macro. Currently this is only required if
339the platform decides not to use the coherent memory section by undefining the
340USE_COHERENT_MEM build flag. In this case, the framework allocates the required
341memory within the the per-cpu data to minimize wastage.
342
343* **#define : PLAT_PCPU_DATA_SIZE**
344
345 Defines the memory (in bytes) to be reserved within the per-cpu data
346 structure for use by the platform layer.
347
Sandrine Bailleux46d49f632014-06-23 17:00:23 +0100348The following constants are optional. They should be defined when the platform
Dan Handley4a75b842015-03-19 19:24:43 +0000349memory layout implies some image overlaying like in ARM standard platforms.
Sandrine Bailleux46d49f632014-06-23 17:00:23 +0100350
351* **#define : BL31_PROGBITS_LIMIT**
352
353 Defines the maximum address in secure RAM that the BL3-1's progbits sections
354 can occupy.
355
Dan Handley5a06bb72014-08-04 11:41:20 +0100356* **#define : TSP_PROGBITS_LIMIT**
Sandrine Bailleux46d49f632014-06-23 17:00:23 +0100357
358 Defines the maximum address that the TSP's progbits sections can occupy.
Sandrine Bailleux2467f702014-05-20 17:22:24 +0100359
Dan Handleyb68954c2014-05-29 12:30:24 +0100360### File : plat_macros.S [mandatory]
Soby Mathewa43d4312014-04-07 15:28:55 +0100361
Dan Handleyb68954c2014-05-29 12:30:24 +0100362Each platform must ensure a file of this name is in the system include path with
Dan Handley4a75b842015-03-19 19:24:43 +0000363the following macro defined. In the ARM development platforms, this file is
364found in `plat/arm/board/<plat_name>/include/plat_macros.S`.
Soby Mathewa43d4312014-04-07 15:28:55 +0100365
366* **Macro : plat_print_gic_regs**
367
368 This macro allows the crash reporting routine to print GIC registers
Soby Mathew8c106902014-07-16 09:23:52 +0100369 in case of an unhandled exception in BL3-1. This aids in debugging and
Soby Mathewa43d4312014-04-07 15:28:55 +0100370 this macro can be defined to be empty in case GIC register reporting is
371 not desired.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100372
Soby Mathew8c106902014-07-16 09:23:52 +0100373* **Macro : plat_print_interconnect_regs**
374
Dan Handley4a75b842015-03-19 19:24:43 +0000375 This macro allows the crash reporting routine to print interconnect
376 registers in case of an unhandled exception in BL3-1. This aids in debugging
377 and this macro can be defined to be empty in case interconnect register
378 reporting is not desired. In ARM standard platforms, the CCI snoop
379 control registers are reported.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100380
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000381
Vikram Kanigirie452cd82014-05-23 15:56:12 +01003822.2 Handling Reset
383------------------
384
385BL1 by default implements the reset vector where execution starts from a cold
386or warm boot. BL3-1 can be optionally set as a reset vector using the
387RESET_TO_BL31 make variable.
388
389For each CPU, the reset vector code is responsible for the following tasks:
390
3911. Distinguishing between a cold boot and a warm boot.
392
3932. In the case of a cold boot and the CPU being a secondary CPU, ensuring that
394 the CPU is placed in a platform-specific state until the primary CPU
395 performs the necessary steps to remove it from this state.
396
3973. In the case of a warm boot, ensuring that the CPU jumps to a platform-
398 specific address in the BL3-1 image in the same processor mode as it was
399 when released from reset.
400
401The following functions need to be implemented by the platform port to enable
402reset vector code to perform the above tasks.
403
404
405### Function : platform_get_entrypoint() [mandatory]
406
407 Argument : unsigned long
408 Return : unsigned int
409
410This function is called with the `SCTLR.M` and `SCTLR.C` bits disabled. The CPU
411is identified by its `MPIDR`, which is passed as the argument. The function is
412responsible for distinguishing between a warm and cold reset using platform-
413specific means. If it's a warm reset then it returns the entrypoint into the
414BL3-1 image that the CPU must jump to. If it's a cold reset then this function
415must return zero.
416
417This function is also responsible for implementing a platform-specific mechanism
418to handle the condition where the CPU has been warm reset but there is no
419entrypoint to jump to.
420
421This function does not follow the Procedure Call Standard used by the
422Application Binary Interface for the ARM 64-bit architecture. The caller should
423not assume that callee saved registers are preserved across a call to this
424function.
425
426This function fulfills requirement 1 and 3 listed above.
427
428
429### Function : plat_secondary_cold_boot_setup() [mandatory]
430
431 Argument : void
432 Return : void
433
434This function is called with the MMU and data caches disabled. It is responsible
435for placing the executing secondary CPU in a platform-specific state until the
436primary CPU performs the necessary actions to bring it out of that state and
437allow entry into the OS.
438
439In the ARM FVP port, each secondary CPU powers itself off. The primary CPU is
440responsible for powering up the secondary CPU when normal world software
441requires them.
442
443This function fulfills requirement 2 above.
444
445
Juan Castillo53fdceb2014-07-16 15:53:43 +0100446### Function : platform_is_primary_cpu() [mandatory]
447
448 Argument : unsigned long
449 Return : unsigned int
450
451This function identifies a CPU by its `MPIDR`, which is passed as the argument,
452to determine whether this CPU is the primary CPU or a secondary CPU. A return
453value of zero indicates that the CPU is not the primary CPU, while a non-zero
454return value indicates that the CPU is the primary CPU.
455
456
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100457### Function : platform_mem_init() [mandatory]
458
459 Argument : void
460 Return : void
461
462This function is called before any access to data is made by the firmware, in
463order to carry out any essential memory initialization.
464
465The ARM FVP port uses this function to initialize the mailbox memory used for
466providing the warm-boot entry-point addresses.
467
468
Juan Castillo6eadf762015-01-07 10:39:25 +0000469### Function: plat_match_rotpk()
470
471 Argument : const unsigned char *, unsigned int
472 Return : int
473
474This function is mandatory when Trusted Board Boot is enabled. It receives a
475pointer to a buffer containing a signing key and its size as parameters and
476returns 0 (success) if that key matches the ROT (Root Of Trust) key stored in
477the platform. Any other return value means a mismatch.
478
479
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100480
4812.3 Common optional modifications
Achin Gupta4f6ad662013-10-25 09:08:21 +0100482---------------------------------
483
484The following are helper functions implemented by the firmware that perform
485common platform-specific tasks. A platform may choose to override these
486definitions.
487
488
489### Function : platform_get_core_pos()
490
491 Argument : unsigned long
492 Return : int
493
494A platform may need to convert the `MPIDR` of a CPU to an absolute number, which
495can be used as a CPU-specific linear index into blocks of memory (for example
496while allocating per-CPU stacks). This routine contains a simple mechanism
497to perform this conversion, using the assumption that each cluster contains a
498maximum of 4 CPUs:
499
500 linear index = cpu_id + (cluster_id * 4)
501
502 cpu_id = 8-bit value in MPIDR at affinity level 0
503 cluster_id = 8-bit value in MPIDR at affinity level 1
504
505
Achin Gupta4f6ad662013-10-25 09:08:21 +0100506### Function : platform_set_stack()
507
508 Argument : unsigned long
509 Return : void
510
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000511This function sets the current stack pointer to the normal memory stack that
512has been allocated for the CPU specificed by MPIDR. For BL images that only
513require a stack for the primary CPU the parameter is ignored. The size of
514the stack allocated to each CPU is specified by the platform defined constant
515`PLATFORM_STACK_SIZE`.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100516
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000517Common implementations of this function for the UP and MP BL images are
518provided in [plat/common/aarch64/platform_up_stack.S] and
519[plat/common/aarch64/platform_mp_stack.S]
Achin Gupta4f6ad662013-10-25 09:08:21 +0100520
521
Achin Guptac8afc782013-11-25 18:45:02 +0000522### Function : platform_get_stack()
523
524 Argument : unsigned long
525 Return : unsigned long
526
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000527This function returns the base address of the normal memory stack that
528has been allocated for the CPU specificed by MPIDR. For BL images that only
529require a stack for the primary CPU the parameter is ignored. The size of
530the stack allocated to each CPU is specified by the platform defined constant
531`PLATFORM_STACK_SIZE`.
Achin Guptac8afc782013-11-25 18:45:02 +0000532
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000533Common implementations of this function for the UP and MP BL images are
534provided in [plat/common/aarch64/platform_up_stack.S] and
535[plat/common/aarch64/platform_mp_stack.S]
Achin Guptac8afc782013-11-25 18:45:02 +0000536
537
Achin Gupta4f6ad662013-10-25 09:08:21 +0100538### Function : plat_report_exception()
539
540 Argument : unsigned int
541 Return : void
542
543A platform may need to report various information about its status when an
544exception is taken, for example the current exception level, the CPU security
545state (secure/non-secure), the exception type, and so on. This function is
546called in the following circumstances:
547
548* In BL1, whenever an exception is taken.
549* In BL2, whenever an exception is taken.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100550
551The default implementation doesn't do anything, to avoid making assumptions
552about the way the platform displays its status information.
553
554This function receives the exception type as its argument. Possible values for
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000555exceptions types are listed in the [include/runtime_svc.h] header file. Note
Achin Gupta4f6ad662013-10-25 09:08:21 +0100556that these constants are not related to any architectural exception code; they
557are just an ARM Trusted Firmware convention.
558
559
Soby Mathew24fb8382014-08-14 12:22:32 +0100560### Function : plat_reset_handler()
561
562 Argument : void
563 Return : void
564
565A platform may need to do additional initialization after reset. This function
566allows the platform to do the platform specific intializations. Platform
567specific errata workarounds could also be implemented here. The api should
Soby Mathew683f7882015-01-29 12:00:58 +0000568preserve the values of callee saved registers x19 to x29.
Soby Mathew24fb8382014-08-14 12:22:32 +0100569
Yatharth Kochar79a97b22014-11-20 18:09:41 +0000570The default implementation doesn't do anything. If a platform needs to override
Dan Handley4a75b842015-03-19 19:24:43 +0000571the default implementation, refer to the [Firmware Design] for general
Sandrine Bailleux452b7fa2015-05-27 17:14:22 +0100572guidelines.
Soby Mathew24fb8382014-08-14 12:22:32 +0100573
Soby Mathewadd40352014-08-14 12:49:05 +0100574### Function : plat_disable_acp()
575
576 Argument : void
577 Return : void
578
579This api allows a platform to disable the Accelerator Coherency Port (if
580present) during a cluster power down sequence. The default weak implementation
581doesn't do anything. Since this api is called during the power down sequence,
582it has restrictions for stack usage and it can use the registers x0 - x17 as
583scratch registers. It should preserve the value in x18 register as it is used
584by the caller to store the return address.
585
Soby Mathew24fb8382014-08-14 12:22:32 +0100586
Achin Gupta4f6ad662013-10-25 09:08:21 +01005873. Modifications specific to a Boot Loader stage
588-------------------------------------------------
589
5903.1 Boot Loader Stage 1 (BL1)
591-----------------------------
592
593BL1 implements the reset vector where execution starts from after a cold or
594warm boot. For each CPU, BL1 is responsible for the following tasks:
595
Vikram Kanigirie452cd82014-05-23 15:56:12 +01005961. Handling the reset as described in section 2.2
Achin Gupta4f6ad662013-10-25 09:08:21 +0100597
5982. In the case of a cold boot and the CPU being the primary CPU, ensuring that
599 only this CPU executes the remaining BL1 code, including loading and passing
600 control to the BL2 stage.
601
Vikram Kanigirie452cd82014-05-23 15:56:12 +01006023. Loading the BL2 image from non-volatile storage into secure memory at the
Achin Gupta4f6ad662013-10-25 09:08:21 +0100603 address specified by the platform defined constant `BL2_BASE`.
604
Vikram Kanigirie452cd82014-05-23 15:56:12 +01006054. Populating a `meminfo` structure with the following information in memory,
Achin Gupta4f6ad662013-10-25 09:08:21 +0100606 accessible by BL2 immediately upon entry.
607
608 meminfo.total_base = Base address of secure RAM visible to BL2
609 meminfo.total_size = Size of secure RAM visible to BL2
610 meminfo.free_base = Base address of secure RAM available for
611 allocation to BL2
612 meminfo.free_size = Size of secure RAM available for allocation to BL2
613
614 BL1 places this `meminfo` structure at the beginning of the free memory
615 available for its use. Since BL1 cannot allocate memory dynamically at the
616 moment, its free memory will be available for BL2's use as-is. However, this
617 means that BL2 must read the `meminfo` structure before it starts using its
618 free memory (this is discussed in Section 3.2).
619
620 In future releases of the ARM Trusted Firmware it will be possible for
621 the platform to decide where it wants to place the `meminfo` structure for
622 BL2.
623
Sandrine Bailleux8f55dfb2014-06-24 14:02:34 +0100624 BL1 implements the `bl1_init_bl2_mem_layout()` function to populate the
Achin Gupta4f6ad662013-10-25 09:08:21 +0100625 BL2 `meminfo` structure. The platform may override this implementation, for
626 example if the platform wants to restrict the amount of memory visible to
627 BL2. Details of how to do this are given below.
628
629The following functions need to be implemented by the platform port to enable
630BL1 to perform the above tasks.
631
632
Dan Handley4a75b842015-03-19 19:24:43 +0000633### Function : bl1_early_platform_setup() [mandatory]
634
635 Argument : void
636 Return : void
637
638This function executes with the MMU and data caches disabled. It is only called
639by the primary CPU.
640
641In ARM standard platforms, this function initializes the console and enables
642snoop requests into the primary CPU's cluster.
643
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100644### Function : bl1_plat_arch_setup() [mandatory]
Achin Gupta4f6ad662013-10-25 09:08:21 +0100645
646 Argument : void
647 Return : void
648
Achin Gupta4f6ad662013-10-25 09:08:21 +0100649This function performs any platform-specific and architectural setup that the
Dan Handley4a75b842015-03-19 19:24:43 +0000650platform requires. Platform-specific setup might include configuration of
651memory controllers and the interconnect.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100652
Dan Handley4a75b842015-03-19 19:24:43 +0000653In ARM standard platforms, this function enables the MMU.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100654
655This function helps fulfill requirement 2 above.
656
657
658### Function : bl1_platform_setup() [mandatory]
659
660 Argument : void
661 Return : void
662
663This function executes with the MMU and data caches enabled. It is responsible
664for performing any remaining platform-specific setup that can occur after the
665MMU and data cache have been enabled.
666
Dan Handley4a75b842015-03-19 19:24:43 +0000667In ARM standard platforms, this function initializes the storage abstraction
668layer used to load the next bootloader image.
Harry Liebeld265bd72014-01-31 19:04:10 +0000669
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100670This function helps fulfill requirement 3 above.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100671
672
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000673### Function : bl1_plat_sec_mem_layout() [mandatory]
Achin Gupta4f6ad662013-10-25 09:08:21 +0100674
675 Argument : void
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000676 Return : meminfo *
Achin Gupta4f6ad662013-10-25 09:08:21 +0100677
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000678This function should only be called on the cold boot path. It executes with the
679MMU and data caches enabled. The pointer returned by this function must point to
680a `meminfo` structure containing the extents and availability of secure RAM for
681the BL1 stage.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100682
683 meminfo.total_base = Base address of secure RAM visible to BL1
684 meminfo.total_size = Size of secure RAM visible to BL1
685 meminfo.free_base = Base address of secure RAM available for allocation
686 to BL1
687 meminfo.free_size = Size of secure RAM available for allocation to BL1
688
689This information is used by BL1 to load the BL2 image in secure RAM. BL1 also
690populates a similar structure to tell BL2 the extents of memory available for
691its own use.
692
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100693This function helps fulfill requirement 3 above.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100694
695
Sandrine Bailleux8f55dfb2014-06-24 14:02:34 +0100696### Function : bl1_init_bl2_mem_layout() [optional]
Achin Gupta4f6ad662013-10-25 09:08:21 +0100697
698 Argument : meminfo *, meminfo *, unsigned int, unsigned long
699 Return : void
700
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100701BL1 needs to tell the next stage the amount of secure RAM available
702for it to use. This information is populated in a `meminfo`
Achin Gupta4f6ad662013-10-25 09:08:21 +0100703structure.
704
705Depending upon where BL2 has been loaded in secure RAM (determined by
706`BL2_BASE`), BL1 calculates the amount of free memory available for BL2 to use.
707BL1 also ensures that its data sections resident in secure RAM are not visible
Dan Handley4a75b842015-03-19 19:24:43 +0000708to BL2. An illustration of how this is done in ARM standard platforms is given
709in the **Memory layout on ARM development platforms** section in the
710[Firmware Design].
Achin Gupta4f6ad662013-10-25 09:08:21 +0100711
712
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100713### Function : bl1_plat_set_bl2_ep_info() [mandatory]
714
715 Argument : image_info *, entry_point_info *
716 Return : void
717
718This function is called after loading BL2 image and it can be used to overwrite
719the entry point set by loader and also set the security state and SPSR which
720represents the entry point system state for BL2.
721
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100722
Achin Gupta4f6ad662013-10-25 09:08:21 +01007233.2 Boot Loader Stage 2 (BL2)
724-----------------------------
725
726The BL2 stage is executed only by the primary CPU, which is determined in BL1
727using the `platform_is_primary_cpu()` function. BL1 passed control to BL2 at
728`BL2_BASE`. BL2 executes in Secure EL1 and is responsible for:
729
Sandrine Bailleux93d81d62014-06-24 14:19:36 +01007301. (Optional) Loading the BL3-0 binary image (if present) from platform
731 provided non-volatile storage. To load the BL3-0 image, BL2 makes use of
732 the `meminfo` returned by the `bl2_plat_get_bl30_meminfo()` function.
733 The platform also defines the address in memory where BL3-0 is loaded
734 through the optional constant `BL30_BASE`. BL2 uses this information
735 to determine if there is enough memory to load the BL3-0 image.
736 Subsequent handling of the BL3-0 image is platform-specific and is
737 implemented in the `bl2_plat_handle_bl30()` function.
738 If `BL30_BASE` is not defined then this step is not performed.
739
7402. Loading the BL3-1 binary image into secure RAM from non-volatile storage. To
Harry Liebeld265bd72014-01-31 19:04:10 +0000741 load the BL3-1 image, BL2 makes use of the `meminfo` structure passed to it
742 by BL1. This structure allows BL2 to calculate how much secure RAM is
743 available for its use. The platform also defines the address in secure RAM
744 where BL3-1 is loaded through the constant `BL31_BASE`. BL2 uses this
745 information to determine if there is enough memory to load the BL3-1 image.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100746
Sandrine Bailleux93d81d62014-06-24 14:19:36 +01007473. (Optional) Loading the BL3-2 binary image (if present) from platform
Dan Handley1151c822014-04-15 11:38:38 +0100748 provided non-volatile storage. To load the BL3-2 image, BL2 makes use of
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100749 the `meminfo` returned by the `bl2_plat_get_bl32_meminfo()` function.
750 The platform also defines the address in memory where BL3-2 is loaded
751 through the optional constant `BL32_BASE`. BL2 uses this information
752 to determine if there is enough memory to load the BL3-2 image.
753 If `BL32_BASE` is not defined then this and the next step is not performed.
Achin Guptaa3050ed2014-02-19 17:52:35 +0000754
Sandrine Bailleux93d81d62014-06-24 14:19:36 +01007554. (Optional) Arranging to pass control to the BL3-2 image (if present) that
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100756 has been pre-loaded at `BL32_BASE`. BL2 populates an `entry_point_info`
Dan Handley1151c822014-04-15 11:38:38 +0100757 structure in memory provided by the platform with information about how
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100758 BL3-1 should pass control to the BL3-2 image.
Achin Guptaa3050ed2014-02-19 17:52:35 +0000759
Sandrine Bailleux93d81d62014-06-24 14:19:36 +01007605. Loading the normal world BL3-3 binary image into non-secure DRAM from
761 platform storage and arranging for BL3-1 to pass control to this image. This
762 address is determined using the `plat_get_ns_image_entrypoint()` function
763 described below.
764
7656. BL2 populates an `entry_point_info` structure in memory provided by the
766 platform with information about how BL3-1 should pass control to the
767 other BL images.
768
Achin Gupta4f6ad662013-10-25 09:08:21 +0100769The following functions must be implemented by the platform port to enable BL2
770to perform the above tasks.
771
772
773### Function : bl2_early_platform_setup() [mandatory]
774
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100775 Argument : meminfo *
Achin Gupta4f6ad662013-10-25 09:08:21 +0100776 Return : void
777
778This function executes with the MMU and data caches disabled. It is only called
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100779by the primary CPU. The arguments to this function is the address of the
780`meminfo` structure populated by BL1.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100781
782The platform must copy the contents of the `meminfo` structure into a private
783variable as the original memory may be subsequently overwritten by BL2. The
784copied structure is made available to all BL2 code through the
Achin Guptae4d084e2014-02-19 17:18:23 +0000785`bl2_plat_sec_mem_layout()` function.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100786
Dan Handley4a75b842015-03-19 19:24:43 +0000787In ARM standard platforms, this function also initializes the storage
788abstraction layer used to load further bootloader images. It is necessary to do
789this early on platforms with a BL3-0 image, since the later `bl2_platform_setup`
790must be done after BL3-0 is loaded.
791
Achin Gupta4f6ad662013-10-25 09:08:21 +0100792
793### Function : bl2_plat_arch_setup() [mandatory]
794
795 Argument : void
796 Return : void
797
798This function executes with the MMU and data caches disabled. It is only called
799by the primary CPU.
800
801The purpose of this function is to perform any architectural initialization
802that varies across platforms, for example enabling the MMU (since the memory
803map differs across platforms).
804
805
806### Function : bl2_platform_setup() [mandatory]
807
808 Argument : void
809 Return : void
810
811This function may execute with the MMU and data caches enabled if the platform
812port does the necessary initialization in `bl2_plat_arch_setup()`. It is only
813called by the primary CPU.
814
Achin Guptae4d084e2014-02-19 17:18:23 +0000815The purpose of this function is to perform any platform initialization
Dan Handley4a75b842015-03-19 19:24:43 +0000816specific to BL2.
Harry Liebelce19cf12014-04-01 19:28:07 +0100817
Dan Handley4a75b842015-03-19 19:24:43 +0000818In ARM standard platforms, this function performs security setup, including
819configuration of the TrustZone controller to allow non-secure masters access
820to most of DRAM. Part of DRAM is reserved for secure world use.
Harry Liebeld265bd72014-01-31 19:04:10 +0000821
Achin Gupta4f6ad662013-10-25 09:08:21 +0100822
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000823### Function : bl2_plat_sec_mem_layout() [mandatory]
Achin Gupta4f6ad662013-10-25 09:08:21 +0100824
825 Argument : void
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000826 Return : meminfo *
Achin Gupta4f6ad662013-10-25 09:08:21 +0100827
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000828This function should only be called on the cold boot path. It may execute with
829the MMU and data caches enabled if the platform port does the necessary
830initialization in `bl2_plat_arch_setup()`. It is only called by the primary CPU.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100831
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000832The purpose of this function is to return a pointer to a `meminfo` structure
833populated with the extents of secure RAM available for BL2 to use. See
Achin Gupta4f6ad662013-10-25 09:08:21 +0100834`bl2_early_platform_setup()` above.
835
836
Sandrine Bailleux93d81d62014-06-24 14:19:36 +0100837### Function : bl2_plat_get_bl30_meminfo() [mandatory]
838
839 Argument : meminfo *
840 Return : void
841
842This function is used to get the memory limits where BL2 can load the
843BL3-0 image. The meminfo provided by this is used by load_image() to
844validate whether the BL3-0 image can be loaded within the given
845memory from the given base.
846
847
848### Function : bl2_plat_handle_bl30() [mandatory]
849
850 Argument : image_info *
851 Return : int
852
853This function is called after loading BL3-0 image and it is used to perform any
854platform-specific actions required to handle the SCP firmware. Typically it
855transfers the image into SCP memory using a platform-specific protocol and waits
856until SCP executes it and signals to the Application Processor (AP) for BL2
857execution to continue.
858
859This function returns 0 on success, a negative error code otherwise.
860
861
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100862### Function : bl2_plat_get_bl31_params() [mandatory]
Harry Liebeld265bd72014-01-31 19:04:10 +0000863
864 Argument : void
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100865 Return : bl31_params *
Harry Liebeld265bd72014-01-31 19:04:10 +0000866
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100867BL2 platform code needs to return a pointer to a `bl31_params` structure it
868will use for passing information to BL3-1. The `bl31_params` structure carries
869the following information.
870 - Header describing the version information for interpreting the bl31_param
871 structure
872 - Information about executing the BL3-3 image in the `bl33_ep_info` field
873 - Information about executing the BL3-2 image in the `bl32_ep_info` field
874 - Information about the type and extents of BL3-1 image in the
875 `bl31_image_info` field
876 - Information about the type and extents of BL3-2 image in the
877 `bl32_image_info` field
878 - Information about the type and extents of BL3-3 image in the
879 `bl33_image_info` field
880
881The memory pointed by this structure and its sub-structures should be
882accessible from BL3-1 initialisation code. BL3-1 might choose to copy the
883necessary content, or maintain the structures until BL3-3 is initialised.
Harry Liebeld265bd72014-01-31 19:04:10 +0000884
885
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100886### Funtion : bl2_plat_get_bl31_ep_info() [mandatory]
Achin Gupta4f6ad662013-10-25 09:08:21 +0100887
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100888 Argument : void
889 Return : entry_point_info *
890
891BL2 platform code returns a pointer which is used to populate the entry point
892information for BL3-1 entry point. The location pointed by it should be
893accessible from BL1 while processing the synchronous exception to run to BL3-1.
894
Dan Handley4a75b842015-03-19 19:24:43 +0000895In ARM standard platforms this is allocated inside a bl2_to_bl31_params_mem
896structure in BL2 memory.
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100897
898
899### Function : bl2_plat_set_bl31_ep_info() [mandatory]
900
901 Argument : image_info *, entry_point_info *
Achin Gupta4f6ad662013-10-25 09:08:21 +0100902 Return : void
903
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100904This function is called after loading BL3-1 image and it can be used to
905overwrite the entry point set by loader and also set the security state
906and SPSR which represents the entry point system state for BL3-1.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100907
Achin Gupta4f6ad662013-10-25 09:08:21 +0100908
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100909### Function : bl2_plat_set_bl32_ep_info() [mandatory]
910
911 Argument : image_info *, entry_point_info *
912 Return : void
913
914This function is called after loading BL3-2 image and it can be used to
915overwrite the entry point set by loader and also set the security state
916and SPSR which represents the entry point system state for BL3-2.
917
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100918
919### Function : bl2_plat_set_bl33_ep_info() [mandatory]
920
921 Argument : image_info *, entry_point_info *
922 Return : void
923
924This function is called after loading BL3-3 image and it can be used to
925overwrite the entry point set by loader and also set the security state
926and SPSR which represents the entry point system state for BL3-3.
927
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100928
929### Function : bl2_plat_get_bl32_meminfo() [mandatory]
930
931 Argument : meminfo *
932 Return : void
933
934This function is used to get the memory limits where BL2 can load the
935BL3-2 image. The meminfo provided by this is used by load_image() to
936validate whether the BL3-2 image can be loaded with in the given
937memory from the given base.
938
939### Function : bl2_plat_get_bl33_meminfo() [mandatory]
940
941 Argument : meminfo *
942 Return : void
943
944This function is used to get the memory limits where BL2 can load the
945BL3-3 image. The meminfo provided by this is used by load_image() to
946validate whether the BL3-3 image can be loaded with in the given
947memory from the given base.
948
949### Function : bl2_plat_flush_bl31_params() [mandatory]
950
951 Argument : void
952 Return : void
953
954Once BL2 has populated all the structures that needs to be read by BL1
955and BL3-1 including the bl31_params structures and its sub-structures,
956the bl31_ep_info structure and any platform specific data. It flushes
957all these data to the main memory so that it is available when we jump to
958later Bootloader stages with MMU off
Achin Gupta4f6ad662013-10-25 09:08:21 +0100959
960### Function : plat_get_ns_image_entrypoint() [mandatory]
961
962 Argument : void
963 Return : unsigned long
964
965As previously described, BL2 is responsible for arranging for control to be
966passed to a normal world BL image through BL3-1. This function returns the
967entrypoint of that image, which BL3-1 uses to jump to it.
968
Harry Liebeld265bd72014-01-31 19:04:10 +0000969BL2 is responsible for loading the normal world BL3-3 image (e.g. UEFI).
Achin Gupta4f6ad662013-10-25 09:08:21 +0100970
971
9723.2 Boot Loader Stage 3-1 (BL3-1)
973---------------------------------
974
975During cold boot, the BL3-1 stage is executed only by the primary CPU. This is
976determined in BL1 using the `platform_is_primary_cpu()` function. BL1 passes
977control to BL3-1 at `BL31_BASE`. During warm boot, BL3-1 is executed by all
978CPUs. BL3-1 executes at EL3 and is responsible for:
979
9801. Re-initializing all architectural and platform state. Although BL1 performs
981 some of this initialization, BL3-1 remains resident in EL3 and must ensure
982 that EL3 architectural and platform state is completely initialized. It
983 should make no assumptions about the system state when it receives control.
984
9852. Passing control to a normal world BL image, pre-loaded at a platform-
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100986 specific address by BL2. BL3-1 uses the `entry_point_info` structure that BL2
Achin Gupta4f6ad662013-10-25 09:08:21 +0100987 populated in memory to do this.
988
9893. Providing runtime firmware services. Currently, BL3-1 only implements a
990 subset of the Power State Coordination Interface (PSCI) API as a runtime
991 service. See Section 3.3 below for details of porting the PSCI
992 implementation.
993
Achin Gupta35ca3512014-02-19 17:58:33 +00009944. Optionally passing control to the BL3-2 image, pre-loaded at a platform-
995 specific address by BL2. BL3-1 exports a set of apis that allow runtime
996 services to specify the security state in which the next image should be
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100997 executed and run the corresponding image. BL3-1 uses the `entry_point_info`
998 structure populated by BL2 to do this.
999
1000If BL3-1 is a reset vector, It also needs to handle the reset as specified in
1001section 2.2 before the tasks described above.
Achin Gupta35ca3512014-02-19 17:58:33 +00001002
Achin Gupta4f6ad662013-10-25 09:08:21 +01001003The following functions must be implemented by the platform port to enable BL3-1
1004to perform the above tasks.
1005
1006
1007### Function : bl31_early_platform_setup() [mandatory]
1008
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001009 Argument : bl31_params *, void *
Achin Gupta4f6ad662013-10-25 09:08:21 +01001010 Return : void
1011
1012This function executes with the MMU and data caches disabled. It is only called
1013by the primary CPU. The arguments to this function are:
1014
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001015* The address of the `bl31_params` structure populated by BL2.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001016* An opaque pointer that the platform may use as needed.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001017
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001018The platform can copy the contents of the `bl31_params` structure and its
1019sub-structures into private variables if the original memory may be
1020subsequently overwritten by BL3-1 and similarly the `void *` pointing
1021to the platform data also needs to be saved.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001022
Dan Handley4a75b842015-03-19 19:24:43 +00001023In ARM standard platforms, BL2 passes a pointer to a `bl31_params` structure
1024in BL2 memory. BL3-1 copies the information in this pointer to internal data
1025structures.
1026
Achin Gupta4f6ad662013-10-25 09:08:21 +01001027
1028### Function : bl31_plat_arch_setup() [mandatory]
1029
1030 Argument : void
1031 Return : void
1032
1033This function executes with the MMU and data caches disabled. It is only called
1034by the primary CPU.
1035
1036The purpose of this function is to perform any architectural initialization
1037that varies across platforms, for example enabling the MMU (since the memory
1038map differs across platforms).
1039
1040
1041### Function : bl31_platform_setup() [mandatory]
1042
1043 Argument : void
1044 Return : void
1045
1046This function may execute with the MMU and data caches enabled if the platform
1047port does the necessary initialization in `bl31_plat_arch_setup()`. It is only
1048called by the primary CPU.
1049
1050The purpose of this function is to complete platform initialization so that both
1051BL3-1 runtime services and normal world software can function correctly.
1052
Dan Handley4a75b842015-03-19 19:24:43 +00001053In ARM standard platforms, this function does the following:
Achin Gupta4f6ad662013-10-25 09:08:21 +01001054* Initializes the generic interrupt controller.
Sandrine Bailleux9e864902014-03-31 11:25:18 +01001055* Enables system-level implementation of the generic timer counter.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001056* Grants access to the system counter timer module
Dan Handley4a75b842015-03-19 19:24:43 +00001057* Initializes the power controller device
Achin Gupta4f6ad662013-10-25 09:08:21 +01001058* Detects the system topology.
1059
1060
1061### Function : bl31_get_next_image_info() [mandatory]
1062
Achin Gupta35ca3512014-02-19 17:58:33 +00001063 Argument : unsigned int
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001064 Return : entry_point_info *
Achin Gupta4f6ad662013-10-25 09:08:21 +01001065
1066This function may execute with the MMU and data caches enabled if the platform
1067port does the necessary initializations in `bl31_plat_arch_setup()`.
1068
1069This function is called by `bl31_main()` to retrieve information provided by
Achin Gupta35ca3512014-02-19 17:58:33 +00001070BL2 for the next image in the security state specified by the argument. BL3-1
1071uses this information to pass control to that image in the specified security
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001072state. This function must return a pointer to the `entry_point_info` structure
Achin Gupta35ca3512014-02-19 17:58:33 +00001073(that was copied during `bl31_early_platform_setup()`) if the image exists. It
1074should return NULL otherwise.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001075
Dan Handley4a75b842015-03-19 19:24:43 +00001076### Function : plat_get_syscnt_freq() [mandatory]
1077
1078 Argument : void
1079 Return : uint64_t
1080
1081This function is used by the architecture setup code to retrieve the counter
1082frequency for the CPU's generic timer. This value will be programmed into the
1083`CNTFRQ_EL0` register. In ARM standard platforms, it returns the base frequency
1084of the system counter, which is retrieved from the first entry in the frequency
1085modes table.
1086
Achin Gupta4f6ad662013-10-25 09:08:21 +01001087
Achin Gupta4f6ad662013-10-25 09:08:21 +010010883.3 Power State Coordination Interface (in BL3-1)
1089------------------------------------------------
1090
1091The ARM Trusted Firmware's implementation of the PSCI API is based around the
1092concept of an _affinity instance_. Each _affinity instance_ can be uniquely
1093identified in a system by a CPU ID (the processor `MPIDR` is used in the PSCI
1094interface) and an _affinity level_. A processing element (for example, a
1095CPU) is at level 0. If the CPUs in the system are described in a tree where the
1096node above a CPU is a logical grouping of CPUs that share some state, then
1097affinity level 1 is that group of CPUs (for example, a cluster), and affinity
1098level 2 is a group of clusters (for example, the system). The implementation
1099assumes that the affinity level 1 ID can be computed from the affinity level 0
1100ID (for example, a unique cluster ID can be computed from the CPU ID). The
1101current implementation computes this on the basis of the recommended use of
1102`MPIDR` affinity fields in the ARM Architecture Reference Manual.
1103
1104BL3-1's platform initialization code exports a pointer to the platform-specific
1105power management operations required for the PSCI implementation to function
1106correctly. This information is populated in the `plat_pm_ops` structure. The
1107PSCI implementation calls members of the `plat_pm_ops` structure for performing
1108power management operations for each affinity instance. For example, the target
1109CPU is specified by its `MPIDR` in a PSCI `CPU_ON` call. The `affinst_on()`
1110handler (if present) is called for each affinity instance as the PSCI
1111implementation powers up each affinity level implemented in the `MPIDR` (for
1112example, CPU, cluster and system).
1113
1114The following functions must be implemented to initialize PSCI functionality in
1115the ARM Trusted Firmware.
1116
1117
1118### Function : plat_get_aff_count() [mandatory]
1119
1120 Argument : unsigned int, unsigned long
1121 Return : unsigned int
1122
1123This function may execute with the MMU and data caches enabled if the platform
1124port does the necessary initializations in `bl31_plat_arch_setup()`. It is only
1125called by the primary CPU.
1126
1127This function is called by the PSCI initialization code to detect the system
1128topology. Its purpose is to return the number of affinity instances implemented
1129at a given `affinity level` (specified by the first argument) and a given
1130`MPIDR` (specified by the second argument). For example, on a dual-cluster
1131system where first cluster implements 2 CPUs and the second cluster implements 4
1132CPUs, a call to this function with an `MPIDR` corresponding to the first cluster
1133(`0x0`) and affinity level 0, would return 2. A call to this function with an
1134`MPIDR` corresponding to the second cluster (`0x100`) and affinity level 0,
1135would return 4.
1136
1137
1138### Function : plat_get_aff_state() [mandatory]
1139
1140 Argument : unsigned int, unsigned long
1141 Return : unsigned int
1142
1143This function may execute with the MMU and data caches enabled if the platform
1144port does the necessary initializations in `bl31_plat_arch_setup()`. It is only
1145called by the primary CPU.
1146
1147This function is called by the PSCI initialization code. Its purpose is to
1148return the state of an affinity instance. The affinity instance is determined by
1149the affinity ID at a given `affinity level` (specified by the first argument)
1150and an `MPIDR` (specified by the second argument). The state can be one of
1151`PSCI_AFF_PRESENT` or `PSCI_AFF_ABSENT`. The latter state is used to cater for
1152system topologies where certain affinity instances are unimplemented. For
1153example, consider a platform that implements a single cluster with 4 CPUs and
1154another CPU implemented directly on the interconnect with the cluster. The
1155`MPIDR`s of the cluster would range from `0x0-0x3`. The `MPIDR` of the single
1156CPU would be 0x100 to indicate that it does not belong to cluster 0. Cluster 1
1157is missing but needs to be accounted for to reach this single CPU in the
1158topology tree. Hence it is marked as `PSCI_AFF_ABSENT`.
1159
1160
Achin Gupta4f6ad662013-10-25 09:08:21 +01001161### Function : platform_setup_pm() [mandatory]
1162
Sandrine Bailleux44804252014-08-06 11:27:23 +01001163 Argument : const plat_pm_ops **
Achin Gupta4f6ad662013-10-25 09:08:21 +01001164 Return : int
1165
1166This function may execute with the MMU and data caches enabled if the platform
1167port does the necessary initializations in `bl31_plat_arch_setup()`. It is only
1168called by the primary CPU.
1169
1170This function is called by PSCI initialization code. Its purpose is to export
1171handler routines for platform-specific power management actions by populating
1172the passed pointer with a pointer to BL3-1's private `plat_pm_ops` structure.
1173
1174A description of each member of this structure is given below. Please refer to
Dan Handley4a75b842015-03-19 19:24:43 +00001175the ARM FVP specific implementation of these handlers in
1176[plat/arm/board/fvp/fvp_pm.c] as an example. A platform port is expected to
1177implement these handlers if the corresponding PSCI operation is to be supported
1178and these handlers are expected to succeed if the return type is `void`.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001179
1180#### plat_pm_ops.affinst_standby()
1181
1182Perform the platform-specific setup to enter the standby state indicated by the
Soby Mathew539dced2014-10-02 16:56:51 +01001183passed argument. The generic code expects the handler to succeed.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001184
1185#### plat_pm_ops.affinst_on()
1186
1187Perform the platform specific setup to power on an affinity instance, specified
Soby Mathewe146f4c2014-09-26 15:08:52 +01001188by the `MPIDR` (first argument) and `affinity level` (third argument). The
1189`state` (fourth argument) contains the current state of that affinity instance
Achin Gupta4f6ad662013-10-25 09:08:21 +01001190(ON or OFF). This is useful to determine whether any action must be taken. For
1191example, while powering on a CPU, the cluster that contains this CPU might
1192already be in the ON state. The platform decides what actions must be taken to
1193transition from the current state to the target state (indicated by the power
Soby Mathew539dced2014-10-02 16:56:51 +01001194management operation). The generic code expects the platform to return
1195E_SUCCESS on success or E_INTERN_FAIL for any failure.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001196
1197#### plat_pm_ops.affinst_off()
1198
Soby Mathewe146f4c2014-09-26 15:08:52 +01001199Perform the platform specific setup to power off an affinity instance of the
1200calling CPU. It is called by the PSCI `CPU_OFF` API implementation.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001201
Soby Mathewe146f4c2014-09-26 15:08:52 +01001202The `affinity level` (first argument) and `state` (second argument) have
1203a similar meaning as described in the `affinst_on()` operation. They are
1204used to identify the affinity instance on which the call is made and its
1205current state. This gives the platform port an indication of the
Achin Gupta4f6ad662013-10-25 09:08:21 +01001206state transition it must make to perform the requested action. For example, if
1207the calling CPU is the last powered on CPU in the cluster, after powering down
1208affinity level 0 (CPU), the platform port should power down affinity level 1
Soby Mathew539dced2014-10-02 16:56:51 +01001209(the cluster) as well. The generic code expects the handler to succeed.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001210
Achin Gupta4f6ad662013-10-25 09:08:21 +01001211#### plat_pm_ops.affinst_suspend()
1212
Soby Mathewe146f4c2014-09-26 15:08:52 +01001213Perform the platform specific setup to power off an affinity instance of the
1214calling CPU. It is called by the PSCI `CPU_SUSPEND` API
Achin Gupta4f6ad662013-10-25 09:08:21 +01001215implementation.
1216
Soby Mathewe146f4c2014-09-26 15:08:52 +01001217The `affinity level` (second argument) and `state` (third argument) have a
1218similar meaning as described in the `affinst_on()` operation. They are used to
1219identify the affinity instance on which the call is made and its current state.
1220This gives the platform port an indication of the state transition it must
1221make to perform the requested action. For example, if the calling CPU is the
1222last powered on CPU in the cluster, after powering down affinity level 0 (CPU),
1223the platform port should power down affinity level 1 (the cluster) as well.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001224
1225The difference between turning an affinity instance off versus suspending it
1226is that in the former case, the affinity instance is expected to re-initialize
1227its state when its next powered on (see `affinst_on_finish()`). In the latter
1228case, the affinity instance is expected to save enough state so that it can
1229resume execution by restoring this state when its powered on (see
Soby Mathew539dced2014-10-02 16:56:51 +01001230`affinst_suspend_finish()`).The generic code expects the handler to succeed.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001231
Achin Gupta4f6ad662013-10-25 09:08:21 +01001232#### plat_pm_ops.affinst_on_finish()
1233
1234This function is called by the PSCI implementation after the calling CPU is
1235powered on and released from reset in response to an earlier PSCI `CPU_ON` call.
1236It performs the platform-specific setup required to initialize enough state for
1237this CPU to enter the normal world and also provide secure runtime firmware
1238services.
1239
Soby Mathewe146f4c2014-09-26 15:08:52 +01001240The `affinity level` (first argument) and `state` (second argument) have a
Soby Mathew539dced2014-10-02 16:56:51 +01001241similar meaning as described in the previous operations. The generic code
1242expects the handler to succeed.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001243
Achin Gupta4f6ad662013-10-25 09:08:21 +01001244#### plat_pm_ops.affinst_on_suspend()
1245
1246This function is called by the PSCI implementation after the calling CPU is
1247powered on and released from reset in response to an asynchronous wakeup
1248event, for example a timer interrupt that was programmed by the CPU during the
1249`CPU_SUSPEND` call. It performs the platform-specific setup required to
1250restore the saved state for this CPU to resume execution in the normal world
1251and also provide secure runtime firmware services.
1252
Soby Mathewe146f4c2014-09-26 15:08:52 +01001253The `affinity level` (first argument) and `state` (second argument) have a
Soby Mathew539dced2014-10-02 16:56:51 +01001254similar meaning as described in the previous operations. The generic code
1255expects the platform to succeed.
1256
1257#### plat_pm_ops.validate_power_state()
1258
1259This function is called by the PSCI implementation during the `CPU_SUSPEND`
1260call to validate the `power_state` parameter of the PSCI API. If the
1261`power_state` is known to be invalid, the platform must return
1262PSCI_E_INVALID_PARAMS as error, which is propagated back to the normal
1263world PSCI client.
1264
1265#### plat_pm_ops.validate_ns_entrypoint()
1266
1267This function is called by the PSCI implementation during the `CPU_SUSPEND`
1268and `CPU_ON` calls to validate the non-secure `entry_point` parameter passed
1269by the normal world. If the `entry_point` is known to be invalid, the platform
1270must return PSCI_E_INVALID_PARAMS as error, which is propagated back to the
1271normal world PSCI client.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001272
Achin Gupta4f6ad662013-10-25 09:08:21 +01001273BL3-1 platform initialization code must also detect the system topology and
1274the state of each affinity instance in the topology. This information is
1275critical for the PSCI runtime service to function correctly. More details are
1276provided in the description of the `plat_get_aff_count()` and
1277`plat_get_aff_state()` functions above.
1278
Achin Guptaa4fa3cb2014-06-02 22:27:36 +010012793.4 Interrupt Management framework (in BL3-1)
1280----------------------------------------------
1281BL3-1 implements an Interrupt Management Framework (IMF) to manage interrupts
1282generated in either security state and targeted to EL1 or EL2 in the non-secure
1283state or EL3/S-EL1 in the secure state. The design of this framework is
1284described in the [IMF Design Guide]
1285
1286A platform should export the following APIs to support the IMF. The following
Dan Handley4a75b842015-03-19 19:24:43 +00001287text briefly describes each api and its implementation in ARM standard
1288platforms. The API implementation depends upon the type of interrupt controller
1289present in the platform. ARM standard platforms implements an ARM Generic
1290Interrupt Controller (ARM GIC) as per the version 2.0 of the
1291[ARM GIC Architecture Specification].
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001292
1293### Function : plat_interrupt_type_to_line() [mandatory]
1294
1295 Argument : uint32_t, uint32_t
1296 Return : uint32_t
1297
1298The ARM processor signals an interrupt exception either through the IRQ or FIQ
1299interrupt line. The specific line that is signaled depends on how the interrupt
1300controller (IC) reports different interrupt types from an execution context in
1301either security state. The IMF uses this API to determine which interrupt line
1302the platform IC uses to signal each type of interrupt supported by the framework
1303from a given security state.
1304
1305The first parameter will be one of the `INTR_TYPE_*` values (see [IMF Design
1306Guide]) indicating the target type of the interrupt, the second parameter is the
1307security state of the originating execution context. The return result is the
1308bit position in the `SCR_EL3` register of the respective interrupt trap: IRQ=1,
1309FIQ=2.
1310
Dan Handley4a75b842015-03-19 19:24:43 +00001311ARM standard platforms configure the ARM GIC to signal S-EL1 interrupts
1312as FIQs and Non-secure interrupts as IRQs from either security state.
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001313
1314
1315### Function : plat_ic_get_pending_interrupt_type() [mandatory]
1316
1317 Argument : void
1318 Return : uint32_t
1319
1320This API returns the type of the highest priority pending interrupt at the
1321platform IC. The IMF uses the interrupt type to retrieve the corresponding
1322handler function. `INTR_TYPE_INVAL` is returned when there is no interrupt
1323pending. The valid interrupt types that can be returned are `INTR_TYPE_EL3`,
1324`INTR_TYPE_S_EL1` and `INTR_TYPE_NS`.
1325
Dan Handley4a75b842015-03-19 19:24:43 +00001326ARM standard platforms read the _Highest Priority Pending Interrupt
1327Register_ (`GICC_HPPIR`) to determine the id of the pending interrupt. The type
1328of interrupt depends upon the id value as follows.
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001329
13301. id < 1022 is reported as a S-EL1 interrupt
13312. id = 1022 is reported as a Non-secure interrupt.
13323. id = 1023 is reported as an invalid interrupt type.
1333
1334
1335### Function : plat_ic_get_pending_interrupt_id() [mandatory]
1336
1337 Argument : void
1338 Return : uint32_t
1339
1340This API returns the id of the highest priority pending interrupt at the
1341platform IC. The IMF passes the id returned by this API to the registered
1342handler for the pending interrupt if the `IMF_READ_INTERRUPT_ID` build time flag
1343is set. INTR_ID_UNAVAILABLE is returned when there is no interrupt pending.
1344
Dan Handley4a75b842015-03-19 19:24:43 +00001345ARM standard platforms read the _Highest Priority Pending Interrupt
1346Register_ (`GICC_HPPIR`) to determine the id of the pending interrupt. The id
1347that is returned by API depends upon the value of the id read from the interrupt
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001348controller as follows.
1349
13501. id < 1022. id is returned as is.
13512. id = 1022. The _Aliased Highest Priority Pending Interrupt Register_
1352 (`GICC_AHPPIR`) is read to determine the id of the non-secure interrupt. This
1353 id is returned by the API.
13543. id = 1023. `INTR_ID_UNAVAILABLE` is returned.
1355
1356
1357### Function : plat_ic_acknowledge_interrupt() [mandatory]
1358
1359 Argument : void
1360 Return : uint32_t
1361
1362This API is used by the CPU to indicate to the platform IC that processing of
1363the highest pending interrupt has begun. It should return the id of the
1364interrupt which is being processed.
1365
Dan Handley4a75b842015-03-19 19:24:43 +00001366This function in ARM standard platforms reads the _Interrupt Acknowledge
1367Register_ (`GICC_IAR`). This changes the state of the highest priority pending
1368interrupt from pending to active in the interrupt controller. It returns the
1369value read from the `GICC_IAR`. This value is the id of the interrupt whose
1370state has been changed.
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001371
1372The TSP uses this API to start processing of the secure physical timer
1373interrupt.
1374
1375
1376### Function : plat_ic_end_of_interrupt() [mandatory]
1377
1378 Argument : uint32_t
1379 Return : void
1380
1381This API is used by the CPU to indicate to the platform IC that processing of
1382the interrupt corresponding to the id (passed as the parameter) has
1383finished. The id should be the same as the id returned by the
1384`plat_ic_acknowledge_interrupt()` API.
1385
Dan Handley4a75b842015-03-19 19:24:43 +00001386ARM standard platforms write the id to the _End of Interrupt Register_
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001387(`GICC_EOIR`). This deactivates the corresponding interrupt in the interrupt
1388controller.
1389
1390The TSP uses this API to finish processing of the secure physical timer
1391interrupt.
1392
1393
1394### Function : plat_ic_get_interrupt_type() [mandatory]
1395
1396 Argument : uint32_t
1397 Return : uint32_t
1398
1399This API returns the type of the interrupt id passed as the parameter.
1400`INTR_TYPE_INVAL` is returned if the id is invalid. If the id is valid, a valid
1401interrupt type (one of `INTR_TYPE_EL3`, `INTR_TYPE_S_EL1` and `INTR_TYPE_NS`) is
1402returned depending upon how the interrupt has been configured by the platform
1403IC.
1404
Dan Handley4a75b842015-03-19 19:24:43 +00001405This function in ARM standard platforms configures S-EL1 interrupts
1406as Group0 interrupts and Non-secure interrupts as Group1 interrupts. It reads
1407the group value corresponding to the interrupt id from the relevant _Interrupt
1408Group Register_ (`GICD_IGROUPRn`). It uses the group value to determine the
1409type of interrupt.
1410
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001411
Soby Mathewc67b09b2014-07-14 16:57:23 +010014123.5 Crash Reporting mechanism (in BL3-1)
1413----------------------------------------------
1414BL3-1 implements a crash reporting mechanism which prints the various registers
Sandrine Bailleux44804252014-08-06 11:27:23 +01001415of the CPU to enable quick crash analysis and debugging. It requires that a
1416console is designated as the crash console by the platform which will be used to
1417print the register dump.
Soby Mathewc67b09b2014-07-14 16:57:23 +01001418
Sandrine Bailleux44804252014-08-06 11:27:23 +01001419The following functions must be implemented by the platform if it wants crash
1420reporting mechanism in BL3-1. The functions are implemented in assembly so that
1421they can be invoked without a C Runtime stack.
Soby Mathewc67b09b2014-07-14 16:57:23 +01001422
1423### Function : plat_crash_console_init
1424
1425 Argument : void
1426 Return : int
1427
Sandrine Bailleux44804252014-08-06 11:27:23 +01001428This API is used by the crash reporting mechanism to initialize the crash
1429console. It should only use the general purpose registers x0 to x2 to do the
1430initialization and returns 1 on success.
Soby Mathewc67b09b2014-07-14 16:57:23 +01001431
Soby Mathewc67b09b2014-07-14 16:57:23 +01001432### Function : plat_crash_console_putc
1433
1434 Argument : int
1435 Return : int
1436
1437This API is used by the crash reporting mechanism to print a character on the
1438designated crash console. It should only use general purpose registers x1 and
1439x2 to do its work. The parameter and the return value are in general purpose
1440register x0.
1441
Soby Mathew27713fb2014-09-08 17:51:01 +010014424. Build flags
1443---------------
1444
1445There are some build flags which can be defined by the platform to control
1446inclusion or exclusion of certain BL stages from the FIP image. These flags
1447need to be defined in the platform makefile which will get included by the
1448build system.
1449
1450* **NEED_BL30**
1451 This flag if defined by the platform mandates that a BL3-0 binary should
1452 be included in the FIP image. The path to the BL3-0 binary can be specified
1453 by the `BL30` build option (see build options in the [User Guide]).
1454
1455* **NEED_BL33**
1456 By default, this flag is defined `yes` by the build system and `BL33`
1457 build option should be supplied as a build option. The platform has the option
1458 of excluding the BL3-3 image in the `fip` image by defining this flag to
1459 `no`.
1460
14615. C Library
Harry Liebela960f282013-12-12 16:03:44 +00001462-------------
1463
1464To avoid subtle toolchain behavioral dependencies, the header files provided
1465by the compiler are not used. The software is built with the `-nostdinc` flag
1466to ensure no headers are included from the toolchain inadvertently. Instead the
1467required headers are included in the ARM Trusted Firmware source tree. The
1468library only contains those C library definitions required by the local
1469implementation. If more functionality is required, the needed library functions
1470will need to be added to the local implementation.
1471
1472Versions of [FreeBSD] headers can be found in `include/stdlib`. Some of these
1473headers have been cut down in order to simplify the implementation. In order to
1474minimize changes to the header files, the [FreeBSD] layout has been maintained.
1475The generic C library definitions can be found in `include/stdlib` with more
1476system and machine specific declarations in `include/stdlib/sys` and
1477`include/stdlib/machine`.
1478
1479The local C library implementations can be found in `lib/stdlib`. In order to
1480extend the C library these files may need to be modified. It is recommended to
1481use a release version of [FreeBSD] as a starting point.
1482
1483The C library header files in the [FreeBSD] source tree are located in the
1484`include` and `sys/sys` directories. [FreeBSD] machine specific definitions
1485can be found in the `sys/<machine-type>` directories. These files define things
1486like 'the size of a pointer' and 'the range of an integer'. Since an AArch64
1487port for [FreeBSD] does not yet exist, the machine specific definitions are
1488based on existing machine types with similar properties (for example SPARC64).
1489
1490Where possible, C library function implementations were taken from [FreeBSD]
1491as found in the `lib/libc` directory.
1492
1493A copy of the [FreeBSD] sources can be downloaded with `git`.
1494
1495 git clone git://github.com/freebsd/freebsd.git -b origin/release/9.2.0
1496
1497
Soby Mathew27713fb2014-09-08 17:51:01 +010014986. Storage abstraction layer
Harry Liebeld265bd72014-01-31 19:04:10 +00001499-----------------------------
1500
1501In order to improve platform independence and portability an storage abstraction
1502layer is used to load data from non-volatile platform storage.
1503
1504Each platform should register devices and their drivers via the Storage layer.
1505These drivers then need to be initialized by bootloader phases as
1506required in their respective `blx_platform_setup()` functions. Currently
1507storage access is only required by BL1 and BL2 phases. The `load_image()`
1508function uses the storage layer to access non-volatile platform storage.
1509
Dan Handley4a75b842015-03-19 19:24:43 +00001510It is mandatory to implement at least one storage driver. For the ARM
1511development platforms the Firmware Image Package (FIP) driver is provided as
1512the default means to load data from storage (see the "Firmware Image Package"
1513section in the [User Guide]). The storage layer is described in the header file
1514`include/drivers/io/io_storage.h`. The implementation of the common library
Sandrine Bailleux121f2ae2015-01-28 10:11:48 +00001515is in `drivers/io/io_storage.c` and the driver files are located in
1516`drivers/io/`.
Harry Liebeld265bd72014-01-31 19:04:10 +00001517
1518Each IO driver must provide `io_dev_*` structures, as described in
1519`drivers/io/io_driver.h`. These are returned via a mandatory registration
1520function that is called on platform initialization. The semi-hosting driver
1521implementation in `io_semihosting.c` can be used as an example.
1522
1523The Storage layer provides mechanisms to initialize storage devices before
1524IO operations are called. The basic operations supported by the layer
1525include `open()`, `close()`, `read()`, `write()`, `size()` and `seek()`.
1526Drivers do not have to implement all operations, but each platform must
1527provide at least one driver for a device capable of supporting generic
1528operations such as loading a bootloader image.
1529
1530The current implementation only allows for known images to be loaded by the
Dan Handleyb68954c2014-05-29 12:30:24 +01001531firmware. These images are specified by using their names, as defined in
1532[include/plat/common/platform.h]. The platform layer (`plat_get_image_source()`)
1533then returns a reference to a device and a driver-specific `spec` which will be
1534understood by the driver to allow access to the image data.
Harry Liebeld265bd72014-01-31 19:04:10 +00001535
1536The layer is designed in such a way that is it possible to chain drivers with
1537other drivers. For example, file-system drivers may be implemented on top of
1538physical block devices, both represented by IO devices with corresponding
1539drivers. In such a case, the file-system "binding" with the block device may
1540be deferred until the file-system device is initialised.
1541
1542The abstraction currently depends on structures being statically allocated
1543by the drivers and callers, as the system does not yet provide a means of
1544dynamically allocating memory. This may also have the affect of limiting the
1545amount of open resources per driver.
1546
1547
Achin Gupta4f6ad662013-10-25 09:08:21 +01001548- - - - - - - - - - - - - - - - - - - - - - - - - -
1549
Dan Handley4a75b842015-03-19 19:24:43 +00001550_Copyright (c) 2013-2015, ARM Limited and Contributors. All rights reserved._
Achin Gupta4f6ad662013-10-25 09:08:21 +01001551
1552
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001553[ARM GIC Architecture Specification]: http://arminfo.emea.arm.com/help/topic/com.arm.doc.ihi0048b/IHI0048B_gic_architecture_specification.pdf
1554[IMF Design Guide]: interrupt-framework-design.md
1555[User Guide]: user-guide.md
1556[FreeBSD]: http://www.freebsd.org
Dan Handley4a75b842015-03-19 19:24:43 +00001557[Firmware Design]: firmware-design.md
Achin Gupta4f6ad662013-10-25 09:08:21 +01001558
Andrew Thoelke2bf28e62014-03-20 10:48:23 +00001559[plat/common/aarch64/platform_mp_stack.S]: ../plat/common/aarch64/platform_mp_stack.S
1560[plat/common/aarch64/platform_up_stack.S]: ../plat/common/aarch64/platform_up_stack.S
Dan Handley4a75b842015-03-19 19:24:43 +00001561[plat/arm/board/fvp/fvp_pm.c]: ../plat/arm/board/fvp/fvp_pm.c
Andrew Thoelke2bf28e62014-03-20 10:48:23 +00001562[include/runtime_svc.h]: ../include/runtime_svc.h
Dan Handley4a75b842015-03-19 19:24:43 +00001563[include/plat/arm/common/arm_def.h]: ../include/plat/arm/common/arm_def.h
1564[include/plat/common/common_def.h]: ../include/plat/common/common_def.h
Dan Handleyb68954c2014-05-29 12:30:24 +01001565[include/plat/common/platform.h]: ../include/plat/common/platform.h
Dan Handley4a75b842015-03-19 19:24:43 +00001566[include/plat/arm/common/plat_arm.h]: ../include/plat/arm/common/plat_arm.h]