summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ports/stm32/boards/LEGO_HUB_NO7/board_init.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/ports/stm32/boards/LEGO_HUB_NO7/board_init.c b/ports/stm32/boards/LEGO_HUB_NO7/board_init.c
index 7b155b1c3..4f7b36c29 100644
--- a/ports/stm32/boards/LEGO_HUB_NO7/board_init.c
+++ b/ports/stm32/boards/LEGO_HUB_NO7/board_init.c
@@ -199,7 +199,14 @@ int board_mboot_get_reset_mode(uint32_t *initial_r0) {
}
void board_mboot_state_change(int state, uint32_t arg) {
- if (state == MBOOT_STATE_FSLOAD_END) {
+ if (state == MBOOT_STATE_FSLOAD_START) {
+ // The FS-load update is about to start. Program the update key and FS-load elements
+ // into the flash so they can be retrieved if there is a power failure during the update.
+ mp_spiflash_erase_block(MBOOT_SPIFLASH_SPIFLASH, SPIFLASH_UPDATE_KEY_ADDR);
+ mp_spiflash_write(MBOOT_SPIFLASH_SPIFLASH, SPIFLASH_UPDATE_KEY_ADDR + 4, ELEM_DATA_SIZE, ELEM_DATA_START);
+ uint32_t key = SPIFLASH_UPDATE_KEY_VALUE;
+ mp_spiflash_write(MBOOT_SPIFLASH_SPIFLASH, SPIFLASH_UPDATE_KEY_ADDR, 4, (const uint8_t *)&key);
+ } else if (state == MBOOT_STATE_FSLOAD_END) {
// The FS-load update completed (either with success or failure), so erase the
// update key and write the result of the FS-load operation into flash.
mp_spiflash_erase_block(MBOOT_SPIFLASH_SPIFLASH, SPIFLASH_UPDATE_KEY_ADDR);