blob: 300098126587b49893e811866a19e6ec3f3f9df3 [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``
Sebastian Bøeb73f1762021-10-28 14:23:13 +020097 - ``RelWithDebInfo``
Anton Komlevb8e3af02020-08-28 10:23:57 +010098 - ``Release``
Sebastian Bøeb73f1762021-10-28 14:23:13 +020099 - ``MinSizeRel``
Anton Komlevb8e3af02020-08-28 10:23:57 +0100100
101``Release`` is default.
102
Sebastian Bøeb73f1762021-10-28 14:23:13 +0200103Debug symbols are added by default to all builds, but can be removed
104from ``Release`` and ``MinSizeRel`` builds by setting
105``TFM_DEBUG_SYMBOLS`` to ``OFF``.
106
107``RelWithDebInfo``, ``Release`` and ``MinSizeRel`` all have different
108optimizations turned on and hence will produce smaller, faster code
109than ``Debug``. ``MinSizeRel`` will produce the smallest code, and
110hence is often a good idea on RAM or flash constrained systems.
Anton Komlevb8e3af02020-08-28 10:23:57 +0100111
112Other cmake parameters
113----------------------
114
115The full list of default options is in ``config/config_default.cmake``. Several
116important options are listed below.
117
118
119+---------------------+----------------------------------------+---------------+
120| Parameter | Description | Default value |
121+=====================+========================================+===============+
122| BL2 | Build level 2 secure bootloader. | ON |
123+---------------------+----------------------------------------+---------------+
124| NS | Build NS app. Required for test code. | ON |
125+---------------------+----------------------------------------+---------------+
Kevin Peng23a583c2021-09-08 22:33:33 +0800126| TFM_LIB_MODEL | Use secure library model instead of | OFF |
127| | PSA api (IPC model). | |
Anton Komlevb8e3af02020-08-28 10:23:57 +0100128+---------------------+----------------------------------------+---------------+
129| TFM_ISOLATION_LEVEL | Set TFM isolation level. | 1 |
130+---------------------+----------------------------------------+---------------+
131| TFM_PROFILE | Set TFM profile. | |
132+---------------------+----------------------------------------+---------------+
133| TEST_S | Build secure regression tests. | OFF |
134+---------------------+----------------------------------------+---------------+
135| TEST_NS | Build non-secure regression tests. | OFF |
136+---------------------+----------------------------------------+---------------+
137| TEST_PSA_API | Build PSA API TESTS for the given | |
138| | suite. Takes a PSA api ``SUITE`` as an | |
139| | argument (``CRYPTO`` etc). | |
140+---------------------+----------------------------------------+---------------+
141
142Regression test configuration
143-----------------------------
144
shejia01bfd37122021-06-03 13:31:51 +0800145Regression test configuration is controlled entirely by ``TEST_NS`` or
146``TEST_S`` or single test suite configuration. The group test
147configurations and single test suite configurations are listed below, all of
148them are disabled by default.
149
150+---------------------+--------------------------------------------------------------------+
151| Parameter | Description |
152+=====================+====================================================================+
153| TEST_NS_ATTESTATION | Build non-secure regression Attestation tests. |
154+---------------------+--------------------------------------------------------------------+
155| TEST_NS_T_COSE | Build non-secure regression t_cose tests. |
156+---------------------+--------------------------------------------------------------------+
157| TEST_NS_QCBOR | Build non-secure regression QCBOR tests. |
158+---------------------+--------------------------------------------------------------------+
159| TEST_NS_AUDIT | Build non-secure regression Audit log tests. |
160+---------------------+--------------------------------------------------------------------+
161| TEST_NS_CORE | Build non-secure regression Core tests. |
162+---------------------+--------------------------------------------------------------------+
163| TEST_NS_CRYPTO | Build non-secure regression Crypto tests. |
164+---------------------+--------------------------------------------------------------------+
165| TEST_NS_ITS | Build non-secure regression ITS tests. |
166+---------------------+--------------------------------------------------------------------+
167| TEST_NS_PS | Build non-secure regression PS tests. |
168+---------------------+--------------------------------------------------------------------+
169| TEST_NS_PLATFORM | Build non-secure regression Platform tests. |
170+---------------------+--------------------------------------------------------------------+
171| TEST_NS_FWU | Build non-secure regression FWU tests. |
172+---------------------+--------------------------------------------------------------------+
173| TEST_NS_IPC | Build non-secure regression IPC tests. |
174+---------------------+--------------------------------------------------------------------+
175| TEST_NS_SLIH_IRQ | Build non-secure regression Second-Level Interrupt Handling tests. |
176+---------------------+--------------------------------------------------------------------+
177| TEST_NS_FLIH_IRQ | Build non-secure regression First-Level Interrupt Handling tests. |
178+---------------------+--------------------------------------------------------------------+
179| TEST_NS_MULTI_CORE | Build non-secure regression multi-core tests. |
180+---------------------+--------------------------------------------------------------------+
181| TEST_S_ATTESTATION | Build secure regression Attestation tests. |
182+---------------------+--------------------------------------------------------------------+
183| TEST_S_AUDIT | Build secure regression Audit log tests. |
184+---------------------+--------------------------------------------------------------------+
185| TEST_S_CRYPTO | Build secure regression Crypto tests. |
186+---------------------+--------------------------------------------------------------------+
187| TEST_S_ITS | Build secure regression ITS tests. |
188+---------------------+--------------------------------------------------------------------+
189| TEST_S_PS | Build secure regression PS tests. |
190+---------------------+--------------------------------------------------------------------+
191| TEST_S_PLATFORM | Build secure regression Platform tests. |
192+---------------------+--------------------------------------------------------------------+
193| TEST_S_FWU | Build secure regression FWU tests. |
194+---------------------+--------------------------------------------------------------------+
195| TEST_S_IPC | Build secure regression IPC tests. |
196+---------------------+--------------------------------------------------------------------+
197
198The single test suite can be opened when their dependencies like partitions or
199other specific configurations are set. On the one hand, some test suites depend
200on other test suites. On the other hand, some test suites have confict with
201other test suites. Test configurations and dependencies will be
202checked in ``${TFM_TEST_REPO_PATH}/test/config/check_config.cmake``.
Anton Komlevb8e3af02020-08-28 10:23:57 +0100203
204If regression testing is enabled, it will then enable all tests for the enabled
Kevin Peng23a583c2021-09-08 22:33:33 +0800205secure partitions.
206Multicore tests will be enabled if ``TFM_MULTI_CORE_TOPOLOGY`` is enabled.
Anton Komlevb8e3af02020-08-28 10:23:57 +0100207
208Some cryptographic tests can be enabled and disabled. This is done to prevent
209false failures from being reported when a smaller Mbed Crypto config is being
210used which does not support all features.
211
212+-----------------------------+-------------------------------------+---------------+
213| Parameter | Description | Default value |
214+=============================+=====================================+===============+
215| TFM_CRYPTO_TEST_ALG_CBC | Test CBC cryptography mode | ON |
216+-----------------------------+-------------------------------------+---------------+
217| TFM_CRYPTO_TEST_ALG_CCM | Test CCM cryptography mode | ON |
218+-----------------------------+-------------------------------------+---------------+
219| TFM_CRYPTO_TEST_ALG_CFB | Test CFB cryptography mode | ON |
220+-----------------------------+-------------------------------------+---------------+
Abbas Bracken Ziad46a21b62021-08-31 13:03:56 +0100221| TFM_CRYPTO_TEST_ALG_ECB | Test ECB cryptography mode | ON |
222+-----------------------------+-------------------------------------+---------------+
Anton Komlevb8e3af02020-08-28 10:23:57 +0100223| TFM_CRYPTO_TEST_ALG_CTR | Test CTR cryptography mode | ON |
224+-----------------------------+-------------------------------------+---------------+
Abbas Bracken Ziad3d262f42021-08-19 15:07:05 +0100225| TFM_CRYPTO_TEST_ALG_OFB | Test OFB cryptography mode | ON |
226+-----------------------------+-------------------------------------+---------------+
Anton Komlevb8e3af02020-08-28 10:23:57 +0100227| TFM_CRYPTO_TEST_ALG_GCM | Test GCM cryptography mode | ON |
228+-----------------------------+-------------------------------------+---------------+
229| TFM_CRYPTO_TEST_ALG_SHA_512 | Test SHA-512 cryptography algorithm | ON |
230+-----------------------------+-------------------------------------+---------------+
Antonio de Angelis6eb5ecb2021-07-29 11:33:48 +0200231| TFM_CRYPTO_TEST_HKDF | Test HKDF key derivation algorithm | ON |
232+-----------------------------+-------------------------------------+---------------+
233| TFM_CRYPTO_TEST_ECDH | Test ECDH key agreement algorithm | ON |
Anton Komlevb8e3af02020-08-28 10:23:57 +0100234+-----------------------------+-------------------------------------+---------------+
235
Anton Komlev211aacf2020-11-02 12:48:11 +0000236TF-M Profiles
237-------------
238
239TF-M Profiles are implemented as a single cmake configuration file, under the
240``config/profile`` directory. A good understanding can be gained quickly by
241looking at the Profile configuration files, but the ultimate reference for
Summer Qinabf66982021-04-06 17:22:15 +0800242Profiles are the design documents in the ``docs/technical_references/profiles/``
Anton Komlev211aacf2020-11-02 12:48:11 +0000243directory.
Anton Komlevb8e3af02020-08-28 10:23:57 +0100244
245PSA test configuration
246----------------------
247
248PSA tests are configured by using the ``TEST_PSA_API`` cmake variable. The
249variable should be set to the name of the test suite that is desired. It is
250_not_ supported to set both ``TEST_PSA_API`` and ``TEST_S`` or ``TEST_NS``.
251
Jamie Fox19c91c22019-02-10 18:04:58 +0000252The Functional API tests are:
Anton Komlevb8e3af02020-08-28 10:23:57 +0100253 - ``CRYPTO``
254 - ``INITIAL_ATTESTATION``
255 - ``STORAGE`` (INTERNAL_TRUSTED_STORAGE and PROTECTED_STORAGE)
256 - ``INTERNAL_TRUSTED_STORAGE``
257 - ``PROTECTED_STORAGE``
258
Jamie Fox19c91c22019-02-10 18:04:58 +0000259The Firmware Framework test suites are:
Anton Komlevb8e3af02020-08-28 10:23:57 +0100260 - ``IPC``
261
262Note that these map directly to the ``SUITE`` cmake variable used in the
263psa-arch-tests documentation.
264
David Wangd6fd6af2021-06-21 17:17:26 +0800265.. _Migration from legacy buildsystem:
266
Anton Komlevb8e3af02020-08-28 10:23:57 +0100267Migration from legacy buildsystem
268---------------------------------
269
270The previous (legacy) cmake buildsystem made use of separate configuration
271files, where now build options are controlled by variables. For ease of
272transition, a table below is provided that maps the legacy files to the current
273variables, in the format of cmake command line parameters.
274
Summer Qin001ce9d2020-11-04 14:41:54 +0800275+------------------------------------------+---------------------------------------+
276| File | Cmake command line |
277+==========================================+=======================================+
Kevin Peng23a583c2021-09-08 22:33:33 +0800278| ConfigDefault.cmake | -DTFM_LIB_MODEL=ON |
Summer Qin001ce9d2020-11-04 14:41:54 +0800279+------------------------------------------+---------------------------------------+
Kevin Peng23a583c2021-09-08 22:33:33 +0800280| ConfigCoreIPC.cmake | <no options> |
Summer Qin001ce9d2020-11-04 14:41:54 +0800281+------------------------------------------+---------------------------------------+
Kevin Peng23a583c2021-09-08 22:33:33 +0800282| ConfigCoreIPCTfmLevel2.cmake | -DTFM_ISOLATION_LEVEL=2 |
Summer Qin001ce9d2020-11-04 14:41:54 +0800283+------------------------------------------+---------------------------------------+
284| ConfigDefaultProfileS.cmake | -DTFM_PROFILE=profile_small |
285+------------------------------------------+---------------------------------------+
286| ConfigDefaultProfileM.cmake | -DTFM_PROFILE=profile_medium |
287+------------------------------------------+---------------------------------------+
288| ConfigRegression.cmake | -DTEST_NS=ON -DTEST_S=ON |
289+------------------------------------------+---------------------------------------+
290| ConfigRegressionIPC.cmake | -DTEST_NS=ON -DTEST_S=ON |
Summer Qin001ce9d2020-11-04 14:41:54 +0800291+------------------------------------------+---------------------------------------+
292| ConfigRegressionIPCTfmLevel2.cmake | -DTEST_NS=ON -DTEST_S=ON |
Summer Qin001ce9d2020-11-04 14:41:54 +0800293| | -DTFM_ISOLATION_LEVEL=2 |
294+------------------------------------------+---------------------------------------+
295| ConfigRegressionProfileS.cmake | -DTFM_PROFILE=profile_small |
296| | -DTEST_NS=ON -DTEST_S=ON |
297+------------------------------------------+---------------------------------------+
298| ConfigRegressionProfileM.cmake | -DTFM_PROFILE=profile_medium |
299| | -DTEST_NS=ON -DTEST_S=ON |
300+------------------------------------------+---------------------------------------+
301| ConfigPsaApiTest.cmake | -DTEST_PSA_API=<test_suite> |
302+------------------------------------------+---------------------------------------+
303| ConfigPsaApiTestIPC.cmake | -DTEST_PSA_API=<test_suite> |
Summer Qin001ce9d2020-11-04 14:41:54 +0800304+------------------------------------------+---------------------------------------+
305| ConfigPsaApiTestIPCTfmLevel2.cmake | -DTEST_PSA_API=<test_suite> |
Summer Qin001ce9d2020-11-04 14:41:54 +0800306| | -DTFM_ISOLATION_LEVEL=2 |
307+------------------------------------------+---------------------------------------+
308| ConfigDefaultProfileM.cmake | -DTFM_PROFILE=profile_medium |
309| + profile_m_config_ext_ps_disabled.cmake | -DTFM_PARTITION_PROTECTED_STORAGE=OFF |
310+------------------------------------------+---------------------------------------+
Anton Komlevb8e3af02020-08-28 10:23:57 +0100311
312There has also been some changes to the PSA manifest file generation. The files
313are now generated into a seperate tree in the ``<tfm build dir>/generated``
314directory. Therefore they have been removed from the source tree. Any changes
315should be made only to the template files.
316
317The api for the ``tools/tfm_parse_manifest_list.py`` script has also changed
318slightly. It is no longer required to be run manually as it is run as part of
319cmake.
320
321*******************
322TF-M build examples
323*******************
324
Subhasish Ghoshbc849302021-04-08 20:21:20 +0100325.. Note::
326 By default, CMAKE_BUILD_TYPE is set to Release, for debug support change
327 this to Debug. See below for an example.
328
Anton Komlevb8e3af02020-08-28 10:23:57 +0100329Example: building TF-M for AN521 platform using GCC:
330====================================================
331.. code-block:: bash
332
Leonardo Sandoval98350142021-02-03 16:32:14 -0600333 cd <TF-M base folder>
Summer Qin2de23d02021-05-14 13:44:14 +0800334 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 +0100335 cmake --build cmake_build -- install
336
337Alternately using traditional cmake syntax
338
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200339.. code-block:: bash
340
Leonardo Sandoval98350142021-02-03 16:32:14 -0600341 cd <TF-M base folder>
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200342 mkdir cmake_build
343 cd cmake_build
Summer Qin2de23d02021-05-14 13:44:14 +0800344 cmake .. -DTFM_PLATFORM=arm/mps2/an521 -DTFM_TOOLCHAIN_FILE=../toolchain_GNUARM.cmake
Anton Komlevb8e3af02020-08-28 10:23:57 +0100345 make install
346
347.. Note::
348 Unix Makefiles is the default generator. Ninja is also supported by setting
349 -GNinja
350
351.. Note::
352
353 It is recommended to build each different build configuration in a separate
354 build directory.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200355
Leonardo Sandoval49a558c2021-02-03 17:04:22 -0600356As seen above, the toolchain can be set using the -DTFM_TOOLCHAIN_FILE parameter. Without
357it, the build command takes the GNU ARM toolchain as default, so there is no need
358to explicitly include it. In case other toolchain is required, i.e. ARM Clang, simply
359specify in the command line
360
361.. code-block:: bash
Subhasish Ghoshbc849302021-04-08 20:21:20 +0100362
Leonardo Sandoval49a558c2021-02-03 17:04:22 -0600363 cd <TF-M base folder>
Summer Qin2de23d02021-05-14 13:44:14 +0800364 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 -0600365 cmake --build cmake_build -- install
366
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200367Regression Tests for the AN521 target platform
368==============================================
Anton Komlevb8e3af02020-08-28 10:23:57 +0100369
370Regression tests can be build by using the TEST_S and TEST_NS settings. Either
371can be used in isolation or both can be used to enable both suites. All tests
372for all enabled partitions are run, along with IPC and Multicore tests if those
373features are enabled.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200374
375.. code-block:: bash
376
Leonardo Sandoval98350142021-02-03 16:32:14 -0600377 cd <TF-M base folder>
Summer Qin2de23d02021-05-14 13:44:14 +0800378 cmake -S . -B cmake_build -DTFM_PLATFORM=arm/mps2/an521 -DTEST_S=ON -DTEST_NS=ON
Anton Komlevb8e3af02020-08-28 10:23:57 +0100379 cmake --build cmake_build -- install
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200380
Anton Komlevb8e3af02020-08-28 10:23:57 +0100381Alternately using traditional cmake syntax
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200382
383.. code-block:: bash
384
Leonardo Sandoval98350142021-02-03 16:32:14 -0600385 cd <TF-M base folder>
Anton Komlevb8e3af02020-08-28 10:23:57 +0100386 mkdir cmake_build
387 cd cmake_build
Summer Qin2de23d02021-05-14 13:44:14 +0800388 cmake .. -DTFM_PLATFORM=arm/mps2/an521 -DTEST_S=ON -DTEST_NS=ON
Anton Komlevb8e3af02020-08-28 10:23:57 +0100389 make install
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200390
Kevin Peng23a583c2021-09-08 22:33:33 +0800391Build for PSA API tests
392=======================
Anton Komlevb8e3af02020-08-28 10:23:57 +0100393The build system provides support for building and integrating the PSA API tests
394from https://github.com/ARM-software/psa-arch-tests. PSA API tests are
395controlled using the TEST_PSA_API variable. Enabling both regression tests and
396PSA API tests simultaneously is **not** supported.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200397
Anton Komlevb8e3af02020-08-28 10:23:57 +0100398The value of the TEST_PSA_API variable is the suite to be run.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200399
Subhasish Ghoshbc849302021-04-08 20:21:20 +0100400.. code-block:: bash
Anton Komlevb8e3af02020-08-28 10:23:57 +0100401
402 -DTEST_PSA_API=INTERNAL_TRUSTED_STORAGE
403 -DTEST_PSA_API=PROTECTED_STORAGE
404 -DTEST_PSA_API=STORAGE
405 -DTEST_PSA_API=CRYPTO
406 -DTEST_PSA_API=INITIAL_ATTESTATION
407
408Respectively for the corresponding service. For example, to enable the PSA API
409tests for the Crypto service:
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200410
411.. code-block:: bash
412
Leonardo Sandoval98350142021-02-03 16:32:14 -0600413 cd <TF-M base folder>
Summer Qin2de23d02021-05-14 13:44:14 +0800414 cmake -S . -B cmake_build -DTFM_PLATFORM=arm/mps2/an521 -DTEST_PSA_API=CRYPTO
Anton Komlevb8e3af02020-08-28 10:23:57 +0100415 cmake --build cmake_build -- install
416
417Alternately using traditional cmake syntax
418
419.. code-block:: bash
420
Leonardo Sandoval98350142021-02-03 16:32:14 -0600421 cd <TF-M base folder>
Anton Komlevb8e3af02020-08-28 10:23:57 +0100422 mkdir cmake_build
423 cd cmake_build
Summer Qin2de23d02021-05-14 13:44:14 +0800424 cmake .. -DTFM_PLATFORM=arm/mps2/an521 -DTEST_PSA_API=CRYPTO
Anton Komlevb8e3af02020-08-28 10:23:57 +0100425 make install
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200426
427Location of build artifacts
428===========================
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200429
Anton Komlevb8e3af02020-08-28 10:23:57 +0100430All build artifacts are provided in the ``<build_dir>/bin`` directory. It is
431**not** required to run ``make install`` to generate artifacts in this location.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200432
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200433
Anton Komlevb8e3af02020-08-28 10:23:57 +0100434For the purposes of maintaining compatibility with the legacy cmake build
435system, they are also provided in
436``<build_dir>/install/outputs/<target_platform>/``. In order to generate the
437artifacts in this location ``make install`` must be run.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200438
Anton Komlevb8e3af02020-08-28 10:23:57 +0100439****************************
440Manual dependency management
441****************************
Galanakis, Minos757139a2019-11-11 15:00:11 +0000442
Raef Coles1ecb8132020-10-02 15:11:24 +0100443The TF-M build system will by default fetch all dependencies with appropriate
444versions and store them inside the build tree. In this case, the build tree
445location is ``<build_dir>/lib/ext``, and the extra libraries can be cleaned by
446deleting that directory.
Galanakis, Minos757139a2019-11-11 15:00:11 +0000447
Raef Coles1ecb8132020-10-02 15:11:24 +0100448If you have local copies already, and wish to avoid having the libraries
449downloaded every time the build directory is deleted, then the following
Raef Colesc630b882020-12-10 15:46:18 +0000450variables can be set to the path to the root directory of the local repo. This
451will disable the automatic downloading for that dependency.
Raef Coles1ecb8132020-10-02 15:11:24 +0100452
Raef Colesc630b882020-12-10 15:46:18 +0000453+----------------+---------------------+-----------------------------------------------------+
454| Dependency | Cmake variable | Git repo URL |
455+================+=====================+=====================================================+
456| Mbed Crypto | MBEDCRYPTO_PATH | https://github.com/ARMmbed/mbedtls |
457+----------------+---------------------+-----------------------------------------------------+
458| tf-m-tests | TFM_TEST_REPO_PATH | https://git.trustedfirmware.org/TF-M/tf-m-tests.git |
459+----------------+---------------------+-----------------------------------------------------+
460| MCUboot | MCUBOOT_PATH | https://github.com/mcu-tools/mcuboot |
461+----------------+---------------------+-----------------------------------------------------+
462| psa-arch-tests | PSA_ARCH_TESTS_PATH | https://github.com/ARM-software/psa-arch-tests |
463+----------------+---------------------+-----------------------------------------------------+
Galanakis, Minos757139a2019-11-11 15:00:11 +0000464
Anton Komlevb8e3af02020-08-28 10:23:57 +0100465For required versions of the dependencies, refer to ``config/config_default.cmake``.
Galanakis, Minos757139a2019-11-11 15:00:11 +0000466
467.. Note::
Anton Komlevb8e3af02020-08-28 10:23:57 +0100468 - Some patches are required to the mbedtls repo to allow building it as part of
469 TF-M. While these patches are being upstreamed they are stored in
Raef Coles1ecb8132020-10-02 15:11:24 +0100470 ``lib/ext/mbedcrypo``. In order to use a local copy of Mbed Crypto it is
471 required to apply all patch files in this directory.
Galanakis, Minos757139a2019-11-11 15:00:11 +0000472
Anton Komlevb8e3af02020-08-28 10:23:57 +0100473.. Note::
474 - CMSIS 5 is provided by the TF-M tests repo. If you wish to use a different
475 source for CMSIS 5, it can be configured using CMSIS_5_PATH.
David Hu2cbf5df2020-06-15 10:41:44 +0800476
Kevin Pengcba37d32020-12-07 17:07:39 +0800477TF-M Tests
478==========
479
480Dependency auto downloading is used by default.
481The TF-M build system downloads the tf-m-tests repo with a fixed version
David Huf89bcb62021-09-06 15:02:34 +0800482specified by ``TFM_TEST_REPO_VERSION`` in
483:file:`lib/ext/tf-m-tests/repo_config_default.cmake`.
Kevin Pengcba37d32020-12-07 17:07:39 +0800484The version can be a release tag or a commit hash.
485
486Developers who want a different version of tf-m-tests can override
487``TFM_TEST_REPO_PATH`` to a local copy with the desired version.
488
David Huf89bcb62021-09-06 15:02:34 +0800489As the test repo is part of the TF-M project and coupled with TF-M repo,
490the version should be updated when there are dependency changes between the TF-M
Kevin Pengcba37d32020-12-07 17:07:39 +0800491repo and the test repo and when there is a complete change merged in test repo.
492
493A complete change is one or more patches that are for the same purpose, for
494example a new test suite or enhancements on the test cases.
495Patches in one change can be merge individually provided they do not break
496anything or cause any regressions.
497But the version in the TF-M gets updated only when all the patches are merged.
498
Raef Coles1ecb8132020-10-02 15:11:24 +0100499Example: building TF-M for AN521 platform with local Mbed Crypto
500================================================================
501
502Prepare Mbed Crypto repository
503------------------------------
504
505This is only required to be done once. For dependencies that do not have any
506``.patch`` files in their ``lib/ext`` directory the only required step is
507cloning the repo and checking out the correct branch.
508
509.. code-block:: bash
510
511 cd <Mbed Crypto base folder>
512 git clone https://github.com/ARMmbed/mbedtls
513 cd mbedtls
514 git checkout <MBEDCRYPTO_VERSION from config_default.cmake>
515 git apply <TF-M base folder>/trusted-firmware-m/lib/ext/mbedcrypo/*.patch
516
517.. Note::
518 - <Mbed Crypto base folder> does not need to have any fixed posisition related
519 to the TF-M repo.
520
521Build TF-M
522----------
523
524With new cmake syntax
525
526.. code-block:: bash
527
Leonardo Sandoval98350142021-02-03 16:32:14 -0600528 cd <TF-M base folder>
Summer Qin2de23d02021-05-14 13:44:14 +0800529 cmake -S . -B cmake_build -DTFM_PLATFORM=arm/mps2/an521 -DMBEDCRYPTO_PATH=<Mbed Crypto base folder>/mbedtls
Raef Coles1ecb8132020-10-02 15:11:24 +0100530 cmake --build cmake_build -- install
531
532Alternately using traditional cmake syntax
533
534.. code-block:: bash
535
Leonardo Sandoval98350142021-02-03 16:32:14 -0600536 cd <TF-M base folder>
Raef Coles1ecb8132020-10-02 15:11:24 +0100537 mkdir cmake_build
538 cd cmake_build
Summer Qin2de23d02021-05-14 13:44:14 +0800539 cmake .. -DTFM_PLATFORM=arm/mps2/an521 -DMBEDCRYPTO_PATH=<Mbed Crypto base folder>/mbedtls
Raef Coles1ecb8132020-10-02 15:11:24 +0100540 make install
541
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200542--------------
543
Summer Qinabf66982021-04-06 17:22:15 +0800544*Copyright (c) 2017-2021, Arm Limited. All rights reserved.*