blob: 59d9dbad50b4b18f19312c28b4a343d9991a57c6 [file] [log] [blame]
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +02001Trusted Firmware-A Tests - Porting Guide
2========================================
3
4.. section-numbering::
5 :suffix: .
6
7.. contents::
8
9--------------
10
11Introduction
12------------
13
14Please note that this document is incomplete.
15
16Porting the TF-A Tests to a new platform involves making some mandatory and
17optional modifications for both the cold and warm boot paths. Modifications
18consist of:
19
20* Implementing a platform-specific function or variable,
21* Setting up the execution context in a certain way, or
22* Defining certain constants (for example #defines).
23
24The platform-specific functions and variables are all declared in
25``include/plat/common/platform.h``. The framework provides a default
26implementation of variables and functions to fulfill the optional requirements.
27These implementations are all weakly defined; they are provided to ease the
28porting effort. Each platform port can override them with its own implementation
29if the default implementation is inadequate.
30
31Platform requirements
32---------------------
33
34The TF-A Tests rely on the following features to be present on the platform and
35accessible from Normal World.
36
37- Watchdog
38- Non-Volatile Memory
39- System Timer
40
41This also means that a platform port of the TF-A Tests must include software
42drivers for those features.
43
44Mandatory modifications
45-----------------------
46
47File : platform_def.h [mandatory]
48`````````````````````````````````
49
50Each platform must ensure that a header file of this name is in the system
51include path with the following constants defined. This may require updating the
52list of ``PLAT_INCLUDES`` in the ``platform.mk`` file. In the ARM FVP port, this
53file is found in ``plat/arm/board/fvp/include/platform_def.h``.
54
55- **#define : PLATFORM_LINKER_FORMAT**
56
57 Defines the linker format used by the platform, for example
58 `elf64-littleaarch64` used by the FVP.
59
60- **#define : PLATFORM_LINKER_ARCH**
61
62 Defines the processor architecture for the linker by the platform, for
63 example `aarch64` used by the FVP.
64
65- **#define : PLATFORM_STACK_SIZE**
66
67 Defines the stack memory available to each CPU. This constant is used by
68 ``plat/common/aarch64/platform_mp_stack.S``.
69
70- **#define : PLATFORM_CLUSTER_COUNT**
71
72 Defines the total number of clusters implemented by the platform in the
73 system.
74
75- **#define : PLATFORM_CORE_COUNT**
76
77 Defines the total number of CPUs implemented by the platform across all
78 clusters in the system.
79
80- **#define : PLATFORM_NUM_AFFS**
81
82 Defines the total number of nodes in the affinity hierarchy at all affinity
83 levels used by the platform.
84
85- **#define : PLATFORM_MAX_AFFLVL**
86
87 Defines the maximum number of affinity levels in the system that the platform
88 implements. ARMv8-A has support for 4 affinity levels. It is likely that
89 hardware will implement fewer affinity levels. For example, the Base AEM FVP
90 implements two clusters with a configurable number of CPUs. It reports the
91 maximum affinity level as 1.
92
93- **#define : PLAT_MAX_SPI_OFFSET_ID**
94
95 Defines the offset of the last Shared Peripheral Interrupt supported by the
96 TF-A Tests on this platform. SPI numbers are mapped onto GIC interrupt IDs,
97 starting from interrupt ID 32. In other words, this offset ID corresponds to
98 the last SPI number, to which 32 must be added to get the corresponding last
99 GIC IRQ ID.
100
101 E.g. If ``PLAT_MAX_SPI_OFFSET_ID`` is 10, this means that IRQ #42 is the last
102 SPI.
103
104- **#define : PLAT_LOCAL_PSTATE_WIDTH**
105
106 Defines the bit-field width of the local state in State-ID field of the
107 power-state parameter. This macro will be used to compose the State-ID field
108 given the local power state at different affinity levels.
109
110- **#define : PLAT_MAX_PWR_STATES_PER_LVL**
111
112 Defines the maximum number of power states at a power domain level for the
113 platform. This macro will be used by the ``PSCI_STAT_COUNT/RESIDENCY`` tests
114 to determine the size of the array to allocate for storing the statistics.
115
116- **#define : TFTF_BASE**
117
118 Defines the base address of the TFTF binary in DRAM. Used by the linker
119 script to link the image at the right address. Must be aligned on a page-size
120 boundary.
121
122- **#define : IRQ_PCPU_NS_TIMER**
123
124 Defines the IRQ ID of the per-CPU Non-Secure timer of the platform.
125
126- **#define : IRQ_CNTPSIRQ1**
127
128 Defines the IRQ ID of the System timer of the platform.
129
130- **#define : TFTF_NVM_OFFSET**
131
132 The TFTF needs some Non-Volatile Memory to store persistent data. This
133 defines the offset from the beginning of this memory that the TFTF can use.
134
135- **#define : TFTF_NVM_SIZE**
136
137 Defines the size of the Non-Volatile Memory allocated for TFTF usage.
138
139If the platform port uses the ARM Watchdog Module (`SP805`_) peripheral, the
140following constant needs to be defined:
141
142- **#define : SP805_WDOG_BASE**
143
144 Defines the base address of the `SP805`_ watchdog peripheral.
145
146If the platform port uses the IO storage framework, the following constants
147must also be defined:
148
149- **#define : MAX_IO_DEVICES**
150
151 Defines the maximum number of registered IO devices. Attempting to register
152 more devices than this value using ``io_register_device()`` will fail with
153 ``IO_RESOURCES_EXHAUSTED``.
154
155- **#define : MAX_IO_HANDLES**
156
157 Defines the maximum number of open IO handles. Attempting to open more IO
158 entities than this value using ``io_open()`` will fail with
159 ``IO_RESOURCES_EXHAUSTED``.
160
161If the platform port uses the VExpress NOR flash driver (see
162``drivers/io/vexpress_nor/``), the following constants must also be defined:
163
164- **#define : NOR_FLASH_BLOCK_SIZE**
165
166 Defines the largest block size as seen by the software while writing to NOR
167 flash.
168
169Function : tftf_plat_arch_setup() [mandatory]
170`````````````````````````````````````````````
171::
172
173 Argument : void
174 Return : void
175
176This function performs any platform-specific and architectural setup that the
177platform requires.
178
179In both the ARM FVP and Juno ports, this function configures and enables the
180MMU.
181
182Function : tftf_early_platform_setup() [mandatory]
183``````````````````````````````````````````````````
184
185::
186
187 Argument : void
188 Return : void
189
190This function executes with the MMU and data caches disabled. It is only called
191by the primary CPU. It is used to perform platform-specific actions very early
192in the boot.
193
194In both the ARM FVP and Juno ports, this function configures the console.
195
196Function : tftf_platform_setup() [mandatory]
197````````````````````````````````````````````
198
199::
200
201 Argument : void
202 Return : void
203
204This function executes with the MMU and data caches enabled. It is responsible
205for performing any remaining platform-specific setup that can occur after the
206MMU and data cache have been enabled.
207
208This function is also responsible for initializing the storage abstraction layer
209used to access non-volatile memory for permanent storage of test results. It
210also initialises the GIC and detects the platform topology using
211platform-specific means.
212
213Function : plat_get_nvm_handle() [mandatory]
214````````````````````````````````````````````
215
216::
217
218 Argument : uintptr_t *
219 Return : void
220
221It is needed if the platform port uses IO storage framework. This function is
222responsible for getting the pointer to the initialised non-volatile memory
223entity.
224
225Function : tftf_plat_get_pwr_domain_tree_desc() [mandatory]
226```````````````````````````````````````````````````````````
227
228::
229
230 Argument : void
231 Return : const unsigned char *
232
233This function returns the platform topology description array in a suitable
234format as expected by TFTF. The size of the array is expected to be
235``PLATFORM_NUM_AFFS - PLATFORM_CORE_COUNT + 1``. The format used to describe
236this array is :
237
2381. The first entry in the array specifies the number of power domains at the
239 highest power level implemented in the platform. This caters for platforms
240 where the power domain tree does not have a single root node e.g. the FVP
241 which has two cluster power domains at the highest level (that is, 1).
242
2432. Each subsequent entry corresponds to a power domain and contains the number
244 of power domains that are its direct children.
245
246The array format is the same as the one used by Trusted Firmware-A and more
247details of its description can be found in the Trusted Firmware-A documentation:
248`docs/psci-pd-tree.rst`_.
249
250Function : tftf_plat_get_mpidr() [mandatory]
251````````````````````````````````````````````
252
253::
254
255 Argument : unsigned int
256 Return : uint64_t
257
258This function converts a given `core_pos` into a valid MPIDR if the CPU is
259present in the platform. The `core_pos` is a unique number less than the
260``PLATFORM_CORE_COUNT`` returned by ``platform_get_core_pos()`` for a given
261CPU. This API is used by the topology framework in TFTF to query the presence of
262a CPU and, if present, returns the corresponding MPIDR for it. If the CPU
263referred to by the `core_pos` is absent, then this function returns
264``INVALID_MPID``.
265
266Function : plat_get_state_prop() [mandatory]
267````````````````````````````````````````````
268
269::
270
271 Argument : unsigned int
272 Return : const plat_state_prop_t *
273
274This functions returns the ``plat_state_prop_t`` array for all the valid low
275power states from platform for a specified affinity level and returns ``NULL``
276for an invalid affinity level. The array is expected to be NULL-terminated.
277This function is expected to be used by tests that need to compose the power
278state parameter for use in ``PSCI_CPU_SUSPEND`` API or ``PSCI_STAT/RESIDENCY``
279API.
280
281Function : plat_fwu_io_setup() [mandatory]
282``````````````````````````````````````````
283
284::
285
286 Argument : void
287 Return : void
288
289This function initializes the IO system used by the firmware update.
290
291Function : plat_arm_gic_init() [mandatory]
292``````````````````````````````````````````
293
294::
295
296 Argument : void
297 Return : void
298
299This function initializes the ARM Generic Interrupt Controller (GIC).
300
301Optional modifications
302----------------------
303
304The following are helper functions implemented by the test framework that
305perform common platform-specific tasks. A platform may choose to override these
306definitions.
307
308Function : platform_get_stack()
309```````````````````````````````
310
311::
312
313 Argument : unsigned long
314 Return : unsigned long
315
316This function returns the base address of the memory stack that has been
317allocated for the CPU specified by MPIDR. The size of the stack allocated to
318each CPU is specified by the platform defined constant ``PLATFORM_STACK_SIZE``.
319
320Common implementation of this function is provided in
321``plat/common/aarch64/platform_mp_stack.S``.
322
323Function : tftf_platform_end()
324``````````````````````````````
325
326::
327
328 Argument : void
329 Return : void
330
331This function performs any operation required by the platform to properly finish
332the test session.
333
334The default implementation sends an EOT (End Of Transmission) character on the
335UART. This can be used to automatically shutdown the FVP models. When running on
336real hardware, the UART output may be parsed by an external tool looking for
337this character and rebooting the platform for example.
338
339Function : tftf_plat_reset()
340````````````````````````````
341
342::
343
344 Argument : void
345 Return : void
346
347This function resets the platform.
348
349The default implementation uses the ARM watchdog peripheral (`SP805`_) to
350generate a watchdog timeout interrupt. This interrupt remains deliberately
351unserviced, which eventually asserts the reset signal.
352
353Function : tftf_platform_setup()
354````````````````````````````````
355
356::
357
358 Argument : void
359 Return : void
360
361Setup code for platform hardware. The default implementation initializes the IO
362and GIC.
363
364Storage abstraction layer
365-------------------------
366
367In order to improve platform independence and portability a storage abstraction
368layer is used to store test results to non-volatile platform storage.
369
370Each platform should register devices and their drivers via the Storage layer.
371These drivers then need to be initialized in ``tftf_platform_setup()`` function.
372
373It is mandatory to implement at least one storage driver. For the FVP and Juno
374platforms the NOR Flash driver is provided as the default means to store test
375results to storage. The storage layer is described in the header file
376``include/lib/io_storage.h``. The implementation of the common library is in
377``drivers/io/io_storage.c`` and the driver files are located in ``drivers/io/``.
378
379
380Build Flags
381-----------
382
383- **PLAT_TESTS_SKIP_LIST**
384
385This build flag can be defined by the platform to control exclusion of some
386testcases from the default test plan for a platform. If used this needs to
387point to a text file which follows the following criteria:
388
389 - Contain a list of tests to skip for this platform.
390
391 - Specify 1 test per line, using the following format:
392
393 ::
394
395 testsuite_name/testcase_name
396
397 where ``testsuite_name`` and ``testcase_name`` are the names that appear in
398 the XML tests file.
399
400 - Alternatively, it is possible to disable a test suite entirely, which will
401 disable all test cases part of this test suite. To do so, only specify the
402 test suite name, omitting the ``/testcase_name`` part.
403
404--------------
405
406*Copyright (c) 2018, Arm Limited. All rights reserved.*
407
408.. _docs/psci-pd-tree.rst: https://github.com/ARM-software/arm-trusted-firmware/blob/master/docs/psci-pd-tree.rst
409.. _SP805: https://static.docs.arm.com/ddi0270/b/DDI0270.pdf