Skip to content

Commit 1248d38

Browse files
authored
Updater - missing error codes (#9104)
Adds the two missing error states when beginning an Update. There were debugging logs for this but the error state was not set which would lead to confusion
1 parent 760dbee commit 1248d38

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

cores/esp8266/Updater.cpp

+14-6
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ bool UpdaterClass::begin(size_t size, int command, int ledPin, uint8_t ledOn) {
7070
#ifdef DEBUG_UPDATER
7171
DEBUG_UPDATER.println(F("[begin] already running"));
7272
#endif
73+
_setError(UPDATE_ERROR_RUNNING_ALREADY);
7374
return false;
7475
}
7576

@@ -86,7 +87,7 @@ bool UpdaterClass::begin(size_t size, int command, int ledPin, uint8_t ledOn) {
8687
_setError(UPDATE_ERROR_BOOTSTRAP);
8788
return false;
8889
}
89-
90+
9091
#ifdef DEBUG_UPDATER
9192
if (command == U_FS) {
9293
DEBUG_UPDATER.println(F("[begin] Update Filesystem."));
@@ -133,7 +134,7 @@ bool UpdaterClass::begin(size_t size, int command, int ledPin, uint8_t ledOn) {
133134

134135
//make sure that the size of both sketches is less than the total space (updateEndAddress)
135136
if(updateStartAddress < currentSketchSize) {
136-
_setError(UPDATE_ERROR_SPACE);
137+
_setError(UPDATE_ERROR_SPACE);
137138
return false;
138139
}
139140
}
@@ -162,6 +163,7 @@ bool UpdaterClass::begin(size_t size, int command, int ledPin, uint8_t ledOn) {
162163
#ifdef DEBUG_UPDATER
163164
DEBUG_UPDATER.println(F("[begin] Unknown update command."));
164165
#endif
166+
_setError(UPDATE_ERROR_UNKNOWN_COMMAND);
165167
return false;
166168
}
167169

@@ -404,7 +406,7 @@ bool UpdaterClass::_writeBuffer(){
404406
modifyFlashMode = true;
405407
}
406408
}
407-
409+
408410
if (eraseResult) {
409411
if(!_async) yield();
410412
writeResult = ESP.flashWrite(_currentAddress, _buffer, _bufferLen);
@@ -488,7 +490,7 @@ bool UpdaterClass::_verifyEnd() {
488490
uint8_t buf[4] __attribute__((aligned(4)));
489491
if(!ESP.flashRead(_startAddress, (uint32_t *) &buf[0], 4)) {
490492
_currentAddress = (_startAddress);
491-
_setError(UPDATE_ERROR_READ);
493+
_setError(UPDATE_ERROR_READ);
492494
return false;
493495
}
494496

@@ -500,7 +502,7 @@ bool UpdaterClass::_verifyEnd() {
500502
return true;
501503
} else if (buf[0] != 0xE9) {
502504
_currentAddress = (_startAddress);
503-
_setError(UPDATE_ERROR_MAGIC_BYTE);
505+
_setError(UPDATE_ERROR_MAGIC_BYTE);
504506
return false;
505507
}
506508

@@ -512,7 +514,7 @@ bool UpdaterClass::_verifyEnd() {
512514
// check if new bin fits to SPI flash
513515
if(bin_flash_size > ESP.getFlashChipRealSize()) {
514516
_currentAddress = (_startAddress);
515-
_setError(UPDATE_ERROR_NEW_FLASH_CONFIG);
517+
_setError(UPDATE_ERROR_NEW_FLASH_CONFIG);
516518
return false;
517519
}
518520
#endif
@@ -649,6 +651,12 @@ String UpdaterClass::getErrorString() const {
649651
case UPDATE_ERROR_OOM:
650652
out = F("Out of memory");
651653
break;
654+
case UPDATE_ERROR_RUNNING_ALREADY:
655+
out = F("Update already running");
656+
break;
657+
case UPDATE_ERROR_UNKNOWN_COMMAND:
658+
out = F("Unknown update command");
659+
break;
652660
default:
653661
out = F("UNKNOWN");
654662
break;

cores/esp8266/Updater.h

+5-3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#define UPDATE_ERROR_SIGN (12)
2222
#define UPDATE_ERROR_NO_DATA (13)
2323
#define UPDATE_ERROR_OOM (14)
24+
#define UPDATE_ERROR_RUNNING_ALREADY (15)
25+
#define UPDATE_ERROR_UNKNOWN_COMMAND (16)
2426

2527
#define U_FLASH 0
2628
#define U_FS 100
@@ -55,7 +57,7 @@ class UpdaterClass {
5557
using THandlerFunction_Progress = std::function<void(size_t, size_t)>;
5658
using THandlerFunction_Error = std::function<void(uint8_t)>;
5759
using THandlerFunction = std::function<void()>;
58-
60+
5961
UpdaterClass();
6062
~UpdaterClass();
6163

@@ -69,7 +71,7 @@ class UpdaterClass {
6971
bool begin(size_t size, int command = U_FLASH, int ledPin = -1, uint8_t ledOn = LOW);
7072

7173
/*
72-
Run Updater from asynchronous callbacs
74+
Run Updater from asynchronous callbacks
7375
*/
7476
void runAsync(bool async){ _async = async; }
7577

@@ -216,7 +218,7 @@ class UpdaterClass {
216218
bool _verifyHeader(uint8_t data);
217219
bool _verifyEnd();
218220

219-
void _setError(int error);
221+
void _setError(int error);
220222

221223
bool _async = false;
222224
uint8_t _error = 0;

0 commit comments

Comments
 (0)