Skip to content

Commit 6cda806

Browse files
committed
alloc error
1 parent 3d71612 commit 6cda806

File tree

3 files changed

+34
-12
lines changed

3 files changed

+34
-12
lines changed

cores/esp8266/Updater.cpp

+11-10
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,7 @@ bool UpdaterClass::begin(size_t size, int command, int ledPin, uint8_t ledOn) {
176176
}
177177
_buffer = new (std::nothrow) uint8_t[_bufferSize];
178178
if (!_buffer) {
179-
#ifdef DEBUG_UPDATER
180-
DEBUG_UPDATER.println(F("[begin] Unable to allocate a temporary buffer."));
181-
#endif
179+
_setError(UPDATE_ERROR_OOM);
182180
_reset(false);
183181
return false;
184182
}
@@ -307,7 +305,7 @@ bool UpdaterClass::end(bool evenIfRemaining){
307305
const uint32_t sigAddr = _startAddress + binSize;
308306
sig.reset(new (std::nothrow) uint8_t[sigLen]);
309307
if (!sig) {
310-
_setError(UPDATE_ERROR_SIGN);
308+
_setError(UPDATE_ERROR_OOM);
311309
_reset();
312310
return false;
313311
}
@@ -622,17 +620,11 @@ String UpdaterClass::getErrorString() const {
622620
case UPDATE_ERROR_STREAM:
623621
out = F("Stream Read Timeout");
624622
break;
625-
case UPDATE_ERROR_NO_DATA:
626-
out = F("No data supplied");
627-
break;
628623
case UPDATE_ERROR_MD5:
629624
out += F("MD5 verification failed: ");
630625
out += F("expected: ") + _target_md5;
631626
out += F(", calculated: ") + _md5.toString();
632627
break;
633-
case UPDATE_ERROR_SIGN:
634-
out = F("Signature verification failed");
635-
break;
636628
case UPDATE_ERROR_FLASH_CONFIG:
637629
out += F("Flash config wrong: ");
638630
out += F("real: ") + String(ESP.getFlashChipRealSize(), 10);
@@ -648,6 +640,15 @@ String UpdaterClass::getErrorString() const {
648640
case UPDATE_ERROR_BOOTSTRAP:
649641
out = F("Invalid bootstrapping state, reset ESP8266 before updating");
650642
break;
643+
case UPDATE_ERROR_SIGN:
644+
out = F("Signature verification failed");
645+
break;
646+
case UPDATE_ERROR_NO_DATA:
647+
out = F("No data supplied");
648+
break;
649+
case UPDATE_ERROR_OOM:
650+
out = F("Out of memory");
651+
break;
651652
default:
652653
out = F("UNKNOWN");
653654
break;

cores/esp8266/Updater.h

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#define UPDATE_ERROR_BOOTSTRAP (11)
2121
#define UPDATE_ERROR_SIGN (12)
2222
#define UPDATE_ERROR_NO_DATA (13)
23+
#define UPDATE_ERROR_OOM (14)
2324

2425
#define U_FLASH 0
2526
#define U_FS 100

doc/ota_updates/readme.rst

+22-2
Original file line numberDiff line numberDiff line change
@@ -668,9 +668,29 @@ Updater class
668668

669669
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.
670670

671-
**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>`__.
671+
The following `Updater <https://github.com/esp8266/Arduino/tree/master/cores/esp8266/Updater.h` methods could be used to be notified about OTA progress:
672672

673-
**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>`__.
673+
.. code:: cpp
674+
675+
using THandlerFunction_Progress = std::function<void(size_t, size_t)>;
676+
void onProgress(THandlerFunction_Progress); // current and total number of bytes
677+
678+
using THandlerFunction_Error = std::function<void(uint8_t)>;
679+
void onStart(THandlerFunction_Error); // error code
680+
681+
using THandlerFunction = std::function<void()>;
682+
void onEnd(THandlerFunction);
683+
void onError(THandlerFunction);
684+
685+
Using RTC memory
686+
~~~~~~~~~~~~~~~~
687+
688+
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>`__.
689+
690+
Flash mode and size
691+
~~~~~~~~~~~~~~~~~~~
692+
693+
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>`__.
674694

675695
Update process - memory view
676696
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

0 commit comments

Comments
 (0)