blob: 80c695554a36008559ee33c9268de172e736d1d3 [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.
Anton Komlevb8e3af02020-08-28 10:23:57 +010063
64.. Warning::
65 This means that command-line settings are not applied when they conflict
66 with required platform settings. If it is required to override platform
67 settings (this is not usually a good idea) then TFM_EXTRA_CONFIG_PATH should be
68 used.
69
70Required cmake parameters for building TF-M
71-------------------------------------------
72
73+----------------------+-------------------------------------------------------+
74| Parameter | Description |
75+======================+=======================================================+
76| TFM_PLATFORM | The target platform as a path from the base directory |
Øyvind Rønningstada9d5eac2021-01-22 14:21:25 +010077| | ``/platform/ext/target``, or as an absolute path. |
Anton Komlevb8e3af02020-08-28 10:23:57 +010078+----------------------+-------------------------------------------------------+
Anton Komlevb8e3af02020-08-28 10:23:57 +010079
80By default release configuration builds. Alternate build types can be controlled
81by the CMAKE_BUILD_TYPE variable.
82
83Build type
84----------
85
86Build type is controlled by the ``CMAKE_BUILD_TYPE`` variable. The possible
87types are:
88
89 - ``Debug``
90 - ``Relwithdebinfo``
91 - ``Release``
92 - ``Minsizerel``
93
94``Release`` is default.
95
96Both ``Debug`` and ``Relwithdebinfo`` will include debug symbols in the output
97files. ``Relwithdebinfo``, ``Release`` and ``Minsizerel`` have optimization
Raef Coles1ecb8132020-10-02 15:11:24 +010098turned on and hence will produce smaller, faster code. ``Minsizerel`` will
Anton Komlevb8e3af02020-08-28 10:23:57 +010099produce the smallest code, and hence is often a good idea on RAM or flash
100constrained systems.
101
102Other cmake parameters
103----------------------
104
105The full list of default options is in ``config/config_default.cmake``. Several
106important options are listed below.
107
108
109+---------------------+----------------------------------------+---------------+
110| Parameter | Description | Default value |
111+=====================+========================================+===============+
112| BL2 | Build level 2 secure bootloader. | ON |
113+---------------------+----------------------------------------+---------------+
114| NS | Build NS app. Required for test code. | ON |
115+---------------------+----------------------------------------+---------------+
116| TFM_PSA_API | Use PSA api (IPC mode) instead of | OFF |
117| | secure library mode. | |
118+---------------------+----------------------------------------+---------------+
119| TFM_ISOLATION_LEVEL | Set TFM isolation level. | 1 |
120+---------------------+----------------------------------------+---------------+
121| TFM_PROFILE | Set TFM profile. | |
122+---------------------+----------------------------------------+---------------+
123| TEST_S | Build secure regression tests. | OFF |
124+---------------------+----------------------------------------+---------------+
125| TEST_NS | Build non-secure regression tests. | OFF |
126+---------------------+----------------------------------------+---------------+
127| TEST_PSA_API | Build PSA API TESTS for the given | |
128| | suite. Takes a PSA api ``SUITE`` as an | |
129| | argument (``CRYPTO`` etc). | |
130+---------------------+----------------------------------------+---------------+
131
132Regression test configuration
133-----------------------------
134
135Regression test configuration is controlled entirely by the ``TEST_S`` and
136``TEST_NS`` cmake variables.
137
138If regression testing is enabled, it will then enable all tests for the enabled
139secure partitions. If IPC mode is enabled via ``TFM_PSA_API`` the IPC tests will
140be enabled. QCBOR and T_COSE tests are linked to the Initial Attestation
141partition, as they are only used there. Multicore tests will be enabled if
142``TFM_MULTI_CORE_TOPOLOGY`` is enabled.
143
144Some cryptographic tests can be enabled and disabled. This is done to prevent
145false failures from being reported when a smaller Mbed Crypto config is being
146used which does not support all features.
147
148+-----------------------------+-------------------------------------+---------------+
149| Parameter | Description | Default value |
150+=============================+=====================================+===============+
151| TFM_CRYPTO_TEST_ALG_CBC | Test CBC cryptography mode | ON |
152+-----------------------------+-------------------------------------+---------------+
153| TFM_CRYPTO_TEST_ALG_CCM | Test CCM cryptography mode | ON |
154+-----------------------------+-------------------------------------+---------------+
155| TFM_CRYPTO_TEST_ALG_CFB | Test CFB cryptography mode | ON |
156+-----------------------------+-------------------------------------+---------------+
157| TFM_CRYPTO_TEST_ALG_CTR | Test CTR cryptography mode | ON |
158+-----------------------------+-------------------------------------+---------------+
159| TFM_CRYPTO_TEST_ALG_GCM | Test GCM cryptography mode | ON |
160+-----------------------------+-------------------------------------+---------------+
161| TFM_CRYPTO_TEST_ALG_SHA_512 | Test SHA-512 cryptography algorithm | ON |
162+-----------------------------+-------------------------------------+---------------+
Antonio de Angelis6eb5ecb2021-07-29 11:33:48 +0200163| TFM_CRYPTO_TEST_HKDF | Test HKDF key derivation algorithm | ON |
164+-----------------------------+-------------------------------------+---------------+
165| TFM_CRYPTO_TEST_ECDH | Test ECDH key agreement algorithm | ON |
Anton Komlevb8e3af02020-08-28 10:23:57 +0100166+-----------------------------+-------------------------------------+---------------+
167
Anton Komlev211aacf2020-11-02 12:48:11 +0000168TF-M Profiles
169-------------
170
171TF-M Profiles are implemented as a single cmake configuration file, under the
172``config/profile`` directory. A good understanding can be gained quickly by
173looking at the Profile configuration files, but the ultimate reference for
Summer Qinabf66982021-04-06 17:22:15 +0800174Profiles are the design documents in the ``docs/technical_references/profiles/``
Anton Komlev211aacf2020-11-02 12:48:11 +0000175directory.
Anton Komlevb8e3af02020-08-28 10:23:57 +0100176
177PSA test configuration
178----------------------
179
180PSA tests are configured by using the ``TEST_PSA_API`` cmake variable. The
181variable should be set to the name of the test suite that is desired. It is
182_not_ supported to set both ``TEST_PSA_API`` and ``TEST_S`` or ``TEST_NS``.
183
Jamie Fox19c91c22019-02-10 18:04:58 +0000184The Functional API tests are:
Anton Komlevb8e3af02020-08-28 10:23:57 +0100185 - ``CRYPTO``
186 - ``INITIAL_ATTESTATION``
187 - ``STORAGE`` (INTERNAL_TRUSTED_STORAGE and PROTECTED_STORAGE)
188 - ``INTERNAL_TRUSTED_STORAGE``
189 - ``PROTECTED_STORAGE``
190
Jamie Fox19c91c22019-02-10 18:04:58 +0000191The Firmware Framework test suites are:
Anton Komlevb8e3af02020-08-28 10:23:57 +0100192 - ``IPC``
193
194Note that these map directly to the ``SUITE`` cmake variable used in the
195psa-arch-tests documentation.
196
David Wangd6fd6af2021-06-21 17:17:26 +0800197.. _Migration from legacy buildsystem:
198
Anton Komlevb8e3af02020-08-28 10:23:57 +0100199Migration from legacy buildsystem
200---------------------------------
201
202The previous (legacy) cmake buildsystem made use of separate configuration
203files, where now build options are controlled by variables. For ease of
204transition, a table below is provided that maps the legacy files to the current
205variables, in the format of cmake command line parameters.
206
Summer Qin001ce9d2020-11-04 14:41:54 +0800207+------------------------------------------+---------------------------------------+
208| File | Cmake command line |
209+==========================================+=======================================+
210| ConfigDefault.cmake | <No options> |
211+------------------------------------------+---------------------------------------+
212| ConfigCoreIPC.cmake | -DTFM_PSA_API=ON |
213+------------------------------------------+---------------------------------------+
214| ConfigCoreIPCTfmLevel2.cmake | -DTFM_PSA_API=ON |
215| | -DTFM_ISOLATION_LEVEL=2 |
216+------------------------------------------+---------------------------------------+
217| ConfigDefaultProfileS.cmake | -DTFM_PROFILE=profile_small |
218+------------------------------------------+---------------------------------------+
219| ConfigDefaultProfileM.cmake | -DTFM_PROFILE=profile_medium |
220+------------------------------------------+---------------------------------------+
221| ConfigRegression.cmake | -DTEST_NS=ON -DTEST_S=ON |
222+------------------------------------------+---------------------------------------+
223| ConfigRegressionIPC.cmake | -DTEST_NS=ON -DTEST_S=ON |
224| | -DTFM_PSA_API=ON |
225+------------------------------------------+---------------------------------------+
226| ConfigRegressionIPCTfmLevel2.cmake | -DTEST_NS=ON -DTEST_S=ON |
227| | -DTFM_PSA_API=ON |
228| | -DTFM_ISOLATION_LEVEL=2 |
229+------------------------------------------+---------------------------------------+
230| ConfigRegressionProfileS.cmake | -DTFM_PROFILE=profile_small |
231| | -DTEST_NS=ON -DTEST_S=ON |
232+------------------------------------------+---------------------------------------+
233| ConfigRegressionProfileM.cmake | -DTFM_PROFILE=profile_medium |
234| | -DTEST_NS=ON -DTEST_S=ON |
235+------------------------------------------+---------------------------------------+
236| ConfigPsaApiTest.cmake | -DTEST_PSA_API=<test_suite> |
237+------------------------------------------+---------------------------------------+
238| ConfigPsaApiTestIPC.cmake | -DTEST_PSA_API=<test_suite> |
239| | -DTFM_PSA_API=ON |
240+------------------------------------------+---------------------------------------+
241| ConfigPsaApiTestIPCTfmLevel2.cmake | -DTEST_PSA_API=<test_suite> |
242| | -DTFM_PSA_API=ON |
243| | -DTFM_ISOLATION_LEVEL=2 |
244+------------------------------------------+---------------------------------------+
245| ConfigDefaultProfileM.cmake | -DTFM_PROFILE=profile_medium |
246| + profile_m_config_ext_ps_disabled.cmake | -DTFM_PARTITION_PROTECTED_STORAGE=OFF |
247+------------------------------------------+---------------------------------------+
Anton Komlevb8e3af02020-08-28 10:23:57 +0100248
249There has also been some changes to the PSA manifest file generation. The files
250are now generated into a seperate tree in the ``<tfm build dir>/generated``
251directory. Therefore they have been removed from the source tree. Any changes
252should be made only to the template files.
253
254The api for the ``tools/tfm_parse_manifest_list.py`` script has also changed
255slightly. It is no longer required to be run manually as it is run as part of
256cmake.
257
258*******************
259TF-M build examples
260*******************
261
Subhasish Ghoshbc849302021-04-08 20:21:20 +0100262.. Note::
263 By default, CMAKE_BUILD_TYPE is set to Release, for debug support change
264 this to Debug. See below for an example.
265
Anton Komlevb8e3af02020-08-28 10:23:57 +0100266Example: building TF-M for AN521 platform using GCC:
267====================================================
268.. code-block:: bash
269
Leonardo Sandoval98350142021-02-03 16:32:14 -0600270 cd <TF-M base folder>
Summer Qin2de23d02021-05-14 13:44:14 +0800271 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 +0100272 cmake --build cmake_build -- install
273
274Alternately using traditional cmake syntax
275
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200276.. code-block:: bash
277
Leonardo Sandoval98350142021-02-03 16:32:14 -0600278 cd <TF-M base folder>
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200279 mkdir cmake_build
280 cd cmake_build
Summer Qin2de23d02021-05-14 13:44:14 +0800281 cmake .. -DTFM_PLATFORM=arm/mps2/an521 -DTFM_TOOLCHAIN_FILE=../toolchain_GNUARM.cmake
Anton Komlevb8e3af02020-08-28 10:23:57 +0100282 make install
283
284.. Note::
285 Unix Makefiles is the default generator. Ninja is also supported by setting
286 -GNinja
287
288.. Note::
289
290 It is recommended to build each different build configuration in a separate
291 build directory.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200292
Leonardo Sandoval49a558c2021-02-03 17:04:22 -0600293As seen above, the toolchain can be set using the -DTFM_TOOLCHAIN_FILE parameter. Without
294it, the build command takes the GNU ARM toolchain as default, so there is no need
295to explicitly include it. In case other toolchain is required, i.e. ARM Clang, simply
296specify in the command line
297
298.. code-block:: bash
Subhasish Ghoshbc849302021-04-08 20:21:20 +0100299
Leonardo Sandoval49a558c2021-02-03 17:04:22 -0600300 cd <TF-M base folder>
Summer Qin2de23d02021-05-14 13:44:14 +0800301 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 -0600302 cmake --build cmake_build -- install
303
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200304Regression Tests for the AN521 target platform
305==============================================
Anton Komlevb8e3af02020-08-28 10:23:57 +0100306
307Regression tests can be build by using the TEST_S and TEST_NS settings. Either
308can be used in isolation or both can be used to enable both suites. All tests
309for all enabled partitions are run, along with IPC and Multicore tests if those
310features are enabled.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200311
312.. code-block:: bash
313
Leonardo Sandoval98350142021-02-03 16:32:14 -0600314 cd <TF-M base folder>
Summer Qin2de23d02021-05-14 13:44:14 +0800315 cmake -S . -B cmake_build -DTFM_PLATFORM=arm/mps2/an521 -DTEST_S=ON -DTEST_NS=ON
Anton Komlevb8e3af02020-08-28 10:23:57 +0100316 cmake --build cmake_build -- install
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200317
Anton Komlevb8e3af02020-08-28 10:23:57 +0100318Alternately using traditional cmake syntax
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200319
320.. code-block:: bash
321
Leonardo Sandoval98350142021-02-03 16:32:14 -0600322 cd <TF-M base folder>
Anton Komlevb8e3af02020-08-28 10:23:57 +0100323 mkdir cmake_build
324 cd cmake_build
Summer Qin2de23d02021-05-14 13:44:14 +0800325 cmake .. -DTFM_PLATFORM=arm/mps2/an521 -DTEST_S=ON -DTEST_NS=ON
Anton Komlevb8e3af02020-08-28 10:23:57 +0100326 make install
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200327
Jamie Fox19c91c22019-02-10 18:04:58 +0000328Build for PSA Functional API compliance tests
329=============================================
Anton Komlevb8e3af02020-08-28 10:23:57 +0100330The build system provides support for building and integrating the PSA API tests
331from https://github.com/ARM-software/psa-arch-tests. PSA API tests are
332controlled using the TEST_PSA_API variable. Enabling both regression tests and
333PSA API tests simultaneously is **not** supported.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200334
Anton Komlevb8e3af02020-08-28 10:23:57 +0100335The value of the TEST_PSA_API variable is the suite to be run.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200336
Subhasish Ghoshbc849302021-04-08 20:21:20 +0100337.. code-block:: bash
Anton Komlevb8e3af02020-08-28 10:23:57 +0100338
339 -DTEST_PSA_API=INTERNAL_TRUSTED_STORAGE
340 -DTEST_PSA_API=PROTECTED_STORAGE
341 -DTEST_PSA_API=STORAGE
342 -DTEST_PSA_API=CRYPTO
343 -DTEST_PSA_API=INITIAL_ATTESTATION
344
345Respectively for the corresponding service. For example, to enable the PSA API
346tests for the Crypto service:
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200347
348.. code-block:: bash
349
Leonardo Sandoval98350142021-02-03 16:32:14 -0600350 cd <TF-M base folder>
Summer Qin2de23d02021-05-14 13:44:14 +0800351 cmake -S . -B cmake_build -DTFM_PLATFORM=arm/mps2/an521 -DTEST_PSA_API=CRYPTO
Anton Komlevb8e3af02020-08-28 10:23:57 +0100352 cmake --build cmake_build -- install
353
354Alternately using traditional cmake syntax
355
356.. code-block:: bash
357
Leonardo Sandoval98350142021-02-03 16:32:14 -0600358 cd <TF-M base folder>
Anton Komlevb8e3af02020-08-28 10:23:57 +0100359 mkdir cmake_build
360 cd cmake_build
Summer Qin2de23d02021-05-14 13:44:14 +0800361 cmake .. -DTFM_PLATFORM=arm/mps2/an521 -DTEST_PSA_API=CRYPTO
Anton Komlevb8e3af02020-08-28 10:23:57 +0100362 make install
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200363
Jaykumar Pitambarbhai Patel6891b8b2020-01-23 14:32:20 +0530364Build for PSA FF (IPC) compliance tests
365=======================================
366
Anton Komlevb8e3af02020-08-28 10:23:57 +0100367The build system provides support for building and integrating the PSA FF
368compliance test. This support is controlled by the TEST_PSA_API variable:
Jaykumar Pitambarbhai Patel6891b8b2020-01-23 14:32:20 +0530369
Subhasish Ghoshbc849302021-04-08 20:21:20 +0100370.. code-block:: bash
Anton Komlevb8e3af02020-08-28 10:23:57 +0100371
372 -DTEST_PSA_API=IPC
Jaykumar Pitambarbhai Patel6891b8b2020-01-23 14:32:20 +0530373
374.. code-block:: bash
Minos Galanakisfc6804e2020-03-10 11:03:34 +0000375
Leonardo Sandoval98350142021-02-03 16:32:14 -0600376 cd <TF-M base folder>
Summer Qin2de23d02021-05-14 13:44:14 +0800377 cmake -S . -B cmake_build -DTFM_PLATFORM=arm/mps2/an521 -DTEST_PSA_API=IPC -DTFM_PSA_API=ON
Anton Komlevb8e3af02020-08-28 10:23:57 +0100378 cmake --build cmake_build -- install
Jaykumar Pitambarbhai Patel6891b8b2020-01-23 14:32:20 +0530379
Anton Komlevb8e3af02020-08-28 10:23:57 +0100380Alternately using traditional cmake syntax
Jaykumar Pitambarbhai Patel6891b8b2020-01-23 14:32:20 +0530381
382.. code-block:: bash
383
Leonardo Sandoval98350142021-02-03 16:32:14 -0600384 cd <TF-M base folder>
Anton Komlevb8e3af02020-08-28 10:23:57 +0100385 mkdir cmake_build
386 cd cmake_build
Summer Qin2de23d02021-05-14 13:44:14 +0800387 cmake .. -DTFM_PLATFORM=arm/mps2/an521 -DTEST_PSA_API=IPC -DTFM_PSA_API=ON
Anton Komlevb8e3af02020-08-28 10:23:57 +0100388 make install
Jaykumar Pitambarbhai Patel6891b8b2020-01-23 14:32:20 +0530389
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200390Location of build artifacts
391===========================
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200392
Anton Komlevb8e3af02020-08-28 10:23:57 +0100393All build artifacts are provided in the ``<build_dir>/bin`` directory. It is
394**not** required to run ``make install`` to generate artifacts in this location.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200395
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200396
Anton Komlevb8e3af02020-08-28 10:23:57 +0100397For the purposes of maintaining compatibility with the legacy cmake build
398system, they are also provided in
399``<build_dir>/install/outputs/<target_platform>/``. In order to generate the
400artifacts in this location ``make install`` must be run.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200401
Anton Komlevb8e3af02020-08-28 10:23:57 +0100402****************************
403Manual dependency management
404****************************
Galanakis, Minos757139a2019-11-11 15:00:11 +0000405
Raef Coles1ecb8132020-10-02 15:11:24 +0100406The TF-M build system will by default fetch all dependencies with appropriate
407versions and store them inside the build tree. In this case, the build tree
408location is ``<build_dir>/lib/ext``, and the extra libraries can be cleaned by
409deleting that directory.
Galanakis, Minos757139a2019-11-11 15:00:11 +0000410
Raef Coles1ecb8132020-10-02 15:11:24 +0100411If you have local copies already, and wish to avoid having the libraries
412downloaded every time the build directory is deleted, then the following
Raef Colesc630b882020-12-10 15:46:18 +0000413variables can be set to the path to the root directory of the local repo. This
414will disable the automatic downloading for that dependency.
Raef Coles1ecb8132020-10-02 15:11:24 +0100415
Raef Colesc630b882020-12-10 15:46:18 +0000416+----------------+---------------------+-----------------------------------------------------+
417| Dependency | Cmake variable | Git repo URL |
418+================+=====================+=====================================================+
419| Mbed Crypto | MBEDCRYPTO_PATH | https://github.com/ARMmbed/mbedtls |
420+----------------+---------------------+-----------------------------------------------------+
421| tf-m-tests | TFM_TEST_REPO_PATH | https://git.trustedfirmware.org/TF-M/tf-m-tests.git |
422+----------------+---------------------+-----------------------------------------------------+
423| MCUboot | MCUBOOT_PATH | https://github.com/mcu-tools/mcuboot |
424+----------------+---------------------+-----------------------------------------------------+
425| psa-arch-tests | PSA_ARCH_TESTS_PATH | https://github.com/ARM-software/psa-arch-tests |
426+----------------+---------------------+-----------------------------------------------------+
Galanakis, Minos757139a2019-11-11 15:00:11 +0000427
Anton Komlevb8e3af02020-08-28 10:23:57 +0100428For required versions of the dependencies, refer to ``config/config_default.cmake``.
Galanakis, Minos757139a2019-11-11 15:00:11 +0000429
430.. Note::
Anton Komlevb8e3af02020-08-28 10:23:57 +0100431 - Some patches are required to the mbedtls repo to allow building it as part of
432 TF-M. While these patches are being upstreamed they are stored in
Raef Coles1ecb8132020-10-02 15:11:24 +0100433 ``lib/ext/mbedcrypo``. In order to use a local copy of Mbed Crypto it is
434 required to apply all patch files in this directory.
Galanakis, Minos757139a2019-11-11 15:00:11 +0000435
Anton Komlevb8e3af02020-08-28 10:23:57 +0100436.. Note::
437 - CMSIS 5 is provided by the TF-M tests repo. If you wish to use a different
438 source for CMSIS 5, it can be configured using CMSIS_5_PATH.
David Hu2cbf5df2020-06-15 10:41:44 +0800439
Kevin Pengcba37d32020-12-07 17:07:39 +0800440TF-M Tests
441==========
442
443Dependency auto downloading is used by default.
444The TF-M build system downloads the tf-m-tests repo with a fixed version
445specified by ``TFM_TEST_REPO_VERSION`` in ``config/config_default.cmake``.
446The version can be a release tag or a commit hash.
447
448Developers who want a different version of tf-m-tests can override
449``TFM_TEST_REPO_PATH`` to a local copy with the desired version.
450
451As the test repo is part of the TF-M project and coupled with TF-M repo a lot,
452The version should be updated when there are dependency changes between the TF-M
453repo and the test repo and when there is a complete change merged in test repo.
454
455A complete change is one or more patches that are for the same purpose, for
456example a new test suite or enhancements on the test cases.
457Patches in one change can be merge individually provided they do not break
458anything or cause any regressions.
459But the version in the TF-M gets updated only when all the patches are merged.
460
Raef Coles1ecb8132020-10-02 15:11:24 +0100461Example: building TF-M for AN521 platform with local Mbed Crypto
462================================================================
463
464Prepare Mbed Crypto repository
465------------------------------
466
467This is only required to be done once. For dependencies that do not have any
468``.patch`` files in their ``lib/ext`` directory the only required step is
469cloning the repo and checking out the correct branch.
470
471.. code-block:: bash
472
473 cd <Mbed Crypto base folder>
474 git clone https://github.com/ARMmbed/mbedtls
475 cd mbedtls
476 git checkout <MBEDCRYPTO_VERSION from config_default.cmake>
477 git apply <TF-M base folder>/trusted-firmware-m/lib/ext/mbedcrypo/*.patch
478
479.. Note::
480 - <Mbed Crypto base folder> does not need to have any fixed posisition related
481 to the TF-M repo.
482
483Build TF-M
484----------
485
486With new cmake syntax
487
488.. code-block:: bash
489
Leonardo Sandoval98350142021-02-03 16:32:14 -0600490 cd <TF-M base folder>
Summer Qin2de23d02021-05-14 13:44:14 +0800491 cmake -S . -B cmake_build -DTFM_PLATFORM=arm/mps2/an521 -DMBEDCRYPTO_PATH=<Mbed Crypto base folder>/mbedtls
Raef Coles1ecb8132020-10-02 15:11:24 +0100492 cmake --build cmake_build -- install
493
494Alternately using traditional cmake syntax
495
496.. code-block:: bash
497
Leonardo Sandoval98350142021-02-03 16:32:14 -0600498 cd <TF-M base folder>
Raef Coles1ecb8132020-10-02 15:11:24 +0100499 mkdir cmake_build
500 cd cmake_build
Summer Qin2de23d02021-05-14 13:44:14 +0800501 cmake .. -DTFM_PLATFORM=arm/mps2/an521 -DMBEDCRYPTO_PATH=<Mbed Crypto base folder>/mbedtls
Raef Coles1ecb8132020-10-02 15:11:24 +0100502 make install
503
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200504--------------
505
Summer Qinabf66982021-04-06 17:22:15 +0800506*Copyright (c) 2017-2021, Arm Limited. All rights reserved.*