Skip to content
Open
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
15 changes: 15 additions & 0 deletions boot/bootutil/include/bootutil/boot_hooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,21 @@ int boot_img_install_stat_hook(int image_index, int slot,
*/
int boot_reset_request_hook(bool force);

/** Hook provides a way for the custom image loading and validation.
*
* @param img_index the index of the image pair
* @param slot slot number
* @param img_dst image destination address to be populated
* @param img_sz image size to be populated
*
* @retval 0: success, mcuboot will follow normal code execution flow after
* execution of this call.
* non-zero: an error, will be transferred as part of command response
* as "rc" entry.
*/
int boot_load_image_to_sram_hook(int image_index, int slot,
uint32_t *img_dst, uint32_t *img_sz);
Comment on lines +240 to +241

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this doesn't make sense vs what boot_load_image_to_sram has?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, not 100% clear here. The intention of this call is that we can hook the SRAM load process to replace the decryption and memory copy routines, for cases where we have custom hardware that handles those routines. Are you saying that the documentation here isn't clear, or that the hook should behave differently?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should have the same function arguments that the normal function has to allow it to do a variety of different things. Also not sure how this would work loading since you have no information from the image?


/**
* Hook to implement custom action before boot_go() function.
*
Expand Down
9 changes: 8 additions & 1 deletion boot/bootutil/src/loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -2307,7 +2307,14 @@ boot_load_and_validate_images(struct boot_loader_state *state)
* when loading images from external (untrusted) flash to internal
* (trusted) RAM and image is authenticated before copying.
*/
rc = boot_load_image_to_sram(state);
rc = BOOT_HOOK_CALL(boot_load_image_to_sram_hook, BOOT_HOOK_REGULAR,
BOOT_CURR_IMG(state), active_slot,
&state->slot_usage[BOOT_CURR_IMG(state)].img_dst,
&state->slot_usage[BOOT_CURR_IMG(state)].img_sz);
if (rc == BOOT_HOOK_REGULAR)
{
rc = boot_load_image_to_sram(state);
}
if (rc != 0 ) {
/* Image cannot be ramloaded. */
boot_remove_image_from_flash(state, active_slot);
Expand Down
6 changes: 6 additions & 0 deletions boot/zephyr/hooks_sample.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,9 @@ int boot_find_next_slot_hook(struct boot_loader_state *state, uint8_t image,
{
return BOOT_HOOK_REGULAR;
}

int boot_load_image_to_sram_hook(int image_index, int slot,
size_t *img_dst, size_t *img_sz)
{
return BOOT_HOOK_REGULAR;
}
Loading