blob: fc729a5ea7853a9c26a2f8bc2d4aea03e49b27c2 [file] [log] [blame]
Galanakis, Minos41f85972019-09-30 15:56:40 +01001#################
2Integration guide
3#################
Gyorgy Szingdb9783c2019-04-17 21:08:48 +02004The purpose of this document is to provide a guide on how to integrate TF-M
5with other hardware platforms and operating systems.
6
7*****************
8How to build TF-M
9*****************
10Follow the :doc:`Build instructions <tfm_build_instruction>`.
11
12********************************************************
13How to export files for building non-secure applications
14********************************************************
15Explained in the :doc:`Build instructions <tfm_build_instruction>`.
16
17*************************
18How to add a new platform
19*************************
20The 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 Berke8aae06f2019-11-25 16:46:12 +010024- Arm SSE-123 Example Subsystem for MPS2+ (AN539)
Marton Berke07fc95f2020-08-18 15:24:14 +020025- Corstone-300 Ecosystem FVP (Cortex-M55 SSE-300 MPS2+)
Marton Berke8c2f5242020-07-28 14:52:29 +020026- Corstone-300 Ethos-U55 FVP (Cortex-M55 plus Ethos-U55 SSE-300 MPS3)
Jamie Foxb8a92702019-06-05 17:19:31 +010027- Musca-A test chip board (Cortex-M33 SSE-200 subsystem)
Gyorgy Szingdb9783c2019-04-17 21:08:48 +020028- Musca-B1 test chip board (Cortex-M33 SSE-200 subsystem)
Marton Berke8aae06f2019-11-25 16:46:12 +010029- Musca-S1 test chip board (Cortex-M33 SSE-200 subsystem)
Kevin Peng0a142112018-09-21 10:42:22 +080030- CoreLink SSE-200 Subsystem for MPS3 (AN524)
Marton Berkee9803662019-11-11 14:11:05 +010031- DesignStart FPGA on Cloud: Cortex-M33 based platform (SSE-200_AWS)
Ludovic Barre8a77bdd2020-03-26 19:53:07 +010032- STM32L5xx: Cortex-M33 based platform (STM32L562 and STM32L552 socs)
Øyvind Rønningstadba9aac02020-09-14 15:19:28 +020033- nRF9160 DK (Cortex-M33)
Andrzej Głąbekbb4d5c52020-11-03 10:08:48 +010034- nRF5340 PDK/DK (Cortex-M33 Application MCU)
Gyorgy Szingdb9783c2019-04-17 21:08:48 +020035
36The files related to the supported platforms are contained under the
37``platform`` subfolder. The platform specific files are under
38``platform/ext/target``, which is organised by boards
39(e.g. ``platform/ext/target/mps2``), while the folder ``platform/ext/common``
40is used to store source and header files which are platform generic.
41
42More information about subsystems supported by the MPS2+ board can be found in:
43`MPS2+ homepage <https://developer.arm.com/products/system-design/development-boards/fpga-prototyping-boards/mps2>`__
44
Jamie Foxb8a92702019-06-05 17:19:31 +010045More information about the Musca-A test chip board can be found in:
Gyorgy Szingdb9783c2019-04-17 21:08:48 +020046`Musca-A homepage <https://developer.arm.com/products/system-design/development-boards/iot-test-chips-and-boards/musca-a-test-chip-board>`__
47
48More information about the Musca-B1 test chip board can be found in:
49`Musca-B1 homepage <https://www.arm.com/products/development-tools/development-boards/musca-b1-iot>`__
50
Marton Berke8aae06f2019-11-25 16:46:12 +010051More information about the Musca-S1 test chip board can be found in:
52`Musca-S1 homepage <https://www.arm.com/company/news/2019/05/arm-demonstrates-new-iot-test-chip-and-board>`__
53
Kevin Peng0a142112018-09-21 10:42:22 +080054More information about subsystems supported by the MPS3 board can be found in:
55`MPS3 homepage <https://www.arm.com/products/development-tools/development-boards/mps3>`__
56
Marton Berkee9803662019-11-11 14:11:05 +010057More information about the SSE-200_AWS platform can be found in:
58`SSE-200_AWS product page <https://aws.amazon.com/marketplace/pp/ARM-DesignStart-FPGA-on-Cloud-Cortex-M33-based-pla/B082DMMTLW>`__
59
Marton Berke8c2f5242020-07-28 14:52:29 +020060More information about the Corstone-300 FVPs can be found in:
61`Arm Ecosystem FVPs homepage <https://developer.arm.com/tools-and-software/open-source-software/arm-platforms-software/arm-ecosystem-fvps>`__
62
Ludovic Barre8a77bdd2020-03-26 19:53:07 +010063More information about the STM32L5xx platform can be found in:
64`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>`__
65
Øyvind Rønningstadba9aac02020-09-14 15:19:28 +020066More information about the nRF5340 PDK platform can be found in:
67`nRF5340 PDK product page <https://www.nordicsemi.com/Software-and-tools/Development-Kits/nRF5340-PDK>`__
68
69More information about the nRF9160 DK platform can be found in:
70`nRF9160 DK product page <https://www.nordicsemi.com/Software-and-tools/Development-Kits/nRF9160-DK>`__
71
Gyorgy Szingdb9783c2019-04-17 21:08:48 +020072Generic drivers and startup/scatter files
73=========================================
74The addition of a new platform means the creation of a new subfolder inside
75``target/<board_name>`` to provide an implementation of the drivers currently
76used by TF-M, in particular MPC, PPC, and USART drivers. In addition to the
77drivers, startup and scatter files need to be provided for the supported
78toolchains.
79
80There are also board specific drivers which are used by the board
81platform to interact with the external world, for example during tests, that
82have to be provided, e.g. to blink LEDs or count time in the MPS2 board.
83
84.. Note::
85
Kevin Pengc6d74502020-03-04 16:55:37 +080086 Currently ITS, PS and BL2 bootloader use different flash interface
Gyorgy Szingdb9783c2019-04-17 21:08:48 +020087
88Target configuration files
89==========================
90Inside the base root folder of the selected target, each implementation has to
91provide its own copy of ``target_cfg.c/.h``. This file has target specific
92configuration functions and settings that are called by the TF-M during the
93platform configuration step during TF-M boot. Examples of the configurations
94performed during this phase are the MPC configuration, the SAU configuration,
95or eventually PPC configuration if supported by the hardware platform.
96Similarly, the ``uart_stdout.c`` is used to provide functions needed to redirect
97the stdout on UART (this is currently used by TF-M to log messages).
98
99Platform retarget files
100=======================
101An important part that each new platform has to provide is the set of retarget
102files which are contained inside the ``retarget`` folder. These files define the
103peripheral base addresses for the platform, both for the secure and non-secure
104aliases (when available), and bind those addresses to the base addresses used by
105the devices available in the hardware platform.
106
107***************************
108How to integrate another OS
109***************************
110To work with TF-M, the OS needs to support the Armv8-M architecture and, in
111particular, it needs to be able to run in the non-secure world. More
112information about OS migration to the Armv8-M architecture can be found in the
113:doc:`OS requirements <os_migration_guide_armv8m>`. Depending upon the system
114configuration this may require configuring drivers to use appropriate address
115ranges.
116
117Interface with TF-M
118===================
119The files needed for the interface with TF-M are exported at the
Raef Coles4fed4632020-12-08 12:56:47 +0000120``<install_dir>/interface`` path. The NS side is only allowed to call
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200121TF-M secure functions (veneers) from the NS Thread mode. For this reason, the
Raef Coles4fed4632020-12-08 12:56:47 +0000122API is a collection of functions in the ``<install_dir>/interface/include``
Kevin Pengc6d74502020-03-04 16:55:37 +0800123directory. For example, the interface for the Protected Storage (PS) service
124is described in the file ``psa_ps_api.h`` as a collection of functions that
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200125call service veneer functions. This API is a wrapper for the secure veneers,
126and returns the return value from the service to the caller.
127
Kevin Pengc6d74502020-03-04 16:55:37 +0800128The protected storage service uses a numerical ID, to identify the clients that
129use the service. For details see
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200130:doc:`ns client identification documentation <tfm_ns_client_identification>`.
131
132Interface with non-secure world regression tests
133================================================
134A non-secure application that wants to run the non-secure regression tests
135needs to call the ``tfm_non_secure_client_run_tests()``. This function is
136exported into the header file ``test_framework_integ_test.h`` inside the
137``<build_dir>/install`` folder structure in the test specific files,
138i.e. ``<build_dir>/install/export/tfm/test/inc``. The non-secure regression
139tests are precompiled and delivered as a static library which is available in
140``<build_dir>/install/export/tfm/test/lib``, so that the non-secure application
141needs to link against the library to be able to invoke the
Kevin Pengc6d74502020-03-04 16:55:37 +0800142``tfm_non_secure_client_run_tests()`` function. The PS non-secure side
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200143regression tests rely on some OS functionality e.g. threads, mutexes etc. These
144functions comply with CMSIS RTOS2 standard and have been exported as thin
145wrappers defined in ``os_wrapper.h`` contained in
146``<build_dir>/install/export/tfm/test/inc``. OS needs to provide the
147implementation of these wrappers to be able to run the tests.
148
149NS client Identification
150========================
151See
152:doc:`ns client identification documentation <tfm_ns_client_identification>`.
153
Mate Toth-Pal12d7a182019-04-28 14:05:21 +0200154*********************
155Non-secure interrupts
156*********************
157Non-secure interrupts are allowed to preempt Secure thread mode.
158With the current implementation, a NSPE task can spoof the identity of another
159NSPE task. This is an issue only when NSPE has provisions for task isolation.
160Note, that ``AIRCR.PRIS`` is still set to restrict the priority range available
161to NS interrupts to the lower half of available priorities so that it wouldn't
162be possible for any non-secure interrupt to preempt a higher-priority secure
163interrupt.
164
Raef Coles558487a2020-10-29 13:09:44 +0000165**********************************
166Integration with non-Cmake systems
167**********************************
168
169Generated Files
170===============
171
172Files that are derived from PSA manifests are generated at build-time by cmake.
173For integration with systems that do no use cmake, the files must be generated
174manually.
175
176The ``tools/tfm_parse_manifest_list.py`` script can be invoked manually. Some
177arguments will be needed to be provided. Please refer to
178``tfm_parse_manifest_list.py --help`` for more details.
179
180Some variables are used in the template files, these will need to be set in the
181environment before the script will succeed when the script is not run via cmake.
182
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200183--------------
184
Raef Colesa198a442020-11-24 11:42:53 +0000185*Copyright (c) 2017-2021, Arm Limited. All rights reserved.*