Galanakis, Minos | 41f8597 | 2019-09-30 15:56:40 +0100 | [diff] [blame] | 1 | ########### |
| 2 | Secure boot |
| 3 | ########### |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 4 | For secure devices it is security critical to enforce firmware authenticity to |
| 5 | protect against execution of malicious software. This is implemented by building |
| 6 | a trust chain where each step in the execution chain authenticates the next |
| 7 | step before execution. The chain of trust in based on a "Root of Trust" which |
| 8 | is implemented using asymmetric cryptography. The Root of Trust is a combination |
| 9 | of an immutable bootloader and a public key (ROTPK). |
| 10 | |
Tamas Ban | 07a11a2 | 2019-09-23 13:54:15 +0100 | [diff] [blame] | 11 | .. Warning:: |
| 12 | In order to implement a proper chain of trust functionality, it is |
| 13 | mandatory that the first stage bootloader and ROTPK is stored in an |
| 14 | **immutable** way. To achieve this the bootloader code must be stored and |
| 15 | executed from ROM or such part of flash memory which supports write |
| 16 | protection. ROTPK can be stored in a one-time-programmable (OTP) memory. If |
| 17 | the SoC has a built-in BL1 (immutable) bootloader and the immutability of |
| 18 | TF-M secure boot code is not guaranteed then TF-M secure boot code must be |
| 19 | authenticated by BL1 bootloader before execution. If immutability of root |
| 20 | of trust (first stage bootloader + ROTPK) is not ensured then there is a |
| 21 | risk that the secure boot process could be bypassed, which could lead to |
| 22 | arbitrary code execution on the device. Current TF-M secure boot code is |
| 23 | intended to be a second stage bootloader, therefore it requires |
| 24 | authentication before execution. If TF-M secure boot code is used as a first |
| 25 | stage bootloader then it must be stored according to the above requirements. |
| 26 | |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 27 | ******************************* |
| 28 | Second stage bootloader in TF-M |
| 29 | ******************************* |
Balint Matyi | 69e2d2e | 2020-07-08 10:53:54 +0100 | [diff] [blame] | 30 | By default, the MCUboot project from |
Tamas Ban | c5b2f2b | 2020-11-12 09:47:05 +0000 | [diff] [blame] | 31 | `GitHub <https://github.com/mcu-tools/mcuboot>`__ is used as the secure |
Balint Matyi | 69e2d2e | 2020-07-08 10:53:54 +0100 | [diff] [blame] | 32 | bootloader in TF-M. The repository is going to be automatically downloaded by |
| 33 | CMake. The version downloaded can be controlled by the ``MCUBOOT_VERSION`` |
| 34 | CMake variable. If you wish to use a locally downloaded copy, the CMake variable |
| 35 | ``MCUBOOT_PATH`` can be set to its location. This document contains information |
| 36 | about how MCUboot has been integrated to TF-M. For further information about |
| 37 | MCUboot design please refer to the `MCUBoot homepage <https://www.mcuboot.com/>`__. |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 38 | |
| 39 | Bootloader is started when CPU is released from reset. It runs in secure mode. |
| 40 | It authenticates the firmware image by hash (SHA-256) and digital signature |
David Vincze | 9c60901 | 2019-08-22 13:37:21 +0200 | [diff] [blame] | 41 | (RSA-3072) validation. Public key, that the checks happens against, can be built |
| 42 | into the bootloader image or can be provisioned to the SoC during manufacturing. |
| 43 | Metadata of the image is delivered together with the image itself in a header |
| 44 | and trailer section. In case of successful authentication, bootloader passes |
| 45 | execution to the secure image. Execution never returns to bootloader until |
| 46 | next reset. |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 47 | |
| 48 | A default RSA key pair is stored in the repository, public key is in ``keys.c`` |
Anton Komlev | b8e3af0 | 2020-08-28 10:23:57 +0100 | [diff] [blame] | 49 | and private key is in ``root-RSA-3072.pem``. |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 50 | |
David Vincze | 8a2a4e2 | 2019-05-24 10:14:23 +0200 | [diff] [blame] | 51 | .. Warning:: |
| 52 | DO NOT use them in production code, they are exclusively for testing! |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 53 | |
Balint Matyi | 69e2d2e | 2020-07-08 10:53:54 +0100 | [diff] [blame] | 54 | The private key must be stored in a safe place outside of the repository. |
| 55 | ``imgtool.py`` (found in the ``scripts`` directory in the MCUBoot repository, |
| 56 | or installed through the pip package manager) can be used to generate new key |
| 57 | pairs. |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 58 | |
David Vincze | 9c60901 | 2019-08-22 13:37:21 +0200 | [diff] [blame] | 59 | The bootloader can handle the secure and non-secure images independently |
| 60 | (multiple image boot) or together (single image boot). In case of multiple image |
| 61 | boot they are signed independently with different keys and they can be updated |
| 62 | separately. In case of single image boot the secure and non-secure image is |
| 63 | handled as a single blob, therefore they must be contiguous in the device |
| 64 | memory. In this case they are signed together and also they can be updated only |
| 65 | together. In order to have the same artefacts at the end of the build regardless |
| 66 | of how the images are handled (independently or together) the images are always |
| 67 | concatenated. In case of single image boot they are concatenated first and then |
| 68 | signed. In case of multiple image boot they are separately signed first and then |
| 69 | concatenated. Preparation of payload is done by Python scripts: |
| 70 | ``bl2/ext/mcuboot/scripts/``. At the end of a successful build the signed TF-M |
Anton Komlev | b8e3af0 | 2020-08-28 10:23:57 +0100 | [diff] [blame] | 71 | payload can be found in: ``<build_dir>/bin/tfm_s_ns_signed.bin`` |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 72 | |
| 73 | ********************* |
| 74 | Integration with TF-M |
| 75 | ********************* |
| 76 | MCUBoot assumes a predefined memory layout which is described below (applicable |
David Vincze | 8bdfc2d | 2019-03-18 15:49:23 +0100 | [diff] [blame] | 77 | for AN521). It is mandatory to define the primary slot and the secondary slot |
David Vincze | 9c60901 | 2019-08-22 13:37:21 +0200 | [diff] [blame] | 78 | partitions, but their size and location can be changed:: |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 79 | |
| 80 | - 0x0000_0000 - 0x0007_FFFF: BL2 bootloader - MCUBoot |
David Vincze | 8bdfc2d | 2019-03-18 15:49:23 +0100 | [diff] [blame] | 81 | - 0x0008_0000 - 0x000F_FFFF: Primary slot : Single binary blob: |
| 82 | Secure + Non-Secure image; |
| 83 | Primary memory partition |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 84 | - 0x0008_0000 - 0x0008_03FF: Common image header |
| 85 | - 0x0008_0400 - 0x0008_xxxx: Secure image |
| 86 | - 0x0008_xxxx - 0x0010_03FF: Padding (with 0xFF) |
| 87 | - 0x0010_0400 - 0x0010_xxxx: Non-secure image |
David Vincze | 9c60901 | 2019-08-22 13:37:21 +0200 | [diff] [blame] | 88 | - 0x0010_xxxx - 0x0010_xxxx: Hash value(SHA256), RSA signature and other |
| 89 | metadata of combined image |
David Vincze | 8a2a4e2 | 2019-05-24 10:14:23 +0200 | [diff] [blame] | 90 | |
David Vincze | 8bdfc2d | 2019-03-18 15:49:23 +0100 | [diff] [blame] | 91 | - 0x0018_0000 - 0x0027_FFFF: Secondary slot : Secure + Non-Secure image; |
| 92 | Secondary memory partition, structured |
| 93 | identically to the primary slot |
David Vincze | 9c60901 | 2019-08-22 13:37:21 +0200 | [diff] [blame] | 94 | - 0x0028_0000 - 0x0037_FFFF: Scratch area, only used during image |
| 95 | swapping |
| 96 | |
| 97 | Multiple image boot requires a slightly different layout:: |
| 98 | |
| 99 | - 0x0000_0000 - 0x0007_FFFF: BL2 bootloader - MCUBoot |
| 100 | - 0x0008_0000 - 0x000F_FFFF: Primary slot : Secure image |
| 101 | - 0x0008_0000 - 0x0008_03FF: Secure image header |
| 102 | - 0x0008_0400 - 0x000x_xxxx: Secure image |
| 103 | - 0x000x_xxxx - 0x000x_xxxx: Hash value(SHA256), RSA signature and other |
| 104 | metadata of secure image |
| 105 | |
| 106 | - 0x0010_0000 - 0x0017_FFFF: Primary slot : Non-secure image |
| 107 | - 0x0010_0000 - 0x0010_03FF: Non-secure image header |
| 108 | - 0x0010_0400 - 0x001x_xxxx: Non-secure image |
| 109 | - 0x001x_xxxx - 0x001x_xxxx: Hash value(SHA256), RSA signature and other |
| 110 | metadata of non-secure image |
| 111 | |
| 112 | - 0x0018_0000 - 0x001F_FFFF: Secondary slot : Secure image |
| 113 | - 0x0020_0000 - 0x0027_FFFF: Secondary slot : Non-secure image |
| 114 | |
| 115 | - 0x0028_0000 - 0x002F_FFFF: Scratch area, only used during image |
| 116 | swapping, used for secure and non-secure |
| 117 | image as well |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 118 | |
| 119 | ************************** |
| 120 | Firmware upgrade operation |
| 121 | ************************** |
| 122 | MCUBoot handles only the firmware authenticity check after start-up and the |
| 123 | firmware switch part of the firmware update process. Downloading the new version |
David Vincze | 8a2a4e2 | 2019-05-24 10:14:23 +0200 | [diff] [blame] | 124 | of the firmware is out-of-scope for MCUBoot. MCUBoot supports three different |
| 125 | ways to switch to the new firmware and it is assumed that firmware images are |
| 126 | executed-in-place (XIP). The default behaviour is the overwrite-based image |
David Vincze | 8bdfc2d | 2019-03-18 15:49:23 +0100 | [diff] [blame] | 127 | upgrade. In this case the active firmware is always executed from the primary |
| 128 | slot and the secondary slot is a staging area for new images. Before executing |
| 129 | the new firmware image, the content of the primary slot must be overwritten with |
| 130 | the content of the secondary slot (the new firmware image). The second option is |
| 131 | the image swapping strategy when the content of the two memory slots must be |
| 132 | physically swapped. This needs the scratch area to be defined in the memory |
Tamas Ban | 0bd0dfc | 2020-09-11 15:25:48 +0100 | [diff] [blame] | 133 | layout. The third option is the direct execute-in-place version, which |
| 134 | eliminates the complexity of image swapping and its administration. Active image |
| 135 | can be executed from either memory slot, but new firmware must be linked to the |
| 136 | address space of the proper (currently inactive) memory slot. |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 137 | |
David Vincze | 8a2a4e2 | 2019-05-24 10:14:23 +0200 | [diff] [blame] | 138 | Overwrite operation |
Tamas Ban | e7efdc6 | 2019-06-05 13:14:52 +0100 | [diff] [blame] | 139 | =================== |
David Vincze | 8bdfc2d | 2019-03-18 15:49:23 +0100 | [diff] [blame] | 140 | Active image is stored in the primary slot, and this image is started always by |
| 141 | the bootloader. Therefore images must be linked to the primary slot. If the |
| 142 | bootloader finds a valid image in the secondary slot, which is marked for |
| 143 | upgrade, then the content of the primary slot will be simply overwritten with |
| 144 | the content of the secondary slot, before starting the new image from the |
| 145 | primary slot. After the content of the primary slot has been successfully |
| 146 | overwritten, the header and trailer of the new image in the secondary slot is |
David Vincze | 9c60901 | 2019-08-22 13:37:21 +0200 | [diff] [blame] | 147 | erased to prevent the triggering of another unnecessary image upgrade after a |
David Vincze | 8bdfc2d | 2019-03-18 15:49:23 +0100 | [diff] [blame] | 148 | restart. The overwrite operation is fail-safe and resistant to power-cut |
| 149 | failures. For more details please refer to the MCUBoot |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 150 | `documentation <https://www.mcuboot.com/mcuboot/design.html>`__. |
| 151 | |
David Vincze | 8a2a4e2 | 2019-05-24 10:14:23 +0200 | [diff] [blame] | 152 | Swapping operation |
| 153 | ================== |
| 154 | This operation can be set with the ``MCUBOOT_UPGRADE_STRATEGY`` compile time |
| 155 | switch (see `Build time configuration`_). With swapping image upgrade strategy |
David Vincze | 8bdfc2d | 2019-03-18 15:49:23 +0100 | [diff] [blame] | 156 | the active image is also stored in the primary slot and it will always be |
| 157 | started by the bootloader. If the bootloader finds a valid image in the |
| 158 | secondary slot, which is marked for upgrade, then contents of the primary slot |
| 159 | and the secondary slot will be swapped, before starting the new image from the |
| 160 | primary slot. Scratch area is used as a temporary storage place during image |
| 161 | swapping. Update mark from the secondary slot is removed when the swapping is |
David Vincze | 8a2a4e2 | 2019-05-24 10:14:23 +0200 | [diff] [blame] | 162 | successful. The boot loader can revert the swapping as a fall-back mechanism to |
| 163 | recover the previous working firmware version after a faulty update. The swap |
| 164 | operation is fail-safe and resistant to power-cut failures. For more details |
| 165 | please refer to the MCUBoot |
| 166 | `documentation <https://www.mcuboot.com/mcuboot/design.html>`__. |
| 167 | |
| 168 | .. Note:: |
| 169 | |
| 170 | After a successful image upgrade the firmware can mark itself as "OK" at |
| 171 | runtime by setting the image_ok flag in the flash. When this happens, the |
| 172 | swap is made "permanent" and MCUBoot will then still choose to run it |
| 173 | during the next boot. Currently TF-M does not set the image_ok flag, |
| 174 | therefore the bootloader will always perform a "revert" (swap the images |
| 175 | back) during the next boot. |
| 176 | |
Tamas Ban | 0bd0dfc | 2020-09-11 15:25:48 +0100 | [diff] [blame] | 177 | Direct execute-in-place operation |
| 178 | ================================= |
David Vincze | 8a2a4e2 | 2019-05-24 10:14:23 +0200 | [diff] [blame] | 179 | This operation can be set with the ``MCUBOOT_UPGRADE_STRATEGY`` compile time |
Tamas Ban | 0bd0dfc | 2020-09-11 15:25:48 +0100 | [diff] [blame] | 180 | switch (see `Build time configuration`_). When enabling direct-xip operation |
David Vincze | 8a2a4e2 | 2019-05-24 10:14:23 +0200 | [diff] [blame] | 181 | then the active image flag is moved between slots during firmware upgrade. If |
| 182 | firmware is executed-in-place (XIP), then two firmware images must be generated. |
David Vincze | 8bdfc2d | 2019-03-18 15:49:23 +0100 | [diff] [blame] | 183 | One of them is linked to be executed from the primary slot memory region and the |
| 184 | other from the secondary slot. The firmware upgrade client, which downloads the |
| 185 | new image, must be aware, which slot hosts the active firmware and which acts as |
| 186 | a staging area and it is responsible for downloading the proper firmware image. |
| 187 | At boot time MCUBoot inspects the version number in the image header and passes |
| 188 | execution to the newer firmware version. New image must be marked for upgrade |
| 189 | which is automatically done by Python scripts at compile time. Image |
| 190 | verification is done the same way in all operational modes. If new image fails |
| 191 | during authentication then MCUBoot erases the memory slot and starts the other |
| 192 | image, after successful authentication. |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 193 | |
Anton Komlev | b8e3af0 | 2020-08-28 10:23:57 +0100 | [diff] [blame] | 194 | To select which slot the image is to be executed from, set |
| 195 | ``MCUBOOT_EXECUTION_SLOT`` to the desired index. It is suggested that you create |
| 196 | two build directories when building images using this mode, as intermediate |
| 197 | dependencies cannot be reused due to changes in the flash layout. |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 198 | |
David Vincze | 9c60901 | 2019-08-22 13:37:21 +0200 | [diff] [blame] | 199 | .. Note:: |
| 200 | |
Tamas Ban | 0bd0dfc | 2020-09-11 15:25:48 +0100 | [diff] [blame] | 201 | Only single image boot is supported with direct-xip upgrade mode. |
David Vincze | 9c60901 | 2019-08-22 13:37:21 +0200 | [diff] [blame] | 202 | |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 203 | RAM Loading firmware upgrade |
| 204 | ============================ |
David Vincze | 8a2a4e2 | 2019-05-24 10:14:23 +0200 | [diff] [blame] | 205 | Musca-A supports an image upgrade mode that is separate to the other (overwrite, |
Tamas Ban | f4023f3 | 2020-09-16 11:02:52 +0100 | [diff] [blame] | 206 | swapping and dirext-xip) modes. This is the ``RAM load`` mode (please refer |
Tamas Ban | 0bd0dfc | 2020-09-11 15:25:48 +0100 | [diff] [blame] | 207 | to the table below). Like the direct-xip mode, this selects the newest image |
David Vincze | 8a2a4e2 | 2019-05-24 10:14:23 +0200 | [diff] [blame] | 208 | by reading the image version numbers in the image headers, but instead of |
| 209 | executing it in place, the newest image is copied to RAM for execution. The load |
| 210 | address, the location in RAM where the image is copied to, is stored in the |
| 211 | image header. |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 212 | |
David Vincze | 9c60901 | 2019-08-22 13:37:21 +0200 | [diff] [blame] | 213 | .. Note:: |
| 214 | |
Tamas Ban | f4023f3 | 2020-09-16 11:02:52 +0100 | [diff] [blame] | 215 | Only single image boot is supported with ``RAM load`` upgrade mode. |
David Vincze | 9c60901 | 2019-08-22 13:37:21 +0200 | [diff] [blame] | 216 | |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 217 | Summary of different modes for image upgrade |
| 218 | ============================================ |
| 219 | Different implementations of the image upgrade operation (whether through |
Tamas Ban | 0bd0dfc | 2020-09-11 15:25:48 +0100 | [diff] [blame] | 220 | overwriting, swapping, direct-xip or loading into RAM and executing from |
David Vincze | 8a2a4e2 | 2019-05-24 10:14:23 +0200 | [diff] [blame] | 221 | there) are supported by the platforms. The table below shows which of these |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 222 | modes are supported by which platforms: |
| 223 | |
Tamas Ban | f4023f3 | 2020-09-16 11:02:52 +0100 | [diff] [blame] | 224 | +---------------------+-----------------+----------------------------------------------------------+ |
| 225 | | | Without BL2 [1]_| With BL2 [2]_ | |
| 226 | +=====================+=================+===============+==========+================+==============+ |
| 227 | | | XIP | XIP | XIP | XIP | Not XIP | |
| 228 | +---------------------+-----------------+---------------+----------+----------------+--------------+ |
| 229 | | | | Overwrite [3]_| Swap [4]_| direct-xip [5]_| RAM load [6]_| |
| 230 | +---------------------+-----------------+---------------+----------+----------------+--------------+ |
| 231 | | AN521 | Yes | Yes | Yes | Yes | No | |
| 232 | +---------------------+-----------------+---------------+----------+----------------+--------------+ |
| 233 | | AN519 | Yes | Yes | Yes | Yes | No | |
| 234 | +---------------------+-----------------+---------------+----------+----------------+--------------+ |
| 235 | | AN539 | Yes | Yes | Yes | Yes | No | |
| 236 | +---------------------+-----------------+---------------+----------+----------------+--------------+ |
David Vincze | abe6b29 | 2020-10-27 12:12:12 +0100 | [diff] [blame] | 237 | | FVP_SSE300_MPS2 | No | Yes | Yes | Yes | No | |
Tamas Ban | f4023f3 | 2020-09-16 11:02:52 +0100 | [diff] [blame] | 238 | +---------------------+-----------------+---------------+----------+----------------+--------------+ |
Marton Berke | 8c2f524 | 2020-07-28 14:52:29 +0200 | [diff] [blame] | 239 | | FVP_SSE300_MPS3 | No | Yes | Yes | Yes | No | |
| 240 | +---------------------+-----------------+---------------+----------+----------------+--------------+ |
David Vincze | abe6b29 | 2020-10-27 12:12:12 +0100 | [diff] [blame] | 241 | | LPC55S69 | Yes | Yes | No | Yes | No | |
Tamas Ban | f4023f3 | 2020-09-16 11:02:52 +0100 | [diff] [blame] | 242 | +---------------------+-----------------+---------------+----------+----------------+--------------+ |
| 243 | | Musca-A | No | No | No | No | Yes | |
| 244 | +---------------------+-----------------+---------------+----------+----------------+--------------+ |
| 245 | | Musca-B1 | Yes | Yes | Yes | Yes | No | |
| 246 | +---------------------+-----------------+---------------+----------+----------------+--------------+ |
| 247 | | Musca-S1 | Yes | Yes | Yes | Yes | No | |
| 248 | +---------------------+-----------------+---------------+----------+----------------+--------------+ |
| 249 | | AN524 | Yes | No | No | Yes | No | |
| 250 | +---------------------+-----------------+---------------+----------+----------------+--------------+ |
| 251 | | PSoC64 | Yes | No | No | No | No | |
| 252 | +---------------------+-----------------+---------------+----------+----------------+--------------+ |
| 253 | | SSE-200_AWS | Yes | Yes | Yes | Yes | No | |
| 254 | +---------------------+-----------------+---------------+----------+----------------+--------------+ |
| 255 | | STM_DISCO_L562QE | No | Yes | No | No | No | |
| 256 | +---------------------+-----------------+---------------+----------+----------------+--------------+ |
| 257 | | STM_NUCLEO_L552ZE_Q | No | Yes | No | No | No | |
| 258 | +---------------------+-----------------+---------------+----------+----------------+--------------+ |
Øyvind Rønningstad | ba9aac0 | 2020-09-14 15:19:28 +0200 | [diff] [blame] | 259 | | nRF9160 DK | Yes | Yes | No | No | No | |
| 260 | +---------------------+-----------------+---------------+----------+----------------+--------------+ |
Andrzej Głąbek | bb4d5c5 | 2020-11-03 10:08:48 +0100 | [diff] [blame] | 261 | | nRF5340 PDK/DK | Yes | Yes | No | No | No | |
Øyvind Rønningstad | ba9aac0 | 2020-09-14 15:19:28 +0200 | [diff] [blame] | 262 | +---------------------+-----------------+---------------+----------+----------------+--------------+ |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 263 | |
Anton Komlev | b8e3af0 | 2020-08-28 10:23:57 +0100 | [diff] [blame] | 264 | .. [1] To disable BL2, please set the ``BL2`` cmake option to ``OFF`` |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 265 | |
| 266 | .. [2] BL2 is enabled by default |
| 267 | |
David Vincze | 8a2a4e2 | 2019-05-24 10:14:23 +0200 | [diff] [blame] | 268 | .. [3] The image executes in-place (XIP) and is in Overwrite mode for image |
| 269 | update by default |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 270 | |
David Vincze | 8a2a4e2 | 2019-05-24 10:14:23 +0200 | [diff] [blame] | 271 | .. [4] To enable XIP Swap mode, assign the "SWAP" string to the |
David Vincze | 9c60901 | 2019-08-22 13:37:21 +0200 | [diff] [blame] | 272 | ``MCUBOOT_UPGRADE_STRATEGY`` configuration variable in the build |
David Vincze | 8a2a4e2 | 2019-05-24 10:14:23 +0200 | [diff] [blame] | 273 | configuration file, or include this macro definition in the command line |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 274 | |
Tamas Ban | 0bd0dfc | 2020-09-11 15:25:48 +0100 | [diff] [blame] | 275 | .. [5] To enable direct-xip, assign the "DIRECT_XIP" string to the |
David Vincze | 9c60901 | 2019-08-22 13:37:21 +0200 | [diff] [blame] | 276 | ``MCUBOOT_UPGRADE_STRATEGY`` configuration variable in the build |
David Vincze | 8a2a4e2 | 2019-05-24 10:14:23 +0200 | [diff] [blame] | 277 | configuration file, or include this macro definition in the command line |
| 278 | |
Tamas Ban | f4023f3 | 2020-09-16 11:02:52 +0100 | [diff] [blame] | 279 | .. [6] To enable RAM load, assign the "RAM_LOAD" string to the |
David Vincze | 9c60901 | 2019-08-22 13:37:21 +0200 | [diff] [blame] | 280 | ``MCUBOOT_UPGRADE_STRATEGY`` configuration variable in the build |
David Vincze | 8a2a4e2 | 2019-05-24 10:14:23 +0200 | [diff] [blame] | 281 | configuration file, or include this macro definition in the command line |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 282 | |
David Vincze | 9c60901 | 2019-08-22 13:37:21 +0200 | [diff] [blame] | 283 | ******************* |
| 284 | Multiple image boot |
| 285 | ******************* |
| 286 | It is possible to update the firmware images independently to support the |
| 287 | scenario when secure and non-secure images are provided by different vendors. |
| 288 | Multiple image boot is supported only together with the overwrite and swap |
| 289 | firmware upgrade modes. |
| 290 | |
| 291 | It is possible to describe the dependencies of the images on each other in |
| 292 | order to avoid a faulty upgrade when incompatible versions would be installed. |
| 293 | These dependencies are part of the image manifest area. |
| 294 | The dependencies are composed from two parts: |
| 295 | |
| 296 | - **Image identifier:** The number of the image which the current image (whose |
| 297 | manifest area contains the dependency entry) depends on. The image identifier |
| 298 | starts from 0. |
| 299 | |
| 300 | - **Minimum version:** The minimum version of other image must be present on |
| 301 | the device by the end of the upgrade (both images might be updated at the |
| 302 | same time). |
| 303 | |
| 304 | Dependencies can be added to the images at compile time with the following |
| 305 | compile time switches: |
| 306 | |
Anton Komlev | b8e3af0 | 2020-08-28 10:23:57 +0100 | [diff] [blame] | 307 | - ``MCUBOOT_S_IMAGE_MIN_VER`` It is added to the non-secure image and specifies the |
David Vincze | 9c60901 | 2019-08-22 13:37:21 +0200 | [diff] [blame] | 308 | minimum required version of the secure image. |
Anton Komlev | b8e3af0 | 2020-08-28 10:23:57 +0100 | [diff] [blame] | 309 | - ``MCUBOOT_NS_IMAGE_MIN_VER`` It is added to the secure image and specifies the |
David Vincze | 9c60901 | 2019-08-22 13:37:21 +0200 | [diff] [blame] | 310 | minimum required version of the non-secure image. |
| 311 | |
| 312 | Example of how to provide the secure image minimum version:: |
| 313 | |
Gabor Abonyi | 944e9c2 | 2020-10-01 16:18:41 +0200 | [diff] [blame] | 314 | cmake -DTFM_PLATFORM=musca_b1/sse_200 -DTFM_TOOLCHAIN_FILE=../toolchain_GNUARM.cmake -DMCUBOOT_S_IMAGE_MIN_VER=1.2.3+4 .. |
David Vincze | 9c60901 | 2019-08-22 13:37:21 +0200 | [diff] [blame] | 315 | |
Tamas Ban | 7801ed4 | 2019-05-20 13:21:53 +0100 | [diff] [blame] | 316 | ******************** |
| 317 | Signature algorithms |
| 318 | ******************** |
| 319 | MbedTLS library is used to sign the images. The list of supported signing |
| 320 | algorithms: |
Tamas Ban | e7efdc6 | 2019-06-05 13:14:52 +0100 | [diff] [blame] | 321 | |
| 322 | - `RSA-2048` |
| 323 | - `RSA-3072`: default |
| 324 | |
David Vincze | 9c60901 | 2019-08-22 13:37:21 +0200 | [diff] [blame] | 325 | Example keys stored in: |
| 326 | |
Anton Komlev | b8e3af0 | 2020-08-28 10:23:57 +0100 | [diff] [blame] | 327 | - ``root-RSA-2048.pem`` : Used to sign single image (S+NS) or secure image |
David Vincze | 9c60901 | 2019-08-22 13:37:21 +0200 | [diff] [blame] | 328 | in case of multiple image boot |
Anton Komlev | b8e3af0 | 2020-08-28 10:23:57 +0100 | [diff] [blame] | 329 | - ``root-RSA-2048_1.pem`` : Used to sign non-secure image in case of multiple |
David Vincze | 9c60901 | 2019-08-22 13:37:21 +0200 | [diff] [blame] | 330 | image boot |
Anton Komlev | b8e3af0 | 2020-08-28 10:23:57 +0100 | [diff] [blame] | 331 | - ``root-RSA-3072.pem`` : Used to sign single image (S+NS) or secure image |
David Vincze | 9c60901 | 2019-08-22 13:37:21 +0200 | [diff] [blame] | 332 | in case of multiple image boot |
Anton Komlev | b8e3af0 | 2020-08-28 10:23:57 +0100 | [diff] [blame] | 333 | - ``root-RSA-3072_1.pem`` : Used to sign non-secure image in case of multiple |
David Vincze | 9c60901 | 2019-08-22 13:37:21 +0200 | [diff] [blame] | 334 | image boot |
Tamas Ban | 7801ed4 | 2019-05-20 13:21:53 +0100 | [diff] [blame] | 335 | |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 336 | ************************ |
| 337 | Build time configuration |
| 338 | ************************ |
Anton Komlev | b8e3af0 | 2020-08-28 10:23:57 +0100 | [diff] [blame] | 339 | MCUBoot related compile time switches can be set by cmake variables. |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 340 | |
| 341 | - BL2 (default: True): |
| 342 | - **True:** TF-M built together with bootloader. MCUBoot is executed after |
| 343 | reset and it authenticates TF-M and starts secure code. |
| 344 | - **False:** TF-M built without bootloader. Secure image linked to the |
| 345 | beginning of the device memory and executed after reset. If it is false |
David Vincze | 9c60901 | 2019-08-22 13:37:21 +0200 | [diff] [blame] | 346 | then using any of the further compile time switches is invalid. |
David Vincze | 8a2a4e2 | 2019-05-24 10:14:23 +0200 | [diff] [blame] | 347 | - MCUBOOT_UPGRADE_STRATEGY (default: "OVERWRITE_ONLY"): |
| 348 | - **"OVERWRITE_ONLY":** Default firmware upgrade operation with overwrite. |
| 349 | - **"SWAP":** Activate swapping firmware upgrade operation. |
Tamas Ban | 0bd0dfc | 2020-09-11 15:25:48 +0100 | [diff] [blame] | 350 | - **"DIRECT_XIP":** Activate direct execute-in-place firmware upgrade |
| 351 | operation. |
Tamas Ban | f4023f3 | 2020-09-16 11:02:52 +0100 | [diff] [blame] | 352 | - **"RAM_LOAD":** Activate RAM loading firmware upgrade operation, where |
David Vincze | 9c60901 | 2019-08-22 13:37:21 +0200 | [diff] [blame] | 353 | the latest image is copied to RAM and runs from there instead of being |
David Vincze | 8a2a4e2 | 2019-05-24 10:14:23 +0200 | [diff] [blame] | 354 | executed in-place. |
Anton Komlev | b8e3af0 | 2020-08-28 10:23:57 +0100 | [diff] [blame] | 355 | - MCUBOOT_SIGNATURE_TYPE (default: RSA): |
| 356 | - **RSA:** Image is signed with RSA algorithm |
| 357 | - MCUBOOT_SIGNATURE_KEY_LEN (default: 3072): |
| 358 | - **2048:** Image is signed with 2048 bit key. |
| 359 | - **3072:** Image is signed with 3072 bit key. |
David Vincze | 9c60901 | 2019-08-22 13:37:21 +0200 | [diff] [blame] | 360 | - MCUBOOT_IMAGE_NUMBER (default: 2): |
| 361 | - **1:** Single image boot, secure and non-secure images are signed and |
| 362 | updated together. |
| 363 | - **2:** Multiple image boot, secure and non-secure images are signed and |
| 364 | updatable independently. |
| 365 | - MCUBOOT_HW_KEY (default: True): |
| 366 | - **True:** The hash of public key is provisioned to the SoC and the image |
Anton Komlev | b8e3af0 | 2020-08-28 10:23:57 +0100 | [diff] [blame] | 367 | manifest contains the whole public key (imgtool uses |
| 368 | ``--public_key_format=full``). MCUBoot validates the key before using it |
| 369 | for firmware authentication, it calculates the hash of public key from the |
| 370 | manifest and compare against the retrieved key-hash from the hardware. |
| 371 | This way MCUBoot is independent from the public key(s). Key(s) can be |
| 372 | provisioned any time and by different parties. |
David Vincze | 9c60901 | 2019-08-22 13:37:21 +0200 | [diff] [blame] | 373 | - **False:** The whole public key is embedded to the bootloader code and the |
Anton Komlev | b8e3af0 | 2020-08-28 10:23:57 +0100 | [diff] [blame] | 374 | image manifest contains only the hash of the public key (imgtool uses |
| 375 | ``--public_key_format=hash``). MCUBoot validates the key before using it |
| 376 | for firmware authentication, it calculates the hash of built-in public key |
| 377 | and compare against the retrieved key-hash from the image manifest. After |
| 378 | this the bootloader can verify that the image was signed with a private |
| 379 | key that corresponds to the retrieved key-hash (it can have more public |
| 380 | keys embedded in and it may have to look for the matching one). All the |
| 381 | public key(s) must be known at MCUBoot build time. |
David Vincze | 73dfbc5 | 2019-10-11 13:54:58 +0200 | [diff] [blame] | 382 | - MCUBOOT_LOG_LEVEL: |
| 383 | Can be used to configure the level of logging in MCUBoot. The possible |
| 384 | values are the following: |
| 385 | |
Tamas Ban | 98d16de | 2020-11-25 12:55:42 +0000 | [diff] [blame] | 386 | - **OFF** |
| 387 | - **ERROR** |
| 388 | - **WARNING** |
| 389 | - **INFO** |
| 390 | - **DEBUG** |
David Vincze | 73dfbc5 | 2019-10-11 13:54:58 +0200 | [diff] [blame] | 391 | |
| 392 | The logging in MCUBoot can be disabled and thus the code size can be reduced |
Tamas Ban | 98d16de | 2020-11-25 12:55:42 +0000 | [diff] [blame] | 393 | by setting it to ``OFF``. Its value depends on the build type. If the build |
| 394 | type is ``Debug`` then default value is ``INFO``. In case of different kinds |
| 395 | of ``Release`` builds the default value is ``OFF``. The default value can |
| 396 | be overridden through the command line or in the CMake GUI regardless of the |
| 397 | build type. |
Anton Komlev | b8e3af0 | 2020-08-28 10:23:57 +0100 | [diff] [blame] | 398 | - MCUBOOT_ENC_IMAGES (default: False): |
Balint Matyi | 5c47631 | 2020-03-31 13:15:39 +0100 | [diff] [blame] | 399 | - **True:** Adds encrypted image support in the source and encrypts the |
| 400 | resulting image using the ``enc-rsa2048-pub.pem`` key found in the MCUBoot |
| 401 | repository. |
| 402 | - **False:** Doesn't add encrypted image support and doesn't encrypt the |
| 403 | image. |
| 404 | |
Balint Matyi | fb7e60f | 2020-07-27 10:06:44 +0100 | [diff] [blame] | 405 | .. Note:: |
| 406 | The decryption takes place during the upgrade process, when the images |
| 407 | are being moved between the slots. This means that boards that don't |
| 408 | already have an image on them with MCUBoot that has been compiled with |
| 409 | ``MCUBOOT_ENCRYPT_RSA`` enabled need special treatment. In order to load |
| 410 | an encrypted image to such boards, an upgrade needs to be executed. This |
| 411 | can be done by using MCUBoot, putting an image in the secondary image |
| 412 | area, and setting ``MCUBOOT_ENCRYPT_RSA`` to ``ON``. When using the |
| 413 | ``OVERWRITE_ONLY`` upgrade strategy, this is enough. When using |
| 414 | ``SWAP``, an image is needed in the primary image area as well, to |
| 415 | trigger the update. |
| 416 | |
Balint Matyi | 5c47631 | 2020-03-31 13:15:39 +0100 | [diff] [blame] | 417 | .. Warning:: |
Balint Matyi | fb7e60f | 2020-07-27 10:06:44 +0100 | [diff] [blame] | 418 | DO NOT use the ``enc-rsa2048-pub.pem`` key in production code, it is |
| 419 | exclusively for testing! |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 420 | |
| 421 | Image versioning |
| 422 | ================ |
David Vincze | 9c60901 | 2019-08-22 13:37:21 +0200 | [diff] [blame] | 423 | An image version number is written to its header by one of the Python scripts, |
Tamas Ban | 0bd0dfc | 2020-09-11 15:25:48 +0100 | [diff] [blame] | 424 | and this number is used by the bootloader when the direct execute-in-place or |
| 425 | the RAM loading mode is enabled. It is also used in case of multiple image boot |
| 426 | when the bootloader checks the image dependencies if any have been added to the |
| 427 | images. |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 428 | |
David Vincze | 9c60901 | 2019-08-22 13:37:21 +0200 | [diff] [blame] | 429 | The version number of the image (single image boot) can manually be passed in |
| 430 | through the command line in the cmake configuration step:: |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 431 | |
Gabor Abonyi | 944e9c2 | 2020-10-01 16:18:41 +0200 | [diff] [blame] | 432 | cmake -DTFM_PLATFORM=musca_b1/sse_200 -DTFM_TOOLCHAIN_FILE=../toolchain_GNUARM.cmake -DIMAGE_VERSION_S=1.2.3+4 .. |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 433 | |
| 434 | Alternatively, the version number can be less specific (e.g 1, 1.2, or 1.2.3), |
| 435 | where the missing numbers are automatically set to zero. The image version |
| 436 | number argument is optional, and if it is left out, then the version numbers of |
| 437 | the image(s) being built in the same directory will automatically change. In |
| 438 | this case, the last component (the build number) automatically increments from |
| 439 | the previous one: 0.0.0+1 -> 0.0.0+2, for as many times as the build is re-ran, |
| 440 | **until a number is explicitly provided**. If automatic versioning is in place |
| 441 | and then an image version number is provided for the first time, the new number |
| 442 | will take precedence and be used instead. All subsequent image versions are |
| 443 | then set to the last number that has been specified, and the build number would |
| 444 | stop incrementing. Any new version numbers that are provided will overwrite |
| 445 | the previous one: 0.0.0+1 -> 0.0.0+2. Note: To re-apply automatic image |
| 446 | versioning, please start a clean build without specifying the image version |
David Vincze | 9c60901 | 2019-08-22 13:37:21 +0200 | [diff] [blame] | 447 | number at all. In case of multiple image boot there are separate compile time |
| 448 | switches for both images to provide their version: ``IMAGE_VERSION_S`` and |
Anton Komlev | b8e3af0 | 2020-08-28 10:23:57 +0100 | [diff] [blame] | 449 | ``IMAGE_VERSION_NS``. These must be used instead of ``IMAGE_VERSION_S``. |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 450 | |
David Vincze | 060968d | 2019-05-23 01:13:14 +0200 | [diff] [blame] | 451 | Security counter |
| 452 | ================ |
| 453 | Each signed image contains a security counter in its manifest. It is used by the |
| 454 | bootloader and its aim is to have an independent (from the image version) |
| 455 | counter to ensure rollback protection by comparing the new image's security |
| 456 | counter against the original (currently active) image's security counter during |
| 457 | the image upgrade process. It is added to the manifest (to the TLV area that is |
David Vincze | 9c60901 | 2019-08-22 13:37:21 +0200 | [diff] [blame] | 458 | appended to the end of the image) by one of the Python scripts when signing the |
David Vincze | 060968d | 2019-05-23 01:13:14 +0200 | [diff] [blame] | 459 | image. The value of the security counter is security critical data and it is in |
David Vincze | 9c60901 | 2019-08-22 13:37:21 +0200 | [diff] [blame] | 460 | the integrity protected part of the image. The last valid security counter |
| 461 | should always be stored in a non-volatile and trusted component of the device |
| 462 | and its value should always be increased if a security flaw was fixed in the |
| 463 | current image version. The value of the security counter (single image boot) can |
| 464 | be specified at build time in the cmake configuration step:: |
David Vincze | 060968d | 2019-05-23 01:13:14 +0200 | [diff] [blame] | 465 | |
Gabor Abonyi | 944e9c2 | 2020-10-01 16:18:41 +0200 | [diff] [blame] | 466 | cmake -DTFM_PLATFORM=musca_b1/sse_200 -DTFM_TOOLCHAIN_FILE=../toolchain_GNUARM.cmake -DSECURITY_COUNTER_S=42 ../ |
David Vincze | 060968d | 2019-05-23 01:13:14 +0200 | [diff] [blame] | 467 | |
| 468 | The security counter can be independent from the image version, but not |
| 469 | necessarily. Alternatively, if it is not specified at build time with the |
David Vincze | 9c60901 | 2019-08-22 13:37:21 +0200 | [diff] [blame] | 470 | ``SECURITY_COUNTER`` option the Python script will automatically generate it |
David Vincze | 060968d | 2019-05-23 01:13:14 +0200 | [diff] [blame] | 471 | from the image version number (not including the build number) and this value |
David Vincze | 9c60901 | 2019-08-22 13:37:21 +0200 | [diff] [blame] | 472 | will be added to the signed image. In case of multiple image boot there are |
| 473 | separate compile time switches for both images to provide their security counter |
| 474 | value: ``SECURITY_COUNTER_S`` and ``SECURITY_COUNTER_NS``. These must be used |
Anton Komlev | b8e3af0 | 2020-08-28 10:23:57 +0100 | [diff] [blame] | 475 | instead of ``SECURITY_COUNTER_S``. If these are not defined then the security |
David Vincze | 9c60901 | 2019-08-22 13:37:21 +0200 | [diff] [blame] | 476 | counter values will be derived from the corresponding image version similar to |
| 477 | the single image boot. |
| 478 | |
| 479 | *************************** |
| 480 | Signing the images manually |
| 481 | *************************** |
| 482 | Normally the build system handles the signing (computing hash over the image |
| 483 | and security critical manifest data and then signing the hash) of the firmware |
| 484 | images. However, the images also can be signed manually by using the ``imgtool`` |
Balint Matyi | 69e2d2e | 2020-07-08 10:53:54 +0100 | [diff] [blame] | 485 | Python program which is located in the MCUboot repository in the ``scripts`` |
| 486 | folder or can be installed with the pip package manager. |
David Vincze | 9c60901 | 2019-08-22 13:37:21 +0200 | [diff] [blame] | 487 | Issue the ``python3 imgtool.py sign --help`` command in the directory for more |
| 488 | information about the mandatory and optional arguments. The tool takes an image |
| 489 | in binary or Intel Hex format and adds a header and trailer that MCUBoot is |
| 490 | expecting. In case of single image boot after a successful build the |
Anton Komlev | b8e3af0 | 2020-08-28 10:23:57 +0100 | [diff] [blame] | 491 | ``tfm_s_ns.bin`` build artifact (contains the concatenated secure and non-secure |
David Vincze | 9c60901 | 2019-08-22 13:37:21 +0200 | [diff] [blame] | 492 | images) must be passed to the script and in case of multiple image boot the |
| 493 | ``tfm_s.bin`` and ``tfm_ns.bin`` binaries can be passed to prepare the signed |
| 494 | images. |
| 495 | |
| 496 | Signing the secure image manually in case of multiple image boot |
| 497 | ================================================================ |
| 498 | |
| 499 | :: |
| 500 | |
| 501 | python3 bl2/ext/mcuboot/scripts/imgtool.py sign \ |
Anton Komlev | b8e3af0 | 2020-08-28 10:23:57 +0100 | [diff] [blame] | 502 | --layout <build_dir>/bl2/ext/mcuboot/CMakeFiles/signing_layout_s.dir/signing_layout_s.c.obj \ |
| 503 | -k <tfm_dir>/bl2/ext/mcuboot/root-RSA-3072.pem \ |
David Vincze | 9c60901 | 2019-08-22 13:37:21 +0200 | [diff] [blame] | 504 | --public-key-format full \ |
| 505 | --align 1 \ |
| 506 | -v 1.2.3+4 \ |
| 507 | -d "(1,1.2.3+0)" \ |
| 508 | -s 42 \ |
| 509 | -H 0x400 \ |
Anton Komlev | b8e3af0 | 2020-08-28 10:23:57 +0100 | [diff] [blame] | 510 | <build_dir>/bin/tfm_s.bin \ |
| 511 | <build_dir>/bin/tfm_s_signed.bin |
David Vincze | 060968d | 2019-05-23 01:13:14 +0200 | [diff] [blame] | 512 | |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 513 | ************************ |
| 514 | Testing firmware upgrade |
| 515 | ************************ |
| 516 | As downloading the new firmware image is out of scope for MCUBoot, the update |
| 517 | process is started from a state where the original and the new image are already |
| 518 | programmed to the appropriate memory slots. To generate the original and a new |
| 519 | firmware package, TF-M is built twice with different build configurations. |
| 520 | |
David Vincze | 8a2a4e2 | 2019-05-24 10:14:23 +0200 | [diff] [blame] | 521 | Overwriting firmware upgrade |
Tamas Ban | e7efdc6 | 2019-06-05 13:14:52 +0100 | [diff] [blame] | 522 | ============================ |
David Vincze | 9c60901 | 2019-08-22 13:37:21 +0200 | [diff] [blame] | 523 | Run TF-M build twice with ``MCUBOOT_IMAGE_NUMBER`` set to "1" in both cases |
| 524 | (single image boot), but with two different build configurations: default and |
David Vincze | 8a2a4e2 | 2019-05-24 10:14:23 +0200 | [diff] [blame] | 525 | regression. Save the artifacts between builds, because second run can overwrite |
David Vincze | 8bdfc2d | 2019-03-18 15:49:23 +0100 | [diff] [blame] | 526 | original binaries. Download default build to the primary slot and regression |
| 527 | build to the secondary slot. |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 528 | |
| 529 | Executing firmware upgrade on FVP_MPS2_AEMv8M |
| 530 | --------------------------------------------- |
| 531 | .. code-block:: bash |
| 532 | |
Minos Galanakis | 3b740a1 | 2020-10-15 11:10:26 +0100 | [diff] [blame] | 533 | <ARM_DS_PATH>/sw/models/bin/FVP_MPS2_AEMv8M \ |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 534 | --parameter fvp_mps2.platform_type=2 \ |
| 535 | --parameter cpu0.baseline=0 \ |
| 536 | --parameter cpu0.INITVTOR_S=0x10000000 \ |
| 537 | --parameter cpu0.semihosting-enable=0 \ |
| 538 | --parameter fvp_mps2.DISABLE_GATING=0 \ |
| 539 | --parameter fvp_mps2.telnetterminal0.start_telnet=1 \ |
| 540 | --parameter fvp_mps2.telnetterminal1.start_telnet=0 \ |
| 541 | --parameter fvp_mps2.telnetterminal2.start_telnet=0 \ |
| 542 | --parameter fvp_mps2.telnetterminal0.quiet=0 \ |
| 543 | --parameter fvp_mps2.telnetterminal1.quiet=1 \ |
| 544 | --parameter fvp_mps2.telnetterminal2.quiet=1 \ |
Summer Qin | 57096f9 | 2020-09-25 14:33:36 +0800 | [diff] [blame] | 545 | --application cpu0=<build_dir>/bin/bl2.axf \ |
Anton Komlev | b8e3af0 | 2020-08-28 10:23:57 +0100 | [diff] [blame] | 546 | --data cpu0=<default_build_dir>/bin/tfm_s_ns_signed.bin@0x10080000 \ |
| 547 | --data cpu0=<regresssion_build_dir>/bin/tfm_s_ns_signed.bin@0x10180000 |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 548 | |
| 549 | Executing firmware upgrade on SSE 200 FPGA on MPS2 board |
| 550 | -------------------------------------------------------- |
| 551 | |
| 552 | :: |
| 553 | |
| 554 | TITLE: Versatile Express Images Configuration File |
| 555 | [IMAGES] |
| 556 | TOTALIMAGES: 3 ;Number of Images (Max: 32) |
| 557 | IMAGE0ADDRESS: 0x00000000 |
Summer Qin | 57096f9 | 2020-09-25 14:33:36 +0800 | [diff] [blame] | 558 | IMAGE0FILE: \Software\bl2.axf ; BL2 bootloader |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 559 | IMAGE1ADDRESS: 0x10080000 |
David Vincze | 8a2a4e2 | 2019-05-24 10:14:23 +0200 | [diff] [blame] | 560 | IMAGE1FILE: \Software\tfm_sig1.bin ; TF-M default test binary blob |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 561 | IMAGE2ADDRESS: 0x10180000 |
| 562 | IMAGE2FILE: \Software\tfm_sig2.bin ; TF-M regression test binary blob |
| 563 | |
David Vincze | 8a2a4e2 | 2019-05-24 10:14:23 +0200 | [diff] [blame] | 564 | The following message will be shown in case of successful firmware upgrade: |
| 565 | |
| 566 | :: |
| 567 | |
| 568 | [INF] Starting bootloader |
| 569 | [INF] Swap type: test |
David Vincze | 8bdfc2d | 2019-03-18 15:49:23 +0100 | [diff] [blame] | 570 | [INF] Image upgrade secondary slot -> primary slot |
| 571 | [INF] Erasing the primary slot |
| 572 | [INF] Copying the secondary slot to the primary slot: 0x100000 bytes |
David Vincze | 8a2a4e2 | 2019-05-24 10:14:23 +0200 | [diff] [blame] | 573 | [INF] Bootloader chainload address offset: 0x80000 |
| 574 | [INF] Jumping to the first image slot |
| 575 | [Sec Thread] Secure image initializing! |
| 576 | |
| 577 | #### Execute test suites for the Secure area #### |
Kevin Peng | c6d7450 | 2020-03-04 16:55:37 +0800 | [diff] [blame] | 578 | Running Test Suite PSA protected storage S interface tests (TFM_PS_TEST_2XXX)... |
David Vincze | 8a2a4e2 | 2019-05-24 10:14:23 +0200 | [diff] [blame] | 579 | ... |
| 580 | |
David Vincze | 9c60901 | 2019-08-22 13:37:21 +0200 | [diff] [blame] | 581 | To update the secure and non-secure images separately (multiple image boot), |
| 582 | set the ``MCUBOOT_IMAGE_NUMBER`` switch to "2" (this is the default |
| 583 | configuration value) and follow the same instructions as in case of single image |
| 584 | boot. |
| 585 | |
| 586 | Executing multiple firmware upgrades on SSE 200 FPGA on MPS2 board |
| 587 | ------------------------------------------------------------------ |
| 588 | |
| 589 | :: |
| 590 | |
| 591 | TITLE: Versatile Express Images Configuration File |
| 592 | [IMAGES] |
| 593 | TOTALIMAGES: 4 ;Number of Images (Max: 32) |
| 594 | IMAGE0ADDRESS: 0x00000000 |
Summer Qin | 57096f9 | 2020-09-25 14:33:36 +0800 | [diff] [blame] | 595 | IMAGE0FILE: \Software\bl2.axf ; BL2 bootloader |
David Vincze | 9c60901 | 2019-08-22 13:37:21 +0200 | [diff] [blame] | 596 | IMAGE1ADDRESS: 0x10080000 |
| 597 | IMAGE1FILE: \Software\tfm_sign.bin ; TF-M default test binary blob |
| 598 | IMAGE2ADDRESS: 0x10180000 |
| 599 | IMAGE2FILE: \Software\tfm_ss1.bin ; TF-M regression test secure (signed) image |
| 600 | IMAGE3ADDRESS: 0x10200000 |
| 601 | IMAGE3FILE: \Software\tfm_nss1.bin ; TF-M regression test non-secure (signed) image |
| 602 | |
| 603 | Note that both the concatenated binary blob (the images are signed separately |
| 604 | and then concatenated) and the separate signed images can be downloaded to the |
| 605 | device because on this platform (AN521) both the primary slots and the secondary |
| 606 | slots are contiguous areas in the Flash (see `Integration with TF-M`_). The |
| 607 | following message will be shown in case of successful firmware upgrades: |
| 608 | |
| 609 | :: |
| 610 | |
| 611 | [INF] Starting bootloader |
| 612 | [INF] Swap type: test |
| 613 | [INF] Swap type: test |
| 614 | [INF] Image upgrade secondary slot -> primary slot |
| 615 | [INF] Erasing the primary slot |
| 616 | [INF] Copying the secondary slot to the primary slot: 0x80000 bytes |
| 617 | [INF] Image upgrade secondary slot -> primary slot |
| 618 | [INF] Erasing the primary slot |
| 619 | [INF] Copying the secondary slot to the primary slot: 0x80000 bytes |
| 620 | [INF] Bootloader chainload address offset: 0x80000 |
| 621 | [INF] Jumping to the first image slot |
| 622 | [Sec Thread] Secure image initializing! |
| 623 | TFM level is: 1 |
| 624 | [Sec Thread] Jumping to non-secure code... |
| 625 | |
| 626 | #### Execute test suites for the Secure area #### |
Kevin Peng | c6d7450 | 2020-03-04 16:55:37 +0800 | [diff] [blame] | 627 | Running Test Suite PSA protected storage S interface tests (TFM_PS_TEST_2XXX)... |
David Vincze | 9c60901 | 2019-08-22 13:37:21 +0200 | [diff] [blame] | 628 | ... |
| 629 | |
David Vincze | 8a2a4e2 | 2019-05-24 10:14:23 +0200 | [diff] [blame] | 630 | Swapping firmware upgrade |
| 631 | ============================= |
| 632 | Follow the same instructions and platform related configurations as in case of |
| 633 | overwriting build including these changes: |
| 634 | |
David Vincze | 9c60901 | 2019-08-22 13:37:21 +0200 | [diff] [blame] | 635 | - Set the ``MCUBOOT_UPGRADE_STRATEGY`` compile time switch to "SWAP" |
| 636 | before build. |
| 637 | - Set the ``MCUBOOT_IMAGE_NUMBER`` compile time switch to "1" (single image |
| 638 | boot) or "2" (multiple image boot) before build. |
David Vincze | 8a2a4e2 | 2019-05-24 10:14:23 +0200 | [diff] [blame] | 639 | |
David Vincze | 9c60901 | 2019-08-22 13:37:21 +0200 | [diff] [blame] | 640 | During single image boot the following message will be shown in case of |
| 641 | successful firmware upgrade, ``Swap type: test`` indicates that images were |
| 642 | swapped: |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 643 | |
| 644 | :: |
| 645 | |
David Vincze | 8a2a4e2 | 2019-05-24 10:14:23 +0200 | [diff] [blame] | 646 | [INF] Starting bootloader |
| 647 | [INF] Image 0: magic= good, copy_done=0x3, image_ok=0x3 |
| 648 | [INF] Scratch: magic= bad, copy_done=0x0, image_ok=0x2 |
David Vincze | 8bdfc2d | 2019-03-18 15:49:23 +0100 | [diff] [blame] | 649 | [INF] Boot source: primary slot |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 650 | [INF] Swap type: test |
| 651 | [INF] Bootloader chainload address offset: 0x80000 |
| 652 | [INF] Jumping to the first image slot |
| 653 | [Sec Thread] Secure image initializing! |
| 654 | |
David Vincze | 8a2a4e2 | 2019-05-24 10:14:23 +0200 | [diff] [blame] | 655 | #### Execute test suites for the Secure area #### |
Kevin Peng | c6d7450 | 2020-03-04 16:55:37 +0800 | [diff] [blame] | 656 | Running Test Suite PSA protected storage S interface tests (TFM_PS_TEST_2XXX)... |
David Vincze | 8a2a4e2 | 2019-05-24 10:14:23 +0200 | [diff] [blame] | 657 | ... |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 658 | |
Tamas Ban | 0bd0dfc | 2020-09-11 15:25:48 +0100 | [diff] [blame] | 659 | Direct execute-in-place firmware upgrade |
| 660 | ======================================== |
David Vincze | 9c60901 | 2019-08-22 13:37:21 +0200 | [diff] [blame] | 661 | Follow the same instructions and platform related configurations as in case of |
| 662 | overwriting build including these changes: |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 663 | |
Tamas Ban | 0bd0dfc | 2020-09-11 15:25:48 +0100 | [diff] [blame] | 664 | - Set the ``MCUBOOT_UPGRADE_STRATEGY`` compile time switch to "DIRECT_XIP" |
David Vincze | 8a2a4e2 | 2019-05-24 10:14:23 +0200 | [diff] [blame] | 665 | before build. |
Anton Komlev | b8e3af0 | 2020-08-28 10:23:57 +0100 | [diff] [blame] | 666 | - set ``MCUBOOT_EXECUTION_SLOT`` to ``1`` in the regression build dir. |
David Vincze | 9c60901 | 2019-08-22 13:37:21 +0200 | [diff] [blame] | 667 | - Make sure the image version number was increased between the two build runs |
| 668 | either by specifying it manually or by checking in the build log that it was |
| 669 | incremented automatically. |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 670 | |
| 671 | Executing firmware upgrade on FVP_MPS2_AEMv8M |
| 672 | --------------------------------------------- |
| 673 | |
| 674 | .. code-block:: bash |
| 675 | |
Minos Galanakis | 3b740a1 | 2020-10-15 11:10:26 +0100 | [diff] [blame] | 676 | <ARM_DS_PATH>/sw/models/bin/FVP_MPS2_AEMv8M \ |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 677 | --parameter fvp_mps2.platform_type=2 \ |
| 678 | --parameter cpu0.baseline=0 \ |
| 679 | --parameter cpu0.INITVTOR_S=0x10000000 \ |
| 680 | --parameter cpu0.semihosting-enable=0 \ |
| 681 | --parameter fvp_mps2.DISABLE_GATING=0 \ |
| 682 | --parameter fvp_mps2.telnetterminal0.start_telnet=1 \ |
| 683 | --parameter fvp_mps2.telnetterminal1.start_telnet=0 \ |
| 684 | --parameter fvp_mps2.telnetterminal2.start_telnet=0 \ |
| 685 | --parameter fvp_mps2.telnetterminal0.quiet=0 \ |
| 686 | --parameter fvp_mps2.telnetterminal1.quiet=1 \ |
| 687 | --parameter fvp_mps2.telnetterminal2.quiet=1 \ |
Summer Qin | 57096f9 | 2020-09-25 14:33:36 +0800 | [diff] [blame] | 688 | --application cpu0=<build_dir>/bin/bl2.axf \ |
Anton Komlev | b8e3af0 | 2020-08-28 10:23:57 +0100 | [diff] [blame] | 689 | --data cpu0=<default_build_dir>/bin/tfm_s_ns_signed.bin@0x10080000 \ |
| 690 | --data cpu0=<regresssion_build_dir>/bin/tfm_s_ns_signed.bin@0x10180000 |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 691 | |
| 692 | Executing firmware upgrade on SSE 200 FPGA on MPS2 board |
| 693 | -------------------------------------------------------- |
| 694 | |
| 695 | :: |
| 696 | |
| 697 | TITLE: Versatile Express Images Configuration File |
| 698 | [IMAGES] |
| 699 | TOTALIMAGES: 3 ;Number of Images (Max: 32) |
| 700 | IMAGE0ADDRESS: 0x00000000 |
Summer Qin | 57096f9 | 2020-09-25 14:33:36 +0800 | [diff] [blame] | 701 | IMAGE0FILE: \Software\bl2.axf ; BL2 bootloader |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 702 | IMAGE1ADDRESS: 0x10080000 |
Tamas Ban | bba8564 | 2019-06-06 09:31:59 +0100 | [diff] [blame] | 703 | IMAGE1FILE: \Software\tfm_sign.bin ; TF-M default test binary blob |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 704 | IMAGE2ADDRESS: 0x10180000 |
| 705 | IMAGE2FILE: \Software\tfm_sig1.bin ; TF-M regression test binary blob |
| 706 | |
Balint Matyi | 6844e44 | 2020-04-22 07:24:40 +0100 | [diff] [blame] | 707 | Executing firmware upgrade on Musca-B1 and Musca-S1 boards |
| 708 | ---------------------------------------------------------- |
David Vincze | 9c60901 | 2019-08-22 13:37:21 +0200 | [diff] [blame] | 709 | After the two images have been built, they can be concatenated to create the |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 710 | combined image using ``srec_cat``: |
| 711 | |
| 712 | - Linux:: |
David Vincze | 8a2a4e2 | 2019-05-24 10:14:23 +0200 | [diff] [blame] | 713 | |
Summer Qin | 57096f9 | 2020-09-25 14:33:36 +0800 | [diff] [blame] | 714 | srec_cat bin/bl2.bin -Binary -offset 0xA000000 tfm_sign.bin -Binary -offset 0xA020000 tfm_sign_1.bin -Binary -offset 0xA100000 -o tfm.hex -Intel |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 715 | |
| 716 | - Windows:: |
David Vincze | 8a2a4e2 | 2019-05-24 10:14:23 +0200 | [diff] [blame] | 717 | |
Summer Qin | 57096f9 | 2020-09-25 14:33:36 +0800 | [diff] [blame] | 718 | srec_cat.exe bin\bl2.bin -Binary -offset 0xA000000 tfm_sign.bin -Binary -offset 0xA020000 tfm_sign_1.bin -Binary -offset 0xA100000 -o tfm.hex -Intel |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 719 | |
| 720 | The following message will be shown in case of successful firmware upgrade, |
| 721 | notice that image with higher version number (``version=1.2.3.5``) is executed: |
| 722 | |
| 723 | :: |
| 724 | |
| 725 | [INF] Starting bootloader |
David Vincze | 8a2a4e2 | 2019-05-24 10:14:23 +0200 | [diff] [blame] | 726 | [INF] Image 0: version=1.2.3.4, magic= good, image_ok=0x3 |
| 727 | [INF] Image 1: version=1.2.3.5, magic= good, image_ok=0x3 |
David Vincze | 8bdfc2d | 2019-03-18 15:49:23 +0100 | [diff] [blame] | 728 | [INF] Booting image from the secondary slot |
David Vincze | 8a2a4e2 | 2019-05-24 10:14:23 +0200 | [diff] [blame] | 729 | [INF] Bootloader chainload address offset: 0xa0000 |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 730 | [INF] Jumping to the first image slot |
| 731 | [Sec Thread] Secure image initializing! |
| 732 | |
David Vincze | 8a2a4e2 | 2019-05-24 10:14:23 +0200 | [diff] [blame] | 733 | #### Execute test suites for the Secure area #### |
Kevin Peng | c6d7450 | 2020-03-04 16:55:37 +0800 | [diff] [blame] | 734 | Running Test Suite PSA protected storage S interface tests (TFM_PS_TEST_2XXX)... |
David Vincze | 8a2a4e2 | 2019-05-24 10:14:23 +0200 | [diff] [blame] | 735 | ... |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 736 | |
Kevin Peng | 0a14211 | 2018-09-21 10:42:22 +0800 | [diff] [blame] | 737 | Executing firmware upgrade on CoreLink SSE-200 Subsystem for MPS3 (AN524) |
| 738 | ------------------------------------------------------------------------- |
| 739 | |
| 740 | :: |
| 741 | |
| 742 | TITLE: Arm MPS3 FPGA prototyping board Images Configuration File |
| 743 | |
| 744 | [IMAGES] |
| 745 | TOTALIMAGES: 3 ;Number of Images (Max: 32) |
| 746 | |
| 747 | IMAGE0UPDATE: AUTO ;Image Update:NONE/AUTO/FORCE |
| 748 | IMAGE0ADDRESS: 0x00000000 |
Summer Qin | 57096f9 | 2020-09-25 14:33:36 +0800 | [diff] [blame] | 749 | IMAGE0FILE: \SOFTWARE\bl2.bin ;BL2 bootloader |
Kevin Peng | 0a14211 | 2018-09-21 10:42:22 +0800 | [diff] [blame] | 750 | IMAGE1UPDATE: AUTO |
| 751 | IMAGE1ADDRESS: 0x00040000 |
| 752 | IMAGE1FILE: \SOFTWARE\tfm_sig0.bin ;TF-M example application binary blob |
| 753 | IMAGE2UPDATE: AUTO |
| 754 | IMAGE2ADDRESS: 0x000C0000 |
| 755 | IMAGE2FILE: \SOFTWARE\tfm_sig1.bin ;TF-M regression test binary blob |
| 756 | |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 757 | RAM loading firmware upgrade |
| 758 | ============================ |
Tamas Ban | f4023f3 | 2020-09-16 11:02:52 +0100 | [diff] [blame] | 759 | To enable RAM loading, please set ``MCUBOOT_UPGRADE_STRATEGY`` to "RAM_LOAD" |
David Vincze | 8a2a4e2 | 2019-05-24 10:14:23 +0200 | [diff] [blame] | 760 | (either in the configuration file or through the command line), and then specify |
| 761 | a destination load address in RAM where the image can be copied to and executed |
| 762 | from. The ``IMAGE_LOAD_ADDRESS`` macro must be specified in the target dependent |
| 763 | files, for example with Musca-A, its ``flash_layout.h`` file in the ``platform`` |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 764 | folder should include ``#define IMAGE_LOAD_ADDRESS #0x10020000`` |
| 765 | |
David Vincze | 8a2a4e2 | 2019-05-24 10:14:23 +0200 | [diff] [blame] | 766 | Executing firmware upgrade on Musca-A board |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 767 | -------------------------------------------- |
| 768 | After two images have been built, they can be concatenated to create the |
| 769 | combined image using ``srec_cat``: |
| 770 | |
David Vincze | 8a2a4e2 | 2019-05-24 10:14:23 +0200 | [diff] [blame] | 771 | - Linux:: |
| 772 | |
Summer Qin | 57096f9 | 2020-09-25 14:33:36 +0800 | [diff] [blame] | 773 | srec_cat bin/bl2.bin -Binary -offset 0x200000 tfm_sign_old.bin -Binary -offset 0x220000 tfm_sign_new.bin -Binary -offset 0x320000 -o tfm.hex -Intel |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 774 | |
| 775 | - Windows:: |
David Vincze | 8a2a4e2 | 2019-05-24 10:14:23 +0200 | [diff] [blame] | 776 | |
Summer Qin | 57096f9 | 2020-09-25 14:33:36 +0800 | [diff] [blame] | 777 | srec_cat.exe bin\bl2.bin -Binary -offset 0x200000 tfm_sign_old.bin -Binary -offset 0x220000 tfm_sign_new.bin -Binary -offset 0x320000 -o tfm.hex -Intel |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 778 | |
| 779 | The following message will be shown in case of successful firmware upgrade when, |
| 780 | RAM loading is enabled, notice that image with higher version number |
| 781 | (``version=0.0.0.2``) is executed: |
| 782 | |
| 783 | :: |
| 784 | |
David Vincze | 8a2a4e2 | 2019-05-24 10:14:23 +0200 | [diff] [blame] | 785 | [INF] Starting bootloader |
| 786 | [INF] Image 0: version=0.0.0.1, magic= good, image_ok=0x3 |
| 787 | [INF] Image 1: version=0.0.0.2, magic= good, image_ok=0x3 |
David Vincze | 8bdfc2d | 2019-03-18 15:49:23 +0100 | [diff] [blame] | 788 | [INF] Image has been copied from the secondary slot in flash to SRAM address 0x10020000 |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 789 | [INF] Booting image from SRAM at address 0x10020000 |
| 790 | [INF] Bootloader chainload address offset: 0x20000 |
| 791 | [INF] Jumping to the first image slot |
| 792 | [Sec Thread] Secure image initializing! |
| 793 | |
| 794 | -------------- |
| 795 | |
David Vincze | c3e313a | 2020-01-06 17:31:11 +0100 | [diff] [blame] | 796 | *Copyright (c) 2018-2020, Arm Limited. All rights reserved.* |