-
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_ota_write unexpectedly slow on encrypted flash (IDFGH-11415) #12553
Comments
This is the sdkconfig of the encrypted module: |
I checked the tasks on the system during OTA update. There are some strange phenomena:
(cpu usage %, @coreIDm b:baseprio, c:currentprio, s:stack high watermark)
When I pin http to core 0 or 1, I strangely get somewhat better flash write performance. Pinned to core0, it looks like this:
pinned to core 1:
What are ipc tasks doing during OTA update? Where shall OTA update run? (now it runs from httpd server context). |
I made a small app_main-only test: (run on the board with flash encryption enabled)
Results (write times of a 8kbyte block): Interestingly legacy implementation (SPI_FLASH_USE_LEGACY_IMPL) improves flash write speed but the difference is there: This difference is also an issue but the main problem is that why does encrypted flash speed decay so much when serial write via esptool.py does not show such degradation? |
I made some measurements to find where the time is spent during flash writes. I did this by accumulating the ccounts needed by various parts of the code.
From the ~100ms that is needed for writing 8192 bytes to encrypted flash, 47ms is spent in rom_spiflash_api_funcs->start(chip) in esp_flash_api.c, functionesp_flash_write_encrypted(). This number is 0ms for the non-encrypted write. The same is true with spi_flash_guard_start() in the legacy code. The reason for the increased time needed for flash writes when flash encryption is enabled: When encryption is enabled, CONFIG_SPI_FLASH_WRITE_CHUNK_SIZE does not come into play: the writes are always done in small chunks of max 64 bytes. These single writes are ALL protected by the guards that takes most of the time. Imho this is a bug, spi guards shall only be called in larger chunks, the same way as it is done in the non-encrypted case. |
In the legacy implementation, this modified spi_flash_write_encrypted_chip() (in flash_ops_esp32.c) speeds up encrypted writes from 100ms to 20ms:
The same can be applied to the non-legacy solution as well. However, even with the mods similar to the one above, the non-legacy is still slower than the legacy one. (~20ms compared to ~38ms). Please elaborate. |
Answers checklist.
IDF version.
v4.4.6-150-g2bab3b36bc
Espressif SoC revision.
Chip is ESP32-D0WD-V3 (revision v3.1)
Operating System used.
Linux
How did you build your project?
Command line with Make
If you are using Windows, please specify command line type.
None
Development Kit.
Custom board using ESP32-WROOM-32E
Power Supply used.
External 3.3V
What is the expected behavior?
We have a working product that uses OTA via http server running on ESP32. Client is PUTting firmware image to the server that writes the image to flash via esp_ota_write(). This works just fine.
However now we decided to turn on flash encryption and secure boot (V2). No issues there either, but: when flash encryption is enabled, esp_ota_write() is plainfully slow: it performs a write of a 8kbyte block in 400ms. Interestingly, the flash write times during serial update does not change much. Here are the numbers:
plaintext
encrypted:
Note: the measurement is done using the same binary running on two identical modules of the same batch, one of them plaintext, the other encrypted.
What is the actual behavior?
esp_ota_write() speed should be much higher.
Steps to reproduce.
See the comment below where I included a simple test.
Debug Logs.
More Information.
No response
The text was updated successfully, but these errors were encountered: