How to tell if encrypted flash has been written
Posted: Sun Dec 04, 2022 6:34 pm
We have been using esp_partition_write/read functions to access a partition to store custom data, without flash encryption.
The code needs to detect whether a particular data element has been written yet. Previously, we read the contents, and if the bytes were 0xFF, we assumed the data has been erased and not written yet (we never write 0xFF to that location).
However, with flash encryption enabled, if the contents of the partition are erased, reading the data (with esp_partition_read or memory mapped access) returns garbled data because the device "decrypts" the 0xFF values.
We could use "esp_flash_read" to read the raw bytes, but then (maybe?) it is possible that real data has been written to the flash, which happened to encrypt to the value 0xFF.
Is there some other way to detect whether a flash sector is in an erased / unwritten state when flash encryption is turned on?
The code needs to detect whether a particular data element has been written yet. Previously, we read the contents, and if the bytes were 0xFF, we assumed the data has been erased and not written yet (we never write 0xFF to that location).
However, with flash encryption enabled, if the contents of the partition are erased, reading the data (with esp_partition_read or memory mapped access) returns garbled data because the device "decrypts" the 0xFF values.
We could use "esp_flash_read" to read the raw bytes, but then (maybe?) it is possible that real data has been written to the flash, which happened to encrypt to the value 0xFF.
Is there some other way to detect whether a flash sector is in an erased / unwritten state when flash encryption is turned on?