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 | ***************** |
| 10 | Follow the :doc:`Build instructions <tfm_build_instruction>`. |
| 11 | |
| 12 | ******************************************************** |
| 13 | How to export files for building non-secure applications |
| 14 | ******************************************************** |
| 15 | Explained in the :doc:`Build instructions <tfm_build_instruction>`. |
| 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 | 8aae06f | 2019-11-25 16:46:12 +0100 | [diff] [blame] | 24 | - Arm SSE-123 Example Subsystem for MPS2+ (AN539) |
Marton Berke | 07fc95f | 2020-08-18 15:24:14 +0200 | [diff] [blame] | 25 | - Corstone-300 Ecosystem FVP (Cortex-M55 SSE-300 MPS2+) |
Jamie Fox | b8a9270 | 2019-06-05 17:19:31 +0100 | [diff] [blame] | 26 | - Musca-A test chip board (Cortex-M33 SSE-200 subsystem) |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 27 | - Musca-B1 test chip board (Cortex-M33 SSE-200 subsystem) |
Marton Berke | 8aae06f | 2019-11-25 16:46:12 +0100 | [diff] [blame] | 28 | - Musca-S1 test chip board (Cortex-M33 SSE-200 subsystem) |
Kevin Peng | 0a14211 | 2018-09-21 10:42:22 +0800 | [diff] [blame] | 29 | - CoreLink SSE-200 Subsystem for MPS3 (AN524) |
Marton Berke | e980366 | 2019-11-11 14:11:05 +0100 | [diff] [blame] | 30 | - DesignStart FPGA on Cloud: Cortex-M33 based platform (SSE-200_AWS) |
Ludovic Barre | 8a77bdd | 2020-03-26 19:53:07 +0100 | [diff] [blame] | 31 | - STM32L5xx: Cortex-M33 based platform (STM32L562 and STM32L552 socs) |
Øyvind Rønningstad | ba9aac0 | 2020-09-14 15:19:28 +0200 | [diff] [blame^] | 32 | - nRF9160 DK (Cortex-M33) |
| 33 | - nRF5340 PDK (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 | |
Jamie Fox | b8a9270 | 2019-06-05 17:19:31 +0100 | [diff] [blame] | 44 | More information about the Musca-A test chip board can be found in: |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 45 | `Musca-A homepage <https://developer.arm.com/products/system-design/development-boards/iot-test-chips-and-boards/musca-a-test-chip-board>`__ |
| 46 | |
| 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 | e980366 | 2019-11-11 14:11:05 +0100 | [diff] [blame] | 56 | More information about the SSE-200_AWS platform can be found in: |
| 57 | `SSE-200_AWS product page <https://aws.amazon.com/marketplace/pp/ARM-DesignStart-FPGA-on-Cloud-Cortex-M33-based-pla/B082DMMTLW>`__ |
| 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 | |
Øyvind Rønningstad | ba9aac0 | 2020-09-14 15:19:28 +0200 | [diff] [blame^] | 62 | More information about the nRF5340 PDK platform can be found in: |
| 63 | `nRF5340 PDK product page <https://www.nordicsemi.com/Software-and-tools/Development-Kits/nRF5340-PDK>`__ |
| 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 | |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 68 | Generic drivers and startup/scatter files |
| 69 | ========================================= |
| 70 | The addition of a new platform means the creation of a new subfolder inside |
| 71 | ``target/<board_name>`` to provide an implementation of the drivers currently |
| 72 | used by TF-M, in particular MPC, PPC, and USART drivers. In addition to the |
| 73 | drivers, startup and scatter files need to be provided for the supported |
| 74 | toolchains. |
| 75 | |
| 76 | There are also board specific drivers which are used by the board |
| 77 | platform to interact with the external world, for example during tests, that |
| 78 | have to be provided, e.g. to blink LEDs or count time in the MPS2 board. |
| 79 | |
| 80 | .. Note:: |
| 81 | |
Kevin Peng | c6d7450 | 2020-03-04 16:55:37 +0800 | [diff] [blame] | 82 | Currently ITS, PS and BL2 bootloader use different flash interface |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 83 | |
| 84 | Target configuration files |
| 85 | ========================== |
| 86 | Inside the base root folder of the selected target, each implementation has to |
| 87 | provide its own copy of ``target_cfg.c/.h``. This file has target specific |
| 88 | configuration functions and settings that are called by the TF-M during the |
| 89 | platform configuration step during TF-M boot. Examples of the configurations |
| 90 | performed during this phase are the MPC configuration, the SAU configuration, |
| 91 | or eventually PPC configuration if supported by the hardware platform. |
| 92 | Similarly, the ``uart_stdout.c`` is used to provide functions needed to redirect |
| 93 | the stdout on UART (this is currently used by TF-M to log messages). |
| 94 | |
| 95 | Platform retarget files |
| 96 | ======================= |
| 97 | An important part that each new platform has to provide is the set of retarget |
| 98 | files which are contained inside the ``retarget`` folder. These files define the |
| 99 | peripheral base addresses for the platform, both for the secure and non-secure |
| 100 | aliases (when available), and bind those addresses to the base addresses used by |
| 101 | the devices available in the hardware platform. |
| 102 | |
| 103 | *************************** |
| 104 | How to integrate another OS |
| 105 | *************************** |
| 106 | To work with TF-M, the OS needs to support the Armv8-M architecture and, in |
| 107 | particular, it needs to be able to run in the non-secure world. More |
| 108 | information about OS migration to the Armv8-M architecture can be found in the |
| 109 | :doc:`OS requirements <os_migration_guide_armv8m>`. Depending upon the system |
| 110 | configuration this may require configuring drivers to use appropriate address |
| 111 | ranges. |
| 112 | |
| 113 | Interface with TF-M |
| 114 | =================== |
| 115 | The files needed for the interface with TF-M are exported at the |
| 116 | ``<build_dir>/install/export/tfm`` path. The NS side is only allowed to call |
| 117 | TF-M secure functions (veneers) from the NS Thread mode. For this reason, the |
| 118 | API is a collection of functions in the ``<build_dir>/install/export/tfm/inc`` |
Kevin Peng | c6d7450 | 2020-03-04 16:55:37 +0800 | [diff] [blame] | 119 | directory. For example, the interface for the Protected Storage (PS) service |
| 120 | is described in the file ``psa_ps_api.h`` as a collection of functions that |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 121 | call service veneer functions. This API is a wrapper for the secure veneers, |
| 122 | and returns the return value from the service to the caller. |
| 123 | |
Kevin Peng | c6d7450 | 2020-03-04 16:55:37 +0800 | [diff] [blame] | 124 | The protected storage service uses a numerical ID, to identify the clients that |
| 125 | use the service. For details see |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 126 | :doc:`ns client identification documentation <tfm_ns_client_identification>`. |
| 127 | |
| 128 | Interface with non-secure world regression tests |
| 129 | ================================================ |
| 130 | A non-secure application that wants to run the non-secure regression tests |
| 131 | needs to call the ``tfm_non_secure_client_run_tests()``. This function is |
| 132 | exported into the header file ``test_framework_integ_test.h`` inside the |
| 133 | ``<build_dir>/install`` folder structure in the test specific files, |
| 134 | i.e. ``<build_dir>/install/export/tfm/test/inc``. The non-secure regression |
| 135 | tests are precompiled and delivered as a static library which is available in |
| 136 | ``<build_dir>/install/export/tfm/test/lib``, so that the non-secure application |
| 137 | needs to link against the library to be able to invoke the |
Kevin Peng | c6d7450 | 2020-03-04 16:55:37 +0800 | [diff] [blame] | 138 | ``tfm_non_secure_client_run_tests()`` function. The PS non-secure side |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 139 | regression tests rely on some OS functionality e.g. threads, mutexes etc. These |
| 140 | functions comply with CMSIS RTOS2 standard and have been exported as thin |
| 141 | wrappers defined in ``os_wrapper.h`` contained in |
| 142 | ``<build_dir>/install/export/tfm/test/inc``. OS needs to provide the |
| 143 | implementation of these wrappers to be able to run the tests. |
| 144 | |
| 145 | NS client Identification |
| 146 | ======================== |
| 147 | See |
| 148 | :doc:`ns client identification documentation <tfm_ns_client_identification>`. |
| 149 | |
Mate Toth-Pal | 12d7a18 | 2019-04-28 14:05:21 +0200 | [diff] [blame] | 150 | ********************* |
| 151 | Non-secure interrupts |
| 152 | ********************* |
| 153 | Non-secure interrupts are allowed to preempt Secure thread mode. |
| 154 | With the current implementation, a NSPE task can spoof the identity of another |
| 155 | NSPE task. This is an issue only when NSPE has provisions for task isolation. |
| 156 | Note, that ``AIRCR.PRIS`` is still set to restrict the priority range available |
| 157 | to NS interrupts to the lower half of available priorities so that it wouldn't |
| 158 | be possible for any non-secure interrupt to preempt a higher-priority secure |
| 159 | interrupt. |
| 160 | |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 161 | -------------- |
| 162 | |
Kevin Peng | c6d7450 | 2020-03-04 16:55:37 +0800 | [diff] [blame] | 163 | *Copyright (c) 2017-2020, Arm Limited. All rights reserved.* |