blob: 49bdeffc2b93aee0ee50c7fb3c6c0e4be807360b [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+-----------------------------+-------------------------------------+---------------+
163| TFM_CRYPTO_TEST_HKDF | Test SHA-512 cryptography algorithm | ON |
164+-----------------------------+-------------------------------------+---------------+
165
Anton Komlev211aacf2020-11-02 12:48:11 +0000166TF-M Profiles
167-------------
168
169TF-M Profiles are implemented as a single cmake configuration file, under the
170``config/profile`` directory. A good understanding can be gained quickly by
171looking at the Profile configuration files, but the ultimate reference for
Summer Qinabf66982021-04-06 17:22:15 +0800172Profiles are the design documents in the ``docs/technical_references/profiles/``
Anton Komlev211aacf2020-11-02 12:48:11 +0000173directory.
Anton Komlevb8e3af02020-08-28 10:23:57 +0100174
175PSA test configuration
176----------------------
177
178PSA tests are configured by using the ``TEST_PSA_API`` cmake variable. The
179variable should be set to the name of the test suite that is desired. It is
180_not_ supported to set both ``TEST_PSA_API`` and ``TEST_S`` or ``TEST_NS``.
181
Jamie Fox19c91c22019-02-10 18:04:58 +0000182The Functional API tests are:
Anton Komlevb8e3af02020-08-28 10:23:57 +0100183 - ``CRYPTO``
184 - ``INITIAL_ATTESTATION``
185 - ``STORAGE`` (INTERNAL_TRUSTED_STORAGE and PROTECTED_STORAGE)
186 - ``INTERNAL_TRUSTED_STORAGE``
187 - ``PROTECTED_STORAGE``
188
Jamie Fox19c91c22019-02-10 18:04:58 +0000189The Firmware Framework test suites are:
Anton Komlevb8e3af02020-08-28 10:23:57 +0100190 - ``IPC``
191
192Note that these map directly to the ``SUITE`` cmake variable used in the
193psa-arch-tests documentation.
194
David Wangd6fd6af2021-06-21 17:17:26 +0800195.. _Migration from legacy buildsystem:
196
Anton Komlevb8e3af02020-08-28 10:23:57 +0100197Migration from legacy buildsystem
198---------------------------------
199
200The previous (legacy) cmake buildsystem made use of separate configuration
201files, where now build options are controlled by variables. For ease of
202transition, a table below is provided that maps the legacy files to the current
203variables, in the format of cmake command line parameters.
204
Summer Qin001ce9d2020-11-04 14:41:54 +0800205+------------------------------------------+---------------------------------------+
206| File | Cmake command line |
207+==========================================+=======================================+
208| ConfigDefault.cmake | <No options> |
209+------------------------------------------+---------------------------------------+
210| ConfigCoreIPC.cmake | -DTFM_PSA_API=ON |
211+------------------------------------------+---------------------------------------+
212| ConfigCoreIPCTfmLevel2.cmake | -DTFM_PSA_API=ON |
213| | -DTFM_ISOLATION_LEVEL=2 |
214+------------------------------------------+---------------------------------------+
215| ConfigDefaultProfileS.cmake | -DTFM_PROFILE=profile_small |
216+------------------------------------------+---------------------------------------+
217| ConfigDefaultProfileM.cmake | -DTFM_PROFILE=profile_medium |
218+------------------------------------------+---------------------------------------+
219| ConfigRegression.cmake | -DTEST_NS=ON -DTEST_S=ON |
220+------------------------------------------+---------------------------------------+
221| ConfigRegressionIPC.cmake | -DTEST_NS=ON -DTEST_S=ON |
222| | -DTFM_PSA_API=ON |
223+------------------------------------------+---------------------------------------+
224| ConfigRegressionIPCTfmLevel2.cmake | -DTEST_NS=ON -DTEST_S=ON |
225| | -DTFM_PSA_API=ON |
226| | -DTFM_ISOLATION_LEVEL=2 |
227+------------------------------------------+---------------------------------------+
228| ConfigRegressionProfileS.cmake | -DTFM_PROFILE=profile_small |
229| | -DTEST_NS=ON -DTEST_S=ON |
230+------------------------------------------+---------------------------------------+
231| ConfigRegressionProfileM.cmake | -DTFM_PROFILE=profile_medium |
232| | -DTEST_NS=ON -DTEST_S=ON |
233+------------------------------------------+---------------------------------------+
234| ConfigPsaApiTest.cmake | -DTEST_PSA_API=<test_suite> |
235+------------------------------------------+---------------------------------------+
236| ConfigPsaApiTestIPC.cmake | -DTEST_PSA_API=<test_suite> |
237| | -DTFM_PSA_API=ON |
238+------------------------------------------+---------------------------------------+
239| ConfigPsaApiTestIPCTfmLevel2.cmake | -DTEST_PSA_API=<test_suite> |
240| | -DTFM_PSA_API=ON |
241| | -DTFM_ISOLATION_LEVEL=2 |
242+------------------------------------------+---------------------------------------+
243| ConfigDefaultProfileM.cmake | -DTFM_PROFILE=profile_medium |
244| + profile_m_config_ext_ps_disabled.cmake | -DTFM_PARTITION_PROTECTED_STORAGE=OFF |
245+------------------------------------------+---------------------------------------+
Anton Komlevb8e3af02020-08-28 10:23:57 +0100246
247There has also been some changes to the PSA manifest file generation. The files
248are now generated into a seperate tree in the ``<tfm build dir>/generated``
249directory. Therefore they have been removed from the source tree. Any changes
250should be made only to the template files.
251
252The api for the ``tools/tfm_parse_manifest_list.py`` script has also changed
253slightly. It is no longer required to be run manually as it is run as part of
254cmake.
255
256*******************
257TF-M build examples
258*******************
259
Subhasish Ghoshbc849302021-04-08 20:21:20 +0100260.. Note::
261 By default, CMAKE_BUILD_TYPE is set to Release, for debug support change
262 this to Debug. See below for an example.
263
Anton Komlevb8e3af02020-08-28 10:23:57 +0100264Example: building TF-M for AN521 platform using GCC:
265====================================================
266.. code-block:: bash
267
Leonardo Sandoval98350142021-02-03 16:32:14 -0600268 cd <TF-M base folder>
Summer Qin2de23d02021-05-14 13:44:14 +0800269 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 +0100270 cmake --build cmake_build -- install
271
272Alternately using traditional cmake syntax
273
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200274.. code-block:: bash
275
Leonardo Sandoval98350142021-02-03 16:32:14 -0600276 cd <TF-M base folder>
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200277 mkdir cmake_build
278 cd cmake_build
Summer Qin2de23d02021-05-14 13:44:14 +0800279 cmake .. -DTFM_PLATFORM=arm/mps2/an521 -DTFM_TOOLCHAIN_FILE=../toolchain_GNUARM.cmake
Anton Komlevb8e3af02020-08-28 10:23:57 +0100280 make install
281
282.. Note::
283 Unix Makefiles is the default generator. Ninja is also supported by setting
284 -GNinja
285
286.. Note::
287
288 It is recommended to build each different build configuration in a separate
289 build directory.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200290
Leonardo Sandoval49a558c2021-02-03 17:04:22 -0600291As seen above, the toolchain can be set using the -DTFM_TOOLCHAIN_FILE parameter. Without
292it, the build command takes the GNU ARM toolchain as default, so there is no need
293to explicitly include it. In case other toolchain is required, i.e. ARM Clang, simply
294specify in the command line
295
296.. code-block:: bash
Subhasish Ghoshbc849302021-04-08 20:21:20 +0100297
Leonardo Sandoval49a558c2021-02-03 17:04:22 -0600298 cd <TF-M base folder>
Summer Qin2de23d02021-05-14 13:44:14 +0800299 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 -0600300 cmake --build cmake_build -- install
301
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200302Regression Tests for the AN521 target platform
303==============================================
Anton Komlevb8e3af02020-08-28 10:23:57 +0100304
305Regression tests can be build by using the TEST_S and TEST_NS settings. Either
306can be used in isolation or both can be used to enable both suites. All tests
307for all enabled partitions are run, along with IPC and Multicore tests if those
308features are enabled.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200309
310.. code-block:: bash
311
Leonardo Sandoval98350142021-02-03 16:32:14 -0600312 cd <TF-M base folder>
Summer Qin2de23d02021-05-14 13:44:14 +0800313 cmake -S . -B cmake_build -DTFM_PLATFORM=arm/mps2/an521 -DTEST_S=ON -DTEST_NS=ON
Anton Komlevb8e3af02020-08-28 10:23:57 +0100314 cmake --build cmake_build -- install
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200315
Anton Komlevb8e3af02020-08-28 10:23:57 +0100316Alternately using traditional cmake syntax
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200317
318.. code-block:: bash
319
Leonardo Sandoval98350142021-02-03 16:32:14 -0600320 cd <TF-M base folder>
Anton Komlevb8e3af02020-08-28 10:23:57 +0100321 mkdir cmake_build
322 cd cmake_build
Summer Qin2de23d02021-05-14 13:44:14 +0800323 cmake .. -DTFM_PLATFORM=arm/mps2/an521 -DTEST_S=ON -DTEST_NS=ON
Anton Komlevb8e3af02020-08-28 10:23:57 +0100324 make install
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200325
Jamie Fox19c91c22019-02-10 18:04:58 +0000326Build for PSA Functional API compliance tests
327=============================================
Anton Komlevb8e3af02020-08-28 10:23:57 +0100328The build system provides support for building and integrating the PSA API tests
329from https://github.com/ARM-software/psa-arch-tests. PSA API tests are
330controlled using the TEST_PSA_API variable. Enabling both regression tests and
331PSA API tests simultaneously is **not** supported.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200332
Anton Komlevb8e3af02020-08-28 10:23:57 +0100333The value of the TEST_PSA_API variable is the suite to be run.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200334
Subhasish Ghoshbc849302021-04-08 20:21:20 +0100335.. code-block:: bash
Anton Komlevb8e3af02020-08-28 10:23:57 +0100336
337 -DTEST_PSA_API=INTERNAL_TRUSTED_STORAGE
338 -DTEST_PSA_API=PROTECTED_STORAGE
339 -DTEST_PSA_API=STORAGE
340 -DTEST_PSA_API=CRYPTO
341 -DTEST_PSA_API=INITIAL_ATTESTATION
342
343Respectively for the corresponding service. For example, to enable the PSA API
344tests for the Crypto service:
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200345
346.. code-block:: bash
347
Leonardo Sandoval98350142021-02-03 16:32:14 -0600348 cd <TF-M base folder>
Summer Qin2de23d02021-05-14 13:44:14 +0800349 cmake -S . -B cmake_build -DTFM_PLATFORM=arm/mps2/an521 -DTEST_PSA_API=CRYPTO
Anton Komlevb8e3af02020-08-28 10:23:57 +0100350 cmake --build cmake_build -- install
351
352Alternately using traditional cmake syntax
353
354.. code-block:: bash
355
Leonardo Sandoval98350142021-02-03 16:32:14 -0600356 cd <TF-M base folder>
Anton Komlevb8e3af02020-08-28 10:23:57 +0100357 mkdir cmake_build
358 cd cmake_build
Summer Qin2de23d02021-05-14 13:44:14 +0800359 cmake .. -DTFM_PLATFORM=arm/mps2/an521 -DTEST_PSA_API=CRYPTO
Anton Komlevb8e3af02020-08-28 10:23:57 +0100360 make install
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200361
Jaykumar Pitambarbhai Patel6891b8b2020-01-23 14:32:20 +0530362Build for PSA FF (IPC) compliance tests
363=======================================
364
Anton Komlevb8e3af02020-08-28 10:23:57 +0100365The build system provides support for building and integrating the PSA FF
366compliance test. This support is controlled by the TEST_PSA_API variable:
Jaykumar Pitambarbhai Patel6891b8b2020-01-23 14:32:20 +0530367
Subhasish Ghoshbc849302021-04-08 20:21:20 +0100368.. code-block:: bash
Anton Komlevb8e3af02020-08-28 10:23:57 +0100369
370 -DTEST_PSA_API=IPC
Jaykumar Pitambarbhai Patel6891b8b2020-01-23 14:32:20 +0530371
372.. code-block:: bash
Minos Galanakisfc6804e2020-03-10 11:03:34 +0000373
Leonardo Sandoval98350142021-02-03 16:32:14 -0600374 cd <TF-M base folder>
Summer Qin2de23d02021-05-14 13:44:14 +0800375 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 +0100376 cmake --build cmake_build -- install
Jaykumar Pitambarbhai Patel6891b8b2020-01-23 14:32:20 +0530377
Anton Komlevb8e3af02020-08-28 10:23:57 +0100378Alternately using traditional cmake syntax
Jaykumar Pitambarbhai Patel6891b8b2020-01-23 14:32:20 +0530379
380.. code-block:: bash
381
Leonardo Sandoval98350142021-02-03 16:32:14 -0600382 cd <TF-M base folder>
Anton Komlevb8e3af02020-08-28 10:23:57 +0100383 mkdir cmake_build
384 cd cmake_build
Summer Qin2de23d02021-05-14 13:44:14 +0800385 cmake .. -DTFM_PLATFORM=arm/mps2/an521 -DTEST_PSA_API=IPC -DTFM_PSA_API=ON
Anton Komlevb8e3af02020-08-28 10:23:57 +0100386 make install
Jaykumar Pitambarbhai Patel6891b8b2020-01-23 14:32:20 +0530387
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200388Location of build artifacts
389===========================
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200390
Anton Komlevb8e3af02020-08-28 10:23:57 +0100391All build artifacts are provided in the ``<build_dir>/bin`` directory. It is
392**not** required to run ``make install`` to generate artifacts in this location.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200393
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200394
Anton Komlevb8e3af02020-08-28 10:23:57 +0100395For the purposes of maintaining compatibility with the legacy cmake build
396system, they are also provided in
397``<build_dir>/install/outputs/<target_platform>/``. In order to generate the
398artifacts in this location ``make install`` must be run.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200399
Anton Komlevb8e3af02020-08-28 10:23:57 +0100400****************************
401Manual dependency management
402****************************
Galanakis, Minos757139a2019-11-11 15:00:11 +0000403
Raef Coles1ecb8132020-10-02 15:11:24 +0100404The TF-M build system will by default fetch all dependencies with appropriate
405versions and store them inside the build tree. In this case, the build tree
406location is ``<build_dir>/lib/ext``, and the extra libraries can be cleaned by
407deleting that directory.
Galanakis, Minos757139a2019-11-11 15:00:11 +0000408
Raef Coles1ecb8132020-10-02 15:11:24 +0100409If you have local copies already, and wish to avoid having the libraries
410downloaded every time the build directory is deleted, then the following
Raef Colesc630b882020-12-10 15:46:18 +0000411variables can be set to the path to the root directory of the local repo. This
412will disable the automatic downloading for that dependency.
Raef Coles1ecb8132020-10-02 15:11:24 +0100413
Raef Colesc630b882020-12-10 15:46:18 +0000414+----------------+---------------------+-----------------------------------------------------+
415| Dependency | Cmake variable | Git repo URL |
416+================+=====================+=====================================================+
417| Mbed Crypto | MBEDCRYPTO_PATH | https://github.com/ARMmbed/mbedtls |
418+----------------+---------------------+-----------------------------------------------------+
419| tf-m-tests | TFM_TEST_REPO_PATH | https://git.trustedfirmware.org/TF-M/tf-m-tests.git |
420+----------------+---------------------+-----------------------------------------------------+
421| MCUboot | MCUBOOT_PATH | https://github.com/mcu-tools/mcuboot |
422+----------------+---------------------+-----------------------------------------------------+
423| psa-arch-tests | PSA_ARCH_TESTS_PATH | https://github.com/ARM-software/psa-arch-tests |
424+----------------+---------------------+-----------------------------------------------------+
Galanakis, Minos757139a2019-11-11 15:00:11 +0000425
Anton Komlevb8e3af02020-08-28 10:23:57 +0100426For required versions of the dependencies, refer to ``config/config_default.cmake``.
Galanakis, Minos757139a2019-11-11 15:00:11 +0000427
428.. Note::
Anton Komlevb8e3af02020-08-28 10:23:57 +0100429 - Some patches are required to the mbedtls repo to allow building it as part of
430 TF-M. While these patches are being upstreamed they are stored in
Raef Coles1ecb8132020-10-02 15:11:24 +0100431 ``lib/ext/mbedcrypo``. In order to use a local copy of Mbed Crypto it is
432 required to apply all patch files in this directory.
Galanakis, Minos757139a2019-11-11 15:00:11 +0000433
Anton Komlevb8e3af02020-08-28 10:23:57 +0100434.. Note::
435 - CMSIS 5 is provided by the TF-M tests repo. If you wish to use a different
436 source for CMSIS 5, it can be configured using CMSIS_5_PATH.
David Hu2cbf5df2020-06-15 10:41:44 +0800437
Kevin Pengcba37d32020-12-07 17:07:39 +0800438TF-M Tests
439==========
440
441Dependency auto downloading is used by default.
442The TF-M build system downloads the tf-m-tests repo with a fixed version
443specified by ``TFM_TEST_REPO_VERSION`` in ``config/config_default.cmake``.
444The version can be a release tag or a commit hash.
445
446Developers who want a different version of tf-m-tests can override
447``TFM_TEST_REPO_PATH`` to a local copy with the desired version.
448
449As the test repo is part of the TF-M project and coupled with TF-M repo a lot,
450The version should be updated when there are dependency changes between the TF-M
451repo and the test repo and when there is a complete change merged in test repo.
452
453A complete change is one or more patches that are for the same purpose, for
454example a new test suite or enhancements on the test cases.
455Patches in one change can be merge individually provided they do not break
456anything or cause any regressions.
457But the version in the TF-M gets updated only when all the patches are merged.
458
Raef Coles1ecb8132020-10-02 15:11:24 +0100459Example: building TF-M for AN521 platform with local Mbed Crypto
460================================================================
461
462Prepare Mbed Crypto repository
463------------------------------
464
465This is only required to be done once. For dependencies that do not have any
466``.patch`` files in their ``lib/ext`` directory the only required step is
467cloning the repo and checking out the correct branch.
468
469.. code-block:: bash
470
471 cd <Mbed Crypto base folder>
472 git clone https://github.com/ARMmbed/mbedtls
473 cd mbedtls
474 git checkout <MBEDCRYPTO_VERSION from config_default.cmake>
475 git apply <TF-M base folder>/trusted-firmware-m/lib/ext/mbedcrypo/*.patch
476
477.. Note::
478 - <Mbed Crypto base folder> does not need to have any fixed posisition related
479 to the TF-M repo.
480
481Build TF-M
482----------
483
484With new cmake syntax
485
486.. code-block:: bash
487
Leonardo Sandoval98350142021-02-03 16:32:14 -0600488 cd <TF-M base folder>
Summer Qin2de23d02021-05-14 13:44:14 +0800489 cmake -S . -B cmake_build -DTFM_PLATFORM=arm/mps2/an521 -DMBEDCRYPTO_PATH=<Mbed Crypto base folder>/mbedtls
Raef Coles1ecb8132020-10-02 15:11:24 +0100490 cmake --build cmake_build -- install
491
492Alternately using traditional cmake syntax
493
494.. code-block:: bash
495
Leonardo Sandoval98350142021-02-03 16:32:14 -0600496 cd <TF-M base folder>
Raef Coles1ecb8132020-10-02 15:11:24 +0100497 mkdir cmake_build
498 cd cmake_build
Summer Qin2de23d02021-05-14 13:44:14 +0800499 cmake .. -DTFM_PLATFORM=arm/mps2/an521 -DMBEDCRYPTO_PATH=<Mbed Crypto base folder>/mbedtls
Raef Coles1ecb8132020-10-02 15:11:24 +0100500 make install
501
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200502--------------
503
Summer Qinabf66982021-04-06 17:22:15 +0800504*Copyright (c) 2017-2021, Arm Limited. All rights reserved.*