-
Notifications
You must be signed in to change notification settings - Fork 7.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
esp_flash_write_encrypted is broken (IDFGH-4493) #6322
Comments
Thanks for reporting, we will look into. |
@rojer if you switch from QIO to DIO mode, does this issue still happen? |
@igrr set from memory when i was debugging this - after new flash driver initializes, reading status register via rom function starts returning incorrect result. so yes, there is some configuration mismatch but it's not QIO / DIO, it seems. |
Thanks for checking @rojer. We do have an automated test for flash encryption functionality (based on the examples/security/flash_encryption example), and that seems to be passing both on master and on release/v4.2 branch. So we need to find what is different between your setup and ours. Will look into it more. If you get a chance, could you please try running examples/security/flash_encryption example with its default configuration on your hardware? |
@igrr investigated further and found the root cause: frequency mismatch between rom settings and the driver. |
alternatively (and preferably), esp_flash driver should sync ROM's settings to the one it uses. |
Because modern API falls back to ROM API for encrypted writes, the flash frequency used by ROM APIs must match the frequency (but curiously not necessarily I/o mode) set by the modern API. mos tool has been setting frerquenct to 80 MHz since forever (actually since mongoose-os/mos@74448ba) so we set compile-time default to 80 MHz as well. This issue has been reported upstream in espressif/esp-idf#6322
ok, for now the workaround is pretty simple - set default to 80 mhz, to match what mos tool sets by default (cesanta/mongoose-os@23e8064) but proper fix wshould be made to ensure speed settings agree between ROM and modern APIs or that modern API does not require ROM API for encrypted writes anymore. |
another twist on this issue is the SPIRAM clock - if it doesn't match the flash settings, ROM access to flash is also broken. |
SPIRAM frequency, if enabled, must also match the flash frequency. espressif/esp-idf#6322
Sorry for the long wait, I have fixed the issue(flash_encryption failed with 80M flash and 40M psram) with the patch below, could you please have a try? Thanks! |
@mythbuster5 yes, that works, thank you! |
…_encryption_write, Related espressif#6322, Related espressif#6254" This reverts commit c1b41ec.
…_encryption_write, Related espressif#6322, Related espressif#6254" This reverts commit c1b41ec.
Thanks for reporting and sharing updates, feel free to reopen. |
Environment
Problem Description
esp_partition_write() does not work on encrypted partitions.
Expected Behavior
esp_partition_write() should be able to write data to encrypted partitions
Actual Behavior
new API falls back to ROM API (spi_flash_write_encrypted) that doesn't work.
gets stuck unable to set WEL bit properly (more likely, unable to read status register properly).
Steps to reproduce
ESP32D0WDQ6 with GigaDevice flash in 80 MHz QIO mode
Code to reproduce this issue
enable flash encryption and try to write to an encrypted partition.
works fine if new API is disabled (CONFIG_SPI_FLASH_USE_LEGACY_IMPL=y)
The text was updated successfully, but these errors were encountered: