Galanakis, Minos | 41f8597 | 2019-09-30 15:56:40 +0100 | [diff] [blame] | 1 | ################# |
| 2 | Integration guide |
| 3 | ################# |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 4 | The purpose of this document is to provide a guide on how to integrate TF-M |
| 5 | with other hardware platforms and operating systems. |
| 6 | |
| 7 | ***************** |
| 8 | How to build TF-M |
| 9 | ***************** |
Summer Qin | ab1dd99 | 2021-05-25 13:58:55 +0800 | [diff] [blame^] | 10 | Follow the :doc:`Build instructions </docs/technical_references/instructions/tfm_build_instruction>`. |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 11 | |
| 12 | ******************************************************** |
| 13 | How to export files for building non-secure applications |
| 14 | ******************************************************** |
Summer Qin | ab1dd99 | 2021-05-25 13:58:55 +0800 | [diff] [blame^] | 15 | Explained in the :doc:`Build instructions </docs/technical_references/instructions/tfm_build_instruction>`. |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 16 | |
| 17 | ************************* |
| 18 | How to add a new platform |
| 19 | ************************* |
| 20 | The hardware platforms currently supported are: |
| 21 | |
| 22 | - Soft Macro Model (SMM) Cortex-M33 SSE-200 subsystem for MPS2+ (AN521) |
| 23 | - Cortex-M23 IoT Kit subsystem for MPS2+ (AN519) |
Marton Berke | 07fc95f | 2020-08-18 15:24:14 +0200 | [diff] [blame] | 24 | - Corstone-300 Ecosystem FVP (Cortex-M55 SSE-300 MPS2+) |
Marton Berke | 8c2f524 | 2020-07-28 14:52:29 +0200 | [diff] [blame] | 25 | - Corstone-300 Ethos-U55 FVP (Cortex-M55 plus Ethos-U55 SSE-300 MPS3) |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 26 | - Musca-B1 test chip board (Cortex-M33 SSE-200 subsystem) |
Marton Berke | 8aae06f | 2019-11-25 16:46:12 +0100 | [diff] [blame] | 27 | - Musca-S1 test chip board (Cortex-M33 SSE-200 subsystem) |
Kevin Peng | 0a14211 | 2018-09-21 10:42:22 +0800 | [diff] [blame] | 28 | - CoreLink SSE-200 Subsystem for MPS3 (AN524) |
Gabor Toth | f07e92e | 2020-11-20 13:55:06 +0100 | [diff] [blame] | 29 | - Corstone SSE-300 with Ethos-U55 Example Subsystem for MPS3 (AN547) |
Ludovic Barre | 8a77bdd | 2020-03-26 19:53:07 +0100 | [diff] [blame] | 30 | - STM32L5xx: Cortex-M33 based platform (STM32L562 and STM32L552 socs) |
Øyvind Rønningstad | ba9aac0 | 2020-09-14 15:19:28 +0200 | [diff] [blame] | 31 | - nRF9160 DK (Cortex-M33) |
Andrzej Głąbek | aa74ab6 | 2021-04-20 11:46:27 +0200 | [diff] [blame] | 32 | - nRF5340 DK (Cortex-M33 Application MCU) |
Jamie McCrae | 13ff457 | 2021-04-06 10:47:12 +0100 | [diff] [blame] | 33 | - BL5340 DVK (Cortex-M33 Application MCU) |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 34 | |
| 35 | The files related to the supported platforms are contained under the |
| 36 | ``platform`` subfolder. The platform specific files are under |
| 37 | ``platform/ext/target``, which is organised by boards |
| 38 | (e.g. ``platform/ext/target/mps2``), while the folder ``platform/ext/common`` |
| 39 | is used to store source and header files which are platform generic. |
| 40 | |
| 41 | More information about subsystems supported by the MPS2+ board can be found in: |
| 42 | `MPS2+ homepage <https://developer.arm.com/products/system-design/development-boards/fpga-prototyping-boards/mps2>`__ |
| 43 | |
Gabor Toth | f07e92e | 2020-11-20 13:55:06 +0100 | [diff] [blame] | 44 | More information about subsystems supported by the MPS3 board can be found in: |
| 45 | `MPS3 homepage <https://developer.arm.com/products/system-design/development-boards/fpga-prototyping-boards/mps3>`__ |
| 46 | |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 47 | More information about the Musca-B1 test chip board can be found in: |
| 48 | `Musca-B1 homepage <https://www.arm.com/products/development-tools/development-boards/musca-b1-iot>`__ |
| 49 | |
Marton Berke | 8aae06f | 2019-11-25 16:46:12 +0100 | [diff] [blame] | 50 | More information about the Musca-S1 test chip board can be found in: |
| 51 | `Musca-S1 homepage <https://www.arm.com/company/news/2019/05/arm-demonstrates-new-iot-test-chip-and-board>`__ |
| 52 | |
Kevin Peng | 0a14211 | 2018-09-21 10:42:22 +0800 | [diff] [blame] | 53 | More information about subsystems supported by the MPS3 board can be found in: |
| 54 | `MPS3 homepage <https://www.arm.com/products/development-tools/development-boards/mps3>`__ |
| 55 | |
Marton Berke | 8c2f524 | 2020-07-28 14:52:29 +0200 | [diff] [blame] | 56 | More information about the Corstone-300 FVPs can be found in: |
| 57 | `Arm Ecosystem FVPs homepage <https://developer.arm.com/tools-and-software/open-source-software/arm-platforms-software/arm-ecosystem-fvps>`__ |
| 58 | |
Ludovic Barre | 8a77bdd | 2020-03-26 19:53:07 +0100 | [diff] [blame] | 59 | More information about the STM32L5xx platform can be found in: |
| 60 | `STM32L5 series product page <https://www.st.com/content/st_com/en/products/microcontrollers-microprocessors/stm32-32-bit-arm-cortex-mcus/stm32-ultra-low-power-mcus/stm32l5-series.html>`__ |
| 61 | |
Andrzej Głąbek | aa74ab6 | 2021-04-20 11:46:27 +0200 | [diff] [blame] | 62 | More information about the nRF5340 DK platform can be found in: |
| 63 | `nRF5340 DK product page <https://www.nordicsemi.com/Software-and-tools/Development-Kits/nRF5340-DK>`__ |
Øyvind Rønningstad | ba9aac0 | 2020-09-14 15:19:28 +0200 | [diff] [blame] | 64 | |
| 65 | More information about the nRF9160 DK platform can be found in: |
| 66 | `nRF9160 DK product page <https://www.nordicsemi.com/Software-and-tools/Development-Kits/nRF9160-DK>`__ |
| 67 | |
Jamie McCrae | 13ff457 | 2021-04-06 10:47:12 +0100 | [diff] [blame] | 68 | More information about the BL5340 platform can be found in: |
| 69 | `BL5340 product page <https://www.lairdconnect.com/wireless-modules/bluetooth-modules/bluetooth-5-modules/bl5340-series-multi-core-bluetooth-52-802154-nfc-modules>`__ |
| 70 | |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 71 | Generic drivers and startup/scatter files |
| 72 | ========================================= |
| 73 | The addition of a new platform means the creation of a new subfolder inside |
| 74 | ``target/<board_name>`` to provide an implementation of the drivers currently |
| 75 | used by TF-M, in particular MPC, PPC, and USART drivers. In addition to the |
| 76 | drivers, startup and scatter files need to be provided for the supported |
| 77 | toolchains. |
| 78 | |
| 79 | There are also board specific drivers which are used by the board |
| 80 | platform to interact with the external world, for example during tests, that |
| 81 | have to be provided, e.g. to blink LEDs or count time in the MPS2 board. |
| 82 | |
| 83 | .. Note:: |
| 84 | |
Kevin Peng | c6d7450 | 2020-03-04 16:55:37 +0800 | [diff] [blame] | 85 | Currently ITS, PS and BL2 bootloader use different flash interface |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 86 | |
| 87 | Target configuration files |
| 88 | ========================== |
| 89 | Inside the base root folder of the selected target, each implementation has to |
| 90 | provide its own copy of ``target_cfg.c/.h``. This file has target specific |
| 91 | configuration functions and settings that are called by the TF-M during the |
| 92 | platform configuration step during TF-M boot. Examples of the configurations |
| 93 | performed during this phase are the MPC configuration, the SAU configuration, |
| 94 | or eventually PPC configuration if supported by the hardware platform. |
| 95 | Similarly, the ``uart_stdout.c`` is used to provide functions needed to redirect |
| 96 | the stdout on UART (this is currently used by TF-M to log messages). |
| 97 | |
| 98 | Platform retarget files |
| 99 | ======================= |
| 100 | An important part that each new platform has to provide is the set of retarget |
| 101 | files which are contained inside the ``retarget`` folder. These files define the |
| 102 | peripheral base addresses for the platform, both for the secure and non-secure |
| 103 | aliases (when available), and bind those addresses to the base addresses used by |
| 104 | the devices available in the hardware platform. |
| 105 | |
| 106 | *************************** |
| 107 | How to integrate another OS |
| 108 | *************************** |
David Hu | 5079a04 | 2021-04-07 17:16:59 +0800 | [diff] [blame] | 109 | |
| 110 | OS migration to Armv8-M platforms |
| 111 | ================================= |
| 112 | To work with TF-M on Armv8-M platforms, the OS needs to support the Armv8-M |
| 113 | architecture and, in particular, it needs to be able to run in the non-secure |
| 114 | world. More information about OS migration to the Armv8-M architecture can be |
| 115 | found in the :doc:`OS requirements <os_migration_guide_armv8m>`. Depending upon |
| 116 | the system configuration this may require configuring drivers to use appropriate |
| 117 | address ranges. |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 118 | |
| 119 | Interface with TF-M |
| 120 | =================== |
| 121 | The files needed for the interface with TF-M are exported at the |
Raef Coles | 4fed463 | 2020-12-08 12:56:47 +0000 | [diff] [blame] | 122 | ``<install_dir>/interface`` path. The NS side is only allowed to call |
David Hu | 5079a04 | 2021-04-07 17:16:59 +0800 | [diff] [blame] | 123 | TF-M secure functions (veneers) from the NS Thread mode. |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 124 | |
David Hu | 5079a04 | 2021-04-07 17:16:59 +0800 | [diff] [blame] | 125 | TF-M interface header files are exported in ``<install_dir>/interface/include`` |
| 126 | directory. For example, the Protected Storage (PS) service PSA API is declared |
| 127 | in the file ``<install_dir>/interface/include/psa/protected_storage.h``. |
| 128 | |
| 129 | TF-M also exports a reference implementation of PSA APIs for NS clients in the |
| 130 | ``<install_dir>/interface/src``. |
| 131 | |
| 132 | On Armv8-M TrustZone based platforms, NS OS shall implement interface API |
| 133 | ``tfm_ns_interface_dispatch()`` to integrate with TF-M implementation of PSA |
| 134 | APIs. See ``interface/include/tfm_ns_interface.h`` for the detailed declaration |
| 135 | of ``tfm_ns_interface_dispatch()``. |
| 136 | TF-M provides an example of ``tfm_ns_interface_dispatch()`` implementation on |
| 137 | Armv8-M TrustZone based platforms. In this example, NS OS calls mutex in |
| 138 | ``tfm_ns_interface_dispatch()`` to synchronize multiple NS client calls to TF-M. |
| 139 | See ``interface/src/tfm_ns_interface.c.example`` for more details. |
| 140 | |
| 141 | TF-M provides a reference implementation of NS mailbox on multi-core platforms, |
| 142 | under folder ``interface/src/multi_core``. |
| 143 | See :doc:`Mailbox design </docs/technical_references/dual-cpu/mailbox_design_on_dual_core_system>` |
| 144 | for TF-M multi-core mailbox design. |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 145 | |
| 146 | Interface with non-secure world regression tests |
| 147 | ================================================ |
| 148 | A non-secure application that wants to run the non-secure regression tests |
| 149 | needs to call the ``tfm_non_secure_client_run_tests()``. This function is |
| 150 | exported into the header file ``test_framework_integ_test.h`` inside the |
| 151 | ``<build_dir>/install`` folder structure in the test specific files, |
| 152 | i.e. ``<build_dir>/install/export/tfm/test/inc``. The non-secure regression |
| 153 | tests are precompiled and delivered as a static library which is available in |
| 154 | ``<build_dir>/install/export/tfm/test/lib``, so that the non-secure application |
| 155 | needs to link against the library to be able to invoke the |
Kevin Peng | c6d7450 | 2020-03-04 16:55:37 +0800 | [diff] [blame] | 156 | ``tfm_non_secure_client_run_tests()`` function. The PS non-secure side |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 157 | regression tests rely on some OS functionality e.g. threads, mutexes etc. These |
| 158 | functions comply with CMSIS RTOS2 standard and have been exported as thin |
| 159 | wrappers defined in ``os_wrapper.h`` contained in |
| 160 | ``<build_dir>/install/export/tfm/test/inc``. OS needs to provide the |
| 161 | implementation of these wrappers to be able to run the tests. |
| 162 | |
| 163 | NS client Identification |
| 164 | ======================== |
| 165 | See |
Summer Qin | abf6698 | 2021-04-06 17:22:15 +0800 | [diff] [blame] | 166 | :doc:`ns client identification documentation </docs/technical_references/tfm_ns_client_identification>`. |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 167 | |
Mate Toth-Pal | 12d7a18 | 2019-04-28 14:05:21 +0200 | [diff] [blame] | 168 | ********************* |
| 169 | Non-secure interrupts |
| 170 | ********************* |
| 171 | Non-secure interrupts are allowed to preempt Secure thread mode. |
| 172 | With the current implementation, a NSPE task can spoof the identity of another |
| 173 | NSPE task. This is an issue only when NSPE has provisions for task isolation. |
| 174 | Note, that ``AIRCR.PRIS`` is still set to restrict the priority range available |
| 175 | to NS interrupts to the lower half of available priorities so that it wouldn't |
| 176 | be possible for any non-secure interrupt to preempt a higher-priority secure |
| 177 | interrupt. |
| 178 | |
Raef Coles | 558487a | 2020-10-29 13:09:44 +0000 | [diff] [blame] | 179 | ********************************** |
| 180 | Integration with non-Cmake systems |
| 181 | ********************************** |
| 182 | |
| 183 | Generated Files |
| 184 | =============== |
| 185 | |
| 186 | Files that are derived from PSA manifests are generated at build-time by cmake. |
| 187 | For integration with systems that do no use cmake, the files must be generated |
| 188 | manually. |
| 189 | |
| 190 | The ``tools/tfm_parse_manifest_list.py`` script can be invoked manually. Some |
| 191 | arguments will be needed to be provided. Please refer to |
| 192 | ``tfm_parse_manifest_list.py --help`` for more details. |
| 193 | |
| 194 | Some variables are used in the template files, these will need to be set in the |
| 195 | environment before the script will succeed when the script is not run via cmake. |
| 196 | |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 197 | -------------- |
| 198 | |
Raef Coles | a198a44 | 2020-11-24 11:42:53 +0000 | [diff] [blame] | 199 | *Copyright (c) 2017-2021, Arm Limited. All rights reserved.* |