1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-21 10:26:06 +03:00

add magic byte check for Update class

Note: only check of first 0xE9 possible.
This commit is contained in:
Markus Sattler 2015-12-20 11:46:00 +01:00
parent a04c225c59
commit 53e01932d3
2 changed files with 13 additions and 0 deletions

View File

@ -252,6 +252,16 @@ size_t UpdaterClass::writeStream(Stream &data) {
if(hasError() || !isRunning())
return 0;
// check for valid first magic byte (is always 0xE9)
if(data.peek() != 0xE9) {
_error = UPDATE_ERROR_MAGIC_BYTE;
_currentAddress = (_startAddress + _size);
#ifdef DEBUG_UPDATER
printError(DEBUG_UPDATER);
#endif
return 0;
}
while(remaining()) {
toRead = data.readBytes(_buffer + _bufferLen, (FLASH_SECTOR_SIZE - _bufferLen));
if(toRead == 0) { //Timeout
@ -293,6 +303,8 @@ void UpdaterClass::printError(Stream &out){
out.println("MD5 Check Failed");
} else if(_error == UPDATE_ERROR_FLASH_CONFIG){
out.printf("Flash config wrong real: %d IDE: %d\n", ESP.getFlashChipRealSize(), ESP.getFlashChipSize());
} else if(_error == UPDATE_ERROR_MAGIC_BYTE){
out.println("Magic byte is wrong, not 0xE9");
} else {
out.println("UNKNOWN");
}

View File

@ -13,6 +13,7 @@
#define UPDATE_ERROR_STREAM (5)
#define UPDATE_ERROR_MD5 (6)
#define UPDATE_ERROR_FLASH_CONFIG (7)
#define UPDATE_ERROR_MAGIC_BYTE (8)
#define U_FLASH 0