boot_serial: espressif: enable erase progressively option on serial recovery
Signed-off-by: Almir Okato <almir.okato@espressif.com>
diff --git a/boot/espressif/hal/include/mcuboot_config/mcuboot_config.h b/boot/espressif/hal/include/mcuboot_config/mcuboot_config.h
index 5cfe786..eee8f0b 100644
--- a/boot/espressif/hal/include/mcuboot_config/mcuboot_config.h
+++ b/boot/espressif/hal/include/mcuboot_config/mcuboot_config.h
@@ -143,6 +143,18 @@
#define CONFIG_MCUBOOT_SERIAL
#endif
+/*
+ * When a serial recovery process is receiving the image data, this option
+ * enables it to erase flash progressively (by sectors) instead of the
+ * default behavior that is erasing whole image size of flash area after
+ * receiving first frame.
+ * Enabling this options prevents stalling the beginning of transfer
+ * for the time needed to erase large chunk of flash.
+ */
+#ifdef CONFIG_ESP_MCUBOOT_ERASE_PROGRESSIVELY
+#define MCUBOOT_ERASE_PROGRESSIVELY
+#endif
+
/* Serial extensions are not implemented
*/
#define MCUBOOT_PERUSER_MGMT_GROUP_ENABLED 0
diff --git a/boot/espressif/include/flash_map_backend/flash_map_backend.h b/boot/espressif/include/flash_map_backend/flash_map_backend.h
index b56bcbc..804b768 100644
--- a/boot/espressif/include/flash_map_backend/flash_map_backend.h
+++ b/boot/espressif/include/flash_map_backend/flash_map_backend.h
@@ -77,6 +77,9 @@
int flash_area_get_sectors(int fa_id, uint32_t *count,
struct flash_sector *sectors);
+//! Retrieve the flash sector a given offset belongs to.
+int flash_area_sector_from_off(uint32_t off, struct flash_sector *sector);
+
//! Returns the `fa_id` for slot, where slot is 0 (primary) or 1 (secondary).
//!
//! `image_index` (0 or 1) is the index of the image. Image index is
diff --git a/boot/espressif/port/esp32/bootloader.conf b/boot/espressif/port/esp32/bootloader.conf
index c374e13..67a4d14 100644
--- a/boot/espressif/port/esp32/bootloader.conf
+++ b/boot/espressif/port/esp32/bootloader.conf
@@ -15,6 +15,9 @@
# Enables the MCUboot Serial Recovery, that allows the use of
# MCUMGR to upload a firmware through the serial port
# CONFIG_ESP_MCUBOOT_SERIAL=y
+# Use sector erasing instead of entire image size erasing
+# when uploading through Serial Recovery
+# CONFIG_ESP_MCUBOOT_ERASE_PROGRESSIVELY=y
# GPIO used to boot on Serial Recovery
# CONFIG_ESP_SERIAL_BOOT_GPIO_DETECT=32
# GPIO input type (0 for Pull-down, 1 for Pull-up)
diff --git a/boot/espressif/port/esp_mcuboot.c b/boot/espressif/port/esp_mcuboot.c
index 3035515..088749c 100644
--- a/boot/espressif/port/esp_mcuboot.c
+++ b/boot/espressif/port/esp_mcuboot.c
@@ -364,6 +364,14 @@
return 0;
}
+int flash_area_sector_from_off(uint32_t off, struct flash_sector *sector)
+{
+ sector->fs_off = (off / FLASH_SECTOR_SIZE) * FLASH_SECTOR_SIZE;
+ sector->fs_size = FLASH_SECTOR_SIZE;
+
+ return 0;
+}
+
int flash_area_id_from_multi_image_slot(int image_index, int slot)
{
BOOT_LOG_DBG("%s", __func__);