diff --git a/tasmota/support_esp.ino b/tasmota/support_esp.ino index 2d8905e54..d551914ea 100644 --- a/tasmota/support_esp.ino +++ b/tasmota/support_esp.ino @@ -295,9 +295,16 @@ extern "C" { #include "rom/spi_flash.h" #endif +bool EspSingleOtaPartition(void) { + return (1 == esp_ota_get_app_partition_count()); +} + +void EspRestartToSaveMode(void) { + esp_ota_mark_app_invalid_rollback_and_reboot(); +} + uint32_t EspFlashBaseAddress(void) { - uint32_t part_count = esp_ota_get_app_partition_count(); - if (1 == part_count) { // Only one partition so start at end of sketch + if (EspSingleOtaPartition()) { // Only one partition so start at end of sketch const esp_partition_t *running = esp_ota_get_running_partition(); if (!running) { return 0; } return running->address + ESP_getSketchSize(); @@ -309,8 +316,7 @@ uint32_t EspFlashBaseAddress(void) { } uint32_t EspFlashBaseEndAddress(void) { - uint32_t part_count = esp_ota_get_app_partition_count(); - const esp_partition_t* partition = (1 == part_count) ? esp_ota_get_running_partition() : esp_ota_get_next_update_partition(nullptr); + const esp_partition_t* partition = (EspSingleOtaPartition()) ? esp_ota_get_running_partition() : esp_ota_get_next_update_partition(nullptr); if (!partition) { return 0; } return partition->address + partition->size; // For tasmota 0x00200000 or 0x003F0000 } diff --git a/tasmota/support_tasmota.ino b/tasmota/support_tasmota.ino index a0295d501..36701e598 100644 --- a/tasmota/support_tasmota.ino +++ b/tasmota/support_tasmota.ino @@ -1242,6 +1242,20 @@ void Every250mSeconds(void) } } #endif // ESP8266 + +#ifdef ESP32 +#ifndef FIRMWARE_MINIMAL + if (EspSingleOtaPartition()) { + RtcSettings.ota_loader = 1; // Try safemode image next + SettingsSaveAll(); + AddLog(LOG_LEVEL_INFO, PSTR(D_LOG_APPLICATION D_RESTARTING)); + ResetPwm(); + WifiShutdown(true); + EspRestartToSaveMode(); + } +#endif // FIRMWARE_MINIMAL +#endif // ESP32 + char version[50]; snprintf_P(version, sizeof(version), PSTR("%s%s"), TasmotaGlobal.version, TasmotaGlobal.image_name); AddLog(LOG_LEVEL_DEBUG, PSTR(D_LOG_UPLOAD "%s %s"), full_ota_url, version); diff --git a/tasmota/support_wifi.ino b/tasmota/support_wifi.ino index 04d44e78b..0d3fd0717 100644 --- a/tasmota/support_wifi.ino +++ b/tasmota/support_wifi.ino @@ -617,8 +617,7 @@ void WifiConnect(void) #endif // WIFI_RF_PRE_INIT } -void WifiShutdown(bool option = false) -{ +void WifiShutdown(bool option) { // option = false - Legacy disconnect also used by DeepSleep // option = true - Disconnect with SDK wifi calibrate sector erase when WIFI_FORCE_RF_CAL_ERASE enabled delay(100); // Allow time for message xfer - disabled v6.1.0b diff --git a/tasmota/tasmota_globals.h b/tasmota/tasmota_globals.h index e30bfe22f..ddeab70a3 100644 --- a/tasmota/tasmota_globals.h +++ b/tasmota/tasmota_globals.h @@ -38,6 +38,7 @@ extern "C" { void KNX_CB_Action(message_t const &msg, void *arg); #endif // USE_KNX +void WifiShutdown(bool option = false); void DomoticzTempHumPressureSensor(float temp, float hum, float baro = -1); char* ToHex_P(const unsigned char * in, size_t insz, char * out, size_t outsz, char inbetween = '\0'); extern "C" void custom_crash_callback(struct rst_info * rst_info, uint32_t stack, uint32_t stack_end);