I am currently researching OTA updates for ESP8266 firmware, and I have a question that I couldn't find an answer to:
Question: Is the number of OTA updates limited? According to the documentation, it states: "The flash chip size should be large enough to hold the old sketch (currently running) and the new sketch (OTA) at the same time." Does this mean that the old sketch always remains, and with each new update, the previous versions continue to exist? If so, does this imply that after multiple updates, the flash memory will eventually be full, preventing any further updates?
Thank you for your assistance.
2 Answers 2
No each update overrites the oldest one (if present) so there are only ever a maximum of 2 versions in flash
This statement takes mainly two reasons into account:
- The OTA update needs a complete sketch that executes the update. Overwriting a running sketch with an update crashes in almost all cases.
- An OTA update can be disrupted or fail, as a wireless connection is notoriously unreliable. The device needs a working sketch after such events.
That's why the device stores the new sketch in a space separated from the old sketch.
But as soon as the "download" is complete and hopefully checked (by a hash or other means of checksum) to be error-free and valid, the old sketch is not needed any more. The system "switches" from the old sketch to the new sketch, in your case the bootloader overwrites the old sketch with the new sketch, see the last part of the documentation you link to.
The space after the now running new sketch is again free for the next OTA update.
However, there is a physical limit caused by flash memory wear. Commonly this is far away from the number of OTA updates a device will have in its lifetime.