c18d50cb91
Background The current implementation of Update() uses the spi_flash_* api to write and read from flash. These functions ignore the partition->encrypted flag and always write raw data to flash even if the partition is marked as encrypted. Changes in this PR Update() now uses the esp_partition_* api. Wrapper functions for esp_partition_* added to ESP.cpp. This was done to maintain a consistent approach to the way the spi_flash_* functions were used. I note though that not all of the esp-idf functions are used are wrapped, for example esp_ota_get_next_update_partition() so it may be that these should not be added? The current implementation of Update() changes the first (magic) byte of firmware to 0xFF on write, and then when the firmware is completely written changes it back to ESP_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 as 0xFF. Then, in _enablePartition() the stashed bytes can be successfully written. Benefits Whilst it's not possible to use encrypted flash directly from either the Arduino IDE or PIO it's reasonably straightforward to compile and flash a bootloader with the necessary support from a simple esp-idf project and then use ArduinoOTA for subsequent updates. This PR enables the use of this workflow until such time as encrypted flash is supported, and is a first (small) step toward adding support. Regardless of the above, the esp_partition_* api is recommended over the api_flash_* api. Application code should mostly use these esp_partition_* API functions instead of lower level spi_flash_* API functions. Partition table API functions do bounds checking and calculate correct offsets in flash, based on data stored in a partition table. |
||
---|---|---|
.. | ||
apps/sntp | ||
libb64 | ||
Arduino.h | ||
base64.cpp | ||
base64.h | ||
binary.h | ||
cbuf.cpp | ||
cbuf.h | ||
Client.h | ||
esp32-hal-adc.c | ||
esp32-hal-adc.h | ||
esp32-hal-bt.c | ||
esp32-hal-bt.h | ||
esp32-hal-cpu.c | ||
esp32-hal-cpu.h | ||
esp32-hal-dac.c | ||
esp32-hal-dac.h | ||
esp32-hal-gpio.c | ||
esp32-hal-gpio.h | ||
esp32-hal-i2c.c | ||
esp32-hal-i2c.h | ||
esp32-hal-ledc.c | ||
esp32-hal-ledc.h | ||
esp32-hal-log.h | ||
esp32-hal-matrix.c | ||
esp32-hal-matrix.h | ||
esp32-hal-misc.c | ||
esp32-hal-psram.c | ||
esp32-hal-psram.h | ||
esp32-hal-rmt.c | ||
esp32-hal-rmt.h | ||
esp32-hal-sigmadelta.c | ||
esp32-hal-sigmadelta.h | ||
esp32-hal-spi.c | ||
esp32-hal-spi.h | ||
esp32-hal-time.c | ||
esp32-hal-timer.c | ||
esp32-hal-timer.h | ||
esp32-hal-touch.c | ||
esp32-hal-touch.h | ||
esp32-hal-uart.c | ||
esp32-hal-uart.h | ||
esp32-hal.h | ||
esp8266-compat.h | ||
Esp.cpp | ||
Esp.h | ||
FunctionalInterrupt.cpp | ||
FunctionalInterrupt.h | ||
HardwareSerial.cpp | ||
HardwareSerial.h | ||
IPAddress.cpp | ||
IPAddress.h | ||
IPv6Address.cpp | ||
IPv6Address.h | ||
main.cpp | ||
MD5Builder.cpp | ||
MD5Builder.h | ||
pgmspace.h | ||
Print.cpp | ||
Print.h | ||
Printable.h | ||
Server.h | ||
stdlib_noniso.c | ||
stdlib_noniso.h | ||
Stream.cpp | ||
Stream.h | ||
StreamString.cpp | ||
StreamString.h | ||
Udp.h | ||
WCharacter.h | ||
wiring_private.h | ||
wiring_pulse.c | ||
wiring_shift.c | ||
WMath.cpp | ||
WString.cpp | ||
WString.h |