From 401c940434acbbc5e0b42b45ab1ad7be08e0e3d6 Mon Sep 17 00:00:00 2001 From: Mahavir Jain Date: Mon, 27 Aug 2018 21:54:20 +0530 Subject: [PATCH] spi_flash: fix erase_range for block erase check Erase in block (64k) as much as possible, before falling back to sector (4k) erase. Signed-off-by: Mahavir Jain --- components/spi_flash/flash_ops.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/spi_flash/flash_ops.c b/components/spi_flash/flash_ops.c index aab0c1210f..89f9ef5e14 100644 --- a/components/spi_flash/flash_ops.c +++ b/components/spi_flash/flash_ops.c @@ -218,7 +218,7 @@ esp_err_t IRAM_ATTR spi_flash_erase_range(uint32_t start_addr, uint32_t size) if (rc == ESP_ROM_SPIFLASH_RESULT_OK) { for (size_t sector = start; sector != end && rc == ESP_ROM_SPIFLASH_RESULT_OK; ) { spi_flash_guard_start(); - if (sector % sectors_per_block == 0 && end - sector > sectors_per_block) { + if (sector % sectors_per_block == 0 && end - sector >= sectors_per_block) { rc = esp_rom_spiflash_erase_block(sector / sectors_per_block); sector += sectors_per_block; COUNTER_ADD_BYTES(erase, sectors_per_block * SPI_FLASH_SEC_SIZE);