diff --git a/components/app_update/esp_ota_ops.c b/components/app_update/esp_ota_ops.c index 94bcc430fe85..59f122ea3e81 100644 --- a/components/app_update/esp_ota_ops.c +++ b/components/app_update/esp_ota_ops.c @@ -205,6 +205,13 @@ esp_err_t esp_ota_write(esp_ota_handle_t handle, const void *data, size_t size) uint32_t first_sector = it->wrote_size / SPI_FLASH_SEC_SIZE; uint32_t last_sector = (it->wrote_size + size) / SPI_FLASH_SEC_SIZE; + if(last_sector * SPI_FLASH_SEC_SIZE >= it->part->size) + { + //special case of having arrived passed the end of the flash, so move to the real last sector + //it probably has been erased previously, if last_sector==first_sector + last_sector = (it->part->size / SPI_FLASH_SEC_SIZE) - 1; + } + ret = ESP_OK; if ((it->wrote_size % SPI_FLASH_SEC_SIZE) == 0) { ret = esp_partition_erase_range(it->part, it->wrote_size, ((last_sector - first_sector) + 1) * SPI_FLASH_SEC_SIZE);