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
3 changes: 2 additions & 1 deletion boot/boot_serial/src/boot_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ bs_list_set(uint8_t op, char *buf, int len)
bool area_opened = false;

state = boot_get_loader_state();
boot_state_clear(state);
boot_state_init(state);

rc = boot_open_all_flash_areas(state);
if (rc != 0) {
Expand Down Expand Up @@ -696,6 +696,7 @@ bs_list_set(uint8_t op, char *buf, int len)
if (area_opened) {
boot_close_all_flash_areas(state);
}
boot_state_clear(state);

if (rc != 0) {
bs_rc_rsp(rc);
Expand Down
7 changes: 7 additions & 0 deletions boot/bootutil/include/bootutil/bootutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ fih_ret context_boot_go(struct boot_loader_state *state, struct boot_rsp *rsp);
*/
struct boot_loader_state *boot_get_loader_state(void);

/**
* Initialize boot_loader_state object
*
* @param state Bootloader state.
*/
void boot_state_init(struct boot_loader_state *state);

#if defined(MCUBOOT_SERIAL_IMG_GRP_SLOT_INFO) || defined(MCUBOOT_DATA_SHARING)
/**
* Returns pointer to array of image maximum sizes.
Expand Down
18 changes: 18 additions & 0 deletions boot/bootutil/src/bootutil_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -381,3 +381,21 @@ boot_close_all_flash_areas(struct boot_loader_state *state)
}
}
#endif /* !MCUBOOT_SINGLE_APPLICATION_SLOT_RAM_LOAD && !MCUBOOT_SINGLE_APPLICATION_SLOT */

void boot_state_init(struct boot_loader_state *state)
{
#if defined(MCUBOOT_ENC_IMAGES)
int image;
int slot;
#endif

memset(state, 0, sizeof(*state));

#if defined(MCUBOOT_ENC_IMAGES)
for (image = 0; image < BOOT_IMAGE_NUMBER; ++image) {
for (slot = 0; slot < BOOT_NUM_SLOTS; ++slot) {
boot_enc_init(&state->enc[image][slot]);
Copy link
Collaborator

Choose a reason for hiding this comment

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

whatever was pointed by state get zeroized already.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, but the boot_enc_init may be doing extra stuff on the context, and may actually set here something different than 0.

}
}
#endif
}
21 changes: 14 additions & 7 deletions boot/bootutil/src/bootutil_misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -643,15 +643,22 @@ const struct image_max_size *boot_get_max_app_size(void)
* Clears the boot state, so that previous operations have no effect on new
* ones.
*
* @param state The state that should be cleared. If the value
* is NULL, the default bootloader state will be
* cleared.
* @param state The state that should be cleared.
*/
void boot_state_clear(struct boot_loader_state *state)
{
if (state != NULL) {
memset(state, 0, sizeof(struct boot_loader_state));
} else {
memset(boot_get_loader_state(), 0, sizeof(struct boot_loader_state));
#if defined(MCUBOOT_ENC_IMAGES)
int image;
int slot;

for (image = 0; image < BOOT_IMAGE_NUMBER; ++image) {
for (slot = 0; slot < BOOT_NUM_SLOTS; ++slot) {
/* Not using boot_enc_zeorize here, as it is redundant
* to the memset below that clears entire boot_loader_state.
*/
boot_enc_drop(&state->enc[image][slot]);
}
}
#endif
memset(state, 0, sizeof(struct boot_loader_state));
}
5 changes: 4 additions & 1 deletion boot/bootutil/src/loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -2446,9 +2446,12 @@ boot_go(struct boot_rsp *rsp)
{
FIH_DECLARE(fih_rc, FIH_FAILURE);

boot_state_clear(NULL);
boot_state_init(&boot_data);

FIH_CALL(context_boot_go, fih_rc, &boot_data, rsp);

boot_state_clear(&boot_data);

FIH_RET(fih_rc);
}

Expand Down
Loading