File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -252,6 +252,16 @@ size_t UpdaterClass::writeStream(Stream &data) {
252252 if (hasError () || !isRunning ())
253253 return 0 ;
254254
255+ // check for valid first magic byte (is always 0xE9)
256+ if (data.peek () != 0xE9 ) {
257+ _error = UPDATE_ERROR_MAGIC_BYTE;
258+ _currentAddress = (_startAddress + _size);
259+ #ifdef DEBUG_UPDATER
260+ printError (DEBUG_UPDATER);
261+ #endif
262+ return 0 ;
263+ }
264+
255265 while (remaining ()) {
256266 toRead = data.readBytes (_buffer + _bufferLen, (FLASH_SECTOR_SIZE - _bufferLen));
257267 if (toRead == 0 ) { // Timeout
@@ -293,6 +303,8 @@ void UpdaterClass::printError(Stream &out){
293303 out.println (" MD5 Check Failed" );
294304 } else if (_error == UPDATE_ERROR_FLASH_CONFIG){
295305 out.printf (" Flash config wrong real: %d IDE: %d\n " , ESP.getFlashChipRealSize (), ESP.getFlashChipSize ());
306+ } else if (_error == UPDATE_ERROR_MAGIC_BYTE){
307+ out.println (" Magic byte is wrong, not 0xE9" );
296308 } else {
297309 out.println (" UNKNOWN" );
298310 }
Original file line number Diff line number Diff line change 1313#define UPDATE_ERROR_STREAM (5 )
1414#define UPDATE_ERROR_MD5 (6 )
1515#define UPDATE_ERROR_FLASH_CONFIG (7 )
16+ #define UPDATE_ERROR_MAGIC_BYTE (8 )
1617
1718
1819#define U_FLASH 0
You can’t perform that action at this time.
0 commit comments