Feeding the watchdog when erasing a big update partition on external flash
I am using mcuboot on a nrf91 (zephyr/nrf-sdk). The update partition mcuboot_secondary is a 1MByte partition on external spi nor flash.
It the update firmware (app_update.bin) is signed with the wrong key, mcuboot detects this (in about 650msec for a 400kByte files). Afterwards the complete partition in erased in one step: https://github.com/mcu-tools/mcuboot/blob/main/boot/bootutil/src/loader.c#L770 This takes about 3.7 seconds on my platform, which is the slowest operation within mcuboot.
To be able to use the watchdog with lower timeout, e.g. 2 seconds, i implemented a workaround to feed the watchdog:
/* Erase in 128 kByte blocks to be able to feed the watchdog.
* This takes about 460msec each block on nrf91 with external
* nor flash.
*/
size_t erase_size = 0x20000;
for (off_t offset = 0; offset < fap->fa_size; offset += erase_size) {
if (offset + erase_size > fap->fa_size) {
erase_size = fap->fa_size - offset;
}
MCUBOOT_WATCHDOG_FEED();
flash_area_erase(fap, offset, erase_size);
}
MCUBOOT_WATCHDOG_FEED();
Could this contributed, if this would be implemented in a better way?
I think it would be better to have this functionality in the wrapper between MCUboot and the platform or os-specific interfaces to the flash drivers. Although I'm not aware of any flash devices with sectors larger than 128k, this would fail if such devices existed.
Given that the flash area API is implemented directly by Zephyr, putting it there is probably not ideal. This would work, if we had a configuration variable that specific smaller values to set the erase size to.
Perhaps implement an MCUboot-specific erase call that either just calls flash_area_erase directly, or does it in a loop with watchdog feeding, as you have above.
This issue has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this issue will automatically be closed in 14 days. Note, that you can always re-open a closed issue at any time.