Updater.cpp support for encrypted flash #3898
Merged
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
Background
The current implementation of
Update()uses thespi_flash_*api to write and read from flash. These functions ignore thepartition->encryptedflag and always write raw data to flash even if the partition is marked as encrypted.Changes in this PR
Update()now uses theesp_partition_*api.esp_partition_*added toESP.cpp. This was done to maintain a consistent approach to the way thespi_flash_*functions were used. I note though that not all of the esp-idf functions are used are wrapped, for exampleesp_ota_get_next_update_partition()so it may be that these should not be added?0xFFon write, and then when the firmware is completely written changes it back toESP_IMAGE_HEADER_MAGIC. This works without erasing the sector because flash bits can be changed from 1->0 (but not 0->1). If the flash is encrypted then the actual data written to flash will not be all ones, so this approach will not work. In addition, encrypted flash must be written in 16 byte blocks. So, instead of changing the first byte the changed code stashes the first 16 bytes, and starts writing at the 17th byte, leaving the first 16 bytes as0xFF. Then, in_enablePartition()the stashed bytes can be successfully written.Benefits
esp_partition_*api is recommended over theapi_flash_*api.Questions