Skip to content

Commit 9f1e573

Browse files
edersondisouzanvlsianpu
authored andcommitted
boot/bootutil: Split RAM load code to its own file
RAM loading code is currently under bootutil/loader.c, and it's not accessible for different loaders, such as the single loaders. Future patches will make use of the RAM loading code outside the bootutil/loader.c context, and this patch prepares for that by making it standalone on boot/bootutil/src/ram_load.c Signed-off-by: Ederson de Souza <[email protected]> Signed-off-by: Tom Burdick <[email protected]>
1 parent 33de65c commit 9f1e573

File tree

11 files changed

+546
-471
lines changed

11 files changed

+546
-471
lines changed

boot/bootutil/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,9 @@ target_sources(bootutil
3333
src/swap_scratch.c
3434
src/tlv.c
3535
)
36+
if(CONFIG_BOOT_RAM_LOAD)
37+
target_sources(bootutil
38+
PRIVATE
39+
src/ram_load.c
40+
)
41+
endif()

boot/bootutil/pkg.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ pkg.ign_files.BOOTUTIL_SINGLE_APPLICATION_SLOT:
4545
- "loader.c"
4646
- "swap_scratch.c"
4747

48+
pkg.ign_files:
49+
- "ram_load.c"
50+
4851
pkg.deps.BOOTUTIL_USE_MBED_TLS:
4952
- "@apache-mynewt-core/crypto/mbedtls"
5053

boot/bootutil/src/bootutil_misc.c

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,3 +355,68 @@ uint32_t bootutil_max_image_size(const struct flash_area *fap)
355355
return boot_swap_info_off(fap);
356356
#endif
357357
}
358+
359+
/*
360+
* Compute the total size of the given image. Includes the size of
361+
* the TLVs.
362+
*/
363+
#if !defined(MCUBOOT_DIRECT_XIP) && \
364+
(!defined(MCUBOOT_OVERWRITE_ONLY) || \
365+
defined(MCUBOOT_OVERWRITE_ONLY_FAST))
366+
int
367+
boot_read_image_size(struct boot_loader_state *state, int slot, uint32_t *size)
368+
{
369+
const struct flash_area *fap;
370+
struct image_tlv_info info;
371+
uint32_t off;
372+
uint32_t protect_tlv_size;
373+
int area_id;
374+
int rc;
375+
376+
#if (BOOT_IMAGE_NUMBER == 1)
377+
(void)state;
378+
#endif
379+
380+
area_id = flash_area_id_from_multi_image_slot(BOOT_CURR_IMG(state), slot);
381+
rc = flash_area_open(area_id, &fap);
382+
if (rc != 0) {
383+
rc = BOOT_EFLASH;
384+
goto done;
385+
}
386+
387+
off = BOOT_TLV_OFF(boot_img_hdr(state, slot));
388+
389+
if (flash_area_read(fap, off, &info, sizeof(info))) {
390+
rc = BOOT_EFLASH;
391+
goto done;
392+
}
393+
394+
protect_tlv_size = boot_img_hdr(state, slot)->ih_protect_tlv_size;
395+
if (info.it_magic == IMAGE_TLV_PROT_INFO_MAGIC) {
396+
if (protect_tlv_size != info.it_tlv_tot) {
397+
rc = BOOT_EBADIMAGE;
398+
goto done;
399+
}
400+
401+
if (flash_area_read(fap, off + info.it_tlv_tot, &info, sizeof(info))) {
402+
rc = BOOT_EFLASH;
403+
goto done;
404+
}
405+
} else if (protect_tlv_size != 0) {
406+
rc = BOOT_EBADIMAGE;
407+
goto done;
408+
}
409+
410+
if (info.it_magic != IMAGE_TLV_INFO_MAGIC) {
411+
rc = BOOT_EBADIMAGE;
412+
goto done;
413+
}
414+
415+
*size = off + protect_tlv_size + info.it_tlv_tot;
416+
rc = 0;
417+
418+
done:
419+
flash_area_close(fap);
420+
return rc;
421+
}
422+
#endif /* !MCUBOOT_OVERWRITE_ONLY */

boot/bootutil/src/bootutil_priv.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ struct flash_area;
5151

5252
#define BOOT_TMPBUF_SZ 256
5353

54+
#define NO_ACTIVE_SLOT UINT32_MAX
55+
5456
/** Number of image slots in flash; currently limited to two. */
5557
#define BOOT_NUM_SLOTS 2
5658

@@ -467,15 +469,24 @@ struct bootsim_ram_info *bootsim_get_ram_info(void);
467469
#define LOAD_IMAGE_DATA(hdr, fap, start, output, size) \
468470
(memcpy((output),(void*)(IMAGE_RAM_BASE + (hdr)->ih_load_addr + (start)), \
469471
(size)), 0)
472+
473+
int boot_load_image_to_sram(struct boot_loader_state *state);
474+
int boot_remove_image_from_sram(struct boot_loader_state *state);
475+
int boot_remove_image_from_flash(struct boot_loader_state *state,
476+
uint32_t slot);
470477
#else
471478
#define IMAGE_RAM_BASE ((uintptr_t)0)
472479

473480
#define LOAD_IMAGE_DATA(hdr, fap, start, output, size) \
474481
(flash_area_read((fap), (start), (output), (size)))
482+
475483
#endif /* MCUBOOT_RAM_LOAD */
476484

477485
uint32_t bootutil_max_image_size(const struct flash_area *fap);
478486

487+
int boot_read_image_size(struct boot_loader_state *state, int slot,
488+
uint32_t *size);
489+
479490
#ifdef __cplusplus
480491
}
481492
#endif

0 commit comments

Comments
 (0)