1 /*
2 * SPDX-License-Identifier: Apache-2.0
3 *
4 * Copyright (c) 2017-2020 Linaro LTD
5 * Copyright (c) 2017-2019 JUUL Labs
6 * Copyright (c) 2019-2021 Arm Limited
7 *
8 * Original license:
9 *
10 * Licensed to the Apache Software Foundation (ASF) under one
11 * or more contributor license agreements. See the NOTICE file
12 * distributed with this work for additional information
13 * regarding copyright ownership. The ASF licenses this file
14 * to you under the Apache License, Version 2.0 (the
15 * "License"); you may not use this file except in compliance
16 * with the License. You may obtain a copy of the License at
17 *
18 * http://www.apache.org/licenses/LICENSE-2.0
19 *
20 * Unless required by applicable law or agreed to in writing,
21 * software distributed under the License is distributed on an
22 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
23 * KIND, either express or implied. See the License for the
24 * specific language governing permissions and limitations
25 * under the License.
26 */
27
28 #ifndef H_BOOTUTIL_PRIV_
29 #define H_BOOTUTIL_PRIV_
30
31 #include <string.h>
32
33 #include "sysflash/sysflash.h"
34
35 #include <flash_map_backend/flash_map_backend.h>
36
37 #include "bootutil/bootutil.h"
38 #include "bootutil/image.h"
39 #include "bootutil/fault_injection_hardening.h"
40 #include "mcuboot_config/mcuboot_config.h"
41
42 #ifdef MCUBOOT_ENC_IMAGES
43 #include "bootutil/enc_key.h"
44 #endif
45
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49
50 struct flash_area;
51
52 #define BOOT_TMPBUF_SZ 256
53
54 #define NO_ACTIVE_SLOT UINT32_MAX
55
56 /** Number of image slots in flash; currently limited to two. */
57 #define BOOT_NUM_SLOTS 2
58
59 #if (defined(MCUBOOT_OVERWRITE_ONLY) + \
60 defined(MCUBOOT_SWAP_USING_MOVE) + \
61 defined(MCUBOOT_SWAP_USING_OFFSET) + \
62 defined(MCUBOOT_DIRECT_XIP) + \
63 defined(MCUBOOT_RAM_LOAD) + \
64 defined(MCUBOOT_FIRMWARE_LOADER) + \
65 defined(MCUBOOT_SWAP_USING_SCRATCH)) > 1
66 #error "Please enable only one of MCUBOOT_OVERWRITE_ONLY, MCUBOOT_SWAP_USING_MOVE, MCUBOOT_SWAP_USING_OFFSET, MCUBOOT_DIRECT_XIP, MCUBOOT_RAM_LOAD or MCUBOOT_FIRMWARE_LOADER"
67 #endif
68
69 #if !defined(MCUBOOT_DIRECT_XIP) && \
70 defined(MCUBOOT_DIRECT_XIP_REVERT)
71 #error "MCUBOOT_DIRECT_XIP_REVERT cannot be enabled unless MCUBOOT_DIRECT_XIP is used"
72 #endif
73
74 #if !defined(MCUBOOT_OVERWRITE_ONLY) && \
75 !defined(MCUBOOT_SWAP_USING_MOVE) && \
76 !defined(MCUBOOT_SWAP_USING_OFFSET) && \
77 !defined(MCUBOOT_DIRECT_XIP) && \
78 !defined(MCUBOOT_RAM_LOAD) && \
79 !defined(MCUBOOT_SINGLE_APPLICATION_SLOT) && \
80 !defined(MCUBOOT_FIRMWARE_LOADER)
81 #define MCUBOOT_SWAP_USING_SCRATCH 1
82 #endif
83
84 #if defined(MCUBOOT_SWAP_USING_OFFSET)
85 #define BOOT_STATUS_OP_SWAP 1
86 #else
87 #define BOOT_STATUS_OP_MOVE 1
88 #define BOOT_STATUS_OP_SWAP 2
89 #endif
90
91 /*
92 * Maintain state of copy progress.
93 */
94 struct boot_status {
95 uint32_t idx; /* Which area we're operating on */
96 uint8_t state; /* Which part of the swapping process are we at */
97 uint8_t op; /* What operation are we performing? */
98 uint8_t use_scratch; /* Are status bytes ever written to scratch? */
99 uint8_t swap_type; /* The type of swap in effect */
100 uint32_t swap_size; /* Total size of swapped image */
101 #ifdef MCUBOOT_ENC_IMAGES
102 uint8_t enckey[BOOT_NUM_SLOTS][BOOT_ENC_KEY_ALIGN_SIZE];
103 #if MCUBOOT_SWAP_SAVE_ENCTLV
104 uint8_t enctlv[BOOT_NUM_SLOTS][BOOT_ENC_TLV_ALIGN_SIZE];
105 #endif
106 #endif
107 int source; /* Which slot contains swap status metadata */
108 };
109
110 #define BOOT_STATUS_IDX_0 1
111
112 #define BOOT_STATUS_STATE_0 1
113 #define BOOT_STATUS_STATE_1 2
114 #define BOOT_STATUS_STATE_2 3
115
116 /**
117 * End-of-image slot structure.
118 *
119 * 0 1 2 3
120 * 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
121 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
122 * ~ ~
123 * ~ Swap status (BOOT_MAX_IMG_SECTORS * min-write-size * 3) ~
124 * ~ ~
125 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
126 * | Encryption key 0 (16 octets) [*] |
127 * | |
128 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
129 * | 0xff padding as needed |
130 * | (BOOT_MAX_ALIGN minus 16 octets from Encryption key 0) [*] |
131 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
132 * | Encryption key 1 (16 octets) [*] |
133 * | |
134 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
135 * | 0xff padding as needed |
136 * | (BOOT_MAX_ALIGN minus 16 octets from Encryption key 1) [*] |
137 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
138 * | Swap size (4 octets) |
139 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
140 * | 0xff padding as needed |
141 * | (BOOT_MAX_ALIGN minus 4 octets from Swap size) |
142 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
143 * | Swap info | 0xff padding (BOOT_MAX_ALIGN minus 1 octet) |
144 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
145 * | Copy done | 0xff padding (BOOT_MAX_ALIGN minus 1 octet) |
146 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
147 * | Image OK | 0xff padding (BOOT_MAX_ALIGN minus 1 octet) |
148 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
149 * | 0xff padding as needed |
150 * | (BOOT_MAX_ALIGN minus 16 octets from MAGIC) |
151 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
152 * | MAGIC (16 octets) |
153 * | |
154 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
155 *
156 * [*]: Only present if the encryption option is enabled
157 * (`MCUBOOT_ENC_IMAGES`).
158 */
159
160 union boot_img_magic_t
161 {
162 struct {
163 uint16_t align;
164 uint8_t magic[14];
165 };
166 uint8_t val[16];
167 };
168
169 extern const union boot_img_magic_t boot_img_magic;
170
171 #define BOOT_IMG_MAGIC (boot_img_magic.val)
172
173 #if BOOT_MAX_ALIGN == 8
174 #define BOOT_IMG_ALIGN (BOOT_MAX_ALIGN)
175 #else
176 #define BOOT_IMG_ALIGN (boot_img_magic.align)
177 #endif
178
179 _Static_assert(sizeof(boot_img_magic) == BOOT_MAGIC_SZ, "Invalid size for image magic");
180
181 #if !defined(MCUBOOT_DIRECT_XIP) && !defined(MCUBOOT_RAM_LOAD)
182 #define ARE_SLOTS_EQUIVALENT() 0
183 #else
184 #define ARE_SLOTS_EQUIVALENT() 1
185
186 #if defined(MCUBOOT_DIRECT_XIP) && defined(MCUBOOT_ENC_IMAGES)
187 #error "Image encryption (MCUBOOT_ENC_IMAGES) is not supported when MCUBOOT_DIRECT_XIP is selected."
188 #endif /* MCUBOOT_DIRECT_XIP && MCUBOOT_ENC_IMAGES */
189 #endif /* MCUBOOT_DIRECT_XIP || MCUBOOT_RAM_LOAD */
190
191 #define BOOT_MAX_IMG_SECTORS MCUBOOT_MAX_IMG_SECTORS
192
193 #define BOOT_LOG_IMAGE_INFO(slot, hdr) \
194 BOOT_LOG_INF("%-9s slot: version=%u.%u.%u+%u", \
195 ((slot) == BOOT_PRIMARY_SLOT) ? "Primary" : "Secondary", \
196 (hdr)->ih_ver.iv_major, \
197 (hdr)->ih_ver.iv_minor, \
198 (hdr)->ih_ver.iv_revision, \
199 (hdr)->ih_ver.iv_build_num)
200
201 #if MCUBOOT_SWAP_USING_MOVE
202 #define BOOT_STATUS_MOVE_STATE_COUNT 1
203 #define BOOT_STATUS_SWAP_STATE_COUNT 2
204 #define BOOT_STATUS_STATE_COUNT (BOOT_STATUS_MOVE_STATE_COUNT + BOOT_STATUS_SWAP_STATE_COUNT)
205 #elif MCUBOOT_SWAP_USING_OFFSET
206 #define BOOT_STATUS_SWAP_STATE_COUNT 2
207 #define BOOT_STATUS_STATE_COUNT BOOT_STATUS_SWAP_STATE_COUNT
208 #else
209 #define BOOT_STATUS_STATE_COUNT 3
210 #endif
211
212 /** Maximum number of image sectors supported by the bootloader. */
213 #define BOOT_STATUS_MAX_ENTRIES BOOT_MAX_IMG_SECTORS
214
215 #define BOOT_PRIMARY_SLOT 0
216 #define BOOT_SECONDARY_SLOT 1
217
218 #define BOOT_STATUS_SOURCE_NONE 0
219 #define BOOT_STATUS_SOURCE_SCRATCH 1
220 #define BOOT_STATUS_SOURCE_PRIMARY_SLOT 2
221
222 /**
223 * Compatibility shim for flash sector type.
224 *
225 * This can be deleted when flash_area_to_sectors() is removed.
226 */
227 #ifdef MCUBOOT_USE_FLASH_AREA_GET_SECTORS
228 typedef struct flash_sector boot_sector_t;
229 #else
230 typedef struct flash_area boot_sector_t;
231 #endif
232
233 /** Private state maintained during boot. */
234 struct boot_loader_state {
235 struct {
236 struct image_header hdr;
237 const struct flash_area *area;
238 boot_sector_t *sectors;
239 uint32_t num_sectors;
240 } imgs[BOOT_IMAGE_NUMBER][BOOT_NUM_SLOTS];
241
242 #if MCUBOOT_SWAP_USING_SCRATCH
243 struct {
244 const struct flash_area *area;
245 boot_sector_t *sectors;
246 uint32_t num_sectors;
247 } scratch;
248 #endif
249
250 uint8_t swap_type[BOOT_IMAGE_NUMBER];
251 uint32_t write_sz;
252
253 #if defined(MCUBOOT_SWAP_USING_OFFSET)
254 uint32_t secondary_offset[BOOT_IMAGE_NUMBER];
255 #if defined(MCUBOOT_BOOTSTRAP)
256 bool bootstrap_secondary_offset_set[BOOT_IMAGE_NUMBER];
257 #endif
258 #endif
259
260 #if defined(MCUBOOT_ENC_IMAGES)
261 struct enc_key_data enc[BOOT_IMAGE_NUMBER][BOOT_NUM_SLOTS];
262 #endif
263
264 #if (BOOT_IMAGE_NUMBER > 1)
265 uint8_t curr_img_idx;
266 bool img_mask[BOOT_IMAGE_NUMBER];
267 #endif
268
269 #if defined(MCUBOOT_DIRECT_XIP) || defined(MCUBOOT_RAM_LOAD)
270 struct slot_usage_t {
271 /* Index of the slot chosen to be loaded */
272 uint32_t active_slot;
273 bool slot_available[BOOT_NUM_SLOTS];
274 #if defined(MCUBOOT_RAM_LOAD)
275 /* Image destination and size for the active slot */
276 uint32_t img_dst;
277 uint32_t img_sz;
278 #elif defined(MCUBOOT_DIRECT_XIP_REVERT)
279 /* Swap status for the active slot */
280 struct boot_swap_state swap_state;
281 #endif
282 } slot_usage[BOOT_IMAGE_NUMBER];
283 #endif /* MCUBOOT_DIRECT_XIP || MCUBOOT_RAM_LOAD */
284 };
285
286 /* The function is intended for verification of image hash against
287 * provided signature.
288 */
289 fih_ret bootutil_verify_sig(uint8_t *hash, uint32_t hlen, uint8_t *sig,
290 size_t slen, uint8_t key_id);
291
292 /* The function is intended for direct verification of image
293 * against provided signature.
294 */
295 fih_ret bootutil_verify_img(uint8_t *img, uint32_t size,
296 uint8_t *sig, size_t slen, uint8_t key_id);
297
298 fih_ret boot_fih_memequal(const void *s1, const void *s2, size_t n);
299
300 int boot_find_status(int image_index, const struct flash_area **fap);
301 int boot_magic_compatible_check(uint8_t tbl_val, uint8_t val);
302 uint32_t boot_status_sz(uint32_t min_write_sz);
303 uint32_t boot_trailer_sz(uint32_t min_write_sz);
304 int boot_status_entries(int image_index, const struct flash_area *fap);
305 uint32_t boot_status_off(const struct flash_area *fap);
306 int boot_read_swap_state(const struct flash_area *fap,
307 struct boot_swap_state *state);
308 int boot_read_swap_state_by_id(int flash_area_id,
309 struct boot_swap_state *state);
310 int boot_write_magic(const struct flash_area *fap);
311 int boot_write_status(const struct boot_loader_state *state, struct boot_status *bs);
312 int boot_write_copy_done(const struct flash_area *fap);
313 int boot_write_image_ok(const struct flash_area *fap);
314 int boot_write_swap_info(const struct flash_area *fap, uint8_t swap_type,
315 uint8_t image_num);
316 int boot_write_swap_size(const struct flash_area *fap, uint32_t swap_size);
317 int boot_write_trailer(const struct flash_area *fap, uint32_t off,
318 const uint8_t *inbuf, uint8_t inlen);
319 int boot_write_trailer_flag(const struct flash_area *fap, uint32_t off,
320 uint8_t flag_val);
321 int boot_read_swap_size(const struct flash_area *fap, uint32_t *swap_size);
322 int boot_slots_compatible(struct boot_loader_state *state);
323 uint32_t boot_status_internal_off(const struct boot_status *bs, int elem_sz);
324 int boot_read_image_header(struct boot_loader_state *state, int slot,
325 struct image_header *out_hdr, struct boot_status *bs);
326 #if defined(MCUBOOT_SWAP_USING_OFFSET) && defined(MCUBOOT_ENC_IMAGES)
327 int boot_copy_region(struct boot_loader_state *state,
328 const struct flash_area *fap_src,
329 const struct flash_area *fap_dst,
330 uint32_t off_src, uint32_t off_dst, uint32_t sz, uint32_t sector_off);
331 #else
332 int boot_copy_region(struct boot_loader_state *state,
333 const struct flash_area *fap_src,
334 const struct flash_area *fap_dst,
335 uint32_t off_src, uint32_t off_dst, uint32_t sz);
336 #endif
337 int boot_erase_region(const struct flash_area *fap, uint32_t off, uint32_t sz);
338 bool boot_status_is_reset(const struct boot_status *bs);
339
340 #ifdef MCUBOOT_ENC_IMAGES
341 int boot_write_enc_key(const struct flash_area *fap, uint8_t slot,
342 const struct boot_status *bs);
343 int boot_read_enc_key(const struct flash_area *fap, uint8_t slot,
344 struct boot_status *bs);
345 #endif
346
347 /**
348 * Checks that a buffer is erased according to what the erase value for the
349 * flash device provided in `flash_area` is.
350 *
351 * @returns true if the buffer is erased; false if any of the bytes is not
352 * erased, or when buffer is NULL, or when len == 0.
353 */
354 bool bootutil_buffer_is_erased(const struct flash_area *area,
355 const void *buffer, size_t len);
356
357 /**
358 * Safe (non-overflowing) uint32_t addition. Returns true, and stores
359 * the result in *dest if it can be done without overflow. Otherwise,
360 * returns false.
361 */
boot_u32_safe_add(uint32_t * dest,uint32_t a,uint32_t b)362 static inline bool boot_u32_safe_add(uint32_t *dest, uint32_t a, uint32_t b)
363 {
364 /*
365 * "a + b <= UINT32_MAX", subtract 'b' from both sides to avoid
366 * the overflow.
367 */
368 if (a > UINT32_MAX - b) {
369 return false;
370 } else {
371 *dest = a + b;
372 return true;
373 }
374 }
375
376 /**
377 * Safe (non-overflowing) uint16_t addition. Returns true, and stores
378 * the result in *dest if it can be done without overflow. Otherwise,
379 * returns false.
380 */
boot_u16_safe_add(uint16_t * dest,uint16_t a,uint16_t b)381 static inline bool boot_u16_safe_add(uint16_t *dest, uint16_t a, uint16_t b)
382 {
383 uint32_t tmp = a + b;
384 if (tmp > UINT16_MAX) {
385 return false;
386 } else {
387 *dest = tmp;
388 return true;
389 }
390 }
391
392 /*
393 * Accessors for the contents of struct boot_loader_state.
394 */
395
396 /* These are macros so they can be used as lvalues. */
397 #if (BOOT_IMAGE_NUMBER > 1)
398 #define BOOT_CURR_IMG(state) ((state)->curr_img_idx)
399 #else
400 #define BOOT_CURR_IMG(state) 0
401 #endif
402 #ifdef MCUBOOT_ENC_IMAGES
403 #define BOOT_CURR_ENC(state) ((state)->enc[BOOT_CURR_IMG(state)])
404 #else
405 #define BOOT_CURR_ENC(state) NULL
406 #endif
407 #define BOOT_IMG(state, slot) ((state)->imgs[BOOT_CURR_IMG(state)][(slot)])
408 #define BOOT_IMG_AREA(state, slot) (BOOT_IMG(state, slot).area)
409 #define BOOT_WRITE_SZ(state) ((state)->write_sz)
410 #define BOOT_SWAP_TYPE(state) ((state)->swap_type[BOOT_CURR_IMG(state)])
411 #define BOOT_TLV_OFF(hdr) ((hdr)->ih_hdr_size + (hdr)->ih_img_size)
412
413 #define BOOT_IS_UPGRADE(swap_type) \
414 (((swap_type) == BOOT_SWAP_TYPE_TEST) || \
415 ((swap_type) == BOOT_SWAP_TYPE_REVERT) || \
416 ((swap_type) == BOOT_SWAP_TYPE_PERM))
417
418 static inline struct image_header*
boot_img_hdr(struct boot_loader_state * state,size_t slot)419 boot_img_hdr(struct boot_loader_state *state, size_t slot)
420 {
421 return &BOOT_IMG(state, slot).hdr;
422 }
423
424 static inline size_t
boot_img_num_sectors(const struct boot_loader_state * state,size_t slot)425 boot_img_num_sectors(const struct boot_loader_state *state, size_t slot)
426 {
427 return BOOT_IMG(state, slot).num_sectors;
428 }
429
430 /*
431 * Offset of the slot from the beginning of the flash device.
432 */
433 static inline uint32_t
boot_img_slot_off(struct boot_loader_state * state,size_t slot)434 boot_img_slot_off(struct boot_loader_state *state, size_t slot)
435 {
436 return flash_area_get_off(BOOT_IMG_AREA(state, slot));
437 }
438
439 #ifndef MCUBOOT_USE_FLASH_AREA_GET_SECTORS
440
441 static inline size_t
boot_img_sector_size(const struct boot_loader_state * state,size_t slot,size_t sector)442 boot_img_sector_size(const struct boot_loader_state *state,
443 size_t slot, size_t sector)
444 {
445 return flash_area_get_size(&BOOT_IMG(state, slot).sectors[sector]);
446 }
447
448 /*
449 * Offset of the sector from the beginning of the image, NOT the flash
450 * device.
451 */
452 static inline uint32_t
boot_img_sector_off(const struct boot_loader_state * state,size_t slot,size_t sector)453 boot_img_sector_off(const struct boot_loader_state *state, size_t slot,
454 size_t sector)
455 {
456 return flash_area_get_off(&BOOT_IMG(state, slot).sectors[sector]) -
457 flash_area_get_off(&BOOT_IMG(state, slot).sectors[0]);
458 }
459
460 #else /* defined(MCUBOOT_USE_FLASH_AREA_GET_SECTORS) */
461
462 static inline size_t
boot_img_sector_size(const struct boot_loader_state * state,size_t slot,size_t sector)463 boot_img_sector_size(const struct boot_loader_state *state,
464 size_t slot, size_t sector)
465 {
466 return flash_sector_get_size(&BOOT_IMG(state, slot).sectors[sector]);
467 }
468
469 static inline uint32_t
boot_img_sector_off(const struct boot_loader_state * state,size_t slot,size_t sector)470 boot_img_sector_off(const struct boot_loader_state *state, size_t slot,
471 size_t sector)
472 {
473 return flash_sector_get_off(&BOOT_IMG(state, slot).sectors[sector]) -
474 flash_sector_get_off(&BOOT_IMG(state, slot).sectors[0]);
475 }
476
477 #endif /* !defined(MCUBOOT_USE_FLASH_AREA_GET_SECTORS) */
478
479 #ifdef MCUBOOT_RAM_LOAD
480 # ifdef __BOOTSIM__
481
482 /* Query for the layout of a RAM buffer appropriate for holding the
483 * image. This will be per-test-thread, and therefore must be queried
484 * through this call. */
485 struct bootsim_ram_info {
486 uint32_t start;
487 uint32_t size;
488 uintptr_t base;
489 };
490 struct bootsim_ram_info *bootsim_get_ram_info(void);
491
492 #define IMAGE_GET_FIELD(field) (bootsim_get_ram_info()->field)
493 #define IMAGE_RAM_BASE IMAGE_GET_FIELD(base)
494 #define IMAGE_EXECUTABLE_RAM_START IMAGE_GET_FIELD(start)
495 #define IMAGE_EXECUTABLE_RAM_SIZE IMAGE_GET_FIELD(size)
496
497 # else
498 # define IMAGE_RAM_BASE ((uintptr_t)0)
499 # endif
500
501 #define LOAD_IMAGE_DATA(hdr, fap, start, output, size) \
502 (memcpy((output),(void*)(IMAGE_RAM_BASE + (hdr)->ih_load_addr + (start)), \
503 (size)), 0)
504
505 int boot_load_image_to_sram(struct boot_loader_state *state);
506 #else
507 #define IMAGE_RAM_BASE ((uintptr_t)0)
508
509 #define LOAD_IMAGE_DATA(hdr, fap, start, output, size) \
510 (flash_area_read((fap), (start), (output), (size)))
511
512 #endif /* MCUBOOT_RAM_LOAD */
513
514 uint32_t bootutil_max_image_size(const struct flash_area *fap);
515
516 int boot_read_image_size(struct boot_loader_state *state, int slot,
517 uint32_t *size);
518
519 #ifdef __cplusplus
520 }
521 #endif
522
523 #endif
524