blob: 3db54c4a9ed39569887176e36620b46442f092b7 [file] [log] [blame]
Galanakis, Minos41f85972019-09-30 15:56:40 +01001##################
2Build instructions
3##################
Gyorgy Szingdb9783c2019-04-17 21:08:48 +02004Please make sure you have all required software installed as explained in the
Anton Komlev3356ba32022-03-31 22:02:11 +01005:doc:`TF-M getting started </getting_started/tfm_getting_started>`.
Anton Komlev91281f02022-04-22 09:24:20 +01006The additional building materials you can find in the following links:
7
8.. toctree::
9 :maxdepth: 1
10
11 IAR toolchain <tfm_build_instruction_iar>
12 Run TF-M examples <run_tfm_examples_on_arm_platforms>
13 Building documentation <documentation_generation>
Gyorgy Szingdb9783c2019-04-17 21:08:48 +020014
Gyorgy Szingdb9783c2019-04-17 21:08:48 +020015****************
16TF-M build steps
17****************
18TF-M uses `cmake <https://cmake.org/overview/>`__ to provide an out-of-source
19build environment. The instructions are below.
20
Raef Coles69817322020-10-19 14:14:14 +010021Cmake version ``3.15.0`` or higher is required.
Raef Coles1ecb8132020-10-02 15:11:24 +010022
David Wangd6fd6af2021-06-21 17:17:26 +080023.. _Getting the source-code:
24
Gyorgy Szingdb9783c2019-04-17 21:08:48 +020025Getting the source-code
26=======================
27.. code-block:: bash
28
Leonardo Sandovald7f72d52020-07-28 18:02:34 -050029 cd <base folder>
Minos Galanakis0f39fa52020-06-08 16:53:53 +010030 git clone https://git.trustedfirmware.org/TF-M/trusted-firmware-m.git
Anton Komlevb8e3af02020-08-28 10:23:57 +010031
Leonardo Sandoval98350142021-02-03 16:32:14 -060032To simplify documentation commands, the new created repository under
33``trusted-firmware-m`` would be referenced as ``<TF-M base folder>`` and
34its parent, the ``<base folder>``. Dependency management is now handled by
35cmake. If you wish to alter this behaviour, see
Anton Komlev3356ba32022-03-31 22:02:11 +010036:ref:`technical_references/instructions/tfm_build_instruction:Manual
Anton Komlevb8e3af02020-08-28 10:23:57 +010037dependency 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 Komlevb8e3af02020-08-28 10:23:57 +010046.. _tfm_cmake_configuration:
47
48Cmake configuration
49===================
50
51All configuration options are provided by cmake variables, and their default
52values, with docstrings, can be found in ``config/config_default.cmake``.
53
Tamas Ban69219202020-10-27 08:13:18 +000054Configuration is provided in multiple stages. Each stage will not override any
55config that has already been set at any of the prior stages.
Anton Komlevb8e3af02020-08-28 10:23:57 +010056
Tamas Ban69219202020-10-27 08:13:18 +000057 1. Command-line variable settings are applied.
58 2. If the ``TFM_EXTRA_CONFIG_PATH`` variable has been set, that file is
Soby Mathew7b7e1242020-10-07 13:31:56 +010059 loaded.
Tamas Ban69219202020-10-27 08:13:18 +000060 3. If TEST_PSA_TEST is set, then PSA API test related config is applied from
61 ``config/tests/config_test_psa_api.cmake``.
62 4. If it exists, CMAKE_BUILD_TYPE specific config is applied from
63 ``config/build_type/<build_type>.cmake``.
64 5. Target specific config from ``platform/ext/target/<target_platform>/config.cmake``
65 is applied.
66 6. If CRYPTO_HW_ACCELERATOR is set, then a config specific to the
67 accelerator type is applied if it exists.
68 7. If it exists, TFM Profile specific config is applied from
69 ``config/profile/<tfm_profile>.cmake``.
70 8. ``config/config_default.cmake`` is loaded.
shejia01bfd37122021-06-03 13:31:51 +080071 9. If ``TEST_S`` or ``TEST_NS`` or other single test suite config like
72 ``TEST_NS_ATTESTATION`` (see `Regression test configuration`_)is set, then
73 config from ``${TFM_TEST_REPO_PATH}/test/config/set_config.cmake`` and
74 ``${TFM_TEST_REPO_PATH}/test/config/default_ns_test_config.cmake`` or
75 ``${TFM_TEST_REPO_PATH}/test/config/default_s_test_config.cmake`` or
76 ``${TFM_TEST_REPO_PATH}/test/config/default_test_config.cmake`` is
77 applied.
Anton Komlevb8e3af02020-08-28 10:23:57 +010078
79.. Warning::
80 This means that command-line settings are not applied when they conflict
81 with required platform settings. If it is required to override platform
82 settings (this is not usually a good idea) then TFM_EXTRA_CONFIG_PATH should be
83 used.
84
85Required cmake parameters for building TF-M
86-------------------------------------------
87
Jianliang Shen2628db72022-03-17 10:13:06 +080088``TFM_PLATFORM`` is required to select the target platform, it can be:
89 - A relative path under ``<TF-M_root>/platform/ext/target``,
90 for example ``arm/mps2/an521``.
91 - An absolute path of target platform, mainly used for out-of-tree platform
92 build.
93 - A target platform name that is supported under
94 <TF-M_root>/platform/ext/target, for example ``an521``.
Anton Komlevb8e3af02020-08-28 10:23:57 +010095
Anton Komlevb8e3af02020-08-28 10:23:57 +010096Build type
97----------
98
Chris Brand80266ba2022-01-05 09:14:52 -080099By default, a release configuration is built. Alternate build types can be
100specified with the ``CMAKE_BUILD_TYPE`` variable. The possible
Anton Komlevb8e3af02020-08-28 10:23:57 +0100101types are:
102
103 - ``Debug``
Sebastian Bøeb73f1762021-10-28 14:23:13 +0200104 - ``RelWithDebInfo``
Anton Komlevb8e3af02020-08-28 10:23:57 +0100105 - ``Release``
Sebastian Bøeb73f1762021-10-28 14:23:13 +0200106 - ``MinSizeRel``
Anton Komlevb8e3af02020-08-28 10:23:57 +0100107
108``Release`` is default.
109
Sebastian Bøeb73f1762021-10-28 14:23:13 +0200110Debug symbols are added by default to all builds, but can be removed
111from ``Release`` and ``MinSizeRel`` builds by setting
112``TFM_DEBUG_SYMBOLS`` to ``OFF``.
113
114``RelWithDebInfo``, ``Release`` and ``MinSizeRel`` all have different
115optimizations turned on and hence will produce smaller, faster code
116than ``Debug``. ``MinSizeRel`` will produce the smallest code, and
117hence is often a good idea on RAM or flash constrained systems.
Anton Komlevb8e3af02020-08-28 10:23:57 +0100118
119Other cmake parameters
120----------------------
121
122The full list of default options is in ``config/config_default.cmake``. Several
123important options are listed below.
124
125
126+---------------------+----------------------------------------+---------------+
127| Parameter | Description | Default value |
128+=====================+========================================+===============+
129| BL2 | Build level 2 secure bootloader. | ON |
130+---------------------+----------------------------------------+---------------+
131| NS | Build NS app. Required for test code. | ON |
132+---------------------+----------------------------------------+---------------+
Kevin Peng23a583c2021-09-08 22:33:33 +0800133| TFM_LIB_MODEL | Use secure library model instead of | OFF |
134| | PSA api (IPC model). | |
Anton Komlevb8e3af02020-08-28 10:23:57 +0100135+---------------------+----------------------------------------+---------------+
136| TFM_ISOLATION_LEVEL | Set TFM isolation level. | 1 |
137+---------------------+----------------------------------------+---------------+
138| TFM_PROFILE | Set TFM profile. | |
139+---------------------+----------------------------------------+---------------+
140| TEST_S | Build secure regression tests. | OFF |
141+---------------------+----------------------------------------+---------------+
142| TEST_NS | Build non-secure regression tests. | OFF |
143+---------------------+----------------------------------------+---------------+
144| TEST_PSA_API | Build PSA API TESTS for the given | |
145| | suite. Takes a PSA api ``SUITE`` as an | |
146| | argument (``CRYPTO`` etc). | |
147+---------------------+----------------------------------------+---------------+
148
149Regression test configuration
150-----------------------------
151
shejia01bfd37122021-06-03 13:31:51 +0800152Regression test configuration is controlled entirely by ``TEST_NS`` or
153``TEST_S`` or single test suite configuration. The group test
154configurations and single test suite configurations are listed below, all of
155them are disabled by default.
156
157+---------------------+--------------------------------------------------------------------+
158| Parameter | Description |
159+=====================+====================================================================+
160| TEST_NS_ATTESTATION | Build non-secure regression Attestation tests. |
161+---------------------+--------------------------------------------------------------------+
162| TEST_NS_T_COSE | Build non-secure regression t_cose tests. |
163+---------------------+--------------------------------------------------------------------+
164| TEST_NS_QCBOR | Build non-secure regression QCBOR tests. |
165+---------------------+--------------------------------------------------------------------+
166| TEST_NS_AUDIT | Build non-secure regression Audit log tests. |
167+---------------------+--------------------------------------------------------------------+
168| TEST_NS_CORE | Build non-secure regression Core tests. |
169+---------------------+--------------------------------------------------------------------+
170| TEST_NS_CRYPTO | Build non-secure regression Crypto tests. |
171+---------------------+--------------------------------------------------------------------+
172| TEST_NS_ITS | Build non-secure regression ITS tests. |
173+---------------------+--------------------------------------------------------------------+
174| TEST_NS_PS | Build non-secure regression PS tests. |
175+---------------------+--------------------------------------------------------------------+
176| TEST_NS_PLATFORM | Build non-secure regression Platform tests. |
177+---------------------+--------------------------------------------------------------------+
178| TEST_NS_FWU | Build non-secure regression FWU tests. |
179+---------------------+--------------------------------------------------------------------+
180| TEST_NS_IPC | Build non-secure regression IPC tests. |
181+---------------------+--------------------------------------------------------------------+
182| TEST_NS_SLIH_IRQ | Build non-secure regression Second-Level Interrupt Handling tests. |
183+---------------------+--------------------------------------------------------------------+
184| TEST_NS_FLIH_IRQ | Build non-secure regression First-Level Interrupt Handling tests. |
185+---------------------+--------------------------------------------------------------------+
186| TEST_NS_MULTI_CORE | Build non-secure regression multi-core tests. |
187+---------------------+--------------------------------------------------------------------+
188| TEST_S_ATTESTATION | Build secure regression Attestation tests. |
189+---------------------+--------------------------------------------------------------------+
190| TEST_S_AUDIT | Build secure regression Audit log tests. |
191+---------------------+--------------------------------------------------------------------+
192| TEST_S_CRYPTO | Build secure regression Crypto tests. |
193+---------------------+--------------------------------------------------------------------+
194| TEST_S_ITS | Build secure regression ITS tests. |
195+---------------------+--------------------------------------------------------------------+
196| TEST_S_PS | Build secure regression PS tests. |
197+---------------------+--------------------------------------------------------------------+
198| TEST_S_PLATFORM | Build secure regression Platform tests. |
199+---------------------+--------------------------------------------------------------------+
200| TEST_S_FWU | Build secure regression FWU tests. |
201+---------------------+--------------------------------------------------------------------+
202| TEST_S_IPC | Build secure regression IPC tests. |
203+---------------------+--------------------------------------------------------------------+
204
Chris Brand80266ba2022-01-05 09:14:52 -0800205Individual test suites can be enabled when their dependencies like partitions or
shejia01bfd37122021-06-03 13:31:51 +0800206other specific configurations are set. On the one hand, some test suites depend
Chris Brand80266ba2022-01-05 09:14:52 -0800207on other test suites. On the other hand, some test suites conflict with
shejia01bfd37122021-06-03 13:31:51 +0800208other test suites. Test configurations and dependencies will be
209checked in ``${TFM_TEST_REPO_PATH}/test/config/check_config.cmake``.
Anton Komlevb8e3af02020-08-28 10:23:57 +0100210
Chris Brand80266ba2022-01-05 09:14:52 -0800211If regression testing is enabled by ``TEST_NS`` or ``TEST_S``, individual
212test suites will be enabled or disabled as appropriate for the TF-M
213configuration (i.e. all enabled secure partitions will be tested).
Anton Komlevb8e3af02020-08-28 10:23:57 +0100214
215Some cryptographic tests can be enabled and disabled. This is done to prevent
216false failures from being reported when a smaller Mbed Crypto config is being
217used which does not support all features.
218
219+-----------------------------+-------------------------------------+---------------+
220| Parameter | Description | Default value |
221+=============================+=====================================+===============+
222| TFM_CRYPTO_TEST_ALG_CBC | Test CBC cryptography mode | ON |
223+-----------------------------+-------------------------------------+---------------+
224| TFM_CRYPTO_TEST_ALG_CCM | Test CCM cryptography mode | ON |
225+-----------------------------+-------------------------------------+---------------+
226| TFM_CRYPTO_TEST_ALG_CFB | Test CFB cryptography mode | ON |
227+-----------------------------+-------------------------------------+---------------+
Abbas Bracken Ziad46a21b62021-08-31 13:03:56 +0100228| TFM_CRYPTO_TEST_ALG_ECB | Test ECB cryptography mode | ON |
229+-----------------------------+-------------------------------------+---------------+
Anton Komlevb8e3af02020-08-28 10:23:57 +0100230| TFM_CRYPTO_TEST_ALG_CTR | Test CTR cryptography mode | ON |
231+-----------------------------+-------------------------------------+---------------+
Abbas Bracken Ziad3d262f42021-08-19 15:07:05 +0100232| TFM_CRYPTO_TEST_ALG_OFB | Test OFB cryptography mode | ON |
233+-----------------------------+-------------------------------------+---------------+
Anton Komlevb8e3af02020-08-28 10:23:57 +0100234| TFM_CRYPTO_TEST_ALG_GCM | Test GCM cryptography mode | ON |
235+-----------------------------+-------------------------------------+---------------+
236| TFM_CRYPTO_TEST_ALG_SHA_512 | Test SHA-512 cryptography algorithm | ON |
237+-----------------------------+-------------------------------------+---------------+
Antonio de Angelis6eb5ecb2021-07-29 11:33:48 +0200238| TFM_CRYPTO_TEST_HKDF | Test HKDF key derivation algorithm | ON |
239+-----------------------------+-------------------------------------+---------------+
240| TFM_CRYPTO_TEST_ECDH | Test ECDH key agreement algorithm | ON |
Anton Komlevb8e3af02020-08-28 10:23:57 +0100241+-----------------------------+-------------------------------------+---------------+
242
Anton Komlev211aacf2020-11-02 12:48:11 +0000243TF-M Profiles
244-------------
245
246TF-M Profiles are implemented as a single cmake configuration file, under the
247``config/profile`` directory. A good understanding can be gained quickly by
248looking at the Profile configuration files, but the ultimate reference for
Summer Qinabf66982021-04-06 17:22:15 +0800249Profiles are the design documents in the ``docs/technical_references/profiles/``
Anton Komlev211aacf2020-11-02 12:48:11 +0000250directory.
Anton Komlevb8e3af02020-08-28 10:23:57 +0100251
252PSA test configuration
253----------------------
254
255PSA tests are configured by using the ``TEST_PSA_API`` cmake variable. The
256variable should be set to the name of the test suite that is desired. It is
257_not_ supported to set both ``TEST_PSA_API`` and ``TEST_S`` or ``TEST_NS``.
258
Jamie Fox19c91c22019-02-10 18:04:58 +0000259The Functional API tests are:
Anton Komlevb8e3af02020-08-28 10:23:57 +0100260 - ``CRYPTO``
261 - ``INITIAL_ATTESTATION``
262 - ``STORAGE`` (INTERNAL_TRUSTED_STORAGE and PROTECTED_STORAGE)
263 - ``INTERNAL_TRUSTED_STORAGE``
264 - ``PROTECTED_STORAGE``
265
Jamie Fox19c91c22019-02-10 18:04:58 +0000266The Firmware Framework test suites are:
Anton Komlevb8e3af02020-08-28 10:23:57 +0100267 - ``IPC``
268
269Note that these map directly to the ``SUITE`` cmake variable used in the
270psa-arch-tests documentation.
271
David Wangd6fd6af2021-06-21 17:17:26 +0800272.. _Migration from legacy buildsystem:
273
Anton Komlevb8e3af02020-08-28 10:23:57 +0100274Migration from legacy buildsystem
275---------------------------------
276
277The previous (legacy) cmake buildsystem made use of separate configuration
278files, where now build options are controlled by variables. For ease of
279transition, a table below is provided that maps the legacy files to the current
280variables, in the format of cmake command line parameters.
281
Summer Qin001ce9d2020-11-04 14:41:54 +0800282+------------------------------------------+---------------------------------------+
283| File | Cmake command line |
284+==========================================+=======================================+
Kevin Peng23a583c2021-09-08 22:33:33 +0800285| ConfigDefault.cmake | -DTFM_LIB_MODEL=ON |
Summer Qin001ce9d2020-11-04 14:41:54 +0800286+------------------------------------------+---------------------------------------+
Kevin Peng23a583c2021-09-08 22:33:33 +0800287| ConfigCoreIPC.cmake | <no options> |
Summer Qin001ce9d2020-11-04 14:41:54 +0800288+------------------------------------------+---------------------------------------+
Kevin Peng23a583c2021-09-08 22:33:33 +0800289| ConfigCoreIPCTfmLevel2.cmake | -DTFM_ISOLATION_LEVEL=2 |
Summer Qin001ce9d2020-11-04 14:41:54 +0800290+------------------------------------------+---------------------------------------+
291| ConfigDefaultProfileS.cmake | -DTFM_PROFILE=profile_small |
292+------------------------------------------+---------------------------------------+
293| ConfigDefaultProfileM.cmake | -DTFM_PROFILE=profile_medium |
294+------------------------------------------+---------------------------------------+
295| ConfigRegression.cmake | -DTEST_NS=ON -DTEST_S=ON |
296+------------------------------------------+---------------------------------------+
297| ConfigRegressionIPC.cmake | -DTEST_NS=ON -DTEST_S=ON |
Summer Qin001ce9d2020-11-04 14:41:54 +0800298+------------------------------------------+---------------------------------------+
299| ConfigRegressionIPCTfmLevel2.cmake | -DTEST_NS=ON -DTEST_S=ON |
Summer Qin001ce9d2020-11-04 14:41:54 +0800300| | -DTFM_ISOLATION_LEVEL=2 |
301+------------------------------------------+---------------------------------------+
302| ConfigRegressionProfileS.cmake | -DTFM_PROFILE=profile_small |
303| | -DTEST_NS=ON -DTEST_S=ON |
304+------------------------------------------+---------------------------------------+
305| ConfigRegressionProfileM.cmake | -DTFM_PROFILE=profile_medium |
306| | -DTEST_NS=ON -DTEST_S=ON |
307+------------------------------------------+---------------------------------------+
308| ConfigPsaApiTest.cmake | -DTEST_PSA_API=<test_suite> |
309+------------------------------------------+---------------------------------------+
310| ConfigPsaApiTestIPC.cmake | -DTEST_PSA_API=<test_suite> |
Summer Qin001ce9d2020-11-04 14:41:54 +0800311+------------------------------------------+---------------------------------------+
312| ConfigPsaApiTestIPCTfmLevel2.cmake | -DTEST_PSA_API=<test_suite> |
Summer Qin001ce9d2020-11-04 14:41:54 +0800313| | -DTFM_ISOLATION_LEVEL=2 |
314+------------------------------------------+---------------------------------------+
315| ConfigDefaultProfileM.cmake | -DTFM_PROFILE=profile_medium |
316| + profile_m_config_ext_ps_disabled.cmake | -DTFM_PARTITION_PROTECTED_STORAGE=OFF |
317+------------------------------------------+---------------------------------------+
Anton Komlevb8e3af02020-08-28 10:23:57 +0100318
319There has also been some changes to the PSA manifest file generation. The files
Chris Brand80266ba2022-01-05 09:14:52 -0800320are now generated into a separate tree in the ``<tfm build dir>/generated``
Anton Komlevb8e3af02020-08-28 10:23:57 +0100321directory. Therefore they have been removed from the source tree. Any changes
322should be made only to the template files.
323
Chris Brand80266ba2022-01-05 09:14:52 -0800324The API for the ``tools/tfm_parse_manifest_list.py`` script has also changed
Anton Komlevb8e3af02020-08-28 10:23:57 +0100325slightly. It is no longer required to be run manually as it is run as part of
326cmake.
327
328*******************
329TF-M build examples
330*******************
331
332Example: building TF-M for AN521 platform using GCC:
333====================================================
334.. code-block:: bash
335
Leonardo Sandoval98350142021-02-03 16:32:14 -0600336 cd <TF-M base folder>
Chris Brand80266ba2022-01-05 09:14:52 -0800337 cmake -S . -B cmake_build -DTFM_PLATFORM=arm/mps2/an521
Anton Komlevb8e3af02020-08-28 10:23:57 +0100338 cmake --build cmake_build -- install
339
340Alternately using traditional cmake syntax
341
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200342.. code-block:: bash
343
Leonardo Sandoval98350142021-02-03 16:32:14 -0600344 cd <TF-M base folder>
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200345 mkdir cmake_build
346 cd cmake_build
Chris Brand80266ba2022-01-05 09:14:52 -0800347 cmake .. -DTFM_PLATFORM=arm/mps2/an521
Anton Komlevb8e3af02020-08-28 10:23:57 +0100348 make install
349
350.. Note::
Anton Komlevb8e3af02020-08-28 10:23:57 +0100351
352 It is recommended to build each different build configuration in a separate
353 build directory.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200354
Chris Brand80266ba2022-01-05 09:14:52 -0800355The default build uses Unix Makefiles. The ``-G`` option can be used to change
356this. The default build uses the GNU ARM toolchain and creates a Release build.
357These options can be overridden using the ``TFM_TOOLCHAIN_FILE`` and
358``CMAKE_BUILD_TYPE`` parameters, as shown below
Leonardo Sandoval49a558c2021-02-03 17:04:22 -0600359
360.. code-block:: bash
Subhasish Ghoshbc849302021-04-08 20:21:20 +0100361
Leonardo Sandoval49a558c2021-02-03 17:04:22 -0600362 cd <TF-M base folder>
Chris Brand80266ba2022-01-05 09:14:52 -0800363 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 -0600364 cmake --build cmake_build -- install
365
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200366Regression Tests for the AN521 target platform
367==============================================
Anton Komlevb8e3af02020-08-28 10:23:57 +0100368
369Regression tests can be build by using the TEST_S and TEST_NS settings. Either
370can be used in isolation or both can be used to enable both suites. All tests
371for all enabled partitions are run, along with IPC and Multicore tests if those
372features are enabled.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200373
374.. code-block:: bash
375
Leonardo Sandoval98350142021-02-03 16:32:14 -0600376 cd <TF-M base folder>
Summer Qin2de23d02021-05-14 13:44:14 +0800377 cmake -S . -B cmake_build -DTFM_PLATFORM=arm/mps2/an521 -DTEST_S=ON -DTEST_NS=ON
Anton Komlevb8e3af02020-08-28 10:23:57 +0100378 cmake --build cmake_build -- install
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200379
Anton Komlevb8e3af02020-08-28 10:23:57 +0100380Alternately using traditional cmake syntax
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200381
382.. code-block:: bash
383
Leonardo Sandoval98350142021-02-03 16:32:14 -0600384 cd <TF-M base folder>
Anton Komlevb8e3af02020-08-28 10:23:57 +0100385 mkdir cmake_build
386 cd cmake_build
Summer Qin2de23d02021-05-14 13:44:14 +0800387 cmake .. -DTFM_PLATFORM=arm/mps2/an521 -DTEST_S=ON -DTEST_NS=ON
Anton Komlevb8e3af02020-08-28 10:23:57 +0100388 make install
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200389
Kevin Peng23a583c2021-09-08 22:33:33 +0800390Build for PSA API tests
391=======================
Anton Komlevb8e3af02020-08-28 10:23:57 +0100392The build system provides support for building and integrating the PSA API tests
393from https://github.com/ARM-software/psa-arch-tests. PSA API tests are
394controlled using the TEST_PSA_API variable. Enabling both regression tests and
395PSA API tests simultaneously is **not** supported.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200396
Anton Komlevb8e3af02020-08-28 10:23:57 +0100397The value of the TEST_PSA_API variable is the suite to be run.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200398
Subhasish Ghoshbc849302021-04-08 20:21:20 +0100399.. code-block:: bash
Anton Komlevb8e3af02020-08-28 10:23:57 +0100400
401 -DTEST_PSA_API=INTERNAL_TRUSTED_STORAGE
402 -DTEST_PSA_API=PROTECTED_STORAGE
403 -DTEST_PSA_API=STORAGE
404 -DTEST_PSA_API=CRYPTO
405 -DTEST_PSA_API=INITIAL_ATTESTATION
406
407Respectively for the corresponding service. For example, to enable the PSA API
408tests for the Crypto service:
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200409
410.. code-block:: bash
411
Leonardo Sandoval98350142021-02-03 16:32:14 -0600412 cd <TF-M base folder>
Summer Qin2de23d02021-05-14 13:44:14 +0800413 cmake -S . -B cmake_build -DTFM_PLATFORM=arm/mps2/an521 -DTEST_PSA_API=CRYPTO
Anton Komlevb8e3af02020-08-28 10:23:57 +0100414 cmake --build cmake_build -- install
415
416Alternately using traditional cmake syntax
417
418.. code-block:: bash
419
Leonardo Sandoval98350142021-02-03 16:32:14 -0600420 cd <TF-M base folder>
Anton Komlevb8e3af02020-08-28 10:23:57 +0100421 mkdir cmake_build
422 cd cmake_build
Summer Qin2de23d02021-05-14 13:44:14 +0800423 cmake .. -DTFM_PLATFORM=arm/mps2/an521 -DTEST_PSA_API=CRYPTO
Anton Komlevb8e3af02020-08-28 10:23:57 +0100424 make install
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200425
426Location of build artifacts
427===========================
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200428
Anton Komlevb8e3af02020-08-28 10:23:57 +0100429All build artifacts are provided in the ``<build_dir>/bin`` directory. It is
430**not** required to run ``make install`` to generate artifacts in this location.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200431
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200432
Anton Komlevb8e3af02020-08-28 10:23:57 +0100433For the purposes of maintaining compatibility with the legacy cmake build
434system, they are also provided in
435``<build_dir>/install/outputs/<target_platform>/``. In order to generate the
436artifacts in this location ``make install`` must be run.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200437
Anton Komlevb8e3af02020-08-28 10:23:57 +0100438****************************
439Manual dependency management
440****************************
Galanakis, Minos757139a2019-11-11 15:00:11 +0000441
Raef Coles1ecb8132020-10-02 15:11:24 +0100442The TF-M build system will by default fetch all dependencies with appropriate
443versions and store them inside the build tree. In this case, the build tree
444location is ``<build_dir>/lib/ext``, and the extra libraries can be cleaned by
445deleting that directory.
Galanakis, Minos757139a2019-11-11 15:00:11 +0000446
Raef Coles1ecb8132020-10-02 15:11:24 +0100447If you have local copies already, and wish to avoid having the libraries
448downloaded every time the build directory is deleted, then the following
Raef Colesc630b882020-12-10 15:46:18 +0000449variables can be set to the path to the root directory of the local repo. This
450will disable the automatic downloading for that dependency.
Raef Coles1ecb8132020-10-02 15:11:24 +0100451
Raef Colesc630b882020-12-10 15:46:18 +0000452+----------------+---------------------+-----------------------------------------------------+
453| Dependency | Cmake variable | Git repo URL |
454+================+=====================+=====================================================+
455| Mbed Crypto | MBEDCRYPTO_PATH | https://github.com/ARMmbed/mbedtls |
456+----------------+---------------------+-----------------------------------------------------+
457| tf-m-tests | TFM_TEST_REPO_PATH | https://git.trustedfirmware.org/TF-M/tf-m-tests.git |
458+----------------+---------------------+-----------------------------------------------------+
459| MCUboot | MCUBOOT_PATH | https://github.com/mcu-tools/mcuboot |
460+----------------+---------------------+-----------------------------------------------------+
461| psa-arch-tests | PSA_ARCH_TESTS_PATH | https://github.com/ARM-software/psa-arch-tests |
462+----------------+---------------------+-----------------------------------------------------+
Galanakis, Minos757139a2019-11-11 15:00:11 +0000463
Anton Komlevb8e3af02020-08-28 10:23:57 +0100464For required versions of the dependencies, refer to ``config/config_default.cmake``.
Galanakis, Minos757139a2019-11-11 15:00:11 +0000465
466.. Note::
Anton Komlevb8e3af02020-08-28 10:23:57 +0100467 - Some patches are required to the mbedtls repo to allow building it as part of
468 TF-M. While these patches are being upstreamed they are stored in
Raef Coles1ecb8132020-10-02 15:11:24 +0100469 ``lib/ext/mbedcrypo``. In order to use a local copy of Mbed Crypto it is
470 required to apply all patch files in this directory.
Galanakis, Minos757139a2019-11-11 15:00:11 +0000471
Anton Komlevb8e3af02020-08-28 10:23:57 +0100472.. Note::
473 - CMSIS 5 is provided by the TF-M tests repo. If you wish to use a different
474 source for CMSIS 5, it can be configured using CMSIS_5_PATH.
David Hu2cbf5df2020-06-15 10:41:44 +0800475
Kevin Pengcba37d32020-12-07 17:07:39 +0800476TF-M Tests
477==========
478
479Dependency auto downloading is used by default.
480The TF-M build system downloads the tf-m-tests repo with a fixed version
David Huf89bcb62021-09-06 15:02:34 +0800481specified by ``TFM_TEST_REPO_VERSION`` in
482:file:`lib/ext/tf-m-tests/repo_config_default.cmake`.
Kevin Pengcba37d32020-12-07 17:07:39 +0800483The version can be a release tag or a commit hash.
484
485Developers who want a different version of tf-m-tests can override
486``TFM_TEST_REPO_PATH`` to a local copy with the desired version.
487
David Huf89bcb62021-09-06 15:02:34 +0800488As the test repo is part of the TF-M project and coupled with TF-M repo,
489the version should be updated when there are dependency changes between the TF-M
Kevin Pengcba37d32020-12-07 17:07:39 +0800490repo and the test repo and when there is a complete change merged in test repo.
491
492A complete change is one or more patches that are for the same purpose, for
493example a new test suite or enhancements on the test cases.
494Patches in one change can be merge individually provided they do not break
495anything or cause any regressions.
496But the version in the TF-M gets updated only when all the patches are merged.
497
Raef Coles1ecb8132020-10-02 15:11:24 +0100498Example: building TF-M for AN521 platform with local Mbed Crypto
499================================================================
500
501Prepare Mbed Crypto repository
502------------------------------
503
504This is only required to be done once. For dependencies that do not have any
505``.patch`` files in their ``lib/ext`` directory the only required step is
506cloning the repo and checking out the correct branch.
507
508.. code-block:: bash
509
510 cd <Mbed Crypto base folder>
511 git clone https://github.com/ARMmbed/mbedtls
512 cd mbedtls
513 git checkout <MBEDCRYPTO_VERSION from config_default.cmake>
514 git apply <TF-M base folder>/trusted-firmware-m/lib/ext/mbedcrypo/*.patch
515
516.. Note::
517 - <Mbed Crypto base folder> does not need to have any fixed posisition related
518 to the TF-M repo.
519
520Build TF-M
521----------
522
523With new cmake syntax
524
525.. code-block:: bash
526
Leonardo Sandoval98350142021-02-03 16:32:14 -0600527 cd <TF-M base folder>
Summer Qin2de23d02021-05-14 13:44:14 +0800528 cmake -S . -B cmake_build -DTFM_PLATFORM=arm/mps2/an521 -DMBEDCRYPTO_PATH=<Mbed Crypto base folder>/mbedtls
Raef Coles1ecb8132020-10-02 15:11:24 +0100529 cmake --build cmake_build -- install
530
531Alternately using traditional cmake syntax
532
533.. code-block:: bash
534
Leonardo Sandoval98350142021-02-03 16:32:14 -0600535 cd <TF-M base folder>
Raef Coles1ecb8132020-10-02 15:11:24 +0100536 mkdir cmake_build
537 cd cmake_build
Summer Qin2de23d02021-05-14 13:44:14 +0800538 cmake .. -DTFM_PLATFORM=arm/mps2/an521 -DMBEDCRYPTO_PATH=<Mbed Crypto base folder>/mbedtls
Raef Coles1ecb8132020-10-02 15:11:24 +0100539 make install
540
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200541--------------
542
Jianliang Shen2628db72022-03-17 10:13:06 +0800543*Copyright (c) 2017-2022, Arm Limited. All rights reserved.*
Chris Brand80266ba2022-01-05 09:14:52 -0800544*Copyright (c) 2022, Cypress Semiconductor Corporation. All rights reserved.*