Galanakis, Minos | 41f8597 | 2019-09-30 15:56:40 +0100 | [diff] [blame] | 1 | ################## |
| 2 | Build instructions |
| 3 | ################## |
Anton Komlev | 0dbe8f1 | 2022-06-17 16:48:12 +0100 | [diff] [blame] | 4 | |
Anton Komlev | 4b1c05c | 2023-10-06 20:22:58 +0100 | [diff] [blame^] | 5 | .. warning:: |
| 6 | The build process was changed a lot in Q3 2023 and included into the release after v1.9. |
| 7 | For building instructions for early versions please refer to the documentation of respective |
| 8 | versions. |
| 9 | |
| 10 | As you know from the :doc:`introduction </introduction/readme>` TF-M implements |
| 11 | :term:`SPE` with a set of secure services. |
| 12 | TF-M application as :term:`NSPE` client uses those services through isolation boundary via |
| 13 | :term:`PSA-FF-M` API. |
| 14 | Both SPE and NSPE are separate binaries and built independently. |
| 15 | This document describes the process of building both of them and the interface between. |
| 16 | SPE and NSPE binaries are combined and signed making the final image for downloading onto targets. |
| 17 | |
| 18 | TF-M uses `CMake <https://cmake.org/overview/>`__ **v3.15** or higher. |
| 19 | Before starting please make sure you have all required software installed and |
| 20 | configured as explained in the |
Anton Komlev | 3356ba3 | 2022-03-31 22:02:11 +0100 | [diff] [blame] | 21 | :doc:`TF-M getting started </getting_started/tfm_getting_started>`. |
Anton Komlev | 4b1c05c | 2023-10-06 20:22:58 +0100 | [diff] [blame^] | 22 | |
| 23 | .. contents:: Contents |
| 24 | :depth: 2 |
| 25 | :local: |
| 26 | |
| 27 | The additional building materials you can find in the following links:TF-M source folder |
Anton Komlev | 91281f0 | 2022-04-22 09:24:20 +0100 | [diff] [blame] | 28 | |
| 29 | .. toctree:: |
| 30 | :maxdepth: 1 |
| 31 | |
Anton Komlev | 4b1c05c | 2023-10-06 20:22:58 +0100 | [diff] [blame^] | 32 | Run TF-M tests and applications <run_tfm_examples_on_arm_platforms> |
Anton Komlev | 0dbe8f1 | 2022-06-17 16:48:12 +0100 | [diff] [blame] | 33 | Building the documentation <documentation_generation> |
| 34 | IAR toolchain <tfm_build_instruction_iar> |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 35 | |
Anton Komlev | 4b1c05c | 2023-10-06 20:22:58 +0100 | [diff] [blame^] | 36 | .. _Building SPE: |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 37 | |
Anton Komlev | 4b1c05c | 2023-10-06 20:22:58 +0100 | [diff] [blame^] | 38 | ******************* |
| 39 | Building TF-M (SPE) |
| 40 | ******************* |
| 41 | This build generates the SPE binary and artifacts, necessary for :ref:`Building NSPE`. |
Raef Coles | 1ecb813 | 2020-10-02 15:11:24 +0100 | [diff] [blame] | 42 | |
David Wang | d6fd6af | 2021-06-21 17:17:26 +0800 | [diff] [blame] | 43 | .. _Getting the source-code: |
| 44 | |
Anton Komlev | 4b1c05c | 2023-10-06 20:22:58 +0100 | [diff] [blame^] | 45 | Getting the source code |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 46 | ======================= |
| 47 | .. code-block:: bash |
| 48 | |
Leonardo Sandoval | d7f72d5 | 2020-07-28 18:02:34 -0500 | [diff] [blame] | 49 | cd <base folder> |
Minos Galanakis | 0f39fa5 | 2020-06-08 16:53:53 +0100 | [diff] [blame] | 50 | git clone https://git.trustedfirmware.org/TF-M/trusted-firmware-m.git |
Anton Komlev | b8e3af0 | 2020-08-28 10:23:57 +0100 | [diff] [blame] | 51 | |
Anton Komlev | 4b1c05c | 2023-10-06 20:22:58 +0100 | [diff] [blame^] | 52 | In this documentation, the cloned ``trusted-firmware-m`` repository will be referenced as |
| 53 | ``<TF-M source dir>``. |
| 54 | Additionally, TF-M depends on several external projects, handled by CMake automatically but |
| 55 | you can alter that behaviour using :ref:`Dependency management`. |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 56 | |
Minos Galanakis | ac6b06c | 2020-03-19 12:57:02 +0000 | [diff] [blame] | 57 | .. Note:: |
Anton Komlev | b8e3af0 | 2020-08-28 10:23:57 +0100 | [diff] [blame] | 58 | |
Minos Galanakis | 3b740a1 | 2020-10-15 11:10:26 +0100 | [diff] [blame] | 59 | - For building with Armclang compiler version 6.10.0+, please follow the note |
Anton Komlev | 3356ba3 | 2022-03-31 22:02:11 +0100 | [diff] [blame] | 60 | in :doc:`TF-M getting started </getting_started/tfm_getting_started>`. |
Anton Komlev | b8e3af0 | 2020-08-28 10:23:57 +0100 | [diff] [blame] | 61 | - For building with the IAR toolchain, please see the notes in |
Minos Galanakis | 3b740a1 | 2020-10-15 11:10:26 +0100 | [diff] [blame] | 62 | :doc:`IAR software requirements <tfm_build_instruction_iar>` |
TTornblom | b9e5ed0 | 2020-02-13 16:53:15 +0100 | [diff] [blame] | 63 | |
Anton Komlev | 4b1c05c | 2023-10-06 20:22:58 +0100 | [diff] [blame^] | 64 | Configuring |
| 65 | =========== |
| 66 | TF-M has many config options for configuring and fine-tuning. Please check the |
| 67 | :ref:`tf-m_configuration` section for the details. The **base** (default) configuration |
| 68 | contains only essential components such as SPM and HW platform support hence the |
| 69 | only mandatory argument to TF-M build is a platform name, provided via |
| 70 | CMake command-line option ``-DTFM_PLATFORM=<platform name>``, it can be: |
Anton Komlev | b8e3af0 | 2020-08-28 10:23:57 +0100 | [diff] [blame] | 71 | |
Anton Komlev | 4b1c05c | 2023-10-06 20:22:58 +0100 | [diff] [blame^] | 72 | - A relative path under ``<TF-M source dir>/platform/ext/target``, for example ``arm/mps2/an521``. |
| 73 | - An absolute path of target platform, mainly used for out-of-tree platform build. |
| 74 | - A basename of the target platform folder, for example ``an521``. |
Anton Komlev | b8e3af0 | 2020-08-28 10:23:57 +0100 | [diff] [blame] | 75 | |
Anton Komlev | 4b1c05c | 2023-10-06 20:22:58 +0100 | [diff] [blame^] | 76 | Essential Directories |
| 77 | --------------------- |
| 78 | There are 3 essential directories used by CMake for building TF-M: |
| 79 | |
| 80 | - Source code directory ``<TF-M source dir>`` |
| 81 | - Build directory ``<Build Dir>`` - the location of all intermediate files required to produce |
| 82 | a build target. |
| 83 | - Install directory ``<Artifact Dir>`` - the location of the build output files. |
| 84 | |
| 85 | Note:: |
| 86 | It's recommended to use absolute paths for all directories. Relative paths may not fully work. |
| 87 | |
| 88 | .. _Toolchains: |
| 89 | |
| 90 | Toolchains |
| 91 | ---------- |
| 92 | TF-M supports 3 toolchains for cross-compiling and building the project binaries: |
| 93 | |
| 94 | - GNU - **default** |
| 95 | - ArmClang |
| 96 | - IAR |
| 97 | |
| 98 | Each toolchain has a configuration file for the compiler and linker. |
| 99 | Use ``TFM_TOOLCHAIN_FILE`` option to provide a path to a preferred toolchain file or the toolchain |
| 100 | file name. |
| 101 | The default **toolchain_GNUARM.cmake** is selected by `config_base.cmake` |
| 102 | file if the option is omitted. |
| 103 | |
| 104 | .. _Build type: |
Anton Komlev | b8e3af0 | 2020-08-28 10:23:57 +0100 | [diff] [blame] | 105 | |
Anton Komlev | b8e3af0 | 2020-08-28 10:23:57 +0100 | [diff] [blame] | 106 | Build type |
| 107 | ---------- |
Dávid Házi | e50f0a9 | 2022-07-06 14:46:01 +0200 | [diff] [blame] | 108 | By default, a MinSizeRel configuration is built. Alternate build types can be |
Chris Brand | 80266ba | 2022-01-05 09:14:52 -0800 | [diff] [blame] | 109 | specified with the ``CMAKE_BUILD_TYPE`` variable. The possible |
Anton Komlev | b8e3af0 | 2020-08-28 10:23:57 +0100 | [diff] [blame] | 110 | types are: |
| 111 | |
Anton Komlev | 4b1c05c | 2023-10-06 20:22:58 +0100 | [diff] [blame^] | 112 | - Debug |
| 113 | - RelWithDebInfo |
| 114 | - Release |
| 115 | - MinSizeRel - **default** |
Anton Komlev | b8e3af0 | 2020-08-28 10:23:57 +0100 | [diff] [blame] | 116 | |
Anton Komlev | 4b1c05c | 2023-10-06 20:22:58 +0100 | [diff] [blame^] | 117 | Debug symbols are added by default to all builds, but can be removed from |
| 118 | *Release* and *MinSizeRel* builds by setting ``TFM_DEBUG_SYMBOLS`` to `OFF`. |
Sebastian Bøe | b73f176 | 2021-10-28 14:23:13 +0200 | [diff] [blame] | 119 | |
Anton Komlev | 4b1c05c | 2023-10-06 20:22:58 +0100 | [diff] [blame^] | 120 | *RelWithDebInfo*, *Release* and *MinSizeRel* all have different |
| 121 | optimizations turned on and hence will produce smaller, faster code than |
| 122 | *Debug*. *MinSizeRel* will produce the smallest code and hence is often |
| 123 | a good idea on RAM or flash-constrained systems. |
Anton Komlev | b8e3af0 | 2020-08-28 10:23:57 +0100 | [diff] [blame] | 124 | |
Anton Komlev | 4b1c05c | 2023-10-06 20:22:58 +0100 | [diff] [blame^] | 125 | .. _Output files: |
| 126 | |
| 127 | Output files |
| 128 | ------------ |
| 129 | In a successful build, a set of files will be created in the ``<Artifact Dir>``. |
| 130 | By default, it is ``<Build Dir>\api_ns`` subfolder but you can redirect the |
| 131 | output to any location using ``CMAKE_INSTALL_PREFIX`` option. It can be an |
| 132 | absolute path or relative to your current directory. For the contents of the |
| 133 | artifact directory please refer to :ref:`Artifacts structure`. |
| 134 | |
| 135 | Other build parameters |
Anton Komlev | b8e3af0 | 2020-08-28 10:23:57 +0100 | [diff] [blame] | 136 | ---------------------- |
Anton Komlev | 2cd9153 | 2022-11-17 13:36:55 +0000 | [diff] [blame] | 137 | The full list of default options is in ``config/config_base.cmake`` and |
| 138 | explained in :ref:`tfm_cmake_configuration`. Several important options |
| 139 | are listed below. |
Anton Komlev | b8e3af0 | 2020-08-28 10:23:57 +0100 | [diff] [blame] | 140 | |
Xinyu Zhang | 5f9ffeb | 2023-03-31 11:09:45 +0800 | [diff] [blame] | 141 | +----------------------------+------------------------------------------+---------------+ |
| 142 | | Parameter | Description | Default value | |
| 143 | +============================+==========================================+===============+ |
| 144 | | BL2 | Build level 2 secure bootloader. | ON | |
| 145 | +----------------------------+------------------------------------------+---------------+ |
Xinyu Zhang | 5f9ffeb | 2023-03-31 11:09:45 +0800 | [diff] [blame] | 146 | | PROJECT_CONFIG_HEADER_FILE | User defined header file for TF-M config | | |
| 147 | +----------------------------+------------------------------------------+---------------+ |
| 148 | | TFM_ISOLATION_LEVEL | Set TFM isolation level. | 1 | |
| 149 | +----------------------------+------------------------------------------+---------------+ |
Anton Komlev | 4b1c05c | 2023-10-06 20:22:58 +0100 | [diff] [blame^] | 150 | | TFM_PROFILE | See :ref:`tf-m_profiles`. | | |
Xinyu Zhang | 5f9ffeb | 2023-03-31 11:09:45 +0800 | [diff] [blame] | 151 | +----------------------------+------------------------------------------+---------------+ |
| 152 | |
| 153 | Project Config Header File |
| 154 | -------------------------- |
Anton Komlev | 4b1c05c | 2023-10-06 20:22:58 +0100 | [diff] [blame^] | 155 | CMake variable ``PROJECT_CONFIG_HEADER_FILE`` can be set by a user the full path to a |
Xinyu Zhang | 5f9ffeb | 2023-03-31 11:09:45 +0800 | [diff] [blame] | 156 | configuration header file, which is used to fine-tune component options. The detailed reference |
Anton Komlev | 4b1c05c | 2023-10-06 20:22:58 +0100 | [diff] [blame^] | 157 | for the project config header file is in :ref:`Header_configuration`. |
Xinyu Zhang | 5f9ffeb | 2023-03-31 11:09:45 +0800 | [diff] [blame] | 158 | |
Anton Komlev | 4b1c05c | 2023-10-06 20:22:58 +0100 | [diff] [blame^] | 159 | Building binaries |
| 160 | ================= |
Xinyu Zhang | 5f9ffeb | 2023-03-31 11:09:45 +0800 | [diff] [blame] | 161 | |
Anton Komlev | 4b1c05c | 2023-10-06 20:22:58 +0100 | [diff] [blame^] | 162 | The command below shows a general template for building TF-M as a typical CMake project: |
Anton Komlev | b8e3af0 | 2020-08-28 10:23:57 +0100 | [diff] [blame] | 163 | |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 164 | .. code-block:: bash |
| 165 | |
Anton Komlev | 4b1c05c | 2023-10-06 20:22:58 +0100 | [diff] [blame^] | 166 | cmake -S <TF-M source dir> -B <Build Dir> -DTFM_PLATFORM=<platform> |
| 167 | cmake --build <Build Dir> -- install |
Anton Komlev | b8e3af0 | 2020-08-28 10:23:57 +0100 | [diff] [blame] | 168 | |
| 169 | .. Note:: |
Anton Komlev | 4b1c05c | 2023-10-06 20:22:58 +0100 | [diff] [blame^] | 170 | It is recommended to clean up the build directory before re-build if the config |
| 171 | header file is updated. CMake is unable to automatically recognize the |
| 172 | dependency when the header file is defined as a macro. |
Anton Komlev | b8e3af0 | 2020-08-28 10:23:57 +0100 | [diff] [blame] | 173 | |
Anton Komlev | 4b1c05c | 2023-10-06 20:22:58 +0100 | [diff] [blame^] | 174 | Building default configuration for an521 |
| 175 | ---------------------------------------- |
| 176 | |
| 177 | .. code-block:: bash |
| 178 | |
| 179 | cd <TF-M source dir> |
| 180 | cmake -S . -B build -DTFM_PLATFORM=arm/mps2/an521 |
| 181 | cmake --build build -- install |
| 182 | |
| 183 | The command above is intended to do: |
| 184 | - take TF-M sources in the current ``.`` folder |
| 185 | - build SPE in the ``build`` folder |
| 186 | - for **an521** platform |
| 187 | - using GNU toolchain *by default*. Use ``-DTFM_TOOLCHAIN_FILE=<toolchain file>`` |
| 188 | for alternatives as described in :ref:`Toolchains` |
| 189 | - install output files in ``build/api_ns`` folder *by default*. You can specify |
| 190 | a different directory using ``-DCMAKE_INSTALL_PREFIX=<Artifact dir>`` |
| 191 | as described in :ref:`Output files` |
| 192 | |
| 193 | .. Note:: |
Anton Komlev | b8e3af0 | 2020-08-28 10:23:57 +0100 | [diff] [blame] | 194 | It is recommended to build each different build configuration in a separate |
| 195 | build directory. |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 196 | |
Anton Komlev | 4b1c05c | 2023-10-06 20:22:58 +0100 | [diff] [blame^] | 197 | CMake can generate code for many native build systems. TF-M is tested with |
| 198 | ``Unix Makefiles`` (default) and ``Ninja``. The ``-G`` option can specify |
| 199 | alternative generators. For example for building with Ninja in the Debug |
| 200 | :ref:`Build type` using ArmClang :ref:`Toolchains` you can use the following: |
Leonardo Sandoval | 49a558c | 2021-02-03 17:04:22 -0600 | [diff] [blame] | 201 | |
| 202 | .. code-block:: bash |
Subhasish Ghosh | bc84930 | 2021-04-08 20:21:20 +0100 | [diff] [blame] | 203 | |
Anton Komlev | 4b1c05c | 2023-10-06 20:22:58 +0100 | [diff] [blame^] | 204 | cd <TF-M source dir> |
| 205 | cmake -S . -B build -DTFM_PLATFORM=arm/mps2/an521 -GNinja -DTFM_TOOLCHAIN_FILE=toolchain_ARMCLANG.cmake -DCMAKE_BUILD_TYPE=Debug |
| 206 | cmake --build build -- install |
Leonardo Sandoval | 49a558c | 2021-02-03 17:04:22 -0600 | [diff] [blame] | 207 | |
Anton Komlev | 4b1c05c | 2023-10-06 20:22:58 +0100 | [diff] [blame^] | 208 | .. _Dependency management: |
Anton Komlev | b8e3af0 | 2020-08-28 10:23:57 +0100 | [diff] [blame] | 209 | |
Anton Komlev | 4b1c05c | 2023-10-06 20:22:58 +0100 | [diff] [blame^] | 210 | Dependency management |
| 211 | ===================== |
| 212 | |
| 213 | The TF-M build system will fetch all dependencies by default with appropriate |
| 214 | versions and store them inside the build tree. In this case, the build tree |
| 215 | location is ``<build_dir>/lib/ext``. |
| 216 | |
| 217 | If you have local copies already and wish to avoid having the libraries |
| 218 | downloaded every time the build directory is deleted, then the following |
| 219 | variables can be set to the paths to the root directories of the local repos. |
| 220 | This will disable the automatic downloading for that dependencies and speed up |
| 221 | development iterations or allow usage of a dependency version different from the |
| 222 | current one. |
| 223 | Additionally, these path variables can be set in ``localrepos.cmake`` |
| 224 | file which will be included in a build if it exists. |
| 225 | This file is ignored in TF-M git settings. |
| 226 | |
| 227 | The following table lists the commonly used repos. For others, you can refer to ``lib/ext``. |
| 228 | |
| 229 | +----------------+---------------------+-----------------------------------------------------+ |
| 230 | | Dependency | Cmake variable | Git repo URL | |
| 231 | +================+=====================+=====================================================+ |
| 232 | | Mbed Crypto | MBEDCRYPTO_PATH | https://github.com/ARMmbed/mbedtls | |
| 233 | +----------------+---------------------+-----------------------------------------------------+ |
| 234 | | MCUboot | MCUBOOT_PATH | https://github.com/mcu-tools/mcuboot | |
| 235 | +----------------+---------------------+-----------------------------------------------------+ |
| 236 | | QCBOR | QCBOR_PATH | https://github.com/laurencelundblade/QCBOR.git | |
| 237 | +----------------+---------------------+-----------------------------------------------------+ |
| 238 | |
| 239 | The recommended versions of the dependencies are listed in ``config/config_base.cmake``. |
| 240 | |
| 241 | .. Note:: |
| 242 | |
| 243 | - Some repositories might need patches to allow building it as a part of TF-M. |
| 244 | While these patches are being upstreamed they are stored in a |
| 245 | dependency folder under ``lib/ext/``. |
| 246 | In order to use local repositories those patches shall be applied to original source. |
| 247 | An alternative is to copy out the auto-downloaded repos under the ``<build_dir>/lib/ext``. |
| 248 | They have been applied with patches and can be used directly. |
| 249 | |
| 250 | - **tf-m-tests** is a special dependency used for testing purpose only as described in |
| 251 | :ref:`Building Tests` |
| 252 | |
| 253 | Example: building TF-M with local Mbed Crypto repo |
| 254 | -------------------------------------------------- |
| 255 | |
| 256 | Preparing a local repository consists of 2 steps: cloning and patching. |
| 257 | This is only required to be done once. For dependencies without ``.patch`` |
| 258 | files in their ``lib/ext`` directory the only required step is |
| 259 | cloning the repo and checking out the correct branch. |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 260 | |
| 261 | .. code-block:: bash |
| 262 | |
Anton Komlev | 4b1c05c | 2023-10-06 20:22:58 +0100 | [diff] [blame^] | 263 | cd <Mbed Crypto base folder> |
| 264 | git clone https://github.com/ARMmbed/mbedtls |
| 265 | cd mbedtls |
| 266 | git checkout <MBEDCRYPTO_VERSION from <TF-M source dir>/config_base.cmake> |
| 267 | git apply <TF-M source dir>/lib/ext/mbedcrypo/*.patch |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 268 | |
Anton Komlev | 4b1c05c | 2023-10-06 20:22:58 +0100 | [diff] [blame^] | 269 | .. Note:: |
| 270 | |
| 271 | ``<Mbed Crypto base folder>`` does not need to have any fixed position related |
| 272 | to the TF-M repo so alternative method to get prepared dependency repos is to |
| 273 | let TF-M download it once and then copy them out of the ``build/lib/ext`` folder. |
| 274 | |
| 275 | Now build TF-M binaries |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 276 | |
| 277 | .. code-block:: bash |
| 278 | |
Anton Komlev | 4b1c05c | 2023-10-06 20:22:58 +0100 | [diff] [blame^] | 279 | cd <TF-M source dir> |
| 280 | cmake -S . -B build -DTFM_PLATFORM=arm/mps2/an521 -DMBEDCRYPTO_PATH=<Mbed Crypto base folder>/mbedtls |
| 281 | cmake --build build -- install |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 282 | |
Anton Komlev | 4b1c05c | 2023-10-06 20:22:58 +0100 | [diff] [blame^] | 283 | .. _Building NSPE: |
| 284 | |
| 285 | *************************** |
| 286 | Building Application (NSPE) |
| 287 | *************************** |
| 288 | |
| 289 | As a result of :ref:`Building SPE` you will get a set of :ref:`Output files` in |
| 290 | ``<Artifact Dir>`` required for building TF-M application. Essentially, SPE |
| 291 | exports a binary and a set of C source files for PSA interface and platform. |
| 292 | Please note that NSPE and SPE are independent projects and can be built using |
| 293 | different toolchains and toolchain options. |
| 294 | |
| 295 | .. _Artifacts structure: |
| 296 | |
| 297 | SPE artifacts structure |
Kevin Peng | 23a583c | 2021-09-08 22:33:33 +0800 | [diff] [blame] | 298 | ======================= |
Anton Komlev | 4b1c05c | 2023-10-06 20:22:58 +0100 | [diff] [blame^] | 299 | |
| 300 | SPE components prepared and installed for NSPE usage in ``<Artifact Dir>`` |
| 301 | will have the following structure: |
| 302 | |
| 303 | .. code-block:: none |
| 304 | |
| 305 | <Artifact Dir> |
| 306 | ├── bin |
| 307 | ├── cmake |
| 308 | ├── config |
| 309 | ├── image_signing |
| 310 | ├── interface |
| 311 | ├── platform |
| 312 | └── CMakeLists.txt |
| 313 | |
| 314 | With certain configurations, additional folders may also be installed. |
| 315 | These folders have the following content: |
| 316 | |
| 317 | - **bin** - binary images of SPE, Bootloader(optional) and combined. |
| 318 | - **cmake** - CMake scripts like SPE configuration and :ref:`NSPE toolchains`. |
| 319 | - **config** - Configuration files |
| 320 | - **image_signing** - binary image signing tool and keys. |
| 321 | - **interface** - PSA interface exposed by SPE. |
| 322 | - **platform** - source code for a selected hardware platform. |
| 323 | - **CMakeLists.txt** - CMake script for the artifacts integration in NSPE. |
| 324 | |
| 325 | The content of ``<Artifact Dir>`` is a prepared directory for integration with |
| 326 | CMake project as shown in the :ref:`NSPE CmakeLists.txt` below. |
| 327 | |
| 328 | .. _NSPE toolchains: |
| 329 | |
| 330 | NSPE toolchains |
| 331 | =============== |
| 332 | |
| 333 | SPE prepares and exports CMake toolchain files for building NSPE in all |
| 334 | supported :ref:`Toolchains` in ``<Artifact Dir>/cmake`` folder. |
| 335 | Toolchain used to build NSPE can be different from what is used to build SPE. |
| 336 | |
| 337 | .. _NSPE CmakeLists.txt: |
| 338 | |
| 339 | Basic SPE integration |
| 340 | ===================== |
| 341 | Refer to the example of TF-M applications in **tf-m-extras** repository. |
| 342 | |
| 343 | .. _Building Tests: |
| 344 | |
| 345 | ************** |
| 346 | Building Tests |
| 347 | ************** |
| 348 | The tests is a TF-M application which verifies TF-M functionality on both SPE and NSPE sides. |
| 349 | Conceptually, it builds the same way as described above in 2 consequent steps (SPE then NSPE). |
| 350 | |
| 351 | However, tests require an extension of SPE side with test code and extra functionality |
| 352 | for some Non-Secure test cases. To inject that test code into SPE the |
| 353 | ``CONFIG_TFM_TEST_DIR`` option is used. When SPE build system sees this option |
| 354 | it adds the corresponding folder via ``add_subdirectory(${CONFIG_TFM_TEST_DIR} tf-m-test)`` |
| 355 | and includes it to SPE binary. |
| 356 | Also, test configurations should be passed to SPE build to include building Secure Tests. |
| 357 | |
| 358 | To hide these complexities to developers, TF-M implements a wrapper CMake in **tf-m-tests** |
| 359 | repository to build the SPE for testing. |
| 360 | |
| 361 | The recommended tf-m-tests repo commit to verify TF-M can be found at |
| 362 | ``<TF-M source dir>/lib/ext/tf-m-tests/version.txt``. |
| 363 | It does not support auto-downloading as builds start from it. |
| 364 | You need to download it manually before building any tests. |
| 365 | |
| 366 | Regression Tests |
| 367 | ================ |
| 368 | For instructions on configuring, building and executing the regression tests |
| 369 | please refer to the documentation in **tf-m-tests** repository (to be added). |
| 370 | The regression test application is located under **/tests_reg** folder. |
| 371 | It is recommended to build both SPE and NSPE from that folder. |
| 372 | |
| 373 | The basic commands for building the regression tests will be: |
| 374 | |
| 375 | .. code-block:: bash |
| 376 | |
| 377 | cd </tf-m-tests/tests_reg> |
| 378 | cmake -S spe -B build_spe -DTFM_PLATFORM=arm/mps2/an521 -DCONFIG_TFM_SOURCE_PATH=<TF-M source dir> |
| 379 | -DTEST_S=ON -DTEST_NS=ON |
| 380 | cmake --build build_spe -- install |
| 381 | |
| 382 | cmake -S . -B build_test -DCONFIG_SPE_PATH=<Absolute path to>/build_spe/api_ns |
| 383 | cmake --build build_test |
| 384 | |
| 385 | Instead of enable all the supported Secure (``TEST_S``) and NS (``TEST_NS`` tests, you can also |
| 386 | enable individual test suites by using ``-DTEST_S_<SUITE>=ON`` or ``-DTEST_NS_<SUITE>=ON``. |
| 387 | For the available test suites, refer to the ``default_s_test_config.cmake`` and |
| 388 | ``default_ns_test_config.cmake`` files in tf-m-tests repo. |
| 389 | |
| 390 | PSA API tests |
| 391 | ============= |
| 392 | PSA API tests from https://github.com/ARM-software/psa-arch-tests use the same |
| 393 | mechanism for SPE extension as the regression tests above utilising ``CONFIG_TFM_TEST_DIR`` option. |
| 394 | PSA API tests are selected by the TEST_PSA_API variable. Enabling both regression tests and |
Anton Komlev | b8e3af0 | 2020-08-28 10:23:57 +0100 | [diff] [blame] | 395 | PSA API tests simultaneously is **not** supported. |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 396 | |
Anton Komlev | 4b1c05c | 2023-10-06 20:22:58 +0100 | [diff] [blame^] | 397 | TF-M implements a wrapper CMake for PSA API tests as well. |
| 398 | |
| 399 | For instructions on building and executing the regression tests |
| 400 | please refer to the documentation in **tf-m-tests** repository (to be added). |
| 401 | The PSA API test codes are located under **/tests_psa_arch** folder. |
| 402 | |
| 403 | Here is a brief description of the basic flow: |
| 404 | There are 5 different TEST_PSA_API test suites to be run. |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 405 | |
Subhasish Ghosh | bc84930 | 2021-04-08 20:21:20 +0100 | [diff] [blame] | 406 | .. code-block:: bash |
Anton Komlev | b8e3af0 | 2020-08-28 10:23:57 +0100 | [diff] [blame] | 407 | |
| 408 | -DTEST_PSA_API=INTERNAL_TRUSTED_STORAGE |
| 409 | -DTEST_PSA_API=PROTECTED_STORAGE |
| 410 | -DTEST_PSA_API=STORAGE |
| 411 | -DTEST_PSA_API=CRYPTO |
| 412 | -DTEST_PSA_API=INITIAL_ATTESTATION |
| 413 | |
| 414 | Respectively for the corresponding service. For example, to enable the PSA API |
| 415 | tests for the Crypto service: |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 416 | |
| 417 | .. code-block:: bash |
| 418 | |
Anton Komlev | 4b1c05c | 2023-10-06 20:22:58 +0100 | [diff] [blame^] | 419 | cd </tf-m-tests/tests_psa_arch folder> |
| 420 | cmake -S spe -B build_spe -DTFM_PLATFORM=arm/mps2/an521 -DCONFIG_TFM_SOURCE_PATH=<TF-M source dir> |
| 421 | -DTEST_PSA_API=CRYPTO |
| 422 | cmake --build build_spe -- install |
Anton Komlev | b8e3af0 | 2020-08-28 10:23:57 +0100 | [diff] [blame] | 423 | |
Anton Komlev | 4b1c05c | 2023-10-06 20:22:58 +0100 | [diff] [blame^] | 424 | cmake -S . -B build_test -DCONFIG_SPE_PATH=<Absolute path to>/build_spe/api_ns |
| 425 | cmake --build build_test |
Raef Coles | 1ecb813 | 2020-10-02 15:11:24 +0100 | [diff] [blame] | 426 | |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 427 | -------------- |
| 428 | |
Xinyu Zhang | 5f9ffeb | 2023-03-31 11:09:45 +0800 | [diff] [blame] | 429 | *Copyright (c) 2017-2023, Arm Limited. All rights reserved.* |
Chris Brand | 80266ba | 2022-01-05 09:14:52 -0800 | [diff] [blame] | 430 | *Copyright (c) 2022, Cypress Semiconductor Corporation. All rights reserved.* |