Skip to content

Commit c9aa7fd

Browse files
edersondisouzanordicjm
authored andcommitted
boot/bootutil: Make RAM loading methods public
RAM loading methods are currently private, which prevents external modules with hooks from using them. This patch makes them public. An interesting note is that a new method, `boot_load_image_from_flash_to_sram()`, is added so that code can actually set the image to be loaded - currently, that is inferred from current boot loader state, but external code can't directly access members of relevant `struct boot_loader_state`. Signed-off-by: Ederson de Souza <[email protected]>
1 parent 98a6681 commit c9aa7fd

File tree

3 files changed

+49
-3
lines changed

3 files changed

+49
-3
lines changed

boot/bootutil/include/bootutil/bootutil_public.h

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,41 @@ int
311311
boot_image_load_header(const struct flash_area *fa_p,
312312
struct image_header *hdr);
313313

314+
#ifdef MCUBOOT_RAM_LOAD
315+
/**
316+
* Loads image with given header to RAM.
317+
*
318+
* Destination on RAM and size is described on image header.
319+
*
320+
* @param[in] state boot loader state
321+
* @param[in] hdr image header
322+
*
323+
* @return 0 on success, error code otherwise
324+
*/
325+
int boot_load_image_from_flash_to_sram(struct boot_loader_state *state,
326+
struct image_header *hdr);
327+
328+
/**
329+
* Removes an image from SRAM, by overwriting it with zeros.
330+
*
331+
* @param state Boot loader status information.
332+
*
333+
* @return 0 on success; nonzero on failure.
334+
*/
335+
int boot_remove_image_from_sram(struct boot_loader_state *state);
336+
337+
/**
338+
* Removes an image from flash by erasing the corresponding flash area
339+
*
340+
* @param state Boot loader status information.
341+
* @param slot The flash slot of the image to be erased.
342+
*
343+
* @return 0 on success; nonzero on failure.
344+
*/
345+
int boot_remove_image_from_flash(struct boot_loader_state *state,
346+
uint32_t slot);
347+
#endif
348+
314349
#ifdef __cplusplus
315350
}
316351
#endif

boot/bootutil/src/bootutil_priv.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -503,9 +503,6 @@ struct bootsim_ram_info *bootsim_get_ram_info(void);
503503
(size)), 0)
504504

505505
int boot_load_image_to_sram(struct boot_loader_state *state);
506-
int boot_remove_image_from_sram(struct boot_loader_state *state);
507-
int boot_remove_image_from_flash(struct boot_loader_state *state,
508-
uint32_t slot);
509506
#else
510507
#define IMAGE_RAM_BASE ((uintptr_t)0)
511508

boot/bootutil/src/ram_load.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,3 +438,17 @@ boot_remove_image_from_flash(struct boot_loader_state *state, uint32_t slot)
438438

439439
return rc;
440440
}
441+
442+
int boot_load_image_from_flash_to_sram(struct boot_loader_state *state,
443+
struct image_header *hdr)
444+
{
445+
int active_slot;
446+
447+
/* boot_load_image_to_sram will load the image from state active_slot,
448+
* so force it before loading the image.
449+
*/
450+
active_slot = state->slot_usage[BOOT_CURR_IMG(state)].active_slot;
451+
BOOT_IMG(state, active_slot).hdr = *hdr;
452+
453+
return boot_load_image_to_sram(state);
454+
}

0 commit comments

Comments
 (0)