blob: 3657f6f7fdd9de5407c00f3522d1f33f6d285222 [file] [log] [blame]
Summer Qin6d5c91c2021-05-24 15:32:44 +08001####################################
2Select and set up build environments
3####################################
4
5TF-M officially supports a limited set of build environments and setups. In
6this context, official support means that the environments listed below
7are actively used by team members and active developers, hence users should
8be able to recreate the same configurations by following the instructions
9described below. In case of problems, the TF-M team provides support
10only for these environments, but building in other environments can still be
11possible.
12
13The following environments are supported:
14
15.. tabs::
16
17 .. group-tab:: Linux
18
19 1. version supported:
20
21 Ubuntu 18.04 x64+
22
23 2. install dependencies:
24
25 .. code-block:: bash
26
27 sudo apt-get install -y git curl wget build-essential libssl-dev python3 \
28 python3-pip cmake make
29
30 3. verify cmake version:
31
32 .. code-block:: bash
33
34 cmake --version
35
36 .. note::
37
38 Please download cmake 3.15 or later version from https://cmake.org/download/.
39
40 4. add CMake path into environment:
41
42 .. code-block:: bash
43
44 export PATH=<CMake path>/bin:$PATH
45
46 .. group-tab:: Windows
47
48 1. version supported:
49
50 Windows 10 x64
51
52 2. install dependecies:
53
54 - Git client latest version (https://git-scm.com/download/win)
55 - CMake (`native Windows version <https://cmake.org/download/>`__)
56 - GNU make (http://gnuwin32.sourceforge.net/packages/make.htm)
57 - Python3 `(native Windows version) <https://www.python.org/downloads/>`__ and
58 the pip package manager (from Python 3.4 it's included)
59
60 3. add CMake path into environment:
61
62 .. code-block:: bash
63
64 set PATH=<CMake_Path>\bin;$PATH
65
66###########################
67Install python dependencies
68###########################
69
70Clone the TF-M source code, and then install the TF-M's additional Python
71dependencies.
72
73.. tabs::
74
75 .. group-tab:: Linux
76
77 1. get the TF-M source code:
78
79 .. code-block:: bash
80
81 cd <base folder>
82 git clone https://git.trustedfirmware.org/TF-M/trusted-firmware-m.git
83
84 2. TF-M's ``tools/requirements.txt`` file declares additional Python
85 dependencies. Install them with ``pip3``:
86
87 .. code-block:: bash
88
89 pip3 install --upgrade pip
90 cd trusted-firmware-m
91 pip3 install -r tools/requirements.txt
92
93 .. group-tab:: Windows
94
95 1. get the TF-M source code:
96
97 .. code-block:: bash
98
99 cd <base folder>
100 git clone https://git.trustedfirmware.org/TF-M/trusted-firmware-m.git
101
102 2. TF-M's ``tools/requirements.txt`` file declares additional Python
103 dependencies. Install them with ``pip3``:
104
105 .. code-block:: bash
106
107 cd trusted-firmware-m
108 pip3 install -r tools\requirements.txt
109
110###################
111Install a toolchain
112###################
113
114To compile TF-M code, at least one of the supported compiler toolchains have to
115be available in the build environment. The currently supported compiler
116versions are:
117
David Hu3aca3ed2022-01-12 20:58:05 +0800118 - Arm Compiler v6.10.1 ~ v6.14.1
Summer Qin6d5c91c2021-05-24 15:32:44 +0800119
120 .. tabs::
121
122 .. group-tab:: Linux
123
124 - Download the standalone packages from `here <https://developer.arm.com/products/software-development-tools/compilers/arm-compiler/downloads/version-6>`__.
125 - Add Arm Compiler into environment:
126
127 .. code-block:: bash
128
David Hu3aca3ed2022-01-12 20:58:05 +0800129 export PATH=<ARM_CLANG_PATH>/bin:$PATH
Summer Qin6d5c91c2021-05-24 15:32:44 +0800130 export ARM_PRODUCT_PATH=<ARM_CLANG_PATH>/sw/mappings
131
David Hu3aca3ed2022-01-12 20:58:05 +0800132 - Configure proper tool variant and license.
133
Summer Qin6d5c91c2021-05-24 15:32:44 +0800134 .. group-tab:: Windows
135
136 - Download the standalone packages from `here <https://developer.arm.com/products/software-development-tools/compilers/arm-compiler/downloads/version-6>`__.
137 - Add Arm Compiler into environment:
138
139 .. code-block:: bash
140
David Hu3aca3ed2022-01-12 20:58:05 +0800141 set PATH=<ARM_CLANG_PATH>\bin;$PATH
Summer Qin6d5c91c2021-05-24 15:32:44 +0800142 set ARM_PRODUCT_PATH=<ARM_CLANG_PATH>\sw\mappings
143
David Hu3aca3ed2022-01-12 20:58:05 +0800144 - Configure proper tool variant and license.
145
Anton Komlevc52e2d92021-11-25 17:20:09 +0000146 .. note::
147
Anton Komlev81506422022-02-15 21:53:13 +0000148 Arm compiler starting from *v6.15* may cause MemManage fault in TF-M
149 higher isolation levels. The issue is under investigation and
150 recommended to using versions prior to v6.15.
Anton Komlevc52e2d92021-11-25 17:20:09 +0000151
Summer Qin6d5c91c2021-05-24 15:32:44 +0800152 - GNU Arm compiler v7.3.1+
153
154 .. tabs::
155
156 .. group-tab:: Linux
157
158 - Download the GNU Arm compiler from `here <https://developer.arm.com/open-source/gnu-toolchain/gnu-rm/downloads>`__.
159 - Add GNU Arm into environment:
160
161 .. code-block:: bash
162
163 export PATH=<GNU_ARM_PATH>/bin:$PATH
164
165 .. group-tab:: Windows
166
167 - Download the GNU Arm compiler from `here <https://developer.arm.com/open-source/gnu-toolchain/gnu-rm/downloads>`__.
168 - Add GNU Arm into environment:
169
170 .. code-block:: bash
171
172 export PATH=<GNU_ARM_PATH>\bin;$PATH
173
174 .. note::
175
176 GNU Arm compiler version *10-2020-q4-major* has an issue in CMSE
177 support. The bug is reported in `here <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99157>`__.
178 Select other GNU Arm compiler versions instead.
179
180 - IAR Arm compiler v8.42.x, v8.50.x
181
182 .. tabs::
183
184 .. group-tab:: Linux
185
186 - Download IAR build tools from `here <https://www.iar.com/iar-embedded-workbench/build-tools-for-linux/>`__.
187 - Add IAR Arm compiler into environment:
188
189 .. code-block:: bash
190
191 export PATH=<IAR_COMPILER_PATH>/bin:$PATH
192
193 .. group-tab:: Windows
194
195 - Download IAR build tools from `here <https://www.iar.com/iar-embedded-workbench/#!?architecture=Arm>`__.
196 - Add IAR Arm compiler into environment:
197
198 .. code-block:: bash
199
200 export PATH=<IAR_COMPILER_PATH>\bin;$PATH
201
202#############################
203Build AN521 regression sample
204#############################
205
206Here, we take building TF-M for AN521 platform with regression tests using GCC
207as an example:
208
209.. tabs::
210
211 .. group-tab:: Linux
212
213 .. code-block:: bash
214
215 cd trusted-firmware-m
216 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
217 cmake --build cmake_build -- install
218
219 Alternately using traditional cmake syntax
220
221 .. code-block:: bash
222
223 cd trusted-firmware-m
224 mkdir cmake_build
225 cd cmake_build
226 cmake .. -DTFM_PLATFORM=arm/mps2/an521 -DTFM_TOOLCHAIN_FILE=../toolchain_GNUARM.cmake -DTEST_S=ON -DTEST_NS=ON
227 make install
228
229 .. group-tab:: Windows
230
231 .. code-block:: bash
232
233 cd trusted-firmware-m
234 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
235 cmake --build cmake_build -- install
236
237 Alternately using traditional cmake syntax
238
239 .. code-block:: bash
240
241 cd trusted-firmware-m
242 mkdir cmake_build
243 cd cmake_build
244 cmake -G"Unix Makefiles" .. -DTFM_PLATFORM=arm/mps2/an521 -DTFM_TOOLCHAIN_FILE=../toolchain_GNUARM.cmake -DTEST_S=ON -DTEST_NS=ON
245 make install
246
Anton Komlev81506422022-02-15 21:53:13 +0000247
248 .. note::
249 The latest Windows support long paths, but if you are less lucky
250 then you can reduce paths by moving the build directory closer to
251 the root, using the 'out of tree' build.
252 For example to build in ``C:\build`` folder you can:
253
254 .. code-block:: bash
255
256 cd trusted-firmware-m
257 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
258 cmake --build C:/build -- install
259
260
Summer Qin6d5c91c2021-05-24 15:32:44 +0800261###########################
262Run AN521 regression sample
263###########################
264
265Run the sample code on SSE-200 Fast-Model, using FVP_MPS2_AEMv8M provided by
266Arm Development Studio.
267
268.. note::
269
270 Arm Development Studio is not essential to develop TF-M, you can skip this
271 section if don't want to try on Arm develop boards.
272
273.. tabs::
274
275 .. group-tab:: Linux
276
277 1. install Arm Development Studio to get the fast-model.
278
279 Download Arm Development Studio from `here <https://developer.arm.com/tools-and-software/embedded/arm-development-studio>`__.
280
281 2. Add ``bl2.axf`` and ``tfm_s_ns_signed.bin`` to symbol files in Debug
282 Configuration menu.
283
284 .. code-block:: bash
285
286 <DS_PATH>/sw/models/bin/FVP_MPS2_AEMv8M \
287 --parameter fvp_mps2.platform_type=2 \
288 --parameter cpu0.baseline=0 \
289 --parameter cpu0.INITVTOR_S=0x10000000 \
290 --parameter cpu0.semihosting-enable=0 \
291 --parameter fvp_mps2.DISABLE_GATING=0 \
292 --parameter fvp_mps2.telnetterminal0.start_telnet=1 \
293 --parameter fvp_mps2.telnetterminal1.start_telnet=0 \
294 --parameter fvp_mps2.telnetterminal2.start_telnet=0 \
295 --parameter fvp_mps2.telnetterminal0.quiet=0 \
296 --parameter fvp_mps2.telnetterminal1.quiet=1 \
297 --parameter fvp_mps2.telnetterminal2.quiet=1 \
298 --application cpu0=<build_dir>/bin/bl2.axf \
299 --data cpu0=<build_dir>/bin/tfm_s_ns_signed.bin@0x10080000
300
301 .. group-tab:: Windows
302
303 1. install Arm Development Studio to get the fast-model.
304
305 Download Arm Development Studio from `here <https://developer.arm.com/tools-and-software/embedded/arm-development-studio>`__.
306
307 2. Add ``bl2.axf`` and ``tfm_s_ns_signed.bin`` to symbol files in Debug
308 Configuration menu.
309
310 .. code-block:: bash
311
312 <DS_PATH>\sw\models\bin\FVP_MPS2_AEMv8M \
313 --parameter fvp_mps2.platform_type=2 \
314 --parameter cpu0.baseline=0 \
315 --parameter cpu0.INITVTOR_S=0x10000000 \
316 --parameter cpu0.semihosting-enable=0 \
317 --parameter fvp_mps2.DISABLE_GATING=0 \
318 --parameter fvp_mps2.telnetterminal0.start_telnet=1 \
319 --parameter fvp_mps2.telnetterminal1.start_telnet=0 \
320 --parameter fvp_mps2.telnetterminal2.start_telnet=0 \
321 --parameter fvp_mps2.telnetterminal0.quiet=0 \
322 --parameter fvp_mps2.telnetterminal1.quiet=1 \
323 --parameter fvp_mps2.telnetterminal2.quiet=1 \
324 --application cpu0=<build_dir>/bin/bl2.axf \
325 --data cpu0=<build_dir>/bin/tfm_s_ns_signed.bin@0x10080000
326
327After completing the procedure you should see the following messages on the
328DAPLink UART (baud 115200 8n1)::
329
330 [INF] Starting bootloader
331 [INF] Image 0: magic=good, copy_done=0xff, image_ok=0xff
332 [INF] Scratch: magic=bad, copy_done=0x5, image_ok=0x9
333 [INF] Boot source: primary slot
334 [INF] Swap type: none
335 [INF] Bootloader chainload address offset: 0x20000
336 [INF] Jumping to the first image slot
337 [Sec Thread] Secure image initializing!
338
339 #### Execute test suites for the protected storage service ####
340 Running Test Suite PS secure interface tests (TFM_PS_TEST_2XXX)...
341 > Executing 'TFM_PS_TEST_2001'
342 Description: 'Create interface'
343 TEST PASSED!
344 > Executing 'TFM_PS_TEST_2002'
345 Description: 'Get handle interface (DEPRECATED)'
346 This test is DEPRECATED and the test execution was SKIPPED
347 TEST PASSED!
348 > Executing 'TFM_PS_TEST_2003'
349 Description: 'Get handle with null handle pointer (DEPRECATED)'
350 This test is DEPRECATED and the test execution was SKIPPED
351 TEST PASSED!
352 > Executing 'TFM_PS_TEST_2004'
353 Description: 'Get attributes interface'
354 TEST PASSED!
355 > Executing 'TFM_PS_TEST_2005'
356 Description: 'Get attributes with null attributes struct pointer'
357 ....
358
359##########################
360Tool & Dependency overview
361##########################
362
363To build the TF-M firmware the following tools are needed:
364
Anton Komlev4c436bf2021-10-18 21:59:55 +0100365 - C compiler of supported toolchains
366 - CMake version 3.15 or later
367 - Git
368 - gmake, aka GNU Make
369 - Python v3.x
370 - a set of python modules listed in ``tools/requiremtns.txt``
Summer Qin6d5c91c2021-05-24 15:32:44 +0800371
Anton Komlev4c436bf2021-10-18 21:59:55 +0100372Dependency chain
373----------------
Summer Qin6d5c91c2021-05-24 15:32:44 +0800374
375.. uml::
376
377 @startuml
378 skinparam state {
379 BackgroundColor #92AEE0
380 FontColor black
381 FontSize 16
382 AttributeFontColor black
383 AttributeFontSize 16
Summer Qin6d5c91c2021-05-24 15:32:44 +0800384 }
385 state fw as "Firmware" : TF-M binary
386 state c_comp as "C Compiler" : C99
Anton Komlev4c436bf2021-10-18 21:59:55 +0100387 state python as "Python" : v3.x
Summer Qin6d5c91c2021-05-24 15:32:44 +0800388
Summer Qin6d5c91c2021-05-24 15:32:44 +0800389 fw --> c_comp
390 fw --> CMake
391 CMake --> gmake
Anton Komlev4c436bf2021-10-18 21:59:55 +0100392 CMake --> Ninja
Summer Qin6d5c91c2021-05-24 15:32:44 +0800393 fw --> cryptography
394 fw --> pyasn1
395 fw --> yaml
396 fw --> jinja2
Ross Burton5ba82392021-11-10 16:56:10 +0000397 fw --> cbor2
Summer Qin6d5c91c2021-05-24 15:32:44 +0800398 fw --> click
399 fw --> imgtool
Anton Komlev4c436bf2021-10-18 21:59:55 +0100400 c_comp --> GCC
401 c_comp --> CLANG
402 c_comp --> IAR
403 cryptography --> python
404 pyasn1 --> python
405 yaml --> python
406 jinja2 --> python
Ross Burton5ba82392021-11-10 16:56:10 +0000407 cbor2 --> python
Anton Komlev4c436bf2021-10-18 21:59:55 +0100408 click --> python
409 imgtool --> python
Summer Qin6d5c91c2021-05-24 15:32:44 +0800410 @enduml
411
412##########
413Next steps
414##########
415
416Here are some next steps for exploring TF-M:
417
Anton Komlev3356ba32022-03-31 22:02:11 +0100418 - Detailed :doc:`Build instructions </technical_references/instructions/tfm_build_instruction>`.
419 - :doc:`IAR Build instructions </technical_references/instructions/tfm_build_instruction_iar>`.
420 - Try other :doc:`Samples and Demos </technical_references/instructions/run_tfm_examples_on_arm_platforms>`.
421 - :doc:`Documentation generation </technical_references/instructions/documentation_generation>`.
Summer Qin6d5c91c2021-05-24 15:32:44 +0800422
423--------------
424
David Hu3aca3ed2022-01-12 20:58:05 +0800425*Copyright (c) 2017-2022, Arm Limited. All rights reserved.*