Galanakis, Minos | 41f8597 | 2019-09-30 15:56:40 +0100 | [diff] [blame] | 1 | ################# |
| 2 | Integration guide |
| 3 | ################# |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 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 | |
| 7 | ***************** |
| 8 | How to build TF-M |
| 9 | ***************** |
Anton Komlev | 3356ba3 | 2022-03-31 22:02:11 +0100 | [diff] [blame] | 10 | Follow the :doc:`Build instructions </technical_references/instructions/tfm_build_instruction>`. |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 11 | |
| 12 | ******************************************************** |
| 13 | How to export files for building non-secure applications |
| 14 | ******************************************************** |
Anton Komlev | 3356ba3 | 2022-03-31 22:02:11 +0100 | [diff] [blame] | 15 | Explained in the :doc:`Build instructions </technical_references/instructions/tfm_build_instruction>`. |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 16 | |
| 17 | ************************* |
| 18 | How to add a new platform |
| 19 | ************************* |
Robert Wakim | 12018a1 | 2021-06-29 11:47:03 +0100 | [diff] [blame] | 20 | |
Anton Komlev | 3356ba3 | 2022-03-31 22:02:11 +0100 | [diff] [blame] | 21 | :doc:`Porting TF-M to a New Hardware </integration_guide/porting_TFM_to_a_new_hardware>` |
Robert Wakim | 12018a1 | 2021-06-29 11:47:03 +0100 | [diff] [blame] | 22 | contains guidance on how to add a new platform. |
| 23 | |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 24 | *************************** |
| 25 | How to integrate another OS |
| 26 | *************************** |
David Hu | 5079a04 | 2021-04-07 17:16:59 +0800 | [diff] [blame] | 27 | |
| 28 | OS migration to Armv8-M platforms |
| 29 | ================================= |
| 30 | To work with TF-M on Armv8-M platforms, the OS needs to support the Armv8-M |
| 31 | architecture and, in particular, it needs to be able to run in the non-secure |
| 32 | world. More information about OS migration to the Armv8-M architecture can be |
| 33 | found in the :doc:`OS requirements <os_migration_guide_armv8m>`. Depending upon |
| 34 | the system configuration this may require configuring drivers to use appropriate |
| 35 | address ranges. |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 36 | |
| 37 | Interface with TF-M |
| 38 | =================== |
| 39 | The files needed for the interface with TF-M are exported at the |
Raef Coles | 4fed463 | 2020-12-08 12:56:47 +0000 | [diff] [blame] | 40 | ``<install_dir>/interface`` path. The NS side is only allowed to call |
David Hu | 5079a04 | 2021-04-07 17:16:59 +0800 | [diff] [blame] | 41 | TF-M secure functions (veneers) from the NS Thread mode. |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 42 | |
David Hu | 5079a04 | 2021-04-07 17:16:59 +0800 | [diff] [blame] | 43 | TF-M interface header files are exported in ``<install_dir>/interface/include`` |
| 44 | directory. For example, the Protected Storage (PS) service PSA API is declared |
| 45 | in the file ``<install_dir>/interface/include/psa/protected_storage.h``. |
| 46 | |
| 47 | TF-M also exports a reference implementation of PSA APIs for NS clients in the |
| 48 | ``<install_dir>/interface/src``. |
| 49 | |
| 50 | On Armv8-M TrustZone based platforms, NS OS shall implement interface API |
| 51 | ``tfm_ns_interface_dispatch()`` to integrate with TF-M implementation of PSA |
| 52 | APIs. See ``interface/include/tfm_ns_interface.h`` for the detailed declaration |
| 53 | of ``tfm_ns_interface_dispatch()``. |
| 54 | TF-M provides an example of ``tfm_ns_interface_dispatch()`` implementation on |
| 55 | Armv8-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. |
| 57 | See ``interface/src/tfm_ns_interface.c.example`` for more details. |
| 58 | |
| 59 | TF-M provides a reference implementation of NS mailbox on multi-core platforms, |
| 60 | under folder ``interface/src/multi_core``. |
Anton Komlev | 3356ba3 | 2022-03-31 22:02:11 +0100 | [diff] [blame] | 61 | See :doc:`Mailbox design </technical_references/design_docs/dual-cpu/mailbox_design_on_dual_core_system>` |
David Hu | 5079a04 | 2021-04-07 17:16:59 +0800 | [diff] [blame] | 62 | for TF-M multi-core mailbox design. |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 63 | |
| 64 | Interface with non-secure world regression tests |
| 65 | ================================================ |
| 66 | A non-secure application that wants to run the non-secure regression tests |
| 67 | needs to call the ``tfm_non_secure_client_run_tests()``. This function is |
| 68 | exported into the header file ``test_framework_integ_test.h`` inside the |
| 69 | ``<build_dir>/install`` folder structure in the test specific files, |
| 70 | i.e. ``<build_dir>/install/export/tfm/test/inc``. The non-secure regression |
| 71 | tests 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 |
| 73 | needs to link against the library to be able to invoke the |
Kevin Peng | c6d7450 | 2020-03-04 16:55:37 +0800 | [diff] [blame] | 74 | ``tfm_non_secure_client_run_tests()`` function. The PS non-secure side |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 75 | regression tests rely on some OS functionality e.g. threads, mutexes etc. These |
| 76 | functions comply with CMSIS RTOS2 standard and have been exported as thin |
| 77 | wrappers defined in ``os_wrapper.h`` contained in |
| 78 | ``<build_dir>/install/export/tfm/test/inc``. OS needs to provide the |
| 79 | implementation of these wrappers to be able to run the tests. |
| 80 | |
| 81 | NS client Identification |
| 82 | ======================== |
David Wang | 9678752 | 2021-09-22 20:51:01 +0800 | [diff] [blame] | 83 | |
| 84 | The NS client identification (NSID) is specified by either SPM or NSPE RTOS. |
| 85 | If SPM manages the NSID (default option), then the same NSID (-1) will be used |
| 86 | for all connections from NS clients. |
| 87 | For the case that NSPE RTOS manages the NSID and/or different NSIDs should be |
| 88 | used for different NS clients. See |
Anton Komlev | 3356ba3 | 2022-03-31 22:02:11 +0100 | [diff] [blame] | 89 | :doc:`Non-secure Client Extension Integration Guide </integration_guide/non-secure_client_extension_integration_guide>`. |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 90 | |
Mate Toth-Pal | 12d7a18 | 2019-04-28 14:05:21 +0200 | [diff] [blame] | 91 | ********************* |
| 92 | Non-secure interrupts |
| 93 | ********************* |
| 94 | Non-secure interrupts are allowed to preempt Secure thread mode. |
| 95 | With the current implementation, a NSPE task can spoof the identity of another |
| 96 | NSPE task. This is an issue only when NSPE has provisions for task isolation. |
| 97 | Note, that ``AIRCR.PRIS`` is still set to restrict the priority range available |
| 98 | to NS interrupts to the lower half of available priorities so that it wouldn't |
| 99 | be possible for any non-secure interrupt to preempt a higher-priority secure |
| 100 | interrupt. |
| 101 | |
Raef Coles | 558487a | 2020-10-29 13:09:44 +0000 | [diff] [blame] | 102 | ********************************** |
| 103 | Integration with non-Cmake systems |
| 104 | ********************************** |
| 105 | |
| 106 | Generated Files |
| 107 | =============== |
| 108 | |
| 109 | Files that are derived from PSA manifests are generated at build-time by cmake. |
| 110 | For integration with systems that do no use cmake, the files must be generated |
| 111 | manually. |
| 112 | |
| 113 | The ``tools/tfm_parse_manifest_list.py`` script can be invoked manually. Some |
| 114 | arguments will be needed to be provided. Please refer to |
| 115 | ``tfm_parse_manifest_list.py --help`` for more details. |
| 116 | |
| 117 | Some variables are used in the template files, these will need to be set in the |
| 118 | environment before the script will succeed when the script is not run via cmake. |
| 119 | |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 120 | -------------- |
| 121 | |
Gabor Abonyi | 25c955b | 2022-01-13 09:58:22 +0100 | [diff] [blame] | 122 | *Copyright (c) 2017-2022, Arm Limited. All rights reserved.* |