Skip to content
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

Updater lifetime callbacks #8653

Merged
merged 7 commits into from
Nov 3, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
alloc error
  • Loading branch information
mcspr committed Nov 1, 2022
commit 6cda80688b8921bbfd45d864d75f8236310d7a8f
21 changes: 11 additions & 10 deletions cores/esp8266/Updater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,7 @@ bool UpdaterClass::begin(size_t size, int command, int ledPin, uint8_t ledOn) {
}
_buffer = new (std::nothrow) uint8_t[_bufferSize];
if (!_buffer) {
#ifdef DEBUG_UPDATER
DEBUG_UPDATER.println(F("[begin] Unable to allocate a temporary buffer."));
#endif
_setError(UPDATE_ERROR_OOM);
_reset(false);
return false;
}
Expand Down Expand Up @@ -307,7 +305,7 @@ bool UpdaterClass::end(bool evenIfRemaining){
const uint32_t sigAddr = _startAddress + binSize;
sig.reset(new (std::nothrow) uint8_t[sigLen]);
if (!sig) {
_setError(UPDATE_ERROR_SIGN);
_setError(UPDATE_ERROR_OOM);
_reset();
return false;
}
Expand Down Expand Up @@ -622,17 +620,11 @@ String UpdaterClass::getErrorString() const {
case UPDATE_ERROR_STREAM:
out = F("Stream Read Timeout");
break;
case UPDATE_ERROR_NO_DATA:
out = F("No data supplied");
break;
case UPDATE_ERROR_MD5:
out += F("MD5 verification failed: ");
out += F("expected: ") + _target_md5;
out += F(", calculated: ") + _md5.toString();
break;
case UPDATE_ERROR_SIGN:
out = F("Signature verification failed");
break;
case UPDATE_ERROR_FLASH_CONFIG:
out += F("Flash config wrong: ");
out += F("real: ") + String(ESP.getFlashChipRealSize(), 10);
Expand All @@ -648,6 +640,15 @@ String UpdaterClass::getErrorString() const {
case UPDATE_ERROR_BOOTSTRAP:
out = F("Invalid bootstrapping state, reset ESP8266 before updating");
break;
case UPDATE_ERROR_SIGN:
out = F("Signature verification failed");
break;
case UPDATE_ERROR_NO_DATA:
out = F("No data supplied");
break;
case UPDATE_ERROR_OOM:
out = F("Out of memory");
break;
default:
out = F("UNKNOWN");
break;
Expand Down
1 change: 1 addition & 0 deletions cores/esp8266/Updater.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#define UPDATE_ERROR_BOOTSTRAP (11)
#define UPDATE_ERROR_SIGN (12)
#define UPDATE_ERROR_NO_DATA (13)
#define UPDATE_ERROR_OOM (14)

#define U_FLASH 0
#define U_FS 100
Expand Down
24 changes: 22 additions & 2 deletions doc/ota_updates/readme.rst
Original file line number Diff line number Diff line change
Expand Up @@ -668,9 +668,29 @@ Updater class

Updater is in the Core and deals with writing the firmware to the flash, checking its integrity and telling the bootloader (eboot) to load the new firmware on the next boot.

**Note:** The bootloader command will be stored into the first 128 bytes of user RTC memory, then it will be retrieved by eboot on boot. That means that user data present there will be lost `(per discussion in #5330) <https://github.com/esp8266/Arduino/pull/5330#issuecomment-437803456>`__.
The following `Updater <https://github.com/esp8266/Arduino/tree/master/cores/esp8266/Updater.h` methods could be used to be notified about OTA progress:

**Note:** For uncompressed firmware images, the Updater will change the flash mode bits if they differ from the flash mode the device is currently running at. This ensures that the flash mode is not changed to an incompatible mode when the device is in a remote or hard to access area. Compressed images are not modified, thus changing the flash mode in this instance could result in damage to the ESP8266 and/or flash memory chip or your device no longer be accessible via OTA, and requiring re-flashing via a serial connection `(per discussion in #7307) <https://github.com/esp8266/Arduino/issues/7307#issuecomment-631523053>`__.
.. code:: cpp

using THandlerFunction_Progress = std::function<void(size_t, size_t)>;
void onProgress(THandlerFunction_Progress); // current and total number of bytes

using THandlerFunction_Error = std::function<void(uint8_t)>;
void onStart(THandlerFunction_Error); // error code

using THandlerFunction = std::function<void()>;
void onEnd(THandlerFunction);
void onError(THandlerFunction);

Using RTC memory
~~~~~~~~~~~~~~~~

The bootloader command will be stored into the first 128 bytes of user RTC memory, then it will be retrieved by eboot on boot. That means that user data present there will be lost `(per discussion in #5330) <https://github.com/esp8266/Arduino/pull/5330#issuecomment-437803456>`__.

Flash mode and size
~~~~~~~~~~~~~~~~~~~

For uncompressed firmware images, the Updater will change the flash mode bits if they differ from the flash mode the device is currently running at. This ensures that the flash mode is not changed to an incompatible mode when the device is in a remote or hard to access area. Compressed images are not modified, thus changing the flash mode in this instance could result in damage to the ESP8266 and/or flash memory chip or your device no longer be accessible via OTA, and requiring re-flashing via a serial connection `(per discussion in #7307) <https://github.com/esp8266/Arduino/issues/7307#issuecomment-631523053>`__.

Update process - memory view
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down