Summer Qin | 6d5c91c | 2021-05-24 15:32:44 +0800 | [diff] [blame] | 1 | #################################### |
| 2 | Select and set up build environments |
| 3 | #################################### |
| 4 | |
| 5 | TF-M officially supports a limited set of build environments and setups. In |
| 6 | this context, official support means that the environments listed below |
| 7 | are actively used by team members and active developers, hence users should |
| 8 | be able to recreate the same configurations by following the instructions |
| 9 | described below. In case of problems, the TF-M team provides support |
| 10 | only for these environments, but building in other environments can still be |
| 11 | possible. |
| 12 | |
| 13 | The 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 | ########################### |
| 67 | Install python dependencies |
| 68 | ########################### |
| 69 | |
| 70 | Clone the TF-M source code, and then install the TF-M's additional Python |
| 71 | dependencies. |
| 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 | ################### |
| 111 | Install a toolchain |
| 112 | ################### |
| 113 | |
| 114 | To compile TF-M code, at least one of the supported compiler toolchains have to |
| 115 | be available in the build environment. The currently supported compiler |
| 116 | versions are: |
| 117 | |
David Hu | 3aca3ed | 2022-01-12 20:58:05 +0800 | [diff] [blame] | 118 | - Arm Compiler v6.10.1 ~ v6.14.1 |
Summer Qin | 6d5c91c | 2021-05-24 15:32:44 +0800 | [diff] [blame] | 119 | |
| 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 Hu | 3aca3ed | 2022-01-12 20:58:05 +0800 | [diff] [blame] | 129 | export PATH=<ARM_CLANG_PATH>/bin:$PATH |
Summer Qin | 6d5c91c | 2021-05-24 15:32:44 +0800 | [diff] [blame] | 130 | export ARM_PRODUCT_PATH=<ARM_CLANG_PATH>/sw/mappings |
| 131 | |
David Hu | 3aca3ed | 2022-01-12 20:58:05 +0800 | [diff] [blame] | 132 | - Configure proper tool variant and license. |
| 133 | |
Summer Qin | 6d5c91c | 2021-05-24 15:32:44 +0800 | [diff] [blame] | 134 | .. 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 Hu | 3aca3ed | 2022-01-12 20:58:05 +0800 | [diff] [blame] | 141 | set PATH=<ARM_CLANG_PATH>\bin;$PATH |
Summer Qin | 6d5c91c | 2021-05-24 15:32:44 +0800 | [diff] [blame] | 142 | set ARM_PRODUCT_PATH=<ARM_CLANG_PATH>\sw\mappings |
| 143 | |
David Hu | 3aca3ed | 2022-01-12 20:58:05 +0800 | [diff] [blame] | 144 | - Configure proper tool variant and license. |
| 145 | |
Anton Komlev | c52e2d9 | 2021-11-25 17:20:09 +0000 | [diff] [blame] | 146 | .. note:: |
| 147 | |
Anton Komlev | 8150642 | 2022-02-15 21:53:13 +0000 | [diff] [blame^] | 148 | 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 Komlev | c52e2d9 | 2021-11-25 17:20:09 +0000 | [diff] [blame] | 151 | |
Summer Qin | 6d5c91c | 2021-05-24 15:32:44 +0800 | [diff] [blame] | 152 | - 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 | ############################# |
| 203 | Build AN521 regression sample |
| 204 | ############################# |
| 205 | |
| 206 | Here, we take building TF-M for AN521 platform with regression tests using GCC |
| 207 | as 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 Komlev | 8150642 | 2022-02-15 21:53:13 +0000 | [diff] [blame^] | 247 | |
| 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 Qin | 6d5c91c | 2021-05-24 15:32:44 +0800 | [diff] [blame] | 261 | ########################### |
| 262 | Run AN521 regression sample |
| 263 | ########################### |
| 264 | |
| 265 | Run the sample code on SSE-200 Fast-Model, using FVP_MPS2_AEMv8M provided by |
| 266 | Arm 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 | |
| 327 | After completing the procedure you should see the following messages on the |
| 328 | DAPLink 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 | ########################## |
| 360 | Tool & Dependency overview |
| 361 | ########################## |
| 362 | |
| 363 | To build the TF-M firmware the following tools are needed: |
| 364 | |
Anton Komlev | 4c436bf | 2021-10-18 21:59:55 +0100 | [diff] [blame] | 365 | - 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 Qin | 6d5c91c | 2021-05-24 15:32:44 +0800 | [diff] [blame] | 371 | |
Anton Komlev | 4c436bf | 2021-10-18 21:59:55 +0100 | [diff] [blame] | 372 | Dependency chain |
| 373 | ---------------- |
Summer Qin | 6d5c91c | 2021-05-24 15:32:44 +0800 | [diff] [blame] | 374 | |
| 375 | .. uml:: |
| 376 | |
| 377 | @startuml |
| 378 | skinparam state { |
| 379 | BackgroundColor #92AEE0 |
| 380 | FontColor black |
| 381 | FontSize 16 |
| 382 | AttributeFontColor black |
| 383 | AttributeFontSize 16 |
Summer Qin | 6d5c91c | 2021-05-24 15:32:44 +0800 | [diff] [blame] | 384 | } |
| 385 | state fw as "Firmware" : TF-M binary |
| 386 | state c_comp as "C Compiler" : C99 |
Anton Komlev | 4c436bf | 2021-10-18 21:59:55 +0100 | [diff] [blame] | 387 | state python as "Python" : v3.x |
Summer Qin | 6d5c91c | 2021-05-24 15:32:44 +0800 | [diff] [blame] | 388 | |
Summer Qin | 6d5c91c | 2021-05-24 15:32:44 +0800 | [diff] [blame] | 389 | fw --> c_comp |
| 390 | fw --> CMake |
| 391 | CMake --> gmake |
Anton Komlev | 4c436bf | 2021-10-18 21:59:55 +0100 | [diff] [blame] | 392 | CMake --> Ninja |
Summer Qin | 6d5c91c | 2021-05-24 15:32:44 +0800 | [diff] [blame] | 393 | fw --> cryptography |
| 394 | fw --> pyasn1 |
| 395 | fw --> yaml |
| 396 | fw --> jinja2 |
Ross Burton | 5ba8239 | 2021-11-10 16:56:10 +0000 | [diff] [blame] | 397 | fw --> cbor2 |
Summer Qin | 6d5c91c | 2021-05-24 15:32:44 +0800 | [diff] [blame] | 398 | fw --> click |
| 399 | fw --> imgtool |
Anton Komlev | 4c436bf | 2021-10-18 21:59:55 +0100 | [diff] [blame] | 400 | c_comp --> GCC |
| 401 | c_comp --> CLANG |
| 402 | c_comp --> IAR |
| 403 | cryptography --> python |
| 404 | pyasn1 --> python |
| 405 | yaml --> python |
| 406 | jinja2 --> python |
Ross Burton | 5ba8239 | 2021-11-10 16:56:10 +0000 | [diff] [blame] | 407 | cbor2 --> python |
Anton Komlev | 4c436bf | 2021-10-18 21:59:55 +0100 | [diff] [blame] | 408 | click --> python |
| 409 | imgtool --> python |
Summer Qin | 6d5c91c | 2021-05-24 15:32:44 +0800 | [diff] [blame] | 410 | @enduml |
| 411 | |
| 412 | ########## |
| 413 | Next steps |
| 414 | ########## |
| 415 | |
| 416 | Here are some next steps for exploring TF-M: |
| 417 | |
| 418 | - Detailed :doc:`Build instructions </docs/technical_references/instructions/tfm_build_instruction>`. |
| 419 | - :doc:`IAR Build instructions </docs/technical_references/instructions/tfm_build_instruction_iar>`. |
| 420 | - Try other :doc:`Samples and Demos </docs/technical_references/instructions/run_tfm_examples_on_arm_platforms>`. |
| 421 | - :doc:`Documentation generation </docs/technical_references/instructions/documentation_generation>`. |
| 422 | |
| 423 | -------------- |
| 424 | |
David Hu | 3aca3ed | 2022-01-12 20:58:05 +0800 | [diff] [blame] | 425 | *Copyright (c) 2017-2022, Arm Limited. All rights reserved.* |