8000 stm32/mboot: Improve mass erase to erase all non-protected pages. · pimoroni/micropython@7002a19 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7002a19

Browse files
committed
stm32/mboot: Improve mass erase to erase all non-protected pages.
Signed-off-by: Damien George <damien@micropython.org>
1 parent b7b9952 commit 7002a19

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

ports/stm32/mboot/main.c

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -449,14 +449,6 @@ static bool flash_is_modifiable_addr_range(uint32_t addr, uint32_t len) {
449449
|| addr >= (uint32_t)&_mboot_protected_flash_end_exclusive;
450450
}
451451

452-
static int mboot_flash_mass_erase(void) {
453-
// Erase all flash pages after mboot.
454-
uint32_t start_addr = (uint32_t)&_mboot_protected_flash_end_exclusive;
455-
uint32_t num_words = (FLASH_END + 1 - start_addr) / sizeof(uint32_t);
456-
int ret = flash_erase(start_addr, num_words);
457-
return ret;
458-
}
459-
460452
static int mboot_flash_page_erase(uint32_t addr, uint32_t *next_addr) {
461453
// Compute start and end address of the sector being erased.
462454
uint32_t sector_size = 0;
@@ -488,6 +480,23 @@ static int mboot_flash_page_erase(uint32_t addr, uint32_t *next_addr) {
488480
return 0;
489481
}
490482

483+
static int mboot_flash_mass_erase(void) {
484+
// Erase all flash pages except those disallowed because they overlap with mboot.
485+
uint32_t addr = FLASH_START;
486+
while (addr <= FLASH_END) {
487+
int ret = mboot_flash_page_erase(addr, &addr);
488+
if (ret != 0 && ret != -MBOOT_ERRNO_FLASH_ERASE_DISALLOWED) {
489+
return ret;
490+
}
491+
}
492+
493+
// Reset any errors from disallowed page erases.
494+
dfu_context.status = DFU_STATUS_OK;
495+
dfu_context.error = 0;
496+
497+
return 0;
498+
}
499+
491500
static int mboot_flash_write(uint32_t addr, const uint8_t *src8, size_t len) {
492501
bool valid = flash_is_valid_addr(addr);
493502
if (!valid || !flash_is_modifiable_addr_range(addr, len)) {

0 commit comments

Comments
 (0)
0