blob: 96b78675408c1968d139a3f1d9e2e4fa98dd6eb2 [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
Summer Qin6d5c91c2021-05-24 15:32:44 +08005:doc:`TF-M getting started </docs/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
Summer Qinab1dd992021-05-25 13:58:55 +080028:ref:`docs/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
Summer Qin6d5c91c2021-05-24 15:32:44 +080034 in :doc:`TF-M getting started </docs/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
80+----------------------+-------------------------------------------------------+
81| Parameter | Description |
82+======================+=======================================================+
83| TFM_PLATFORM | The target platform as a path from the base directory |
Øyvind Rønningstada9d5eac2021-01-22 14:21:25 +010084| | ``/platform/ext/target``, or as an absolute path. |
Anton Komlevb8e3af02020-08-28 10:23:57 +010085+----------------------+-------------------------------------------------------+
Anton Komlevb8e3af02020-08-28 10:23:57 +010086
87By default release configuration builds. Alternate build types can be controlled
88by the CMAKE_BUILD_TYPE variable.
89
90Build type
91----------
92
93Build type is controlled by the ``CMAKE_BUILD_TYPE`` variable. The possible
94types are:
95
96 - ``Debug``
97 - ``Relwithdebinfo``
98 - ``Release``
99 - ``Minsizerel``
100
101``Release`` is default.
102
103Both ``Debug`` and ``Relwithdebinfo`` will include debug symbols in the output
104files. ``Relwithdebinfo``, ``Release`` and ``Minsizerel`` have optimization
Raef Coles1ecb8132020-10-02 15:11:24 +0100105turned on and hence will produce smaller, faster code. ``Minsizerel`` will
Anton Komlevb8e3af02020-08-28 10:23:57 +0100106produce the smallest code, and hence is often a good idea on RAM or flash
107constrained systems.
108
109Other cmake parameters
110----------------------
111
112The full list of default options is in ``config/config_default.cmake``. Several
113important options are listed below.
114
115
116+---------------------+----------------------------------------+---------------+
117| Parameter | Description | Default value |
118+=====================+========================================+===============+
119| BL2 | Build level 2 secure bootloader. | ON |
120+---------------------+----------------------------------------+---------------+
121| NS | Build NS app. Required for test code. | ON |
122+---------------------+----------------------------------------+---------------+
123| TFM_PSA_API | Use PSA api (IPC mode) instead of | OFF |
124| | secure library mode. | |
125+---------------------+----------------------------------------+---------------+
126| TFM_ISOLATION_LEVEL | Set TFM isolation level. | 1 |
127+---------------------+----------------------------------------+---------------+
128| TFM_PROFILE | Set TFM profile. | |
129+---------------------+----------------------------------------+---------------+
130| TEST_S | Build secure regression tests. | OFF |
131+---------------------+----------------------------------------+---------------+
132| TEST_NS | Build non-secure regression tests. | OFF |
133+---------------------+----------------------------------------+---------------+
134| TEST_PSA_API | Build PSA API TESTS for the given | |
135| | suite. Takes a PSA api ``SUITE`` as an | |
136| | argument (``CRYPTO`` etc). | |
137+---------------------+----------------------------------------+---------------+
138
139Regression test configuration
140-----------------------------
141
shejia01bfd37122021-06-03 13:31:51 +0800142Regression test configuration is controlled entirely by ``TEST_NS`` or
143``TEST_S`` or single test suite configuration. The group test
144configurations and single test suite configurations are listed below, all of
145them are disabled by default.
146
147+---------------------+--------------------------------------------------------------------+
148| Parameter | Description |
149+=====================+====================================================================+
150| TEST_NS_ATTESTATION | Build non-secure regression Attestation tests. |
151+---------------------+--------------------------------------------------------------------+
152| TEST_NS_T_COSE | Build non-secure regression t_cose tests. |
153+---------------------+--------------------------------------------------------------------+
154| TEST_NS_QCBOR | Build non-secure regression QCBOR tests. |
155+---------------------+--------------------------------------------------------------------+
156| TEST_NS_AUDIT | Build non-secure regression Audit log tests. |
157+---------------------+--------------------------------------------------------------------+
158| TEST_NS_CORE | Build non-secure regression Core tests. |
159+---------------------+--------------------------------------------------------------------+
160| TEST_NS_CRYPTO | Build non-secure regression Crypto tests. |
161+---------------------+--------------------------------------------------------------------+
162| TEST_NS_ITS | Build non-secure regression ITS tests. |
163+---------------------+--------------------------------------------------------------------+
164| TEST_NS_PS | Build non-secure regression PS tests. |
165+---------------------+--------------------------------------------------------------------+
166| TEST_NS_PLATFORM | Build non-secure regression Platform tests. |
167+---------------------+--------------------------------------------------------------------+
168| TEST_NS_FWU | Build non-secure regression FWU tests. |
169+---------------------+--------------------------------------------------------------------+
170| TEST_NS_IPC | Build non-secure regression IPC tests. |
171+---------------------+--------------------------------------------------------------------+
172| TEST_NS_SLIH_IRQ | Build non-secure regression Second-Level Interrupt Handling tests. |
173+---------------------+--------------------------------------------------------------------+
174| TEST_NS_FLIH_IRQ | Build non-secure regression First-Level Interrupt Handling tests. |
175+---------------------+--------------------------------------------------------------------+
176| TEST_NS_MULTI_CORE | Build non-secure regression multi-core tests. |
177+---------------------+--------------------------------------------------------------------+
178| TEST_S_ATTESTATION | Build secure regression Attestation tests. |
179+---------------------+--------------------------------------------------------------------+
180| TEST_S_AUDIT | Build secure regression Audit log tests. |
181+---------------------+--------------------------------------------------------------------+
182| TEST_S_CRYPTO | Build secure regression Crypto tests. |
183+---------------------+--------------------------------------------------------------------+
184| TEST_S_ITS | Build secure regression ITS tests. |
185+---------------------+--------------------------------------------------------------------+
186| TEST_S_PS | Build secure regression PS tests. |
187+---------------------+--------------------------------------------------------------------+
188| TEST_S_PLATFORM | Build secure regression Platform tests. |
189+---------------------+--------------------------------------------------------------------+
190| TEST_S_FWU | Build secure regression FWU tests. |
191+---------------------+--------------------------------------------------------------------+
192| TEST_S_IPC | Build secure regression IPC tests. |
193+---------------------+--------------------------------------------------------------------+
194
195The single test suite can be opened when their dependencies like partitions or
196other specific configurations are set. On the one hand, some test suites depend
197on other test suites. On the other hand, some test suites have confict with
198other test suites. Test configurations and dependencies will be
199checked in ``${TFM_TEST_REPO_PATH}/test/config/check_config.cmake``.
Anton Komlevb8e3af02020-08-28 10:23:57 +0100200
201If regression testing is enabled, it will then enable all tests for the enabled
202secure partitions. If IPC mode is enabled via ``TFM_PSA_API`` the IPC tests will
shejia01bfd37122021-06-03 13:31:51 +0800203be enabled. Multicore tests will be enabled if ``TFM_MULTI_CORE_TOPOLOGY`` is
204enabled.
Anton Komlevb8e3af02020-08-28 10:23:57 +0100205
206Some cryptographic tests can be enabled and disabled. This is done to prevent
207false failures from being reported when a smaller Mbed Crypto config is being
208used which does not support all features.
209
210+-----------------------------+-------------------------------------+---------------+
211| Parameter | Description | Default value |
212+=============================+=====================================+===============+
213| TFM_CRYPTO_TEST_ALG_CBC | Test CBC cryptography mode | ON |
214+-----------------------------+-------------------------------------+---------------+
215| TFM_CRYPTO_TEST_ALG_CCM | Test CCM cryptography mode | ON |
216+-----------------------------+-------------------------------------+---------------+
217| TFM_CRYPTO_TEST_ALG_CFB | Test CFB cryptography mode | ON |
218+-----------------------------+-------------------------------------+---------------+
Abbas Bracken Ziad46a21b62021-08-31 13:03:56 +0100219| TFM_CRYPTO_TEST_ALG_ECB | Test ECB cryptography mode | ON |
220+-----------------------------+-------------------------------------+---------------+
Anton Komlevb8e3af02020-08-28 10:23:57 +0100221| TFM_CRYPTO_TEST_ALG_CTR | Test CTR cryptography mode | ON |
222+-----------------------------+-------------------------------------+---------------+
Abbas Bracken Ziad3d262f42021-08-19 15:07:05 +0100223| TFM_CRYPTO_TEST_ALG_OFB | Test OFB cryptography mode | ON |
224+-----------------------------+-------------------------------------+---------------+
Anton Komlevb8e3af02020-08-28 10:23:57 +0100225| TFM_CRYPTO_TEST_ALG_GCM | Test GCM cryptography mode | ON |
226+-----------------------------+-------------------------------------+---------------+
227| TFM_CRYPTO_TEST_ALG_SHA_512 | Test SHA-512 cryptography algorithm | ON |
228+-----------------------------+-------------------------------------+---------------+
Antonio de Angelis6eb5ecb2021-07-29 11:33:48 +0200229| TFM_CRYPTO_TEST_HKDF | Test HKDF key derivation algorithm | ON |
230+-----------------------------+-------------------------------------+---------------+
231| TFM_CRYPTO_TEST_ECDH | Test ECDH key agreement algorithm | ON |
Anton Komlevb8e3af02020-08-28 10:23:57 +0100232+-----------------------------+-------------------------------------+---------------+
233
Anton Komlev211aacf2020-11-02 12:48:11 +0000234TF-M Profiles
235-------------
236
237TF-M Profiles are implemented as a single cmake configuration file, under the
238``config/profile`` directory. A good understanding can be gained quickly by
239looking at the Profile configuration files, but the ultimate reference for
Summer Qinabf66982021-04-06 17:22:15 +0800240Profiles are the design documents in the ``docs/technical_references/profiles/``
Anton Komlev211aacf2020-11-02 12:48:11 +0000241directory.
Anton Komlevb8e3af02020-08-28 10:23:57 +0100242
243PSA test configuration
244----------------------
245
246PSA tests are configured by using the ``TEST_PSA_API`` cmake variable. The
247variable should be set to the name of the test suite that is desired. It is
248_not_ supported to set both ``TEST_PSA_API`` and ``TEST_S`` or ``TEST_NS``.
249
Jamie Fox19c91c22019-02-10 18:04:58 +0000250The Functional API tests are:
Anton Komlevb8e3af02020-08-28 10:23:57 +0100251 - ``CRYPTO``
252 - ``INITIAL_ATTESTATION``
253 - ``STORAGE`` (INTERNAL_TRUSTED_STORAGE and PROTECTED_STORAGE)
254 - ``INTERNAL_TRUSTED_STORAGE``
255 - ``PROTECTED_STORAGE``
256
Jamie Fox19c91c22019-02-10 18:04:58 +0000257The Firmware Framework test suites are:
Anton Komlevb8e3af02020-08-28 10:23:57 +0100258 - ``IPC``
259
260Note that these map directly to the ``SUITE`` cmake variable used in the
261psa-arch-tests documentation.
262
David Wangd6fd6af2021-06-21 17:17:26 +0800263.. _Migration from legacy buildsystem:
264
Anton Komlevb8e3af02020-08-28 10:23:57 +0100265Migration from legacy buildsystem
266---------------------------------
267
268The previous (legacy) cmake buildsystem made use of separate configuration
269files, where now build options are controlled by variables. For ease of
270transition, a table below is provided that maps the legacy files to the current
271variables, in the format of cmake command line parameters.
272
Summer Qin001ce9d2020-11-04 14:41:54 +0800273+------------------------------------------+---------------------------------------+
274| File | Cmake command line |
275+==========================================+=======================================+
276| ConfigDefault.cmake | <No options> |
277+------------------------------------------+---------------------------------------+
278| ConfigCoreIPC.cmake | -DTFM_PSA_API=ON |
279+------------------------------------------+---------------------------------------+
280| ConfigCoreIPCTfmLevel2.cmake | -DTFM_PSA_API=ON |
281| | -DTFM_ISOLATION_LEVEL=2 |
282+------------------------------------------+---------------------------------------+
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 |
290| | -DTFM_PSA_API=ON |
291+------------------------------------------+---------------------------------------+
292| ConfigRegressionIPCTfmLevel2.cmake | -DTEST_NS=ON -DTEST_S=ON |
293| | -DTFM_PSA_API=ON |
294| | -DTFM_ISOLATION_LEVEL=2 |
295+------------------------------------------+---------------------------------------+
296| ConfigRegressionProfileS.cmake | -DTFM_PROFILE=profile_small |
297| | -DTEST_NS=ON -DTEST_S=ON |
298+------------------------------------------+---------------------------------------+
299| ConfigRegressionProfileM.cmake | -DTFM_PROFILE=profile_medium |
300| | -DTEST_NS=ON -DTEST_S=ON |
301+------------------------------------------+---------------------------------------+
302| ConfigPsaApiTest.cmake | -DTEST_PSA_API=<test_suite> |
303+------------------------------------------+---------------------------------------+
304| ConfigPsaApiTestIPC.cmake | -DTEST_PSA_API=<test_suite> |
305| | -DTFM_PSA_API=ON |
306+------------------------------------------+---------------------------------------+
307| ConfigPsaApiTestIPCTfmLevel2.cmake | -DTEST_PSA_API=<test_suite> |
308| | -DTFM_PSA_API=ON |
309| | -DTFM_ISOLATION_LEVEL=2 |
310+------------------------------------------+---------------------------------------+
311| ConfigDefaultProfileM.cmake | -DTFM_PROFILE=profile_medium |
312| + profile_m_config_ext_ps_disabled.cmake | -DTFM_PARTITION_PROTECTED_STORAGE=OFF |
313+------------------------------------------+---------------------------------------+
Anton Komlevb8e3af02020-08-28 10:23:57 +0100314
315There has also been some changes to the PSA manifest file generation. The files
316are now generated into a seperate tree in the ``<tfm build dir>/generated``
317directory. Therefore they have been removed from the source tree. Any changes
318should be made only to the template files.
319
320The api for the ``tools/tfm_parse_manifest_list.py`` script has also changed
321slightly. It is no longer required to be run manually as it is run as part of
322cmake.
323
324*******************
325TF-M build examples
326*******************
327
Subhasish Ghoshbc849302021-04-08 20:21:20 +0100328.. Note::
329 By default, CMAKE_BUILD_TYPE is set to Release, for debug support change
330 this to Debug. See below for an example.
331
Anton Komlevb8e3af02020-08-28 10:23:57 +0100332Example: 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>
Summer Qin2de23d02021-05-14 13:44:14 +0800337 cmake -S . -B cmake_build -DTFM_PLATFORM=arm/mps2/an521 -DTFM_TOOLCHAIN_FILE=toolchain_GNUARM.cmake -DCMAKE_BUILD_TYPE=Debug
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
Summer Qin2de23d02021-05-14 13:44:14 +0800347 cmake .. -DTFM_PLATFORM=arm/mps2/an521 -DTFM_TOOLCHAIN_FILE=../toolchain_GNUARM.cmake
Anton Komlevb8e3af02020-08-28 10:23:57 +0100348 make install
349
350.. Note::
351 Unix Makefiles is the default generator. Ninja is also supported by setting
352 -GNinja
353
354.. Note::
355
356 It is recommended to build each different build configuration in a separate
357 build directory.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200358
Leonardo Sandoval49a558c2021-02-03 17:04:22 -0600359As seen above, the toolchain can be set using the -DTFM_TOOLCHAIN_FILE parameter. Without
360it, the build command takes the GNU ARM toolchain as default, so there is no need
361to explicitly include it. In case other toolchain is required, i.e. ARM Clang, simply
362specify in the command line
363
364.. code-block:: bash
Subhasish Ghoshbc849302021-04-08 20:21:20 +0100365
Leonardo Sandoval49a558c2021-02-03 17:04:22 -0600366 cd <TF-M base folder>
Summer Qin2de23d02021-05-14 13:44:14 +0800367 cmake -S . -B cmake_build -DTFM_PLATFORM=arm/mps2/an521 -DTFM_TOOLCHAIN_FILE=toolchain_ARMCLANG.cmake -DTEST_S=ON -DTEST_NS=ON
Leonardo Sandoval49a558c2021-02-03 17:04:22 -0600368 cmake --build cmake_build -- install
369
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200370Regression Tests for the AN521 target platform
371==============================================
Anton Komlevb8e3af02020-08-28 10:23:57 +0100372
373Regression tests can be build by using the TEST_S and TEST_NS settings. Either
374can be used in isolation or both can be used to enable both suites. All tests
375for all enabled partitions are run, along with IPC and Multicore tests if those
376features are enabled.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200377
378.. code-block:: bash
379
Leonardo Sandoval98350142021-02-03 16:32:14 -0600380 cd <TF-M base folder>
Summer Qin2de23d02021-05-14 13:44:14 +0800381 cmake -S . -B cmake_build -DTFM_PLATFORM=arm/mps2/an521 -DTEST_S=ON -DTEST_NS=ON
Anton Komlevb8e3af02020-08-28 10:23:57 +0100382 cmake --build cmake_build -- install
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200383
Anton Komlevb8e3af02020-08-28 10:23:57 +0100384Alternately using traditional cmake syntax
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200385
386.. code-block:: bash
387
Leonardo Sandoval98350142021-02-03 16:32:14 -0600388 cd <TF-M base folder>
Anton Komlevb8e3af02020-08-28 10:23:57 +0100389 mkdir cmake_build
390 cd cmake_build
Summer Qin2de23d02021-05-14 13:44:14 +0800391 cmake .. -DTFM_PLATFORM=arm/mps2/an521 -DTEST_S=ON -DTEST_NS=ON
Anton Komlevb8e3af02020-08-28 10:23:57 +0100392 make install
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200393
Jamie Fox19c91c22019-02-10 18:04:58 +0000394Build for PSA Functional API compliance tests
395=============================================
Anton Komlevb8e3af02020-08-28 10:23:57 +0100396The build system provides support for building and integrating the PSA API tests
397from https://github.com/ARM-software/psa-arch-tests. PSA API tests are
398controlled using the TEST_PSA_API variable. Enabling both regression tests and
399PSA API tests simultaneously is **not** supported.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200400
Anton Komlevb8e3af02020-08-28 10:23:57 +0100401The value of the TEST_PSA_API variable is the suite to be run.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200402
Subhasish Ghoshbc849302021-04-08 20:21:20 +0100403.. code-block:: bash
Anton Komlevb8e3af02020-08-28 10:23:57 +0100404
405 -DTEST_PSA_API=INTERNAL_TRUSTED_STORAGE
406 -DTEST_PSA_API=PROTECTED_STORAGE
407 -DTEST_PSA_API=STORAGE
408 -DTEST_PSA_API=CRYPTO
409 -DTEST_PSA_API=INITIAL_ATTESTATION
410
411Respectively for the corresponding service. For example, to enable the PSA API
412tests for the Crypto service:
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200413
414.. code-block:: bash
415
Leonardo Sandoval98350142021-02-03 16:32:14 -0600416 cd <TF-M base folder>
Summer Qin2de23d02021-05-14 13:44:14 +0800417 cmake -S . -B cmake_build -DTFM_PLATFORM=arm/mps2/an521 -DTEST_PSA_API=CRYPTO
Anton Komlevb8e3af02020-08-28 10:23:57 +0100418 cmake --build cmake_build -- install
419
420Alternately using traditional cmake syntax
421
422.. code-block:: bash
423
Leonardo Sandoval98350142021-02-03 16:32:14 -0600424 cd <TF-M base folder>
Anton Komlevb8e3af02020-08-28 10:23:57 +0100425 mkdir cmake_build
426 cd cmake_build
Summer Qin2de23d02021-05-14 13:44:14 +0800427 cmake .. -DTFM_PLATFORM=arm/mps2/an521 -DTEST_PSA_API=CRYPTO
Anton Komlevb8e3af02020-08-28 10:23:57 +0100428 make install
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200429
Jaykumar Pitambarbhai Patel6891b8b2020-01-23 14:32:20 +0530430Build for PSA FF (IPC) compliance tests
431=======================================
432
Anton Komlevb8e3af02020-08-28 10:23:57 +0100433The build system provides support for building and integrating the PSA FF
434compliance test. This support is controlled by the TEST_PSA_API variable:
Jaykumar Pitambarbhai Patel6891b8b2020-01-23 14:32:20 +0530435
Subhasish Ghoshbc849302021-04-08 20:21:20 +0100436.. code-block:: bash
Anton Komlevb8e3af02020-08-28 10:23:57 +0100437
438 -DTEST_PSA_API=IPC
Jaykumar Pitambarbhai Patel6891b8b2020-01-23 14:32:20 +0530439
440.. code-block:: bash
Minos Galanakisfc6804e2020-03-10 11:03:34 +0000441
Leonardo Sandoval98350142021-02-03 16:32:14 -0600442 cd <TF-M base folder>
Summer Qin2de23d02021-05-14 13:44:14 +0800443 cmake -S . -B cmake_build -DTFM_PLATFORM=arm/mps2/an521 -DTEST_PSA_API=IPC -DTFM_PSA_API=ON
Anton Komlevb8e3af02020-08-28 10:23:57 +0100444 cmake --build cmake_build -- install
Jaykumar Pitambarbhai Patel6891b8b2020-01-23 14:32:20 +0530445
Anton Komlevb8e3af02020-08-28 10:23:57 +0100446Alternately using traditional cmake syntax
Jaykumar Pitambarbhai Patel6891b8b2020-01-23 14:32:20 +0530447
448.. code-block:: bash
449
Leonardo Sandoval98350142021-02-03 16:32:14 -0600450 cd <TF-M base folder>
Anton Komlevb8e3af02020-08-28 10:23:57 +0100451 mkdir cmake_build
452 cd cmake_build
Summer Qin2de23d02021-05-14 13:44:14 +0800453 cmake .. -DTFM_PLATFORM=arm/mps2/an521 -DTEST_PSA_API=IPC -DTFM_PSA_API=ON
Anton Komlevb8e3af02020-08-28 10:23:57 +0100454 make install
Jaykumar Pitambarbhai Patel6891b8b2020-01-23 14:32:20 +0530455
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200456Location of build artifacts
457===========================
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200458
Anton Komlevb8e3af02020-08-28 10:23:57 +0100459All build artifacts are provided in the ``<build_dir>/bin`` directory. It is
460**not** required to run ``make install`` to generate artifacts in this location.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200461
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200462
Anton Komlevb8e3af02020-08-28 10:23:57 +0100463For the purposes of maintaining compatibility with the legacy cmake build
464system, they are also provided in
465``<build_dir>/install/outputs/<target_platform>/``. In order to generate the
466artifacts in this location ``make install`` must be run.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200467
Anton Komlevb8e3af02020-08-28 10:23:57 +0100468****************************
469Manual dependency management
470****************************
Galanakis, Minos757139a2019-11-11 15:00:11 +0000471
Raef Coles1ecb8132020-10-02 15:11:24 +0100472The TF-M build system will by default fetch all dependencies with appropriate
473versions and store them inside the build tree. In this case, the build tree
474location is ``<build_dir>/lib/ext``, and the extra libraries can be cleaned by
475deleting that directory.
Galanakis, Minos757139a2019-11-11 15:00:11 +0000476
Raef Coles1ecb8132020-10-02 15:11:24 +0100477If you have local copies already, and wish to avoid having the libraries
478downloaded every time the build directory is deleted, then the following
Raef Colesc630b882020-12-10 15:46:18 +0000479variables can be set to the path to the root directory of the local repo. This
480will disable the automatic downloading for that dependency.
Raef Coles1ecb8132020-10-02 15:11:24 +0100481
Raef Colesc630b882020-12-10 15:46:18 +0000482+----------------+---------------------+-----------------------------------------------------+
483| Dependency | Cmake variable | Git repo URL |
484+================+=====================+=====================================================+
485| Mbed Crypto | MBEDCRYPTO_PATH | https://github.com/ARMmbed/mbedtls |
486+----------------+---------------------+-----------------------------------------------------+
487| tf-m-tests | TFM_TEST_REPO_PATH | https://git.trustedfirmware.org/TF-M/tf-m-tests.git |
488+----------------+---------------------+-----------------------------------------------------+
489| MCUboot | MCUBOOT_PATH | https://github.com/mcu-tools/mcuboot |
490+----------------+---------------------+-----------------------------------------------------+
491| psa-arch-tests | PSA_ARCH_TESTS_PATH | https://github.com/ARM-software/psa-arch-tests |
492+----------------+---------------------+-----------------------------------------------------+
Galanakis, Minos757139a2019-11-11 15:00:11 +0000493
Anton Komlevb8e3af02020-08-28 10:23:57 +0100494For required versions of the dependencies, refer to ``config/config_default.cmake``.
Galanakis, Minos757139a2019-11-11 15:00:11 +0000495
496.. Note::
Anton Komlevb8e3af02020-08-28 10:23:57 +0100497 - Some patches are required to the mbedtls repo to allow building it as part of
498 TF-M. While these patches are being upstreamed they are stored in
Raef Coles1ecb8132020-10-02 15:11:24 +0100499 ``lib/ext/mbedcrypo``. In order to use a local copy of Mbed Crypto it is
500 required to apply all patch files in this directory.
Galanakis, Minos757139a2019-11-11 15:00:11 +0000501
Anton Komlevb8e3af02020-08-28 10:23:57 +0100502.. Note::
503 - CMSIS 5 is provided by the TF-M tests repo. If you wish to use a different
504 source for CMSIS 5, it can be configured using CMSIS_5_PATH.
David Hu2cbf5df2020-06-15 10:41:44 +0800505
Kevin Pengcba37d32020-12-07 17:07:39 +0800506TF-M Tests
507==========
508
509Dependency auto downloading is used by default.
510The TF-M build system downloads the tf-m-tests repo with a fixed version
511specified by ``TFM_TEST_REPO_VERSION`` in ``config/config_default.cmake``.
512The version can be a release tag or a commit hash.
513
514Developers who want a different version of tf-m-tests can override
515``TFM_TEST_REPO_PATH`` to a local copy with the desired version.
516
517As the test repo is part of the TF-M project and coupled with TF-M repo a lot,
518The version should be updated when there are dependency changes between the TF-M
519repo and the test repo and when there is a complete change merged in test repo.
520
521A complete change is one or more patches that are for the same purpose, for
522example a new test suite or enhancements on the test cases.
523Patches in one change can be merge individually provided they do not break
524anything or cause any regressions.
525But the version in the TF-M gets updated only when all the patches are merged.
526
Raef Coles1ecb8132020-10-02 15:11:24 +0100527Example: building TF-M for AN521 platform with local Mbed Crypto
528================================================================
529
530Prepare Mbed Crypto repository
531------------------------------
532
533This is only required to be done once. For dependencies that do not have any
534``.patch`` files in their ``lib/ext`` directory the only required step is
535cloning the repo and checking out the correct branch.
536
537.. code-block:: bash
538
539 cd <Mbed Crypto base folder>
540 git clone https://github.com/ARMmbed/mbedtls
541 cd mbedtls
542 git checkout <MBEDCRYPTO_VERSION from config_default.cmake>
543 git apply <TF-M base folder>/trusted-firmware-m/lib/ext/mbedcrypo/*.patch
544
545.. Note::
546 - <Mbed Crypto base folder> does not need to have any fixed posisition related
547 to the TF-M repo.
548
549Build TF-M
550----------
551
552With new cmake syntax
553
554.. code-block:: bash
555
Leonardo Sandoval98350142021-02-03 16:32:14 -0600556 cd <TF-M base folder>
Summer Qin2de23d02021-05-14 13:44:14 +0800557 cmake -S . -B cmake_build -DTFM_PLATFORM=arm/mps2/an521 -DMBEDCRYPTO_PATH=<Mbed Crypto base folder>/mbedtls
Raef Coles1ecb8132020-10-02 15:11:24 +0100558 cmake --build cmake_build -- install
559
560Alternately using traditional cmake syntax
561
562.. code-block:: bash
563
Leonardo Sandoval98350142021-02-03 16:32:14 -0600564 cd <TF-M base folder>
Raef Coles1ecb8132020-10-02 15:11:24 +0100565 mkdir cmake_build
566 cd cmake_build
Summer Qin2de23d02021-05-14 13:44:14 +0800567 cmake .. -DTFM_PLATFORM=arm/mps2/an521 -DMBEDCRYPTO_PATH=<Mbed Crypto base folder>/mbedtls
Raef Coles1ecb8132020-10-02 15:11:24 +0100568 make install
569
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200570--------------
571
Summer Qinabf66982021-04-06 17:22:15 +0800572*Copyright (c) 2017-2021, Arm Limited. All rights reserved.*