Skip to content

Commit 899592a

Browse files
committed
stm32/boards/LEGO_HUB_NO6: Move robust logic to mboot.
Signed-off-by: Damien George <damien@micropython.org>
1 parent 9651046 commit 899592a

File tree

2 files changed

+8
-13
lines changed

2 files changed

+8
-13
lines changed

ports/stm32/boards/LEGO_HUB_NO6/appupdate.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
_IOCTL_BLOCK_COUNT = const(4)
88
_IOCTL_BLOCK_SIZE = const(5)
99

10-
_SPIFLASH_UPDATE_KEY_ADDR = const(1020 * 1024)
11-
_SPIFLASH_UPDATE_KEY_VALUE = const(0x12345678)
12-
1310
_FILESYSTEM_ADDR = const(0x8000_0000 + 1024 * 1024)
1411

1512
# Roundabout way to get actual filesystem size from config.
@@ -26,9 +23,6 @@ def update_app(filename):
2623
if not elems:
2724
return
2825

29-
# Create the update key.
30-
key = struct.pack("<I", _SPIFLASH_UPDATE_KEY_VALUE)
31-
3226
# Create a SPI flash object.
3327
spi = machine.SoftSPI(
3428
sck=machine.Pin.board.FLASH_SCK,
@@ -41,11 +35,5 @@ def update_app(filename):
4135
# We can't use pyb.Flash() because we need to write to the "reserved" 1M area.
4236
flash = spiflash.SPIFlash(spi, cs)
4337

44-
# Write the update key and elements to the SPI flash.
45-
flash.erase_block(_SPIFLASH_UPDATE_KEY_ADDR)
46-
flash.write(_SPIFLASH_UPDATE_KEY_ADDR, key + elems)
47-
4838
# Enter mboot with a request to do a filesystem-load update.
49-
# If there is a power failure during the update (eg battery removed) then
50-
# mboot will read the SPI flash update key and elements and retry.
5139
machine.bootloader(elems)

ports/stm32/boards/LEGO_HUB_NO6/board_init.c

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

196196
void board_mboot_state_change(int state, uint32_t arg) {
197-
if (state == MBOOT_STATE_FSLOAD_END) {
197+
if (state == MBOOT_STATE_FSLOAD_START) {
198+
// The FS-load update is about to start. Program the update key and FS-load elements
199+
// into the flash so they can be retrieved if there is a power failure during the update.
200+
mp_spiflash_erase_block(MBOOT_SPIFLASH_SPIFLASH, SPIFLASH_UPDATE_KEY_ADDR);
201+
uint32_t key = SPIFLASH_UPDATE_KEY_VALUE;
202+
mp_spiflash_write(MBOOT_SPIFLASH_SPIFLASH, SPIFLASH_UPDATE_KEY_ADDR, 4, (const uint8_t *)&key);
203+
mp_spiflash_write(MBOOT_SPIFLASH_SPIFLASH, SPIFLASH_UPDATE_KEY_ADDR + 4, ELEM_DATA_SIZE, ELEM_DATA_START);
204+
} else if (state == MBOOT_STATE_FSLOAD_END) {
198205
// The FS-load update completed (either with success or failure), so erase the
199206
// update key and write the result of the FS-load operation into flash.
200207
mp_spiflash_erase_block(MBOOT_SPIFLASH_SPIFLASH, SPIFLASH_UPDATE_KEY_ADDR);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy