blob: 9eef380d03f3aa258c3b5c0cf9ef3d7d94c08eb8 [file] [log] [blame]
Galanakis, Minos41f85972019-09-30 15:56:40 +01001##################
2Build instructions
3##################
Anton Komlev0dbe8f12022-06-17 16:48:12 +01004
Gyorgy Szingdb9783c2019-04-17 21:08:48 +02005Please make sure you have all required software installed as explained in the
Anton Komlev3356ba32022-03-31 22:02:11 +01006:doc:`TF-M getting started </getting_started/tfm_getting_started>`.
Anton Komlev91281f02022-04-22 09:24:20 +01007The additional building materials you can find in the following links:
8
9.. toctree::
10 :maxdepth: 1
11
Anton Komlev91281f02022-04-22 09:24:20 +010012 Run TF-M examples <run_tfm_examples_on_arm_platforms>
Anton Komlev0dbe8f12022-06-17 16:48:12 +010013 Building the documentation <documentation_generation>
14 IAR toolchain <tfm_build_instruction_iar>
Gyorgy Szingdb9783c2019-04-17 21:08:48 +020015
Gyorgy Szingdb9783c2019-04-17 21:08:48 +020016****************
17TF-M build steps
18****************
19TF-M uses `cmake <https://cmake.org/overview/>`__ to provide an out-of-source
20build environment. The instructions are below.
21
Raef Coles69817322020-10-19 14:14:14 +010022Cmake version ``3.15.0`` or higher is required.
Raef Coles1ecb8132020-10-02 15:11:24 +010023
David Wangd6fd6af2021-06-21 17:17:26 +080024.. _Getting the source-code:
25
Gyorgy Szingdb9783c2019-04-17 21:08:48 +020026Getting the source-code
27=======================
28.. code-block:: bash
29
Leonardo Sandovald7f72d52020-07-28 18:02:34 -050030 cd <base folder>
Minos Galanakis0f39fa52020-06-08 16:53:53 +010031 git clone https://git.trustedfirmware.org/TF-M/trusted-firmware-m.git
Anton Komlevb8e3af02020-08-28 10:23:57 +010032
Leonardo Sandoval98350142021-02-03 16:32:14 -060033To simplify documentation commands, the new created repository under
34``trusted-firmware-m`` would be referenced as ``<TF-M base folder>`` and
35its parent, the ``<base folder>``. Dependency management is now handled by
36cmake. If you wish to alter this behaviour, see
Anton Komlev0dbe8f12022-06-17 16:48:12 +010037:ref:`building/tfm_build_instruction:Manual dependency management`
Gyorgy Szingdb9783c2019-04-17 21:08:48 +020038
Minos Galanakisac6b06c2020-03-19 12:57:02 +000039.. Note::
Anton Komlevb8e3af02020-08-28 10:23:57 +010040
Minos Galanakis3b740a12020-10-15 11:10:26 +010041 - For building with Armclang compiler version 6.10.0+, please follow the note
Anton Komlev3356ba32022-03-31 22:02:11 +010042 in :doc:`TF-M getting started </getting_started/tfm_getting_started>`.
Anton Komlevb8e3af02020-08-28 10:23:57 +010043 - For building with the IAR toolchain, please see the notes in
Minos Galanakis3b740a12020-10-15 11:10:26 +010044 :doc:`IAR software requirements <tfm_build_instruction_iar>`
TTornblomb9e5ed02020-02-13 16:53:15 +010045
Anton Komlev2cd91532022-11-17 13:36:55 +000046Basic configuration
Anton Komlevb8e3af02020-08-28 10:23:57 +010047===================
48
Anton Komlev2cd91532022-11-17 13:36:55 +000049TF-M has many options for configuration and fine-tuning. Please check the
50:ref:`tf-m_configuration` section for details. The **base** configuration
51will be build by default with only essential modules SPM and platform hence
52a platform must be selected via ``TFM_PLATFORM`` options, it can be:
Anton Komlevb8e3af02020-08-28 10:23:57 +010053
Jianliang Shen2628db72022-03-17 10:13:06 +080054 - A relative path under ``<TF-M_root>/platform/ext/target``,
55 for example ``arm/mps2/an521``.
56 - An absolute path of target platform, mainly used for out-of-tree platform
57 build.
58 - A target platform name that is supported under
59 <TF-M_root>/platform/ext/target, for example ``an521``.
Anton Komlevb8e3af02020-08-28 10:23:57 +010060
Anton Komlevb8e3af02020-08-28 10:23:57 +010061Build type
62----------
63
Dávid Házie50f0a92022-07-06 14:46:01 +020064By default, a MinSizeRel configuration is built. Alternate build types can be
Chris Brand80266ba2022-01-05 09:14:52 -080065specified with the ``CMAKE_BUILD_TYPE`` variable. The possible
Anton Komlevb8e3af02020-08-28 10:23:57 +010066types are:
67
68 - ``Debug``
Sebastian Bøeb73f1762021-10-28 14:23:13 +020069 - ``RelWithDebInfo``
Anton Komlevb8e3af02020-08-28 10:23:57 +010070 - ``Release``
Anton Komlev2cd91532022-11-17 13:36:55 +000071 - ``MinSizeRel`` - default
Anton Komlevb8e3af02020-08-28 10:23:57 +010072
Sebastian Bøeb73f1762021-10-28 14:23:13 +020073Debug symbols are added by default to all builds, but can be removed
74from ``Release`` and ``MinSizeRel`` builds by setting
75``TFM_DEBUG_SYMBOLS`` to ``OFF``.
76
77``RelWithDebInfo``, ``Release`` and ``MinSizeRel`` all have different
78optimizations turned on and hence will produce smaller, faster code
79than ``Debug``. ``MinSizeRel`` will produce the smallest code, and
80hence is often a good idea on RAM or flash constrained systems.
Anton Komlevb8e3af02020-08-28 10:23:57 +010081
82Other cmake parameters
83----------------------
84
Anton Komlev2cd91532022-11-17 13:36:55 +000085The full list of default options is in ``config/config_base.cmake`` and
86explained in :ref:`tfm_cmake_configuration`. Several important options
87are listed below.
Anton Komlevb8e3af02020-08-28 10:23:57 +010088
Xinyu Zhang5f9ffeb2023-03-31 11:09:45 +080089+----------------------------+------------------------------------------+---------------+
90| Parameter | Description | Default value |
91+============================+==========================================+===============+
92| BL2 | Build level 2 secure bootloader. | ON |
93+----------------------------+------------------------------------------+---------------+
94| NS | Build NS app. Required for test code. | ON |
95+----------------------------+------------------------------------------+---------------+
96| PROJECT_CONFIG_HEADER_FILE | User defined header file for TF-M config | |
97+----------------------------+------------------------------------------+---------------+
98| TFM_ISOLATION_LEVEL | Set TFM isolation level. | 1 |
99+----------------------------+------------------------------------------+---------------+
100| TFM_PROFILE | Set TFM profile. | |
101+----------------------------+------------------------------------------+---------------+
102| TEST_S | Build secure regression tests. | OFF |
103+----------------------------+------------------------------------------+---------------+
104| TEST_NS | Build non-secure regression tests. | OFF |
105+----------------------------+------------------------------------------+---------------+
106| TEST_PSA_API | Build PSA API TESTS for the given | |
107| | suite. Takes a PSA api ``SUITE`` as an | |
108| | argument (``CRYPTO`` etc). | |
109+----------------------------+------------------------------------------+---------------+
110
111Project Config Header File
112--------------------------
113
114CMake variable ``PROJECT_CONFIG_HEADER_FILE`` is set by users with the full path of the
115configuration header file, which is used to fine-tune component options. The detailed reference
116for project config header file is in :ref:`Header_configuration`.
117
118.. Note::
119
120 It is recommended to clean up build folder before re-build if config header file is updated.
121 CMake is unable to automatically recognize the dependency when the header file is defined as a macro.
Anton Komlevb8e3af02020-08-28 10:23:57 +0100122
Anton Komlev211aacf2020-11-02 12:48:11 +0000123TF-M Profiles
124-------------
125
126TF-M Profiles are implemented as a single cmake configuration file, under the
127``config/profile`` directory. A good understanding can be gained quickly by
128looking at the Profile configuration files, but the ultimate reference for
Anton Komlev2cd91532022-11-17 13:36:55 +0000129Profiles is in :ref:`tf-m_profiles`.
Anton Komlevb8e3af02020-08-28 10:23:57 +0100130
Anton Komlevb8e3af02020-08-28 10:23:57 +0100131*******************
132TF-M build examples
133*******************
134
135Example: building TF-M for AN521 platform using GCC:
136====================================================
137.. code-block:: bash
138
Leonardo Sandoval98350142021-02-03 16:32:14 -0600139 cd <TF-M base folder>
Chris Brand80266ba2022-01-05 09:14:52 -0800140 cmake -S . -B cmake_build -DTFM_PLATFORM=arm/mps2/an521
Anton Komlevb8e3af02020-08-28 10:23:57 +0100141 cmake --build cmake_build -- install
142
143Alternately using traditional cmake syntax
144
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200145.. code-block:: bash
146
Leonardo Sandoval98350142021-02-03 16:32:14 -0600147 cd <TF-M base folder>
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200148 mkdir cmake_build
149 cd cmake_build
Chris Brand80266ba2022-01-05 09:14:52 -0800150 cmake .. -DTFM_PLATFORM=arm/mps2/an521
Anton Komlevb8e3af02020-08-28 10:23:57 +0100151 make install
152
153.. Note::
Anton Komlevb8e3af02020-08-28 10:23:57 +0100154
155 It is recommended to build each different build configuration in a separate
156 build directory.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200157
Chris Brand80266ba2022-01-05 09:14:52 -0800158The default build uses Unix Makefiles. The ``-G`` option can be used to change
159this. The default build uses the GNU ARM toolchain and creates a Release build.
160These options can be overridden using the ``TFM_TOOLCHAIN_FILE`` and
161``CMAKE_BUILD_TYPE`` parameters, as shown below
Leonardo Sandoval49a558c2021-02-03 17:04:22 -0600162
163.. code-block:: bash
Subhasish Ghoshbc849302021-04-08 20:21:20 +0100164
Leonardo Sandoval49a558c2021-02-03 17:04:22 -0600165 cd <TF-M base folder>
Chris Brand80266ba2022-01-05 09:14:52 -0800166 cmake -S . -B cmake_build -DTFM_PLATFORM=arm/mps2/an521 -GNinja -DTFM_TOOLCHAIN_FILE=toolchain_ARMCLANG.cmake -DCMAKE_BUILD_TYPE=Debug
Leonardo Sandoval49a558c2021-02-03 17:04:22 -0600167 cmake --build cmake_build -- install
168
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200169Regression Tests for the AN521 target platform
170==============================================
Anton Komlevb8e3af02020-08-28 10:23:57 +0100171
172Regression tests can be build by using the TEST_S and TEST_NS settings. Either
173can be used in isolation or both can be used to enable both suites. All tests
174for all enabled partitions are run, along with IPC and Multicore tests if those
175features are enabled.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200176
177.. code-block:: bash
178
Leonardo Sandoval98350142021-02-03 16:32:14 -0600179 cd <TF-M base folder>
Summer Qin2de23d02021-05-14 13:44:14 +0800180 cmake -S . -B cmake_build -DTFM_PLATFORM=arm/mps2/an521 -DTEST_S=ON -DTEST_NS=ON
Anton Komlevb8e3af02020-08-28 10:23:57 +0100181 cmake --build cmake_build -- install
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200182
Anton Komlevb8e3af02020-08-28 10:23:57 +0100183Alternately using traditional cmake syntax
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200184
185.. code-block:: bash
186
Leonardo Sandoval98350142021-02-03 16:32:14 -0600187 cd <TF-M base folder>
Anton Komlevb8e3af02020-08-28 10:23:57 +0100188 mkdir cmake_build
189 cd cmake_build
Summer Qin2de23d02021-05-14 13:44:14 +0800190 cmake .. -DTFM_PLATFORM=arm/mps2/an521 -DTEST_S=ON -DTEST_NS=ON
Anton Komlevb8e3af02020-08-28 10:23:57 +0100191 make install
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200192
Kevin Peng23a583c2021-09-08 22:33:33 +0800193Build for PSA API tests
194=======================
Anton Komlevb8e3af02020-08-28 10:23:57 +0100195The build system provides support for building and integrating the PSA API tests
196from https://github.com/ARM-software/psa-arch-tests. PSA API tests are
197controlled using the TEST_PSA_API variable. Enabling both regression tests and
198PSA API tests simultaneously is **not** supported.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200199
Anton Komlevb8e3af02020-08-28 10:23:57 +0100200The value of the TEST_PSA_API variable is the suite to be run.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200201
Subhasish Ghoshbc849302021-04-08 20:21:20 +0100202.. code-block:: bash
Anton Komlevb8e3af02020-08-28 10:23:57 +0100203
204 -DTEST_PSA_API=INTERNAL_TRUSTED_STORAGE
205 -DTEST_PSA_API=PROTECTED_STORAGE
206 -DTEST_PSA_API=STORAGE
207 -DTEST_PSA_API=CRYPTO
208 -DTEST_PSA_API=INITIAL_ATTESTATION
209
210Respectively for the corresponding service. For example, to enable the PSA API
211tests for the Crypto service:
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200212
213.. code-block:: bash
214
Leonardo Sandoval98350142021-02-03 16:32:14 -0600215 cd <TF-M base folder>
Summer Qin2de23d02021-05-14 13:44:14 +0800216 cmake -S . -B cmake_build -DTFM_PLATFORM=arm/mps2/an521 -DTEST_PSA_API=CRYPTO
Anton Komlevb8e3af02020-08-28 10:23:57 +0100217 cmake --build cmake_build -- install
218
219Alternately using traditional cmake syntax
220
221.. code-block:: bash
222
Leonardo Sandoval98350142021-02-03 16:32:14 -0600223 cd <TF-M base folder>
Anton Komlevb8e3af02020-08-28 10:23:57 +0100224 mkdir cmake_build
225 cd cmake_build
Summer Qin2de23d02021-05-14 13:44:14 +0800226 cmake .. -DTFM_PLATFORM=arm/mps2/an521 -DTEST_PSA_API=CRYPTO
Anton Komlevb8e3af02020-08-28 10:23:57 +0100227 make install
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200228
229Location of build artifacts
230===========================
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200231
Anton Komlevb8e3af02020-08-28 10:23:57 +0100232All build artifacts are provided in the ``<build_dir>/bin`` directory. It is
233**not** required to run ``make install`` to generate artifacts in this location.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200234
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200235
Anton Komlevb8e3af02020-08-28 10:23:57 +0100236For the purposes of maintaining compatibility with the legacy cmake build
237system, they are also provided in
238``<build_dir>/install/outputs/<target_platform>/``. In order to generate the
239artifacts in this location ``make install`` must be run.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200240
Anton Komlevb8e3af02020-08-28 10:23:57 +0100241****************************
242Manual dependency management
243****************************
Galanakis, Minos757139a2019-11-11 15:00:11 +0000244
Raef Coles1ecb8132020-10-02 15:11:24 +0100245The TF-M build system will by default fetch all dependencies with appropriate
246versions and store them inside the build tree. In this case, the build tree
247location is ``<build_dir>/lib/ext``, and the extra libraries can be cleaned by
248deleting that directory.
Galanakis, Minos757139a2019-11-11 15:00:11 +0000249
Raef Coles1ecb8132020-10-02 15:11:24 +0100250If you have local copies already, and wish to avoid having the libraries
251downloaded every time the build directory is deleted, then the following
Raef Colesc630b882020-12-10 15:46:18 +0000252variables can be set to the path to the root directory of the local repo. This
253will disable the automatic downloading for that dependency.
Raef Coles1ecb8132020-10-02 15:11:24 +0100254
Raef Colesc630b882020-12-10 15:46:18 +0000255+----------------+---------------------+-----------------------------------------------------+
256| Dependency | Cmake variable | Git repo URL |
257+================+=====================+=====================================================+
258| Mbed Crypto | MBEDCRYPTO_PATH | https://github.com/ARMmbed/mbedtls |
259+----------------+---------------------+-----------------------------------------------------+
260| tf-m-tests | TFM_TEST_REPO_PATH | https://git.trustedfirmware.org/TF-M/tf-m-tests.git |
261+----------------+---------------------+-----------------------------------------------------+
262| MCUboot | MCUBOOT_PATH | https://github.com/mcu-tools/mcuboot |
263+----------------+---------------------+-----------------------------------------------------+
264| psa-arch-tests | PSA_ARCH_TESTS_PATH | https://github.com/ARM-software/psa-arch-tests |
265+----------------+---------------------+-----------------------------------------------------+
Galanakis, Minos757139a2019-11-11 15:00:11 +0000266
Anton Komlev1dfd2092022-10-25 17:50:09 +0100267For required versions of the dependencies, refer to ``config/config_base.cmake``.
Galanakis, Minos757139a2019-11-11 15:00:11 +0000268
269.. Note::
Anton Komlevb8e3af02020-08-28 10:23:57 +0100270 - Some patches are required to the mbedtls repo to allow building it as part of
271 TF-M. While these patches are being upstreamed they are stored in
Raef Coles1ecb8132020-10-02 15:11:24 +0100272 ``lib/ext/mbedcrypo``. In order to use a local copy of Mbed Crypto it is
273 required to apply all patch files in this directory.
Galanakis, Minos757139a2019-11-11 15:00:11 +0000274
Anton Komlevb8e3af02020-08-28 10:23:57 +0100275.. Note::
276 - CMSIS 5 is provided by the TF-M tests repo. If you wish to use a different
277 source for CMSIS 5, it can be configured using CMSIS_5_PATH.
David Hu2cbf5df2020-06-15 10:41:44 +0800278
Kevin Pengcba37d32020-12-07 17:07:39 +0800279TF-M Tests
280==========
281
282Dependency auto downloading is used by default.
283The TF-M build system downloads the tf-m-tests repo with a fixed version
David Huf89bcb62021-09-06 15:02:34 +0800284specified by ``TFM_TEST_REPO_VERSION`` in
Anton Komlev1dfd2092022-10-25 17:50:09 +0100285:file:`lib/ext/tf-m-tests/repo_config_base.cmake`.
Kevin Pengcba37d32020-12-07 17:07:39 +0800286The version can be a release tag or a commit hash.
287
288Developers who want a different version of tf-m-tests can override
289``TFM_TEST_REPO_PATH`` to a local copy with the desired version.
290
David Huf89bcb62021-09-06 15:02:34 +0800291As the test repo is part of the TF-M project and coupled with TF-M repo,
292the version should be updated when there are dependency changes between the TF-M
Kevin Pengcba37d32020-12-07 17:07:39 +0800293repo and the test repo and when there is a complete change merged in test repo.
294
295A complete change is one or more patches that are for the same purpose, for
296example a new test suite or enhancements on the test cases.
297Patches in one change can be merge individually provided they do not break
298anything or cause any regressions.
299But the version in the TF-M gets updated only when all the patches are merged.
300
Raef Coles1ecb8132020-10-02 15:11:24 +0100301Example: building TF-M for AN521 platform with local Mbed Crypto
302================================================================
303
304Prepare Mbed Crypto repository
305------------------------------
306
307This is only required to be done once. For dependencies that do not have any
308``.patch`` files in their ``lib/ext`` directory the only required step is
309cloning the repo and checking out the correct branch.
310
311.. code-block:: bash
312
313 cd <Mbed Crypto base folder>
314 git clone https://github.com/ARMmbed/mbedtls
315 cd mbedtls
Anton Komlev1dfd2092022-10-25 17:50:09 +0100316 git checkout <MBEDCRYPTO_VERSION from config_base.cmake>
Raef Coles1ecb8132020-10-02 15:11:24 +0100317 git apply <TF-M base folder>/trusted-firmware-m/lib/ext/mbedcrypo/*.patch
318
319.. Note::
320 - <Mbed Crypto base folder> does not need to have any fixed posisition related
321 to the TF-M repo.
322
323Build TF-M
324----------
325
326With new cmake syntax
327
328.. code-block:: bash
329
Leonardo Sandoval98350142021-02-03 16:32:14 -0600330 cd <TF-M base folder>
Summer Qin2de23d02021-05-14 13:44:14 +0800331 cmake -S . -B cmake_build -DTFM_PLATFORM=arm/mps2/an521 -DMBEDCRYPTO_PATH=<Mbed Crypto base folder>/mbedtls
Raef Coles1ecb8132020-10-02 15:11:24 +0100332 cmake --build cmake_build -- install
333
334Alternately using traditional cmake syntax
335
336.. code-block:: bash
337
Leonardo Sandoval98350142021-02-03 16:32:14 -0600338 cd <TF-M base folder>
Raef Coles1ecb8132020-10-02 15:11:24 +0100339 mkdir cmake_build
340 cd cmake_build
Summer Qin2de23d02021-05-14 13:44:14 +0800341 cmake .. -DTFM_PLATFORM=arm/mps2/an521 -DMBEDCRYPTO_PATH=<Mbed Crypto base folder>/mbedtls
Raef Coles1ecb8132020-10-02 15:11:24 +0100342 make install
343
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200344--------------
345
Xinyu Zhang5f9ffeb2023-03-31 11:09:45 +0800346*Copyright (c) 2017-2023, Arm Limited. All rights reserved.*
Chris Brand80266ba2022-01-05 09:14:52 -0800347*Copyright (c) 2022, Cypress Semiconductor Corporation. All rights reserved.*