blob: 5d25ec13abe360153392c7c9643befceadb61706 [file] [log] [blame]
Christopher Collins92ea77f2016-12-12 15:59:26 -08001#
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
9#
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
24The Mynewt bootloader comprises two packages:
25
26 * The bootutil library (boot/bootutil)
27 * The boot application (apps/boot)
28
29The bootutil library performs most of the functions of a boot loader. In
30particular, the piece that is missing is the final step of actually jumping to
31the main image. This last step is instead implemented by the boot application.
32Boot loader functionality is separated in this manner to enable unit testing of
33the boot loader. A library can be unit tested, but an application can't.
34Therefore, functionality is delegated to the bootutil library when possible.
35
36*** LIMITATIONS
37
38The boot loader currently only supports images with the following
39characteristics:
40 * Built to run from flash.
41 * Build to run from a fixed location (i.e., not position-independent).
42
43*** IMAGE FORMAT
44
45The following definitions describe the image format.
46
47#define IMAGE_MAGIC 0x96f3b83c
48
49#define IMAGE_HEADER_SIZE 32
50
51struct 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. */
59struct 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. */
73struct image_tlv {
74 uint8_t it_type; /* IMAGE_TLV_[...]. */
75 uint8_t _pad;
76 uint16_t it_len /* Data length (not including TLV header). */
77};
78
79/*
80 * Image header flags.
81 */
82#define IMAGE_F_PIC 0x00000001 /* Not currently supported. */
83#define IMAGE_F_SHA256 0x00000002 /* Image contains hash TLV */
84#define IMAGE_F_PKCS15_RSA2048_SHA256 0x00000004 /* PKCS15 w/RSA and SHA */
85#define IMAGE_F_ECDSA224_SHA256 0x00000008 /* ECDSA256 over SHA256 */
86#define IMAGE_F_NON_BOOTABLE 0x00000010 /* Split image app. */
Fabio Utzig150ea962017-03-08 11:25:09 -030087#define IMAGE_F_ECDSA256_SHA256 0x00000020 /* ECDSA256 over SHA256 */
Christopher Collins92ea77f2016-12-12 15:59:26 -080088
89/*
90 * Image trailer TLV types.
91 */
Fabio Utzig150ea962017-03-08 11:25:09 -030092#define IMAGE_TLV_SHA256 1 /* SHA256 of image hdr and body */
93#define IMAGE_TLV_RSA2048 2 /* RSA2048 of hash output */
Christopher Collins92ea77f2016-12-12 15:59:26 -080094#define IMAGE_TLV_ECDSA224 3 /* ECDSA of hash output */
Fabio Utzig150ea962017-03-08 11:25:09 -030095#define IMAGE_TLV_ECDSA256 4 /* ECDSA of hash output */
Christopher Collins92ea77f2016-12-12 15:59:26 -080096
97Optional type-length-value records (TLVs) containing image metadata are placed
98after the end of the image.
99
100The ih_hdr_size field indicates the length of the header, and therefore the
101offset of the image itself. This field provides for backwards compatibility in
102case of changes to the format of the image header.
103
104*** FLASH MAP
105
106A Mynewt device's flash is partitioned according to its _flash map_. At a high
107level, the flash map maps numeric IDs to _flash areas_. A flash area is a
108region of disk with the following properties:
109 (1) An area can be fully erased without affecting any other areas.
110 (2) A write to one area does not restrict writes to other areas.
111
112The boot loader uses the following flash areas:
113
114#define FLASH_AREA_BOOTLOADER 0
115#define FLASH_AREA_IMAGE_0 1
116#define FLASH_AREA_IMAGE_1 2
117#define FLASH_AREA_IMAGE_SCRATCH 3
118
119*** IMAGE SLOTS
120
121A portion of the flash memory is partitioned into two image slots: a primary
122slot (0) and a secondary slot (1). The boot loader will only run an image from
123the primary slot, so images must be built such that they can run from that
124fixed location in flash. If the boot loader needs to run the image resident in
125the secondary slot, it must swap the two images in flash prior to booting.
126
127In addition to the two image slots, the boot loader requires a scratch area to
128allow for reliable image swapping.
129
Christopher Collinsfd7eb5c2016-12-21 13:46:08 -0800130*** BOOT STATES
131
132Logically, you can think of a pair of values associated with each image slot:
133pending and confirmed. On startup, the boot loader determines the state of the
134device by inspecting each pair of values. These values have the following
135meanings:
136
137* pending: Indicates whether the image should be used on the next reboot; can
138 hold one of three values:
139 " " (unset): Don't use image on next boot
140 "T" (temporary): Use image on next boot; absent subsequent confirm command,
141 revert to original image on second reboot.
142 "P" (permanent): Use image on next boot and all subsequent boots
143
144* confirmed: always use image unless excluded by a test image.
145
146In English, when the user wants to run the secondary image, they set the
147pending flag for the second slot and reboot the device. On startup, the boot
148loader will swap the two images in flash, clear the secondary slot's pending
149flag, and run the newly-copied image in slot 0. If the user set the pending
150flag to "temporary," then this is only a temporary state; if the device reboots
151again, the boot loader swaps the images back to their original slots and boots
152into the original image. If the user doesn't want to revert to the original
153state, they can make the current state permanent by setting the confirmed flag
154in slot 0.
155
156Switching to an alternate image is a two-step process (set + confirm) to
157prevent a device from becoming "bricked" by bad firmware. If the device
158crashes immediately upon booting the second image, the boot loader reverts to
159the working image, rather than repeatedly rebooting into the bad image.
160
161Alternatively, if the user is confident that the second image is good, they can
162set and confirm in a single action by setting the pending flag to "permanent."
163
164The following set of tables illustrate the four possible states that the device
165can be in:
166
167 | slot-0 | slot-1 |
168 ---------------+--------+--------|
169 pending | | |
170 confirmed | X | |
171 ---------------+--------+--------'
172 Image 0 confirmed; |
173 No change on reboot |
174 ---------------------------------'
175
176 | slot-0 | slot-1 |
177 ---------------+--------+--------|
178 pending | | T |
179 confirmed | X | |
180 ---------------+--------+--------'
181 Image 0 confirmed; |
182 Test image 1 on next reboot |
183 ---------------------------------'
184
185 | slot-0 | slot-1 |
186 ---------------+--------+--------|
187 pending | | P |
188 confirmed | X | |
189 ---------------+--------+--------'
190 Image 0 confirmed; |
191 Use image 1 permanently on boot |
192 ---------------------------------'
193
194 | slot-0 | slot-1 |
195 ---------------+--------+--------|
196 pending | | |
197 confirmed | | X |
198 ---------------+--------+--------'
199 Testing image 0; |
200 Revert to image 1 on next reboot |
201 ---------------------------------'
202
Christopher Collins92ea77f2016-12-12 15:59:26 -0800203*** BOOT VECTOR
204
205At startup, the boot loader determines which of the above three states the
206device is in by inspecting the boot vector. The boot vector consists of two
207records (called "image trailers"), one written at the end of each image slot.
208An image trailer has the following structure:
209
210 0 1 2 3
211 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
212 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
213 ~ MAGIC (16 octets) ~
214 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
215 ~ ~
216 ~ Swap status (128 * min-write-size * 3) ~
217 ~ ~
218 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
219 | Copy done | 0xff padding (up to min-write-sz - 1) ~
220 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
221 | Image OK | 0xff padding (up to min-write-sz - 1) ~
222 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
223
224These records are at the end of each image slot. The offset immediately
225following such a record represents the start of the next flash area.
226
227Note: "min-write-size" is a property of the flash hardware. If the hardware
228allows individual bytes to be written at arbitrary addresses, then
229min-write-size is 1. If the hardware only allows writes at even addresses,
230then min-write-size is 2, and so on.
231
232The fields are defined as follows:
233
2341. MAGIC: The following 16 bytes, written in host-byte-order:
235
236 const uint32_t boot_img_magic[4] = {
237 0xf395c277,
238 0x7fefd260,
239 0x0f505235,
240 0x8079b62c,
241 };
242
2432. Swap status: A series of single-byte records. Each record corresponds to a
244flash sector in an image slot. A swap status byte indicate the location of
245the corresponding sector data. During an image swap, image data is moved one
246sector at a time. The swap status is necessary for resuming a swap operation
247if the device rebooted before a swap operation completed.
248
2493. Copy done: A single byte indicating whether the image in this slot is
250complete (0x01=done; 0xff=not done).
251
2524. Image OK: A single byte indicating whether the image in this slot has been
253confirmed as good by the user (0x01=confirmed; 0xff=not confirmed).
254
255The boot vector records are structured around the limitations imposed by flash
256hardware. As a consequence, they do not have a very intuitive design, and it
257is difficult to get a sense of the state of the device just by looking at the
258boot vector. It is better to map all the possible vector states to the three
259states described above via a set of tables. These tables are reproduced below.
260In these tables, the "pending" and "confirmed" flags are shown for illustrative
261purposes; they are not actually present in the boot vector.
262
263
264 State I
265 | slot-0 | slot-1 |
266 -----------------+--------+--------|
267 magic | Unset | Unset |
Christopher Collinsfd7eb5c2016-12-21 13:46:08 -0800268 image-ok | Any | Any |
Christopher Collins92ea77f2016-12-12 15:59:26 -0800269 -----------------+--------+--------'
270 pending | | |
271 confirmed | X | |
272 -----------------+--------+--------'
273 swap: none |
274 -----------------------------------'
275
276
277 State II
278 | slot-0 | slot-1 |
279 -----------------+--------+--------|
280 magic | Any | Good |
Christopher Collinsfd7eb5c2016-12-21 13:46:08 -0800281 image-ok | Any | Unset |
Christopher Collins92ea77f2016-12-12 15:59:26 -0800282 -----------------+--------+--------'
Christopher Collinsfd7eb5c2016-12-21 13:46:08 -0800283 pending | | T |
Christopher Collins92ea77f2016-12-12 15:59:26 -0800284 confirmed | X | |
Christopher Collinsfd7eb5c2016-12-21 13:46:08 -0800285 -----------------+--------+--------'
286 swap: test |
287 -----------------------------------'
288
Christopher Collins92ea77f2016-12-12 15:59:26 -0800289
290 State III
291 | slot-0 | slot-1 |
292 -----------------+--------+--------|
Christopher Collinsfd7eb5c2016-12-21 13:46:08 -0800293 magic | Any | Good |
294 image-ok | Any | 0x01 |
295 -----------------+--------+--------'
296 pending | | P |
297 confirmed | X | |
298 -----------------+--------+--------'
299 swap: permanent |
300 -----------------------------------'
301
302
303 State IV
304 | slot-0 | slot-1 |
305 -----------------+--------+--------|
Christopher Collins92ea77f2016-12-12 15:59:26 -0800306 magic | Good | Unset |
Christopher Collinsfd7eb5c2016-12-21 13:46:08 -0800307 image-ok | 0xff | Any |
Christopher Collins92ea77f2016-12-12 15:59:26 -0800308 -----------------+--------+--------'
309 pending | | |
310 confirmed | | X |
311 -----------------+--------+--------'
312 swap: revert (test image running) |
313 -----------------------------------'
314
315
Christopher Collinsfd7eb5c2016-12-21 13:46:08 -0800316 State V
Christopher Collins92ea77f2016-12-12 15:59:26 -0800317 | slot-0 | slot-1 |
318 -----------------+--------+--------|
319 magic | Good | Unset |
Christopher Collinsfd7eb5c2016-12-21 13:46:08 -0800320 image-ok | 0x01 | Any |
Christopher Collins92ea77f2016-12-12 15:59:26 -0800321 -----------------+--------+--------'
322 pending | | |
323 confirmed | X | |
324 -----------------+--------+--------'
325 swap: none (confirmed test image) |
326 -----------------------------------'
327
328*** HIGH-LEVEL OPERATION
329
330With the terms defined, we can now explore the boot loader's operation. First,
331a high-level overview of the boot process is presented. Then, the following
332sections describe each step of the process in more detail.
333
334Procedure:
335
336A. Inspect swap status region; is an interrupted swap is being resumed?
337 Yes: Complete the partial swap operation; skip to step C.
338 No: Proceed to step B.
339
340B. Insect boot vector; is a swap requested?
341 Yes.
342 1. Is the requested image valid (integrity and security check)?
343 Yes.
344 a. Perform swap operation.
345 b. Persist completion of swap procedure to boot vector.
346 c. Proceed to step C.
347 No.
348 a. Erase invalid image.
349 b. Persist failure of swap procedure to boot vector.
350 c. Proceed to step C.
351 No: Proceed to step C.
352
353C. Boot into image in slot 0.
354
Christopher Collins92ea77f2016-12-12 15:59:26 -0800355
356
357*** IMAGE SWAPPING
358
359The boot loader swaps the contents of the two image slots for two reasons:
Christopher Collinsfd7eb5c2016-12-21 13:46:08 -0800360 * User has issued a "set pending" operation; the image in slot-1 should be
361 run once (state II) or repeatedly (state III), depending on whether a
362 permanent swap was specified.
Christopher Collins92ea77f2016-12-12 15:59:26 -0800363 * Test image rebooted without being confirmed; the boot loader should
Christopher Collinsfd7eb5c2016-12-21 13:46:08 -0800364 revert to the original image currently in slot-1 (state IV).
Christopher Collins92ea77f2016-12-12 15:59:26 -0800365
366If the boot vector indicates that the image in the secondary slot should be
367run, the boot loader needs to copy it to the primary slot. The image currently
368in the primary slot also needs to be retained in flash so that it can be used
369later. Furthermore, both images need to be recoverable if the boot loader
370resets in the middle of the swap operation. The two images are swapped
371according to the following procedure:
372
373 1. Determine how many flash sectors each image slot consists of. This
374 number must be the same for both slots.
375 2. Iterate the list of sector indices in descending order (i.e., starting
376 with the greatest index); current element = "index".
377 b. Erase scratch area.
378 c. Copy slot0[index] to scratch area.
379 d. Write updated swap status (i).
380
381 e. Erase slot1[index]
382 f. Copy slot0[index] to slot1[index]
383 - If these are the last sectors (i.e., first swap being perfomed),
384 copy the full sector *except* the image trailer.
385 - Else, copy entire sector contents.
386 g. Write updated swap status (ii).
387
388 h. Erase slot0[index].
389 i. Copy scratch area slot0[index].
390 j. Write updated swap status (iii).
391
392 3. Persist completion of swap procedure to slot 0 image trailer.
393
Christopher Collinsfd7eb5c2016-12-21 13:46:08 -0800394The additional caveats in step 2f are necessary so that the slot 1 image
395trailer can be written by the user at a later time. With the image trailer
396unwritten, the user can test the image in slot 1 (i.e., transition to state
397II).
Christopher Collins92ea77f2016-12-12 15:59:26 -0800398
Christopher Collinsfd7eb5c2016-12-21 13:46:08 -0800399The particulars of step 3 vary depending on whether an image is being tested,
400permanently used, or reverted:
Christopher Collins92ea77f2016-12-12 15:59:26 -0800401 * test:
402 o Write slot0.copy_done = 1
Christopher Collinsfd7eb5c2016-12-21 13:46:08 -0800403 (swap caused the following values to be written:
404 slot0.magic = BOOT_MAGIC
405 slot0.image_ok = Unset)
406 (should now be in state IV)
407
408 * permanent:
409 o Write slot0.copy_done = 1
410 (swap caused the following values to be written:
411 slot0.magic = BOOT_MAGIC
412 slot0.image_ok = 0x01)
413 (should now be in state V)
Christopher Collins92ea77f2016-12-12 15:59:26 -0800414
415 * revert:
416 o Write slot0.magic = BOOT_MAGIC
417 o Write slot0.copy_done = 1
418 o Write slot0.image_ok = 1
Christopher Collinsfd7eb5c2016-12-21 13:46:08 -0800419 (should now be in state V)
Christopher Collins92ea77f2016-12-12 15:59:26 -0800420
421*** SWAP STATUS
422
423The swap status region allows the boot loader to recover in case it restarts in
424the middle of an image swap operation. The swap status region consists of a
425series of single-byte records. These records are written independently, and
426therefore must be padded according to the minimum write size imposed by the
427flash hardware. In the below figure, a min-write-size of 1 is assumed for
428simplicity. The structure of the swap status region is illustrated below. In
429this figure, a min-write-size of 1 is assumed for simplicity.
430
431 0 1 2 3
432 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
433 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
434 |sec127,state 0 |sec127,state 1 |sec127,state 2 |sec126,state 0 |
435 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
436 |sec126,state 1 |sec126,state 2 |sec125,state 0 |sec125,state 1 |
437 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
438 |sec125,state 2 | |
439 +-+-+-+-+-+-+-+-+ +
440 ~ ~
441 ~ [Records for indices 124 through 1 ~
442 ~ ~
443 ~ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
444 ~ |sec000,state 0 |sec000,state 1 |sec000,state 2 |
445 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
446
447The above is probably not helpful at all; here is a description in English.
448
449Each image slot is partitioned into a sequence of flash sectors. If we were to
450enumerate the sectors in a single slot, starting at 0, we would have a list of
451sector indices. Since there are two image slots, each sector index would
452correspond to a pair of sectors. For example, sector index 0 corresponds to
453the first sector in slot 0 and the first sector in slot 1. Furthermore, we
454impose a limit of 128 indices. If an image slot consists of more than 128
455sectors, the flash layout is not compatible with this boot loader. Finally,
456reverse the list of indices such that the list starts with index 127 and ends
457with 0. The swap status region is a representation of this reversed list.
458
459During a swap operation, each sector index transitions through four separate
460states:
461 0. slot 0: image 0, slot 1: image 1, scratch: N/A
462 1. slot 0: image 0, slot 1: N/A, scratch: image 1 (1->s, erase 1)
463 2. slot 0: N/A, slot 1: image 0, scratch: image 1 (0->1, erase 0)
464 3. slot 0: image 1, slot 1: image 0, scratch: N/A (s->0)
465
466Each time a sector index transitions to a new state, the boot loader writes a
467record to the swap status region. Logically, the boot loader only needs one
468record per sector index to keep track of the current swap state. However, due
469to limitations imposed by flash hardware, a record cannot be overwritten when
470an index's state changes. To solve this problem, the boot loader uses three
471records per sector index rather than just one.
472
473Each sector-state pair is represented as a set of three records. The record
474values map to the above four states as follows
475
476 | rec0 | rec1 | rec2
477 --------+------+------+------
478 state 0 | 0xff | 0xff | 0xff
479 state 1 | 0x01 | 0xff | 0xff
480 state 2 | 0x01 | 0x02 | 0xff
481 state 3 | 0x01 | 0x02 | 0x03
482
483The swap status region can accommodate 128 sector indices. Hence, the size of
484the region, in bytes, is 128 * min-write-size * 3. The number 128 is chosen
485somewhat arbitrarily and will likely be made configurable. The only
486requirement for the index count is that is is great enough to account for a
487maximum-sized image (i.e., at least as great as the total sector count in an
488image slot). If a device's image slots use less than 128 sectors, the first
489record that gets written will be somewhere in the middle of the region. For
490example, if a slot uses 64 sectors, the first sector index that gets swapped is
49163, which corresponds to the exact halfway point within the region.
492
493
494*** RESET RECOVERY
495
496If the boot loader resets in the middle of a swap operation, the two images may
497be discontiguous in flash. Bootutil recovers from this condition by using the
498boot vector to determine how the image parts are distributed in flash.
499
500The first step is determine where the relevant swap status region is located.
501Because this region is embedded within the image slots, its location in flash
502changes during a swap operation. The below set of tables map boot vector
503contents to swap status location. In these tables, the "source" field
504indicates where the swap status region is located.
505
506 | slot-0 | scratch |
507 ----------+------------+------------|
508 magic | Good | Any |
509 copy-done | 0x01 | N/A |
510 ----------+------------+------------'
511 source: none |
512 ------------------------------------'
513
514 | slot-0 | scratch |
515 ----------+------------+------------|
516 magic | Good | Any |
517 copy-done | 0xff | N/A |
518 ----------+------------+------------'
519 source: slot 0 |
520 ------------------------------------'
521
522 | slot-0 | scratch |
523 ----------+------------+------------|
524 magic | Any | Good |
525 copy-done | Any | N/A |
526 ----------+------------+------------'
527 source: scratch |
528 ------------------------------------'
529
530 | slot-0 | scratch |
531 ----------+------------+------------|
532 magic | Unset | Any |
533 copy-done | 0xff | N/A |
534 ----------+------------+------------|
535 source: varies |
536 ------------------------------------+------------------------------+
537 This represents one of two cases: |
538 o No swaps ever (no status to read, so no harm in checking). |
539 o Mid-revert; status in slot 0. |
540 -------------------------------------------------------------------'
541
542
543If the swap status region indicates that the images are not contiguous,
544bootutil completes the swap operation that was in progress when the system was
545reset. In other words, it applies the procedure defined in the previous
546section, moving image 1 into slot 0 and image 0 into slot 1. If the boot
547status file indicates that an image part is present in the scratch area, this
548part is copied into the correct location by starting at step e or step h in the
549area-swap procedure, depending on whether the part belongs to image 0 or image
5501.
551
552After the swap operation has been completed, the boot loader proceeds as though
553it had just been started.
554
555*** INTEGRITY CHECK
556
557An image is checked for integrity immediately before it gets copied into the
558primary slot. If the boot loader doesn't perform an image swap, then it
559doesn't perform an integrity check.
560
561During the integrity check, the boot loader verifies the following aspects of
562an image:
563 * 32-bit magic number must be correct (0x96f3b83c).
564 * Image must contain a SHA256 TLV.
565 * Calculated SHA256 must matche SHA256 TLV contents.
566 * Image *may* contain a signature TLV. If it does, its contents must be
567 verifiable using a key embedded in the boot loader.
568
569*** SECURITY
570
571As indicated above, the final step of the integrity check is signature
572verification. The boot loader can have one or more public keys embedded in it
573at build time. During signature verification, the boot loader verifies that an
574image was signed with a private key that corresponds to one of its public keys.
575The image signature TLV indicates the index of the key that is has been signed
576with. The boot loader uses this index to identify the corresponding public
577key.
578
579For information on embedding public keys in the boot loader, as well as
580producing signed images, see: boot/bootutil/signed_images.md