Skip to content

Commit 81a63ee

Browse files
committed
Attempt to fix double write in update_trigger
(when NVM_FLASH_WRITEONCE workaround is active)
1 parent 4b93736 commit 81a63ee

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/libwolfboot.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -753,16 +753,22 @@ void RAMFUNCTION wolfBoot_update_trigger(void)
753753
* not match what's in wolfBoot */
754754
if (FLAGS_UPDATE_EXT()) {
755755
ext_flash_erase(lastSector, SECTOR_FLAGS_SIZE);
756+
wolfBoot_set_partition_state(PART_UPDATE, st);
756757
} else {
757758
#ifndef NVM_FLASH_WRITEONCE
758759
hal_flash_erase(lastSector, SECTOR_FLAGS_SIZE);
760+
wolfBoot_set_partition_state(PART_UPDATE, st);
759761
#else
762+
uint32_t magic = WOLFBOOT_MAGIC_TRAIL;
760763
selSec = nvm_select_fresh_sector(PART_UPDATE);
761764
XMEMCPY(NVM_CACHE, (uint8_t*)lastSector - WOLFBOOT_SECTOR_SIZE * selSec,
762765
WOLFBOOT_SECTOR_SIZE);
763766
/* write to the non selected sector */
764767
hal_flash_erase(lastSector - WOLFBOOT_SECTOR_SIZE * !selSec,
765768
WOLFBOOT_SECTOR_SIZE);
769+
770+
NVM_CACHE[SECTOR_FLAGS_SIZE] = IMG_STATE_UPDATING;
771+
memcpy(NVM_CACHE + SECTOR_FLAGS_SIZE + 1, &magic, sizeof(uint32_t));
766772
hal_flash_write(lastSector - WOLFBOOT_SECTOR_SIZE * !selSec, NVM_CACHE,
767773
WOLFBOOT_SECTOR_SIZE);
768774
/* erase the previously selected sector */
@@ -771,7 +777,6 @@ void RAMFUNCTION wolfBoot_update_trigger(void)
771777
#endif
772778
}
773779

774-
wolfBoot_set_partition_state(PART_UPDATE, st);
775780

776781
if (FLAGS_UPDATE_EXT()) {
777782
ext_flash_lock();

0 commit comments

Comments
 (0)