blob: 5e85d6a061e51dcd41b0fbb751c74a047354bdb1 [file] [log] [blame]
Jimmy Brisson700fdd12020-04-02 15:19:12 -05001Framework Design
2================
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +02003
4This document provides some details about the internals of the TF-A Tests
5design. It is incomplete at the moment.
6
7Global overview of the TF-A tests behaviour
8-------------------------------------------
9
10The EL3 firmware is expected to hand over to the TF-A tests with all secondary
11cores powered down, i.e. only the primary core should enter the TF-A tests.
12
13The primary CPU initialises the platform and the TF-A tests internal data
14structures.
15
16Then the test session begins. The TF-A tests are executed one after the
17other. Tests results are saved in non-volatile memory as we go along.
18
Sandrine Bailleux68d76a22018-11-07 16:31:23 +010019Once all tests have completed, a report is printed over the serial console.
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020020
21Global Code Structure
22---------------------
23
24The code is organised into the following categories (present as directories at
25the top level or under the ``tftf/`` directory):
26
27- **Drivers.**
28
29 Some examples follow, this list might not be exhaustive.
30
31 - Generic GIC driver.
32
33 ``arm_gic.h`` contains the public APIs that tests might use. Both GIC
34 architecture versions 2 and 3 are supported.
35
36 - PL011 UART driver.
37
38 - VExpress NOR flash driver.
39
40 Note that tests are not expected to use this driver in most
41 cases. Instead, they should use the ``tftf_nvm_read()`` and
42 ``tftf_nvm_write()`` wrapper APIs. See definitions in
43 ``tftf/framework/include/nvm.h``. See also the NVM validation test cases
44 (``tftf/tests/framework_validation_tests/test_validation_nvm.c``) for an
45 example of usage of these functions.
46
47 - SP805 watchdog.
48
49 Used solely to generate an interrupt that will reset the system on purpose
50 (used in ``tftf_plat_reset()``).
51
52 - SP804 timer.
53
54 This is used as the system timer on Juno. It is configured such that an
55 interrupt is generated when it reaches 0. It is programmed in one-shot
56 mode, i.e. it must be rearmed every time it reaches 0.
57
58- **Framework.**
59
60 Core features of the test framework.
61
62- **Library code.**
63
Ambroise Vincenta2ede622019-02-11 14:34:26 +000064 Firstly, there is ``include/libc/`` which provides standard C library
John Tsichritzis4586e0d2018-10-18 10:00:28 +010065 functions like ``memcpy()``, ``printf()`` and so on.
66 Additionally, various other APIs are provided under ``include/lib/``. The
67 below list gives some examples but might not be exhaustive.
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020068
69 - ``aarch64/``
70
71 Architecture helper functions for e.g. system registers access, cache
72 maintenance operations, MMU configuration, ...
73
74 - ``events.h``
75
76 Events API. Used to create synchronisation points between CPUs in tests.
77
78 - ``irq.h``
79
80 IRQ handling support. Used to configure IRQs and register/unregister
81 handlers called upon reception of a specific IRQ.
82
83 - ``power_management.h``
84
85 Power management operations (CPU ON/OFF, CPU suspend, etc.).
86
87 - ``sgi.h``
88
89 Software Generated Interrupt support. Used as an inter-CPU communication
90 mechanism.
91
92 - ``spinlock.h``
93
94 Lightweight implementation of synchronisation locks. Used to prevent
95 concurrent accesses to shared data structures.
96
97 - ``timer.h``
98
99 Support for programming the timer. Any timer which is in the `always-on`
100 power domain can be used to exit CPUs from suspend state.
101
102 - ``tftf_lib.h``
103
104 Miscellaneous helper functions/macros: MP-safe ``printf()``, low-level
105 PSCI wrappers, insertion of delays, raw SMC interface, support for writing
106 a string in the test report, macros to skip tests on platforms that do not
107 meet topology requirements, etc.
108
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200109 - ``io_storage.h``
110
111 Low-level IO operations. Tests are not expected to use these APIs
112 directly. They should use higher-level APIs like ``tftf_nvm_read()``
113 and ``tftf_nvm_write()``.
114
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200115- **Platform specific.**
116
117 Note that ``include/plat/common/plat_topology.h`` provides the interfaces
118 that a platform must implement to support topology discovery (i.e. how many
119 CPUs and clusters there are).
120
121- **Tests.**
122
John Tsichritzis88a956f2018-10-19 10:30:00 +0100123 The tests are divided into the following categories (present as directories in
124 the ``tftf/tests/`` directory):
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200125
John Tsichritzis88a956f2018-10-19 10:30:00 +0100126 - **Framework validation tests.**
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200127
John Tsichritzis88a956f2018-10-19 10:30:00 +0100128 Tests that exercise the core features of the framework. Verify that the test
129 framework itself works properly.
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200130
John Tsichritzis88a956f2018-10-19 10:30:00 +0100131 - **Runtime services tests.**
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200132
John Tsichritzis88a956f2018-10-19 10:30:00 +0100133 Tests that exercise the runtime services offered by the EL3 Firmware to the
134 Normal World software. For example, this includes tests for the Standard
135 Service (to which PSCI belongs to), the Trusted OS service or the SiP
136 service.
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200137
John Tsichritzis88a956f2018-10-19 10:30:00 +0100138 - **CPU extensions tests.**
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200139
John Tsichritzis88a956f2018-10-19 10:30:00 +0100140 Tests some CPU extensions features. For example, the AMU tests ensure that
141 the counters provided by the Activity Monitor Unit are behaving correctly.
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200142
John Tsichritzis88a956f2018-10-19 10:30:00 +0100143 - **Firmware Update tests.**
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200144
John Tsichritzis88a956f2018-10-19 10:30:00 +0100145 Tests that exercise the `Firmware Update`_ feature of TF-A.
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200146
John Tsichritzis88a956f2018-10-19 10:30:00 +0100147 - **Template tests.**
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200148
John Tsichritzis88a956f2018-10-19 10:30:00 +0100149 Sample test code showing how to write tests in practice. Serves as
150 documentation.
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200151
John Tsichritzis88a956f2018-10-19 10:30:00 +0100152 - **Performance tests.**
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200153
John Tsichritzis88a956f2018-10-19 10:30:00 +0100154 Simple tests measuring the latency of an SMC call.
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200155
John Tsichritzis88a956f2018-10-19 10:30:00 +0100156 - **Miscellaneous tests.**
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200157
John Tsichritzis88a956f2018-10-19 10:30:00 +0100158 Tests for RAS support, correct system setup, ...
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200159
160All assembler files have the ``.S`` extension. The linker source file has the
161extension ``.ld.S``. This is processed by GCC to create the linker script which
162has the extension ``.ld``.
163
164Detailed Code Structure
165-----------------------
166
167The cold boot entry point is ``tftf_entrypoint`` (see
168``tftf/framework/aarch64/entrypoint.S``). As explained in section `Global
169overview of the TF-A tests behaviour`_, only the primary CPU is expected to
170execute this code.
171
172Tests can power on other CPUs using the function ``tftf_cpu_on()``. This uses
173the PSCI ``CPU_ON`` API of the EL3 Firmware. When entering the Normal World,
174execution starts at the warm boot entry point, which is ``tftf_hotplug_entry()``
175(see ``tftf/framework/aarch64/entrypoint.S``).
176
177Information about the progression of the test session and tests results are
178written into Non-Volatile Memory as we go along. This consists of the following
179data (see struct ``tftf_state_t`` typedef in ``tftf/framework/include/nvm.h``):
180
181- ``test_to_run``
182
183 Reference to the test to run.
184
185- ``test_progress``
186
187 Progress in the execution of ``test_to_run``. This is used to implement the
188 following state machine:
189
190::
191
192 +-> TEST_READY (initial state of the test) <--------------+
193 | | |
194 | | Test framework prepares the test environment. |
195 | | |
196 | v |
197 | TEST_IN_PROGRESS |
198 | | |
199 | | Hand over to the test function. |
200 | | If the test wants to reboot the platform ---> TEST_REBOOTING |
201 | | | |
202 | | Test function returns into framework. | Reboot |
203 | | | |
204 | | +---------+
205 | v
206 | TEST_COMPLETE
207 | |
208 | | Do some framework management.
209 | | Move to next test.
210 +--------+
211
212- ``testcase_buffer``
213
214 A buffer that the test can use as a scratch area for whatever it is doing.
215
216- ``testcase_results``
217
218- ``result_buffer_size``
219
220- ``result_buffer``
221
222 Buffer holding the tests output. Tests output are concatenated.
223
224Interrupts management
225---------------------
226
227The TF-A tests expect SGIs #0 to #7 to be available for their own usage. In
228particular, this means that Trusted World software must configure them as
229non-secure interrupts.
230
231SGI #7 has a special status. It is the SGI that the timer management framework
232sends to all CPUs when the system timer fires off (see the definition of the
233constant ``IRQ_WAKE_SGI`` in the header file ``include/lib/irq.h``). Although
234test cases can use this specific SGI - e.g. they can register an IRQ handler for
235it and use it as an inter-CPU communication mechanism - they have to be aware of
236the underlying consequences. Some tests, like the PSCI ``CPU_SUSPEND`` tests,
237rely on this SGI to be enabled in order to wake up CPUs from their suspend
238state. If it is disabled, these tests will leave the system in an unresponsive
239state.
240
241--------------
242
Sandrine Bailleuxb308d012019-04-10 09:30:10 +0200243*Copyright (c) 2018-2019, Arm Limited. All rights reserved.*
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200244
Sandrine Bailleuxb308d012019-04-10 09:30:10 +0200245.. _Firmware Update: https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git/about/docs/firmware-update.rst