blob: 6b3ae7aad2e61077c4127c608a0e00ee9e72e73a [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*****************
Anton Komlev3356ba32022-03-31 22:02:11 +010010Follow the :doc:`Build instructions </technical_references/instructions/tfm_build_instruction>`.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +020011
12********************************************************
13How to export files for building non-secure applications
14********************************************************
Anton Komlev3356ba32022-03-31 22:02:11 +010015Explained in the :doc:`Build instructions </technical_references/instructions/tfm_build_instruction>`.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +020016
17*************************
18How to add a new platform
19*************************
Robert Wakim12018a12021-06-29 11:47:03 +010020
Anton Komlev3356ba32022-03-31 22:02:11 +010021:doc:`Porting TF-M to a New Hardware </integration_guide/porting_TFM_to_a_new_hardware>`
Robert Wakim12018a12021-06-29 11:47:03 +010022contains guidance on how to add a new platform.
23
Gyorgy Szingdb9783c2019-04-17 21:08:48 +020024***************************
25How to integrate another OS
26***************************
David Hu5079a042021-04-07 17:16:59 +080027
28OS migration to Armv8-M platforms
29=================================
30To work with TF-M on Armv8-M platforms, the OS needs to support the Armv8-M
31architecture and, in particular, it needs to be able to run in the non-secure
32world. More information about OS migration to the Armv8-M architecture can be
33found in the :doc:`OS requirements <os_migration_guide_armv8m>`. Depending upon
34the system configuration this may require configuring drivers to use appropriate
35address ranges.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +020036
37Interface with TF-M
38===================
39The files needed for the interface with TF-M are exported at the
Raef Coles4fed4632020-12-08 12:56:47 +000040``<install_dir>/interface`` path. The NS side is only allowed to call
David Hu5079a042021-04-07 17:16:59 +080041TF-M secure functions (veneers) from the NS Thread mode.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +020042
David Hu5079a042021-04-07 17:16:59 +080043TF-M interface header files are exported in ``<install_dir>/interface/include``
44directory. For example, the Protected Storage (PS) service PSA API is declared
45in the file ``<install_dir>/interface/include/psa/protected_storage.h``.
46
47TF-M also exports a reference implementation of PSA APIs for NS clients in the
48``<install_dir>/interface/src``.
49
50On Armv8-M TrustZone based platforms, NS OS shall implement interface API
51``tfm_ns_interface_dispatch()`` to integrate with TF-M implementation of PSA
52APIs. See ``interface/include/tfm_ns_interface.h`` for the detailed declaration
53of ``tfm_ns_interface_dispatch()``.
54TF-M provides an example of ``tfm_ns_interface_dispatch()`` implementation on
55Armv8-M TrustZone based platforms. In this example, NS OS calls mutex in
56``tfm_ns_interface_dispatch()`` to synchronize multiple NS client calls to TF-M.
57See ``interface/src/tfm_ns_interface.c.example`` for more details.
58
59TF-M provides a reference implementation of NS mailbox on multi-core platforms,
60under folder ``interface/src/multi_core``.
Anton Komlev3356ba32022-03-31 22:02:11 +010061See :doc:`Mailbox design </technical_references/design_docs/dual-cpu/mailbox_design_on_dual_core_system>`
David Hu5079a042021-04-07 17:16:59 +080062for TF-M multi-core mailbox design.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +020063
64Interface with non-secure world regression tests
65================================================
66A non-secure application that wants to run the non-secure regression tests
67needs to call the ``tfm_non_secure_client_run_tests()``. This function is
68exported into the header file ``test_framework_integ_test.h`` inside the
69``<build_dir>/install`` folder structure in the test specific files,
70i.e. ``<build_dir>/install/export/tfm/test/inc``. The non-secure regression
71tests are precompiled and delivered as a static library which is available in
72``<build_dir>/install/export/tfm/test/lib``, so that the non-secure application
73needs to link against the library to be able to invoke the
Kevin Pengc6d74502020-03-04 16:55:37 +080074``tfm_non_secure_client_run_tests()`` function. The PS non-secure side
Gyorgy Szingdb9783c2019-04-17 21:08:48 +020075regression tests rely on some OS functionality e.g. threads, mutexes etc. These
76functions comply with CMSIS RTOS2 standard and have been exported as thin
77wrappers defined in ``os_wrapper.h`` contained in
78``<build_dir>/install/export/tfm/test/inc``. OS needs to provide the
79implementation of these wrappers to be able to run the tests.
80
81NS client Identification
82========================
David Wang96787522021-09-22 20:51:01 +080083
84The NS client identification (NSID) is specified by either SPM or NSPE RTOS.
85If SPM manages the NSID (default option), then the same NSID (-1) will be used
86for all connections from NS clients.
87For the case that NSPE RTOS manages the NSID and/or different NSIDs should be
88used for different NS clients. See
Anton Komlev3356ba32022-03-31 22:02:11 +010089:doc:`Non-secure Client Extension Integration Guide </integration_guide/non-secure_client_extension_integration_guide>`.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +020090
Mate Toth-Pal12d7a182019-04-28 14:05:21 +020091*********************
92Non-secure interrupts
93*********************
94Non-secure interrupts are allowed to preempt Secure thread mode.
95With the current implementation, a NSPE task can spoof the identity of another
96NSPE task. This is an issue only when NSPE has provisions for task isolation.
97Note, that ``AIRCR.PRIS`` is still set to restrict the priority range available
98to NS interrupts to the lower half of available priorities so that it wouldn't
99be possible for any non-secure interrupt to preempt a higher-priority secure
100interrupt.
101
Raef Coles558487a2020-10-29 13:09:44 +0000102**********************************
103Integration with non-Cmake systems
104**********************************
105
106Generated Files
107===============
108
109Files that are derived from PSA manifests are generated at build-time by cmake.
110For integration with systems that do no use cmake, the files must be generated
111manually.
112
113The ``tools/tfm_parse_manifest_list.py`` script can be invoked manually. Some
114arguments will be needed to be provided. Please refer to
115``tfm_parse_manifest_list.py --help`` for more details.
116
117Some variables are used in the template files, these will need to be set in the
118environment before the script will succeed when the script is not run via cmake.
119
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200120--------------
121
Gabor Abonyi25c955b2022-01-13 09:58:22 +0100122*Copyright (c) 2017-2022, Arm Limited. All rights reserved.*