spi_flash: protect spi_flash_unlock

spi_flash_unlock was missing spi_flash_guard_start, which caused cache
to be enabled during unlock operation, causing hard-to-trace crashes
and cache data corruption.
This commit is contained in:
Ivan Grokhotkov 2017-02-22 12:51:16 +08:00
parent e76c187efb
commit cbb71baca9

View File

@ -202,7 +202,9 @@ esp_err_t IRAM_ATTR spi_flash_write(size_t dst, const void *srcv, size_t size)
size_t mid_size = (size - left_size) & ~3U; size_t mid_size = (size - left_size) & ~3U;
size_t right_off = left_size + mid_size; size_t right_off = left_size + mid_size;
size_t right_size = size - mid_size - left_size; size_t right_size = size - mid_size - left_size;
spi_flash_guard_start();
rc = spi_flash_unlock(); rc = spi_flash_unlock();
spi_flash_guard_end();
if (rc != SPI_FLASH_RESULT_OK) { if (rc != SPI_FLASH_RESULT_OK) {
goto out; goto out;
} }
@ -289,7 +291,9 @@ esp_err_t IRAM_ATTR spi_flash_write_encrypted(size_t dest_addr, const void *src,
COUNTER_START(); COUNTER_START();
spi_flash_disable_interrupts_caches_and_other_cpu(); spi_flash_disable_interrupts_caches_and_other_cpu();
SpiFlashOpResult rc; SpiFlashOpResult rc;
spi_flash_guard_start();
rc = spi_flash_unlock(); rc = spi_flash_unlock();
spi_flash_guard_end();
spi_flash_enable_interrupts_caches_and_other_cpu(); spi_flash_enable_interrupts_caches_and_other_cpu();
if (rc == SPI_FLASH_RESULT_OK) { if (rc == SPI_FLASH_RESULT_OK) {