From 6319e71998408f4268b4cdbe9730130dd5d0592c Mon Sep 17 00:00:00 2001 From: Julian Oes Date: Tue, 20 Feb 2024 11:52:08 +1300 Subject: [PATCH] tools/bootloader: add force-erase option If the STM32H7 fails to program or erase a full chunk of 256 bytes, the ECC check will trigger a busfault when trying to read from it. To speed up erasing and optimize wear, we read before erasing to check if it actually needs erasing. That's when a busfault happens and the erase time outs. The workaround is to add an option to do a full erase without check. Credit goes to: https://github.com/ArduPilot/ardupilot/pull/22090 And the protocol option added to the bootloader is the same as for ArduPilot, so compatible. Signed-off-by: Julian Oes --- platforms/nuttx/src/bootloader/nxp/imxrt_common/main.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/platforms/nuttx/src/bootloader/nxp/imxrt_common/main.c b/platforms/nuttx/src/bootloader/nxp/imxrt_common/main.c index dcdc50a91168..ebb9e19950d1 100644 --- a/platforms/nuttx/src/bootloader/nxp/imxrt_common/main.c +++ b/platforms/nuttx/src/bootloader/nxp/imxrt_common/main.c @@ -432,6 +432,7 @@ flash_func_erase_sector(unsigned sector, bool force) return; } +<<<<<<< HEAD if (force || up_progmem_ispageerased(sector) != 0) { struct flexspi_nor_config_s *pConfig = &g_bootConfig; @@ -439,6 +440,11 @@ flash_func_erase_sector(unsigned sector, bool force) const uint32_t bytes_per_sector = flash_func_sector_size(sector); uint32_t *address = (uint32_t *)(IMXRT_FLEXSPI1_CIPHER_BASE + (sector * bytes_per_sector)); +======= + if (force || flash_func_is_sector_blank(sector) != 0) { + struct flexspi_nor_config_s *pConfig = &g_bootConfig; + +>>>>>>> 21e550fdba (tools/bootloader: add force-erase option) uintptr_t offset = ((uintptr_t) address) - IMXRT_FLEXSPI1_CIPHER_BASE; irqstate_t flags; flags = enter_critical_section();