blob: cf4fd2e67cd02e54af1196e6991ba802ec514e89 [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*****************
Summer Qinabf66982021-04-06 17:22:15 +080010Follow the :doc:`Build instructions </docs/getting_started/tfm_build_instruction>`.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +020011
12********************************************************
13How to export files for building non-secure applications
14********************************************************
Summer Qinabf66982021-04-06 17:22:15 +080015Explained in the :doc:`Build instructions </docs/getting_started/tfm_build_instruction>`.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +020016
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 Berke07fc95f2020-08-18 15:24:14 +020024- Corstone-300 Ecosystem FVP (Cortex-M55 SSE-300 MPS2+)
Marton Berke8c2f5242020-07-28 14:52:29 +020025- Corstone-300 Ethos-U55 FVP (Cortex-M55 plus Ethos-U55 SSE-300 MPS3)
Gyorgy Szingdb9783c2019-04-17 21:08:48 +020026- Musca-B1 test chip board (Cortex-M33 SSE-200 subsystem)
Marton Berke8aae06f2019-11-25 16:46:12 +010027- Musca-S1 test chip board (Cortex-M33 SSE-200 subsystem)
Kevin Peng0a142112018-09-21 10:42:22 +080028- CoreLink SSE-200 Subsystem for MPS3 (AN524)
Gabor Tothf07e92e2020-11-20 13:55:06 +010029- Corstone SSE-300 with Ethos-U55 Example Subsystem for MPS3 (AN547)
Ludovic Barre8a77bdd2020-03-26 19:53:07 +010030- STM32L5xx: Cortex-M33 based platform (STM32L562 and STM32L552 socs)
Øyvind Rønningstadba9aac02020-09-14 15:19:28 +020031- nRF9160 DK (Cortex-M33)
Andrzej Głąbekaa74ab62021-04-20 11:46:27 +020032- nRF5340 DK (Cortex-M33 Application MCU)
Gyorgy Szingdb9783c2019-04-17 21:08:48 +020033
34The files related to the supported platforms are contained under the
35``platform`` subfolder. The platform specific files are under
36``platform/ext/target``, which is organised by boards
37(e.g. ``platform/ext/target/mps2``), while the folder ``platform/ext/common``
38is used to store source and header files which are platform generic.
39
40More information about subsystems supported by the MPS2+ board can be found in:
41`MPS2+ homepage <https://developer.arm.com/products/system-design/development-boards/fpga-prototyping-boards/mps2>`__
42
Gabor Tothf07e92e2020-11-20 13:55:06 +010043More information about subsystems supported by the MPS3 board can be found in:
44`MPS3 homepage <https://developer.arm.com/products/system-design/development-boards/fpga-prototyping-boards/mps3>`__
45
Gyorgy Szingdb9783c2019-04-17 21:08:48 +020046More information about the Musca-B1 test chip board can be found in:
47`Musca-B1 homepage <https://www.arm.com/products/development-tools/development-boards/musca-b1-iot>`__
48
Marton Berke8aae06f2019-11-25 16:46:12 +010049More information about the Musca-S1 test chip board can be found in:
50`Musca-S1 homepage <https://www.arm.com/company/news/2019/05/arm-demonstrates-new-iot-test-chip-and-board>`__
51
Kevin Peng0a142112018-09-21 10:42:22 +080052More information about subsystems supported by the MPS3 board can be found in:
53`MPS3 homepage <https://www.arm.com/products/development-tools/development-boards/mps3>`__
54
Marton Berke8c2f5242020-07-28 14:52:29 +020055More information about the Corstone-300 FVPs can be found in:
56`Arm Ecosystem FVPs homepage <https://developer.arm.com/tools-and-software/open-source-software/arm-platforms-software/arm-ecosystem-fvps>`__
57
Ludovic Barre8a77bdd2020-03-26 19:53:07 +010058More information about the STM32L5xx platform can be found in:
59`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>`__
60
Andrzej Głąbekaa74ab62021-04-20 11:46:27 +020061More information about the nRF5340 DK platform can be found in:
62`nRF5340 DK product page <https://www.nordicsemi.com/Software-and-tools/Development-Kits/nRF5340-DK>`__
Øyvind Rønningstadba9aac02020-09-14 15:19:28 +020063
64More information about the nRF9160 DK platform can be found in:
65`nRF9160 DK product page <https://www.nordicsemi.com/Software-and-tools/Development-Kits/nRF9160-DK>`__
66
Gyorgy Szingdb9783c2019-04-17 21:08:48 +020067Generic drivers and startup/scatter files
68=========================================
69The addition of a new platform means the creation of a new subfolder inside
70``target/<board_name>`` to provide an implementation of the drivers currently
71used by TF-M, in particular MPC, PPC, and USART drivers. In addition to the
72drivers, startup and scatter files need to be provided for the supported
73toolchains.
74
75There are also board specific drivers which are used by the board
76platform to interact with the external world, for example during tests, that
77have to be provided, e.g. to blink LEDs or count time in the MPS2 board.
78
79.. Note::
80
Kevin Pengc6d74502020-03-04 16:55:37 +080081 Currently ITS, PS and BL2 bootloader use different flash interface
Gyorgy Szingdb9783c2019-04-17 21:08:48 +020082
83Target configuration files
84==========================
85Inside the base root folder of the selected target, each implementation has to
86provide its own copy of ``target_cfg.c/.h``. This file has target specific
87configuration functions and settings that are called by the TF-M during the
88platform configuration step during TF-M boot. Examples of the configurations
89performed during this phase are the MPC configuration, the SAU configuration,
90or eventually PPC configuration if supported by the hardware platform.
91Similarly, the ``uart_stdout.c`` is used to provide functions needed to redirect
92the stdout on UART (this is currently used by TF-M to log messages).
93
94Platform retarget files
95=======================
96An important part that each new platform has to provide is the set of retarget
97files which are contained inside the ``retarget`` folder. These files define the
98peripheral base addresses for the platform, both for the secure and non-secure
99aliases (when available), and bind those addresses to the base addresses used by
100the devices available in the hardware platform.
101
102***************************
103How to integrate another OS
104***************************
David Hu5079a042021-04-07 17:16:59 +0800105
106OS migration to Armv8-M platforms
107=================================
108To work with TF-M on Armv8-M platforms, the OS needs to support the Armv8-M
109architecture and, in particular, it needs to be able to run in the non-secure
110world. More information about OS migration to the Armv8-M architecture can be
111found in the :doc:`OS requirements <os_migration_guide_armv8m>`. Depending upon
112the system configuration this may require configuring drivers to use appropriate
113address ranges.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200114
115Interface with TF-M
116===================
117The files needed for the interface with TF-M are exported at the
Raef Coles4fed4632020-12-08 12:56:47 +0000118``<install_dir>/interface`` path. The NS side is only allowed to call
David Hu5079a042021-04-07 17:16:59 +0800119TF-M secure functions (veneers) from the NS Thread mode.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200120
David Hu5079a042021-04-07 17:16:59 +0800121TF-M interface header files are exported in ``<install_dir>/interface/include``
122directory. For example, the Protected Storage (PS) service PSA API is declared
123in the file ``<install_dir>/interface/include/psa/protected_storage.h``.
124
125TF-M also exports a reference implementation of PSA APIs for NS clients in the
126``<install_dir>/interface/src``.
127
128On Armv8-M TrustZone based platforms, NS OS shall implement interface API
129``tfm_ns_interface_dispatch()`` to integrate with TF-M implementation of PSA
130APIs. See ``interface/include/tfm_ns_interface.h`` for the detailed declaration
131of ``tfm_ns_interface_dispatch()``.
132TF-M provides an example of ``tfm_ns_interface_dispatch()`` implementation on
133Armv8-M TrustZone based platforms. In this example, NS OS calls mutex in
134``tfm_ns_interface_dispatch()`` to synchronize multiple NS client calls to TF-M.
135See ``interface/src/tfm_ns_interface.c.example`` for more details.
136
137TF-M provides a reference implementation of NS mailbox on multi-core platforms,
138under folder ``interface/src/multi_core``.
139See :doc:`Mailbox design </docs/technical_references/dual-cpu/mailbox_design_on_dual_core_system>`
140for TF-M multi-core mailbox design.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200141
142Interface with non-secure world regression tests
143================================================
144A non-secure application that wants to run the non-secure regression tests
145needs to call the ``tfm_non_secure_client_run_tests()``. This function is
146exported into the header file ``test_framework_integ_test.h`` inside the
147``<build_dir>/install`` folder structure in the test specific files,
148i.e. ``<build_dir>/install/export/tfm/test/inc``. The non-secure regression
149tests are precompiled and delivered as a static library which is available in
150``<build_dir>/install/export/tfm/test/lib``, so that the non-secure application
151needs to link against the library to be able to invoke the
Kevin Pengc6d74502020-03-04 16:55:37 +0800152``tfm_non_secure_client_run_tests()`` function. The PS non-secure side
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200153regression tests rely on some OS functionality e.g. threads, mutexes etc. These
154functions comply with CMSIS RTOS2 standard and have been exported as thin
155wrappers defined in ``os_wrapper.h`` contained in
156``<build_dir>/install/export/tfm/test/inc``. OS needs to provide the
157implementation of these wrappers to be able to run the tests.
158
159NS client Identification
160========================
161See
Summer Qinabf66982021-04-06 17:22:15 +0800162:doc:`ns client identification documentation </docs/technical_references/tfm_ns_client_identification>`.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200163
Mate Toth-Pal12d7a182019-04-28 14:05:21 +0200164*********************
165Non-secure interrupts
166*********************
167Non-secure interrupts are allowed to preempt Secure thread mode.
168With the current implementation, a NSPE task can spoof the identity of another
169NSPE task. This is an issue only when NSPE has provisions for task isolation.
170Note, that ``AIRCR.PRIS`` is still set to restrict the priority range available
171to NS interrupts to the lower half of available priorities so that it wouldn't
172be possible for any non-secure interrupt to preempt a higher-priority secure
173interrupt.
174
Raef Coles558487a2020-10-29 13:09:44 +0000175**********************************
176Integration with non-Cmake systems
177**********************************
178
179Generated Files
180===============
181
182Files that are derived from PSA manifests are generated at build-time by cmake.
183For integration with systems that do no use cmake, the files must be generated
184manually.
185
186The ``tools/tfm_parse_manifest_list.py`` script can be invoked manually. Some
187arguments will be needed to be provided. Please refer to
188``tfm_parse_manifest_list.py --help`` for more details.
189
190Some variables are used in the template files, these will need to be set in the
191environment before the script will succeed when the script is not run via cmake.
192
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200193--------------
194
Raef Colesa198a442020-11-24 11:42:53 +0000195*Copyright (c) 2017-2021, Arm Limited. All rights reserved.*