Commit 993c2ff8 authored by Ederson de Souza's avatar Ederson de Souza Committed by Jamie
Browse files

boot/bootutil/ram_load: Add flash area pointer to bootloader state

Since 1b2fc096, many places now reuse
the flash area pointer from the bootloader state. Unfortunately, some
RAM load usage (on single loader or runtime-source sample) didn't set up
the flash area pointer on the bootloader state, so they were broken.

This patch fixes that by adding the flash area pointer to the created
bootloader states - directly or via a new parameter to
boot_load_image_from_flash_to_sram().

Signed-off-by: default avatarEderson de Souza <ederson.desouza@intel.com>
parent 88294be1
Loading
Loading
Loading
Loading
+3 −1
Changes for boot/bootutil/include/bootutil/bootutil_public.h: 3 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -319,11 +319,13 @@ boot_image_load_header(const struct flash_area *fa_p,
 *
 * @param[in]   state   boot loader state
 * @param[in]   hdr     image header
 * @param[in]   fa      flash area pointer
 *
 * @return              0 on success, error code otherwise
 */
int boot_load_image_from_flash_to_sram(struct boot_loader_state *state,
                                       struct image_header *hdr);
                                       struct image_header *hdr,
                                       const struct flash_area *fa);

/**
 * Removes an image from SRAM, by overwriting it with zeros.
+3 −1
Changes for boot/bootutil/src/ram_load.c: 3 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -419,7 +419,8 @@ boot_remove_image_from_flash(struct boot_loader_state *state, uint32_t slot)
}

int boot_load_image_from_flash_to_sram(struct boot_loader_state *state,
                                       struct image_header *hdr)
                                       struct image_header *hdr,
                                       const struct flash_area *fap)
{
    int active_slot;

@@ -428,6 +429,7 @@ int boot_load_image_from_flash_to_sram(struct boot_loader_state *state,
     */
    active_slot = state->slot_usage[BOOT_CURR_IMG(state)].active_slot;
    BOOT_IMG(state, active_slot).hdr = *hdr;
    BOOT_IMG_AREA(state, active_slot) = fap;

    return boot_load_image_to_sram(state);
}
+1 −0
Changes for boot/zephyr/single_loader.c: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -121,6 +121,7 @@ boot_go(struct boot_rsp *rsp)

#ifdef MCUBOOT_RAM_LOAD
        static struct boot_loader_state state;
        BOOT_IMG_AREA(&state, 0) = _fa_p;
        state.imgs[0][0].hdr = _hdr;

        rc = boot_load_image_to_sram(&state);
+1 −1
Changes for samples/runtime-source/zephyr/hooks/hooks.c: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -72,7 +72,7 @@ fih_ret boot_go_hook(struct boot_rsp *rsp)
#ifdef MCUBOOT_RAM_LOAD
		state = boot_get_loader_state();

		rc = boot_load_image_from_flash_to_sram(state, &_hdr);
		rc = boot_load_image_from_flash_to_sram(state, &_hdr, _fa_p);
		if (rc != 0) {
			flash_area_close(_fa_p);
			continue;