@@ -449,14 +449,6 @@ static bool flash_is_modifiable_addr_range(uint32_t addr, uint32_t len) {
449
449
|| addr >= (uint32_t )& _mboot_protected_flash_end_exclusive ;
450
450
}
451
451
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
-
460
452
static int mboot_flash_page_erase (uint32_t addr , uint32_t * next_addr ) {
461
453
// Compute start and end address of the sector being erased.
462
454
uint32_t sector_size = 0 ;
@@ -488,6 +480,23 @@ static int mboot_flash_page_erase(uint32_t addr, uint32_t *next_addr) {
488
480
return 0 ;
489
481
}
490
482
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
+
491
500
static int mboot_flash_write (uint32_t addr , const uint8_t * src8 , size_t len ) {
492
501
bool valid = flash_is_valid_addr (addr );
493
502
if (!valid || !flash_is_modifiable_addr_range (addr , len )) {
0 commit comments