Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [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 |
| 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 | |
David Vincze | 91b71ef | 2019-06-24 13:06:47 +0200 | [diff] [blame] | 20 | /* |
| 21 | * Original code taken from mcuboot project at: |
| 22 | * https://github.com/JuulLabs-OSS/mcuboot |
| 23 | * Git SHA of the original version: 3c469bc698a9767859ed73cd0201c44161204d5c |
| 24 | * Modifications are Copyright (c) 2019 Arm Limited. |
| 25 | */ |
| 26 | |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 27 | #include <assert.h> |
| 28 | #include <string.h> |
| 29 | #include <inttypes.h> |
| 30 | #include <stddef.h> |
| 31 | |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 32 | #include "flash_map/flash_map.h" |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 33 | #include "bootutil/image.h" |
| 34 | #include "bootutil/bootutil.h" |
| 35 | #include "bootutil_priv.h" |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 36 | #include "bootutil/bootutil_log.h" |
| 37 | |
| 38 | int boot_current_slot; |
| 39 | |
| 40 | const uint32_t boot_img_magic[] = { |
| 41 | 0xf395c277, |
| 42 | 0x7fefd260, |
| 43 | 0x0f505235, |
| 44 | 0x8079b62c, |
| 45 | }; |
| 46 | |
David Vincze | 39e7855 | 2018-10-10 17:10:01 +0200 | [diff] [blame] | 47 | #define BOOT_MAGIC_ARR_SZ \ |
| 48 | (sizeof boot_img_magic / sizeof boot_img_magic[0]) |
| 49 | |
Tamas Ban | 581034a | 2017-12-19 19:54:37 +0000 | [diff] [blame] | 50 | const uint32_t BOOT_MAGIC_SZ = sizeof(boot_img_magic); |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 51 | const uint32_t BOOT_MAX_ALIGN = MAX_FLASH_ALIGN; |
| 52 | |
| 53 | struct boot_swap_table { |
David Vincze | 8bdfc2d | 2019-03-18 15:49:23 +0100 | [diff] [blame] | 54 | uint8_t magic_primary_slot; |
| 55 | uint8_t magic_secondary_slot; |
| 56 | uint8_t image_ok_primary_slot; |
| 57 | uint8_t image_ok_secondary_slot; |
| 58 | uint8_t copy_done_primary_slot; |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 59 | |
| 60 | uint8_t swap_type; |
| 61 | }; |
| 62 | |
| 63 | /** |
| 64 | * This set of tables maps image trailer contents to swap operation type. |
| 65 | * When searching for a match, these tables must be iterated sequentially. |
| 66 | * |
David Vincze | 8bdfc2d | 2019-03-18 15:49:23 +0100 | [diff] [blame] | 67 | * NOTE: the table order is very important. The settings in the secondary |
| 68 | * slot always are priority to the primary slot and should be located |
| 69 | * earlier in the table. |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 70 | * |
| 71 | * The table lists only states where there is action needs to be taken by |
| 72 | * the bootloader, as in starting/finishing a swap operation. |
| 73 | */ |
| 74 | static const struct boot_swap_table boot_swap_tables[] = { |
| 75 | { |
David Vincze | 8bdfc2d | 2019-03-18 15:49:23 +0100 | [diff] [blame] | 76 | .magic_primary_slot = BOOT_MAGIC_ANY, |
| 77 | .magic_secondary_slot = BOOT_MAGIC_GOOD, |
| 78 | .image_ok_primary_slot = BOOT_FLAG_ANY, |
| 79 | .image_ok_secondary_slot = BOOT_FLAG_UNSET, |
| 80 | .copy_done_primary_slot = BOOT_FLAG_ANY, |
| 81 | .swap_type = BOOT_SWAP_TYPE_TEST, |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 82 | }, |
| 83 | { |
David Vincze | 8bdfc2d | 2019-03-18 15:49:23 +0100 | [diff] [blame] | 84 | .magic_primary_slot = BOOT_MAGIC_ANY, |
| 85 | .magic_secondary_slot = BOOT_MAGIC_GOOD, |
| 86 | .image_ok_primary_slot = BOOT_FLAG_ANY, |
| 87 | .image_ok_secondary_slot = BOOT_FLAG_SET, |
| 88 | .copy_done_primary_slot = BOOT_FLAG_ANY, |
| 89 | .swap_type = BOOT_SWAP_TYPE_PERM, |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 90 | }, |
| 91 | { |
David Vincze | 8bdfc2d | 2019-03-18 15:49:23 +0100 | [diff] [blame] | 92 | .magic_primary_slot = BOOT_MAGIC_GOOD, |
| 93 | .magic_secondary_slot = BOOT_MAGIC_UNSET, |
| 94 | .image_ok_primary_slot = BOOT_FLAG_UNSET, |
| 95 | .image_ok_secondary_slot = BOOT_FLAG_ANY, |
| 96 | .copy_done_primary_slot = BOOT_FLAG_SET, |
| 97 | .swap_type = BOOT_SWAP_TYPE_REVERT, |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 98 | }, |
| 99 | }; |
| 100 | |
| 101 | #define BOOT_SWAP_TABLES_COUNT \ |
Tamas Ban | 581034a | 2017-12-19 19:54:37 +0000 | [diff] [blame] | 102 | (sizeof(boot_swap_tables) / sizeof(boot_swap_tables[0])) |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 103 | |
Raef Coles | 25b857a | 2019-09-05 13:59:55 +0100 | [diff] [blame^] | 104 | /** |
| 105 | * @brief Determine if the data at two memory addresses is equal |
| 106 | * |
| 107 | * @param s1 The first memory region to compare. |
| 108 | * @param s2 The second memory region to compare. |
| 109 | * @param n The amount of bytes to compare. |
| 110 | * |
| 111 | * @note This function does not comply with the specification of memcmp, |
| 112 | * so should not be considered a drop-in replacement. |
| 113 | * |
| 114 | * @return 0 if memory regions are equal. |
| 115 | */ |
| 116 | uint32_t boot_secure_memequal(const void *s1, const void *s2, size_t n) |
| 117 | { |
| 118 | size_t i; |
| 119 | uint8_t *s1_p = (uint8_t*) s1; |
| 120 | uint8_t *s2_p = (uint8_t*) s2; |
| 121 | uint32_t ret = 0; |
| 122 | |
| 123 | for (i = 0; i < n; i++) { |
| 124 | ret |= (s1_p[i] ^ s2_p[i]); |
| 125 | } |
| 126 | |
| 127 | return ret; |
| 128 | } |
| 129 | |
David Vincze | 39e7855 | 2018-10-10 17:10:01 +0200 | [diff] [blame] | 130 | static int |
| 131 | boot_magic_decode(const uint32_t *magic) |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 132 | { |
Raef Coles | 25b857a | 2019-09-05 13:59:55 +0100 | [diff] [blame^] | 133 | if (boot_secure_memequal(magic, boot_img_magic, BOOT_MAGIC_SZ) == 0) { |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 134 | return BOOT_MAGIC_GOOD; |
| 135 | } |
David Vincze | 39e7855 | 2018-10-10 17:10:01 +0200 | [diff] [blame] | 136 | return BOOT_MAGIC_BAD; |
| 137 | } |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 138 | |
David Vincze | 39e7855 | 2018-10-10 17:10:01 +0200 | [diff] [blame] | 139 | static int |
| 140 | boot_flag_decode(uint8_t flag) |
| 141 | { |
| 142 | if (flag != BOOT_FLAG_SET) { |
| 143 | return BOOT_FLAG_BAD; |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 144 | } |
David Vincze | 39e7855 | 2018-10-10 17:10:01 +0200 | [diff] [blame] | 145 | return BOOT_FLAG_SET; |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 146 | } |
| 147 | |
David Vincze | 401c742 | 2019-06-21 20:44:05 +0200 | [diff] [blame] | 148 | /** |
| 149 | * Determines if a status source table is satisfied by the specified magic |
| 150 | * code. |
| 151 | * |
| 152 | * @param tbl_val A magic field from a status source table. |
| 153 | * @param val The magic value in a trailer, encoded as a |
| 154 | * BOOT_MAGIC_[...]. |
| 155 | * |
| 156 | * @return 1 if the two values are compatible; |
| 157 | * 0 otherwise. |
| 158 | */ |
| 159 | int |
| 160 | boot_magic_compatible_check(uint8_t tbl_val, uint8_t val) |
| 161 | { |
| 162 | switch (tbl_val) { |
| 163 | case BOOT_MAGIC_ANY: |
| 164 | return 1; |
| 165 | |
| 166 | case BOOT_MAGIC_NOTGOOD: |
| 167 | return val != BOOT_MAGIC_GOOD; |
| 168 | |
| 169 | default: |
| 170 | return tbl_val == val; |
| 171 | } |
| 172 | } |
| 173 | |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 174 | uint32_t |
David Vincze | 401c742 | 2019-06-21 20:44:05 +0200 | [diff] [blame] | 175 | boot_trailer_sz(uint8_t min_write_sz) |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 176 | { |
| 177 | return /* state for all sectors */ |
| 178 | BOOT_STATUS_MAX_ENTRIES * BOOT_STATUS_STATE_COUNT * min_write_sz + |
David Vincze | 401c742 | 2019-06-21 20:44:05 +0200 | [diff] [blame] | 179 | /* swap_type + copy_done + image_ok + swap_size */ |
| 180 | BOOT_MAX_ALIGN * 4 + |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 181 | BOOT_MAGIC_SZ; |
| 182 | } |
| 183 | |
| 184 | static uint32_t |
| 185 | boot_magic_off(const struct flash_area *fap) |
| 186 | { |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 187 | return fap->fa_size - BOOT_MAGIC_SZ; |
| 188 | } |
| 189 | |
| 190 | int |
| 191 | boot_status_entries(const struct flash_area *fap) |
| 192 | { |
David Vincze | bb20798 | 2019-08-21 15:13:04 +0200 | [diff] [blame] | 193 | if (fap->fa_id == FLASH_AREA_IMAGE_SCRATCH) { |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 194 | return BOOT_STATUS_STATE_COUNT; |
David Vincze | bb20798 | 2019-08-21 15:13:04 +0200 | [diff] [blame] | 195 | } else if ((fap->fa_id == FLASH_AREA_IMAGE_PRIMARY) || |
| 196 | (fap->fa_id == FLASH_AREA_IMAGE_SECONDARY)) { |
| 197 | return BOOT_STATUS_STATE_COUNT * BOOT_STATUS_MAX_ENTRIES; |
| 198 | } else { |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 199 | return BOOT_EBADARGS; |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | uint32_t |
| 204 | boot_status_off(const struct flash_area *fap) |
| 205 | { |
| 206 | uint32_t off_from_end; |
| 207 | uint8_t elem_sz; |
| 208 | |
| 209 | elem_sz = flash_area_align(fap); |
| 210 | |
David Vincze | 401c742 | 2019-06-21 20:44:05 +0200 | [diff] [blame] | 211 | off_from_end = boot_trailer_sz(elem_sz); |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 212 | |
| 213 | assert(off_from_end <= fap->fa_size); |
| 214 | return fap->fa_size - off_from_end; |
| 215 | } |
| 216 | |
David Vincze | 401c742 | 2019-06-21 20:44:05 +0200 | [diff] [blame] | 217 | uint32_t |
David Vincze | 91b71ef | 2019-06-24 13:06:47 +0200 | [diff] [blame] | 218 | boot_swap_info_off(const struct flash_area *fap) |
David Vincze | 401c742 | 2019-06-21 20:44:05 +0200 | [diff] [blame] | 219 | { |
| 220 | return fap->fa_size - BOOT_MAGIC_SZ - BOOT_MAX_ALIGN * 3; |
| 221 | } |
| 222 | |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 223 | static uint32_t |
| 224 | boot_copy_done_off(const struct flash_area *fap) |
| 225 | { |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 226 | return fap->fa_size - BOOT_MAGIC_SZ - BOOT_MAX_ALIGN * 2; |
| 227 | } |
| 228 | |
| 229 | static uint32_t |
| 230 | boot_image_ok_off(const struct flash_area *fap) |
| 231 | { |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 232 | return fap->fa_size - BOOT_MAGIC_SZ - BOOT_MAX_ALIGN; |
| 233 | } |
| 234 | |
| 235 | static uint32_t |
| 236 | boot_swap_size_off(const struct flash_area *fap) |
| 237 | { |
David Vincze | 401c742 | 2019-06-21 20:44:05 +0200 | [diff] [blame] | 238 | return fap->fa_size - BOOT_MAGIC_SZ - BOOT_MAX_ALIGN * 4; |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | int |
| 242 | boot_read_swap_state(const struct flash_area *fap, |
| 243 | struct boot_swap_state *state) |
| 244 | { |
David Vincze | 39e7855 | 2018-10-10 17:10:01 +0200 | [diff] [blame] | 245 | uint32_t magic[BOOT_MAGIC_ARR_SZ]; |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 246 | uint32_t off; |
David Vincze | 91b71ef | 2019-06-24 13:06:47 +0200 | [diff] [blame] | 247 | uint8_t swap_info; |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 248 | int rc; |
| 249 | |
| 250 | off = boot_magic_off(fap); |
David Vincze | 39e7855 | 2018-10-10 17:10:01 +0200 | [diff] [blame] | 251 | rc = flash_area_read_is_empty(fap, off, magic, BOOT_MAGIC_SZ); |
| 252 | if (rc < 0) { |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 253 | return BOOT_EFLASH; |
| 254 | } |
David Vincze | 39e7855 | 2018-10-10 17:10:01 +0200 | [diff] [blame] | 255 | if (rc == 1) { |
| 256 | state->magic = BOOT_MAGIC_UNSET; |
| 257 | } else { |
| 258 | state->magic = boot_magic_decode(magic); |
| 259 | } |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 260 | |
David Vincze | 91b71ef | 2019-06-24 13:06:47 +0200 | [diff] [blame] | 261 | off = boot_swap_info_off(fap); |
| 262 | rc = flash_area_read_is_empty(fap, off, &swap_info, sizeof swap_info); |
David Vincze | 401c742 | 2019-06-21 20:44:05 +0200 | [diff] [blame] | 263 | if (rc < 0) { |
| 264 | return BOOT_EFLASH; |
| 265 | } |
David Vincze | 91b71ef | 2019-06-24 13:06:47 +0200 | [diff] [blame] | 266 | |
| 267 | /* Extract the swap type and image number */ |
| 268 | state->swap_type = BOOT_GET_SWAP_TYPE(swap_info); |
| 269 | state->image_num = BOOT_GET_IMAGE_NUM(swap_info); |
| 270 | |
David Vincze | 401c742 | 2019-06-21 20:44:05 +0200 | [diff] [blame] | 271 | if (rc == 1 || state->swap_type > BOOT_SWAP_TYPE_REVERT) { |
| 272 | state->swap_type = BOOT_SWAP_TYPE_NONE; |
David Vincze | 91b71ef | 2019-06-24 13:06:47 +0200 | [diff] [blame] | 273 | state->image_num = 0; |
David Vincze | 401c742 | 2019-06-21 20:44:05 +0200 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | off = boot_copy_done_off(fap); |
| 277 | rc = flash_area_read_is_empty(fap, off, &state->copy_done, |
| 278 | sizeof state->copy_done); |
| 279 | if (rc < 0) { |
| 280 | return BOOT_EFLASH; |
| 281 | } |
| 282 | if (rc == 1) { |
| 283 | state->copy_done = BOOT_FLAG_UNSET; |
| 284 | } else { |
| 285 | state->copy_done = boot_flag_decode(state->copy_done); |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | off = boot_image_ok_off(fap); |
David Vincze | 401c742 | 2019-06-21 20:44:05 +0200 | [diff] [blame] | 289 | rc = flash_area_read_is_empty(fap, off, &state->image_ok, |
| 290 | sizeof state->image_ok); |
David Vincze | 39e7855 | 2018-10-10 17:10:01 +0200 | [diff] [blame] | 291 | if (rc < 0) { |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 292 | return BOOT_EFLASH; |
| 293 | } |
David Vincze | 39e7855 | 2018-10-10 17:10:01 +0200 | [diff] [blame] | 294 | if (rc == 1) { |
| 295 | state->image_ok = BOOT_FLAG_UNSET; |
| 296 | } else { |
| 297 | state->image_ok = boot_flag_decode(state->image_ok); |
| 298 | } |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 299 | |
| 300 | return 0; |
| 301 | } |
| 302 | |
| 303 | /** |
| 304 | * Reads the image trailer from the scratch area. |
| 305 | */ |
| 306 | int |
| 307 | boot_read_swap_state_by_id(int flash_area_id, struct boot_swap_state *state) |
| 308 | { |
| 309 | const struct flash_area *fap; |
| 310 | int rc; |
| 311 | |
David Vincze | bb20798 | 2019-08-21 15:13:04 +0200 | [diff] [blame] | 312 | if (flash_area_id == FLASH_AREA_IMAGE_SCRATCH || |
| 313 | flash_area_id == FLASH_AREA_IMAGE_PRIMARY || |
| 314 | flash_area_id == FLASH_AREA_IMAGE_SECONDARY) { |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 315 | rc = flash_area_open(flash_area_id, &fap); |
| 316 | if (rc != 0) { |
| 317 | return BOOT_EFLASH; |
| 318 | } |
David Vincze | bb20798 | 2019-08-21 15:13:04 +0200 | [diff] [blame] | 319 | } else { |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 320 | return BOOT_EBADARGS; |
| 321 | } |
| 322 | |
| 323 | rc = boot_read_swap_state(fap, state); |
| 324 | flash_area_close(fap); |
| 325 | return rc; |
| 326 | } |
| 327 | |
| 328 | int |
| 329 | boot_read_swap_size(uint32_t *swap_size) |
| 330 | { |
David Vincze | 39e7855 | 2018-10-10 17:10:01 +0200 | [diff] [blame] | 331 | uint32_t magic[BOOT_MAGIC_ARR_SZ]; |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 332 | uint32_t off; |
| 333 | const struct flash_area *fap; |
| 334 | int rc; |
| 335 | |
| 336 | /* |
| 337 | * In the middle a swap, tries to locate the saved swap size. Looks |
David Vincze | 8bdfc2d | 2019-03-18 15:49:23 +0100 | [diff] [blame] | 338 | * for a valid magic, first on the primary slot, then on scratch. |
| 339 | * Both "slots" can end up being temporary storage for a swap and it |
| 340 | * is assumed that if magic is valid then swap size is too, because |
| 341 | * magic is always written in the last step. |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 342 | */ |
| 343 | |
David Vincze | 8bdfc2d | 2019-03-18 15:49:23 +0100 | [diff] [blame] | 344 | rc = flash_area_open(FLASH_AREA_IMAGE_PRIMARY, &fap); |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 345 | if (rc != 0) { |
| 346 | return BOOT_EFLASH; |
| 347 | } |
| 348 | |
| 349 | off = boot_magic_off(fap); |
| 350 | rc = flash_area_read(fap, off, magic, BOOT_MAGIC_SZ); |
| 351 | if (rc != 0) { |
| 352 | rc = BOOT_EFLASH; |
| 353 | goto out; |
| 354 | } |
| 355 | |
Raef Coles | 25b857a | 2019-09-05 13:59:55 +0100 | [diff] [blame^] | 356 | if (boot_secure_memequal(magic, boot_img_magic, BOOT_MAGIC_SZ) != 0) { |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 357 | /* |
David Vincze | 8bdfc2d | 2019-03-18 15:49:23 +0100 | [diff] [blame] | 358 | * If the primary slot's magic is not valid, try scratch... |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 359 | */ |
| 360 | |
| 361 | flash_area_close(fap); |
| 362 | |
| 363 | rc = flash_area_open(FLASH_AREA_IMAGE_SCRATCH, &fap); |
| 364 | if (rc != 0) { |
| 365 | return BOOT_EFLASH; |
| 366 | } |
| 367 | |
| 368 | off = boot_magic_off(fap); |
| 369 | rc = flash_area_read(fap, off, magic, BOOT_MAGIC_SZ); |
| 370 | if (rc != 0) { |
| 371 | rc = BOOT_EFLASH; |
| 372 | goto out; |
| 373 | } |
| 374 | |
Raef Coles | 25b857a | 2019-09-05 13:59:55 +0100 | [diff] [blame^] | 375 | assert(boot_secure_memequal(magic, boot_img_magic, BOOT_MAGIC_SZ) == 0); |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | off = boot_swap_size_off(fap); |
Tamas Ban | 581034a | 2017-12-19 19:54:37 +0000 | [diff] [blame] | 379 | rc = flash_area_read(fap, off, swap_size, sizeof(*swap_size)); |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 380 | if (rc != 0) { |
| 381 | rc = BOOT_EFLASH; |
| 382 | } |
| 383 | |
| 384 | out: |
| 385 | flash_area_close(fap); |
| 386 | return rc; |
| 387 | } |
| 388 | |
| 389 | |
| 390 | int |
| 391 | boot_write_magic(const struct flash_area *fap) |
| 392 | { |
| 393 | uint32_t off; |
| 394 | int rc; |
| 395 | |
| 396 | off = boot_magic_off(fap); |
| 397 | |
David Vincze | 401c742 | 2019-06-21 20:44:05 +0200 | [diff] [blame] | 398 | BOOT_LOG_DBG("writing magic; fa_id=%d off=0x%x (0x%x)", |
| 399 | fap->fa_id, off, fap->fa_off + off); |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 400 | rc = flash_area_write(fap, off, boot_img_magic, BOOT_MAGIC_SZ); |
| 401 | if (rc != 0) { |
| 402 | return BOOT_EFLASH; |
| 403 | } |
| 404 | |
| 405 | return 0; |
| 406 | } |
| 407 | |
| 408 | static int |
David Vincze | 401c742 | 2019-06-21 20:44:05 +0200 | [diff] [blame] | 409 | boot_write_trailer_byte(const struct flash_area *fap, uint32_t off, |
| 410 | uint8_t val) |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 411 | { |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 412 | uint8_t buf[BOOT_MAX_ALIGN]; |
| 413 | uint8_t align; |
David Vincze | 39e7855 | 2018-10-10 17:10:01 +0200 | [diff] [blame] | 414 | uint8_t erased_val; |
David Vincze | 401c742 | 2019-06-21 20:44:05 +0200 | [diff] [blame] | 415 | int rc; |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 416 | |
Tamas Ban | c382885 | 2018-02-01 12:24:16 +0000 | [diff] [blame] | 417 | align = flash_area_align(fap); |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 418 | assert(align <= BOOT_MAX_ALIGN); |
David Vincze | 39e7855 | 2018-10-10 17:10:01 +0200 | [diff] [blame] | 419 | erased_val = flash_area_erased_val(fap); |
| 420 | memset(buf, erased_val, BOOT_MAX_ALIGN); |
David Vincze | 401c742 | 2019-06-21 20:44:05 +0200 | [diff] [blame] | 421 | buf[0] = val; |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 422 | |
| 423 | rc = flash_area_write(fap, off, buf, align); |
| 424 | if (rc != 0) { |
| 425 | return BOOT_EFLASH; |
| 426 | } |
| 427 | |
| 428 | return 0; |
| 429 | } |
| 430 | |
| 431 | int |
| 432 | boot_write_copy_done(const struct flash_area *fap) |
| 433 | { |
David Vincze | 401c742 | 2019-06-21 20:44:05 +0200 | [diff] [blame] | 434 | uint32_t off; |
| 435 | |
| 436 | off = boot_copy_done_off(fap); |
| 437 | BOOT_LOG_DBG("writing copy_done; fa_id=%d off=0x%x (0x%x)", |
| 438 | fap->fa_id, off, fap->fa_off + off); |
| 439 | return boot_write_trailer_byte(fap, off, BOOT_FLAG_SET); |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | int |
| 443 | boot_write_image_ok(const struct flash_area *fap) |
| 444 | { |
David Vincze | 401c742 | 2019-06-21 20:44:05 +0200 | [diff] [blame] | 445 | uint32_t off; |
| 446 | |
| 447 | off = boot_image_ok_off(fap); |
| 448 | BOOT_LOG_DBG("writing image_ok; fa_id=%d off=0x%x (0x%x)", |
| 449 | fap->fa_id, off, fap->fa_off + off); |
| 450 | return boot_write_trailer_byte(fap, off, BOOT_FLAG_SET); |
| 451 | } |
| 452 | |
| 453 | /** |
| 454 | * Writes the specified value to the `swap-type` field of an image trailer. |
| 455 | * This value is persisted so that the boot loader knows what swap operation to |
| 456 | * resume in case of an unexpected reset. |
| 457 | */ |
| 458 | int |
David Vincze | 91b71ef | 2019-06-24 13:06:47 +0200 | [diff] [blame] | 459 | boot_write_swap_info(const struct flash_area *fap, uint8_t swap_type, |
| 460 | uint8_t image_num) |
David Vincze | 401c742 | 2019-06-21 20:44:05 +0200 | [diff] [blame] | 461 | { |
| 462 | uint32_t off; |
David Vincze | 91b71ef | 2019-06-24 13:06:47 +0200 | [diff] [blame] | 463 | uint8_t swap_info; |
David Vincze | 401c742 | 2019-06-21 20:44:05 +0200 | [diff] [blame] | 464 | |
David Vincze | 91b71ef | 2019-06-24 13:06:47 +0200 | [diff] [blame] | 465 | BOOT_SET_SWAP_INFO(swap_info, image_num, swap_type); |
| 466 | off = boot_swap_info_off(fap); |
| 467 | BOOT_LOG_DBG("writing swap_info; fa_id=%d off=0x%x (0x%x), swap_type=0x%x" |
| 468 | " image_num=0x%x", |
| 469 | fap->fa_id, off, fap->fa_off + off, |
| 470 | BOOT_GET_SWAP_TYPE(swap_info), |
| 471 | BOOT_GET_IMAGE_NUM(swap_info)); |
| 472 | return boot_write_trailer_byte(fap, off, swap_info); |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 473 | } |
| 474 | |
| 475 | int |
| 476 | boot_write_swap_size(const struct flash_area *fap, uint32_t swap_size) |
| 477 | { |
| 478 | uint32_t off; |
| 479 | int rc; |
| 480 | uint8_t buf[BOOT_MAX_ALIGN]; |
| 481 | uint8_t align; |
David Vincze | 39e7855 | 2018-10-10 17:10:01 +0200 | [diff] [blame] | 482 | uint8_t erased_val; |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 483 | |
| 484 | off = boot_swap_size_off(fap); |
Tamas Ban | c382885 | 2018-02-01 12:24:16 +0000 | [diff] [blame] | 485 | align = flash_area_align(fap); |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 486 | assert(align <= BOOT_MAX_ALIGN); |
Tamas Ban | 581034a | 2017-12-19 19:54:37 +0000 | [diff] [blame] | 487 | if (align < sizeof(swap_size)) { |
| 488 | align = sizeof(swap_size); |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 489 | } |
David Vincze | 39e7855 | 2018-10-10 17:10:01 +0200 | [diff] [blame] | 490 | erased_val = flash_area_erased_val(fap); |
| 491 | memset(buf, erased_val, BOOT_MAX_ALIGN); |
Tamas Ban | 581034a | 2017-12-19 19:54:37 +0000 | [diff] [blame] | 492 | memcpy(buf, (uint8_t *)&swap_size, sizeof(swap_size)); |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 493 | |
David Vincze | 401c742 | 2019-06-21 20:44:05 +0200 | [diff] [blame] | 494 | BOOT_LOG_DBG("writing swap_size; fa_id=%d off=0x%x (0x%x)", |
| 495 | fap->fa_id, off, fap->fa_off + off); |
| 496 | |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 497 | rc = flash_area_write(fap, off, buf, align); |
| 498 | if (rc != 0) { |
| 499 | return BOOT_EFLASH; |
| 500 | } |
| 501 | |
| 502 | return 0; |
| 503 | } |
| 504 | |
| 505 | int |
| 506 | boot_swap_type(void) |
| 507 | { |
| 508 | const struct boot_swap_table *table; |
David Vincze | 8bdfc2d | 2019-03-18 15:49:23 +0100 | [diff] [blame] | 509 | struct boot_swap_state primary_slot; |
| 510 | struct boot_swap_state secondary_slot; |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 511 | int rc; |
David Vincze | 39e7855 | 2018-10-10 17:10:01 +0200 | [diff] [blame] | 512 | size_t i; |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 513 | |
David Vincze | 8bdfc2d | 2019-03-18 15:49:23 +0100 | [diff] [blame] | 514 | rc = boot_read_swap_state_by_id(FLASH_AREA_IMAGE_PRIMARY, &primary_slot); |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 515 | if (rc) { |
| 516 | return BOOT_SWAP_TYPE_PANIC; |
| 517 | } |
| 518 | |
David Vincze | 8bdfc2d | 2019-03-18 15:49:23 +0100 | [diff] [blame] | 519 | rc = boot_read_swap_state_by_id(FLASH_AREA_IMAGE_SECONDARY, |
| 520 | &secondary_slot); |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 521 | if (rc) { |
| 522 | return BOOT_SWAP_TYPE_PANIC; |
| 523 | } |
| 524 | |
| 525 | for (i = 0; i < BOOT_SWAP_TABLES_COUNT; i++) { |
| 526 | table = boot_swap_tables + i; |
| 527 | |
David Vincze | 401c742 | 2019-06-21 20:44:05 +0200 | [diff] [blame] | 528 | if (boot_magic_compatible_check(table->magic_primary_slot, |
| 529 | primary_slot.magic) && |
| 530 | boot_magic_compatible_check(table->magic_secondary_slot, |
| 531 | secondary_slot.magic) && |
David Vincze | 8bdfc2d | 2019-03-18 15:49:23 +0100 | [diff] [blame] | 532 | (table->image_ok_primary_slot == BOOT_FLAG_ANY || |
| 533 | table->image_ok_primary_slot == primary_slot.image_ok) && |
| 534 | (table->image_ok_secondary_slot == BOOT_FLAG_ANY || |
| 535 | table->image_ok_secondary_slot == secondary_slot.image_ok) && |
| 536 | (table->copy_done_primary_slot == BOOT_FLAG_ANY || |
| 537 | table->copy_done_primary_slot == primary_slot.copy_done)) { |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 538 | BOOT_LOG_INF("Swap type: %s", |
| 539 | table->swap_type == BOOT_SWAP_TYPE_TEST ? "test" : |
| 540 | table->swap_type == BOOT_SWAP_TYPE_PERM ? "perm" : |
| 541 | table->swap_type == BOOT_SWAP_TYPE_REVERT ? "revert" : |
| 542 | "BUG; can't happen"); |
| 543 | assert(table->swap_type == BOOT_SWAP_TYPE_TEST || |
| 544 | table->swap_type == BOOT_SWAP_TYPE_PERM || |
| 545 | table->swap_type == BOOT_SWAP_TYPE_REVERT); |
| 546 | return table->swap_type; |
| 547 | } |
| 548 | } |
| 549 | |
| 550 | BOOT_LOG_INF("Swap type: none"); |
| 551 | return BOOT_SWAP_TYPE_NONE; |
| 552 | } |
| 553 | |
| 554 | /** |
David Vincze | 8bdfc2d | 2019-03-18 15:49:23 +0100 | [diff] [blame] | 555 | * Marks the image in the secondary slot as pending. On the next reboot, |
| 556 | * the system will perform a one-time boot of the the secondary slot image. |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 557 | * |
| 558 | * @param permanent Whether the image should be used permanently or |
| 559 | * only tested once: |
| 560 | * 0=run image once, then confirm or revert. |
| 561 | * 1=run image forever. |
| 562 | * |
| 563 | * @return 0 on success; nonzero on failure. |
| 564 | */ |
| 565 | int |
| 566 | boot_set_pending(int permanent) |
| 567 | { |
Tamas Ban | 581034a | 2017-12-19 19:54:37 +0000 | [diff] [blame] | 568 | const struct flash_area *fap = NULL; |
David Vincze | 8bdfc2d | 2019-03-18 15:49:23 +0100 | [diff] [blame] | 569 | struct boot_swap_state state_secondary_slot; |
David Vincze | 401c742 | 2019-06-21 20:44:05 +0200 | [diff] [blame] | 570 | uint8_t swap_type; |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 571 | int rc; |
| 572 | |
David Vincze | 8bdfc2d | 2019-03-18 15:49:23 +0100 | [diff] [blame] | 573 | rc = boot_read_swap_state_by_id(FLASH_AREA_IMAGE_SECONDARY, |
| 574 | &state_secondary_slot); |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 575 | if (rc != 0) { |
| 576 | return rc; |
| 577 | } |
| 578 | |
David Vincze | 8bdfc2d | 2019-03-18 15:49:23 +0100 | [diff] [blame] | 579 | switch (state_secondary_slot.magic) { |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 580 | case BOOT_MAGIC_GOOD: |
| 581 | /* Swap already scheduled. */ |
| 582 | return 0; |
| 583 | |
| 584 | case BOOT_MAGIC_UNSET: |
David Vincze | 8bdfc2d | 2019-03-18 15:49:23 +0100 | [diff] [blame] | 585 | rc = flash_area_open(FLASH_AREA_IMAGE_SECONDARY, &fap); |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 586 | if (rc != 0) { |
| 587 | rc = BOOT_EFLASH; |
| 588 | } else { |
| 589 | rc = boot_write_magic(fap); |
| 590 | } |
| 591 | |
| 592 | if (rc == 0 && permanent) { |
| 593 | rc = boot_write_image_ok(fap); |
| 594 | } |
| 595 | |
David Vincze | 401c742 | 2019-06-21 20:44:05 +0200 | [diff] [blame] | 596 | if (rc == 0) { |
| 597 | if (permanent) { |
| 598 | swap_type = BOOT_SWAP_TYPE_PERM; |
| 599 | } else { |
| 600 | swap_type = BOOT_SWAP_TYPE_TEST; |
| 601 | } |
David Vincze | 91b71ef | 2019-06-24 13:06:47 +0200 | [diff] [blame] | 602 | rc = boot_write_swap_info(fap, swap_type, 0); |
David Vincze | 401c742 | 2019-06-21 20:44:05 +0200 | [diff] [blame] | 603 | } |
| 604 | |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 605 | flash_area_close(fap); |
| 606 | return rc; |
| 607 | |
David Vincze | 401c742 | 2019-06-21 20:44:05 +0200 | [diff] [blame] | 608 | case BOOT_MAGIC_BAD: |
| 609 | /* The image slot is corrupt. There is no way to recover, so erase the |
| 610 | * slot to allow future upgrades. |
| 611 | */ |
| 612 | rc = flash_area_open(FLASH_AREA_IMAGE_SECONDARY, &fap); |
| 613 | if (rc != 0) { |
| 614 | return BOOT_EFLASH; |
| 615 | } |
| 616 | |
| 617 | flash_area_erase(fap, 0, fap->fa_size); |
| 618 | flash_area_close(fap); |
| 619 | return BOOT_EBADIMAGE; |
| 620 | |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 621 | default: |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 622 | assert(0); |
David Vincze | 401c742 | 2019-06-21 20:44:05 +0200 | [diff] [blame] | 623 | return BOOT_EBADIMAGE; |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 624 | } |
| 625 | } |
| 626 | |
| 627 | /** |
David Vincze | 8bdfc2d | 2019-03-18 15:49:23 +0100 | [diff] [blame] | 628 | * Marks the image in the primary slot as confirmed. The system will continue |
| 629 | * booting into the image in the primary slot until told to boot from a |
| 630 | * different slot. |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 631 | * |
Tamas Ban | 581034a | 2017-12-19 19:54:37 +0000 | [diff] [blame] | 632 | * @return 0 on success; non-zero on failure. |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 633 | */ |
| 634 | int |
| 635 | boot_set_confirmed(void) |
| 636 | { |
Tamas Ban | 581034a | 2017-12-19 19:54:37 +0000 | [diff] [blame] | 637 | const struct flash_area *fap = NULL; |
David Vincze | 8bdfc2d | 2019-03-18 15:49:23 +0100 | [diff] [blame] | 638 | struct boot_swap_state state_primary_slot; |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 639 | int rc; |
| 640 | |
David Vincze | 8bdfc2d | 2019-03-18 15:49:23 +0100 | [diff] [blame] | 641 | rc = boot_read_swap_state_by_id(FLASH_AREA_IMAGE_PRIMARY, |
| 642 | &state_primary_slot); |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 643 | if (rc != 0) { |
| 644 | return rc; |
| 645 | } |
| 646 | |
David Vincze | 8bdfc2d | 2019-03-18 15:49:23 +0100 | [diff] [blame] | 647 | switch (state_primary_slot.magic) { |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 648 | case BOOT_MAGIC_GOOD: |
| 649 | /* Confirm needed; proceed. */ |
| 650 | break; |
| 651 | |
| 652 | case BOOT_MAGIC_UNSET: |
| 653 | /* Already confirmed. */ |
| 654 | return 0; |
| 655 | |
| 656 | case BOOT_MAGIC_BAD: |
| 657 | /* Unexpected state. */ |
| 658 | return BOOT_EBADVECT; |
| 659 | } |
| 660 | |
David Vincze | 8bdfc2d | 2019-03-18 15:49:23 +0100 | [diff] [blame] | 661 | if (state_primary_slot.copy_done == BOOT_FLAG_UNSET) { |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 662 | /* Swap never completed. This is unexpected. */ |
David Vincze | 39e7855 | 2018-10-10 17:10:01 +0200 | [diff] [blame] | 663 | rc = BOOT_EBADVECT; |
| 664 | goto done; |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 665 | } |
| 666 | |
David Vincze | 8bdfc2d | 2019-03-18 15:49:23 +0100 | [diff] [blame] | 667 | if (state_primary_slot.image_ok != BOOT_FLAG_UNSET) { |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 668 | /* Already confirmed. */ |
David Vincze | 39e7855 | 2018-10-10 17:10:01 +0200 | [diff] [blame] | 669 | goto done; |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 670 | } |
| 671 | |
David Vincze | 8bdfc2d | 2019-03-18 15:49:23 +0100 | [diff] [blame] | 672 | rc = flash_area_open(FLASH_AREA_IMAGE_PRIMARY, &fap); |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 673 | if (rc) { |
| 674 | rc = BOOT_EFLASH; |
| 675 | goto done; |
| 676 | } |
| 677 | |
| 678 | rc = boot_write_image_ok(fap); |
| 679 | if (rc != 0) { |
| 680 | goto done; |
| 681 | } |
| 682 | |
| 683 | rc = 0; |
| 684 | |
| 685 | done: |
| 686 | flash_area_close(fap); |
| 687 | return rc; |
| 688 | } |
David Vincze | bb6e3b6 | 2019-07-31 14:24:05 +0200 | [diff] [blame] | 689 | |
| 690 | #if (BOOT_IMAGE_NUMBER > 1) |
| 691 | /** |
| 692 | * Check if the version of the image is not older than required. |
| 693 | * |
| 694 | * @param req Required minimal image version. |
| 695 | * @param ver Version of the image to be checked. |
| 696 | * |
| 697 | * @return 0 if the version is sufficient, nonzero otherwise. |
| 698 | */ |
| 699 | int |
| 700 | boot_is_version_sufficient(struct image_version *req, |
| 701 | struct image_version *ver) |
| 702 | { |
| 703 | if (ver->iv_major > req->iv_major) { |
| 704 | return 0; |
| 705 | } |
| 706 | if (ver->iv_major < req->iv_major) { |
| 707 | return BOOT_EBADVERSION; |
| 708 | } |
| 709 | /* The major version numbers are equal. */ |
| 710 | if (ver->iv_minor > req->iv_minor) { |
| 711 | return 0; |
| 712 | } |
| 713 | if (ver->iv_minor < req->iv_minor) { |
| 714 | return BOOT_EBADVERSION; |
| 715 | } |
| 716 | /* The minor version numbers are equal. */ |
| 717 | if (ver->iv_revision < req->iv_revision) { |
| 718 | return BOOT_EBADVERSION; |
| 719 | } |
| 720 | |
| 721 | return 0; |
| 722 | } |
| 723 | #endif /* BOOT_IMAGE_NUMBER > 1 */ |