Jimmy Brisson | 700fdd1 | 2020-04-02 15:19:12 -0500 | [diff] [blame] | 1 | Framework Design |
| 2 | ================ |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 3 | |
| 4 | This document provides some details about the internals of the TF-A Tests |
| 5 | design. It is incomplete at the moment. |
| 6 | |
| 7 | Global overview of the TF-A tests behaviour |
| 8 | ------------------------------------------- |
| 9 | |
| 10 | The EL3 firmware is expected to hand over to the TF-A tests with all secondary |
| 11 | cores powered down, i.e. only the primary core should enter the TF-A tests. |
| 12 | |
| 13 | The primary CPU initialises the platform and the TF-A tests internal data |
| 14 | structures. |
| 15 | |
| 16 | Then the test session begins. The TF-A tests are executed one after the |
| 17 | other. Tests results are saved in non-volatile memory as we go along. |
| 18 | |
Sandrine Bailleux | 68d76a2 | 2018-11-07 16:31:23 +0100 | [diff] [blame] | 19 | Once all tests have completed, a report is printed over the serial console. |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 20 | |
| 21 | Global Code Structure |
| 22 | --------------------- |
| 23 | |
| 24 | The code is organised into the following categories (present as directories at |
| 25 | the 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 Vincent | a2ede62 | 2019-02-11 14:34:26 +0000 | [diff] [blame] | 64 | Firstly, there is ``include/libc/`` which provides standard C library |
John Tsichritzis | 4586e0d | 2018-10-18 10:00:28 +0100 | [diff] [blame] | 65 | 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 Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 68 | |
| 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 Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 109 | - ``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 Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 115 | - **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 Tsichritzis | 88a956f | 2018-10-19 10:30:00 +0100 | [diff] [blame] | 123 | The tests are divided into the following categories (present as directories in |
| 124 | the ``tftf/tests/`` directory): |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 125 | |
John Tsichritzis | 88a956f | 2018-10-19 10:30:00 +0100 | [diff] [blame] | 126 | - **Framework validation tests.** |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 127 | |
John Tsichritzis | 88a956f | 2018-10-19 10:30:00 +0100 | [diff] [blame] | 128 | Tests that exercise the core features of the framework. Verify that the test |
| 129 | framework itself works properly. |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 130 | |
John Tsichritzis | 88a956f | 2018-10-19 10:30:00 +0100 | [diff] [blame] | 131 | - **Runtime services tests.** |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 132 | |
John Tsichritzis | 88a956f | 2018-10-19 10:30:00 +0100 | [diff] [blame] | 133 | 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 Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 137 | |
John Tsichritzis | 88a956f | 2018-10-19 10:30:00 +0100 | [diff] [blame] | 138 | - **CPU extensions tests.** |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 139 | |
John Tsichritzis | 88a956f | 2018-10-19 10:30:00 +0100 | [diff] [blame] | 140 | 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 Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 142 | |
John Tsichritzis | 88a956f | 2018-10-19 10:30:00 +0100 | [diff] [blame] | 143 | - **Firmware Update tests.** |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 144 | |
John Tsichritzis | 88a956f | 2018-10-19 10:30:00 +0100 | [diff] [blame] | 145 | Tests that exercise the `Firmware Update`_ feature of TF-A. |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 146 | |
John Tsichritzis | 88a956f | 2018-10-19 10:30:00 +0100 | [diff] [blame] | 147 | - **Template tests.** |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 148 | |
John Tsichritzis | 88a956f | 2018-10-19 10:30:00 +0100 | [diff] [blame] | 149 | Sample test code showing how to write tests in practice. Serves as |
| 150 | documentation. |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 151 | |
John Tsichritzis | 88a956f | 2018-10-19 10:30:00 +0100 | [diff] [blame] | 152 | - **Performance tests.** |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 153 | |
John Tsichritzis | 88a956f | 2018-10-19 10:30:00 +0100 | [diff] [blame] | 154 | Simple tests measuring the latency of an SMC call. |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 155 | |
John Tsichritzis | 88a956f | 2018-10-19 10:30:00 +0100 | [diff] [blame] | 156 | - **Miscellaneous tests.** |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 157 | |
John Tsichritzis | 88a956f | 2018-10-19 10:30:00 +0100 | [diff] [blame] | 158 | Tests for RAS support, correct system setup, ... |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 159 | |
| 160 | All assembler files have the ``.S`` extension. The linker source file has the |
| 161 | extension ``.ld.S``. This is processed by GCC to create the linker script which |
| 162 | has the extension ``.ld``. |
| 163 | |
| 164 | Detailed Code Structure |
| 165 | ----------------------- |
| 166 | |
| 167 | The cold boot entry point is ``tftf_entrypoint`` (see |
| 168 | ``tftf/framework/aarch64/entrypoint.S``). As explained in section `Global |
| 169 | overview of the TF-A tests behaviour`_, only the primary CPU is expected to |
| 170 | execute this code. |
| 171 | |
| 172 | Tests can power on other CPUs using the function ``tftf_cpu_on()``. This uses |
| 173 | the PSCI ``CPU_ON`` API of the EL3 Firmware. When entering the Normal World, |
| 174 | execution starts at the warm boot entry point, which is ``tftf_hotplug_entry()`` |
| 175 | (see ``tftf/framework/aarch64/entrypoint.S``). |
| 176 | |
| 177 | Information about the progression of the test session and tests results are |
| 178 | written into Non-Volatile Memory as we go along. This consists of the following |
| 179 | data (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 | |
| 224 | Interrupts management |
| 225 | --------------------- |
| 226 | |
| 227 | The TF-A tests expect SGIs #0 to #7 to be available for their own usage. In |
| 228 | particular, this means that Trusted World software must configure them as |
| 229 | non-secure interrupts. |
| 230 | |
| 231 | SGI #7 has a special status. It is the SGI that the timer management framework |
| 232 | sends to all CPUs when the system timer fires off (see the definition of the |
| 233 | constant ``IRQ_WAKE_SGI`` in the header file ``include/lib/irq.h``). Although |
| 234 | test cases can use this specific SGI - e.g. they can register an IRQ handler for |
| 235 | it and use it as an inter-CPU communication mechanism - they have to be aware of |
| 236 | the underlying consequences. Some tests, like the PSCI ``CPU_SUSPEND`` tests, |
| 237 | rely on this SGI to be enabled in order to wake up CPUs from their suspend |
| 238 | state. If it is disabled, these tests will leave the system in an unresponsive |
| 239 | state. |
| 240 | |
| 241 | -------------- |
| 242 | |
Sandrine Bailleux | b308d01 | 2019-04-10 09:30:10 +0200 | [diff] [blame] | 243 | *Copyright (c) 2018-2019, Arm Limited. All rights reserved.* |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 244 | |
Sandrine Bailleux | b308d01 | 2019-04-10 09:30:10 +0200 | [diff] [blame] | 245 | .. _Firmware Update: https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git/about/docs/firmware-update.rst |