From 6f39fea03de9a0f4f732e885f2898680ea87b619 Mon Sep 17 00:00:00 2001 From: Shubham Kulkarni Date: Fri, 27 Mar 2020 19:37:53 +0530 Subject: [PATCH] esp_ota_ops.c: Fix size calculation to erase partition range for OTA image Closes https://github.com/espressif/esp-idf/issues/4953 --- components/app_update/esp_ota_ops.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/components/app_update/esp_ota_ops.c b/components/app_update/esp_ota_ops.c index 01e1e5de8..56cd8e2ec 100644 --- a/components/app_update/esp_ota_ops.c +++ b/components/app_update/esp_ota_ops.c @@ -165,7 +165,8 @@ esp_err_t esp_ota_begin(const esp_partition_t *partition, size_t image_size, esp if ((image_size == 0) || (image_size == OTA_SIZE_UNKNOWN)) { ret = esp_partition_erase_range(partition, 0, partition->size); } else { - ret = esp_partition_erase_range(partition, 0, (image_size / SPI_FLASH_SEC_SIZE + 1) * SPI_FLASH_SEC_SIZE); + const int aligned_erase_size = (image_size + SPI_FLASH_SEC_SIZE - 1) & ~(SPI_FLASH_SEC_SIZE - 1); + ret = esp_partition_erase_range(partition, 0, aligned_erase_size); } if (ret != ESP_OK) {