Skip to content

Commit b2a6ab8

Browse files
committed
1 parent bac5ce0 commit b2a6ab8

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.cpp

+23-21
Original file line numberDiff line numberDiff line change
@@ -241,31 +241,33 @@ t_httpUpdate_return ESP8266HTTPUpdate::handleUpdate(HTTPClient * http, const cha
241241
DEBUG_HTTP_UPDATE("[httpUpdate] runUpdate flash...\n");
242242
}
243243

244-
uint8_t buf[4];
245-
if(tcp->peekBytes(&buf[0], 4) != 4) {
246-
DEBUG_HTTP_UPDATE("[httpUpdate] peekBytes magic header failed\n");
247-
lastError = HTTP_UE_BIN_VERIFY_HEADER_FAILED;
248-
http->end();
249-
return HTTP_UPDATE_FAILED;
250-
}
244+
if(!spiffs) {
245+
uint8_t buf[4];
246+
if(tcp->peekBytes(&buf[0], 4) != 4) {
247+
DEBUG_HTTP_UPDATE("[httpUpdate] peekBytes magic header failed\n");
248+
lastError = HTTP_UE_BIN_VERIFY_HEADER_FAILED;
249+
http->end();
250+
return HTTP_UPDATE_FAILED;
251+
}
251252

252-
// check for valid first magic byte
253-
if(buf[0] != 0xE9) {
254-
DEBUG_HTTP_UPDATE("[httpUpdate] magic header not starts with 0xE9\n");
255-
lastError = HTTP_UE_BIN_VERIFY_HEADER_FAILED;
256-
http->end();
257-
return HTTP_UPDATE_FAILED;
253+
// check for valid first magic byte
254+
if(buf[0] != 0xE9) {
255+
DEBUG_HTTP_UPDATE("[httpUpdate] magic header not starts with 0xE9\n");
256+
lastError = HTTP_UE_BIN_VERIFY_HEADER_FAILED;
257+
http->end();
258+
return HTTP_UPDATE_FAILED;
258259

259-
}
260+
}
260261

261-
uint32_t bin_flash_size = ESP.magicFlashChipSize((buf[3] & 0xf0) >> 4);
262+
uint32_t bin_flash_size = ESP.magicFlashChipSize((buf[3] & 0xf0) >> 4);
262263

263-
// check if new bin fits to SPI flash
264-
if(bin_flash_size > ESP.getFlashChipRealSize()) {
265-
DEBUG_HTTP_UPDATE("[httpUpdate] magic header, new bin not fits SPI Flash\n");
266-
lastError = HTTP_UE_BIN_FOR_WRONG_FLASH;
267-
http->end();
268-
return HTTP_UPDATE_FAILED;
264+
// check if new bin fits to SPI flash
265+
if(bin_flash_size > ESP.getFlashChipRealSize()) {
266+
DEBUG_HTTP_UPDATE("[httpUpdate] magic header, new bin not fits SPI Flash\n");
267+
lastError = HTTP_UE_BIN_FOR_WRONG_FLASH;
268+
http->end();
269+
return HTTP_UPDATE_FAILED;
270+
}
269271
}
270272

271273
if(runUpdate(*tcp, len, http->header("x-MD5"), command)) {

0 commit comments

Comments
 (0)