blob: c7f096e763d7e7e18f81e36caaf7a6d56569bf61 [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
28 :doc:`Build instructions </technical_references/instructions/tfm_build_instruction>`
29 to compile and build the TF-M source.
30 - Follow the :doc:`Run TF-M examples on Arm platforms </technical_references/instructions/run_tfm_examples_on_arm_platforms>`
31 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
102 set PATH=<CMake_Path>\bin;$PATH
103
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
David Hu3aca3ed2022-01-12 20:58:05 +0800156 - Arm Compiler v6.10.1 ~ v6.14.1
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
David Hu3aca3ed2022-01-12 20:58:05 +0800179 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
Anton Komlev81506422022-02-15 21:53:13 +0000186 Arm compiler starting from *v6.15* may cause MemManage fault in TF-M
187 higher isolation levels. The issue is under investigation and
188 recommended to using versions prior to v6.15.
Anton Komlevc52e2d92021-11-25 17:20:09 +0000189
Summer Qin6d5c91c2021-05-24 15:32:44 +0800190 - GNU Arm compiler v7.3.1+
191
192 .. tabs::
193
194 .. group-tab:: Linux
195
196 - Download the GNU Arm compiler from `here <https://developer.arm.com/open-source/gnu-toolchain/gnu-rm/downloads>`__.
197 - Add GNU Arm into environment:
198
199 .. code-block:: bash
200
201 export PATH=<GNU_ARM_PATH>/bin:$PATH
202
203 .. group-tab:: Windows
204
205 - Download the GNU Arm compiler from `here <https://developer.arm.com/open-source/gnu-toolchain/gnu-rm/downloads>`__.
206 - Add GNU Arm into environment:
207
208 .. code-block:: bash
209
210 export PATH=<GNU_ARM_PATH>\bin;$PATH
211
212 .. note::
213
214 GNU Arm compiler version *10-2020-q4-major* has an issue in CMSE
215 support. The bug is reported in `here <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99157>`__.
216 Select other GNU Arm compiler versions instead.
217
218 - IAR Arm compiler v8.42.x, v8.50.x
219
220 .. tabs::
221
222 .. group-tab:: Linux
223
224 - Download IAR build tools from `here <https://www.iar.com/iar-embedded-workbench/build-tools-for-linux/>`__.
225 - Add IAR Arm compiler into environment:
226
227 .. code-block:: bash
228
229 export PATH=<IAR_COMPILER_PATH>/bin:$PATH
230
231 .. group-tab:: Windows
232
233 - Download IAR build tools from `here <https://www.iar.com/iar-embedded-workbench/#!?architecture=Arm>`__.
234 - Add IAR Arm compiler into environment:
235
236 .. code-block:: bash
237
238 export PATH=<IAR_COMPILER_PATH>\bin;$PATH
239
240#############################
241Build AN521 regression sample
242#############################
243
244Here, we take building TF-M for AN521 platform with regression tests using GCC
245as an example:
246
247.. tabs::
248
249 .. group-tab:: Linux
250
251 .. code-block:: bash
252
253 cd trusted-firmware-m
254 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
255 cmake --build cmake_build -- install
256
257 Alternately using traditional cmake syntax
258
259 .. code-block:: bash
260
261 cd trusted-firmware-m
262 mkdir cmake_build
263 cd cmake_build
264 cmake .. -DTFM_PLATFORM=arm/mps2/an521 -DTFM_TOOLCHAIN_FILE=../toolchain_GNUARM.cmake -DTEST_S=ON -DTEST_NS=ON
265 make install
266
267 .. group-tab:: Windows
268
269 .. code-block:: bash
270
271 cd trusted-firmware-m
272 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
273 cmake --build cmake_build -- install
274
275 Alternately using traditional cmake syntax
276
277 .. code-block:: bash
278
279 cd trusted-firmware-m
280 mkdir cmake_build
281 cd cmake_build
282 cmake -G"Unix Makefiles" .. -DTFM_PLATFORM=arm/mps2/an521 -DTFM_TOOLCHAIN_FILE=../toolchain_GNUARM.cmake -DTEST_S=ON -DTEST_NS=ON
283 make install
284
Anton Komlev81506422022-02-15 21:53:13 +0000285
286 .. note::
287 The latest Windows support long paths, but if you are less lucky
288 then you can reduce paths by moving the build directory closer to
289 the root, using the 'out of tree' build.
290 For example to build in ``C:\build`` folder you can:
291
292 .. code-block:: bash
293
294 cd trusted-firmware-m
295 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
296 cmake --build C:/build -- install
297
298
Summer Qin6d5c91c2021-05-24 15:32:44 +0800299###########################
300Run AN521 regression sample
301###########################
302
303Run the sample code on SSE-200 Fast-Model, using FVP_MPS2_AEMv8M provided by
304Arm Development Studio.
305
306.. note::
307
308 Arm Development Studio is not essential to develop TF-M, you can skip this
309 section if don't want to try on Arm develop boards.
310
311.. tabs::
312
313 .. group-tab:: Linux
314
315 1. install Arm Development Studio to get the fast-model.
316
317 Download Arm Development Studio from `here <https://developer.arm.com/tools-and-software/embedded/arm-development-studio>`__.
318
319 2. Add ``bl2.axf`` and ``tfm_s_ns_signed.bin`` to symbol files in Debug
320 Configuration menu.
321
322 .. code-block:: bash
323
324 <DS_PATH>/sw/models/bin/FVP_MPS2_AEMv8M \
325 --parameter fvp_mps2.platform_type=2 \
326 --parameter cpu0.baseline=0 \
327 --parameter cpu0.INITVTOR_S=0x10000000 \
328 --parameter cpu0.semihosting-enable=0 \
329 --parameter fvp_mps2.DISABLE_GATING=0 \
330 --parameter fvp_mps2.telnetterminal0.start_telnet=1 \
331 --parameter fvp_mps2.telnetterminal1.start_telnet=0 \
332 --parameter fvp_mps2.telnetterminal2.start_telnet=0 \
333 --parameter fvp_mps2.telnetterminal0.quiet=0 \
334 --parameter fvp_mps2.telnetterminal1.quiet=1 \
335 --parameter fvp_mps2.telnetterminal2.quiet=1 \
336 --application cpu0=<build_dir>/bin/bl2.axf \
337 --data cpu0=<build_dir>/bin/tfm_s_ns_signed.bin@0x10080000
338
339 .. group-tab:: Windows
340
341 1. install Arm Development Studio to get the fast-model.
342
343 Download Arm Development Studio from `here <https://developer.arm.com/tools-and-software/embedded/arm-development-studio>`__.
344
345 2. Add ``bl2.axf`` and ``tfm_s_ns_signed.bin`` to symbol files in Debug
346 Configuration menu.
347
348 .. code-block:: bash
349
350 <DS_PATH>\sw\models\bin\FVP_MPS2_AEMv8M \
351 --parameter fvp_mps2.platform_type=2 \
352 --parameter cpu0.baseline=0 \
353 --parameter cpu0.INITVTOR_S=0x10000000 \
354 --parameter cpu0.semihosting-enable=0 \
355 --parameter fvp_mps2.DISABLE_GATING=0 \
356 --parameter fvp_mps2.telnetterminal0.start_telnet=1 \
357 --parameter fvp_mps2.telnetterminal1.start_telnet=0 \
358 --parameter fvp_mps2.telnetterminal2.start_telnet=0 \
359 --parameter fvp_mps2.telnetterminal0.quiet=0 \
360 --parameter fvp_mps2.telnetterminal1.quiet=1 \
361 --parameter fvp_mps2.telnetterminal2.quiet=1 \
362 --application cpu0=<build_dir>/bin/bl2.axf \
363 --data cpu0=<build_dir>/bin/tfm_s_ns_signed.bin@0x10080000
364
365After completing the procedure you should see the following messages on the
366DAPLink UART (baud 115200 8n1)::
367
368 [INF] Starting bootloader
369 [INF] Image 0: magic=good, copy_done=0xff, image_ok=0xff
370 [INF] Scratch: magic=bad, copy_done=0x5, image_ok=0x9
371 [INF] Boot source: primary slot
372 [INF] Swap type: none
373 [INF] Bootloader chainload address offset: 0x20000
374 [INF] Jumping to the first image slot
375 [Sec Thread] Secure image initializing!
376
377 #### Execute test suites for the protected storage service ####
378 Running Test Suite PS secure interface tests (TFM_PS_TEST_2XXX)...
379 > Executing 'TFM_PS_TEST_2001'
380 Description: 'Create interface'
381 TEST PASSED!
382 > Executing 'TFM_PS_TEST_2002'
383 Description: 'Get handle interface (DEPRECATED)'
384 This test is DEPRECATED and the test execution was SKIPPED
385 TEST PASSED!
386 > Executing 'TFM_PS_TEST_2003'
387 Description: 'Get handle with null handle pointer (DEPRECATED)'
388 This test is DEPRECATED and the test execution was SKIPPED
389 TEST PASSED!
390 > Executing 'TFM_PS_TEST_2004'
391 Description: 'Get attributes interface'
392 TEST PASSED!
393 > Executing 'TFM_PS_TEST_2005'
394 Description: 'Get attributes with null attributes struct pointer'
395 ....
396
397##########################
398Tool & Dependency overview
399##########################
400
401To build the TF-M firmware the following tools are needed:
402
Anton Komlev4c436bf2021-10-18 21:59:55 +0100403 - C compiler of supported toolchains
404 - CMake version 3.15 or later
405 - Git
406 - gmake, aka GNU Make
407 - Python v3.x
408 - a set of python modules listed in ``tools/requiremtns.txt``
Summer Qin6d5c91c2021-05-24 15:32:44 +0800409
Anton Komlev91281f02022-04-22 09:24:20 +0100410****************
Anton Komlev4c436bf2021-10-18 21:59:55 +0100411Dependency chain
Anton Komlev91281f02022-04-22 09:24:20 +0100412****************
Summer Qin6d5c91c2021-05-24 15:32:44 +0800413
414.. uml::
415
416 @startuml
417 skinparam state {
418 BackgroundColor #92AEE0
419 FontColor black
420 FontSize 16
421 AttributeFontColor black
422 AttributeFontSize 16
Summer Qin6d5c91c2021-05-24 15:32:44 +0800423 }
424 state fw as "Firmware" : TF-M binary
425 state c_comp as "C Compiler" : C99
Anton Komlev4c436bf2021-10-18 21:59:55 +0100426 state python as "Python" : v3.x
Summer Qin6d5c91c2021-05-24 15:32:44 +0800427
Summer Qin6d5c91c2021-05-24 15:32:44 +0800428 fw --> c_comp
429 fw --> CMake
430 CMake --> gmake
Anton Komlev4c436bf2021-10-18 21:59:55 +0100431 CMake --> Ninja
Summer Qin6d5c91c2021-05-24 15:32:44 +0800432 fw --> cryptography
433 fw --> pyasn1
434 fw --> yaml
435 fw --> jinja2
Ross Burton5ba82392021-11-10 16:56:10 +0000436 fw --> cbor2
Summer Qin6d5c91c2021-05-24 15:32:44 +0800437 fw --> click
438 fw --> imgtool
Anton Komlev4c436bf2021-10-18 21:59:55 +0100439 c_comp --> GCC
440 c_comp --> CLANG
441 c_comp --> IAR
442 cryptography --> python
443 pyasn1 --> python
444 yaml --> python
445 jinja2 --> python
Ross Burton5ba82392021-11-10 16:56:10 +0000446 cbor2 --> python
Anton Komlev4c436bf2021-10-18 21:59:55 +0100447 click --> python
448 imgtool --> python
Summer Qin6d5c91c2021-05-24 15:32:44 +0800449 @enduml
450
Anton Komlev91281f02022-04-22 09:24:20 +0100451.. rubric:: Next steps
Summer Qin6d5c91c2021-05-24 15:32:44 +0800452
453Here are some next steps for exploring TF-M:
454
Anton Komlev3356ba32022-03-31 22:02:11 +0100455 - Detailed :doc:`Build instructions </technical_references/instructions/tfm_build_instruction>`.
456 - :doc:`IAR Build instructions </technical_references/instructions/tfm_build_instruction_iar>`.
457 - Try other :doc:`Samples and Demos </technical_references/instructions/run_tfm_examples_on_arm_platforms>`.
458 - :doc:`Documentation generation </technical_references/instructions/documentation_generation>`.
Summer Qin6d5c91c2021-05-24 15:32:44 +0800459
460--------------
461
David Hu3aca3ed2022-01-12 20:58:05 +0800462*Copyright (c) 2017-2022, Arm Limited. All rights reserved.*