diff --git a/wled00/wled.cpp b/wled00/wled.cpp index b40289be21..2f3755b359 100644 --- a/wled00/wled.cpp +++ b/wled00/wled.cpp @@ -12,6 +12,10 @@ #include "soc/rtc_cntl_reg.h" #endif +#ifdef ARDUINO_ARCH_ESP32 +#include +#endif + extern "C" void usePWMFixedNMI(); /* @@ -361,6 +365,26 @@ void WLED::setup() DEBUG_PRINTF_P(PSTR("---WLED %s %u INIT---\n"), versionString, VERSION); DEBUG_PRINTLN(); #ifdef ARDUINO_ARCH_ESP32 + // Mark OTA app as valid IMMEDIATELY to prevent automatic rollback by ESP-IDF bootloader + // This MUST happen as early as possible, before any potential crashes + // Critical for OTA updates from 0.15 to 0.16+ on ESP32-C3 and other ESP32 variants + const esp_partition_t* running = esp_ota_get_running_partition(); + esp_ota_img_states_t ota_state; + if (esp_ota_get_state_partition(running, &ota_state) == ESP_OK) { + if (ota_state == ESP_OTA_IMG_PENDING_VERIFY) { + DEBUG_PRINTLN(F("*** OTA UPDATE DETECTED - Marking app as valid to prevent rollback ***")); + if (esp_ota_mark_app_valid_cancel_rollback() == ESP_OK) { + DEBUG_PRINTLN(F("OTA app marked valid successfully")); + } else { + DEBUG_PRINTLN(F("WARNING: Failed to mark OTA app as valid!")); + } + } + } + + // Check IDF version for compatibility warnings + const char* idf_ver = esp_get_idf_version(); + DEBUG_PRINTF_P(PSTR("ESP-IDF version: %s\n"), idf_ver); + DEBUG_PRINTF_P(PSTR("esp32 %s\n"), ESP.getSdkVersion()); #if defined(ESP_ARDUINO_VERSION) DEBUG_PRINTF_P(PSTR("arduino-esp32 v%d.%d.%d\n"), int(ESP_ARDUINO_VERSION_MAJOR), int(ESP_ARDUINO_VERSION_MINOR), int(ESP_ARDUINO_VERSION_PATCH)); // available since v2.0.0