diff --git a/tasmota/settings.ino b/tasmota/settings.ino index 21f3e0ab4..0e32bc7bd 100644 --- a/tasmota/settings.ino +++ b/tasmota/settings.ino @@ -343,10 +343,10 @@ void SetFlashModeDout(void) delete[] _buffer; } -uint32_t OtaVersion(void) +bool VersionCompatible(void) { if (Settings.flag3.compatibility_check) { - return 0xFFFFFFFF; + return true; } eboot_command ebcmd; @@ -362,15 +362,15 @@ uint32_t OtaVersion(void) if ((address == start_address) && (0x1F == (buffer[0] & 0xFF))) { version[1] = 0xFFFFFFFF; // Ota file is gzipped and can not be checked for compatibility found = true; - break; - } - for (uint32_t i = 0; i < (FLASH_SECTOR_SIZE / 4); i++) { - version[0] = version[1]; - version[1] = version[2]; - version[2] = buffer[i]; - if ((version[0] == MARKER_START) && (version[2] == MARKER_END)) { - found = true; - break; + } else { + for (uint32_t i = 0; i < (FLASH_SECTOR_SIZE / 4); i++) { + version[0] = version[1]; + version[1] = version[2]; + version[2] = buffer[i]; + if ((MARKER_START == version[0]) && (MARKER_END == version[2])) { + found = true; + break; + } } } if (found) { break; } @@ -381,13 +381,13 @@ uint32_t OtaVersion(void) AddLog_P2(LOG_LEVEL_DEBUG, PSTR("OTA: Version 0x%08X, Compatible 0x%08X"), version[1], VERSION_COMPATIBLE); - return version[1]; -} + if (version[1] < VERSION_COMPATIBLE) { + uint32_t eboot_magic = 0; // Abandon OTA result + ESP.rtcUserMemoryWrite(0, (uint32_t*)&eboot_magic, sizeof(eboot_magic)); + return false; + } -void AbandonOta(void) -{ - uint32_t eboot_magic = 0; - ESP.rtcUserMemoryWrite(0, (uint32_t*)&eboot_magic, sizeof(eboot_magic)); + return true; } void SettingsBufferFree(void) diff --git a/tasmota/support_tasmota.ino b/tasmota/support_tasmota.ino index b20e5ef26..4b0aa48bd 100644 --- a/tasmota/support_tasmota.ino +++ b/tasmota/support_tasmota.ino @@ -869,8 +869,7 @@ void Every250mSeconds(void) Response_P(PSTR("{\"" D_CMND_UPGRADE "\":\"")); if (ota_result) { // SetFlashModeDout(); // Force DOUT for both ESP8266 and ESP8285 - if (OtaVersion() < VERSION_COMPATIBLE) { - AbandonOta(); + if (!VersionCompatible()) { ResponseAppend_P(PSTR(D_JSON_FAILED " " D_UPLOAD_ERR_14)); } else { ResponseAppend_P(PSTR(D_JSON_SUCCESSFUL ". " D_JSON_RESTARTING)); diff --git a/tasmota/xdrv_01_webserver.ino b/tasmota/xdrv_01_webserver.ino index 682663905..b6a45340a 100644 --- a/tasmota/xdrv_01_webserver.ino +++ b/tasmota/xdrv_01_webserver.ino @@ -2398,8 +2398,7 @@ void HandleUploadLoop(void) Web.upload_error = 6; // Upload failed. Enable logging 3 return; } - if (OtaVersion() < VERSION_COMPATIBLE) { - AbandonOta(); + if (!VersionCompatible()) { Web.upload_error = 14; // Not compatible return; }