blob: 22dfa967b6cceed5206a7c1fb6dd7a74eda89641 [file] [log] [blame]
Anton Komlev91281f02022-04-22 09:24:20 +01001#################
Summer Qinabf66982021-04-06 17:22:15 +08002Integration Guide
Anton Komlev91281f02022-04-22 09:24:20 +01003#################
4The purpose of this document is to provide a guide on how to integrate TF-M
5with other hardware platforms and operating systems.
6
Minos Galanakise4094012020-06-12 14:25:34 +01007.. toctree::
8 :maxdepth: 1
Minos Galanakise4094012020-06-12 14:25:34 +01009
Anton Komleve69cf682023-01-31 11:59:25 +000010 Source Structure <source_structure/index>
11 SPM Backends <spm_backends.rst>
12 NS client integration <non-secure_client_extension_integration_guide.rst>
Anton Komlev91281f02022-04-22 09:24:20 +010013 OS migration to Armv8-M <os_migration_guide_armv8m.rst>
Anton Komleve69cf682023-01-31 11:59:25 +000014 Floating-Point Support <tfm_fpu_support.rst>
15 Secure Interrupt <tfm_secure_irq_integration_guide.rst>
16 Platform Provisioning <platform_provisioning.rst>
Nicola Mazzucatofc1bf772024-05-07 16:21:33 +010017 Branch Protection <branch_protection.rst>
Anton Komlev91281f02022-04-22 09:24:20 +010018
19.. toctree::
20 :maxdepth: 2
21
22 platform/index
23 services/index
24
Anton Komlev91281f02022-04-22 09:24:20 +010025*****************
26How to build TF-M
27*****************
Anton Komlev0dbe8f12022-06-17 16:48:12 +010028Follow the :doc:`Build instructions </building/tfm_build_instruction>`.
Anton Komlev91281f02022-04-22 09:24:20 +010029
30********************************************************
31How to export files for building non-secure applications
32********************************************************
Anton Komlev0dbe8f12022-06-17 16:48:12 +010033Explained in the :doc:`Build instructions </building/tfm_build_instruction>`.
Anton Komlev91281f02022-04-22 09:24:20 +010034
35*************************
36How to add a new platform
37*************************
38
Antonio de Angelis671c9712023-02-15 22:40:32 +000039:doc:`Porting TF-M to a New Hardware </integration_guide/platform/porting_tfm_to_a_new_hardware>`
Anton Komlev91281f02022-04-22 09:24:20 +010040contains guidance on how to add a new platform.
41
42***************************
43How to integrate another OS
44***************************
45
46OS migration to Armv8-M platforms
47=================================
48To work with TF-M on Armv8-M platforms, the OS needs to support the Armv8-M
49architecture and, in particular, it needs to be able to run in the non-secure
50world. More information about OS migration to the Armv8-M architecture can be
51found in the :doc:`OS requirements <os_migration_guide_armv8m>`. Depending upon
52the system configuration this may require configuring drivers to use appropriate
53address ranges.
54
55Interface with TF-M
56===================
57The files needed for the interface with TF-M are exported at the
58``<install_dir>/interface`` path. The NS side is only allowed to call
59TF-M secure functions (veneers) from the NS Thread mode.
60
61TF-M interface header files are exported in ``<install_dir>/interface/include``
62directory. For example, the Protected Storage (PS) service PSA API is declared
63in the file ``<install_dir>/interface/include/psa/protected_storage.h``.
64
65TF-M also exports a reference implementation of PSA APIs for NS clients in the
66``<install_dir>/interface/src``.
67
BohdanHunkof871df02023-02-03 14:36:41 +020068On Armv8-M TrustZone based platforms, NS OS uses ``tfm_ns_interface_dispatch()``
69to integrate with TF-M implementation of PSA APIs. TF-M provides a reference
70implementation of this function for RTOS and bare metal use cases.
71RTOS implementation of ``tfm_ns_interface_dispatch()`` (provided in
72``interface\src\os_wrapper\tfm_ns_interface_rtos.c``) uses mutex to provide
73multithread safety. Mutex wrapper functions defined in
74``interface/include/os_wrapper/mutex.h`` are expected to be provided by NS RTOS.
75When reference RTOS implementation of dispatch function is used NS application
76should call ``tfm_ns_interface_init()`` function before first PSA API call.
77Bare metal implementation ``tfm_ns_interface_dispatch()`` (provided in
78``interface\src\os_wrapper\tfm_ns_interface_bare_metal.c``) does not
79provide multithread safety and does not require implementation of mutex
80interface.
81If needed, instead of using reference implementation, NS application may provide
82its own implementation of ``tfm_ns_interface_dispatch()`` function.
Anton Komlev91281f02022-04-22 09:24:20 +010083
84TF-M provides a reference implementation of NS mailbox on multi-core platforms,
85under folder ``interface/src/multi_core``.
Anton Komlevff7cbae2023-01-12 16:28:26 +000086See :doc:`Mailbox design </design_docs/dual-cpu/mailbox_design_on_dual_core_system>`
Anton Komlev91281f02022-04-22 09:24:20 +010087for TF-M multi-core mailbox design.
88
89Interface with non-secure world regression tests
90================================================
91A non-secure application that wants to run the non-secure regression tests
92needs to call the ``tfm_non_secure_client_run_tests()``. This function is
93exported into the header file ``test_framework_integ_test.h`` inside the
94``<build_dir>/install`` folder structure in the test specific files,
95i.e. ``<build_dir>/install/export/tfm/test/inc``. The non-secure regression
96tests are precompiled and delivered as a static library which is available in
97``<build_dir>/install/export/tfm/test/lib``, so that the non-secure application
98needs to link against the library to be able to invoke the
99``tfm_non_secure_client_run_tests()`` function. The PS non-secure side
100regression tests rely on some OS functionality e.g. threads, mutexes etc. These
101functions comply with CMSIS RTOS2 standard and have been exported as thin
102wrappers defined in ``os_wrapper.h`` contained in
103``<build_dir>/install/export/tfm/test/inc``. OS needs to provide the
104implementation of these wrappers to be able to run the tests.
105
106NS client Identification
107========================
108
109The NS client identification (NSID) is specified by either SPM or NSPE RTOS.
110If SPM manages the NSID (default option), then the same NSID (-1) will be used
111for all connections from NS clients.
112For the case that NSPE RTOS manages the NSID and/or different NSIDs should be
113used for different NS clients. See
114:doc:`Non-secure Client Extension Integration Guide </integration_guide/non-secure_client_extension_integration_guide>`.
115
116*********************
117Non-secure interrupts
118*********************
119Non-secure interrupts are allowed to preempt Secure thread mode.
120With the current implementation, a NSPE task can spoof the identity of another
121NSPE task. This is an issue only when NSPE has provisions for task isolation.
122Note, that ``AIRCR.PRIS`` is still set to restrict the priority range available
123to NS interrupts to the lower half of available priorities so that it wouldn't
124be possible for any non-secure interrupt to preempt a higher-priority secure
125interrupt.
126
Chris Brand80326b72023-03-15 13:07:49 -0700127********************************
128Secure interrupts and scheduling
129********************************
130To ensure correct operation in the general case, the secure scheduler is not
131run after handling a secure interrupt that pre-empted the NSPE. On systems
132with specific constraints, it may be desirable to run the scheduler in this
133situation, which can be done by setting
134``CONFIG_TFM_SCHEDULE_WHEN_NS_INTERRUPTED`` to 1. This could be done if the
135NSPE is known to be a simple, single-threaded application or if non-secure
Antonio de Angelis9d496a52025-01-07 21:18:00 +0000136interrupts cannot preempt the SPE, for example.
Chris Brand80326b72023-03-15 13:07:49 -0700137
Nicola Mazzucato85dac5d2025-01-02 09:11:05 +0000138Note that scheduling also depends on the system topology. If your system has
139multiple cores running multiple NSPEs, then refer to
140:doc:`Scheduling Hybrid Platforms </design_docs/dual-cpu/hybrid_platform_solution>`
141for more details.
142
Anton Komlev91281f02022-04-22 09:24:20 +0100143**********************************
144Integration with non-Cmake systems
145**********************************
146
147Generated Files
148===============
149
150Files that are derived from PSA manifests are generated at build-time by cmake.
151For integration with systems that do no use cmake, the files must be generated
152manually.
153
154The ``tools/tfm_parse_manifest_list.py`` script can be invoked manually. Some
155arguments will be needed to be provided. Please refer to
156``tfm_parse_manifest_list.py --help`` for more details.
157
158Some variables are used in the template files, these will need to be set in the
159environment before the script will succeed when the script is not run via cmake.
Minos Galanakise4094012020-06-12 14:25:34 +0100160
161--------------
162
Anton Komlev91281f02022-04-22 09:24:20 +0100163*Copyright (c) 2017-2022, Arm Limited. All rights reserved.*
BohdanHunkof871df02023-02-03 14:36:41 +0200164*Copyright (c) 2023 Cypress Semiconductor Corporation (an Infineon company)
165or an affiliate of Cypress Semiconductor Corporation. All rights reserved.*