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:
parent
a04c225c59
commit
53e01932d3
@ -252,6 +252,16 @@ size_t UpdaterClass::writeStream(Stream &data) {
|
|||||||
if(hasError() || !isRunning())
|
if(hasError() || !isRunning())
|
||||||
return 0;
|
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()) {
|
while(remaining()) {
|
||||||
toRead = data.readBytes(_buffer + _bufferLen, (FLASH_SECTOR_SIZE - _bufferLen));
|
toRead = data.readBytes(_buffer + _bufferLen, (FLASH_SECTOR_SIZE - _bufferLen));
|
||||||
if(toRead == 0) { //Timeout
|
if(toRead == 0) { //Timeout
|
||||||
@ -293,6 +303,8 @@ void UpdaterClass::printError(Stream &out){
|
|||||||
out.println("MD5 Check Failed");
|
out.println("MD5 Check Failed");
|
||||||
} else if(_error == UPDATE_ERROR_FLASH_CONFIG){
|
} else if(_error == UPDATE_ERROR_FLASH_CONFIG){
|
||||||
out.printf("Flash config wrong real: %d IDE: %d\n", ESP.getFlashChipRealSize(), ESP.getFlashChipSize());
|
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 {
|
} else {
|
||||||
out.println("UNKNOWN");
|
out.println("UNKNOWN");
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
#define UPDATE_ERROR_STREAM (5)
|
#define UPDATE_ERROR_STREAM (5)
|
||||||
#define UPDATE_ERROR_MD5 (6)
|
#define UPDATE_ERROR_MD5 (6)
|
||||||
#define UPDATE_ERROR_FLASH_CONFIG (7)
|
#define UPDATE_ERROR_FLASH_CONFIG (7)
|
||||||
|
#define UPDATE_ERROR_MAGIC_BYTE (8)
|
||||||
|
|
||||||
|
|
||||||
#define U_FLASH 0
|
#define U_FLASH 0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user