blob: 5e34af5fbd7f6c9e9630251bf19283bb3b4829f3 [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>`.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +02006
Gyorgy Szingdb9783c2019-04-17 21:08:48 +02007****************
8TF-M build steps
9****************
10TF-M uses `cmake <https://cmake.org/overview/>`__ to provide an out-of-source
11build environment. The instructions are below.
12
Raef Coles69817322020-10-19 14:14:14 +010013Cmake version ``3.15.0`` or higher is required.
Raef Coles1ecb8132020-10-02 15:11:24 +010014
David Wangd6fd6af2021-06-21 17:17:26 +080015.. _Getting the source-code:
16
Gyorgy Szingdb9783c2019-04-17 21:08:48 +020017Getting the source-code
18=======================
19.. code-block:: bash
20
Leonardo Sandovald7f72d52020-07-28 18:02:34 -050021 cd <base folder>
Minos Galanakis0f39fa52020-06-08 16:53:53 +010022 git clone https://git.trustedfirmware.org/TF-M/trusted-firmware-m.git
Anton Komlevb8e3af02020-08-28 10:23:57 +010023
Leonardo Sandoval98350142021-02-03 16:32:14 -060024To simplify documentation commands, the new created repository under
25``trusted-firmware-m`` would be referenced as ``<TF-M base folder>`` and
26its parent, the ``<base folder>``. Dependency management is now handled by
27cmake. If you wish to alter this behaviour, see
Anton Komlev3356ba32022-03-31 22:02:11 +010028:ref:`technical_references/instructions/tfm_build_instruction:Manual
Anton Komlevb8e3af02020-08-28 10:23:57 +010029dependency management`
Gyorgy Szingdb9783c2019-04-17 21:08:48 +020030
Minos Galanakisac6b06c2020-03-19 12:57:02 +000031.. Note::
Anton Komlevb8e3af02020-08-28 10:23:57 +010032
Minos Galanakis3b740a12020-10-15 11:10:26 +010033 - For building with Armclang compiler version 6.10.0+, please follow the note
Anton Komlev3356ba32022-03-31 22:02:11 +010034 in :doc:`TF-M getting started </getting_started/tfm_getting_started>`.
Anton Komlevb8e3af02020-08-28 10:23:57 +010035 - For building with the IAR toolchain, please see the notes in
Minos Galanakis3b740a12020-10-15 11:10:26 +010036 :doc:`IAR software requirements <tfm_build_instruction_iar>`
TTornblomb9e5ed02020-02-13 16:53:15 +010037
Anton Komlevb8e3af02020-08-28 10:23:57 +010038.. _tfm_cmake_configuration:
39
40Cmake configuration
41===================
42
43All configuration options are provided by cmake variables, and their default
44values, with docstrings, can be found in ``config/config_default.cmake``.
45
Tamas Ban69219202020-10-27 08:13:18 +000046Configuration is provided in multiple stages. Each stage will not override any
47config that has already been set at any of the prior stages.
Anton Komlevb8e3af02020-08-28 10:23:57 +010048
Tamas Ban69219202020-10-27 08:13:18 +000049 1. Command-line variable settings are applied.
50 2. If the ``TFM_EXTRA_CONFIG_PATH`` variable has been set, that file is
Soby Mathew7b7e1242020-10-07 13:31:56 +010051 loaded.
Tamas Ban69219202020-10-27 08:13:18 +000052 3. If TEST_PSA_TEST is set, then PSA API test related config is applied from
53 ``config/tests/config_test_psa_api.cmake``.
54 4. If it exists, CMAKE_BUILD_TYPE specific config is applied from
55 ``config/build_type/<build_type>.cmake``.
56 5. Target specific config from ``platform/ext/target/<target_platform>/config.cmake``
57 is applied.
58 6. If CRYPTO_HW_ACCELERATOR is set, then a config specific to the
59 accelerator type is applied if it exists.
60 7. If it exists, TFM Profile specific config is applied from
61 ``config/profile/<tfm_profile>.cmake``.
62 8. ``config/config_default.cmake`` is loaded.
shejia01bfd37122021-06-03 13:31:51 +080063 9. If ``TEST_S`` or ``TEST_NS`` or other single test suite config like
64 ``TEST_NS_ATTESTATION`` (see `Regression test configuration`_)is set, then
65 config from ``${TFM_TEST_REPO_PATH}/test/config/set_config.cmake`` and
66 ``${TFM_TEST_REPO_PATH}/test/config/default_ns_test_config.cmake`` or
67 ``${TFM_TEST_REPO_PATH}/test/config/default_s_test_config.cmake`` or
68 ``${TFM_TEST_REPO_PATH}/test/config/default_test_config.cmake`` is
69 applied.
Anton Komlevb8e3af02020-08-28 10:23:57 +010070
71.. Warning::
72 This means that command-line settings are not applied when they conflict
73 with required platform settings. If it is required to override platform
74 settings (this is not usually a good idea) then TFM_EXTRA_CONFIG_PATH should be
75 used.
76
77Required cmake parameters for building TF-M
78-------------------------------------------
79
Jianliang Shen2628db72022-03-17 10:13:06 +080080``TFM_PLATFORM`` is required to select the target platform, it can be:
81 - A relative path under ``<TF-M_root>/platform/ext/target``,
82 for example ``arm/mps2/an521``.
83 - An absolute path of target platform, mainly used for out-of-tree platform
84 build.
85 - A target platform name that is supported under
86 <TF-M_root>/platform/ext/target, for example ``an521``.
Anton Komlevb8e3af02020-08-28 10:23:57 +010087
Anton Komlevb8e3af02020-08-28 10:23:57 +010088Build type
89----------
90
Chris Brand80266ba2022-01-05 09:14:52 -080091By default, a release configuration is built. Alternate build types can be
92specified with the ``CMAKE_BUILD_TYPE`` variable. The possible
Anton Komlevb8e3af02020-08-28 10:23:57 +010093types are:
94
95 - ``Debug``
Sebastian Bøeb73f1762021-10-28 14:23:13 +020096 - ``RelWithDebInfo``
Anton Komlevb8e3af02020-08-28 10:23:57 +010097 - ``Release``
Sebastian Bøeb73f1762021-10-28 14:23:13 +020098 - ``MinSizeRel``
Anton Komlevb8e3af02020-08-28 10:23:57 +010099
100``Release`` is default.
101
Sebastian Bøeb73f1762021-10-28 14:23:13 +0200102Debug symbols are added by default to all builds, but can be removed
103from ``Release`` and ``MinSizeRel`` builds by setting
104``TFM_DEBUG_SYMBOLS`` to ``OFF``.
105
106``RelWithDebInfo``, ``Release`` and ``MinSizeRel`` all have different
107optimizations turned on and hence will produce smaller, faster code
108than ``Debug``. ``MinSizeRel`` will produce the smallest code, and
109hence is often a good idea on RAM or flash constrained systems.
Anton Komlevb8e3af02020-08-28 10:23:57 +0100110
111Other cmake parameters
112----------------------
113
114The full list of default options is in ``config/config_default.cmake``. Several
115important options are listed below.
116
117
118+---------------------+----------------------------------------+---------------+
119| Parameter | Description | Default value |
120+=====================+========================================+===============+
121| BL2 | Build level 2 secure bootloader. | ON |
122+---------------------+----------------------------------------+---------------+
123| NS | Build NS app. Required for test code. | ON |
124+---------------------+----------------------------------------+---------------+
Kevin Peng23a583c2021-09-08 22:33:33 +0800125| TFM_LIB_MODEL | Use secure library model instead of | OFF |
126| | PSA api (IPC model). | |
Anton Komlevb8e3af02020-08-28 10:23:57 +0100127+---------------------+----------------------------------------+---------------+
128| TFM_ISOLATION_LEVEL | Set TFM isolation level. | 1 |
129+---------------------+----------------------------------------+---------------+
130| TFM_PROFILE | Set TFM profile. | |
131+---------------------+----------------------------------------+---------------+
132| TEST_S | Build secure regression tests. | OFF |
133+---------------------+----------------------------------------+---------------+
134| TEST_NS | Build non-secure regression tests. | OFF |
135+---------------------+----------------------------------------+---------------+
136| TEST_PSA_API | Build PSA API TESTS for the given | |
137| | suite. Takes a PSA api ``SUITE`` as an | |
138| | argument (``CRYPTO`` etc). | |
139+---------------------+----------------------------------------+---------------+
140
141Regression test configuration
142-----------------------------
143
shejia01bfd37122021-06-03 13:31:51 +0800144Regression test configuration is controlled entirely by ``TEST_NS`` or
145``TEST_S`` or single test suite configuration. The group test
146configurations and single test suite configurations are listed below, all of
147them are disabled by default.
148
149+---------------------+--------------------------------------------------------------------+
150| Parameter | Description |
151+=====================+====================================================================+
152| TEST_NS_ATTESTATION | Build non-secure regression Attestation tests. |
153+---------------------+--------------------------------------------------------------------+
154| TEST_NS_T_COSE | Build non-secure regression t_cose tests. |
155+---------------------+--------------------------------------------------------------------+
156| TEST_NS_QCBOR | Build non-secure regression QCBOR tests. |
157+---------------------+--------------------------------------------------------------------+
158| TEST_NS_AUDIT | Build non-secure regression Audit log tests. |
159+---------------------+--------------------------------------------------------------------+
160| TEST_NS_CORE | Build non-secure regression Core tests. |
161+---------------------+--------------------------------------------------------------------+
162| TEST_NS_CRYPTO | Build non-secure regression Crypto tests. |
163+---------------------+--------------------------------------------------------------------+
164| TEST_NS_ITS | Build non-secure regression ITS tests. |
165+---------------------+--------------------------------------------------------------------+
166| TEST_NS_PS | Build non-secure regression PS tests. |
167+---------------------+--------------------------------------------------------------------+
168| TEST_NS_PLATFORM | Build non-secure regression Platform tests. |
169+---------------------+--------------------------------------------------------------------+
170| TEST_NS_FWU | Build non-secure regression FWU tests. |
171+---------------------+--------------------------------------------------------------------+
172| TEST_NS_IPC | Build non-secure regression IPC tests. |
173+---------------------+--------------------------------------------------------------------+
174| TEST_NS_SLIH_IRQ | Build non-secure regression Second-Level Interrupt Handling tests. |
175+---------------------+--------------------------------------------------------------------+
176| TEST_NS_FLIH_IRQ | Build non-secure regression First-Level Interrupt Handling tests. |
177+---------------------+--------------------------------------------------------------------+
178| TEST_NS_MULTI_CORE | Build non-secure regression multi-core tests. |
179+---------------------+--------------------------------------------------------------------+
180| TEST_S_ATTESTATION | Build secure regression Attestation tests. |
181+---------------------+--------------------------------------------------------------------+
182| TEST_S_AUDIT | Build secure regression Audit log tests. |
183+---------------------+--------------------------------------------------------------------+
184| TEST_S_CRYPTO | Build secure regression Crypto tests. |
185+---------------------+--------------------------------------------------------------------+
186| TEST_S_ITS | Build secure regression ITS tests. |
187+---------------------+--------------------------------------------------------------------+
188| TEST_S_PS | Build secure regression PS tests. |
189+---------------------+--------------------------------------------------------------------+
190| TEST_S_PLATFORM | Build secure regression Platform tests. |
191+---------------------+--------------------------------------------------------------------+
192| TEST_S_FWU | Build secure regression FWU tests. |
193+---------------------+--------------------------------------------------------------------+
194| TEST_S_IPC | Build secure regression IPC tests. |
195+---------------------+--------------------------------------------------------------------+
196
Chris Brand80266ba2022-01-05 09:14:52 -0800197Individual test suites can be enabled when their dependencies like partitions or
shejia01bfd37122021-06-03 13:31:51 +0800198other specific configurations are set. On the one hand, some test suites depend
Chris Brand80266ba2022-01-05 09:14:52 -0800199on other test suites. On the other hand, some test suites conflict with
shejia01bfd37122021-06-03 13:31:51 +0800200other test suites. Test configurations and dependencies will be
201checked in ``${TFM_TEST_REPO_PATH}/test/config/check_config.cmake``.
Anton Komlevb8e3af02020-08-28 10:23:57 +0100202
Chris Brand80266ba2022-01-05 09:14:52 -0800203If regression testing is enabled by ``TEST_NS`` or ``TEST_S``, individual
204test suites will be enabled or disabled as appropriate for the TF-M
205configuration (i.e. all enabled secure partitions will be tested).
Anton Komlevb8e3af02020-08-28 10:23:57 +0100206
207Some cryptographic tests can be enabled and disabled. This is done to prevent
208false failures from being reported when a smaller Mbed Crypto config is being
209used which does not support all features.
210
211+-----------------------------+-------------------------------------+---------------+
212| Parameter | Description | Default value |
213+=============================+=====================================+===============+
214| TFM_CRYPTO_TEST_ALG_CBC | Test CBC cryptography mode | ON |
215+-----------------------------+-------------------------------------+---------------+
216| TFM_CRYPTO_TEST_ALG_CCM | Test CCM cryptography mode | ON |
217+-----------------------------+-------------------------------------+---------------+
218| TFM_CRYPTO_TEST_ALG_CFB | Test CFB cryptography mode | ON |
219+-----------------------------+-------------------------------------+---------------+
Abbas Bracken Ziad46a21b62021-08-31 13:03:56 +0100220| TFM_CRYPTO_TEST_ALG_ECB | Test ECB cryptography mode | ON |
221+-----------------------------+-------------------------------------+---------------+
Anton Komlevb8e3af02020-08-28 10:23:57 +0100222| TFM_CRYPTO_TEST_ALG_CTR | Test CTR cryptography mode | ON |
223+-----------------------------+-------------------------------------+---------------+
Abbas Bracken Ziad3d262f42021-08-19 15:07:05 +0100224| TFM_CRYPTO_TEST_ALG_OFB | Test OFB cryptography mode | ON |
225+-----------------------------+-------------------------------------+---------------+
Anton Komlevb8e3af02020-08-28 10:23:57 +0100226| TFM_CRYPTO_TEST_ALG_GCM | Test GCM cryptography mode | ON |
227+-----------------------------+-------------------------------------+---------------+
228| TFM_CRYPTO_TEST_ALG_SHA_512 | Test SHA-512 cryptography algorithm | ON |
229+-----------------------------+-------------------------------------+---------------+
Antonio de Angelis6eb5ecb2021-07-29 11:33:48 +0200230| TFM_CRYPTO_TEST_HKDF | Test HKDF key derivation algorithm | ON |
231+-----------------------------+-------------------------------------+---------------+
232| TFM_CRYPTO_TEST_ECDH | Test ECDH key agreement algorithm | ON |
Anton Komlevb8e3af02020-08-28 10:23:57 +0100233+-----------------------------+-------------------------------------+---------------+
234
Anton Komlev211aacf2020-11-02 12:48:11 +0000235TF-M Profiles
236-------------
237
238TF-M Profiles are implemented as a single cmake configuration file, under the
239``config/profile`` directory. A good understanding can be gained quickly by
240looking at the Profile configuration files, but the ultimate reference for
Summer Qinabf66982021-04-06 17:22:15 +0800241Profiles are the design documents in the ``docs/technical_references/profiles/``
Anton Komlev211aacf2020-11-02 12:48:11 +0000242directory.
Anton Komlevb8e3af02020-08-28 10:23:57 +0100243
244PSA test configuration
245----------------------
246
247PSA tests are configured by using the ``TEST_PSA_API`` cmake variable. The
248variable should be set to the name of the test suite that is desired. It is
249_not_ supported to set both ``TEST_PSA_API`` and ``TEST_S`` or ``TEST_NS``.
250
Jamie Fox19c91c22019-02-10 18:04:58 +0000251The Functional API tests are:
Anton Komlevb8e3af02020-08-28 10:23:57 +0100252 - ``CRYPTO``
253 - ``INITIAL_ATTESTATION``
254 - ``STORAGE`` (INTERNAL_TRUSTED_STORAGE and PROTECTED_STORAGE)
255 - ``INTERNAL_TRUSTED_STORAGE``
256 - ``PROTECTED_STORAGE``
257
Jamie Fox19c91c22019-02-10 18:04:58 +0000258The Firmware Framework test suites are:
Anton Komlevb8e3af02020-08-28 10:23:57 +0100259 - ``IPC``
260
261Note that these map directly to the ``SUITE`` cmake variable used in the
262psa-arch-tests documentation.
263
David Wangd6fd6af2021-06-21 17:17:26 +0800264.. _Migration from legacy buildsystem:
265
Anton Komlevb8e3af02020-08-28 10:23:57 +0100266Migration from legacy buildsystem
267---------------------------------
268
269The previous (legacy) cmake buildsystem made use of separate configuration
270files, where now build options are controlled by variables. For ease of
271transition, a table below is provided that maps the legacy files to the current
272variables, in the format of cmake command line parameters.
273
Summer Qin001ce9d2020-11-04 14:41:54 +0800274+------------------------------------------+---------------------------------------+
275| File | Cmake command line |
276+==========================================+=======================================+
Kevin Peng23a583c2021-09-08 22:33:33 +0800277| ConfigDefault.cmake | -DTFM_LIB_MODEL=ON |
Summer Qin001ce9d2020-11-04 14:41:54 +0800278+------------------------------------------+---------------------------------------+
Kevin Peng23a583c2021-09-08 22:33:33 +0800279| ConfigCoreIPC.cmake | <no options> |
Summer Qin001ce9d2020-11-04 14:41:54 +0800280+------------------------------------------+---------------------------------------+
Kevin Peng23a583c2021-09-08 22:33:33 +0800281| ConfigCoreIPCTfmLevel2.cmake | -DTFM_ISOLATION_LEVEL=2 |
Summer Qin001ce9d2020-11-04 14:41:54 +0800282+------------------------------------------+---------------------------------------+
283| ConfigDefaultProfileS.cmake | -DTFM_PROFILE=profile_small |
284+------------------------------------------+---------------------------------------+
285| ConfigDefaultProfileM.cmake | -DTFM_PROFILE=profile_medium |
286+------------------------------------------+---------------------------------------+
287| ConfigRegression.cmake | -DTEST_NS=ON -DTEST_S=ON |
288+------------------------------------------+---------------------------------------+
289| ConfigRegressionIPC.cmake | -DTEST_NS=ON -DTEST_S=ON |
Summer Qin001ce9d2020-11-04 14:41:54 +0800290+------------------------------------------+---------------------------------------+
291| ConfigRegressionIPCTfmLevel2.cmake | -DTEST_NS=ON -DTEST_S=ON |
Summer Qin001ce9d2020-11-04 14:41:54 +0800292| | -DTFM_ISOLATION_LEVEL=2 |
293+------------------------------------------+---------------------------------------+
294| ConfigRegressionProfileS.cmake | -DTFM_PROFILE=profile_small |
295| | -DTEST_NS=ON -DTEST_S=ON |
296+------------------------------------------+---------------------------------------+
297| ConfigRegressionProfileM.cmake | -DTFM_PROFILE=profile_medium |
298| | -DTEST_NS=ON -DTEST_S=ON |
299+------------------------------------------+---------------------------------------+
300| ConfigPsaApiTest.cmake | -DTEST_PSA_API=<test_suite> |
301+------------------------------------------+---------------------------------------+
302| ConfigPsaApiTestIPC.cmake | -DTEST_PSA_API=<test_suite> |
Summer Qin001ce9d2020-11-04 14:41:54 +0800303+------------------------------------------+---------------------------------------+
304| ConfigPsaApiTestIPCTfmLevel2.cmake | -DTEST_PSA_API=<test_suite> |
Summer Qin001ce9d2020-11-04 14:41:54 +0800305| | -DTFM_ISOLATION_LEVEL=2 |
306+------------------------------------------+---------------------------------------+
307| ConfigDefaultProfileM.cmake | -DTFM_PROFILE=profile_medium |
308| + profile_m_config_ext_ps_disabled.cmake | -DTFM_PARTITION_PROTECTED_STORAGE=OFF |
309+------------------------------------------+---------------------------------------+
Anton Komlevb8e3af02020-08-28 10:23:57 +0100310
311There has also been some changes to the PSA manifest file generation. The files
Chris Brand80266ba2022-01-05 09:14:52 -0800312are now generated into a separate tree in the ``<tfm build dir>/generated``
Anton Komlevb8e3af02020-08-28 10:23:57 +0100313directory. Therefore they have been removed from the source tree. Any changes
314should be made only to the template files.
315
Chris Brand80266ba2022-01-05 09:14:52 -0800316The API for the ``tools/tfm_parse_manifest_list.py`` script has also changed
Anton Komlevb8e3af02020-08-28 10:23:57 +0100317slightly. It is no longer required to be run manually as it is run as part of
318cmake.
319
320*******************
321TF-M build examples
322*******************
323
324Example: building TF-M for AN521 platform using GCC:
325====================================================
326.. code-block:: bash
327
Leonardo Sandoval98350142021-02-03 16:32:14 -0600328 cd <TF-M base folder>
Chris Brand80266ba2022-01-05 09:14:52 -0800329 cmake -S . -B cmake_build -DTFM_PLATFORM=arm/mps2/an521
Anton Komlevb8e3af02020-08-28 10:23:57 +0100330 cmake --build cmake_build -- install
331
332Alternately using traditional cmake syntax
333
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200334.. code-block:: bash
335
Leonardo Sandoval98350142021-02-03 16:32:14 -0600336 cd <TF-M base folder>
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200337 mkdir cmake_build
338 cd cmake_build
Chris Brand80266ba2022-01-05 09:14:52 -0800339 cmake .. -DTFM_PLATFORM=arm/mps2/an521
Anton Komlevb8e3af02020-08-28 10:23:57 +0100340 make install
341
342.. Note::
Anton Komlevb8e3af02020-08-28 10:23:57 +0100343
344 It is recommended to build each different build configuration in a separate
345 build directory.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200346
Chris Brand80266ba2022-01-05 09:14:52 -0800347The default build uses Unix Makefiles. The ``-G`` option can be used to change
348this. The default build uses the GNU ARM toolchain and creates a Release build.
349These options can be overridden using the ``TFM_TOOLCHAIN_FILE`` and
350``CMAKE_BUILD_TYPE`` parameters, as shown below
Leonardo Sandoval49a558c2021-02-03 17:04:22 -0600351
352.. code-block:: bash
Subhasish Ghoshbc849302021-04-08 20:21:20 +0100353
Leonardo Sandoval49a558c2021-02-03 17:04:22 -0600354 cd <TF-M base folder>
Chris Brand80266ba2022-01-05 09:14:52 -0800355 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 -0600356 cmake --build cmake_build -- install
357
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200358Regression Tests for the AN521 target platform
359==============================================
Anton Komlevb8e3af02020-08-28 10:23:57 +0100360
361Regression tests can be build by using the TEST_S and TEST_NS settings. Either
362can be used in isolation or both can be used to enable both suites. All tests
363for all enabled partitions are run, along with IPC and Multicore tests if those
364features are enabled.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200365
366.. code-block:: bash
367
Leonardo Sandoval98350142021-02-03 16:32:14 -0600368 cd <TF-M base folder>
Summer Qin2de23d02021-05-14 13:44:14 +0800369 cmake -S . -B cmake_build -DTFM_PLATFORM=arm/mps2/an521 -DTEST_S=ON -DTEST_NS=ON
Anton Komlevb8e3af02020-08-28 10:23:57 +0100370 cmake --build cmake_build -- install
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200371
Anton Komlevb8e3af02020-08-28 10:23:57 +0100372Alternately using traditional cmake syntax
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>
Anton Komlevb8e3af02020-08-28 10:23:57 +0100377 mkdir cmake_build
378 cd cmake_build
Summer Qin2de23d02021-05-14 13:44:14 +0800379 cmake .. -DTFM_PLATFORM=arm/mps2/an521 -DTEST_S=ON -DTEST_NS=ON
Anton Komlevb8e3af02020-08-28 10:23:57 +0100380 make install
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200381
Kevin Peng23a583c2021-09-08 22:33:33 +0800382Build for PSA API tests
383=======================
Anton Komlevb8e3af02020-08-28 10:23:57 +0100384The build system provides support for building and integrating the PSA API tests
385from https://github.com/ARM-software/psa-arch-tests. PSA API tests are
386controlled using the TEST_PSA_API variable. Enabling both regression tests and
387PSA API tests simultaneously is **not** supported.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200388
Anton Komlevb8e3af02020-08-28 10:23:57 +0100389The value of the TEST_PSA_API variable is the suite to be run.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200390
Subhasish Ghoshbc849302021-04-08 20:21:20 +0100391.. code-block:: bash
Anton Komlevb8e3af02020-08-28 10:23:57 +0100392
393 -DTEST_PSA_API=INTERNAL_TRUSTED_STORAGE
394 -DTEST_PSA_API=PROTECTED_STORAGE
395 -DTEST_PSA_API=STORAGE
396 -DTEST_PSA_API=CRYPTO
397 -DTEST_PSA_API=INITIAL_ATTESTATION
398
399Respectively for the corresponding service. For example, to enable the PSA API
400tests for the Crypto service:
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200401
402.. code-block:: bash
403
Leonardo Sandoval98350142021-02-03 16:32:14 -0600404 cd <TF-M base folder>
Summer Qin2de23d02021-05-14 13:44:14 +0800405 cmake -S . -B cmake_build -DTFM_PLATFORM=arm/mps2/an521 -DTEST_PSA_API=CRYPTO
Anton Komlevb8e3af02020-08-28 10:23:57 +0100406 cmake --build cmake_build -- install
407
408Alternately using traditional cmake syntax
409
410.. code-block:: bash
411
Leonardo Sandoval98350142021-02-03 16:32:14 -0600412 cd <TF-M base folder>
Anton Komlevb8e3af02020-08-28 10:23:57 +0100413 mkdir cmake_build
414 cd cmake_build
Summer Qin2de23d02021-05-14 13:44:14 +0800415 cmake .. -DTFM_PLATFORM=arm/mps2/an521 -DTEST_PSA_API=CRYPTO
Anton Komlevb8e3af02020-08-28 10:23:57 +0100416 make install
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200417
418Location of build artifacts
419===========================
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200420
Anton Komlevb8e3af02020-08-28 10:23:57 +0100421All build artifacts are provided in the ``<build_dir>/bin`` directory. It is
422**not** required to run ``make install`` to generate artifacts in this location.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200423
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200424
Anton Komlevb8e3af02020-08-28 10:23:57 +0100425For the purposes of maintaining compatibility with the legacy cmake build
426system, they are also provided in
427``<build_dir>/install/outputs/<target_platform>/``. In order to generate the
428artifacts in this location ``make install`` must be run.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200429
Anton Komlevb8e3af02020-08-28 10:23:57 +0100430****************************
431Manual dependency management
432****************************
Galanakis, Minos757139a2019-11-11 15:00:11 +0000433
Raef Coles1ecb8132020-10-02 15:11:24 +0100434The TF-M build system will by default fetch all dependencies with appropriate
435versions and store them inside the build tree. In this case, the build tree
436location is ``<build_dir>/lib/ext``, and the extra libraries can be cleaned by
437deleting that directory.
Galanakis, Minos757139a2019-11-11 15:00:11 +0000438
Raef Coles1ecb8132020-10-02 15:11:24 +0100439If you have local copies already, and wish to avoid having the libraries
440downloaded every time the build directory is deleted, then the following
Raef Colesc630b882020-12-10 15:46:18 +0000441variables can be set to the path to the root directory of the local repo. This
442will disable the automatic downloading for that dependency.
Raef Coles1ecb8132020-10-02 15:11:24 +0100443
Raef Colesc630b882020-12-10 15:46:18 +0000444+----------------+---------------------+-----------------------------------------------------+
445| Dependency | Cmake variable | Git repo URL |
446+================+=====================+=====================================================+
447| Mbed Crypto | MBEDCRYPTO_PATH | https://github.com/ARMmbed/mbedtls |
448+----------------+---------------------+-----------------------------------------------------+
449| tf-m-tests | TFM_TEST_REPO_PATH | https://git.trustedfirmware.org/TF-M/tf-m-tests.git |
450+----------------+---------------------+-----------------------------------------------------+
451| MCUboot | MCUBOOT_PATH | https://github.com/mcu-tools/mcuboot |
452+----------------+---------------------+-----------------------------------------------------+
453| psa-arch-tests | PSA_ARCH_TESTS_PATH | https://github.com/ARM-software/psa-arch-tests |
454+----------------+---------------------+-----------------------------------------------------+
Galanakis, Minos757139a2019-11-11 15:00:11 +0000455
Anton Komlevb8e3af02020-08-28 10:23:57 +0100456For required versions of the dependencies, refer to ``config/config_default.cmake``.
Galanakis, Minos757139a2019-11-11 15:00:11 +0000457
458.. Note::
Anton Komlevb8e3af02020-08-28 10:23:57 +0100459 - Some patches are required to the mbedtls repo to allow building it as part of
460 TF-M. While these patches are being upstreamed they are stored in
Raef Coles1ecb8132020-10-02 15:11:24 +0100461 ``lib/ext/mbedcrypo``. In order to use a local copy of Mbed Crypto it is
462 required to apply all patch files in this directory.
Galanakis, Minos757139a2019-11-11 15:00:11 +0000463
Anton Komlevb8e3af02020-08-28 10:23:57 +0100464.. Note::
465 - CMSIS 5 is provided by the TF-M tests repo. If you wish to use a different
466 source for CMSIS 5, it can be configured using CMSIS_5_PATH.
David Hu2cbf5df2020-06-15 10:41:44 +0800467
Kevin Pengcba37d32020-12-07 17:07:39 +0800468TF-M Tests
469==========
470
471Dependency auto downloading is used by default.
472The TF-M build system downloads the tf-m-tests repo with a fixed version
David Huf89bcb62021-09-06 15:02:34 +0800473specified by ``TFM_TEST_REPO_VERSION`` in
474:file:`lib/ext/tf-m-tests/repo_config_default.cmake`.
Kevin Pengcba37d32020-12-07 17:07:39 +0800475The version can be a release tag or a commit hash.
476
477Developers who want a different version of tf-m-tests can override
478``TFM_TEST_REPO_PATH`` to a local copy with the desired version.
479
David Huf89bcb62021-09-06 15:02:34 +0800480As the test repo is part of the TF-M project and coupled with TF-M repo,
481the version should be updated when there are dependency changes between the TF-M
Kevin Pengcba37d32020-12-07 17:07:39 +0800482repo and the test repo and when there is a complete change merged in test repo.
483
484A complete change is one or more patches that are for the same purpose, for
485example a new test suite or enhancements on the test cases.
486Patches in one change can be merge individually provided they do not break
487anything or cause any regressions.
488But the version in the TF-M gets updated only when all the patches are merged.
489
Raef Coles1ecb8132020-10-02 15:11:24 +0100490Example: building TF-M for AN521 platform with local Mbed Crypto
491================================================================
492
493Prepare Mbed Crypto repository
494------------------------------
495
496This is only required to be done once. For dependencies that do not have any
497``.patch`` files in their ``lib/ext`` directory the only required step is
498cloning the repo and checking out the correct branch.
499
500.. code-block:: bash
501
502 cd <Mbed Crypto base folder>
503 git clone https://github.com/ARMmbed/mbedtls
504 cd mbedtls
505 git checkout <MBEDCRYPTO_VERSION from config_default.cmake>
506 git apply <TF-M base folder>/trusted-firmware-m/lib/ext/mbedcrypo/*.patch
507
508.. Note::
509 - <Mbed Crypto base folder> does not need to have any fixed posisition related
510 to the TF-M repo.
511
512Build TF-M
513----------
514
515With new cmake syntax
516
517.. code-block:: bash
518
Leonardo Sandoval98350142021-02-03 16:32:14 -0600519 cd <TF-M base folder>
Summer Qin2de23d02021-05-14 13:44:14 +0800520 cmake -S . -B cmake_build -DTFM_PLATFORM=arm/mps2/an521 -DMBEDCRYPTO_PATH=<Mbed Crypto base folder>/mbedtls
Raef Coles1ecb8132020-10-02 15:11:24 +0100521 cmake --build cmake_build -- install
522
523Alternately using traditional cmake syntax
524
525.. code-block:: bash
526
Leonardo Sandoval98350142021-02-03 16:32:14 -0600527 cd <TF-M base folder>
Raef Coles1ecb8132020-10-02 15:11:24 +0100528 mkdir cmake_build
529 cd cmake_build
Summer Qin2de23d02021-05-14 13:44:14 +0800530 cmake .. -DTFM_PLATFORM=arm/mps2/an521 -DMBEDCRYPTO_PATH=<Mbed Crypto base folder>/mbedtls
Raef Coles1ecb8132020-10-02 15:11:24 +0100531 make install
532
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200533--------------
534
Jianliang Shen2628db72022-03-17 10:13:06 +0800535*Copyright (c) 2017-2022, Arm Limited. All rights reserved.*
Chris Brand80266ba2022-01-05 09:14:52 -0800536*Copyright (c) 2022, Cypress Semiconductor Corporation. All rights reserved.*