Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] Support image sources other than flash #2031

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions boot/bootutil/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,9 @@ target_sources(bootutil
src/swap_scratch.c
src/tlv.c
)
if(CONFIG_BOOT_RAM_LOAD)
target_sources(bootutil
PRIVATE
src/ram_load.c
)
endif()
69 changes: 68 additions & 1 deletion boot/bootutil/src/bootutil_misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,9 @@ boot_write_enc_key(const struct flash_area *fap, uint8_t slot,

uint32_t bootutil_max_image_size(const struct flash_area *fap)
{
#if defined(MCUBOOT_SWAP_USING_SCRATCH) || defined(MCUBOOT_SINGLE_APPLICATION_SLOT) || \
#if defined(MCUBOOT_FLASH_MAP_CUSTOM_SOURCES)
return flash_area_get_size(fap);
#elif defined(MCUBOOT_SWAP_USING_SCRATCH) || defined(MCUBOOT_SINGLE_APPLICATION_SLOT) || \
defined(MCUBOOT_FIRMWARE_LOADER)
return boot_status_off(fap);
#elif defined(MCUBOOT_SWAP_USING_MOVE)
Expand All @@ -355,3 +357,68 @@ uint32_t bootutil_max_image_size(const struct flash_area *fap)
return boot_swap_info_off(fap);
#endif
}

/*
* Compute the total size of the given image. Includes the size of
* the TLVs.
*/
#if !defined(MCUBOOT_DIRECT_XIP) && \
(!defined(MCUBOOT_OVERWRITE_ONLY) || \
defined(MCUBOOT_OVERWRITE_ONLY_FAST))
int
boot_read_image_size(struct boot_loader_state *state, int slot, uint32_t *size)
{
const struct flash_area *fap;
struct image_tlv_info info;
uint32_t off;
uint32_t protect_tlv_size;
int area_id;
int rc;

#if (BOOT_IMAGE_NUMBER == 1)
(void)state;
#endif

area_id = flash_area_id_from_multi_image_slot(BOOT_CURR_IMG(state), slot);
rc = flash_area_open(area_id, &fap);
if (rc != 0) {
rc = BOOT_EFLASH;
goto done;
}

off = BOOT_TLV_OFF(boot_img_hdr(state, slot));

if (flash_area_read(fap, off, &info, sizeof(info))) {
rc = BOOT_EFLASH;
goto done;
}

protect_tlv_size = boot_img_hdr(state, slot)->ih_protect_tlv_size;
if (info.it_magic == IMAGE_TLV_PROT_INFO_MAGIC) {
if (protect_tlv_size != info.it_tlv_tot) {
rc = BOOT_EBADIMAGE;
goto done;
}

if (flash_area_read(fap, off + info.it_tlv_tot, &info, sizeof(info))) {
rc = BOOT_EFLASH;
goto done;
}
} else if (protect_tlv_size != 0) {
rc = BOOT_EBADIMAGE;
goto done;
}

if (info.it_magic != IMAGE_TLV_INFO_MAGIC) {
rc = BOOT_EBADIMAGE;
goto done;
}

*size = off + protect_tlv_size + info.it_tlv_tot;
rc = 0;

done:
flash_area_close(fap);
return rc;
}
#endif /* !MCUBOOT_OVERWRITE_ONLY */
11 changes: 11 additions & 0 deletions boot/bootutil/src/bootutil_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ struct flash_area;

#define BOOT_TMPBUF_SZ 256

#define NO_ACTIVE_SLOT UINT32_MAX

/** Number of image slots in flash; currently limited to two. */
#define BOOT_NUM_SLOTS 2

Expand Down Expand Up @@ -461,15 +463,24 @@ struct bootsim_ram_info *bootsim_get_ram_info(void);
#define LOAD_IMAGE_DATA(hdr, fap, start, output, size) \
(memcpy((output),(void*)(IMAGE_RAM_BASE + (hdr)->ih_load_addr + (start)), \
(size)), 0)

int boot_load_image_to_sram(struct boot_loader_state *state);
int boot_remove_image_from_sram(struct boot_loader_state *state);
int boot_remove_image_from_flash(struct boot_loader_state *state,
uint32_t slot);
#else
#define IMAGE_RAM_BASE ((uintptr_t)0)

#define LOAD_IMAGE_DATA(hdr, fap, start, output, size) \
(flash_area_read((fap), (start), (output), (size)))

#endif /* MCUBOOT_RAM_LOAD */

uint32_t bootutil_max_image_size(const struct flash_area *fap);

int boot_read_image_size(struct boot_loader_state *state, int slot,
uint32_t *size);

#ifdef __cplusplus
}
#endif
Expand Down
Loading