blob: c5f21fc3c3dd9c40312deaecd95e9d2c63844053 [file] [log] [blame]
Anton Komlev91281f02022-04-22 09:24:20 +01001##################
2First Things First
3##################
4
5************
6Prerequisite
7************
8Trusted Firmware M provides a reference implementation of platform security
9architecture reference implementation aligning with PSA Certified guidelines.
10It is assumed that the reader is familiar with specifications can be found at
11`Platform Security Architecture Resources <https://developer.arm.com/architectures/security-architectures/platform-security-architecture>`__.
12
13The current TF-M implementation specifically targets TrustZone for ARMv8-M so a
14good understanding of the v8-M architecture is also necessary. A good place to
15get started with ARMv8-M is
16`developer.arm.com <https://developer.arm.com/architectures/cpu-architecture/m-profile>`__.
17
18**************************
19Build and run instructions
20**************************
21Trusted Firmware M source code is available on
22`git.trustedfirmware.org <https://git.trustedfirmware.org/TF-M/trusted-firmware-m.git/>`__.
23
24To build & run TF-M:
25
26 - Follow the this guide to set up and check your environment.
27 - Follow the
Anton Komlev0dbe8f12022-06-17 16:48:12 +010028 :doc:`Build instructions </building/tfm_build_instruction>`
Anton Komlev91281f02022-04-22 09:24:20 +010029 to compile and build the TF-M source.
Anton Komlev0dbe8f12022-06-17 16:48:12 +010030 - Follow the :doc:`Run TF-M examples on Arm platforms </building/run_tfm_examples_on_arm_platforms>`
Anton Komlev91281f02022-04-22 09:24:20 +010031 for information on running the example.
32
33To port TF-M to a another system or OS, follow the
34:doc:`OS Integration Guide </integration_guide/index>`
35
36:doc:`Contributing Guidelines </contributing/contributing_process>` contains guidance on how to
37contribute to this project.
38
39#########################
40Set up build environments
41#########################
Summer Qin6d5c91c2021-05-24 15:32:44 +080042
43TF-M officially supports a limited set of build environments and setups. In
44this context, official support means that the environments listed below
45are actively used by team members and active developers, hence users should
46be able to recreate the same configurations by following the instructions
47described below. In case of problems, the TF-M team provides support
48only for these environments, but building in other environments can still be
49possible.
50
51The following environments are supported:
52
53.. tabs::
54
55 .. group-tab:: Linux
56
57 1. version supported:
58
59 Ubuntu 18.04 x64+
60
61 2. install dependencies:
62
63 .. code-block:: bash
64
65 sudo apt-get install -y git curl wget build-essential libssl-dev python3 \
66 python3-pip cmake make
67
68 3. verify cmake version:
69
70 .. code-block:: bash
71
72 cmake --version
73
74 .. note::
75
76 Please download cmake 3.15 or later version from https://cmake.org/download/.
77
78 4. add CMake path into environment:
79
80 .. code-block:: bash
81
82 export PATH=<CMake path>/bin:$PATH
83
84 .. group-tab:: Windows
85
86 1. version supported:
87
88 Windows 10 x64
89
90 2. install dependecies:
91
92 - Git client latest version (https://git-scm.com/download/win)
93 - CMake (`native Windows version <https://cmake.org/download/>`__)
94 - GNU make (http://gnuwin32.sourceforge.net/packages/make.htm)
95 - Python3 `(native Windows version) <https://www.python.org/downloads/>`__ and
96 the pip package manager (from Python 3.4 it's included)
97
98 3. add CMake path into environment:
99
100 .. code-block:: bash
101
Anton Komlev3c785b22022-06-19 16:08:49 +0100102 set PATH=<CMake_Path>\bin;%PATH%
Summer Qin6d5c91c2021-05-24 15:32:44 +0800103
104###########################
105Install python dependencies
106###########################
107
108Clone the TF-M source code, and then install the TF-M's additional Python
109dependencies.
110
111.. tabs::
112
113 .. group-tab:: Linux
114
115 1. get the TF-M source code:
116
117 .. code-block:: bash
118
119 cd <base folder>
120 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
137 cd <base folder>
138 git clone https://git.trustedfirmware.org/TF-M/trusted-firmware-m.git
139
140 2. TF-M's ``tools/requirements.txt`` file declares additional Python
141 dependencies. Install them with ``pip3``:
142
143 .. code-block:: bash
144
145 cd trusted-firmware-m
146 pip3 install -r tools\requirements.txt
147
148###################
149Install a toolchain
150###################
151
152To compile TF-M code, at least one of the supported compiler toolchains have to
153be available in the build environment. The currently supported compiler
154versions are:
155
Chris Brand4b381f82022-12-01 16:30:23 -0800156 - Arm Compiler v6.13 ~ v6.14, v6.18+
Summer Qin6d5c91c2021-05-24 15:32:44 +0800157
158 .. tabs::
159
160 .. group-tab:: Linux
161
162 - Download the standalone packages from `here <https://developer.arm.com/products/software-development-tools/compilers/arm-compiler/downloads/version-6>`__.
163 - Add Arm Compiler into environment:
164
165 .. code-block:: bash
166
David Hu3aca3ed2022-01-12 20:58:05 +0800167 export PATH=<ARM_CLANG_PATH>/bin:$PATH
Summer Qin6d5c91c2021-05-24 15:32:44 +0800168 export ARM_PRODUCT_PATH=<ARM_CLANG_PATH>/sw/mappings
169
David Hu3aca3ed2022-01-12 20:58:05 +0800170 - Configure proper tool variant and license.
171
Summer Qin6d5c91c2021-05-24 15:32:44 +0800172 .. group-tab:: Windows
173
174 - Download the standalone packages from `here <https://developer.arm.com/products/software-development-tools/compilers/arm-compiler/downloads/version-6>`__.
175 - Add Arm Compiler into environment:
176
177 .. code-block:: bash
178
Anton Komlev3c785b22022-06-19 16:08:49 +0100179 set PATH=<ARM_CLANG_PATH>\bin;%PATH%
Summer Qin6d5c91c2021-05-24 15:32:44 +0800180 set ARM_PRODUCT_PATH=<ARM_CLANG_PATH>\sw\mappings
181
David Hu3aca3ed2022-01-12 20:58:05 +0800182 - Configure proper tool variant and license.
183
Anton Komlevc52e2d92021-11-25 17:20:09 +0000184 .. note::
185
David Hud9baf202022-05-17 15:47:21 +0800186 Arm compiler v6.15 ~ v6.17 may cause MemManage fault.
187 This defect has been fixed since Arm compiler v6.18.
188 See [SDCOMP-59788] in Armclang v6.18 `release note`__ for details.
189
190 .. __: https://developer.arm.com/-/media/Arm%20Developer%20Community/Downloads/Arm%20Compiler%20for%20Embedded/6-18/Release%20notes%20for%20Arm%20Compiler%20for%20Embedded%206.pdf
Anton Komlevc52e2d92021-11-25 17:20:09 +0000191
Summer Qin6d5c91c2021-05-24 15:32:44 +0800192 - GNU Arm compiler v7.3.1+
193
194 .. tabs::
195
196 .. group-tab:: Linux
197
198 - Download the GNU Arm compiler from `here <https://developer.arm.com/open-source/gnu-toolchain/gnu-rm/downloads>`__.
199 - Add GNU Arm into environment:
200
201 .. code-block:: bash
202
203 export PATH=<GNU_ARM_PATH>/bin:$PATH
204
205 .. group-tab:: Windows
206
207 - Download the GNU Arm compiler from `here <https://developer.arm.com/open-source/gnu-toolchain/gnu-rm/downloads>`__.
208 - Add GNU Arm into environment:
209
210 .. code-block:: bash
211
Anton Komlev3c785b22022-06-19 16:08:49 +0100212 set PATH=<GNU_ARM_PATH>\bin;%PATH%
Summer Qin6d5c91c2021-05-24 15:32:44 +0800213
214 .. note::
215
216 GNU Arm compiler version *10-2020-q4-major* has an issue in CMSE
217 support. The bug is reported in `here <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99157>`__.
218 Select other GNU Arm compiler versions instead.
219
220 - IAR Arm compiler v8.42.x, v8.50.x
221
222 .. tabs::
223
224 .. group-tab:: Linux
225
226 - Download IAR build tools from `here <https://www.iar.com/iar-embedded-workbench/build-tools-for-linux/>`__.
227 - Add IAR Arm compiler into environment:
228
229 .. code-block:: bash
230
231 export PATH=<IAR_COMPILER_PATH>/bin:$PATH
232
233 .. group-tab:: Windows
234
235 - Download IAR build tools from `here <https://www.iar.com/iar-embedded-workbench/#!?architecture=Arm>`__.
236 - Add IAR Arm compiler into environment:
237
238 .. code-block:: bash
239
Anton Komlev3c785b22022-06-19 16:08:49 +0100240 set PATH=<IAR_COMPILER_PATH>\bin;%PATH%
Summer Qin6d5c91c2021-05-24 15:32:44 +0800241
242#############################
243Build AN521 regression sample
244#############################
245
246Here, we take building TF-M for AN521 platform with regression tests using GCC
247as an example:
248
249.. tabs::
250
251 .. group-tab:: Linux
252
253 .. code-block:: bash
254
255 cd trusted-firmware-m
256 cmake -S . -B cmake_build -DTFM_PLATFORM=arm/mps2/an521 -DTFM_TOOLCHAIN_FILE=toolchain_GNUARM.cmake -DCMAKE_BUILD_TYPE=Debug -DTEST_S=ON -DTEST_NS=ON
257 cmake --build cmake_build -- install
258
259 Alternately using traditional cmake syntax
260
261 .. code-block:: bash
262
263 cd trusted-firmware-m
264 mkdir cmake_build
265 cd cmake_build
266 cmake .. -DTFM_PLATFORM=arm/mps2/an521 -DTFM_TOOLCHAIN_FILE=../toolchain_GNUARM.cmake -DTEST_S=ON -DTEST_NS=ON
267 make install
268
269 .. group-tab:: Windows
270
Ken Liu6792e042023-11-13 14:48:00 +0800271 .. important::
272 Use "/" instead of "\\" when assigning Windows paths to CMAKE
273 variables, for example, use "c:/build" instead of "c:\\\\build".
274
Summer Qin6d5c91c2021-05-24 15:32:44 +0800275 .. code-block:: bash
276
277 cd trusted-firmware-m
278 cmake -G"Unix Makefiles" -S . -B cmake_build -DTFM_PLATFORM=arm/mps2/an521 -DTFM_TOOLCHAIN_FILE=toolchain_GNUARM.cmake -DCMAKE_BUILD_TYPE=Debug -DTEST_S=ON -DTEST_NS=ON
279 cmake --build cmake_build -- install
280
281 Alternately using traditional cmake syntax
282
283 .. code-block:: bash
284
285 cd trusted-firmware-m
286 mkdir cmake_build
287 cd cmake_build
288 cmake -G"Unix Makefiles" .. -DTFM_PLATFORM=arm/mps2/an521 -DTFM_TOOLCHAIN_FILE=../toolchain_GNUARM.cmake -DTEST_S=ON -DTEST_NS=ON
289 make install
290
Anton Komlev81506422022-02-15 21:53:13 +0000291
292 .. note::
293 The latest Windows support long paths, but if you are less lucky
294 then you can reduce paths by moving the build directory closer to
295 the root, using the 'out of tree' build.
296 For example to build in ``C:\build`` folder you can:
297
298 .. code-block:: bash
299
300 cd trusted-firmware-m
301 cmake -G"Unix Makefiles" -S . -B C:/build -DTFM_PLATFORM=arm/mps2/an521 -DTFM_TOOLCHAIN_FILE=toolchain_GNUARM.cmake -DCMAKE_BUILD_TYPE=Debug -DTEST_S=ON -DTEST_NS=ON
302 cmake --build C:/build -- install
303
304
Summer Qin6d5c91c2021-05-24 15:32:44 +0800305###########################
306Run AN521 regression sample
307###########################
308
309Run the sample code on SSE-200 Fast-Model, using FVP_MPS2_AEMv8M provided by
310Arm Development Studio.
311
312.. note::
313
314 Arm Development Studio is not essential to develop TF-M, you can skip this
315 section if don't want to try on Arm develop boards.
316
317.. tabs::
318
319 .. group-tab:: Linux
320
321 1. install Arm Development Studio to get the fast-model.
322
323 Download Arm Development Studio from `here <https://developer.arm.com/tools-and-software/embedded/arm-development-studio>`__.
324
325 2. Add ``bl2.axf`` and ``tfm_s_ns_signed.bin`` to symbol files in Debug
326 Configuration menu.
327
328 .. code-block:: bash
329
330 <DS_PATH>/sw/models/bin/FVP_MPS2_AEMv8M \
331 --parameter fvp_mps2.platform_type=2 \
332 --parameter cpu0.baseline=0 \
333 --parameter cpu0.INITVTOR_S=0x10000000 \
334 --parameter cpu0.semihosting-enable=0 \
335 --parameter fvp_mps2.DISABLE_GATING=0 \
336 --parameter fvp_mps2.telnetterminal0.start_telnet=1 \
337 --parameter fvp_mps2.telnetterminal1.start_telnet=0 \
338 --parameter fvp_mps2.telnetterminal2.start_telnet=0 \
339 --parameter fvp_mps2.telnetterminal0.quiet=0 \
340 --parameter fvp_mps2.telnetterminal1.quiet=1 \
341 --parameter fvp_mps2.telnetterminal2.quiet=1 \
342 --application cpu0=<build_dir>/bin/bl2.axf \
343 --data cpu0=<build_dir>/bin/tfm_s_ns_signed.bin@0x10080000
344
Jason Guof64dc6b2023-07-06 15:55:26 +0800345 .. note::
346
347 The log is output to telnet by default.
348 It can be also redirected to stdout by adding the following parameter.
349
350 .. code-block:: bash
351
352 --parameter fvp_mps2.UART0.out_file=/dev/stdout
353
354 To automatically terminate the fast-model when it finishes running,
355 you can add the following parameters:
356
357 .. code-block:: bash
358
359 --parameter fvp_mps2.UART0.shutdown_on_eot=1
360
Summer Qin6d5c91c2021-05-24 15:32:44 +0800361 .. group-tab:: Windows
362
363 1. install Arm Development Studio to get the fast-model.
364
365 Download Arm Development Studio from `here <https://developer.arm.com/tools-and-software/embedded/arm-development-studio>`__.
366
367 2. Add ``bl2.axf`` and ``tfm_s_ns_signed.bin`` to symbol files in Debug
368 Configuration menu.
369
370 .. code-block:: bash
371
372 <DS_PATH>\sw\models\bin\FVP_MPS2_AEMv8M \
373 --parameter fvp_mps2.platform_type=2 \
374 --parameter cpu0.baseline=0 \
375 --parameter cpu0.INITVTOR_S=0x10000000 \
376 --parameter cpu0.semihosting-enable=0 \
377 --parameter fvp_mps2.DISABLE_GATING=0 \
378 --parameter fvp_mps2.telnetterminal0.start_telnet=1 \
379 --parameter fvp_mps2.telnetterminal1.start_telnet=0 \
380 --parameter fvp_mps2.telnetterminal2.start_telnet=0 \
381 --parameter fvp_mps2.telnetterminal0.quiet=0 \
382 --parameter fvp_mps2.telnetterminal1.quiet=1 \
383 --parameter fvp_mps2.telnetterminal2.quiet=1 \
384 --application cpu0=<build_dir>/bin/bl2.axf \
385 --data cpu0=<build_dir>/bin/tfm_s_ns_signed.bin@0x10080000
386
Jason Guof64dc6b2023-07-06 15:55:26 +0800387 .. note::
388
389 To automatically terminate the fast-model when it finishes running,
390 you can add the following parameters:
391
392 .. code-block:: bash
393
394 --parameter fvp_mps2.UART0.shutdown_on_eot=1
395
Summer Qin6d5c91c2021-05-24 15:32:44 +0800396After completing the procedure you should see the following messages on the
397DAPLink UART (baud 115200 8n1)::
398
399 [INF] Starting bootloader
400 [INF] Image 0: magic=good, copy_done=0xff, image_ok=0xff
401 [INF] Scratch: magic=bad, copy_done=0x5, image_ok=0x9
402 [INF] Boot source: primary slot
403 [INF] Swap type: none
404 [INF] Bootloader chainload address offset: 0x20000
405 [INF] Jumping to the first image slot
406 [Sec Thread] Secure image initializing!
407
408 #### Execute test suites for the protected storage service ####
409 Running Test Suite PS secure interface tests (TFM_PS_TEST_2XXX)...
410 > Executing 'TFM_PS_TEST_2001'
411 Description: 'Create interface'
412 TEST PASSED!
413 > Executing 'TFM_PS_TEST_2002'
414 Description: 'Get handle interface (DEPRECATED)'
415 This test is DEPRECATED and the test execution was SKIPPED
416 TEST PASSED!
417 > Executing 'TFM_PS_TEST_2003'
418 Description: 'Get handle with null handle pointer (DEPRECATED)'
419 This test is DEPRECATED and the test execution was SKIPPED
420 TEST PASSED!
421 > Executing 'TFM_PS_TEST_2004'
422 Description: 'Get attributes interface'
423 TEST PASSED!
424 > Executing 'TFM_PS_TEST_2005'
425 Description: 'Get attributes with null attributes struct pointer'
426 ....
427
428##########################
429Tool & Dependency overview
430##########################
431
432To build the TF-M firmware the following tools are needed:
433
Anton Komlev4c436bf2021-10-18 21:59:55 +0100434 - C compiler of supported toolchains
435 - CMake version 3.15 or later
436 - Git
437 - gmake, aka GNU Make
438 - Python v3.x
439 - a set of python modules listed in ``tools/requiremtns.txt``
Summer Qin6d5c91c2021-05-24 15:32:44 +0800440
Anton Komlev91281f02022-04-22 09:24:20 +0100441****************
Anton Komlev4c436bf2021-10-18 21:59:55 +0100442Dependency chain
Anton Komlev91281f02022-04-22 09:24:20 +0100443****************
Summer Qin6d5c91c2021-05-24 15:32:44 +0800444
445.. uml::
446
447 @startuml
448 skinparam state {
449 BackgroundColor #92AEE0
450 FontColor black
451 FontSize 16
452 AttributeFontColor black
453 AttributeFontSize 16
Summer Qin6d5c91c2021-05-24 15:32:44 +0800454 }
455 state fw as "Firmware" : TF-M binary
456 state c_comp as "C Compiler" : C99
Anton Komlev4c436bf2021-10-18 21:59:55 +0100457 state python as "Python" : v3.x
Summer Qin6d5c91c2021-05-24 15:32:44 +0800458
Summer Qin6d5c91c2021-05-24 15:32:44 +0800459 fw --> c_comp
460 fw --> CMake
461 CMake --> gmake
Anton Komlev4c436bf2021-10-18 21:59:55 +0100462 CMake --> Ninja
Summer Qin6d5c91c2021-05-24 15:32:44 +0800463 fw --> cryptography
464 fw --> pyasn1
465 fw --> yaml
466 fw --> jinja2
Ross Burton5ba82392021-11-10 16:56:10 +0000467 fw --> cbor2
Summer Qin6d5c91c2021-05-24 15:32:44 +0800468 fw --> click
469 fw --> imgtool
Anton Komlev4c436bf2021-10-18 21:59:55 +0100470 c_comp --> GCC
471 c_comp --> CLANG
472 c_comp --> IAR
473 cryptography --> python
474 pyasn1 --> python
475 yaml --> python
476 jinja2 --> python
Ross Burton5ba82392021-11-10 16:56:10 +0000477 cbor2 --> python
Anton Komlev4c436bf2021-10-18 21:59:55 +0100478 click --> python
479 imgtool --> python
Jianliang Shendfddc982022-11-29 15:08:19 +0800480 kconfiglib --> python
Summer Qin6d5c91c2021-05-24 15:32:44 +0800481 @enduml
482
Anton Komlev91281f02022-04-22 09:24:20 +0100483.. rubric:: Next steps
Summer Qin6d5c91c2021-05-24 15:32:44 +0800484
485Here are some next steps for exploring TF-M:
486
Anton Komlev0dbe8f12022-06-17 16:48:12 +0100487 - Detailed :doc:`Build instructions </building/tfm_build_instruction>`.
488 - :doc:`IAR Build instructions </building/tfm_build_instruction_iar>`.
489 - Try other :doc:`Samples and Demos </building/run_tfm_examples_on_arm_platforms>`.
490 - :doc:`Documentation generation </building/documentation_generation>`.
Summer Qin6d5c91c2021-05-24 15:32:44 +0800491
492--------------
493
David Hu3aca3ed2022-01-12 20:58:05 +0800494*Copyright (c) 2017-2022, Arm Limited. All rights reserved.*
Chris Brand4b381f82022-12-01 16:30:23 -0800495*Copyright (c) 2022 Cypress Semiconductor Corporation (an Infineon company)
496or an affiliate of Cypress Semiconductor Corporation. All rights reserved.*