blob: fba320a837aaa18e0c9fe0a0e12f506d9f4e03c7 [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)
Soby Mathew58523c02015-06-08 12:32:50 +010011 * [Common mandatory modifications](#23-common-mandatory-modifications)
12 * [Common optional modifications](#24-common-optional-modifications)
Joakim Bech14a5b342014-11-25 10:55:26 +0100133. [Boot Loader stage specific modifications](#3--modifications-specific-to-a-boot-loader-stage)
14 * [Boot Loader stage 1 (BL1)](#31-boot-loader-stage-1-bl1)
15 * [Boot Loader stage 2 (BL2)](#32-boot-loader-stage-2-bl2)
Yatharth Kochar84a5d6d2015-10-27 15:55:18 +000016 * [FWU Boot Loader stage 2 (BL2U)](#33-fwu-boot-loader-stage-2-bl2u)
17 * [Boot Loader stage 3-1 (BL31)](#34-boot-loader-stage-3-1-bl31)
18 * [PSCI implementation (in BL31)](#35-power-state-coordination-interface-in-bl31)
19 * [Interrupt Management framework (in BL31)](#36--interrupt-management-framework-in-bl31)
20 * [Crash Reporting mechanism (in BL31)](#37--crash-reporting-mechanism-in-bl31)
Joakim Bech14a5b342014-11-25 10:55:26 +0100214. [Build flags](#4--build-flags)
225. [C Library](#5--c-library)
236. [Storage abstraction layer](#6--storage-abstraction-layer)
Achin Gupta4f6ad662013-10-25 09:08:21 +010024
25- - - - - - - - - - - - - - - - - -
26
271. Introduction
28----------------
29
Soby Mathew58523c02015-06-08 12:32:50 +010030Please note that this document has been updated for the new platform API
31as required by the PSCI v1.0 implementation. Please refer to the
32[Migration Guide] for the previous platform API.
33
Achin Gupta4f6ad662013-10-25 09:08:21 +010034Porting the ARM Trusted Firmware to a new platform involves making some
35mandatory and optional modifications for both the cold and warm boot paths.
36Modifications consist of:
37
38* Implementing a platform-specific function or variable,
39* Setting up the execution context in a certain way, or
40* Defining certain constants (for example #defines).
41
Dan Handley4a75b842015-03-19 19:24:43 +000042The platform-specific functions and variables are declared in
Dan Handleyb68954c2014-05-29 12:30:24 +010043[include/plat/common/platform.h]. The firmware provides a default implementation
44of variables and functions to fulfill the optional requirements. These
45implementations are all weakly defined; they are provided to ease the porting
46effort. Each platform port can override them with its own implementation if the
47default implementation is inadequate.
Achin Gupta4f6ad662013-10-25 09:08:21 +010048
Dan Handley4a75b842015-03-19 19:24:43 +000049Platform ports that want to be aligned with standard ARM platforms (for example
50FVP and Juno) may also use [include/plat/arm/common/plat_arm.h] and the
51corresponding source files in `plat/arm/common/`. These provide standard
52implementations for some of the required platform porting functions. However,
53using these functions requires the platform port to implement additional
54ARM standard platform porting functions. These additional functions are not
55documented here.
56
Achin Gupta4f6ad662013-10-25 09:08:21 +010057Some modifications are common to all Boot Loader (BL) stages. Section 2
58discusses these in detail. The subsequent sections discuss the remaining
59modifications for each BL stage in detail.
60
61This document should be read in conjunction with the ARM Trusted Firmware
62[User Guide].
63
64
652. Common modifications
66------------------------
67
68This section covers the modifications that should be made by the platform for
69each BL stage to correctly port the firmware stack. They are categorized as
70either mandatory or optional.
71
72
732.1 Common mandatory modifications
74----------------------------------
Sandrine Bailleuxef7fb9e2015-12-02 10:19:06 +000075
76A platform port must enable the Memory Management Unit (MMU) as well as the
77instruction and data caches for each BL stage. Setting up the translation
78tables is the responsibility of the platform port because memory maps differ
Sandrine Bailleux3c2c72f2016-04-26 14:49:57 +010079across platforms. A memory translation library (see `lib/xlat_tables/`) is
80provided to help in this setup. Note that although this library supports
Antonio Nino Diazf33fbb22016-03-31 09:08:56 +010081non-identity mappings, this is intended only for re-mapping peripheral physical
82addresses and allows platforms with high I/O addresses to reduce their virtual
83address space. All other addresses corresponding to code and data must currently
84use an identity mapping.
Sandrine Bailleuxef7fb9e2015-12-02 10:19:06 +000085
86In ARM standard platforms, each BL stage configures the MMU in the
87platform-specific architecture setup function, `blX_plat_arch_setup()`, and uses
88an identity mapping for all addresses.
Achin Gupta4f6ad662013-10-25 09:08:21 +010089
Andrew Thoelkeee7b35c2015-09-10 11:39:36 +010090If the build option `USE_COHERENT_MEM` is enabled, each platform can allocate a
Soby Mathewab8707e2015-01-08 18:02:44 +000091block of identity mapped secure memory with Device-nGnRE attributes aligned to
Andrew Thoelkeee7b35c2015-09-10 11:39:36 +010092page boundary (4K) for each BL stage. All sections which allocate coherent
93memory are grouped under `coherent_ram`. For ex: Bakery locks are placed in a
94section identified by name `bakery_lock` inside `coherent_ram` so that its
95possible for the firmware to place variables in it using the following C code
96directive:
Achin Gupta4f6ad662013-10-25 09:08:21 +010097
Soren Brinkmann65cd2992016-01-14 10:11:05 -080098 __section("bakery_lock")
Achin Gupta4f6ad662013-10-25 09:08:21 +010099
100Or alternatively the following assembler code directive:
101
Andrew Thoelkeee7b35c2015-09-10 11:39:36 +0100102 .section bakery_lock
Achin Gupta4f6ad662013-10-25 09:08:21 +0100103
Andrew Thoelkeee7b35c2015-09-10 11:39:36 +0100104The `coherent_ram` section is a sum of all sections like `bakery_lock` which are
105used to allocate any data structures that are accessed both when a CPU is
106executing with its MMU and caches enabled, and when it's running with its MMU
107and caches disabled. Examples are given below.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100108
109The following variables, functions and constants must be defined by the platform
110for the firmware to work correctly.
111
112
Dan Handleyb68954c2014-05-29 12:30:24 +0100113### File : platform_def.h [mandatory]
Achin Gupta4f6ad662013-10-25 09:08:21 +0100114
Dan Handleyb68954c2014-05-29 12:30:24 +0100115Each platform must ensure that a header file of this name is in the system
116include path with the following constants defined. This may require updating the
Dan Handley4a75b842015-03-19 19:24:43 +0000117list of `PLAT_INCLUDES` in the `platform.mk` file. In the ARM development
118platforms, this file is found in `plat/arm/board/<plat_name>/include/`.
119
120Platform ports may optionally use the file [include/plat/common/common_def.h],
121which provides typical values for some of the constants below. These values are
122likely to be suitable for all platform ports.
123
124Platform ports that want to be aligned with standard ARM platforms (for example
125FVP and Juno) may also use [include/plat/arm/common/arm_def.h], which provides
126standard values for some of the constants below. However, this requires the
127platform port to define additional platform porting constants in
128`platform_def.h`. These additional constants are not documented here.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100129
James Morrisseyba3155b2013-10-29 10:56:46 +0000130* **#define : PLATFORM_LINKER_FORMAT**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100131
132 Defines the linker format used by the platform, for example
Dan Handley4a75b842015-03-19 19:24:43 +0000133 `elf64-littleaarch64`.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100134
James Morrisseyba3155b2013-10-29 10:56:46 +0000135* **#define : PLATFORM_LINKER_ARCH**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100136
137 Defines the processor architecture for the linker by the platform, for
Dan Handley4a75b842015-03-19 19:24:43 +0000138 example `aarch64`.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100139
James Morrisseyba3155b2013-10-29 10:56:46 +0000140* **#define : PLATFORM_STACK_SIZE**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100141
142 Defines the normal stack memory available to each CPU. This constant is used
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000143 by [plat/common/aarch64/platform_mp_stack.S] and
144 [plat/common/aarch64/platform_up_stack.S].
145
Dan Handley4a75b842015-03-19 19:24:43 +0000146* **define : CACHE_WRITEBACK_GRANULE**
147
148 Defines the size in bits of the largest cache line across all the cache
149 levels in the platform.
150
James Morrisseyba3155b2013-10-29 10:56:46 +0000151* **#define : FIRMWARE_WELCOME_STR**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100152
153 Defines the character string printed by BL1 upon entry into the `bl1_main()`
154 function.
155
James Morrisseyba3155b2013-10-29 10:56:46 +0000156* **#define : PLATFORM_CORE_COUNT**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100157
158 Defines the total number of CPUs implemented by the platform across all
159 clusters in the system.
160
Soby Mathew58523c02015-06-08 12:32:50 +0100161* **#define : PLAT_NUM_PWR_DOMAINS**
Andrew Thoelke6c0b45d2014-06-20 00:36:14 +0100162
Soby Mathew58523c02015-06-08 12:32:50 +0100163 Defines the total number of nodes in the power domain topology
164 tree at all the power domain levels used by the platform.
165 This macro is used by the PSCI implementation to allocate
166 data structures to represent power domain topology.
Andrew Thoelke6c0b45d2014-06-20 00:36:14 +0100167
Soby Mathew58523c02015-06-08 12:32:50 +0100168* **#define : PLAT_MAX_PWR_LVL**
Soby Mathew8c32bc22015-02-12 14:45:02 +0000169
Soby Mathew58523c02015-06-08 12:32:50 +0100170 Defines the maximum power domain level that the power management operations
171 should apply to. More often, but not always, the power domain level
172 corresponds to affinity level. This macro allows the PSCI implementation
173 to know the highest power domain level that it should consider for power
174 management operations in the system that the platform implements. For
175 example, the Base AEM FVP implements two clusters with a configurable
176 number of CPUs and it reports the maximum power domain level as 1.
177
178* **#define : PLAT_MAX_OFF_STATE**
179
180 Defines the local power state corresponding to the deepest power down
181 possible at every power domain level in the platform. The local power
182 states for each level may be sparsely allocated between 0 and this value
183 with 0 being reserved for the RUN state. The PSCI implementation uses this
184 value to initialize the local power states of the power domain nodes and
185 to specify the requested power state for a PSCI_CPU_OFF call.
186
187* **#define : PLAT_MAX_RET_STATE**
188
189 Defines the local power state corresponding to the deepest retention state
190 possible at every power domain level in the platform. This macro should be
191 a value less than PLAT_MAX_OFF_STATE and greater than 0. It is used by the
192 PSCI implementation to distuiguish between retention and power down local
193 power states within PSCI_CPU_SUSPEND call.
Soby Mathew8c32bc22015-02-12 14:45:02 +0000194
Sandrine Bailleux638363e2014-05-21 17:08:26 +0100195* **#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 Morrisseyba3155b2013-10-29 10:56:46 +0000215* **#define : BL2_BASE**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100216
217 Defines the base address in secure RAM where BL1 loads the BL2 binary image.
Sandrine Bailleuxcd29b0a2013-11-27 10:32:17 +0000218 Must be aligned on a page-size boundary.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100219
Sandrine Bailleux638363e2014-05-21 17:08:26 +0100220* **#define : BL2_LIMIT**
221
222 Defines the maximum address in secure RAM that the BL2 image can occupy.
223
James Morrisseyba3155b2013-10-29 10:56:46 +0000224* **#define : BL31_BASE**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100225
Juan Castillod1786372015-12-14 09:35:25 +0000226 Defines the base address in secure RAM where BL2 loads the BL31 binary
Sandrine Bailleuxcd29b0a2013-11-27 10:32:17 +0000227 image. Must be aligned on a page-size boundary.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100228
Sandrine Bailleux638363e2014-05-21 17:08:26 +0100229* **#define : BL31_LIMIT**
230
Juan Castillod1786372015-12-14 09:35:25 +0000231 Defines the maximum address in secure RAM that the BL31 image can occupy.
Sandrine Bailleux638363e2014-05-21 17:08:26 +0100232
Juan Castillo16948ae2015-04-13 17:36:19 +0100233For every image, the platform must define individual identifiers that will be
234used by BL1 or BL2 to load the corresponding image into memory from non-volatile
235storage. For the sake of performance, integer numbers will be used as
236identifiers. The platform will use those identifiers to return the relevant
237information about the image to be loaded (file handler, load address,
238authentication information, etc.). The following image identifiers are
239mandatory:
240
241* **#define : BL2_IMAGE_ID**
242
243 BL2 image identifier, used by BL1 to load BL2.
244
245* **#define : BL31_IMAGE_ID**
246
Juan Castillod1786372015-12-14 09:35:25 +0000247 BL31 image identifier, used by BL2 to load BL31.
Juan Castillo16948ae2015-04-13 17:36:19 +0100248
249* **#define : BL33_IMAGE_ID**
250
Juan Castillod1786372015-12-14 09:35:25 +0000251 BL33 image identifier, used by BL2 to load BL33.
Juan Castillo16948ae2015-04-13 17:36:19 +0100252
253If Trusted Board Boot is enabled, the following certificate identifiers must
254also be defined:
255
Juan Castillo516beb52015-12-03 10:19:21 +0000256* **#define : TRUSTED_BOOT_FW_CERT_ID**
Juan Castillo16948ae2015-04-13 17:36:19 +0100257
258 BL2 content certificate identifier, used by BL1 to load the BL2 content
259 certificate.
260
261* **#define : TRUSTED_KEY_CERT_ID**
262
263 Trusted key certificate identifier, used by BL2 to load the trusted key
264 certificate.
265
Juan Castillo516beb52015-12-03 10:19:21 +0000266* **#define : SOC_FW_KEY_CERT_ID**
Juan Castillo16948ae2015-04-13 17:36:19 +0100267
Juan Castillod1786372015-12-14 09:35:25 +0000268 BL31 key certificate identifier, used by BL2 to load the BL31 key
Juan Castillo16948ae2015-04-13 17:36:19 +0100269 certificate.
270
Juan Castillo516beb52015-12-03 10:19:21 +0000271* **#define : SOC_FW_CONTENT_CERT_ID**
Juan Castillo16948ae2015-04-13 17:36:19 +0100272
Juan Castillod1786372015-12-14 09:35:25 +0000273 BL31 content certificate identifier, used by BL2 to load the BL31 content
Juan Castillo16948ae2015-04-13 17:36:19 +0100274 certificate.
275
Juan Castillo516beb52015-12-03 10:19:21 +0000276* **#define : NON_TRUSTED_FW_KEY_CERT_ID**
Juan Castillo16948ae2015-04-13 17:36:19 +0100277
Juan Castillod1786372015-12-14 09:35:25 +0000278 BL33 key certificate identifier, used by BL2 to load the BL33 key
Juan Castillo16948ae2015-04-13 17:36:19 +0100279 certificate.
280
Juan Castillo516beb52015-12-03 10:19:21 +0000281* **#define : NON_TRUSTED_FW_CONTENT_CERT_ID**
Juan Castillo16948ae2015-04-13 17:36:19 +0100282
Juan Castillod1786372015-12-14 09:35:25 +0000283 BL33 content certificate identifier, used by BL2 to load the BL33 content
Juan Castillo16948ae2015-04-13 17:36:19 +0100284 certificate.
285
Yatharth Kochar84a5d6d2015-10-27 15:55:18 +0000286* **#define : FWU_CERT_ID**
287
288 Firmware Update (FWU) certificate identifier, used by NS_BL1U to load the
289 FWU content certificate.
290
291
292If the AP Firmware Updater Configuration image, BL2U is used, the following
293must also be defined:
294
295* **#define : BL2U_BASE**
296
297 Defines the base address in secure memory where BL1 copies the BL2U binary
298 image. Must be aligned on a page-size boundary.
299
300* **#define : BL2U_LIMIT**
301
302 Defines the maximum address in secure memory that the BL2U image can occupy.
303
304* **#define : BL2U_IMAGE_ID**
305
306 BL2U image identifier, used by BL1 to fetch an image descriptor
307 corresponding to BL2U.
308
309If the SCP Firmware Update Configuration Image, SCP_BL2U is used, the following
310must also be defined:
311
312* **#define : SCP_BL2U_IMAGE_ID**
313
314 SCP_BL2U image identifier, used by BL1 to fetch an image descriptor
315 corresponding to SCP_BL2U.
316 NOTE: TF does not provide source code for this image.
317
318If the Non-Secure Firmware Updater ROM, NS_BL1U is used, the following must
319also be defined:
320
321* **#define : NS_BL1U_BASE**
322
323 Defines the base address in non-secure ROM where NS_BL1U executes.
324 Must be aligned on a page-size boundary.
325 NOTE: TF does not provide source code for this image.
326
327* **#define : NS_BL1U_IMAGE_ID**
328
329 NS_BL1U image identifier, used by BL1 to fetch an image descriptor
330 corresponding to NS_BL1U.
331
332If the Non-Secure Firmware Updater, NS_BL2U is used, the following must also
333be defined:
334
335* **#define : NS_BL2U_BASE**
336
337 Defines the base address in non-secure memory where NS_BL2U executes.
338 Must be aligned on a page-size boundary.
339 NOTE: TF does not provide source code for this image.
340
341* **#define : NS_BL2U_IMAGE_ID**
342
343 NS_BL2U image identifier, used by BL1 to fetch an image descriptor
344 corresponding to NS_BL2U.
345
346
Juan Castillof59821d2015-12-10 15:49:17 +0000347If a SCP_BL2 image is supported by the platform, the following constants must
Achin Gupta8d35f612015-01-25 22:44:23 +0000348also be defined:
349
Juan Castillof59821d2015-12-10 15:49:17 +0000350* **#define : SCP_BL2_IMAGE_ID**
Achin Gupta8d35f612015-01-25 22:44:23 +0000351
Juan Castillof59821d2015-12-10 15:49:17 +0000352 SCP_BL2 image identifier, used by BL2 to load SCP_BL2 into secure memory
353 from platform storage before being transfered to the SCP.
Achin Gupta8d35f612015-01-25 22:44:23 +0000354
Juan Castillo516beb52015-12-03 10:19:21 +0000355* **#define : SCP_FW_KEY_CERT_ID**
Achin Gupta8d35f612015-01-25 22:44:23 +0000356
Juan Castillof59821d2015-12-10 15:49:17 +0000357 SCP_BL2 key certificate identifier, used by BL2 to load the SCP_BL2 key
Juan Castillo16948ae2015-04-13 17:36:19 +0100358 certificate (mandatory when Trusted Board Boot is enabled).
Achin Gupta8d35f612015-01-25 22:44:23 +0000359
Juan Castillo516beb52015-12-03 10:19:21 +0000360* **#define : SCP_FW_CONTENT_CERT_ID**
Achin Gupta8d35f612015-01-25 22:44:23 +0000361
Juan Castillof59821d2015-12-10 15:49:17 +0000362 SCP_BL2 content certificate identifier, used by BL2 to load the SCP_BL2
363 content certificate (mandatory when Trusted Board Boot is enabled).
Achin Gupta8d35f612015-01-25 22:44:23 +0000364
Juan Castillod1786372015-12-14 09:35:25 +0000365If a BL32 image is supported by the platform, the following constants must
Dan Handley5a06bb72014-08-04 11:41:20 +0100366also be defined:
Sandrine Bailleux2467f702014-05-20 17:22:24 +0100367
Juan Castillo16948ae2015-04-13 17:36:19 +0100368* **#define : BL32_IMAGE_ID**
Sandrine Bailleux2467f702014-05-20 17:22:24 +0100369
Juan Castillod1786372015-12-14 09:35:25 +0000370 BL32 image identifier, used by BL2 to load BL32.
Sandrine Bailleux2467f702014-05-20 17:22:24 +0100371
Juan Castillo516beb52015-12-03 10:19:21 +0000372* **#define : TRUSTED_OS_FW_KEY_CERT_ID**
Achin Gupta8d35f612015-01-25 22:44:23 +0000373
Juan Castillod1786372015-12-14 09:35:25 +0000374 BL32 key certificate identifier, used by BL2 to load the BL32 key
Juan Castillo16948ae2015-04-13 17:36:19 +0100375 certificate (mandatory when Trusted Board Boot is enabled).
Achin Gupta8d35f612015-01-25 22:44:23 +0000376
Juan Castillo516beb52015-12-03 10:19:21 +0000377* **#define : TRUSTED_OS_FW_CONTENT_CERT_ID**
Achin Gupta8d35f612015-01-25 22:44:23 +0000378
Juan Castillod1786372015-12-14 09:35:25 +0000379 BL32 content certificate identifier, used by BL2 to load the BL32 content
Juan Castillo16948ae2015-04-13 17:36:19 +0100380 certificate (mandatory when Trusted Board Boot is enabled).
Achin Gupta8d35f612015-01-25 22:44:23 +0000381
Sandrine Bailleux2467f702014-05-20 17:22:24 +0100382* **#define : BL32_BASE**
383
Juan Castillod1786372015-12-14 09:35:25 +0000384 Defines the base address in secure memory where BL2 loads the BL32 binary
Dan Handley5a06bb72014-08-04 11:41:20 +0100385 image. Must be aligned on a page-size boundary.
Sandrine Bailleux2467f702014-05-20 17:22:24 +0100386
387* **#define : BL32_LIMIT**
388
Juan Castillod1786372015-12-14 09:35:25 +0000389 Defines the maximum address that the BL32 image can occupy.
Dan Handley5a06bb72014-08-04 11:41:20 +0100390
Juan Castillod1786372015-12-14 09:35:25 +0000391If the Test Secure-EL1 Payload (TSP) instantiation of BL32 is supported by the
Dan Handley5a06bb72014-08-04 11:41:20 +0100392platform, the following constants must also be defined:
393
394* **#define : TSP_SEC_MEM_BASE**
395
396 Defines the base address of the secure memory used by the TSP image on the
397 platform. This must be at the same address or below `BL32_BASE`.
398
399* **#define : TSP_SEC_MEM_SIZE**
400
Juan Castillod1786372015-12-14 09:35:25 +0000401 Defines the size of the secure memory used by the BL32 image on the
Dan Handley5a06bb72014-08-04 11:41:20 +0100402 platform. `TSP_SEC_MEM_BASE` and `TSP_SEC_MEM_SIZE` must fully accomodate
Juan Castillod1786372015-12-14 09:35:25 +0000403 the memory required by the BL32 image, defined by `BL32_BASE` and
Dan Handley5a06bb72014-08-04 11:41:20 +0100404 `BL32_LIMIT`.
405
406* **#define : TSP_IRQ_SEC_PHY_TIMER**
407
408 Defines the ID of the secure physical generic timer interrupt used by the
409 TSP's interrupt handling code.
Sandrine Bailleux2467f702014-05-20 17:22:24 +0100410
Dan Handley4a75b842015-03-19 19:24:43 +0000411If the platform port uses the translation table library code, the following
412constant must also be defined:
413
414* **#define : MAX_XLAT_TABLES**
415
416 Defines the maximum number of translation tables that are allocated by the
417 translation table library code. To minimize the amount of runtime memory
418 used, choose the smallest value needed to map the required virtual addresses
419 for each BL stage.
420
Juan Castillo359b60d2016-01-07 11:29:15 +0000421* **#define : MAX_MMAP_REGIONS**
422
423 Defines the maximum number of regions that are allocated by the translation
424 table library code. A region consists of physical base address, virtual base
425 address, size and attributes (Device/Memory, RO/RW, Secure/Non-Secure), as
426 defined in the `mmap_region_t` structure. The platform defines the regions
427 that should be mapped. Then, the translation table library will create the
428 corresponding tables and descriptors at runtime. To minimize the amount of
429 runtime memory used, choose the smallest value needed to register the
430 required regions for each BL stage.
431
432* **#define : ADDR_SPACE_SIZE**
433
434 Defines the total size of the address space in bytes. For example, for a 32
435 bit address space, this value should be `(1ull << 32)`.
436
Dan Handley6d16ce02014-08-04 18:31:43 +0100437If the platform port uses the IO storage framework, the following constants
438must also be defined:
439
440* **#define : MAX_IO_DEVICES**
441
442 Defines the maximum number of registered IO devices. Attempting to register
443 more devices than this value using `io_register_device()` will fail with
Juan Castillo7e26fe12015-10-01 17:55:11 +0100444 -ENOMEM.
Dan Handley6d16ce02014-08-04 18:31:43 +0100445
446* **#define : MAX_IO_HANDLES**
447
448 Defines the maximum number of open IO handles. Attempting to open more IO
Juan Castillo7e26fe12015-10-01 17:55:11 +0100449 entities than this value using `io_open()` will fail with -ENOMEM.
Dan Handley6d16ce02014-08-04 18:31:43 +0100450
Haojian Zhuang08b375b2016-04-21 10:52:52 +0800451* **#define : MAX_IO_BLOCK_DEVICES**
452
453 Defines the maximum number of registered IO block devices. Attempting to
454 register more devices this value using `io_dev_open()` will fail
455 with -ENOMEM. MAX_IO_BLOCK_DEVICES should be less than MAX_IO_DEVICES.
456 With this macro, multiple block devices could be supported at the same
457 time.
458
Soby Mathewab8707e2015-01-08 18:02:44 +0000459If the platform needs to allocate data within the per-cpu data framework in
Juan Castillod1786372015-12-14 09:35:25 +0000460BL31, it should define the following macro. Currently this is only required if
Soby Mathewab8707e2015-01-08 18:02:44 +0000461the platform decides not to use the coherent memory section by undefining the
Sandrine Bailleux1645d3e2015-12-17 13:58:58 +0000462`USE_COHERENT_MEM` build flag. In this case, the framework allocates the
463required memory within the the per-cpu data to minimize wastage.
Soby Mathewab8707e2015-01-08 18:02:44 +0000464
465* **#define : PLAT_PCPU_DATA_SIZE**
466
467 Defines the memory (in bytes) to be reserved within the per-cpu data
468 structure for use by the platform layer.
469
Sandrine Bailleux46d49f632014-06-23 17:00:23 +0100470The following constants are optional. They should be defined when the platform
Dan Handley4a75b842015-03-19 19:24:43 +0000471memory layout implies some image overlaying like in ARM standard platforms.
Sandrine Bailleux46d49f632014-06-23 17:00:23 +0100472
473* **#define : BL31_PROGBITS_LIMIT**
474
Juan Castillod1786372015-12-14 09:35:25 +0000475 Defines the maximum address in secure RAM that the BL31's progbits sections
Sandrine Bailleux46d49f632014-06-23 17:00:23 +0100476 can occupy.
477
Dan Handley5a06bb72014-08-04 11:41:20 +0100478* **#define : TSP_PROGBITS_LIMIT**
Sandrine Bailleux46d49f632014-06-23 17:00:23 +0100479
480 Defines the maximum address that the TSP's progbits sections can occupy.
Sandrine Bailleux2467f702014-05-20 17:22:24 +0100481
Haojian Zhuang7dc4b222016-02-03 22:35:04 +0800482If the platform port uses the PL061 GPIO driver, the following constant may
483optionally be defined:
484
485* **PLAT_PL061_MAX_GPIOS**
486 Maximum number of GPIOs required by the platform. This allows control how
487 much memory is allocated for PL061 GPIO controllers. The default value is
488 32.
489 [For example, define the build flag in platform.mk]:
490 PLAT_PL061_MAX_GPIOS := 160
491 $(eval $(call add_define,PLAT_PL061_MAX_GPIOS))
492
493
Dan Handleyb68954c2014-05-29 12:30:24 +0100494### File : plat_macros.S [mandatory]
Soby Mathewa43d4312014-04-07 15:28:55 +0100495
Dan Handleyb68954c2014-05-29 12:30:24 +0100496Each platform must ensure a file of this name is in the system include path with
Dan Handley4a75b842015-03-19 19:24:43 +0000497the following macro defined. In the ARM development platforms, this file is
498found in `plat/arm/board/<plat_name>/include/plat_macros.S`.
Soby Mathewa43d4312014-04-07 15:28:55 +0100499
Gerald Lejeune9ff67fa2015-11-26 15:47:53 +0100500* **Macro : plat_crash_print_regs**
Soby Mathewa43d4312014-04-07 15:28:55 +0100501
Gerald Lejeune9ff67fa2015-11-26 15:47:53 +0100502 This macro allows the crash reporting routine to print relevant platform
Juan Castillod1786372015-12-14 09:35:25 +0000503 registers in case of an unhandled exception in BL31. This aids in debugging
Gerald Lejeune9ff67fa2015-11-26 15:47:53 +0100504 and this macro can be defined to be empty in case register reporting is not
505 desired.
506
507 For instance, GIC or interconnect registers may be helpful for
508 troubleshooting.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100509
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000510
Vikram Kanigirie452cd82014-05-23 15:56:12 +01005112.2 Handling Reset
512------------------
513
514BL1 by default implements the reset vector where execution starts from a cold
Juan Castillod1786372015-12-14 09:35:25 +0000515or warm boot. BL31 can be optionally set as a reset vector using the
Sandrine Bailleux1645d3e2015-12-17 13:58:58 +0000516`RESET_TO_BL31` make variable.
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100517
518For each CPU, the reset vector code is responsible for the following tasks:
519
5201. Distinguishing between a cold boot and a warm boot.
521
5222. In the case of a cold boot and the CPU being a secondary CPU, ensuring that
523 the CPU is placed in a platform-specific state until the primary CPU
524 performs the necessary steps to remove it from this state.
525
5263. In the case of a warm boot, ensuring that the CPU jumps to a platform-
Juan Castillod1786372015-12-14 09:35:25 +0000527 specific address in the BL31 image in the same processor mode as it was
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100528 when released from reset.
529
530The following functions need to be implemented by the platform port to enable
531reset vector code to perform the above tasks.
532
533
Soby Mathew58523c02015-06-08 12:32:50 +0100534### Function : plat_get_my_entrypoint() [mandatory when PROGRAMMABLE_RESET_ADDRESS == 0]
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100535
Soby Mathew58523c02015-06-08 12:32:50 +0100536 Argument : void
537 Return : unsigned long
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100538
Soby Mathew58523c02015-06-08 12:32:50 +0100539This function is called with the called with the MMU and caches disabled
540(`SCTLR_EL3.M` = 0 and `SCTLR_EL3.C` = 0). The function is responsible for
541distinguishing between a warm and cold reset for the current CPU using
542platform-specific means. If it's a warm reset, then it returns the warm
543reset entrypoint point provided to `plat_setup_psci_ops()` during
Juan Castillod1786372015-12-14 09:35:25 +0000544BL31 initialization. If it's a cold reset then this function must return zero.
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100545
546This function does not follow the Procedure Call Standard used by the
547Application Binary Interface for the ARM 64-bit architecture. The caller should
548not assume that callee saved registers are preserved across a call to this
549function.
550
551This function fulfills requirement 1 and 3 listed above.
552
Soby Mathew58523c02015-06-08 12:32:50 +0100553Note that for platforms that support programming the reset address, it is
554expected that a CPU will start executing code directly at the right address,
555both on a cold and warm reset. In this case, there is no need to identify the
556type of reset nor to query the warm reset entrypoint. Therefore, implementing
557this function is not required on such platforms.
558
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100559
Sandrine Bailleuxa9bec672015-10-30 15:05:17 +0000560### Function : plat_secondary_cold_boot_setup() [mandatory when COLD_BOOT_SINGLE_CPU == 0]
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100561
562 Argument : void
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100563
564This function is called with the MMU and data caches disabled. It is responsible
565for placing the executing secondary CPU in a platform-specific state until the
566primary CPU performs the necessary actions to bring it out of that state and
Sandrine Bailleux52010cc2015-05-19 11:54:45 +0100567allow entry into the OS. This function must not return.
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100568
Sandrine Bailleuxcdf14082015-10-02 14:35:25 +0100569In the ARM FVP port, when using the normal boot flow, each secondary CPU powers
570itself off. The primary CPU is responsible for powering up the secondary CPUs
571when normal world software requires them. When booting an EL3 payload instead,
572they stay powered on and are put in a holding pen until their mailbox gets
573populated.
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100574
575This function fulfills requirement 2 above.
576
Sandrine Bailleuxa9bec672015-10-30 15:05:17 +0000577Note that for platforms that can't release secondary CPUs out of reset, only the
578primary CPU will execute the cold boot code. Therefore, implementing this
579function is not required on such platforms.
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100580
Sandrine Bailleuxa9bec672015-10-30 15:05:17 +0000581
582### Function : plat_is_my_cpu_primary() [mandatory when COLD_BOOT_SINGLE_CPU == 0]
Juan Castillo53fdceb2014-07-16 15:53:43 +0100583
Soby Mathew58523c02015-06-08 12:32:50 +0100584 Argument : void
Juan Castillo53fdceb2014-07-16 15:53:43 +0100585 Return : unsigned int
586
Soby Mathew58523c02015-06-08 12:32:50 +0100587This function identifies whether the current CPU is the primary CPU or a
588secondary CPU. A return value of zero indicates that the CPU is not the
589primary CPU, while a non-zero return value indicates that the CPU is the
590primary CPU.
Juan Castillo53fdceb2014-07-16 15:53:43 +0100591
Sandrine Bailleuxa9bec672015-10-30 15:05:17 +0000592Note that for platforms that can't release secondary CPUs out of reset, only the
593primary CPU will execute the cold boot code. Therefore, there is no need to
594distinguish between primary and secondary CPUs and implementing this function is
595not required.
596
Juan Castillo53fdceb2014-07-16 15:53:43 +0100597
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100598### Function : platform_mem_init() [mandatory]
599
600 Argument : void
601 Return : void
602
603This function is called before any access to data is made by the firmware, in
604order to carry out any essential memory initialization.
605
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100606
Juan Castillo95cfd4a2015-04-14 12:49:03 +0100607### Function: plat_get_rotpk_info()
608
609 Argument : void *, void **, unsigned int *, unsigned int *
610 Return : int
611
612This function is mandatory when Trusted Board Boot is enabled. It returns a
613pointer to the ROTPK stored in the platform (or a hash of it) and its length.
614The ROTPK must be encoded in DER format according to the following ASN.1
615structure:
616
617 AlgorithmIdentifier ::= SEQUENCE {
618 algorithm OBJECT IDENTIFIER,
619 parameters ANY DEFINED BY algorithm OPTIONAL
620 }
621
622 SubjectPublicKeyInfo ::= SEQUENCE {
623 algorithm AlgorithmIdentifier,
624 subjectPublicKey BIT STRING
625 }
626
627In case the function returns a hash of the key:
628
629 DigestInfo ::= SEQUENCE {
630 digestAlgorithm AlgorithmIdentifier,
631 digest OCTET STRING
632 }
633
Soby Mathew04943d32016-05-24 15:05:15 +0100634The function returns 0 on success. Any other value is treated as error by the
635Trusted Board Boot. The function also reports extra information related
636to the ROTPK in the flags parameter:
Juan Castillo95cfd4a2015-04-14 12:49:03 +0100637
Soby Mathew04943d32016-05-24 15:05:15 +0100638 ROTPK_IS_HASH : Indicates that the ROTPK returned by the platform is a
639 hash.
640 ROTPK_NOT_DEPLOYED : This allows the platform to skip certificate ROTPK
641 verification while the platform ROTPK is not deployed.
642 When this flag is set, the function does not need to
643 return a platform ROTPK, and the authentication
644 framework uses the ROTPK in the certificate without
645 verifying it against the platform value. This flag
646 must not be used in a deployed production environment.
Juan Castillo95cfd4a2015-04-14 12:49:03 +0100647
Juan Castillo48279d52016-01-22 11:05:57 +0000648### Function: plat_get_nv_ctr()
649
650 Argument : void *, unsigned int *
651 Return : int
652
653This function is mandatory when Trusted Board Boot is enabled. It returns the
654non-volatile counter value stored in the platform in the second argument. The
655cookie in the first argument may be used to select the counter in case the
656platform provides more than one (for example, on platforms that use the default
657TBBR CoT, the cookie will correspond to the OID values defined in
658TRUSTED_FW_NVCOUNTER_OID or NON_TRUSTED_FW_NVCOUNTER_OID).
659
660The function returns 0 on success. Any other value means the counter value could
661not be retrieved from the platform.
662
663
664### Function: plat_set_nv_ctr()
665
666 Argument : void *, unsigned int
667 Return : int
668
669This function is mandatory when Trusted Board Boot is enabled. It sets a new
670counter value in the platform. The cookie in the first argument may be used to
671select the counter (as explained in plat_get_nv_ctr()).
672
673The function returns 0 on success. Any other value means the counter value could
674not be updated.
675
676
Soby Mathew58523c02015-06-08 12:32:50 +01006772.3 Common mandatory modifications
678---------------------------------
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100679
Soby Mathew58523c02015-06-08 12:32:50 +0100680The following functions are mandatory functions which need to be implemented
681by the platform port.
682
683### Function : plat_my_core_pos()
684
685 Argument : void
686 Return : unsigned int
687
688This funtion returns the index of the calling CPU which is used as a
689CPU-specific linear index into blocks of memory (for example while allocating
690per-CPU stacks). This function will be invoked very early in the
691initialization sequence which mandates that this function should be
692implemented in assembly and should not rely on the avalability of a C
Antonio Nino Diaze5846732016-02-08 10:39:42 +0000693runtime environment. This function can clobber x0 - x8 and must preserve
694x9 - x29.
Soby Mathew58523c02015-06-08 12:32:50 +0100695
696This function plays a crucial role in the power domain topology framework in
697PSCI and details of this can be found in [Power Domain Topology Design].
698
699### Function : plat_core_pos_by_mpidr()
700
701 Argument : u_register_t
702 Return : int
703
704This function validates the `MPIDR` of a CPU and converts it to an index,
705which can be used as a CPU-specific linear index into blocks of memory. In
706case the `MPIDR` is invalid, this function returns -1. This function will only
Juan Castillod1786372015-12-14 09:35:25 +0000707be invoked by BL31 after the power domain topology is initialized and can
Soby Mathew58523c02015-06-08 12:32:50 +0100708utilize the C runtime environment. For further details about how ARM Trusted
709Firmware represents the power domain topology and how this relates to the
710linear CPU index, please refer [Power Domain Topology Design].
711
712
713
7142.4 Common optional modifications
Achin Gupta4f6ad662013-10-25 09:08:21 +0100715---------------------------------
716
717The following are helper functions implemented by the firmware that perform
718common platform-specific tasks. A platform may choose to override these
719definitions.
720
Soby Mathew58523c02015-06-08 12:32:50 +0100721### Function : plat_set_my_stack()
Achin Gupta4f6ad662013-10-25 09:08:21 +0100722
Soby Mathew58523c02015-06-08 12:32:50 +0100723 Argument : void
Achin Gupta4f6ad662013-10-25 09:08:21 +0100724 Return : void
725
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000726This function sets the current stack pointer to the normal memory stack that
Soby Mathew58523c02015-06-08 12:32:50 +0100727has been allocated for the current CPU. For BL images that only require a
728stack for the primary CPU, the UP version of the function is used. The size
729of the stack allocated to each CPU is specified by the platform defined
730constant `PLATFORM_STACK_SIZE`.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100731
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000732Common implementations of this function for the UP and MP BL images are
733provided in [plat/common/aarch64/platform_up_stack.S] and
734[plat/common/aarch64/platform_mp_stack.S]
Achin Gupta4f6ad662013-10-25 09:08:21 +0100735
736
Soby Mathew58523c02015-06-08 12:32:50 +0100737### Function : plat_get_my_stack()
Achin Guptac8afc782013-11-25 18:45:02 +0000738
Soby Mathew58523c02015-06-08 12:32:50 +0100739 Argument : void
Achin Guptac8afc782013-11-25 18:45:02 +0000740 Return : unsigned long
741
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000742This function returns the base address of the normal memory stack that
Soby Mathew58523c02015-06-08 12:32:50 +0100743has been allocated for the current CPU. For BL images that only require a
744stack for the primary CPU, the UP version of the function is used. The size
745of the stack allocated to each CPU is specified by the platform defined
746constant `PLATFORM_STACK_SIZE`.
Achin Guptac8afc782013-11-25 18:45:02 +0000747
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000748Common implementations of this function for the UP and MP BL images are
749provided in [plat/common/aarch64/platform_up_stack.S] and
750[plat/common/aarch64/platform_mp_stack.S]
Achin Guptac8afc782013-11-25 18:45:02 +0000751
752
Achin Gupta4f6ad662013-10-25 09:08:21 +0100753### Function : plat_report_exception()
754
755 Argument : unsigned int
756 Return : void
757
758A platform may need to report various information about its status when an
759exception is taken, for example the current exception level, the CPU security
760state (secure/non-secure), the exception type, and so on. This function is
761called in the following circumstances:
762
763* In BL1, whenever an exception is taken.
764* In BL2, whenever an exception is taken.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100765
766The default implementation doesn't do anything, to avoid making assumptions
767about the way the platform displays its status information.
768
769This function receives the exception type as its argument. Possible values for
Yatharth Kochar84a5d6d2015-10-27 15:55:18 +0000770exceptions types are listed in the [include/common/bl_common.h] header file.
771Note that these constants are not related to any architectural exception code;
772they are just an ARM Trusted Firmware convention.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100773
774
Soby Mathew24fb8382014-08-14 12:22:32 +0100775### Function : plat_reset_handler()
776
777 Argument : void
778 Return : void
779
780A platform may need to do additional initialization after reset. This function
781allows the platform to do the platform specific intializations. Platform
782specific errata workarounds could also be implemented here. The api should
Soby Mathew683f7882015-01-29 12:00:58 +0000783preserve the values of callee saved registers x19 to x29.
Soby Mathew24fb8382014-08-14 12:22:32 +0100784
Yatharth Kochar79a97b22014-11-20 18:09:41 +0000785The default implementation doesn't do anything. If a platform needs to override
Dan Handley4a75b842015-03-19 19:24:43 +0000786the default implementation, refer to the [Firmware Design] for general
Sandrine Bailleux452b7fa2015-05-27 17:14:22 +0100787guidelines.
Soby Mathew24fb8382014-08-14 12:22:32 +0100788
Soby Mathewadd40352014-08-14 12:49:05 +0100789### Function : plat_disable_acp()
790
791 Argument : void
792 Return : void
793
794This api allows a platform to disable the Accelerator Coherency Port (if
795present) during a cluster power down sequence. The default weak implementation
796doesn't do anything. Since this api is called during the power down sequence,
797it has restrictions for stack usage and it can use the registers x0 - x17 as
798scratch registers. It should preserve the value in x18 register as it is used
799by the caller to store the return address.
800
Juan Castillo40fc6cd2015-09-25 15:41:14 +0100801### Function : plat_error_handler()
802
803 Argument : int
804 Return : void
805
806This API is called when the generic code encounters an error situation from
807which it cannot continue. It allows the platform to perform error reporting or
808recovery actions (for example, reset the system). This function must not return.
809
810The parameter indicates the type of error using standard codes from `errno.h`.
811Possible errors reported by the generic code are:
812
813* `-EAUTH`: a certificate or image could not be authenticated (when Trusted
814 Board Boot is enabled)
815* `-ENOENT`: the requested image or certificate could not be found or an IO
816 error was detected
817* `-ENOMEM`: resources exhausted. Trusted Firmware does not use dynamic
818 memory, so this error is usually an indication of an incorrect array size
819
820The default implementation simply spins.
821
Antonio Nino Diaz1c3ea102016-02-01 13:57:25 +0000822### Function : plat_panic_handler()
823
824 Argument : void
825 Return : void
826
827This API is called when the generic code encounters an unexpected error
828situation from which it cannot recover. This function must not return,
829and must be implemented in assembly because it may be called before the C
830environment is initialized.
831
832Note: The address from where it was called is stored in x30 (Link Register).
833
834The default implementation simply spins.
835
Soby Mathew24fb8382014-08-14 12:22:32 +0100836
Achin Gupta4f6ad662013-10-25 09:08:21 +01008373. Modifications specific to a Boot Loader stage
838-------------------------------------------------
839
8403.1 Boot Loader Stage 1 (BL1)
841-----------------------------
842
843BL1 implements the reset vector where execution starts from after a cold or
844warm boot. For each CPU, BL1 is responsible for the following tasks:
845
Vikram Kanigirie452cd82014-05-23 15:56:12 +01008461. Handling the reset as described in section 2.2
Achin Gupta4f6ad662013-10-25 09:08:21 +0100847
8482. In the case of a cold boot and the CPU being the primary CPU, ensuring that
849 only this CPU executes the remaining BL1 code, including loading and passing
850 control to the BL2 stage.
851
Yatharth Kochar84a5d6d2015-10-27 15:55:18 +00008523. Identifying and starting the Firmware Update process (if required).
853
8544. Loading the BL2 image from non-volatile storage into secure memory at the
Achin Gupta4f6ad662013-10-25 09:08:21 +0100855 address specified by the platform defined constant `BL2_BASE`.
856
Yatharth Kochar84a5d6d2015-10-27 15:55:18 +00008575. Populating a `meminfo` structure with the following information in memory,
Achin Gupta4f6ad662013-10-25 09:08:21 +0100858 accessible by BL2 immediately upon entry.
859
860 meminfo.total_base = Base address of secure RAM visible to BL2
861 meminfo.total_size = Size of secure RAM visible to BL2
862 meminfo.free_base = Base address of secure RAM available for
863 allocation to BL2
864 meminfo.free_size = Size of secure RAM available for allocation to BL2
865
866 BL1 places this `meminfo` structure at the beginning of the free memory
867 available for its use. Since BL1 cannot allocate memory dynamically at the
868 moment, its free memory will be available for BL2's use as-is. However, this
869 means that BL2 must read the `meminfo` structure before it starts using its
870 free memory (this is discussed in Section 3.2).
871
872 In future releases of the ARM Trusted Firmware it will be possible for
873 the platform to decide where it wants to place the `meminfo` structure for
874 BL2.
875
Sandrine Bailleux8f55dfb2014-06-24 14:02:34 +0100876 BL1 implements the `bl1_init_bl2_mem_layout()` function to populate the
Achin Gupta4f6ad662013-10-25 09:08:21 +0100877 BL2 `meminfo` structure. The platform may override this implementation, for
878 example if the platform wants to restrict the amount of memory visible to
879 BL2. Details of how to do this are given below.
880
881The following functions need to be implemented by the platform port to enable
882BL1 to perform the above tasks.
883
884
Dan Handley4a75b842015-03-19 19:24:43 +0000885### Function : bl1_early_platform_setup() [mandatory]
886
887 Argument : void
888 Return : void
889
890This function executes with the MMU and data caches disabled. It is only called
891by the primary CPU.
892
Sandrine Bailleuxeaefdec2016-01-26 15:00:40 +0000893On ARM standard platforms, this function:
894
895* Enables a secure instance of SP805 to act as the Trusted Watchdog.
896
897* Initializes a UART (PL011 console), which enables access to the `printf`
898 family of functions in BL1.
899
900* Enables issuing of snoop and DVM (Distributed Virtual Memory) requests to
901 the CCI slave interface corresponding to the cluster that includes the
902 primary CPU.
Dan Handley4a75b842015-03-19 19:24:43 +0000903
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100904### Function : bl1_plat_arch_setup() [mandatory]
Achin Gupta4f6ad662013-10-25 09:08:21 +0100905
906 Argument : void
907 Return : void
908
Achin Gupta4f6ad662013-10-25 09:08:21 +0100909This function performs any platform-specific and architectural setup that the
Dan Handley4a75b842015-03-19 19:24:43 +0000910platform requires. Platform-specific setup might include configuration of
911memory controllers and the interconnect.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100912
Dan Handley4a75b842015-03-19 19:24:43 +0000913In ARM standard platforms, this function enables the MMU.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100914
915This function helps fulfill requirement 2 above.
916
917
918### Function : bl1_platform_setup() [mandatory]
919
920 Argument : void
921 Return : void
922
923This function executes with the MMU and data caches enabled. It is responsible
924for performing any remaining platform-specific setup that can occur after the
925MMU and data cache have been enabled.
926
Dan Handley4a75b842015-03-19 19:24:43 +0000927In ARM standard platforms, this function initializes the storage abstraction
928layer used to load the next bootloader image.
Harry Liebeld265bd72014-01-31 19:04:10 +0000929
Yatharth Kochar84a5d6d2015-10-27 15:55:18 +0000930This function helps fulfill requirement 4 above.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100931
932
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000933### Function : bl1_plat_sec_mem_layout() [mandatory]
Achin Gupta4f6ad662013-10-25 09:08:21 +0100934
935 Argument : void
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000936 Return : meminfo *
Achin Gupta4f6ad662013-10-25 09:08:21 +0100937
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000938This function should only be called on the cold boot path. It executes with the
939MMU and data caches enabled. The pointer returned by this function must point to
940a `meminfo` structure containing the extents and availability of secure RAM for
941the BL1 stage.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100942
943 meminfo.total_base = Base address of secure RAM visible to BL1
944 meminfo.total_size = Size of secure RAM visible to BL1
945 meminfo.free_base = Base address of secure RAM available for allocation
946 to BL1
947 meminfo.free_size = Size of secure RAM available for allocation to BL1
948
949This information is used by BL1 to load the BL2 image in secure RAM. BL1 also
950populates a similar structure to tell BL2 the extents of memory available for
951its own use.
952
Yatharth Kochar84a5d6d2015-10-27 15:55:18 +0000953This function helps fulfill requirements 4 and 5 above.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100954
955
Sandrine Bailleux8f55dfb2014-06-24 14:02:34 +0100956### Function : bl1_init_bl2_mem_layout() [optional]
Achin Gupta4f6ad662013-10-25 09:08:21 +0100957
958 Argument : meminfo *, meminfo *, unsigned int, unsigned long
959 Return : void
960
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100961BL1 needs to tell the next stage the amount of secure RAM available
962for it to use. This information is populated in a `meminfo`
Achin Gupta4f6ad662013-10-25 09:08:21 +0100963structure.
964
965Depending upon where BL2 has been loaded in secure RAM (determined by
966`BL2_BASE`), BL1 calculates the amount of free memory available for BL2 to use.
967BL1 also ensures that its data sections resident in secure RAM are not visible
Dan Handley4a75b842015-03-19 19:24:43 +0000968to BL2. An illustration of how this is done in ARM standard platforms is given
969in the **Memory layout on ARM development platforms** section in the
970[Firmware Design].
Achin Gupta4f6ad662013-10-25 09:08:21 +0100971
972
Juan Castilloe3f67122015-10-05 16:59:38 +0100973### Function : bl1_plat_prepare_exit() [optional]
974
Sandrine Bailleux862b5dc2015-11-10 15:01:57 +0000975 Argument : entry_point_info_t *
Juan Castilloe3f67122015-10-05 16:59:38 +0100976 Return : void
977
Yatharth Kochar84a5d6d2015-10-27 15:55:18 +0000978This function is called prior to exiting BL1 in response to the
979`BL1_SMC_RUN_IMAGE` SMC request raised by BL2. It should be used to perform
980platform specific clean up or bookkeeping operations before transferring
981control to the next image. It receives the address of the `entry_point_info_t`
982structure passed from BL2. This function runs with MMU disabled.
983
984### Function : bl1_plat_set_ep_info() [optional]
985
986 Argument : unsigned int image_id, entry_point_info_t *ep_info
987 Return : void
988
989This function allows platforms to override `ep_info` for the given `image_id`.
990
991The default implementation just returns.
992
993### Function : bl1_plat_get_next_image_id() [optional]
994
995 Argument : void
996 Return : unsigned int
997
998This and the following function must be overridden to enable the FWU feature.
999
1000BL1 calls this function after platform setup to identify the next image to be
1001loaded and executed. If the platform returns `BL2_IMAGE_ID` then BL1 proceeds
1002with the normal boot sequence, which loads and executes BL2. If the platform
1003returns a different image id, BL1 assumes that Firmware Update is required.
1004
1005The default implementation always returns `BL2_IMAGE_ID`. The ARM development
1006platforms override this function to detect if firmware update is required, and
1007if so, return the first image in the firmware update process.
1008
1009### Function : bl1_plat_get_image_desc() [optional]
1010
1011 Argument : unsigned int image_id
1012 Return : image_desc_t *
1013
1014BL1 calls this function to get the image descriptor information `image_desc_t`
1015for the provided `image_id` from the platform.
1016
1017The default implementation always returns a common BL2 image descriptor. ARM
1018standard platforms return an image descriptor corresponding to BL2 or one of
1019the firmware update images defined in the Trusted Board Boot Requirements
1020specification.
1021
1022### Function : bl1_plat_fwu_done() [optional]
1023
1024 Argument : unsigned int image_id, uintptr_t image_src,
1025 unsigned int image_size
1026 Return : void
1027
1028BL1 calls this function when the FWU process is complete. It must not return.
1029The platform may override this function to take platform specific action, for
1030example to initiate the normal boot flow.
1031
1032The default implementation spins forever.
1033
1034### Function : bl1_plat_mem_check() [mandatory]
1035
1036 Argument : uintptr_t mem_base, unsigned int mem_size,
1037 unsigned int flags
1038 Return : void
1039
1040BL1 calls this function while handling FWU copy and authenticate SMCs. The
1041platform must ensure that the provided `mem_base` and `mem_size` are mapped into
1042BL1, and that this memory corresponds to either a secure or non-secure memory
1043region as indicated by the security state of the `flags` argument.
1044
1045The default implementation of this function asserts therefore platforms must
1046override it when using the FWU feature.
Juan Castilloe3f67122015-10-05 16:59:38 +01001047
1048
Achin Gupta4f6ad662013-10-25 09:08:21 +010010493.2 Boot Loader Stage 2 (BL2)
1050-----------------------------
1051
1052The BL2 stage is executed only by the primary CPU, which is determined in BL1
1053using the `platform_is_primary_cpu()` function. BL1 passed control to BL2 at
1054`BL2_BASE`. BL2 executes in Secure EL1 and is responsible for:
1055
Juan Castillof59821d2015-12-10 15:49:17 +000010561. (Optional) Loading the SCP_BL2 binary image (if present) from platform
1057 provided non-volatile storage. To load the SCP_BL2 image, BL2 makes use of
1058 the `meminfo` returned by the `bl2_plat_get_scp_bl2_meminfo()` function.
1059 The platform also defines the address in memory where SCP_BL2 is loaded
1060 through the optional constant `SCP_BL2_BASE`. BL2 uses this information
1061 to determine if there is enough memory to load the SCP_BL2 image.
1062 Subsequent handling of the SCP_BL2 image is platform-specific and is
1063 implemented in the `bl2_plat_handle_scp_bl2()` function.
1064 If `SCP_BL2_BASE` is not defined then this step is not performed.
Sandrine Bailleux93d81d62014-06-24 14:19:36 +01001065
Juan Castillod1786372015-12-14 09:35:25 +000010662. Loading the BL31 binary image into secure RAM from non-volatile storage. To
1067 load the BL31 image, BL2 makes use of the `meminfo` structure passed to it
Harry Liebeld265bd72014-01-31 19:04:10 +00001068 by BL1. This structure allows BL2 to calculate how much secure RAM is
1069 available for its use. The platform also defines the address in secure RAM
Juan Castillod1786372015-12-14 09:35:25 +00001070 where BL31 is loaded through the constant `BL31_BASE`. BL2 uses this
1071 information to determine if there is enough memory to load the BL31 image.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001072
Juan Castillod1786372015-12-14 09:35:25 +000010733. (Optional) Loading the BL32 binary image (if present) from platform
1074 provided non-volatile storage. To load the BL32 image, BL2 makes use of
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001075 the `meminfo` returned by the `bl2_plat_get_bl32_meminfo()` function.
Juan Castillod1786372015-12-14 09:35:25 +00001076 The platform also defines the address in memory where BL32 is loaded
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001077 through the optional constant `BL32_BASE`. BL2 uses this information
Juan Castillod1786372015-12-14 09:35:25 +00001078 to determine if there is enough memory to load the BL32 image.
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001079 If `BL32_BASE` is not defined then this and the next step is not performed.
Achin Guptaa3050ed2014-02-19 17:52:35 +00001080
Juan Castillod1786372015-12-14 09:35:25 +000010814. (Optional) Arranging to pass control to the BL32 image (if present) that
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001082 has been pre-loaded at `BL32_BASE`. BL2 populates an `entry_point_info`
Dan Handley1151c822014-04-15 11:38:38 +01001083 structure in memory provided by the platform with information about how
Juan Castillod1786372015-12-14 09:35:25 +00001084 BL31 should pass control to the BL32 image.
Achin Guptaa3050ed2014-02-19 17:52:35 +00001085
Antonio Nino Diazcf2c8a32016-02-15 14:53:10 +000010865. (Optional) Loading the normal world BL33 binary image (if not loaded by
1087 other means) into non-secure DRAM from platform storage and arranging for
1088 BL31 to pass control to this image. This address is determined using the
1089 `plat_get_ns_image_entrypoint()` function described below.
Sandrine Bailleux93d81d62014-06-24 14:19:36 +01001090
10916. BL2 populates an `entry_point_info` structure in memory provided by the
Juan Castillod1786372015-12-14 09:35:25 +00001092 platform with information about how BL31 should pass control to the
Sandrine Bailleux93d81d62014-06-24 14:19:36 +01001093 other BL images.
1094
Achin Gupta4f6ad662013-10-25 09:08:21 +01001095The following functions must be implemented by the platform port to enable BL2
1096to perform the above tasks.
1097
1098
1099### Function : bl2_early_platform_setup() [mandatory]
1100
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001101 Argument : meminfo *
Achin Gupta4f6ad662013-10-25 09:08:21 +01001102 Return : void
1103
1104This function executes with the MMU and data caches disabled. It is only called
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001105by the primary CPU. The arguments to this function is the address of the
1106`meminfo` structure populated by BL1.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001107
Sandrine Bailleuxeaefdec2016-01-26 15:00:40 +00001108The platform may copy the contents of the `meminfo` structure into a private
Achin Gupta4f6ad662013-10-25 09:08:21 +01001109variable as the original memory may be subsequently overwritten by BL2. The
1110copied structure is made available to all BL2 code through the
Achin Guptae4d084e2014-02-19 17:18:23 +00001111`bl2_plat_sec_mem_layout()` function.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001112
Sandrine Bailleuxeaefdec2016-01-26 15:00:40 +00001113On ARM standard platforms, this function also:
1114
1115* Initializes a UART (PL011 console), which enables access to the `printf`
1116 family of functions in BL2.
1117
1118* Initializes the storage abstraction layer used to load further bootloader
1119 images. It is necessary to do this early on platforms with a SCP_BL2 image,
1120 since the later `bl2_platform_setup` must be done after SCP_BL2 is loaded.
Dan Handley4a75b842015-03-19 19:24:43 +00001121
Achin Gupta4f6ad662013-10-25 09:08:21 +01001122
1123### Function : bl2_plat_arch_setup() [mandatory]
1124
1125 Argument : void
1126 Return : void
1127
1128This function executes with the MMU and data caches disabled. It is only called
1129by the primary CPU.
1130
1131The purpose of this function is to perform any architectural initialization
Sandrine Bailleuxeaefdec2016-01-26 15:00:40 +00001132that varies across platforms.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001133
Sandrine Bailleuxeaefdec2016-01-26 15:00:40 +00001134On ARM standard platforms, this function enables the MMU.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001135
1136### Function : bl2_platform_setup() [mandatory]
1137
1138 Argument : void
1139 Return : void
1140
1141This function may execute with the MMU and data caches enabled if the platform
1142port does the necessary initialization in `bl2_plat_arch_setup()`. It is only
1143called by the primary CPU.
1144
Achin Guptae4d084e2014-02-19 17:18:23 +00001145The purpose of this function is to perform any platform initialization
Dan Handley4a75b842015-03-19 19:24:43 +00001146specific to BL2.
Harry Liebelce19cf12014-04-01 19:28:07 +01001147
Dan Handley4a75b842015-03-19 19:24:43 +00001148In ARM standard platforms, this function performs security setup, including
1149configuration of the TrustZone controller to allow non-secure masters access
1150to most of DRAM. Part of DRAM is reserved for secure world use.
Harry Liebeld265bd72014-01-31 19:04:10 +00001151
Achin Gupta4f6ad662013-10-25 09:08:21 +01001152
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +00001153### Function : bl2_plat_sec_mem_layout() [mandatory]
Achin Gupta4f6ad662013-10-25 09:08:21 +01001154
1155 Argument : void
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +00001156 Return : meminfo *
Achin Gupta4f6ad662013-10-25 09:08:21 +01001157
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +00001158This function should only be called on the cold boot path. It may execute with
1159the MMU and data caches enabled if the platform port does the necessary
1160initialization in `bl2_plat_arch_setup()`. It is only called by the primary CPU.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001161
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +00001162The purpose of this function is to return a pointer to a `meminfo` structure
1163populated with the extents of secure RAM available for BL2 to use. See
Achin Gupta4f6ad662013-10-25 09:08:21 +01001164`bl2_early_platform_setup()` above.
1165
1166
Juan Castillof59821d2015-12-10 15:49:17 +00001167### Function : bl2_plat_get_scp_bl2_meminfo() [mandatory]
Sandrine Bailleux93d81d62014-06-24 14:19:36 +01001168
1169 Argument : meminfo *
1170 Return : void
1171
1172This function is used to get the memory limits where BL2 can load the
Juan Castillof59821d2015-12-10 15:49:17 +00001173SCP_BL2 image. The meminfo provided by this is used by load_image() to
1174validate whether the SCP_BL2 image can be loaded within the given
Sandrine Bailleux93d81d62014-06-24 14:19:36 +01001175memory from the given base.
1176
1177
Juan Castillof59821d2015-12-10 15:49:17 +00001178### Function : bl2_plat_handle_scp_bl2() [mandatory]
Sandrine Bailleux93d81d62014-06-24 14:19:36 +01001179
1180 Argument : image_info *
1181 Return : int
1182
Juan Castillof59821d2015-12-10 15:49:17 +00001183This function is called after loading SCP_BL2 image and it is used to perform
1184any platform-specific actions required to handle the SCP firmware. Typically it
Sandrine Bailleux93d81d62014-06-24 14:19:36 +01001185transfers the image into SCP memory using a platform-specific protocol and waits
1186until SCP executes it and signals to the Application Processor (AP) for BL2
1187execution to continue.
1188
1189This function returns 0 on success, a negative error code otherwise.
1190
1191
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001192### Function : bl2_plat_get_bl31_params() [mandatory]
Harry Liebeld265bd72014-01-31 19:04:10 +00001193
1194 Argument : void
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001195 Return : bl31_params *
Harry Liebeld265bd72014-01-31 19:04:10 +00001196
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001197BL2 platform code needs to return a pointer to a `bl31_params` structure it
Juan Castillod1786372015-12-14 09:35:25 +00001198will use for passing information to BL31. The `bl31_params` structure carries
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001199the following information.
1200 - Header describing the version information for interpreting the bl31_param
1201 structure
Juan Castillod1786372015-12-14 09:35:25 +00001202 - Information about executing the BL33 image in the `bl33_ep_info` field
1203 - Information about executing the BL32 image in the `bl32_ep_info` field
1204 - Information about the type and extents of BL31 image in the
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001205 `bl31_image_info` field
Juan Castillod1786372015-12-14 09:35:25 +00001206 - Information about the type and extents of BL32 image in the
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001207 `bl32_image_info` field
Juan Castillod1786372015-12-14 09:35:25 +00001208 - Information about the type and extents of BL33 image in the
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001209 `bl33_image_info` field
1210
1211The memory pointed by this structure and its sub-structures should be
Juan Castillod1786372015-12-14 09:35:25 +00001212accessible from BL31 initialisation code. BL31 might choose to copy the
1213necessary content, or maintain the structures until BL33 is initialised.
Harry Liebeld265bd72014-01-31 19:04:10 +00001214
1215
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001216### Funtion : bl2_plat_get_bl31_ep_info() [mandatory]
Achin Gupta4f6ad662013-10-25 09:08:21 +01001217
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001218 Argument : void
1219 Return : entry_point_info *
1220
1221BL2 platform code returns a pointer which is used to populate the entry point
Juan Castillod1786372015-12-14 09:35:25 +00001222information for BL31 entry point. The location pointed by it should be
1223accessible from BL1 while processing the synchronous exception to run to BL31.
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001224
Dan Handley4a75b842015-03-19 19:24:43 +00001225In ARM standard platforms this is allocated inside a bl2_to_bl31_params_mem
1226structure in BL2 memory.
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001227
1228
1229### Function : bl2_plat_set_bl31_ep_info() [mandatory]
1230
1231 Argument : image_info *, entry_point_info *
Achin Gupta4f6ad662013-10-25 09:08:21 +01001232 Return : void
1233
Juan Castillod1786372015-12-14 09:35:25 +00001234In the normal boot flow, this function is called after loading BL31 image and
Sandrine Bailleux4c117f62015-11-26 16:31:34 +00001235it can be used to overwrite the entry point set by loader and also set the
Juan Castillod1786372015-12-14 09:35:25 +00001236security state and SPSR which represents the entry point system state for BL31.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001237
Sandrine Bailleux4c117f62015-11-26 16:31:34 +00001238When booting an EL3 payload instead, this function is called after populating
1239its entry point address and can be used for the same purpose for the payload
1240image. It receives a null pointer as its first argument in this case.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001241
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001242### Function : bl2_plat_set_bl32_ep_info() [mandatory]
1243
1244 Argument : image_info *, entry_point_info *
1245 Return : void
1246
Juan Castillod1786372015-12-14 09:35:25 +00001247This function is called after loading BL32 image and it can be used to
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001248overwrite the entry point set by loader and also set the security state
Juan Castillod1786372015-12-14 09:35:25 +00001249and SPSR which represents the entry point system state for BL32.
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001250
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001251
1252### Function : bl2_plat_set_bl33_ep_info() [mandatory]
1253
1254 Argument : image_info *, entry_point_info *
1255 Return : void
1256
Juan Castillod1786372015-12-14 09:35:25 +00001257This function is called after loading BL33 image and it can be used to
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001258overwrite the entry point set by loader and also set the security state
Juan Castillod1786372015-12-14 09:35:25 +00001259and SPSR which represents the entry point system state for BL33.
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001260
Antonio Nino Diazcf2c8a32016-02-15 14:53:10 +00001261In the preloaded BL33 alternative boot flow, this function is called after
1262populating its entry point address. It is passed a null pointer as its first
1263argument in this case.
1264
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001265
1266### Function : bl2_plat_get_bl32_meminfo() [mandatory]
1267
1268 Argument : meminfo *
1269 Return : void
1270
1271This function is used to get the memory limits where BL2 can load the
Juan Castillod1786372015-12-14 09:35:25 +00001272BL32 image. The meminfo provided by this is used by load_image() to
1273validate whether the BL32 image can be loaded with in the given
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001274memory from the given base.
1275
1276### Function : bl2_plat_get_bl33_meminfo() [mandatory]
1277
1278 Argument : meminfo *
1279 Return : void
1280
1281This function is used to get the memory limits where BL2 can load the
Juan Castillod1786372015-12-14 09:35:25 +00001282BL33 image. The meminfo provided by this is used by load_image() to
1283validate whether the BL33 image can be loaded with in the given
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001284memory from the given base.
1285
Antonio Nino Diaz68450a62016-04-06 17:31:57 +01001286This function isn't needed if either `PRELOADED_BL33_BASE` or `EL3_PAYLOAD_BASE`
1287build options are used.
Antonio Nino Diazcf2c8a32016-02-15 14:53:10 +00001288
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001289### Function : bl2_plat_flush_bl31_params() [mandatory]
1290
1291 Argument : void
1292 Return : void
1293
1294Once BL2 has populated all the structures that needs to be read by BL1
Juan Castillod1786372015-12-14 09:35:25 +00001295and BL31 including the bl31_params structures and its sub-structures,
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001296the bl31_ep_info structure and any platform specific data. It flushes
1297all these data to the main memory so that it is available when we jump to
1298later Bootloader stages with MMU off
Achin Gupta4f6ad662013-10-25 09:08:21 +01001299
1300### Function : plat_get_ns_image_entrypoint() [mandatory]
1301
1302 Argument : void
Soby Mathewa0ad6012016-03-23 10:11:10 +00001303 Return : uintptr_t
Achin Gupta4f6ad662013-10-25 09:08:21 +01001304
1305As previously described, BL2 is responsible for arranging for control to be
Juan Castillod1786372015-12-14 09:35:25 +00001306passed to a normal world BL image through BL31. This function returns the
1307entrypoint of that image, which BL31 uses to jump to it.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001308
Juan Castillod1786372015-12-14 09:35:25 +00001309BL2 is responsible for loading the normal world BL33 image (e.g. UEFI).
Achin Gupta4f6ad662013-10-25 09:08:21 +01001310
Antonio Nino Diaz68450a62016-04-06 17:31:57 +01001311This function isn't needed if either `PRELOADED_BL33_BASE` or `EL3_PAYLOAD_BASE`
1312build options are used.
Antonio Nino Diazcf2c8a32016-02-15 14:53:10 +00001313
Achin Gupta4f6ad662013-10-25 09:08:21 +01001314
Yatharth Kochar84a5d6d2015-10-27 15:55:18 +000013153.3 FWU Boot Loader Stage 2 (BL2U)
1316----------------------------------
1317
1318The AP Firmware Updater Configuration, BL2U, is an optional part of the FWU
1319process and is executed only by the primary CPU. BL1 passes control to BL2U at
1320`BL2U_BASE`. BL2U executes in Secure-EL1 and is responsible for:
1321
13221. (Optional) Transfering the optional SCP_BL2U binary image from AP secure
1323 memory to SCP RAM. BL2U uses the SCP_BL2U `image_info` passed by BL1.
1324 `SCP_BL2U_BASE` defines the address in AP secure memory where SCP_BL2U
1325 should be copied from. Subsequent handling of the SCP_BL2U image is
1326 implemented by the platform specific `bl2u_plat_handle_scp_bl2u()` function.
1327 If `SCP_BL2U_BASE` is not defined then this step is not performed.
1328
13292. Any platform specific setup required to perform the FWU process. For
1330 example, ARM standard platforms initialize the TZC controller so that the
1331 normal world can access DDR memory.
1332
1333The following functions must be implemented by the platform port to enable
1334BL2U to perform the tasks mentioned above.
1335
1336### Function : bl2u_early_platform_setup() [mandatory]
1337
1338 Argument : meminfo *mem_info, void *plat_info
1339 Return : void
1340
1341This function executes with the MMU and data caches disabled. It is only
1342called by the primary CPU. The arguments to this function is the address
1343of the `meminfo` structure and platform specific info provided by BL1.
1344
Sandrine Bailleuxeaefdec2016-01-26 15:00:40 +00001345The platform may copy the contents of the `mem_info` and `plat_info` into
Yatharth Kochar84a5d6d2015-10-27 15:55:18 +00001346private storage as the original memory may be subsequently overwritten by BL2U.
1347
1348On ARM CSS platforms `plat_info` is interpreted as an `image_info_t` structure,
1349to extract SCP_BL2U image information, which is then copied into a private
1350variable.
1351
1352### Function : bl2u_plat_arch_setup() [mandatory]
1353
1354 Argument : void
1355 Return : void
1356
1357This function executes with the MMU and data caches disabled. It is only
1358called by the primary CPU.
1359
1360The purpose of this function is to perform any architectural initialization
1361that varies across platforms, for example enabling the MMU (since the memory
1362map differs across platforms).
1363
1364### Function : bl2u_platform_setup() [mandatory]
1365
1366 Argument : void
1367 Return : void
1368
1369This function may execute with the MMU and data caches enabled if the platform
1370port does the necessary initialization in `bl2u_plat_arch_setup()`. It is only
1371called by the primary CPU.
1372
1373The purpose of this function is to perform any platform initialization
1374specific to BL2U.
1375
1376In ARM standard platforms, this function performs security setup, including
1377configuration of the TrustZone controller to allow non-secure masters access
1378to most of DRAM. Part of DRAM is reserved for secure world use.
1379
1380### Function : bl2u_plat_handle_scp_bl2u() [optional]
1381
1382 Argument : void
1383 Return : int
1384
1385This function is used to perform any platform-specific actions required to
1386handle the SCP firmware. Typically it transfers the image into SCP memory using
1387a platform-specific protocol and waits until SCP executes it and signals to the
1388Application Processor (AP) for BL2U execution to continue.
1389
1390This function returns 0 on success, a negative error code otherwise.
1391This function is included if SCP_BL2U_BASE is defined.
1392
1393
13943.4 Boot Loader Stage 3-1 (BL31)
Achin Gupta4f6ad662013-10-25 09:08:21 +01001395---------------------------------
1396
Juan Castillod1786372015-12-14 09:35:25 +00001397During cold boot, the BL31 stage is executed only by the primary CPU. This is
Achin Gupta4f6ad662013-10-25 09:08:21 +01001398determined in BL1 using the `platform_is_primary_cpu()` function. BL1 passes
Juan Castillod1786372015-12-14 09:35:25 +00001399control to BL31 at `BL31_BASE`. During warm boot, BL31 is executed by all
1400CPUs. BL31 executes at EL3 and is responsible for:
Achin Gupta4f6ad662013-10-25 09:08:21 +01001401
14021. Re-initializing all architectural and platform state. Although BL1 performs
Juan Castillod1786372015-12-14 09:35:25 +00001403 some of this initialization, BL31 remains resident in EL3 and must ensure
Achin Gupta4f6ad662013-10-25 09:08:21 +01001404 that EL3 architectural and platform state is completely initialized. It
1405 should make no assumptions about the system state when it receives control.
1406
14072. Passing control to a normal world BL image, pre-loaded at a platform-
Juan Castillod1786372015-12-14 09:35:25 +00001408 specific address by BL2. BL31 uses the `entry_point_info` structure that BL2
Achin Gupta4f6ad662013-10-25 09:08:21 +01001409 populated in memory to do this.
1410
Juan Castillod1786372015-12-14 09:35:25 +000014113. Providing runtime firmware services. Currently, BL31 only implements a
Achin Gupta4f6ad662013-10-25 09:08:21 +01001412 subset of the Power State Coordination Interface (PSCI) API as a runtime
1413 service. See Section 3.3 below for details of porting the PSCI
1414 implementation.
1415
Juan Castillod1786372015-12-14 09:35:25 +000014164. Optionally passing control to the BL32 image, pre-loaded at a platform-
1417 specific address by BL2. BL31 exports a set of apis that allow runtime
Achin Gupta35ca3512014-02-19 17:58:33 +00001418 services to specify the security state in which the next image should be
Juan Castillod1786372015-12-14 09:35:25 +00001419 executed and run the corresponding image. BL31 uses the `entry_point_info`
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001420 structure populated by BL2 to do this.
1421
Juan Castillod1786372015-12-14 09:35:25 +00001422If BL31 is a reset vector, It also needs to handle the reset as specified in
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001423section 2.2 before the tasks described above.
Achin Gupta35ca3512014-02-19 17:58:33 +00001424
Juan Castillod1786372015-12-14 09:35:25 +00001425The following functions must be implemented by the platform port to enable BL31
Achin Gupta4f6ad662013-10-25 09:08:21 +01001426to perform the above tasks.
1427
1428
1429### Function : bl31_early_platform_setup() [mandatory]
1430
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001431 Argument : bl31_params *, void *
Achin Gupta4f6ad662013-10-25 09:08:21 +01001432 Return : void
1433
1434This function executes with the MMU and data caches disabled. It is only called
1435by the primary CPU. The arguments to this function are:
1436
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001437* The address of the `bl31_params` structure populated by BL2.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001438* An opaque pointer that the platform may use as needed.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001439
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001440The platform can copy the contents of the `bl31_params` structure and its
1441sub-structures into private variables if the original memory may be
Juan Castillod1786372015-12-14 09:35:25 +00001442subsequently overwritten by BL31 and similarly the `void *` pointing
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001443to the platform data also needs to be saved.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001444
Dan Handley4a75b842015-03-19 19:24:43 +00001445In ARM standard platforms, BL2 passes a pointer to a `bl31_params` structure
Juan Castillod1786372015-12-14 09:35:25 +00001446in BL2 memory. BL31 copies the information in this pointer to internal data
Sandrine Bailleuxeaefdec2016-01-26 15:00:40 +00001447structures. It also performs the following:
1448
1449* Initialize a UART (PL011 console), which enables access to the `printf`
1450 family of functions in BL31.
1451
1452* Enable issuing of snoop and DVM (Distributed Virtual Memory) requests to the
1453 CCI slave interface corresponding to the cluster that includes the primary
1454 CPU.
Dan Handley4a75b842015-03-19 19:24:43 +00001455
Achin Gupta4f6ad662013-10-25 09:08:21 +01001456
1457### Function : bl31_plat_arch_setup() [mandatory]
1458
1459 Argument : void
1460 Return : void
1461
1462This function executes with the MMU and data caches disabled. It is only called
1463by the primary CPU.
1464
1465The purpose of this function is to perform any architectural initialization
Sandrine Bailleuxeaefdec2016-01-26 15:00:40 +00001466that varies across platforms.
1467
1468On ARM standard platforms, this function enables the MMU.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001469
1470
1471### Function : bl31_platform_setup() [mandatory]
1472
1473 Argument : void
1474 Return : void
1475
1476This function may execute with the MMU and data caches enabled if the platform
1477port does the necessary initialization in `bl31_plat_arch_setup()`. It is only
1478called by the primary CPU.
1479
1480The purpose of this function is to complete platform initialization so that both
Juan Castillod1786372015-12-14 09:35:25 +00001481BL31 runtime services and normal world software can function correctly.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001482
Sandrine Bailleuxeaefdec2016-01-26 15:00:40 +00001483On ARM standard platforms, this function does the following:
1484
1485* Initialize the generic interrupt controller.
1486
1487 Depending on the GIC driver selected by the platform, the appropriate GICv2
1488 or GICv3 initialization will be done, which mainly consists of:
1489
1490 - Enable secure interrupts in the GIC CPU interface.
1491 - Disable the legacy interrupt bypass mechanism.
1492 - Configure the priority mask register to allow interrupts of all priorities
1493 to be signaled to the CPU interface.
1494 - Mark SGIs 8-15 and the other secure interrupts on the platform as secure.
1495 - Target all secure SPIs to CPU0.
1496 - Enable these secure interrupts in the GIC distributor.
1497 - Configure all other interrupts as non-secure.
1498 - Enable signaling of secure interrupts in the GIC distributor.
1499
1500* Enable system-level implementation of the generic timer counter through the
1501 memory mapped interface.
1502
1503* Grant access to the system counter timer module
1504
1505* Initialize the power controller device.
1506
1507 In particular, initialise the locks that prevent concurrent accesses to the
1508 power controller device.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001509
1510
Soby Mathew78e61612015-12-09 11:28:43 +00001511### Function : bl31_plat_runtime_setup() [optional]
1512
1513 Argument : void
1514 Return : void
1515
1516The purpose of this function is allow the platform to perform any BL31 runtime
1517setup just prior to BL31 exit during cold boot. The default weak
1518implementation of this function will invoke `console_uninit()` which will
1519suppress any BL31 runtime logs.
1520
Soby Mathew080225d2015-12-09 11:38:43 +00001521In ARM Standard platforms, this function will initialize the BL31 runtime
1522console which will cause all further BL31 logs to be output to the
1523runtime console.
1524
Soby Mathew78e61612015-12-09 11:28:43 +00001525
Achin Gupta4f6ad662013-10-25 09:08:21 +01001526### Function : bl31_get_next_image_info() [mandatory]
1527
Achin Gupta35ca3512014-02-19 17:58:33 +00001528 Argument : unsigned int
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001529 Return : entry_point_info *
Achin Gupta4f6ad662013-10-25 09:08:21 +01001530
1531This function may execute with the MMU and data caches enabled if the platform
1532port does the necessary initializations in `bl31_plat_arch_setup()`.
1533
1534This function is called by `bl31_main()` to retrieve information provided by
Juan Castillod1786372015-12-14 09:35:25 +00001535BL2 for the next image in the security state specified by the argument. BL31
Achin Gupta35ca3512014-02-19 17:58:33 +00001536uses this information to pass control to that image in the specified security
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001537state. This function must return a pointer to the `entry_point_info` structure
Achin Gupta35ca3512014-02-19 17:58:33 +00001538(that was copied during `bl31_early_platform_setup()`) if the image exists. It
1539should return NULL otherwise.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001540
Antonio Nino Diazd4486392016-05-18 16:53:31 +01001541### Function : plat_get_syscnt_freq2() [mandatory]
Dan Handley4a75b842015-03-19 19:24:43 +00001542
1543 Argument : void
Antonio Nino Diazd4486392016-05-18 16:53:31 +01001544 Return : unsigned int
Dan Handley4a75b842015-03-19 19:24:43 +00001545
1546This function is used by the architecture setup code to retrieve the counter
1547frequency for the CPU's generic timer. This value will be programmed into the
1548`CNTFRQ_EL0` register. In ARM standard platforms, it returns the base frequency
1549of the system counter, which is retrieved from the first entry in the frequency
1550modes table.
1551
Achin Gupta4f6ad662013-10-25 09:08:21 +01001552
Vikram Kanigiri7173f5f2015-09-24 15:45:43 +01001553### #define : PLAT_PERCPU_BAKERY_LOCK_SIZE [optional]
Andrew Thoelkeee7b35c2015-09-10 11:39:36 +01001554
Vikram Kanigiri7173f5f2015-09-24 15:45:43 +01001555 When `USE_COHERENT_MEM = 0`, this constant defines the total memory (in
1556 bytes) aligned to the cache line boundary that should be allocated per-cpu to
1557 accommodate all the bakery locks.
1558
1559 If this constant is not defined when `USE_COHERENT_MEM = 0`, the linker
1560 calculates the size of the `bakery_lock` input section, aligns it to the
1561 nearest `CACHE_WRITEBACK_GRANULE`, multiplies it with `PLATFORM_CORE_COUNT`
1562 and stores the result in a linker symbol. This constant prevents a platform
1563 from relying on the linker and provide a more efficient mechanism for
1564 accessing per-cpu bakery lock information.
1565
1566 If this constant is defined and its value is not equal to the value
1567 calculated by the linker then a link time assertion is raised. A compile time
1568 assertion is raised if the value of the constant is not aligned to the cache
1569 line boundary.
Andrew Thoelkeee7b35c2015-09-10 11:39:36 +01001570
Yatharth Kochar84a5d6d2015-10-27 15:55:18 +000015713.5 Power State Coordination Interface (in BL31)
Achin Gupta4f6ad662013-10-25 09:08:21 +01001572------------------------------------------------
1573
1574The ARM Trusted Firmware's implementation of the PSCI API is based around the
Soby Mathew58523c02015-06-08 12:32:50 +01001575concept of a _power domain_. A _power domain_ is a CPU or a logical group of
1576CPUs which share some state on which power management operations can be
1577performed as specified by [PSCI]. Each CPU in the system is assigned a cpu
1578index which is a unique number between `0` and `PLATFORM_CORE_COUNT - 1`.
Sandrine Bailleux1645d3e2015-12-17 13:58:58 +00001579The _power domains_ are arranged in a hierarchical tree structure and
Soby Mathew58523c02015-06-08 12:32:50 +01001580each _power domain_ can be identified in a system by the cpu index of any CPU
1581that is part of that domain and a _power domain level_. A processing element
1582(for example, a CPU) is at level 0. If the _power domain_ node above a CPU is
1583a logical grouping of CPUs that share some state, then level 1 is that group
1584of CPUs (for example, a cluster), and level 2 is a group of clusters
1585(for example, the system). More details on the power domain topology and its
1586organization can be found in [Power Domain Topology Design].
Achin Gupta4f6ad662013-10-25 09:08:21 +01001587
Juan Castillod1786372015-12-14 09:35:25 +00001588BL31's platform initialization code exports a pointer to the platform-specific
Achin Gupta4f6ad662013-10-25 09:08:21 +01001589power management operations required for the PSCI implementation to function
Soby Mathew58523c02015-06-08 12:32:50 +01001590correctly. This information is populated in the `plat_psci_ops` structure. The
1591PSCI implementation calls members of the `plat_psci_ops` structure for performing
1592power management operations on the power domains. For example, the target
1593CPU is specified by its `MPIDR` in a PSCI `CPU_ON` call. The `pwr_domain_on()`
1594handler (if present) is called for the CPU power domain.
1595
1596The `power-state` parameter of a PSCI `CPU_SUSPEND` call can be used to
1597describe composite power states specific to a platform. The PSCI implementation
1598defines a generic representation of the power-state parameter viz which is an
1599array of local power states where each index corresponds to a power domain
1600level. Each entry contains the local power state the power domain at that power
1601level could enter. It depends on the `validate_power_state()` handler to
1602convert the power-state parameter (possibly encoding a composite power state)
1603passed in a PSCI `CPU_SUSPEND` call to this representation.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001604
1605The following functions must be implemented to initialize PSCI functionality in
1606the ARM Trusted Firmware.
1607
1608
Soby Mathew58523c02015-06-08 12:32:50 +01001609### Function : plat_get_target_pwr_state() [optional]
Achin Gupta4f6ad662013-10-25 09:08:21 +01001610
Soby Mathew58523c02015-06-08 12:32:50 +01001611 Argument : unsigned int, const plat_local_state_t *, unsigned int
1612 Return : plat_local_state_t
Achin Gupta4f6ad662013-10-25 09:08:21 +01001613
Soby Mathew58523c02015-06-08 12:32:50 +01001614The PSCI generic code uses this function to let the platform participate in
1615state coordination during a power management operation. The function is passed
1616a pointer to an array of platform specific local power state `states` (second
1617argument) which contains the requested power state for each CPU at a particular
1618power domain level `lvl` (first argument) within the power domain. The function
1619is expected to traverse this array of upto `ncpus` (third argument) and return
1620a coordinated target power state by the comparing all the requested power
1621states. The target power state should not be deeper than any of the requested
1622power states.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001623
Soby Mathew58523c02015-06-08 12:32:50 +01001624A weak definition of this API is provided by default wherein it assumes
1625that the platform assigns a local state value in order of increasing depth
1626of the power state i.e. for two power states X & Y, if X < Y
1627then X represents a shallower power state than Y. As a result, the
1628coordinated target local power state for a power domain will be the minimum
1629of the requested local power state values.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001630
1631
Soby Mathew58523c02015-06-08 12:32:50 +01001632### Function : plat_get_power_domain_tree_desc() [mandatory]
Achin Gupta4f6ad662013-10-25 09:08:21 +01001633
Soby Mathew58523c02015-06-08 12:32:50 +01001634 Argument : void
1635 Return : const unsigned char *
Achin Gupta4f6ad662013-10-25 09:08:21 +01001636
Soby Mathew58523c02015-06-08 12:32:50 +01001637This function returns a pointer to the byte array containing the power domain
1638topology tree description. The format and method to construct this array are
Juan Castillod1786372015-12-14 09:35:25 +00001639described in [Power Domain Topology Design]. The BL31 PSCI initilization code
Soby Mathew58523c02015-06-08 12:32:50 +01001640requires this array to be described by the platform, either statically or
1641dynamically, to initialize the power domain topology tree. In case the array
1642is populated dynamically, then plat_core_pos_by_mpidr() and
1643plat_my_core_pos() should also be implemented suitably so that the topology
1644tree description matches the CPU indices returned by these APIs. These APIs
1645together form the platform interface for the PSCI topology framework.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001646
1647
Soby Mathew58523c02015-06-08 12:32:50 +01001648## Function : plat_setup_psci_ops() [mandatory]
Achin Gupta4f6ad662013-10-25 09:08:21 +01001649
Soby Mathew58523c02015-06-08 12:32:50 +01001650 Argument : uintptr_t, const plat_psci_ops **
Achin Gupta4f6ad662013-10-25 09:08:21 +01001651 Return : int
1652
1653This function may execute with the MMU and data caches enabled if the platform
1654port does the necessary initializations in `bl31_plat_arch_setup()`. It is only
1655called by the primary CPU.
1656
Soby Mathew58523c02015-06-08 12:32:50 +01001657This function is called by PSCI initialization code. Its purpose is to let
1658the platform layer know about the warm boot entrypoint through the
1659`sec_entrypoint` (first argument) and to export handler routines for
1660platform-specific psci power management actions by populating the passed
Juan Castillod1786372015-12-14 09:35:25 +00001661pointer with a pointer to BL31's private `plat_psci_ops` structure.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001662
1663A description of each member of this structure is given below. Please refer to
Dan Handley4a75b842015-03-19 19:24:43 +00001664the ARM FVP specific implementation of these handlers in
Soby Mathew58523c02015-06-08 12:32:50 +01001665[plat/arm/board/fvp/fvp_pm.c] as an example. For each PSCI function that the
1666platform wants to support, the associated operation or operations in this
1667structure must be provided and implemented (Refer section 4 of
1668[Firmware Design] for the PSCI API supported in Trusted Firmware). To disable
1669a PSCI function in a platform port, the operation should be removed from this
1670structure instead of providing an empty implementation.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001671
Soby Mathew58523c02015-06-08 12:32:50 +01001672#### plat_psci_ops.cpu_standby()
Achin Gupta4f6ad662013-10-25 09:08:21 +01001673
Soby Mathew58523c02015-06-08 12:32:50 +01001674Perform the platform-specific actions to enter the standby state for a cpu
1675indicated by the passed argument. This provides a fast path for CPU standby
1676wherein overheads of PSCI state management and lock acquistion is avoided.
1677For this handler to be invoked by the PSCI `CPU_SUSPEND` API implementation,
1678the suspend state type specified in the `power-state` parameter should be
1679STANDBY and the target power domain level specified should be the CPU. The
1680handler should put the CPU into a low power retention state (usually by
1681issuing a wfi instruction) and ensure that it can be woken up from that
1682state by a normal interrupt. The generic code expects the handler to succeed.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001683
Soby Mathew58523c02015-06-08 12:32:50 +01001684#### plat_psci_ops.pwr_domain_on()
Achin Gupta4f6ad662013-10-25 09:08:21 +01001685
Soby Mathew58523c02015-06-08 12:32:50 +01001686Perform the platform specific actions to power on a CPU, specified
1687by the `MPIDR` (first argument). The generic code expects the platform to
1688return PSCI_E_SUCCESS on success or PSCI_E_INTERN_FAIL for any failure.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001689
Soby Mathew58523c02015-06-08 12:32:50 +01001690#### plat_psci_ops.pwr_domain_off()
Achin Gupta4f6ad662013-10-25 09:08:21 +01001691
Soby Mathew58523c02015-06-08 12:32:50 +01001692Perform the platform specific actions to prepare to power off the calling CPU
1693and its higher parent power domain levels as indicated by the `target_state`
1694(first argument). It is called by the PSCI `CPU_OFF` API implementation.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001695
Soby Mathew58523c02015-06-08 12:32:50 +01001696The `target_state` encodes the platform coordinated target local power states
1697for the CPU power domain and its parent power domain levels. The handler
1698needs to perform power management operation corresponding to the local state
1699at each power level.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001700
Soby Mathew58523c02015-06-08 12:32:50 +01001701For this handler, the local power state for the CPU power domain will be a
1702power down state where as it could be either power down, retention or run state
1703for the higher power domain levels depending on the result of state
1704coordination. The generic code expects the handler to succeed.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001705
Soby Mathew58523c02015-06-08 12:32:50 +01001706#### plat_psci_ops.pwr_domain_suspend()
Achin Gupta4f6ad662013-10-25 09:08:21 +01001707
Soby Mathew58523c02015-06-08 12:32:50 +01001708Perform the platform specific actions to prepare to suspend the calling
1709CPU and its higher parent power domain levels as indicated by the
1710`target_state` (first argument). It is called by the PSCI `CPU_SUSPEND`
1711API implementation.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001712
Soby Mathew58523c02015-06-08 12:32:50 +01001713The `target_state` has a similar meaning as described in
1714the `pwr_domain_off()` operation. It encodes the platform coordinated
1715target local power states for the CPU power domain and its parent
1716power domain levels. The handler needs to perform power management operation
1717corresponding to the local state at each power level. The generic code
1718expects the handler to succeed.
1719
1720The difference between turning a power domain off versus suspending it
1721is that in the former case, the power domain is expected to re-initialize
1722its state when it is next powered on (see `pwr_domain_on_finish()`). In the
1723latter case, the power domain is expected to save enough state so that it can
Achin Gupta4f6ad662013-10-25 09:08:21 +01001724resume execution by restoring this state when its powered on (see
Soby Mathew58523c02015-06-08 12:32:50 +01001725`pwr_domain_suspend_finish()`).
Achin Gupta4f6ad662013-10-25 09:08:21 +01001726
Soby Mathewac1cc8e2016-04-27 14:46:28 +01001727#### plat_psci_ops.pwr_domain_pwr_down_wfi()
1728
1729This is an optional function and, if implemented, is expected to perform
1730platform specific actions including the `wfi` invocation which allows the
1731CPU to powerdown. Since this function is invoked outside the PSCI locks,
1732the actions performed in this hook must be local to the CPU or the platform
1733must ensure that races between multiple CPUs cannot occur.
1734
1735The `target_state` has a similar meaning as described in the `pwr_domain_off()`
1736operation and it encodes the platform coordinated target local power states for
1737the CPU power domain and its parent power domain levels. This function must
1738not return back to the caller.
1739
1740If this function is not implemented by the platform, PSCI generic
1741implementation invokes `psci_power_down_wfi()` for power down.
1742
Soby Mathew58523c02015-06-08 12:32:50 +01001743#### plat_psci_ops.pwr_domain_on_finish()
Achin Gupta4f6ad662013-10-25 09:08:21 +01001744
1745This function is called by the PSCI implementation after the calling CPU is
1746powered on and released from reset in response to an earlier PSCI `CPU_ON` call.
1747It performs the platform-specific setup required to initialize enough state for
1748this CPU to enter the normal world and also provide secure runtime firmware
1749services.
1750
Soby Mathew58523c02015-06-08 12:32:50 +01001751The `target_state` (first argument) is the prior state of the power domains
1752immediately before the CPU was turned on. It indicates which power domains
1753above the CPU might require initialization due to having previously been in
1754low power states. The generic code expects the handler to succeed.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001755
Soby Mathew58523c02015-06-08 12:32:50 +01001756#### plat_psci_ops.pwr_domain_suspend_finish()
Achin Gupta4f6ad662013-10-25 09:08:21 +01001757
1758This function is called by the PSCI implementation after the calling CPU is
1759powered on and released from reset in response to an asynchronous wakeup
1760event, for example a timer interrupt that was programmed by the CPU during the
Soby Mathewc0aff0e2014-12-17 14:47:57 +00001761`CPU_SUSPEND` call or `SYSTEM_SUSPEND` call. It performs the platform-specific
1762setup required to restore the saved state for this CPU to resume execution
1763in the normal world and also provide secure runtime firmware services.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001764
Soby Mathew58523c02015-06-08 12:32:50 +01001765The `target_state` (first argument) has a similar meaning as described in
1766the `pwr_domain_on_finish()` operation. The generic code expects the platform
1767to succeed.
Soby Mathew539dced2014-10-02 16:56:51 +01001768
Soby Mathew58523c02015-06-08 12:32:50 +01001769#### plat_psci_ops.validate_power_state()
Soby Mathew539dced2014-10-02 16:56:51 +01001770
1771This function is called by the PSCI implementation during the `CPU_SUSPEND`
Soby Mathew58523c02015-06-08 12:32:50 +01001772call to validate the `power_state` parameter of the PSCI API and if valid,
1773populate it in `req_state` (second argument) array as power domain level
1774specific local states. If the `power_state` is invalid, the platform must
1775return PSCI_E_INVALID_PARAMS as error, which is propagated back to the
1776normal world PSCI client.
Soby Mathew539dced2014-10-02 16:56:51 +01001777
Soby Mathew58523c02015-06-08 12:32:50 +01001778#### plat_psci_ops.validate_ns_entrypoint()
Soby Mathew539dced2014-10-02 16:56:51 +01001779
Soby Mathewc0aff0e2014-12-17 14:47:57 +00001780This function is called by the PSCI implementation during the `CPU_SUSPEND`,
1781`SYSTEM_SUSPEND` and `CPU_ON` calls to validate the non-secure `entry_point`
Soby Mathew58523c02015-06-08 12:32:50 +01001782parameter passed by the normal world. If the `entry_point` is invalid,
1783the platform must return PSCI_E_INVALID_ADDRESS as error, which is
Soby Mathewc0aff0e2014-12-17 14:47:57 +00001784propagated back to the normal world PSCI client.
1785
Soby Mathew58523c02015-06-08 12:32:50 +01001786#### plat_psci_ops.get_sys_suspend_power_state()
Soby Mathewc0aff0e2014-12-17 14:47:57 +00001787
1788This function is called by the PSCI implementation during the `SYSTEM_SUSPEND`
Soby Mathew58523c02015-06-08 12:32:50 +01001789call to get the `req_state` parameter from platform which encodes the power
1790domain level specific local states to suspend to system affinity level. The
1791`req_state` will be utilized to do the PSCI state coordination and
1792`pwr_domain_suspend()` will be invoked with the coordinated target state to
1793enter system suspend.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001794
Achin Gupta4f6ad662013-10-25 09:08:21 +01001795
Yatharth Kochar84a5d6d2015-10-27 15:55:18 +000017963.6 Interrupt Management framework (in BL31)
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001797----------------------------------------------
Juan Castillod1786372015-12-14 09:35:25 +00001798BL31 implements an Interrupt Management Framework (IMF) to manage interrupts
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001799generated in either security state and targeted to EL1 or EL2 in the non-secure
1800state or EL3/S-EL1 in the secure state. The design of this framework is
1801described in the [IMF Design Guide]
1802
1803A platform should export the following APIs to support the IMF. The following
Dan Handley4a75b842015-03-19 19:24:43 +00001804text briefly describes each api and its implementation in ARM standard
1805platforms. The API implementation depends upon the type of interrupt controller
Soby Mathew81123e82015-11-23 14:01:21 +00001806present in the platform. ARM standard platform layer supports both [ARM Generic
1807Interrupt Controller version 2.0 (GICv2)][ARM GIC Architecture Specification 2.0]
1808and [3.0 (GICv3)][ARM GIC Architecture Specification 3.0]. Juno builds the ARM
1809Standard layer to use GICv2 and the FVP can be configured to use either GICv2 or
1810GICv3 depending on the build flag `FVP_USE_GIC_DRIVER` (See FVP platform
1811specific build options in [User Guide] for more details).
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001812
1813### Function : plat_interrupt_type_to_line() [mandatory]
1814
1815 Argument : uint32_t, uint32_t
1816 Return : uint32_t
1817
1818The ARM processor signals an interrupt exception either through the IRQ or FIQ
1819interrupt line. The specific line that is signaled depends on how the interrupt
1820controller (IC) reports different interrupt types from an execution context in
1821either security state. The IMF uses this API to determine which interrupt line
1822the platform IC uses to signal each type of interrupt supported by the framework
Soby Mathew81123e82015-11-23 14:01:21 +00001823from a given security state. This API must be invoked at EL3.
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001824
1825The first parameter will be one of the `INTR_TYPE_*` values (see [IMF Design
1826Guide]) indicating the target type of the interrupt, the second parameter is the
1827security state of the originating execution context. The return result is the
1828bit position in the `SCR_EL3` register of the respective interrupt trap: IRQ=1,
1829FIQ=2.
1830
Soby Mathew81123e82015-11-23 14:01:21 +00001831In the case of ARM standard platforms using GICv2, S-EL1 interrupts are
1832configured as FIQs and Non-secure interrupts as IRQs from either security
1833state.
1834
1835In the case of ARM standard platforms using GICv3, the interrupt line to be
1836configured depends on the security state of the execution context when the
1837interrupt is signalled and are as follows:
1838* The S-EL1 interrupts are signaled as IRQ in S-EL0/1 context and as FIQ in
1839 NS-EL0/1/2 context.
1840* The Non secure interrupts are signaled as FIQ in S-EL0/1 context and as IRQ
1841 in the NS-EL0/1/2 context.
1842* The EL3 interrupts are signaled as FIQ in both S-EL0/1 and NS-EL0/1/2
1843 context.
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001844
1845
1846### Function : plat_ic_get_pending_interrupt_type() [mandatory]
1847
1848 Argument : void
1849 Return : uint32_t
1850
1851This API returns the type of the highest priority pending interrupt at the
1852platform IC. The IMF uses the interrupt type to retrieve the corresponding
1853handler function. `INTR_TYPE_INVAL` is returned when there is no interrupt
1854pending. The valid interrupt types that can be returned are `INTR_TYPE_EL3`,
Soby Mathew81123e82015-11-23 14:01:21 +00001855`INTR_TYPE_S_EL1` and `INTR_TYPE_NS`. This API must be invoked at EL3.
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001856
Soby Mathew81123e82015-11-23 14:01:21 +00001857In the case of ARM standard platforms using GICv2, the _Highest Priority
1858Pending Interrupt Register_ (`GICC_HPPIR`) is read to determine the id of
1859the pending interrupt. The type of interrupt depends upon the id value as
1860follows.
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001861
18621. id < 1022 is reported as a S-EL1 interrupt
18632. id = 1022 is reported as a Non-secure interrupt.
18643. id = 1023 is reported as an invalid interrupt type.
1865
Soby Mathew81123e82015-11-23 14:01:21 +00001866In the case of ARM standard platforms using GICv3, the system register
1867`ICC_HPPIR0_EL1`, _Highest Priority Pending group 0 Interrupt Register_,
1868is read to determine the id of the pending interrupt. The type of interrupt
1869depends upon the id value as follows.
1870
18711. id = `PENDING_G1S_INTID` (1020) is reported as a S-EL1 interrupt
18722. id = `PENDING_G1NS_INTID` (1021) is reported as a Non-secure interrupt.
18733. id = `GIC_SPURIOUS_INTERRUPT` (1023) is reported as an invalid interrupt type.
18744. All other interrupt id's are reported as EL3 interrupt.
1875
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001876
1877### Function : plat_ic_get_pending_interrupt_id() [mandatory]
1878
1879 Argument : void
1880 Return : uint32_t
1881
1882This API returns the id of the highest priority pending interrupt at the
Sandrine Bailleux1645d3e2015-12-17 13:58:58 +00001883platform IC. `INTR_ID_UNAVAILABLE` is returned when there is no interrupt
Soby Mathew54718412015-10-27 10:01:06 +00001884pending.
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001885
Soby Mathew81123e82015-11-23 14:01:21 +00001886In the case of ARM standard platforms using GICv2, the _Highest Priority
1887Pending Interrupt Register_ (`GICC_HPPIR`) is read to determine the id of the
1888pending interrupt. The id that is returned by API depends upon the value of
1889the id read from the interrupt controller as follows.
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001890
18911. id < 1022. id is returned as is.
18922. id = 1022. The _Aliased Highest Priority Pending Interrupt Register_
Soby Mathew81123e82015-11-23 14:01:21 +00001893 (`GICC_AHPPIR`) is read to determine the id of the non-secure interrupt.
1894 This id is returned by the API.
Achin Guptaa4fa3cb2014-06-02 22:27:36 +010018953. id = 1023. `INTR_ID_UNAVAILABLE` is returned.
1896
Soby Mathew81123e82015-11-23 14:01:21 +00001897In the case of ARM standard platforms using GICv3, if the API is invoked from
1898EL3, the system register `ICC_HPPIR0_EL1`, _Highest Priority Pending Interrupt
1899group 0 Register_, is read to determine the id of the pending interrupt. The id
1900that is returned by API depends upon the value of the id read from the
1901interrupt controller as follows.
1902
19031. id < `PENDING_G1S_INTID` (1020). id is returned as is.
19042. id = `PENDING_G1S_INTID` (1020) or `PENDING_G1NS_INTID` (1021). The system
1905 register `ICC_HPPIR1_EL1`, _Highest Priority Pending Interrupt group 1
1906 Register_ is read to determine the id of the group 1 interrupt. This id
1907 is returned by the API as long as it is a valid interrupt id
19083. If the id is any of the special interrupt identifiers,
1909 `INTR_ID_UNAVAILABLE` is returned.
1910
1911When the API invoked from S-EL1 for GICv3 systems, the id read from system
1912register `ICC_HPPIR1_EL1`, _Highest Priority Pending group 1 Interrupt
1913Register_, is returned if is not equal to GIC_SPURIOUS_INTERRUPT (1023) else
1914`INTR_ID_UNAVAILABLE` is returned.
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001915
1916### Function : plat_ic_acknowledge_interrupt() [mandatory]
1917
1918 Argument : void
1919 Return : uint32_t
1920
1921This API is used by the CPU to indicate to the platform IC that processing of
1922the highest pending interrupt has begun. It should return the id of the
1923interrupt which is being processed.
1924
Soby Mathew81123e82015-11-23 14:01:21 +00001925This function in ARM standard platforms using GICv2, reads the _Interrupt
1926Acknowledge Register_ (`GICC_IAR`). This changes the state of the highest
1927priority pending interrupt from pending to active in the interrupt controller.
1928It returns the value read from the `GICC_IAR`. This value is the id of the
1929interrupt whose state has been changed.
1930
1931In the case of ARM standard platforms using GICv3, if the API is invoked
1932from EL3, the function reads the system register `ICC_IAR0_EL1`, _Interrupt
1933Acknowledge Register group 0_. If the API is invoked from S-EL1, the function
1934reads the system register `ICC_IAR1_EL1`, _Interrupt Acknowledge Register
1935group 1_. The read changes the state of the highest pending interrupt from
1936pending to active in the interrupt controller. The value read is returned
1937and is the id of the interrupt whose state has been changed.
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001938
1939The TSP uses this API to start processing of the secure physical timer
1940interrupt.
1941
1942
1943### Function : plat_ic_end_of_interrupt() [mandatory]
1944
1945 Argument : uint32_t
1946 Return : void
1947
1948This API is used by the CPU to indicate to the platform IC that processing of
1949the interrupt corresponding to the id (passed as the parameter) has
1950finished. The id should be the same as the id returned by the
1951`plat_ic_acknowledge_interrupt()` API.
1952
Dan Handley4a75b842015-03-19 19:24:43 +00001953ARM standard platforms write the id to the _End of Interrupt Register_
Soby Mathew81123e82015-11-23 14:01:21 +00001954(`GICC_EOIR`) in case of GICv2, and to `ICC_EOIR0_EL1` or `ICC_EOIR1_EL1`
1955system register in case of GICv3 depending on where the API is invoked from,
1956EL3 or S-EL1. This deactivates the corresponding interrupt in the interrupt
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001957controller.
1958
1959The TSP uses this API to finish processing of the secure physical timer
1960interrupt.
1961
1962
1963### Function : plat_ic_get_interrupt_type() [mandatory]
1964
1965 Argument : uint32_t
1966 Return : uint32_t
1967
1968This API returns the type of the interrupt id passed as the parameter.
1969`INTR_TYPE_INVAL` is returned if the id is invalid. If the id is valid, a valid
1970interrupt type (one of `INTR_TYPE_EL3`, `INTR_TYPE_S_EL1` and `INTR_TYPE_NS`) is
1971returned depending upon how the interrupt has been configured by the platform
Soby Mathew81123e82015-11-23 14:01:21 +00001972IC. This API must be invoked at EL3.
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001973
Soby Mathew81123e82015-11-23 14:01:21 +00001974ARM standard platforms using GICv2 configures S-EL1 interrupts as Group0 interrupts
1975and Non-secure interrupts as Group1 interrupts. It reads the group value
1976corresponding to the interrupt id from the relevant _Interrupt Group Register_
1977(`GICD_IGROUPRn`). It uses the group value to determine the type of interrupt.
1978
1979In the case of ARM standard platforms using GICv3, both the _Interrupt Group
1980Register_ (`GICD_IGROUPRn`) and _Interrupt Group Modifier Register_
1981(`GICD_IGRPMODRn`) is read to figure out whether the interrupt is configured
1982as Group 0 secure interrupt, Group 1 secure interrupt or Group 1 NS interrupt.
Dan Handley4a75b842015-03-19 19:24:43 +00001983
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001984
Yatharth Kochar84a5d6d2015-10-27 15:55:18 +000019853.7 Crash Reporting mechanism (in BL31)
Soby Mathewc67b09b2014-07-14 16:57:23 +01001986----------------------------------------------
Juan Castillod1786372015-12-14 09:35:25 +00001987BL31 implements a crash reporting mechanism which prints the various registers
Sandrine Bailleux44804252014-08-06 11:27:23 +01001988of the CPU to enable quick crash analysis and debugging. It requires that a
1989console is designated as the crash console by the platform which will be used to
1990print the register dump.
Soby Mathewc67b09b2014-07-14 16:57:23 +01001991
Sandrine Bailleux44804252014-08-06 11:27:23 +01001992The following functions must be implemented by the platform if it wants crash
Juan Castillod1786372015-12-14 09:35:25 +00001993reporting mechanism in BL31. The functions are implemented in assembly so that
Sandrine Bailleux44804252014-08-06 11:27:23 +01001994they can be invoked without a C Runtime stack.
Soby Mathewc67b09b2014-07-14 16:57:23 +01001995
1996### Function : plat_crash_console_init
1997
1998 Argument : void
1999 Return : int
2000
Sandrine Bailleux44804252014-08-06 11:27:23 +01002001This API is used by the crash reporting mechanism to initialize the crash
Juan Castillo9400b402015-11-26 14:52:15 +00002002console. It must only use the general purpose registers x0 to x4 to do the
Sandrine Bailleux44804252014-08-06 11:27:23 +01002003initialization and returns 1 on success.
Soby Mathewc67b09b2014-07-14 16:57:23 +01002004
Soby Mathewc67b09b2014-07-14 16:57:23 +01002005### Function : plat_crash_console_putc
2006
2007 Argument : int
2008 Return : int
2009
2010This API is used by the crash reporting mechanism to print a character on the
Juan Castillo9400b402015-11-26 14:52:15 +00002011designated crash console. It must only use general purpose registers x1 and
Soby Mathewc67b09b2014-07-14 16:57:23 +01002012x2 to do its work. The parameter and the return value are in general purpose
2013register x0.
2014
Soby Mathew27713fb2014-09-08 17:51:01 +010020154. Build flags
2016---------------
2017
Soby Mathew58523c02015-06-08 12:32:50 +01002018* **ENABLE_PLAT_COMPAT**
2019 All the platforms ports conforming to this API specification should define
2020 the build flag `ENABLE_PLAT_COMPAT` to 0 as the compatibility layer should
2021 be disabled. For more details on compatibility layer, refer
2022 [Migration Guide].
2023
Soby Mathew27713fb2014-09-08 17:51:01 +01002024There are some build flags which can be defined by the platform to control
2025inclusion or exclusion of certain BL stages from the FIP image. These flags
2026need to be defined in the platform makefile which will get included by the
2027build system.
2028
Soby Mathew27713fb2014-09-08 17:51:01 +01002029* **NEED_BL33**
2030 By default, this flag is defined `yes` by the build system and `BL33`
Antonio Nino Diazcf2c8a32016-02-15 14:53:10 +00002031 build option should be supplied as a build option. The platform has the
2032 option of excluding the BL33 image in the `fip` image by defining this flag
Antonio Nino Diaz68450a62016-04-06 17:31:57 +01002033 to `no`. If any of the options `EL3_PAYLOAD_BASE` or `PRELOADED_BL33_BASE`
2034 are used, this flag will be set to `no` automatically.
Soby Mathew27713fb2014-09-08 17:51:01 +01002035
20365. C Library
Harry Liebela960f282013-12-12 16:03:44 +00002037-------------
2038
2039To avoid subtle toolchain behavioral dependencies, the header files provided
2040by the compiler are not used. The software is built with the `-nostdinc` flag
2041to ensure no headers are included from the toolchain inadvertently. Instead the
2042required headers are included in the ARM Trusted Firmware source tree. The
2043library only contains those C library definitions required by the local
2044implementation. If more functionality is required, the needed library functions
2045will need to be added to the local implementation.
2046
2047Versions of [FreeBSD] headers can be found in `include/stdlib`. Some of these
2048headers have been cut down in order to simplify the implementation. In order to
2049minimize changes to the header files, the [FreeBSD] layout has been maintained.
2050The generic C library definitions can be found in `include/stdlib` with more
2051system and machine specific declarations in `include/stdlib/sys` and
2052`include/stdlib/machine`.
2053
2054The local C library implementations can be found in `lib/stdlib`. In order to
2055extend the C library these files may need to be modified. It is recommended to
2056use a release version of [FreeBSD] as a starting point.
2057
2058The C library header files in the [FreeBSD] source tree are located in the
2059`include` and `sys/sys` directories. [FreeBSD] machine specific definitions
2060can be found in the `sys/<machine-type>` directories. These files define things
2061like 'the size of a pointer' and 'the range of an integer'. Since an AArch64
2062port for [FreeBSD] does not yet exist, the machine specific definitions are
2063based on existing machine types with similar properties (for example SPARC64).
2064
2065Where possible, C library function implementations were taken from [FreeBSD]
2066as found in the `lib/libc` directory.
2067
2068A copy of the [FreeBSD] sources can be downloaded with `git`.
2069
2070 git clone git://github.com/freebsd/freebsd.git -b origin/release/9.2.0
2071
2072
Soby Mathew27713fb2014-09-08 17:51:01 +010020736. Storage abstraction layer
Harry Liebeld265bd72014-01-31 19:04:10 +00002074-----------------------------
2075
2076In order to improve platform independence and portability an storage abstraction
2077layer is used to load data from non-volatile platform storage.
2078
2079Each platform should register devices and their drivers via the Storage layer.
2080These drivers then need to be initialized by bootloader phases as
2081required in their respective `blx_platform_setup()` functions. Currently
2082storage access is only required by BL1 and BL2 phases. The `load_image()`
2083function uses the storage layer to access non-volatile platform storage.
2084
Dan Handley4a75b842015-03-19 19:24:43 +00002085It is mandatory to implement at least one storage driver. For the ARM
2086development platforms the Firmware Image Package (FIP) driver is provided as
2087the default means to load data from storage (see the "Firmware Image Package"
2088section in the [User Guide]). The storage layer is described in the header file
2089`include/drivers/io/io_storage.h`. The implementation of the common library
Sandrine Bailleux121f2ae2015-01-28 10:11:48 +00002090is in `drivers/io/io_storage.c` and the driver files are located in
2091`drivers/io/`.
Harry Liebeld265bd72014-01-31 19:04:10 +00002092
2093Each IO driver must provide `io_dev_*` structures, as described in
2094`drivers/io/io_driver.h`. These are returned via a mandatory registration
2095function that is called on platform initialization. The semi-hosting driver
2096implementation in `io_semihosting.c` can be used as an example.
2097
2098The Storage layer provides mechanisms to initialize storage devices before
2099IO operations are called. The basic operations supported by the layer
2100include `open()`, `close()`, `read()`, `write()`, `size()` and `seek()`.
2101Drivers do not have to implement all operations, but each platform must
2102provide at least one driver for a device capable of supporting generic
2103operations such as loading a bootloader image.
2104
2105The current implementation only allows for known images to be loaded by the
Juan Castillo16948ae2015-04-13 17:36:19 +01002106firmware. These images are specified by using their identifiers, as defined in
2107[include/plat/common/platform_def.h] (or a separate header file included from
2108there). The platform layer (`plat_get_image_source()`) then returns a reference
2109to a device and a driver-specific `spec` which will be understood by the driver
2110to allow access to the image data.
Harry Liebeld265bd72014-01-31 19:04:10 +00002111
2112The layer is designed in such a way that is it possible to chain drivers with
2113other drivers. For example, file-system drivers may be implemented on top of
2114physical block devices, both represented by IO devices with corresponding
2115drivers. In such a case, the file-system "binding" with the block device may
2116be deferred until the file-system device is initialised.
2117
2118The abstraction currently depends on structures being statically allocated
2119by the drivers and callers, as the system does not yet provide a means of
2120dynamically allocating memory. This may also have the affect of limiting the
2121amount of open resources per driver.
2122
2123
Achin Gupta4f6ad662013-10-25 09:08:21 +01002124- - - - - - - - - - - - - - - - - - - - - - - - - -
2125
Sandrine Bailleuxeaefdec2016-01-26 15:00:40 +00002126_Copyright (c) 2013-2016, ARM Limited and Contributors. All rights reserved._
Achin Gupta4f6ad662013-10-25 09:08:21 +01002127
2128
Yuping Luo6b140412016-01-15 11:17:27 +08002129[ARM GIC Architecture Specification 2.0]: http://infocenter.arm.com/help/topic/com.arm.doc.ihi0048b/index.html
2130[ARM GIC Architecture Specification 3.0]: http://infocenter.arm.com/help/topic/com.arm.doc.ihi0069b/index.html
Soby Mathew81123e82015-11-23 14:01:21 +00002131[IMF Design Guide]: interrupt-framework-design.md
2132[User Guide]: user-guide.md
2133[FreeBSD]: http://www.freebsd.org
2134[Firmware Design]: firmware-design.md
2135[Power Domain Topology Design]: psci-pd-tree.md
2136[PSCI]: http://infocenter.arm.com/help/topic/com.arm.doc.den0022c/DEN0022C_Power_State_Coordination_Interface.pdf
2137[Migration Guide]: platform-migration-guide.md
Yatharth Kochar84a5d6d2015-10-27 15:55:18 +00002138[Firmware Update]: firmware-update.md
Achin Gupta4f6ad662013-10-25 09:08:21 +01002139
Andrew Thoelke2bf28e62014-03-20 10:48:23 +00002140[plat/common/aarch64/platform_mp_stack.S]: ../plat/common/aarch64/platform_mp_stack.S
2141[plat/common/aarch64/platform_up_stack.S]: ../plat/common/aarch64/platform_up_stack.S
Dan Handley4a75b842015-03-19 19:24:43 +00002142[plat/arm/board/fvp/fvp_pm.c]: ../plat/arm/board/fvp/fvp_pm.c
Yatharth Kochar84a5d6d2015-10-27 15:55:18 +00002143[include/common/bl_common.h]: ../include/common/bl_common.h
Dan Handley4a75b842015-03-19 19:24:43 +00002144[include/plat/arm/common/arm_def.h]: ../include/plat/arm/common/arm_def.h
2145[include/plat/common/common_def.h]: ../include/plat/common/common_def.h
Dan Handleyb68954c2014-05-29 12:30:24 +01002146[include/plat/common/platform.h]: ../include/plat/common/platform.h
Dan Handley4a75b842015-03-19 19:24:43 +00002147[include/plat/arm/common/plat_arm.h]: ../include/plat/arm/common/plat_arm.h]