Skip to content

Commit

Permalink
properly unlock flash on re-entry of wolfBoot_swap_and_final_erase
Browse files Browse the repository at this point in the history
and move it out of the lock logic of update and delta update
  • Loading branch information
jpbland1 committed Dec 7, 2024
1 parent 21a4082 commit a76882a
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions src/update_flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,11 @@ static int wolfBoot_swap_and_final_erase(int resume)
if ((resume == 1) && (swapDone == 0) && (st != IMG_STATE_FINAL_FLAGS)) {
return -1;
}
hal_flash_unlock();
#ifdef EXT_FLASH
ext_flash_unlock();
#endif

if (swapDone == 0) {
/* IMG_STATE_FINAL_FLAGS allows re-entry without blowing away swap */
if (st != IMG_STATE_FINAL_FLAGS) {
Expand Down Expand Up @@ -282,6 +287,12 @@ static int wolfBoot_swap_and_final_erase(int resume)
wolfBoot_set_partition_state(PART_BOOT, IMG_STATE_TESTING);
/* erase the last sector(s) of update */
wb_flash_erase(update, WOLFBOOT_PARTITION_SIZE - eraseLen, eraseLen);

#ifdef EXT_FLASH
ext_flash_lock();
#endif
hal_flash_lock();

return 0;
}
#endif
Expand Down Expand Up @@ -480,15 +491,17 @@ static int wolfBoot_delta_update(struct wolfBoot_image *boot,
sector++;
}
#ifndef DISABLE_BACKUP
/* start re-entrant final erase, return code is only for resumption in
* wolfBoot_start */
wolfBoot_swap_and_final_erase(0);
#endif
out:
#ifdef EXT_FLASH
ext_flash_lock();
#endif
hal_flash_lock();
/* start re-entrant final erase, return code is only for resumption in
* wolfBoot_start */
if (ret == 0) {
wolfBoot_swap_and_final_erase(0);
}
/* encryption key was not erased, will be erased by success */
return ret;
}
Expand Down Expand Up @@ -741,14 +754,14 @@ static int RAMFUNCTION wolfBoot_update(int fallback_allowed)
}
#endif /* WOLFBOOT_FLASH_MULTI_SECTOR_ERASE */

/* start re-entrant final erase, return code is only for resumption in
* wolfBoot_start*/
wolfBoot_swap_and_final_erase(0);
/* encryption key was not erased, will be erased by success */
#ifdef EXT_FLASH
ext_flash_lock();
#endif
hal_flash_lock();
/* start re-entrant final erase, return code is only for resumption in
* wolfBoot_start*/
wolfBoot_swap_and_final_erase(0);

#else /* DISABLE_BACKUP */
/* Direct Swap without power fail safety */
Expand Down

0 comments on commit a76882a

Please sign in to comment.