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