blob: 93b3948de2579898d40b6ec0c01eab560347eb7a [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
89+---------------------+----------------------------------------+---------------+
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+---------------------+----------------------------------------+---------------+
Anton Komlevb8e3af02020-08-28 10:23:57 +010096| TFM_ISOLATION_LEVEL | Set TFM isolation level. | 1 |
97+---------------------+----------------------------------------+---------------+
98| TFM_PROFILE | Set TFM profile. | |
99+---------------------+----------------------------------------+---------------+
100| TEST_S | Build secure regression tests. | OFF |
101+---------------------+----------------------------------------+---------------+
102| TEST_NS | Build non-secure regression tests. | OFF |
103+---------------------+----------------------------------------+---------------+
104| TEST_PSA_API | Build PSA API TESTS for the given | |
105| | suite. Takes a PSA api ``SUITE`` as an | |
106| | argument (``CRYPTO`` etc). | |
107+---------------------+----------------------------------------+---------------+
108
Anton Komlev211aacf2020-11-02 12:48:11 +0000109TF-M Profiles
110-------------
111
112TF-M Profiles are implemented as a single cmake configuration file, under the
113``config/profile`` directory. A good understanding can be gained quickly by
114looking at the Profile configuration files, but the ultimate reference for
Anton Komlev2cd91532022-11-17 13:36:55 +0000115Profiles is in :ref:`tf-m_profiles`.
Anton Komlevb8e3af02020-08-28 10:23:57 +0100116
Anton Komlevb8e3af02020-08-28 10:23:57 +0100117*******************
118TF-M build examples
119*******************
120
121Example: building TF-M for AN521 platform using GCC:
122====================================================
123.. code-block:: bash
124
Leonardo Sandoval98350142021-02-03 16:32:14 -0600125 cd <TF-M base folder>
Chris Brand80266ba2022-01-05 09:14:52 -0800126 cmake -S . -B cmake_build -DTFM_PLATFORM=arm/mps2/an521
Anton Komlevb8e3af02020-08-28 10:23:57 +0100127 cmake --build cmake_build -- install
128
129Alternately using traditional cmake syntax
130
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200131.. code-block:: bash
132
Leonardo Sandoval98350142021-02-03 16:32:14 -0600133 cd <TF-M base folder>
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200134 mkdir cmake_build
135 cd cmake_build
Chris Brand80266ba2022-01-05 09:14:52 -0800136 cmake .. -DTFM_PLATFORM=arm/mps2/an521
Anton Komlevb8e3af02020-08-28 10:23:57 +0100137 make install
138
139.. Note::
Anton Komlevb8e3af02020-08-28 10:23:57 +0100140
141 It is recommended to build each different build configuration in a separate
142 build directory.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200143
Chris Brand80266ba2022-01-05 09:14:52 -0800144The default build uses Unix Makefiles. The ``-G`` option can be used to change
145this. The default build uses the GNU ARM toolchain and creates a Release build.
146These options can be overridden using the ``TFM_TOOLCHAIN_FILE`` and
147``CMAKE_BUILD_TYPE`` parameters, as shown below
Leonardo Sandoval49a558c2021-02-03 17:04:22 -0600148
149.. code-block:: bash
Subhasish Ghoshbc849302021-04-08 20:21:20 +0100150
Leonardo Sandoval49a558c2021-02-03 17:04:22 -0600151 cd <TF-M base folder>
Chris Brand80266ba2022-01-05 09:14:52 -0800152 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 -0600153 cmake --build cmake_build -- install
154
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200155Regression Tests for the AN521 target platform
156==============================================
Anton Komlevb8e3af02020-08-28 10:23:57 +0100157
158Regression tests can be build by using the TEST_S and TEST_NS settings. Either
159can be used in isolation or both can be used to enable both suites. All tests
160for all enabled partitions are run, along with IPC and Multicore tests if those
161features are enabled.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200162
163.. code-block:: bash
164
Leonardo Sandoval98350142021-02-03 16:32:14 -0600165 cd <TF-M base folder>
Summer Qin2de23d02021-05-14 13:44:14 +0800166 cmake -S . -B cmake_build -DTFM_PLATFORM=arm/mps2/an521 -DTEST_S=ON -DTEST_NS=ON
Anton Komlevb8e3af02020-08-28 10:23:57 +0100167 cmake --build cmake_build -- install
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200168
Anton Komlevb8e3af02020-08-28 10:23:57 +0100169Alternately using traditional cmake syntax
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200170
171.. code-block:: bash
172
Leonardo Sandoval98350142021-02-03 16:32:14 -0600173 cd <TF-M base folder>
Anton Komlevb8e3af02020-08-28 10:23:57 +0100174 mkdir cmake_build
175 cd cmake_build
Summer Qin2de23d02021-05-14 13:44:14 +0800176 cmake .. -DTFM_PLATFORM=arm/mps2/an521 -DTEST_S=ON -DTEST_NS=ON
Anton Komlevb8e3af02020-08-28 10:23:57 +0100177 make install
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200178
Kevin Peng23a583c2021-09-08 22:33:33 +0800179Build for PSA API tests
180=======================
Anton Komlevb8e3af02020-08-28 10:23:57 +0100181The build system provides support for building and integrating the PSA API tests
182from https://github.com/ARM-software/psa-arch-tests. PSA API tests are
183controlled using the TEST_PSA_API variable. Enabling both regression tests and
184PSA API tests simultaneously is **not** supported.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200185
Anton Komlevb8e3af02020-08-28 10:23:57 +0100186The value of the TEST_PSA_API variable is the suite to be run.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200187
Subhasish Ghoshbc849302021-04-08 20:21:20 +0100188.. code-block:: bash
Anton Komlevb8e3af02020-08-28 10:23:57 +0100189
190 -DTEST_PSA_API=INTERNAL_TRUSTED_STORAGE
191 -DTEST_PSA_API=PROTECTED_STORAGE
192 -DTEST_PSA_API=STORAGE
193 -DTEST_PSA_API=CRYPTO
194 -DTEST_PSA_API=INITIAL_ATTESTATION
195
196Respectively for the corresponding service. For example, to enable the PSA API
197tests for the Crypto service:
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200198
199.. code-block:: bash
200
Leonardo Sandoval98350142021-02-03 16:32:14 -0600201 cd <TF-M base folder>
Summer Qin2de23d02021-05-14 13:44:14 +0800202 cmake -S . -B cmake_build -DTFM_PLATFORM=arm/mps2/an521 -DTEST_PSA_API=CRYPTO
Anton Komlevb8e3af02020-08-28 10:23:57 +0100203 cmake --build cmake_build -- install
204
205Alternately using traditional cmake syntax
206
207.. code-block:: bash
208
Leonardo Sandoval98350142021-02-03 16:32:14 -0600209 cd <TF-M base folder>
Anton Komlevb8e3af02020-08-28 10:23:57 +0100210 mkdir cmake_build
211 cd cmake_build
Summer Qin2de23d02021-05-14 13:44:14 +0800212 cmake .. -DTFM_PLATFORM=arm/mps2/an521 -DTEST_PSA_API=CRYPTO
Anton Komlevb8e3af02020-08-28 10:23:57 +0100213 make install
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200214
215Location of build artifacts
216===========================
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200217
Anton Komlevb8e3af02020-08-28 10:23:57 +0100218All build artifacts are provided in the ``<build_dir>/bin`` directory. It is
219**not** required to run ``make install`` to generate artifacts in this location.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200220
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200221
Anton Komlevb8e3af02020-08-28 10:23:57 +0100222For the purposes of maintaining compatibility with the legacy cmake build
223system, they are also provided in
224``<build_dir>/install/outputs/<target_platform>/``. In order to generate the
225artifacts in this location ``make install`` must be run.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200226
Anton Komlevb8e3af02020-08-28 10:23:57 +0100227****************************
228Manual dependency management
229****************************
Galanakis, Minos757139a2019-11-11 15:00:11 +0000230
Raef Coles1ecb8132020-10-02 15:11:24 +0100231The TF-M build system will by default fetch all dependencies with appropriate
232versions and store them inside the build tree. In this case, the build tree
233location is ``<build_dir>/lib/ext``, and the extra libraries can be cleaned by
234deleting that directory.
Galanakis, Minos757139a2019-11-11 15:00:11 +0000235
Raef Coles1ecb8132020-10-02 15:11:24 +0100236If you have local copies already, and wish to avoid having the libraries
237downloaded every time the build directory is deleted, then the following
Raef Colesc630b882020-12-10 15:46:18 +0000238variables can be set to the path to the root directory of the local repo. This
239will disable the automatic downloading for that dependency.
Raef Coles1ecb8132020-10-02 15:11:24 +0100240
Raef Colesc630b882020-12-10 15:46:18 +0000241+----------------+---------------------+-----------------------------------------------------+
242| Dependency | Cmake variable | Git repo URL |
243+================+=====================+=====================================================+
244| Mbed Crypto | MBEDCRYPTO_PATH | https://github.com/ARMmbed/mbedtls |
245+----------------+---------------------+-----------------------------------------------------+
246| tf-m-tests | TFM_TEST_REPO_PATH | https://git.trustedfirmware.org/TF-M/tf-m-tests.git |
247+----------------+---------------------+-----------------------------------------------------+
248| MCUboot | MCUBOOT_PATH | https://github.com/mcu-tools/mcuboot |
249+----------------+---------------------+-----------------------------------------------------+
250| psa-arch-tests | PSA_ARCH_TESTS_PATH | https://github.com/ARM-software/psa-arch-tests |
251+----------------+---------------------+-----------------------------------------------------+
Galanakis, Minos757139a2019-11-11 15:00:11 +0000252
Anton Komlev1dfd2092022-10-25 17:50:09 +0100253For required versions of the dependencies, refer to ``config/config_base.cmake``.
Galanakis, Minos757139a2019-11-11 15:00:11 +0000254
255.. Note::
Anton Komlevb8e3af02020-08-28 10:23:57 +0100256 - Some patches are required to the mbedtls repo to allow building it as part of
257 TF-M. While these patches are being upstreamed they are stored in
Raef Coles1ecb8132020-10-02 15:11:24 +0100258 ``lib/ext/mbedcrypo``. In order to use a local copy of Mbed Crypto it is
259 required to apply all patch files in this directory.
Galanakis, Minos757139a2019-11-11 15:00:11 +0000260
Anton Komlevb8e3af02020-08-28 10:23:57 +0100261.. Note::
262 - CMSIS 5 is provided by the TF-M tests repo. If you wish to use a different
263 source for CMSIS 5, it can be configured using CMSIS_5_PATH.
David Hu2cbf5df2020-06-15 10:41:44 +0800264
Kevin Pengcba37d32020-12-07 17:07:39 +0800265TF-M Tests
266==========
267
268Dependency auto downloading is used by default.
269The TF-M build system downloads the tf-m-tests repo with a fixed version
David Huf89bcb62021-09-06 15:02:34 +0800270specified by ``TFM_TEST_REPO_VERSION`` in
Anton Komlev1dfd2092022-10-25 17:50:09 +0100271:file:`lib/ext/tf-m-tests/repo_config_base.cmake`.
Kevin Pengcba37d32020-12-07 17:07:39 +0800272The version can be a release tag or a commit hash.
273
274Developers who want a different version of tf-m-tests can override
275``TFM_TEST_REPO_PATH`` to a local copy with the desired version.
276
David Huf89bcb62021-09-06 15:02:34 +0800277As the test repo is part of the TF-M project and coupled with TF-M repo,
278the version should be updated when there are dependency changes between the TF-M
Kevin Pengcba37d32020-12-07 17:07:39 +0800279repo and the test repo and when there is a complete change merged in test repo.
280
281A complete change is one or more patches that are for the same purpose, for
282example a new test suite or enhancements on the test cases.
283Patches in one change can be merge individually provided they do not break
284anything or cause any regressions.
285But the version in the TF-M gets updated only when all the patches are merged.
286
Raef Coles1ecb8132020-10-02 15:11:24 +0100287Example: building TF-M for AN521 platform with local Mbed Crypto
288================================================================
289
290Prepare Mbed Crypto repository
291------------------------------
292
293This is only required to be done once. For dependencies that do not have any
294``.patch`` files in their ``lib/ext`` directory the only required step is
295cloning the repo and checking out the correct branch.
296
297.. code-block:: bash
298
299 cd <Mbed Crypto base folder>
300 git clone https://github.com/ARMmbed/mbedtls
301 cd mbedtls
Anton Komlev1dfd2092022-10-25 17:50:09 +0100302 git checkout <MBEDCRYPTO_VERSION from config_base.cmake>
Raef Coles1ecb8132020-10-02 15:11:24 +0100303 git apply <TF-M base folder>/trusted-firmware-m/lib/ext/mbedcrypo/*.patch
304
305.. Note::
306 - <Mbed Crypto base folder> does not need to have any fixed posisition related
307 to the TF-M repo.
308
309Build TF-M
310----------
311
312With new cmake syntax
313
314.. code-block:: bash
315
Leonardo Sandoval98350142021-02-03 16:32:14 -0600316 cd <TF-M base folder>
Summer Qin2de23d02021-05-14 13:44:14 +0800317 cmake -S . -B cmake_build -DTFM_PLATFORM=arm/mps2/an521 -DMBEDCRYPTO_PATH=<Mbed Crypto base folder>/mbedtls
Raef Coles1ecb8132020-10-02 15:11:24 +0100318 cmake --build cmake_build -- install
319
320Alternately using traditional cmake syntax
321
322.. code-block:: bash
323
Leonardo Sandoval98350142021-02-03 16:32:14 -0600324 cd <TF-M base folder>
Raef Coles1ecb8132020-10-02 15:11:24 +0100325 mkdir cmake_build
326 cd cmake_build
Summer Qin2de23d02021-05-14 13:44:14 +0800327 cmake .. -DTFM_PLATFORM=arm/mps2/an521 -DMBEDCRYPTO_PATH=<Mbed Crypto base folder>/mbedtls
Raef Coles1ecb8132020-10-02 15:11:24 +0100328 make install
329
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200330--------------
331
Jianliang Shen2628db72022-03-17 10:13:06 +0800332*Copyright (c) 2017-2022, Arm Limited. All rights reserved.*
Chris Brand80266ba2022-01-05 09:14:52 -0800333*Copyright (c) 2022, Cypress Semiconductor Corporation. All rights reserved.*