Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 1 | # |
| 2 | # Licensed to the Apache Software Foundation (ASF) under one |
| 3 | # or more contributor license agreements. See the NOTICE file |
| 4 | # distributed with this work for additional information |
| 5 | # regarding copyright ownership. The ASF licenses this file |
| 6 | # to you under the Apache License, Version 2.0 (the |
| 7 | # "License"); you may not use this file except in compliance |
| 8 | # with the License. You may obtain a copy of the License at |
Marti Bolivar | 49b2917 | 2017-08-04 14:50:51 -0400 | [diff] [blame] | 9 | # |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 10 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | # |
| 12 | # Unless required by applicable law or agreed to in writing, |
| 13 | # software distributed under the License is distributed on an |
| 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | # KIND, either express or implied. See the License for the |
| 16 | # specific language governing permissions and limitations |
| 17 | # under the License. |
| 18 | # |
| 19 | |
| 20 | ****** BOOT LOADER |
| 21 | |
| 22 | *** SUMMARY |
| 23 | |
Fabio Utzig | ac83496 | 2017-07-20 13:20:48 -0300 | [diff] [blame] | 24 | mcuboot comprises two packages: |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 25 | |
| 26 | * The bootutil library (boot/bootutil) |
Fabio Utzig | 5bd4e58 | 2017-07-20 08:55:38 -0300 | [diff] [blame] | 27 | * The boot application (each port has its own at boot/<port>) |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 28 | |
| 29 | The bootutil library performs most of the functions of a boot loader. In |
| 30 | particular, the piece that is missing is the final step of actually jumping to |
| 31 | the main image. This last step is instead implemented by the boot application. |
| 32 | Boot loader functionality is separated in this manner to enable unit testing of |
| 33 | the boot loader. A library can be unit tested, but an application can't. |
| 34 | Therefore, functionality is delegated to the bootutil library when possible. |
| 35 | |
| 36 | *** LIMITATIONS |
| 37 | |
| 38 | The boot loader currently only supports images with the following |
| 39 | characteristics: |
| 40 | * Built to run from flash. |
Marti Bolivar | 49b2917 | 2017-08-04 14:50:51 -0400 | [diff] [blame] | 41 | * Built to run from a fixed location (i.e., not position-independent). |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 42 | |
| 43 | *** IMAGE FORMAT |
| 44 | |
| 45 | The following definitions describe the image format. |
| 46 | |
| 47 | #define IMAGE_MAGIC 0x96f3b83c |
| 48 | |
| 49 | #define IMAGE_HEADER_SIZE 32 |
| 50 | |
| 51 | struct image_version { |
| 52 | uint8_t iv_major; |
| 53 | uint8_t iv_minor; |
| 54 | uint16_t iv_revision; |
| 55 | uint32_t iv_build_num; |
| 56 | }; |
| 57 | |
| 58 | /** Image header. All fields are in little endian byte order. */ |
| 59 | struct image_header { |
| 60 | uint32_t ih_magic; |
| 61 | uint16_t ih_tlv_size; /* Combined size of trailing TLVs (bytes). */ |
| 62 | uint8_t ih_key_id; /* Which key image is signed with (0xff=unsigned). */ |
| 63 | uint8_t _pad1; |
| 64 | uint16_t ih_hdr_size; /* Size of image header (bytes). */ |
| 65 | uint16_t _pad2; |
| 66 | uint32_t ih_img_size; /* Does not include header. */ |
| 67 | uint32_t ih_flags; /* IMAGE_F_[...] */ |
| 68 | struct image_version ih_ver; |
| 69 | uint32_t _pad3; |
| 70 | }; |
| 71 | |
| 72 | /** Image trailer TLV format. All fields in little endian. */ |
| 73 | struct image_tlv { |
| 74 | uint8_t it_type; /* IMAGE_TLV_[...]. */ |
| 75 | uint8_t _pad; |
Marti Bolivar | 49b2917 | 2017-08-04 14:50:51 -0400 | [diff] [blame] | 76 | uint16_t it_len; /* Data length (not including TLV header). */ |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 77 | }; |
| 78 | |
| 79 | /* |
| 80 | * Image header flags. |
| 81 | */ |
Marti Bolivar | 7c057e9 | 2017-08-04 14:46:39 -0400 | [diff] [blame] | 82 | #define IMAGE_F_PIC 0x00000001 /* Not supported. */ |
| 83 | #define IMAGE_F_SHA256 0x00000002 /* Hash TLV is present */ |
| 84 | #define IMAGE_F_PKCS15_RSA2048_SHA256 0x00000004 /* PKCS15 w/RSA and SHA */ |
| 85 | #define IMAGE_F_ECDSA224_SHA256 0x00000008 /* ECDSA224 over SHA256 */ |
| 86 | #define IMAGE_F_NON_BOOTABLE 0x00000010 /* Split image app. */ |
| 87 | #define IMAGE_F_ECDSA256_SHA256 0x00000020 /* ECDSA256 over SHA256 */ |
| 88 | #define IMAGE_F_PKCS1_PSS_RSA2048_SHA256 0x00000040 /* PKCS1 PSS */ |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 89 | |
| 90 | /* |
| 91 | * Image trailer TLV types. |
| 92 | */ |
David Brown | 27648b8 | 2017-08-31 10:40:29 -0600 | [diff] [blame] | 93 | #define IMAGE_TLV_SHA256 0x10 /* SHA256 of image hdr and body */ |
Marko Kiiskila | 8dd56f3 | 2017-08-22 21:40:49 -0700 | [diff] [blame] | 94 | #define IMAGE_TLV_RSA2048_PSS 0x20 /* RSA2048 of hash output */ |
David Brown | 27648b8 | 2017-08-31 10:40:29 -0600 | [diff] [blame] | 95 | #define IMAGE_TLV_ECDSA224 0x21 /* ECDSA of hash output */ |
| 96 | #define IMAGE_TLV_ECDSA256 0x22 /* ECDSA of hash output */ |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 97 | |
| 98 | Optional type-length-value records (TLVs) containing image metadata are placed |
| 99 | after the end of the image. |
| 100 | |
| 101 | The ih_hdr_size field indicates the length of the header, and therefore the |
| 102 | offset of the image itself. This field provides for backwards compatibility in |
| 103 | case of changes to the format of the image header. |
| 104 | |
| 105 | *** FLASH MAP |
| 106 | |
Fabio Utzig | ac83496 | 2017-07-20 13:20:48 -0300 | [diff] [blame] | 107 | A device's flash is partitioned according to its _flash map_. At a high |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 108 | level, the flash map maps numeric IDs to _flash areas_. A flash area is a |
| 109 | region of disk with the following properties: |
| 110 | (1) An area can be fully erased without affecting any other areas. |
| 111 | (2) A write to one area does not restrict writes to other areas. |
| 112 | |
Marti Bolivar | 4e64d56 | 2017-08-04 14:53:33 -0400 | [diff] [blame] | 113 | The boot loader uses the following flash area IDs: |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 114 | |
| 115 | #define FLASH_AREA_BOOTLOADER 0 |
| 116 | #define FLASH_AREA_IMAGE_0 1 |
| 117 | #define FLASH_AREA_IMAGE_1 2 |
| 118 | #define FLASH_AREA_IMAGE_SCRATCH 3 |
| 119 | |
Marti Bolivar | 4e64d56 | 2017-08-04 14:53:33 -0400 | [diff] [blame] | 120 | The bootloader area contains the bootloader image itself. The other areas are |
| 121 | described in subsequent sections. |
| 122 | |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 123 | *** IMAGE SLOTS |
| 124 | |
| 125 | A portion of the flash memory is partitioned into two image slots: a primary |
| 126 | slot (0) and a secondary slot (1). The boot loader will only run an image from |
| 127 | the primary slot, so images must be built such that they can run from that |
| 128 | fixed location in flash. If the boot loader needs to run the image resident in |
Marti Bolivar | a91674f | 2017-08-04 14:56:08 -0400 | [diff] [blame] | 129 | the secondary slot, it must copy its contents into the primary slot before doing |
| 130 | so, either by swapping the two images or by overwriting the contents of the |
| 131 | primary slot. The bootloader supports either swap- or overwrite-based image |
| 132 | upgrades, but must be configured at build time to choose one of these two |
| 133 | strategies. |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 134 | |
| 135 | In addition to the two image slots, the boot loader requires a scratch area to |
| 136 | allow for reliable image swapping. |
| 137 | |
Marti Bolivar | a91674f | 2017-08-04 14:56:08 -0400 | [diff] [blame] | 138 | The overwrite upgrade strategy is substantially simpler to implement than the |
| 139 | image swapping strategy, especially since the bootloader must work properly |
| 140 | even when it is reset during the middle of an image swap. For this reason, the |
| 141 | rest of the document describes its behavior when configured to swap images |
| 142 | during an upgrade. |
| 143 | |
Marti Bolivar | 048d8d8 | 2017-08-04 17:14:24 -0400 | [diff] [blame] | 144 | *** BOOT SWAP TYPES |
Christopher Collins | fd7eb5c | 2016-12-21 13:46:08 -0800 | [diff] [blame] | 145 | |
Marti Bolivar | 048d8d8 | 2017-08-04 17:14:24 -0400 | [diff] [blame] | 146 | When the device first boots under normal circumstances, there is an up-to-date |
| 147 | firmware image in slot 0, which mcuboot can validate and then chain-load. In |
| 148 | this case, no image swaps are necessary. During device upgrades, however, new |
| 149 | candidate images are present in slot 1, which mcuboot must swap into slot 0 |
| 150 | before booting as discussed above. |
Christopher Collins | fd7eb5c | 2016-12-21 13:46:08 -0800 | [diff] [blame] | 151 | |
Marti Bolivar | 048d8d8 | 2017-08-04 17:14:24 -0400 | [diff] [blame] | 152 | Upgrading an old image with a new one by swapping can be a two-step process. In |
| 153 | this process, mcuboot performs a "test" swap of image data in flash and boots |
| 154 | the new image. The new image can then update the contents of flash at runtime |
| 155 | to mark itself "OK", and mcuboot will then still choose to run it during the |
| 156 | next boot. When this happens, the swap is made "permanent". If this doesn't |
| 157 | happen, mcuboot will perform a "revert" swap during the next boot by swapping |
| 158 | the images back into their original locations, and attempting to boot the old |
| 159 | image. |
Christopher Collins | fd7eb5c | 2016-12-21 13:46:08 -0800 | [diff] [blame] | 160 | |
Marti Bolivar | 048d8d8 | 2017-08-04 17:14:24 -0400 | [diff] [blame] | 161 | Depending on the use case, the first swap can also be made permanent directly. |
| 162 | In this case, mcuboot will never attempt to revert the images on the next reset. |
Christopher Collins | fd7eb5c | 2016-12-21 13:46:08 -0800 | [diff] [blame] | 163 | |
Marti Bolivar | 048d8d8 | 2017-08-04 17:14:24 -0400 | [diff] [blame] | 164 | Test swaps are supported to provide a rollback mechanism to prevent devices |
| 165 | from becoming "bricked" by bad firmware. If the device crashes immediately |
| 166 | upon booting a new (bad) image, mcuboot will revert to the old (working) image |
| 167 | at the next device reset, rather than booting the bad image again. This allows |
| 168 | device firmware to make test swaps permanent only after performing a self-test |
| 169 | routine. |
Christopher Collins | fd7eb5c | 2016-12-21 13:46:08 -0800 | [diff] [blame] | 170 | |
Marti Bolivar | 048d8d8 | 2017-08-04 17:14:24 -0400 | [diff] [blame] | 171 | On startup, mcuboot inspects the contents of flash to decide which of these |
| 172 | "swap types" to perform; this decision determines how it proceeds. |
Christopher Collins | fd7eb5c | 2016-12-21 13:46:08 -0800 | [diff] [blame] | 173 | |
Marti Bolivar | 048d8d8 | 2017-08-04 17:14:24 -0400 | [diff] [blame] | 174 | The possible swap types, and their meanings, are: |
Christopher Collins | fd7eb5c | 2016-12-21 13:46:08 -0800 | [diff] [blame] | 175 | |
Marti Bolivar | 048d8d8 | 2017-08-04 17:14:24 -0400 | [diff] [blame] | 176 | - BOOT_SWAP_TYPE_NONE: The "usual" or "no upgrade" case; attempt to boot the |
| 177 | contents of slot 0. |
Christopher Collins | fd7eb5c | 2016-12-21 13:46:08 -0800 | [diff] [blame] | 178 | |
Marti Bolivar | 048d8d8 | 2017-08-04 17:14:24 -0400 | [diff] [blame] | 179 | - BOOT_SWAP_TYPE_TEST: Boot the contents of slot 1 by swapping images. Unless |
| 180 | the swap is made permanent, revert back on the next boot. |
Christopher Collins | fd7eb5c | 2016-12-21 13:46:08 -0800 | [diff] [blame] | 181 | |
Marti Bolivar | 048d8d8 | 2017-08-04 17:14:24 -0400 | [diff] [blame] | 182 | - BOOT_SWAP_TYPE_PERM: Permanently swap images, and boot the upgraded image |
| 183 | firmware. |
Christopher Collins | fd7eb5c | 2016-12-21 13:46:08 -0800 | [diff] [blame] | 184 | |
Marti Bolivar | 048d8d8 | 2017-08-04 17:14:24 -0400 | [diff] [blame] | 185 | - BOOT_SWAP_TYPE_REVERT: A previous test swap was not made permanent; swap back |
| 186 | to the old image whose data are now in slot 1. If the old image marks itself |
| 187 | "OK" when it boots, the next boot will have swap type BOOT_SWAP_TYPE_NONE. |
Christopher Collins | fd7eb5c | 2016-12-21 13:46:08 -0800 | [diff] [blame] | 188 | |
Marti Bolivar | 048d8d8 | 2017-08-04 17:14:24 -0400 | [diff] [blame] | 189 | - BOOT_SWAP_TYPE_FAIL: Swap failed because image to be run is not valid. |
| 190 | |
| 191 | - BOOT_SWAP_TYPE_PANIC: Swapping encountered an unrecoverable error. |
| 192 | |
| 193 | The "swap type" is a high-level representation of the outcome of the |
| 194 | boot. Subsequent sections describe how mcuboot determines the swap type from |
| 195 | the bit-level contents of flash. |
Christopher Collins | fd7eb5c | 2016-12-21 13:46:08 -0800 | [diff] [blame] | 196 | |
Fabio Utzig | 86fe4b2 | 2017-07-28 18:56:29 -0300 | [diff] [blame] | 197 | *** IMAGE TRAILER |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 198 | |
Fabio Utzig | 86fe4b2 | 2017-07-28 18:56:29 -0300 | [diff] [blame] | 199 | For the bootloader to be able to determine the current state and what actions |
Marti Bolivar | 4281803 | 2017-08-04 15:45:01 -0400 | [diff] [blame] | 200 | should be taken during the current boot operation, it uses metadata stored in |
| 201 | the image flash areas. While swapping, some of this metadata is temporarily |
| 202 | copied into and out of the scratch area. |
| 203 | |
| 204 | This metadata is located at the end of the image flash areas, and is called an |
| 205 | image trailer. An image trailer has the following structure: |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 206 | |
| 207 | 0 1 2 3 |
| 208 | 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 |
| 209 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 210 | ~ ~ |
| 211 | ~ Swap status (128 * min-write-size * 3) ~ |
| 212 | ~ ~ |
| 213 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
Fabio Utzig | 2c305aa | 2017-07-20 13:14:25 -0300 | [diff] [blame] | 214 | | Copy done | 0xff padding (7 octets) | |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 215 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
Fabio Utzig | 2c305aa | 2017-07-20 13:14:25 -0300 | [diff] [blame] | 216 | | Image OK | 0xff padding (7 octets) | |
Fabio Utzig | 5bd4e58 | 2017-07-20 08:55:38 -0300 | [diff] [blame] | 217 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 218 | | MAGIC (16 octets) | |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 219 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 220 | |
Marti Bolivar | 4281803 | 2017-08-04 15:45:01 -0400 | [diff] [blame] | 221 | The offset immediately following such a record represents the start of the next |
| 222 | flash area. |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 223 | |
| 224 | Note: "min-write-size" is a property of the flash hardware. If the hardware |
| 225 | allows individual bytes to be written at arbitrary addresses, then |
| 226 | min-write-size is 1. If the hardware only allows writes at even addresses, |
| 227 | then min-write-size is 2, and so on. |
| 228 | |
Marti Bolivar | 1dcb685 | 2017-08-04 15:59:32 -0400 | [diff] [blame] | 229 | An image trailer contains the following fields: |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 230 | |
Marti Bolivar | 1dcb685 | 2017-08-04 15:59:32 -0400 | [diff] [blame] | 231 | 1. Swap status: A series of records which records the progress of an image |
| 232 | swap. To swap entire images, data are swapped between the two image areas one |
| 233 | or more sectors at a time, like this: |
| 234 | |
| 235 | - sector data in slot 0 is copied into scratch, then erased |
| 236 | - sector data in slot 1 is copied into slot 0, then erased |
| 237 | - sector data in scratch is copied into slot 1 |
| 238 | |
| 239 | As it swaps images, the bootloader updates the swap status field in a way that |
| 240 | allows it to compute how far this swap operation has progressed for each |
| 241 | sector. The swap status field can thus used to resume a swap operation if the |
| 242 | bootloader is halted while a swap operation is ongoing and later reset. The |
| 243 | factor of 128 is the maximum number of sectors mcuboot supports for each image; |
| 244 | its value is a bootloader design decision. The factor of min-write-sz is due to |
| 245 | the behavior of flash hardware. The factor of 3 is explained below. |
Fabio Utzig | 5bd4e58 | 2017-07-20 08:55:38 -0300 | [diff] [blame] | 246 | |
| 247 | 2. Copy done: A single byte indicating whether the image in this slot is |
| 248 | complete (0x01=done; 0xff=not done). |
| 249 | |
| 250 | 3. Image OK: A single byte indicating whether the image in this slot has been |
| 251 | confirmed as good by the user (0x01=confirmed; 0xff=not confirmed). |
| 252 | |
| 253 | 4. MAGIC: The following 16 bytes, written in host-byte-order: |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 254 | |
| 255 | const uint32_t boot_img_magic[4] = { |
| 256 | 0xf395c277, |
| 257 | 0x7fefd260, |
| 258 | 0x0f505235, |
| 259 | 0x8079b62c, |
| 260 | }; |
| 261 | |
Fabio Utzig | 86fe4b2 | 2017-07-28 18:56:29 -0300 | [diff] [blame] | 262 | *** IMAGE TRAILERS |
| 263 | |
Marti Bolivar | 048d8d8 | 2017-08-04 17:14:24 -0400 | [diff] [blame] | 264 | At startup, the boot loader determines the boot swap type by inspecting the |
| 265 | image trailers. When using the term "image trailers" what is meant is the |
| 266 | aggregate information provided by both image slot's trailers. |
Fabio Utzig | 86fe4b2 | 2017-07-28 18:56:29 -0300 | [diff] [blame] | 267 | |
| 268 | The image trailers records are structured around the limitations imposed by flash |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 269 | hardware. As a consequence, they do not have a very intuitive design, and it |
| 270 | is difficult to get a sense of the state of the device just by looking at the |
Marti Bolivar | 048d8d8 | 2017-08-04 17:14:24 -0400 | [diff] [blame] | 271 | image trailers. It is better to map all the possible trailer states to the swap |
| 272 | types described above via a set of tables. These tables are reproduced below. |
Fabio Utzig | 86fe4b2 | 2017-07-28 18:56:29 -0300 | [diff] [blame] | 273 | |
| 274 | Note: An important caveat about the tables described below is that they must |
| 275 | be evaluated in the order presented here. Lower state numbers must have a |
| 276 | higher priority when testing the image trailers. |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 277 | |
| 278 | |
| 279 | State I |
| 280 | | slot-0 | slot-1 | |
| 281 | -----------------+--------+--------| |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 282 | magic | Any | Good | |
Christopher Collins | fd7eb5c | 2016-12-21 13:46:08 -0800 | [diff] [blame] | 283 | image-ok | Any | Unset | |
Fabio Utzig | f9d4428 | 2017-07-20 15:05:13 -0300 | [diff] [blame] | 284 | copy-done | Any | Any | |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 285 | -----------------+--------+--------' |
Marti Bolivar | 048d8d8 | 2017-08-04 17:14:24 -0400 | [diff] [blame] | 286 | result: BOOT_SWAP_TYPE_TEST | |
Christopher Collins | fd7eb5c | 2016-12-21 13:46:08 -0800 | [diff] [blame] | 287 | -----------------------------------' |
Fabio Utzig | 5bd4e58 | 2017-07-20 08:55:38 -0300 | [diff] [blame] | 288 | |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 289 | |
Fabio Utzig | 86fe4b2 | 2017-07-28 18:56:29 -0300 | [diff] [blame] | 290 | State II |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 291 | | slot-0 | slot-1 | |
| 292 | -----------------+--------+--------| |
Christopher Collins | fd7eb5c | 2016-12-21 13:46:08 -0800 | [diff] [blame] | 293 | magic | Any | Good | |
| 294 | image-ok | Any | 0x01 | |
Fabio Utzig | f9d4428 | 2017-07-20 15:05:13 -0300 | [diff] [blame] | 295 | copy-done | Any | Any | |
Christopher Collins | fd7eb5c | 2016-12-21 13:46:08 -0800 | [diff] [blame] | 296 | -----------------+--------+--------' |
Marti Bolivar | 048d8d8 | 2017-08-04 17:14:24 -0400 | [diff] [blame] | 297 | result: BOOT_SWAP_TYPE_PERM | |
Christopher Collins | fd7eb5c | 2016-12-21 13:46:08 -0800 | [diff] [blame] | 298 | -----------------------------------' |
Fabio Utzig | 5bd4e58 | 2017-07-20 08:55:38 -0300 | [diff] [blame] | 299 | |
Christopher Collins | fd7eb5c | 2016-12-21 13:46:08 -0800 | [diff] [blame] | 300 | |
Fabio Utzig | 86fe4b2 | 2017-07-28 18:56:29 -0300 | [diff] [blame] | 301 | State III |
Christopher Collins | fd7eb5c | 2016-12-21 13:46:08 -0800 | [diff] [blame] | 302 | | slot-0 | slot-1 | |
| 303 | -----------------+--------+--------| |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 304 | magic | Good | Unset | |
Christopher Collins | fd7eb5c | 2016-12-21 13:46:08 -0800 | [diff] [blame] | 305 | image-ok | 0xff | Any | |
Fabio Utzig | 5bd4e58 | 2017-07-20 08:55:38 -0300 | [diff] [blame] | 306 | copy-done | 0x01 | Any | |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 307 | -----------------+--------+--------' |
Marti Bolivar | 048d8d8 | 2017-08-04 17:14:24 -0400 | [diff] [blame] | 308 | result: BOOT_SWAP_TYPE_REVERT | |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 309 | -----------------------------------' |
| 310 | |
Marti Bolivar | 048d8d8 | 2017-08-04 17:14:24 -0400 | [diff] [blame] | 311 | Any of the above three states results in mcuboot attempting to swap images. |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 312 | |
Marti Bolivar | 048d8d8 | 2017-08-04 17:14:24 -0400 | [diff] [blame] | 313 | Otherwise, mcuboot does not attempt to swap images, resulting in one of the |
| 314 | other three swap types, as illustrated by State IV. |
Fabio Utzig | 86fe4b2 | 2017-07-28 18:56:29 -0300 | [diff] [blame] | 315 | |
| 316 | |
| 317 | State IV |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 318 | | slot-0 | slot-1 | |
| 319 | -----------------+--------+--------| |
Fabio Utzig | 86fe4b2 | 2017-07-28 18:56:29 -0300 | [diff] [blame] | 320 | magic | Any | Any | |
| 321 | image-ok | Any | Any | |
Fabio Utzig | f9d4428 | 2017-07-20 15:05:13 -0300 | [diff] [blame] | 322 | copy-done | Any | Any | |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 323 | -----------------+--------+--------' |
Marti Bolivar | 048d8d8 | 2017-08-04 17:14:24 -0400 | [diff] [blame] | 324 | result: BOOT_SWAP_TYPE_NONE, | |
| 325 | BOOT_SWAP_TYPE_FAIL, or | |
| 326 | BOOT_SWAP_TYPE_PANIC | |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 327 | -----------------------------------' |
| 328 | |
Marti Bolivar | 048d8d8 | 2017-08-04 17:14:24 -0400 | [diff] [blame] | 329 | In State IV, when no errors occur, mcuboot will attempt to boot the contents of |
| 330 | slot 0 directly, and the result is BOOT_SWAP_TYPE_NONE. If the image in slot 0 |
| 331 | is not valid, the result is BOOT_SWAP_TYPE_FAIL. If a fatal error occurs during |
| 332 | boot, the result is BOOT_SWAP_TYPE_PANIC. If the result is either |
| 333 | BOOT_SWAP_TYPE_FAIL or BOOT_SWAP_TYPE_PANIC, mcuboot hangs rather than booting |
| 334 | an invalid or compromised image. |
Fabio Utzig | 86fe4b2 | 2017-07-28 18:56:29 -0300 | [diff] [blame] | 335 | |
Marti Bolivar | 048d8d8 | 2017-08-04 17:14:24 -0400 | [diff] [blame] | 336 | Note: An important caveat to the above is the result when a swap is requested |
| 337 | and the image in slot 1 fails to validate, due to a hashing or signing |
| 338 | error. This state behaves as State IV with the extra action of marking |
| 339 | the image in slot 0 as "OK", to prevent further attempts to swap. |
Fabio Utzig | 86fe4b2 | 2017-07-28 18:56:29 -0300 | [diff] [blame] | 340 | |
| 341 | |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 342 | *** HIGH-LEVEL OPERATION |
| 343 | |
| 344 | With the terms defined, we can now explore the boot loader's operation. First, |
| 345 | a high-level overview of the boot process is presented. Then, the following |
| 346 | sections describe each step of the process in more detail. |
| 347 | |
| 348 | Procedure: |
| 349 | |
Fabio Utzig | 86fe4b2 | 2017-07-28 18:56:29 -0300 | [diff] [blame] | 350 | A. Inspect swap status region; is an interrupted swap being resumed? |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 351 | Yes: Complete the partial swap operation; skip to step C. |
| 352 | No: Proceed to step B. |
| 353 | |
Fabio Utzig | 86fe4b2 | 2017-07-28 18:56:29 -0300 | [diff] [blame] | 354 | B. Inspect image trailers; is a swap requested? |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 355 | Yes. |
| 356 | 1. Is the requested image valid (integrity and security check)? |
| 357 | Yes. |
| 358 | a. Perform swap operation. |
Fabio Utzig | 86fe4b2 | 2017-07-28 18:56:29 -0300 | [diff] [blame] | 359 | b. Persist completion of swap procedure to image trailers. |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 360 | c. Proceed to step C. |
| 361 | No. |
| 362 | a. Erase invalid image. |
Fabio Utzig | 86fe4b2 | 2017-07-28 18:56:29 -0300 | [diff] [blame] | 363 | b. Persist failure of swap procedure to image trailers. |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 364 | c. Proceed to step C. |
| 365 | No: Proceed to step C. |
| 366 | |
| 367 | C. Boot into image in slot 0. |
| 368 | |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 369 | *** IMAGE SWAPPING |
| 370 | |
| 371 | The boot loader swaps the contents of the two image slots for two reasons: |
Christopher Collins | fd7eb5c | 2016-12-21 13:46:08 -0800 | [diff] [blame] | 372 | * User has issued a "set pending" operation; the image in slot-1 should be |
| 373 | run once (state II) or repeatedly (state III), depending on whether a |
| 374 | permanent swap was specified. |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 375 | * Test image rebooted without being confirmed; the boot loader should |
Christopher Collins | fd7eb5c | 2016-12-21 13:46:08 -0800 | [diff] [blame] | 376 | revert to the original image currently in slot-1 (state IV). |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 377 | |
Fabio Utzig | 86fe4b2 | 2017-07-28 18:56:29 -0300 | [diff] [blame] | 378 | If the image trailers indicates that the image in the secondary slot should be |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 379 | run, the boot loader needs to copy it to the primary slot. The image currently |
| 380 | in the primary slot also needs to be retained in flash so that it can be used |
| 381 | later. Furthermore, both images need to be recoverable if the boot loader |
| 382 | resets in the middle of the swap operation. The two images are swapped |
| 383 | according to the following procedure: |
| 384 | |
| 385 | 1. Determine how many flash sectors each image slot consists of. This |
| 386 | number must be the same for both slots. |
| 387 | 2. Iterate the list of sector indices in descending order (i.e., starting |
| 388 | with the greatest index); current element = "index". |
| 389 | b. Erase scratch area. |
| 390 | c. Copy slot0[index] to scratch area. |
Fabio Utzig | 5bd4e58 | 2017-07-20 08:55:38 -0300 | [diff] [blame] | 391 | - If these are the last sectors (i.e., first swap being perfomed), |
| 392 | copy the full sector *except* the image trailer. |
| 393 | - Else, copy entire sector contents. |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 394 | d. Write updated swap status (i). |
| 395 | |
| 396 | e. Erase slot1[index] |
| 397 | f. Copy slot0[index] to slot1[index] |
| 398 | - If these are the last sectors (i.e., first swap being perfomed), |
| 399 | copy the full sector *except* the image trailer. |
| 400 | - Else, copy entire sector contents. |
| 401 | g. Write updated swap status (ii). |
| 402 | |
| 403 | h. Erase slot0[index]. |
| 404 | i. Copy scratch area slot0[index]. |
Fabio Utzig | 5bd4e58 | 2017-07-20 08:55:38 -0300 | [diff] [blame] | 405 | - If these are the last sectors (i.e., first swap being perfomed), |
| 406 | copy the full sector *except* the image trailer. |
| 407 | - Else, copy entire sector contents. |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 408 | j. Write updated swap status (iii). |
| 409 | |
| 410 | 3. Persist completion of swap procedure to slot 0 image trailer. |
| 411 | |
Christopher Collins | fd7eb5c | 2016-12-21 13:46:08 -0800 | [diff] [blame] | 412 | The additional caveats in step 2f are necessary so that the slot 1 image |
| 413 | trailer can be written by the user at a later time. With the image trailer |
| 414 | unwritten, the user can test the image in slot 1 (i.e., transition to state |
| 415 | II). |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 416 | |
Fabio Utzig | 5bd4e58 | 2017-07-20 08:55:38 -0300 | [diff] [blame] | 417 | Note1: If the sector being copied is the last sector, then swap status is |
| 418 | temporarily maintained on scratch for the duration of this operation, always |
| 419 | using slot0's area otherwise. |
| 420 | |
| 421 | Note2: The bootloader tries to copy only used sectors (based on largest image |
| 422 | installed on any of the slots), minimizing the amount of sectors copied and |
| 423 | reducing the amount of time required for a swap operation. |
| 424 | |
Christopher Collins | fd7eb5c | 2016-12-21 13:46:08 -0800 | [diff] [blame] | 425 | The particulars of step 3 vary depending on whether an image is being tested, |
Fabio Utzig | 86fe4b2 | 2017-07-28 18:56:29 -0300 | [diff] [blame] | 426 | permanently used, reverted or a validation failure of slot 1 happened when a |
| 427 | swap was requested: |
| 428 | |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 429 | * test: |
| 430 | o Write slot0.copy_done = 1 |
Christopher Collins | fd7eb5c | 2016-12-21 13:46:08 -0800 | [diff] [blame] | 431 | (swap caused the following values to be written: |
| 432 | slot0.magic = BOOT_MAGIC |
| 433 | slot0.image_ok = Unset) |
Christopher Collins | fd7eb5c | 2016-12-21 13:46:08 -0800 | [diff] [blame] | 434 | |
| 435 | * permanent: |
| 436 | o Write slot0.copy_done = 1 |
| 437 | (swap caused the following values to be written: |
| 438 | slot0.magic = BOOT_MAGIC |
| 439 | slot0.image_ok = 0x01) |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 440 | |
| 441 | * revert: |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 442 | o Write slot0.copy_done = 1 |
| 443 | o Write slot0.image_ok = 1 |
Fabio Utzig | 86fe4b2 | 2017-07-28 18:56:29 -0300 | [diff] [blame] | 444 | (swap caused the following values to be written: |
| 445 | slot0.magic = BOOT_MAGIC) |
| 446 | |
| 447 | * failure to validate slot 1: |
| 448 | o Write slot0.image_ok = 1 |
| 449 | |
| 450 | After completing the operations as described above the image in slot 0 should |
| 451 | be booted. |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 452 | |
| 453 | *** SWAP STATUS |
| 454 | |
| 455 | The swap status region allows the boot loader to recover in case it restarts in |
| 456 | the middle of an image swap operation. The swap status region consists of a |
| 457 | series of single-byte records. These records are written independently, and |
| 458 | therefore must be padded according to the minimum write size imposed by the |
| 459 | flash hardware. In the below figure, a min-write-size of 1 is assumed for |
| 460 | simplicity. The structure of the swap status region is illustrated below. In |
| 461 | this figure, a min-write-size of 1 is assumed for simplicity. |
| 462 | |
| 463 | 0 1 2 3 |
| 464 | 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 |
| 465 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 466 | |sec127,state 0 |sec127,state 1 |sec127,state 2 |sec126,state 0 | |
| 467 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 468 | |sec126,state 1 |sec126,state 2 |sec125,state 0 |sec125,state 1 | |
| 469 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 470 | |sec125,state 2 | | |
| 471 | +-+-+-+-+-+-+-+-+ + |
| 472 | ~ ~ |
| 473 | ~ [Records for indices 124 through 1 ~ |
| 474 | ~ ~ |
| 475 | ~ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 476 | ~ |sec000,state 0 |sec000,state 1 |sec000,state 2 | |
| 477 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 478 | |
| 479 | The above is probably not helpful at all; here is a description in English. |
| 480 | |
| 481 | Each image slot is partitioned into a sequence of flash sectors. If we were to |
| 482 | enumerate the sectors in a single slot, starting at 0, we would have a list of |
| 483 | sector indices. Since there are two image slots, each sector index would |
| 484 | correspond to a pair of sectors. For example, sector index 0 corresponds to |
| 485 | the first sector in slot 0 and the first sector in slot 1. Furthermore, we |
| 486 | impose a limit of 128 indices. If an image slot consists of more than 128 |
| 487 | sectors, the flash layout is not compatible with this boot loader. Finally, |
| 488 | reverse the list of indices such that the list starts with index 127 and ends |
| 489 | with 0. The swap status region is a representation of this reversed list. |
| 490 | |
| 491 | During a swap operation, each sector index transitions through four separate |
| 492 | states: |
| 493 | 0. slot 0: image 0, slot 1: image 1, scratch: N/A |
| 494 | 1. slot 0: image 0, slot 1: N/A, scratch: image 1 (1->s, erase 1) |
| 495 | 2. slot 0: N/A, slot 1: image 0, scratch: image 1 (0->1, erase 0) |
| 496 | 3. slot 0: image 1, slot 1: image 0, scratch: N/A (s->0) |
| 497 | |
| 498 | Each time a sector index transitions to a new state, the boot loader writes a |
| 499 | record to the swap status region. Logically, the boot loader only needs one |
| 500 | record per sector index to keep track of the current swap state. However, due |
| 501 | to limitations imposed by flash hardware, a record cannot be overwritten when |
| 502 | an index's state changes. To solve this problem, the boot loader uses three |
| 503 | records per sector index rather than just one. |
| 504 | |
| 505 | Each sector-state pair is represented as a set of three records. The record |
| 506 | values map to the above four states as follows |
| 507 | |
| 508 | | rec0 | rec1 | rec2 |
| 509 | --------+------+------+------ |
| 510 | state 0 | 0xff | 0xff | 0xff |
| 511 | state 1 | 0x01 | 0xff | 0xff |
| 512 | state 2 | 0x01 | 0x02 | 0xff |
| 513 | state 3 | 0x01 | 0x02 | 0x03 |
| 514 | |
| 515 | The swap status region can accommodate 128 sector indices. Hence, the size of |
| 516 | the region, in bytes, is 128 * min-write-size * 3. The number 128 is chosen |
| 517 | somewhat arbitrarily and will likely be made configurable. The only |
| 518 | requirement for the index count is that is is great enough to account for a |
| 519 | maximum-sized image (i.e., at least as great as the total sector count in an |
| 520 | image slot). If a device's image slots use less than 128 sectors, the first |
| 521 | record that gets written will be somewhere in the middle of the region. For |
| 522 | example, if a slot uses 64 sectors, the first sector index that gets swapped is |
| 523 | 63, which corresponds to the exact halfway point within the region. |
| 524 | |
Fabio Utzig | 5bd4e58 | 2017-07-20 08:55:38 -0300 | [diff] [blame] | 525 | Note: since the scratch area only ever needs to record swapping of the last |
| 526 | sector, it uses at most min-write-size * 3 bytes for its own status area. |
| 527 | |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 528 | *** RESET RECOVERY |
| 529 | |
| 530 | If the boot loader resets in the middle of a swap operation, the two images may |
| 531 | be discontiguous in flash. Bootutil recovers from this condition by using the |
Fabio Utzig | 86fe4b2 | 2017-07-28 18:56:29 -0300 | [diff] [blame] | 532 | image trailers to determine how the image parts are distributed in flash. |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 533 | |
| 534 | The first step is determine where the relevant swap status region is located. |
| 535 | Because this region is embedded within the image slots, its location in flash |
Fabio Utzig | 86fe4b2 | 2017-07-28 18:56:29 -0300 | [diff] [blame] | 536 | changes during a swap operation. The below set of tables map image trailers |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 537 | contents to swap status location. In these tables, the "source" field |
| 538 | indicates where the swap status region is located. |
| 539 | |
| 540 | | slot-0 | scratch | |
| 541 | ----------+------------+------------| |
| 542 | magic | Good | Any | |
| 543 | copy-done | 0x01 | N/A | |
| 544 | ----------+------------+------------' |
| 545 | source: none | |
| 546 | ------------------------------------' |
Marti Bolivar | 49b2917 | 2017-08-04 14:50:51 -0400 | [diff] [blame] | 547 | |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 548 | | slot-0 | scratch | |
| 549 | ----------+------------+------------| |
| 550 | magic | Good | Any | |
| 551 | copy-done | 0xff | N/A | |
| 552 | ----------+------------+------------' |
| 553 | source: slot 0 | |
| 554 | ------------------------------------' |
Marti Bolivar | 49b2917 | 2017-08-04 14:50:51 -0400 | [diff] [blame] | 555 | |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 556 | | slot-0 | scratch | |
| 557 | ----------+------------+------------| |
| 558 | magic | Any | Good | |
| 559 | copy-done | Any | N/A | |
| 560 | ----------+------------+------------' |
| 561 | source: scratch | |
| 562 | ------------------------------------' |
Marti Bolivar | 49b2917 | 2017-08-04 14:50:51 -0400 | [diff] [blame] | 563 | |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 564 | | slot-0 | scratch | |
| 565 | ----------+------------+------------| |
| 566 | magic | Unset | Any | |
| 567 | copy-done | 0xff | N/A | |
| 568 | ----------+------------+------------| |
Fabio Utzig | 86fe4b2 | 2017-07-28 18:56:29 -0300 | [diff] [blame] | 569 | source: slot 0 | |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 570 | ------------------------------------+------------------------------+ |
| 571 | This represents one of two cases: | |
| 572 | o No swaps ever (no status to read, so no harm in checking). | |
| 573 | o Mid-revert; status in slot 0. | |
Fabio Utzig | 86fe4b2 | 2017-07-28 18:56:29 -0300 | [diff] [blame] | 574 | For this reason we assume slot 0 as source, to trigger a check | |
| 575 | of the status area and find out if there was swapping under way. | |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 576 | -------------------------------------------------------------------' |
| 577 | |
| 578 | |
| 579 | If the swap status region indicates that the images are not contiguous, |
| 580 | bootutil completes the swap operation that was in progress when the system was |
| 581 | reset. In other words, it applies the procedure defined in the previous |
| 582 | section, moving image 1 into slot 0 and image 0 into slot 1. If the boot |
| 583 | status file indicates that an image part is present in the scratch area, this |
| 584 | part is copied into the correct location by starting at step e or step h in the |
| 585 | area-swap procedure, depending on whether the part belongs to image 0 or image |
| 586 | 1. |
| 587 | |
| 588 | After the swap operation has been completed, the boot loader proceeds as though |
| 589 | it had just been started. |
| 590 | |
| 591 | *** INTEGRITY CHECK |
| 592 | |
| 593 | An image is checked for integrity immediately before it gets copied into the |
Fabio Utzig | 5bd4e58 | 2017-07-20 08:55:38 -0300 | [diff] [blame] | 594 | primary slot. If the boot loader doesn't perform an image swap, then it can |
| 595 | perform an optional integrity check of the image in slot0 if |
| 596 | MCUBOOT_VALIDATE_SLOT0 is set, otherwise it doesn't perform an integrity check. |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 597 | |
| 598 | During the integrity check, the boot loader verifies the following aspects of |
| 599 | an image: |
| 600 | * 32-bit magic number must be correct (0x96f3b83c). |
| 601 | * Image must contain a SHA256 TLV. |
Fabio Utzig | 86fe4b2 | 2017-07-28 18:56:29 -0300 | [diff] [blame] | 602 | * Calculated SHA256 must match SHA256 TLV contents. |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 603 | * Image *may* contain a signature TLV. If it does, its contents must be |
| 604 | verifiable using a key embedded in the boot loader. |
| 605 | |
| 606 | *** SECURITY |
| 607 | |
| 608 | As indicated above, the final step of the integrity check is signature |
| 609 | verification. The boot loader can have one or more public keys embedded in it |
| 610 | at build time. During signature verification, the boot loader verifies that an |
| 611 | image was signed with a private key that corresponds to one of its public keys. |
| 612 | The image signature TLV indicates the index of the key that is has been signed |
| 613 | with. The boot loader uses this index to identify the corresponding public |
| 614 | key. |
| 615 | |
| 616 | For information on embedding public keys in the boot loader, as well as |
Fabio Utzig | 5bd4e58 | 2017-07-20 08:55:38 -0300 | [diff] [blame] | 617 | producing signed images, see: doc/signed_images.md |