Skip to content

Commit 64f28dc

Browse files
committed
stm32/boards/LEGO_HUB_NO7: Add robust update logic to mboot.
Following change in 899592a Signed-off-by: Damien George <damien@micropython.org>
1 parent b896fa9 commit 64f28dc

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

ports/stm32/boards/LEGO_HUB_NO7/board_init.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,14 @@ int board_mboot_get_reset_mode(uint32_t *initial_r0) {
199199
}
200200

201201
void board_mboot_state_change(int state, uint32_t arg) {
202-
if (state == MBOOT_STATE_FSLOAD_END) {
202+
if (state == MBOOT_STATE_FSLOAD_START) {
203+
// The FS-load update is about to start. Program the update key and FS-load elements
204+
// into the flash so they can be retrieved if there is a power failure during the update.
205+
mp_spiflash_erase_block(MBOOT_SPIFLASH_SPIFLASH, SPIFLASH_UPDATE_KEY_ADDR);
206+
mp_spiflash_write(MBOOT_SPIFLASH_SPIFLASH, SPIFLASH_UPDATE_KEY_ADDR + 4, ELEM_DATA_SIZE, ELEM_DATA_START);
207+
uint32_t key = SPIFLASH_UPDATE_KEY_VALUE;
208+
mp_spiflash_write(MBOOT_SPIFLASH_SPIFLASH, SPIFLASH_UPDATE_KEY_ADDR, 4, (const uint8_t *)&key);
209+
} else if (state == MBOOT_STATE_FSLOAD_END) {
203210
// The FS-load update completed (either with success or failure), so erase the
204211
// update key and write the result of the FS-load operation into flash.
205212
mp_spiflash_erase_block(MBOOT_SPIFLASH_SPIFLASH, SPIFLASH_UPDATE_KEY_ADDR);

0 commit comments

Comments
 (0)