Skip to content

Commit

Permalink
boot: generalize boot_write_image_ok() function to get flag as parameter
Browse files Browse the repository at this point in the history
This commit generalizes boot_write_image_ok() function to take flag
as an input parameter. Function is also rename to boot_write_image_flag()
so the name matches the usage better.

This is useful to future implementation of different algorithms that
might need other flags than BOOT_FLAG_SET to be written to image
trailer.

Signed-off-by: Michal Lenc <michallenc@seznam.cz>
  • Loading branch information
michallenc committed Apr 23, 2024
1 parent d2e69bf commit 1acec48
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion boot/bootutil/src/bootutil_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ int boot_read_swap_state_by_id(int flash_area_id,
int boot_write_magic(const struct flash_area *fap);
int boot_write_status(const struct boot_loader_state *state, struct boot_status *bs);
int boot_write_copy_done(const struct flash_area *fap);
int boot_write_image_ok(const struct flash_area *fap);
int boot_write_image_flag(const struct flash_area *fap, int flag);
int boot_write_swap_info(const struct flash_area *fap, uint8_t swap_type,
uint8_t image_num);
int boot_write_swap_size(const struct flash_area *fap, uint32_t swap_size);
Expand Down
10 changes: 5 additions & 5 deletions boot/bootutil/src/bootutil_public.c
Original file line number Diff line number Diff line change
Expand Up @@ -354,15 +354,15 @@ boot_write_trailer_flag(const struct flash_area *fap, uint32_t off,
}

int
boot_write_image_ok(const struct flash_area *fap)
boot_write_image_flag(const struct flash_area *fap, int flag)
{
uint32_t off;

off = boot_image_ok_off(fap);
BOOT_LOG_DBG("writing image_ok; fa_id=%d off=0x%lx (0x%lx)",
flash_area_get_id(fap), (unsigned long)off,
(unsigned long)(flash_area_get_off(fap) + off));
return boot_write_trailer_flag(fap, off, BOOT_FLAG_SET);
return boot_write_trailer_flag(fap, off, flag);
}

int
Expand Down Expand Up @@ -515,7 +515,7 @@ boot_set_next(const struct flash_area *fa, bool active, bool confirm)
* confirm a padded image which has been programmed using
* a programming interface.
*/
rc = boot_write_image_ok(fa);
rc = boot_write_image_flag(fa, BOOT_FLAG_SET);
}

break;
Expand All @@ -525,7 +525,7 @@ boot_set_next(const struct flash_area *fa, bool active, bool confirm)
rc = boot_write_magic(fa);

if (rc == 0 && confirm) {
rc = boot_write_image_ok(fa);
rc = boot_write_image_flag(fa, BOOT_FLAG_SET);
}

if (rc == 0) {
Expand Down Expand Up @@ -605,7 +605,7 @@ boot_set_next(const struct flash_area *fa, bool active, bool confirm)
}

if (slot_state.image_ok == BOOT_FLAG_UNSET) {
rc = boot_write_image_ok(fa);
rc = boot_write_image_flag(fa, BOOT_FLAG_SET);
if (rc != 0) {
break;
}
Expand Down
4 changes: 2 additions & 2 deletions boot/bootutil/src/swap_misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ swap_status_init(const struct boot_loader_state *state,
}

if (swap_state.image_ok == BOOT_FLAG_SET) {
rc = boot_write_image_ok(fap);
rc = boot_write_image_flag(fap, BOOT_FLAG_SET);
assert(rc == 0);
}

Expand Down Expand Up @@ -222,7 +222,7 @@ swap_set_image_ok(uint8_t image_index)
}

if (state.image_ok == BOOT_FLAG_UNSET) {
rc = boot_write_image_ok(fap);
rc = boot_write_image_flag(fap, BOOT_FLAG_SET);
}

out:
Expand Down
2 changes: 1 addition & 1 deletion boot/bootutil/src/swap_move.c
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ fixup_revert(const struct boot_loader_state *state, struct boot_status *bs,
rc = swap_erase_trailer_sectors(state, fap_sec);
assert(rc == 0);

rc = boot_write_image_ok(fap_sec);
rc = boot_write_image_flag(fap_sec, BOOT_FLAG_SET);
assert(rc == 0);

rc = boot_write_swap_size(fap_sec, bs->swap_size);
Expand Down
2 changes: 1 addition & 1 deletion boot/bootutil/src/swap_scratch.c
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ boot_swap_sectors(int idx, uint32_t sz, struct boot_loader_state *state,
assert(rc == 0);

if (swap_state.image_ok == BOOT_FLAG_SET) {
rc = boot_write_image_ok(fap_primary_slot);
rc = boot_write_image_flag(fap_primary_slot, BOOT_FLAG_SET);
assert(rc == 0);
}

Expand Down
2 changes: 1 addition & 1 deletion boot/zephyr/firmware_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ boot_image_validate_once(const struct flash_area *fa_p,
if (rc != 0)
FIH_RET(FIH_FAILURE);
}
rc = boot_write_image_ok(fa_p);
rc = boot_write_image_flag(fa_p, BOOT_FLAG_SET);
if (rc != 0)
FIH_RET(FIH_FAILURE);
}
Expand Down
2 changes: 1 addition & 1 deletion boot/zephyr/single_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ boot_image_validate_once(const struct flash_area *fa_p,
if (rc != 0)
FIH_RET(FIH_FAILURE);
}
rc = boot_write_image_ok(fa_p);
rc = boot_write_image_flag(fa_p, BOOT_FLAG_SET);
if (rc != 0)
FIH_RET(FIH_FAILURE);
}
Expand Down

0 comments on commit 1acec48

Please sign in to comment.