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 | 39e7855 | 2018-10-10 17:10:01 +0200 | [diff] [blame] | 20 | /* |
| 21 | * Original code taken from mcuboot project at: |
| 22 | * https://github.com/JuulLabs-OSS/mcuboot |
David Vincze | 401c742 | 2019-06-21 20:44:05 +0200 | [diff] [blame] | 23 | * Git SHA of the original version: 3c469bc698a9767859ed73cd0201c44161204d5c |
David Vincze | 39e7855 | 2018-10-10 17:10:01 +0200 | [diff] [blame] | 24 | * Modifications are Copyright (c) 2018-2019 Arm Limited. |
| 25 | */ |
| 26 | |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 27 | #ifndef H_BOOTUTIL_PRIV_ |
| 28 | #define H_BOOTUTIL_PRIV_ |
| 29 | |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 30 | #include "flash_map/flash_map.h" |
David Vincze | 401c742 | 2019-06-21 20:44:05 +0200 | [diff] [blame] | 31 | #include "bootutil/bootutil.h" |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 32 | #include "bootutil/image.h" |
Mate Toth-Pal | a76e2ab | 2018-05-31 15:43:01 +0200 | [diff] [blame] | 33 | #include "flash_layout.h" |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 34 | |
| 35 | #ifdef __cplusplus |
| 36 | extern "C" { |
| 37 | #endif |
| 38 | |
David Vincze | 401c742 | 2019-06-21 20:44:05 +0200 | [diff] [blame] | 39 | #ifdef MCUBOOT_HAVE_ASSERT_H |
| 40 | #include "mcuboot_config/mcuboot_assert.h" |
| 41 | #else |
| 42 | #define ASSERT assert |
| 43 | #endif |
| 44 | |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 45 | struct flash_area; |
| 46 | |
| 47 | #define BOOT_EFLASH 1 |
| 48 | #define BOOT_EFILE 2 |
| 49 | #define BOOT_EBADIMAGE 3 |
| 50 | #define BOOT_EBADVECT 4 |
| 51 | #define BOOT_EBADSTATUS 5 |
| 52 | #define BOOT_ENOMEM 6 |
| 53 | #define BOOT_EBADARGS 7 |
David Vincze | 060968d | 2019-05-23 01:13:14 +0200 | [diff] [blame] | 54 | #define BOOT_EBADMAGIC 8 |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 55 | |
| 56 | #define BOOT_TMPBUF_SZ 256 |
| 57 | |
| 58 | /* |
| 59 | * Maintain state of copy progress. |
| 60 | */ |
| 61 | struct boot_status { |
| 62 | uint32_t idx; /* Which area we're operating on */ |
| 63 | uint8_t state; /* Which part of the swapping process are we at */ |
| 64 | uint8_t use_scratch; /* Are status bytes ever written to scratch? */ |
David Vincze | 401c742 | 2019-06-21 20:44:05 +0200 | [diff] [blame] | 65 | uint8_t swap_type; /* The type of swap in effect */ |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 66 | uint32_t swap_size; /* Total size of swapped image */ |
| 67 | }; |
| 68 | |
David Vincze | 39e7855 | 2018-10-10 17:10:01 +0200 | [diff] [blame] | 69 | #define BOOT_MAGIC_GOOD 1 |
| 70 | #define BOOT_MAGIC_BAD 2 |
| 71 | #define BOOT_MAGIC_UNSET 3 |
| 72 | #define BOOT_MAGIC_ANY 4 /* NOTE: control only, not dependent on sector */ |
David Vincze | 401c742 | 2019-06-21 20:44:05 +0200 | [diff] [blame] | 73 | #define BOOT_MAGIC_NOTGOOD 5 /* NOTE: control only, not dependent on sector */ |
David Vincze | 39e7855 | 2018-10-10 17:10:01 +0200 | [diff] [blame] | 74 | |
| 75 | /* |
| 76 | * NOTE: leave BOOT_FLAG_SET equal to one, this is written to flash! |
| 77 | */ |
| 78 | #define BOOT_FLAG_SET 1 |
| 79 | #define BOOT_FLAG_BAD 2 |
| 80 | #define BOOT_FLAG_UNSET 3 |
| 81 | #define BOOT_FLAG_ANY 4 /* NOTE: control only, not dependent on sector */ |
| 82 | |
| 83 | #define BOOT_STATUS_IDX_0 1 |
| 84 | |
| 85 | #define BOOT_STATUS_STATE_0 1 |
| 86 | #define BOOT_STATUS_STATE_1 2 |
| 87 | #define BOOT_STATUS_STATE_2 3 |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 88 | |
| 89 | /** |
| 90 | * End-of-image slot structure. |
| 91 | * |
David Vincze | 401c742 | 2019-06-21 20:44:05 +0200 | [diff] [blame] | 92 | * 0 1 2 3 |
| 93 | * 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 |
| 94 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 95 | * ~ ~ |
| 96 | * ~ Swap status (BOOT_MAX_IMG_SECTORS * min-write-size * 3) ~ |
| 97 | * ~ ~ |
| 98 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 99 | * | Swap size (4 octets) | |
| 100 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
David Vincze | 91b71ef | 2019-06-24 13:06:47 +0200 | [diff] [blame^] | 101 | * | Swap info | 0xff padding (7 octets) | |
David Vincze | 401c742 | 2019-06-21 20:44:05 +0200 | [diff] [blame] | 102 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 103 | * | Copy done | 0xff padding (7 octets) | |
| 104 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 105 | * | Image OK | 0xff padding (7 octets) | |
| 106 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 107 | * | MAGIC (16 octets) | |
| 108 | * | | |
| 109 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 110 | */ |
| 111 | |
| 112 | extern const uint32_t boot_img_magic[4]; |
| 113 | |
| 114 | struct boot_swap_state { |
David Vincze | 401c742 | 2019-06-21 20:44:05 +0200 | [diff] [blame] | 115 | uint8_t magic; /* One of the BOOT_MAGIC_[...] values. */ |
| 116 | uint8_t swap_type; /* One of the BOOT_SWAP_TYPE_[...] values. */ |
| 117 | uint8_t copy_done; /* One of the BOOT_FLAG_[...] values. */ |
| 118 | uint8_t image_ok; /* One of the BOOT_FLAG_[...] values. */ |
David Vincze | 91b71ef | 2019-06-24 13:06:47 +0200 | [diff] [blame^] | 119 | uint8_t image_num; /* Boot status belongs to this image */ |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 120 | }; |
| 121 | |
David Vincze | 39e7855 | 2018-10-10 17:10:01 +0200 | [diff] [blame] | 122 | /* |
David Vincze | 91b71ef | 2019-06-24 13:06:47 +0200 | [diff] [blame^] | 123 | * Extract the swap type and image number from image trailers's swap_info |
| 124 | * field. |
| 125 | */ |
| 126 | #define SWAP_INFO_SWAP_TYPE_MASK (0x0Fu) |
| 127 | #define SWAP_INFO_SWAP_TYPE_POS (0) |
| 128 | #define SWAP_INFO_IMAGE_NUM_MASK (0xF0u) |
| 129 | #define SWAP_INFO_IMAGE_NUM_POS (4) |
| 130 | |
| 131 | #define BOOT_GET_SWAP_TYPE(swap_info) ((swap_info) & SWAP_INFO_SWAP_TYPE_MASK) |
| 132 | #define BOOT_GET_IMAGE_NUM(swap_info) ((swap_info) >> SWAP_INFO_IMAGE_NUM_POS) |
| 133 | |
| 134 | /* Construct the swap_info field from swap type and image number */ |
| 135 | #define BOOT_SET_SWAP_INFO(swap_info, image, type) { \ |
| 136 | assert(((image) & (SWAP_INFO_IMAGE_NUM_MASK >> \ |
| 137 | SWAP_INFO_IMAGE_NUM_POS)) == (image)); \ |
| 138 | assert(((type) & SWAP_INFO_SWAP_TYPE_MASK) == (type)); \ |
| 139 | (swap_info) = (image) << SWAP_INFO_IMAGE_NUM_POS \ |
| 140 | | (type); \ |
| 141 | } |
| 142 | |
| 143 | /* |
David Vincze | 39e7855 | 2018-10-10 17:10:01 +0200 | [diff] [blame] | 144 | * The current flashmap API does not check the amount of space allocated when |
| 145 | * loading sector data from the flash device, allowing for smaller counts here |
| 146 | * would most surely incur in overruns. |
| 147 | * |
| 148 | * TODO: make flashmap API receive the current sector array size. |
| 149 | */ |
| 150 | #if BOOT_MAX_IMG_SECTORS < 32 |
| 151 | #error "Too few sectors, please increase BOOT_MAX_IMG_SECTORS to at least 32" |
| 152 | #endif |
| 153 | |
| 154 | /** Number of image slots in flash; currently limited to two. */ |
David Vincze | 8bdfc2d | 2019-03-18 15:49:23 +0100 | [diff] [blame] | 155 | #define BOOT_NUM_SLOTS 2 |
David Vincze | 39e7855 | 2018-10-10 17:10:01 +0200 | [diff] [blame] | 156 | |
| 157 | /** Maximum number of image sectors supported by the bootloader. */ |
David Vincze | 8bdfc2d | 2019-03-18 15:49:23 +0100 | [diff] [blame] | 158 | #define BOOT_STATUS_STATE_COUNT 3 |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 159 | |
David Vincze | 8bdfc2d | 2019-03-18 15:49:23 +0100 | [diff] [blame] | 160 | #define BOOT_PRIMARY_SLOT 0 |
| 161 | #define BOOT_SECONDARY_SLOT 1 |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 162 | |
David Vincze | 8bdfc2d | 2019-03-18 15:49:23 +0100 | [diff] [blame] | 163 | #define BOOT_STATUS_SOURCE_NONE 0 |
| 164 | #define BOOT_STATUS_SOURCE_SCRATCH 1 |
| 165 | #define BOOT_STATUS_SOURCE_PRIMARY_SLOT 2 |
| 166 | |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 167 | extern const uint32_t BOOT_MAGIC_SZ; |
| 168 | |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 169 | /** |
| 170 | * Compatibility shim for flash sector type. |
| 171 | * |
| 172 | * This can be deleted when flash_area_to_sectors() is removed. |
| 173 | */ |
| 174 | #ifdef MCUBOOT_USE_FLASH_AREA_GET_SECTORS |
| 175 | typedef struct flash_sector boot_sector_t; |
| 176 | #else |
| 177 | typedef struct flash_area boot_sector_t; |
| 178 | #endif |
| 179 | |
| 180 | /** Private state maintained during boot. */ |
| 181 | struct boot_loader_state { |
| 182 | struct { |
| 183 | struct image_header hdr; |
| 184 | const struct flash_area *area; |
| 185 | boot_sector_t *sectors; |
| 186 | size_t num_sectors; |
| 187 | } imgs[BOOT_NUM_SLOTS]; |
| 188 | |
David Vincze | 401c742 | 2019-06-21 20:44:05 +0200 | [diff] [blame] | 189 | struct { |
| 190 | const struct flash_area *area; |
| 191 | boot_sector_t *sectors; |
| 192 | size_t num_sectors; |
| 193 | } scratch; |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 194 | |
| 195 | uint8_t write_sz; |
| 196 | }; |
| 197 | |
David Vincze | 39e7855 | 2018-10-10 17:10:01 +0200 | [diff] [blame] | 198 | int bootutil_verify_sig(uint8_t *hash, uint32_t hlen, uint8_t *sig, |
| 199 | size_t slen, uint8_t key_id); |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 200 | |
David Vincze | 401c742 | 2019-06-21 20:44:05 +0200 | [diff] [blame] | 201 | int boot_magic_compatible_check(uint8_t tbl_val, uint8_t val); |
| 202 | uint32_t boot_trailer_sz(uint8_t min_write_sz); |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 203 | int boot_status_entries(const struct flash_area *fap); |
| 204 | uint32_t boot_status_off(const struct flash_area *fap); |
David Vincze | 91b71ef | 2019-06-24 13:06:47 +0200 | [diff] [blame^] | 205 | uint32_t boot_swap_info_off(const struct flash_area *fap); |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 206 | int boot_read_swap_state(const struct flash_area *fap, |
| 207 | struct boot_swap_state *state); |
| 208 | int boot_read_swap_state_by_id(int flash_area_id, |
| 209 | struct boot_swap_state *state); |
| 210 | int boot_write_magic(const struct flash_area *fap); |
| 211 | int boot_write_status(struct boot_status *bs); |
| 212 | int boot_schedule_test_swap(void); |
| 213 | int boot_write_copy_done(const struct flash_area *fap); |
| 214 | int boot_write_image_ok(const struct flash_area *fap); |
David Vincze | 91b71ef | 2019-06-24 13:06:47 +0200 | [diff] [blame^] | 215 | int boot_write_swap_info(const struct flash_area *fap, uint8_t swap_type, |
| 216 | uint8_t image_num); |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 217 | int boot_write_swap_size(const struct flash_area *fap, uint32_t swap_size); |
| 218 | int boot_read_swap_size(uint32_t *swap_size); |
| 219 | |
| 220 | /* |
| 221 | * Accessors for the contents of struct boot_loader_state. |
| 222 | */ |
| 223 | |
| 224 | /* These are macros so they can be used as lvalues. */ |
| 225 | #define BOOT_IMG_AREA(state, slot) ((state)->imgs[(slot)].area) |
David Vincze | 401c742 | 2019-06-21 20:44:05 +0200 | [diff] [blame] | 226 | #define BOOT_SCRATCH_AREA(state) ((state)->scratch.area) |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 227 | #define BOOT_WRITE_SZ(state) ((state)->write_sz) |
| 228 | |
| 229 | static inline struct image_header* |
| 230 | boot_img_hdr(struct boot_loader_state *state, size_t slot) |
| 231 | { |
| 232 | return &state->imgs[slot].hdr; |
| 233 | } |
| 234 | |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 235 | static inline size_t |
| 236 | boot_img_num_sectors(struct boot_loader_state *state, size_t slot) |
| 237 | { |
| 238 | return state->imgs[slot].num_sectors; |
| 239 | } |
| 240 | |
David Vincze | 401c742 | 2019-06-21 20:44:05 +0200 | [diff] [blame] | 241 | static inline size_t |
| 242 | boot_scratch_num_sectors(struct boot_loader_state *state) |
| 243 | { |
| 244 | return state->scratch.num_sectors; |
| 245 | } |
| 246 | |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 247 | /* |
| 248 | * Offset of the slot from the beginning of the flash device. |
| 249 | */ |
| 250 | static inline uint32_t |
| 251 | boot_img_slot_off(struct boot_loader_state *state, size_t slot) |
| 252 | { |
| 253 | return state->imgs[slot].area->fa_off; |
| 254 | } |
| 255 | |
| 256 | static inline size_t boot_scratch_area_size(struct boot_loader_state *state) |
| 257 | { |
David Vincze | 401c742 | 2019-06-21 20:44:05 +0200 | [diff] [blame] | 258 | return BOOT_SCRATCH_AREA(state)->fa_size; |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | #ifndef MCUBOOT_USE_FLASH_AREA_GET_SECTORS |
| 262 | |
| 263 | static inline size_t |
| 264 | boot_img_sector_size(struct boot_loader_state *state, |
| 265 | size_t slot, size_t sector) |
| 266 | { |
| 267 | return state->imgs[slot].sectors[sector].fa_size; |
| 268 | } |
| 269 | |
| 270 | /* |
| 271 | * Offset of the sector from the beginning of the image, NOT the flash |
| 272 | * device. |
| 273 | */ |
| 274 | static inline uint32_t |
| 275 | boot_img_sector_off(struct boot_loader_state *state, size_t slot, |
| 276 | size_t sector) |
| 277 | { |
| 278 | return state->imgs[slot].sectors[sector].fa_off - |
| 279 | state->imgs[slot].sectors[0].fa_off; |
| 280 | } |
| 281 | |
| 282 | static inline int |
| 283 | boot_initialize_area(struct boot_loader_state *state, int flash_area) |
| 284 | { |
| 285 | int num_sectors = BOOT_MAX_IMG_SECTORS; |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 286 | int rc; |
| 287 | |
| 288 | switch (flash_area) { |
David Vincze | 8bdfc2d | 2019-03-18 15:49:23 +0100 | [diff] [blame] | 289 | case FLASH_AREA_IMAGE_PRIMARY: |
David Vincze | 401c742 | 2019-06-21 20:44:05 +0200 | [diff] [blame] | 290 | rc = flash_area_to_sectors(flash_area, &num_sectors, |
| 291 | state->imgs[BOOT_PRIMARY_SLOT].sectors); |
| 292 | state->imgs[BOOT_PRIMARY_SLOT].num_sectors = (size_t)num_sectors; |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 293 | break; |
David Vincze | 8bdfc2d | 2019-03-18 15:49:23 +0100 | [diff] [blame] | 294 | case FLASH_AREA_IMAGE_SECONDARY: |
David Vincze | 401c742 | 2019-06-21 20:44:05 +0200 | [diff] [blame] | 295 | rc = flash_area_to_sectors(flash_area, &num_sectors, |
| 296 | state->imgs[BOOT_SECONDARY_SLOT].sectors); |
| 297 | state->imgs[BOOT_SECONDARY_SLOT].num_sectors = (size_t)num_sectors; |
| 298 | break; |
| 299 | case FLASH_AREA_IMAGE_SCRATCH: |
| 300 | rc = flash_area_to_sectors(flash_area, &num_sectors, |
| 301 | state->scratch.sectors); |
| 302 | state->scratch.num_sectors = (size_t)num_sectors; |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 303 | break; |
| 304 | default: |
| 305 | return BOOT_EFLASH; |
| 306 | } |
| 307 | |
David Vincze | 401c742 | 2019-06-21 20:44:05 +0200 | [diff] [blame] | 308 | return rc; |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | #else /* defined(MCUBOOT_USE_FLASH_AREA_GET_SECTORS) */ |
| 312 | |
| 313 | static inline size_t |
| 314 | boot_img_sector_size(struct boot_loader_state *state, |
| 315 | size_t slot, size_t sector) |
| 316 | { |
| 317 | return state->imgs[slot].sectors[sector].fs_size; |
| 318 | } |
| 319 | |
| 320 | static inline uint32_t |
| 321 | boot_img_sector_off(struct boot_loader_state *state, size_t slot, |
| 322 | size_t sector) |
| 323 | { |
| 324 | return state->imgs[slot].sectors[sector].fs_off - |
| 325 | state->imgs[slot].sectors[0].fs_off; |
| 326 | } |
| 327 | |
| 328 | static inline int |
| 329 | boot_initialize_area(struct boot_loader_state *state, int flash_area) |
| 330 | { |
| 331 | uint32_t num_sectors; |
| 332 | struct flash_sector *out_sectors; |
| 333 | size_t *out_num_sectors; |
| 334 | int rc; |
| 335 | |
| 336 | switch (flash_area) { |
David Vincze | 8bdfc2d | 2019-03-18 15:49:23 +0100 | [diff] [blame] | 337 | case FLASH_AREA_IMAGE_PRIMARY: |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 338 | num_sectors = BOOT_MAX_IMG_SECTORS; |
David Vincze | 8bdfc2d | 2019-03-18 15:49:23 +0100 | [diff] [blame] | 339 | out_sectors = state->imgs[BOOT_PRIMARY_SLOT].sectors; |
| 340 | out_num_sectors = &state->imgs[BOOT_PRIMARY_SLOT].num_sectors; |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 341 | break; |
David Vincze | 8bdfc2d | 2019-03-18 15:49:23 +0100 | [diff] [blame] | 342 | case FLASH_AREA_IMAGE_SECONDARY: |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 343 | num_sectors = BOOT_MAX_IMG_SECTORS; |
David Vincze | 8bdfc2d | 2019-03-18 15:49:23 +0100 | [diff] [blame] | 344 | out_sectors = state->imgs[BOOT_SECONDARY_SLOT].sectors; |
| 345 | out_num_sectors = &state->imgs[BOOT_SECONDARY_SLOT].num_sectors; |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 346 | break; |
David Vincze | 401c742 | 2019-06-21 20:44:05 +0200 | [diff] [blame] | 347 | case FLASH_AREA_IMAGE_SCRATCH: |
| 348 | num_sectors = BOOT_MAX_IMG_SECTORS; |
| 349 | out_sectors = state->scratch.sectors; |
| 350 | out_num_sectors = &state->scratch.num_sectors; |
| 351 | break; |
Tamas Ban | f70ef8c | 2017-12-19 15:35:09 +0000 | [diff] [blame] | 352 | default: |
| 353 | return -1; |
| 354 | } |
| 355 | |
| 356 | rc = flash_area_get_sectors(flash_area, &num_sectors, out_sectors); |
| 357 | if (rc != 0) { |
| 358 | return rc; |
| 359 | } |
| 360 | *out_num_sectors = num_sectors; |
| 361 | return 0; |
| 362 | } |
| 363 | |
| 364 | #endif /* !defined(MCUBOOT_USE_FLASH_AREA_GET_SECTORS) */ |
| 365 | |
| 366 | #ifdef __cplusplus |
| 367 | } |
| 368 | #endif |
| 369 | |
| 370 | #endif |