blob: 0eb48cdd7da0744db0880f014ca8c2a52a91632b [file] [log] [blame]
Anton Komlev91281f02022-04-22 09:24:20 +01001##################
2First Things First
3##################
4
5************
6Prerequisite
7************
Antonio de Angelis465cc7b2024-06-27 20:19:01 +01008Trusted Firmware M provides a reference implementation of the Platform Security
9Architecture (PSA) specifications, aligning with PSA Certified guidelines.
10It is assumed that the reader is familiar with the specifications that can be
11found
12`here <https://developer.arm.com/architectures/security-architectures/platform-security-architecture>`__.
Anton Komlev91281f02022-04-22 09:24:20 +010013
Antonio de Angelis465cc7b2024-06-27 20:19:01 +010014The current TF-M implementation on Armv8-M leverages TrustZone for Armv8-M so a
Anton Komlev91281f02022-04-22 09:24:20 +010015good understanding of the v8-M architecture is also necessary. A good place to
Antonio de Angelis465cc7b2024-06-27 20:19:01 +010016get started with Armv8-M is
Anton Komlev91281f02022-04-22 09:24:20 +010017`developer.arm.com <https://developer.arm.com/architectures/cpu-architecture/m-profile>`__.
18
19**************************
20Build and run instructions
21**************************
22Trusted Firmware M source code is available on
23`git.trustedfirmware.org <https://git.trustedfirmware.org/TF-M/trusted-firmware-m.git/>`__.
24
25To build & run TF-M:
26
27 - Follow the this guide to set up and check your environment.
28 - Follow the
Anton Komlev0dbe8f12022-06-17 16:48:12 +010029 :doc:`Build instructions </building/tfm_build_instruction>`
Anton Komlev91281f02022-04-22 09:24:20 +010030 to compile and build the TF-M source.
Anton Komlev0dbe8f12022-06-17 16:48:12 +010031 - Follow the :doc:`Run TF-M examples on Arm platforms </building/run_tfm_examples_on_arm_platforms>`
Anton Komlev91281f02022-04-22 09:24:20 +010032 for information on running the example.
33
34To port TF-M to a another system or OS, follow the
35:doc:`OS Integration Guide </integration_guide/index>`
36
37:doc:`Contributing Guidelines </contributing/contributing_process>` contains guidance on how to
38contribute to this project.
39
40#########################
41Set up build environments
42#########################
Summer Qin6d5c91c2021-05-24 15:32:44 +080043
44TF-M officially supports a limited set of build environments and setups. In
45this context, official support means that the environments listed below
46are actively used by team members and active developers, hence users should
47be able to recreate the same configurations by following the instructions
48described below. In case of problems, the TF-M team provides support
49only for these environments, but building in other environments can still be
50possible.
51
52The following environments are supported:
53
54.. tabs::
55
56 .. group-tab:: Linux
57
58 1. version supported:
59
60 Ubuntu 18.04 x64+
61
62 2. install dependencies:
63
64 .. code-block:: bash
65
66 sudo apt-get install -y git curl wget build-essential libssl-dev python3 \
67 python3-pip cmake make
68
69 3. verify cmake version:
70
71 .. code-block:: bash
72
73 cmake --version
74
75 .. note::
76
Nik Dewallyae923b12024-06-26 15:30:09 +010077 Please download CMake version 3.21 or later from https://cmake.org/download/.
Summer Qin6d5c91c2021-05-24 15:32:44 +080078
79 4. add CMake path into environment:
80
81 .. code-block:: bash
82
83 export PATH=<CMake path>/bin:$PATH
84
85 .. group-tab:: Windows
86
87 1. version supported:
88
89 Windows 10 x64
90
Nik Dewallyae923b12024-06-26 15:30:09 +010091 2. install dependencies:
Summer Qin6d5c91c2021-05-24 15:32:44 +080092
93 - Git client latest version (https://git-scm.com/download/win)
Nik Dewallyae923b12024-06-26 15:30:09 +010094 - CMake version 3.21 or later (`native Windows version <https://cmake.org/download/>`__)
Summer Qin6d5c91c2021-05-24 15:32:44 +080095 - GNU make (http://gnuwin32.sourceforge.net/packages/make.htm)
96 - Python3 `(native Windows version) <https://www.python.org/downloads/>`__ and
97 the pip package manager (from Python 3.4 it's included)
98
99 3. add CMake path into environment:
100
101 .. code-block:: bash
102
Anton Komlev3c785b22022-06-19 16:08:49 +0100103 set PATH=<CMake_Path>\bin;%PATH%
Summer Qin6d5c91c2021-05-24 15:32:44 +0800104
105###########################
106Install python dependencies
107###########################
108
109Clone the TF-M source code, and then install the TF-M's additional Python
110dependencies.
111
112.. tabs::
113
114 .. group-tab:: Linux
115
116 1. get the TF-M source code:
117
118 .. code-block:: bash
119
Summer Qin6d5c91c2021-05-24 15:32:44 +0800120 git clone https://git.trustedfirmware.org/TF-M/trusted-firmware-m.git
121
122 2. TF-M's ``tools/requirements.txt`` file declares additional Python
123 dependencies. Install them with ``pip3``:
124
125 .. code-block:: bash
126
127 pip3 install --upgrade pip
128 cd trusted-firmware-m
129 pip3 install -r tools/requirements.txt
130
131 .. group-tab:: Windows
132
133 1. get the TF-M source code:
134
135 .. code-block:: bash
136
Summer Qin6d5c91c2021-05-24 15:32:44 +0800137 git clone https://git.trustedfirmware.org/TF-M/trusted-firmware-m.git
138
139 2. TF-M's ``tools/requirements.txt`` file declares additional Python
140 dependencies. Install them with ``pip3``:
141
142 .. code-block:: bash
143
144 cd trusted-firmware-m
145 pip3 install -r tools\requirements.txt
146
147###################
148Install a toolchain
149###################
150
151To compile TF-M code, at least one of the supported compiler toolchains have to
152be available in the build environment. The currently supported compiler
153versions are:
154
Chris Brand4b381f82022-12-01 16:30:23 -0800155 - Arm Compiler v6.13 ~ v6.14, v6.18+
Summer Qin6d5c91c2021-05-24 15:32:44 +0800156
157 .. tabs::
158
159 .. group-tab:: Linux
160
161 - Download the standalone packages from `here <https://developer.arm.com/products/software-development-tools/compilers/arm-compiler/downloads/version-6>`__.
162 - Add Arm Compiler into environment:
163
164 .. code-block:: bash
165
David Hu3aca3ed2022-01-12 20:58:05 +0800166 export PATH=<ARM_CLANG_PATH>/bin:$PATH
Summer Qin6d5c91c2021-05-24 15:32:44 +0800167 export ARM_PRODUCT_PATH=<ARM_CLANG_PATH>/sw/mappings
168
David Hu3aca3ed2022-01-12 20:58:05 +0800169 - Configure proper tool variant and license.
170
Summer Qin6d5c91c2021-05-24 15:32:44 +0800171 .. group-tab:: Windows
172
173 - Download the standalone packages from `here <https://developer.arm.com/products/software-development-tools/compilers/arm-compiler/downloads/version-6>`__.
174 - Add Arm Compiler into environment:
175
176 .. code-block:: bash
177
Anton Komlev3c785b22022-06-19 16:08:49 +0100178 set PATH=<ARM_CLANG_PATH>\bin;%PATH%
Summer Qin6d5c91c2021-05-24 15:32:44 +0800179 set ARM_PRODUCT_PATH=<ARM_CLANG_PATH>\sw\mappings
180
David Hu3aca3ed2022-01-12 20:58:05 +0800181 - Configure proper tool variant and license.
182
Anton Komlevc52e2d92021-11-25 17:20:09 +0000183 .. note::
184
David Hud9baf202022-05-17 15:47:21 +0800185 Arm compiler v6.15 ~ v6.17 may cause MemManage fault.
186 This defect has been fixed since Arm compiler v6.18.
187 See [SDCOMP-59788] in Armclang v6.18 `release note`__ for details.
188
Anton Komlevbd4582c2024-04-04 15:37:43 +0100189 .. __: https://developer.arm.com/documentation/107814/6-18
Anton Komlevc52e2d92021-11-25 17:20:09 +0000190
Summer Qin6d5c91c2021-05-24 15:32:44 +0800191 - GNU Arm compiler v7.3.1+
192
193 .. tabs::
194
195 .. group-tab:: Linux
196
197 - Download the GNU Arm compiler from `here <https://developer.arm.com/open-source/gnu-toolchain/gnu-rm/downloads>`__.
198 - Add GNU Arm into environment:
199
200 .. code-block:: bash
201
202 export PATH=<GNU_ARM_PATH>/bin:$PATH
203
204 .. group-tab:: Windows
205
206 - Download the GNU Arm compiler from `here <https://developer.arm.com/open-source/gnu-toolchain/gnu-rm/downloads>`__.
207 - Add GNU Arm into environment:
208
209 .. code-block:: bash
210
Anton Komlev3c785b22022-06-19 16:08:49 +0100211 set PATH=<GNU_ARM_PATH>\bin;%PATH%
Summer Qin6d5c91c2021-05-24 15:32:44 +0800212
213 .. note::
214
215 GNU Arm compiler version *10-2020-q4-major* has an issue in CMSE
216 support. The bug is reported in `here <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99157>`__.
217 Select other GNU Arm compiler versions instead.
218
219 - IAR Arm compiler v8.42.x, v8.50.x
220
221 .. tabs::
222
223 .. group-tab:: Linux
224
Anton Komlevbd4582c2024-04-04 15:37:43 +0100225 - Download IAR build tools from `here <https://www.iar.com/products/architectures/arm/iar-embedded-workbench-for-arm>`__.
Summer Qin6d5c91c2021-05-24 15:32:44 +0800226 - Add IAR Arm compiler into environment:
227
228 .. code-block:: bash
229
230 export PATH=<IAR_COMPILER_PATH>/bin:$PATH
231
232 .. group-tab:: Windows
233
Anton Komlevbd4582c2024-04-04 15:37:43 +0100234 - Download IAR build tools from `here <https://www.iar.com/products/architectures/arm/iar-embedded-workbench-for-arm>`__.
Summer Qin6d5c91c2021-05-24 15:32:44 +0800235 - Add IAR Arm compiler into environment:
236
237 .. code-block:: bash
238
Anton Komlev3c785b22022-06-19 16:08:49 +0100239 set PATH=<IAR_COMPILER_PATH>\bin;%PATH%
Summer Qin6d5c91c2021-05-24 15:32:44 +0800240
241#############################
242Build AN521 regression sample
243#############################
244
245Here, we take building TF-M for AN521 platform with regression tests using GCC
246as an example:
247
248.. tabs::
249
250 .. group-tab:: Linux
251
Kevin Peng2d170442023-11-20 14:09:07 +0800252 Get the TF-M tests source code:
Summer Qin6d5c91c2021-05-24 15:32:44 +0800253
254 .. code-block:: bash
255
Kevin Peng2d170442023-11-20 14:09:07 +0800256 git clone https://git.trustedfirmware.org/TF-M/tf-m-tests.git
257
258 Build SPE and NSPE.
259
260 .. code-block:: bash
261
262 cd </tf-m-tests/tests_reg>
Matthew Dalzellcb5e8b12024-03-20 14:35:39 +0000263 cmake -S spe -B build_spe -DTFM_PLATFORM=arm/mps2/an521 -DCONFIG_TFM_SOURCE_PATH=<TF-M source dir absolute path> \
264 -DCMAKE_BUILD_TYPE=Debug -DTFM_TOOLCHAIN_FILE=<TF-M source dir absolute path>/toolchain_GNUARM.cmake \
Kevin Peng2d170442023-11-20 14:09:07 +0800265 -DTEST_S=ON -DTEST_NS=ON \
266 cmake --build build_spe -- install
267
Matthew Dalzellcb5e8b12024-03-20 14:35:39 +0000268 cmake -S . -B build_test -DCONFIG_SPE_PATH=<tf-m-tests absolute path>/tests_reg/build_spe/api_ns \
269 -DCMAKE_BUILD_TYPE=Debug -DTFM_TOOLCHAIN_FILE=<tf-m-tests absolute path>/tests_reg/build_spe/api_ns/cmake/toolchain_ns_GNUARM.cmake
Kevin Peng2d170442023-11-20 14:09:07 +0800270 cmake --build build_test
Summer Qin6d5c91c2021-05-24 15:32:44 +0800271
272 .. group-tab:: Windows
273
Ken Liu6792e042023-11-13 14:48:00 +0800274 .. important::
275 Use "/" instead of "\\" when assigning Windows paths to CMAKE
276 variables, for example, use "c:/build" instead of "c:\\\\build".
277
Kevin Peng2d170442023-11-20 14:09:07 +0800278 Get the TF-M tests source code:
Summer Qin6d5c91c2021-05-24 15:32:44 +0800279
280 .. code-block:: bash
281
Kevin Peng2d170442023-11-20 14:09:07 +0800282 git clone https://git.trustedfirmware.org/TF-M/tf-m-tests.git
Summer Qin6d5c91c2021-05-24 15:32:44 +0800283
Kevin Peng2d170442023-11-20 14:09:07 +0800284 Build SPE and NSPE.
285
286 .. code-block:: bash
287
288 cd </tf-m-tests/tests_reg>
Matthew Dalzellcb5e8b12024-03-20 14:35:39 +0000289 cmake -G"Unix Makefiles" -S spe -B build_spe -DTFM_PLATFORM=arm/mps2/an521 -DCONFIG_TFM_SOURCE_PATH=<TF-M source dir absolute path> \
290 -DCMAKE_BUILD_TYPE=Debug -DTFM_TOOLCHAIN_FILE=<TF-M source dir absolute path>/toolchain_GNUARM.cmake \
Kevin Peng2d170442023-11-20 14:09:07 +0800291 -DTEST_S=ON -DTEST_NS=ON \
292 cmake --build build_spe -- install
293
Matthew Dalzellcb5e8b12024-03-20 14:35:39 +0000294 cmake -G"Unix Makefiles" -S . -B build_test -DCONFIG_SPE_PATH=<tf-m-tests absolute path>/tests_reg/build_spe/api_ns \
295 -DCMAKE_BUILD_TYPE=Debug -DTFM_TOOLCHAIN_FILE=<tf-m-tests absolute path>/tests_reg/build_spe/api_ns/cmake/toolchain_ns_GNUARM.cmake
Kevin Peng2d170442023-11-20 14:09:07 +0800296 cmake --build build_test
Anton Komlev81506422022-02-15 21:53:13 +0000297
298 .. note::
299 The latest Windows support long paths, but if you are less lucky
300 then you can reduce paths by moving the build directory closer to
Kevin Peng2d170442023-11-20 14:09:07 +0800301 the root by changing the ``-B`` option of the commands, for example,
302 to ``C:\build_spe`` and ``C:\build_test`` folders.
Anton Komlev81506422022-02-15 21:53:13 +0000303
Summer Qin6d5c91c2021-05-24 15:32:44 +0800304###########################
305Run AN521 regression sample
306###########################
307
308Run the sample code on SSE-200 Fast-Model, using FVP_MPS2_AEMv8M provided by
309Arm Development Studio.
310
311.. note::
312
313 Arm Development Studio is not essential to develop TF-M, you can skip this
314 section if don't want to try on Arm develop boards.
315
316.. tabs::
317
318 .. group-tab:: Linux
319
320 1. install Arm Development Studio to get the fast-model.
321
322 Download Arm Development Studio from `here <https://developer.arm.com/tools-and-software/embedded/arm-development-studio>`__.
323
324 2. Add ``bl2.axf`` and ``tfm_s_ns_signed.bin`` to symbol files in Debug
325 Configuration menu.
326
327 .. code-block:: bash
328
329 <DS_PATH>/sw/models/bin/FVP_MPS2_AEMv8M \
330 --parameter fvp_mps2.platform_type=2 \
331 --parameter cpu0.baseline=0 \
332 --parameter cpu0.INITVTOR_S=0x10000000 \
333 --parameter cpu0.semihosting-enable=0 \
334 --parameter fvp_mps2.DISABLE_GATING=0 \
335 --parameter fvp_mps2.telnetterminal0.start_telnet=1 \
336 --parameter fvp_mps2.telnetterminal1.start_telnet=0 \
337 --parameter fvp_mps2.telnetterminal2.start_telnet=0 \
338 --parameter fvp_mps2.telnetterminal0.quiet=0 \
339 --parameter fvp_mps2.telnetterminal1.quiet=1 \
340 --parameter fvp_mps2.telnetterminal2.quiet=1 \
Kevin Peng2d170442023-11-20 14:09:07 +0800341 --application cpu0=<build_spe>/api_ns/bin/bl2.axf \
342 --data cpu0=<build_test>/tfm_s_ns_signed.bin@0x10080000
Summer Qin6d5c91c2021-05-24 15:32:44 +0800343
Jason Guof64dc6b2023-07-06 15:55:26 +0800344 .. note::
345
346 The log is output to telnet by default.
347 It can be also redirected to stdout by adding the following parameter.
348
349 .. code-block:: bash
350
351 --parameter fvp_mps2.UART0.out_file=/dev/stdout
352
353 To automatically terminate the fast-model when it finishes running,
354 you can add the following parameters:
355
356 .. code-block:: bash
357
358 --parameter fvp_mps2.UART0.shutdown_on_eot=1
359
Summer Qin6d5c91c2021-05-24 15:32:44 +0800360 .. group-tab:: Windows
361
362 1. install Arm Development Studio to get the fast-model.
363
364 Download Arm Development Studio from `here <https://developer.arm.com/tools-and-software/embedded/arm-development-studio>`__.
365
366 2. Add ``bl2.axf`` and ``tfm_s_ns_signed.bin`` to symbol files in Debug
367 Configuration menu.
368
369 .. code-block:: bash
370
371 <DS_PATH>\sw\models\bin\FVP_MPS2_AEMv8M \
372 --parameter fvp_mps2.platform_type=2 \
373 --parameter cpu0.baseline=0 \
374 --parameter cpu0.INITVTOR_S=0x10000000 \
375 --parameter cpu0.semihosting-enable=0 \
376 --parameter fvp_mps2.DISABLE_GATING=0 \
377 --parameter fvp_mps2.telnetterminal0.start_telnet=1 \
378 --parameter fvp_mps2.telnetterminal1.start_telnet=0 \
379 --parameter fvp_mps2.telnetterminal2.start_telnet=0 \
380 --parameter fvp_mps2.telnetterminal0.quiet=0 \
381 --parameter fvp_mps2.telnetterminal1.quiet=1 \
382 --parameter fvp_mps2.telnetterminal2.quiet=1 \
Kevin Peng2d170442023-11-20 14:09:07 +0800383 --application cpu0=<build_spe>/api_ns/bin/bl2.axf \
384 --data cpu0=<build_test>/tfm_s_ns_signed.bin@0x10080000
Summer Qin6d5c91c2021-05-24 15:32:44 +0800385
Jason Guof64dc6b2023-07-06 15:55:26 +0800386 .. note::
387
388 To automatically terminate the fast-model when it finishes running,
389 you can add the following parameters:
390
391 .. code-block:: bash
392
393 --parameter fvp_mps2.UART0.shutdown_on_eot=1
394
Summer Qin6d5c91c2021-05-24 15:32:44 +0800395After completing the procedure you should see the following messages on the
396DAPLink UART (baud 115200 8n1)::
397
Kevin Peng2d170442023-11-20 14:09:07 +0800398 ...
399 #### Execute test suites for the Secure area ####
400 Running Test Suite PSA protected storage S interface tests (TFM_S_PS_TEST_1XXX)...
401 > Executing 'TFM_S_PS_TEST_1001'
402 Description: 'Set interface'
403 TEST: TFM_S_PS_TEST_1001 - PASSED!
404 > Executing 'TFM_S_PS_TEST_1002'
405 Description: 'Set interface with create flags'
406 TEST: TFM_S_PS_TEST_1002 - PASSED!
407 > Executing 'TFM_S_PS_TEST_1003'
408 Description: 'Set interface with NULL data pointer'
409 TEST: TFM_S_PS_TEST_1003 - PASSED!
410 > Executing 'TFM_S_PS_TEST_1005'
411 Description: 'Set interface with write once UID'
412 TEST: TFM_S_PS_TEST_1005 - PASSED!
Summer Qin6d5c91c2021-05-24 15:32:44 +0800413 ....
414
415##########################
416Tool & Dependency overview
417##########################
418
419To build the TF-M firmware the following tools are needed:
420
Anton Komlev4c436bf2021-10-18 21:59:55 +0100421 - C compiler of supported toolchains
Nik Dewallyae923b12024-06-26 15:30:09 +0100422 - CMake version 3.21 or later
Anton Komlev4c436bf2021-10-18 21:59:55 +0100423 - Git
424 - gmake, aka GNU Make
425 - Python v3.x
Nicola Mazzucatoafd24bb2024-02-14 17:27:27 +0000426 - a set of python modules listed in ``tools/requirements.txt``
Summer Qin6d5c91c2021-05-24 15:32:44 +0800427
Anton Komlev91281f02022-04-22 09:24:20 +0100428****************
Anton Komlev4c436bf2021-10-18 21:59:55 +0100429Dependency chain
Anton Komlev91281f02022-04-22 09:24:20 +0100430****************
Summer Qin6d5c91c2021-05-24 15:32:44 +0800431
432.. uml::
433
434 @startuml
435 skinparam state {
436 BackgroundColor #92AEE0
437 FontColor black
438 FontSize 16
439 AttributeFontColor black
440 AttributeFontSize 16
Summer Qin6d5c91c2021-05-24 15:32:44 +0800441 }
442 state fw as "Firmware" : TF-M binary
443 state c_comp as "C Compiler" : C99
Anton Komlev4c436bf2021-10-18 21:59:55 +0100444 state python as "Python" : v3.x
Summer Qin6d5c91c2021-05-24 15:32:44 +0800445
Summer Qin6d5c91c2021-05-24 15:32:44 +0800446 fw --> c_comp
447 fw --> CMake
448 CMake --> gmake
Anton Komlev4c436bf2021-10-18 21:59:55 +0100449 CMake --> Ninja
Summer Qin6d5c91c2021-05-24 15:32:44 +0800450 fw --> cryptography
451 fw --> pyasn1
452 fw --> yaml
453 fw --> jinja2
Ross Burton5ba82392021-11-10 16:56:10 +0000454 fw --> cbor2
Summer Qin6d5c91c2021-05-24 15:32:44 +0800455 fw --> click
456 fw --> imgtool
Anton Komlev4c436bf2021-10-18 21:59:55 +0100457 c_comp --> GCC
458 c_comp --> CLANG
459 c_comp --> IAR
460 cryptography --> python
461 pyasn1 --> python
462 yaml --> python
463 jinja2 --> python
Ross Burton5ba82392021-11-10 16:56:10 +0000464 cbor2 --> python
Anton Komlev4c436bf2021-10-18 21:59:55 +0100465 click --> python
466 imgtool --> python
Jianliang Shendfddc982022-11-29 15:08:19 +0800467 kconfiglib --> python
Summer Qin6d5c91c2021-05-24 15:32:44 +0800468 @enduml
469
Anton Komlev91281f02022-04-22 09:24:20 +0100470.. rubric:: Next steps
Summer Qin6d5c91c2021-05-24 15:32:44 +0800471
472Here are some next steps for exploring TF-M:
473
Anton Komlev0dbe8f12022-06-17 16:48:12 +0100474 - Detailed :doc:`Build instructions </building/tfm_build_instruction>`.
475 - :doc:`IAR Build instructions </building/tfm_build_instruction_iar>`.
476 - Try other :doc:`Samples and Demos </building/run_tfm_examples_on_arm_platforms>`.
477 - :doc:`Documentation generation </building/documentation_generation>`.
Summer Qin6d5c91c2021-05-24 15:32:44 +0800478
479--------------
480
Nicola Mazzucatoafd24bb2024-02-14 17:27:27 +0000481*Copyright (c) 2017-2024, Arm Limited. All rights reserved.*
Chris Brand4b381f82022-12-01 16:30:23 -0800482*Copyright (c) 2022 Cypress Semiconductor Corporation (an Infineon company)
483or an affiliate of Cypress Semiconductor Corporation. All rights reserved.*