During development, it is advantageous to be able to have non-encrypted apps, but have encrypted data. However if a partition is marked encrypted, yet flash encryption is disabled, we simply write encrypted garbage and read back garbage.
Here's the scenario:
When using esp_partition_write, it simply checks if partition->encrypted is true, and if so encrypts the write using spi_flash_write_encrypted() which is blindly calling spi_flash_write_encrypted() even when esp_flash_encryption_enabled == false
Later in esp_partition_read, it again detects partition->encrypted is true, uses esp_partition_mmap() and reads back garbage. (I'm guessing because spi_flash_mmap doesn't see a flash key and doesn't de-encrypt using a 0x0000000 key)
I "fixed" this by checking if esp_flash_encryption_enabled() before recognizing partition->encrypted. Example:
Code: Select all
esp_err_t esp_partition_read(const esp_partition_t* partition,
size_t src_offset, void* dst, size_t size)
{
...
if (!partition->encrypted || !esp_flash_encryption_enabled()) {
return spi_flash_read(partition->address + src_offset, dst, size);
}
Code: Select all
esp_err_t esp_partition_write(const esp_partition_t* partition,
size_t dst_offset, const void* src, size_t size)
{
...
if (partition->encrypted && esp_flash_encryption_enabled()) {
return spi_flash_write_encrypted(dst_offset, src, size);
} else {
return spi_flash_write(dst_offset, src, size);
}
}
I'm not saying this modification is good. But I'm saying that it's inconvenient to need to insert this condition into esp-idf just to streamline development.
Anyways, would be great to develop plain-text app, but have encrypted data just to get all that data alignment/testing out of the way. Having to do OTA during development is slow and inconvenient.
Good idea? Bad idea? Am I having a hard time just because I set something up wrong?