Bug: esp_flash_erase_region() misbehaves on an encrypted flash
Posted: Wed Apr 16, 2025 6:58 pm
IDF5.0.1, Flash encryption: DEV MODE
ISSUE: Reading out flash with esp_flash_read_encrypted() right after esp_flash_erase_region() DOES NOT return 0xFF's. Instead, arbitrary garbage is returned.
Same procedure ( esp_flash_erase_region() followed by esp_flash_read() ) on an unencrypted flash returns 0xFF's.
Sample code (DEV_MODE flash encryption):
I believe this is not the way things should happen.
esp_flash_erase_region() is likely to be revised to work with encrypted flash properly.
ISSUE: Reading out flash with esp_flash_read_encrypted() right after esp_flash_erase_region() DOES NOT return 0xFF's. Instead, arbitrary garbage is returned.
Same procedure ( esp_flash_erase_region() followed by esp_flash_read() ) on an unencrypted flash returns 0xFF's.
Sample code (DEV_MODE flash encryption):
Code: Select all
#include "esp_flash_spi_init.h"
#define ANY_ADDR 0x60000
static uint8_t test[0x1000];
// (1) 1st go
esp_flash_read_encrypted(0, ANY_ADDR, &test, 0x1000);
printf("\n\n1st check:\n\n"); for(uint16_t i=0; i< 0x1000; i++){ printf("%02X ",test[i]); }
// (2) erasing flash
esp_flash_erase_region(0, ANY_ADDR, 0x1000);
// (3) 2nd go
esp_flash_read_encrypted(0, ANY_ADDR, &test, 0x1000);
printf("\n\n2nd check:\n\n"); for(uint16_t i=0; i< 0x1000; i++){ printf("%02X ",test[i]); }
fflush(0);
esp_flash_erase_region() is likely to be revised to work with encrypted flash properly.