From e02c181a2d7bd09f2a00b45f62abfb4201fc87be Mon Sep 17 00:00:00 2001 From: Damian Schneider Date: Tue, 11 Nov 2025 12:40:22 +0100 Subject: [PATCH 1/4] change C3 to DIO, add explicit QIO env for C3, add markOTAvalid() to support OTA from 0.15 --- platformio.ini | 11 +++++++++++ wled00/ota_update.cpp | 13 +++++++++++++ wled00/ota_update.h | 6 ++++++ wled00/wled.cpp | 1 + 4 files changed, 31 insertions(+) diff --git a/platformio.ini b/platformio.ini index 348c34e855..0acd08bf1f 100644 --- a/platformio.ini +++ b/platformio.ini @@ -25,6 +25,7 @@ default_envs = nodemcuv2 esp32_wrover lolin_s2_mini esp32c3dev + esp32c3dev_qio esp32s3dev_16MB_opi esp32s3dev_8MB_opi esp32s3_4M_qspi @@ -543,6 +544,16 @@ build_flags = ${common.build_flags} ${esp32c3.build_flags} -D WLED_RELEASE_NAME= upload_speed = 460800 build_unflags = ${common.build_unflags} lib_deps = ${esp32c3.lib_deps} +board_build.flash_mode = dio ; safe default, required for OTA updates to 0.16 from older version which used dio (must match the bootloader!) + +[env:esp32c3dev_qio] +extends = esp32c3dev +build_flags = ${common.build_flags} ${esp32c3.build_flags} -D WLED_RELEASE_NAME=\"ESP32-C3-QIO\" + -D WLED_WATCHDOG_TIMEOUT=0 + -DLOLIN_WIFI_FIX ; lower TX power, seems to work much better with this + -DARDUINO_USB_CDC_ON_BOOT=1 ;; for virtual CDC USB + ;-DARDUINO_USB_CDC_ON_BOOT=0 ;; for serial-to-USB chip +board_build.flash_mode = qio ; qio is faster and works on almost all boards (some may use dio to get 2 extra pins) [env:esp32s3dev_16MB_opi] ;; ESP32-S3 development board, with 16MB FLASH and >= 8MB PSRAM (memory_type: qio_opi) diff --git a/wled00/ota_update.cpp b/wled00/ota_update.cpp index 6a5cf29cd3..4a93312d3a 100644 --- a/wled00/ota_update.cpp +++ b/wled00/ota_update.cpp @@ -259,6 +259,19 @@ void handleOTAData(AsyncWebServerRequest *request, size_t index, uint8_t *data, } } +void markOTAvalid() { + #ifndef ESP8266 + 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) { + esp_ota_mark_app_valid_cancel_rollback(); // only needs to be called once, it marks the ota_state as ESP_OTA_IMG_VALID + DEBUG_PRINTLN(F("Current firmware validated")); + } + } + #endif +} + #if defined(ARDUINO_ARCH_ESP32) && !defined(WLED_DISABLE_OTA) // Cache for bootloader SHA256 digest as hex string static String bootloaderSHA256HexCache = ""; diff --git a/wled00/ota_update.h b/wled00/ota_update.h index 82d97d6ce4..691429b305 100644 --- a/wled00/ota_update.h +++ b/wled00/ota_update.h @@ -51,6 +51,12 @@ std::pair getOTAResult(AsyncWebServerRequest *request); */ void handleOTAData(AsyncWebServerRequest *request, size_t index, uint8_t *data, size_t len, bool isFinal); +/** + * Mark currently running firmware as valid to prevent auto-rollback on reboot. + * This option can be enabled in some builds/bootloaders, it is an sdkconfig flag. + */ +void markOTAvalid(); + #if defined(ARDUINO_ARCH_ESP32) && !defined(WLED_DISABLE_OTA) /** * Calculate and cache the bootloader SHA256 digest diff --git a/wled00/wled.cpp b/wled00/wled.cpp index b40289be21..29ff3be082 100644 --- a/wled00/wled.cpp +++ b/wled00/wled.cpp @@ -555,6 +555,7 @@ void WLED::setup() #if defined(ARDUINO_ARCH_ESP32) && defined(WLED_DISABLE_BROWNOUT_DET) WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 1); //enable brownout detector #endif + markOTAvalid(); } void WLED::beginStrip() From f9a9a13470a30a07dc81340b01d9ddc90be9ce98 Mon Sep 17 00:00:00 2001 From: Damian Schneider Date: Tue, 11 Nov 2025 13:37:04 +0100 Subject: [PATCH 2/4] adding full env definitions --- platformio.ini | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/platformio.ini b/platformio.ini index 0acd08bf1f..d4e4c37f28 100644 --- a/platformio.ini +++ b/platformio.ini @@ -547,12 +547,20 @@ lib_deps = ${esp32c3.lib_deps} board_build.flash_mode = dio ; safe default, required for OTA updates to 0.16 from older version which used dio (must match the bootloader!) [env:esp32c3dev_qio] -extends = esp32c3dev +extends = esp32c3 +platform = ${esp32c3.platform} +platform_packages = ${esp32c3.platform_packages} +framework = arduino +board = esp32-c3-devkitm-1 +board_build.partitions = ${esp32.default_partitions} build_flags = ${common.build_flags} ${esp32c3.build_flags} -D WLED_RELEASE_NAME=\"ESP32-C3-QIO\" -D WLED_WATCHDOG_TIMEOUT=0 -DLOLIN_WIFI_FIX ; lower TX power, seems to work much better with this -DARDUINO_USB_CDC_ON_BOOT=1 ;; for virtual CDC USB ;-DARDUINO_USB_CDC_ON_BOOT=0 ;; for serial-to-USB chip +upload_speed = 460800 +build_unflags = ${common.build_unflags} +lib_deps = ${esp32c3.lib_deps} board_build.flash_mode = qio ; qio is faster and works on almost all boards (some may use dio to get 2 extra pins) [env:esp32s3dev_16MB_opi] From 1a12557517a3401cc36e7ac6a53de5884c0376b1 Mon Sep 17 00:00:00 2001 From: Damian Schneider Date: Wed, 12 Nov 2025 19:33:40 +0100 Subject: [PATCH 3/4] make qio env inherit from c3dev env correctly --- platformio.ini | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/platformio.ini b/platformio.ini index d4e4c37f28..656b90546c 100644 --- a/platformio.ini +++ b/platformio.ini @@ -547,21 +547,10 @@ lib_deps = ${esp32c3.lib_deps} board_build.flash_mode = dio ; safe default, required for OTA updates to 0.16 from older version which used dio (must match the bootloader!) [env:esp32c3dev_qio] -extends = esp32c3 -platform = ${esp32c3.platform} -platform_packages = ${esp32c3.platform_packages} -framework = arduino -board = esp32-c3-devkitm-1 -board_build.partitions = ${esp32.default_partitions} -build_flags = ${common.build_flags} ${esp32c3.build_flags} -D WLED_RELEASE_NAME=\"ESP32-C3-QIO\" - -D WLED_WATCHDOG_TIMEOUT=0 - -DLOLIN_WIFI_FIX ; lower TX power, seems to work much better with this - -DARDUINO_USB_CDC_ON_BOOT=1 ;; for virtual CDC USB - ;-DARDUINO_USB_CDC_ON_BOOT=0 ;; for serial-to-USB chip -upload_speed = 460800 -build_unflags = ${common.build_unflags} -lib_deps = ${esp32c3.lib_deps} -board_build.flash_mode = qio ; qio is faster and works on almost all boards (some may use dio to get 2 extra pins) +extends = env:esp32c3dev +build_unflags = -D WLED_RELEASE_NAME +build_flags = ${env:esp32c3dev.build_flags} -D WLED_RELEASE_NAME=\"ESP32-C3-QIO\" +board_build.flash_mode = qio ; qio is faster and works on almost all boards (some boards may use dio to get 2 extra pins) [env:esp32s3dev_16MB_opi] ;; ESP32-S3 development board, with 16MB FLASH and >= 8MB PSRAM (memory_type: qio_opi) From 1560a97581e625730a06cc46237977e9d882aedb Mon Sep 17 00:00:00 2001 From: Damian Schneider Date: Wed, 12 Nov 2025 19:44:59 +0100 Subject: [PATCH 4/4] cleaner way of inheriting the env, thx rabbit --- platformio.ini | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/platformio.ini b/platformio.ini index 656b90546c..de02535d69 100644 --- a/platformio.ini +++ b/platformio.ini @@ -548,8 +548,7 @@ board_build.flash_mode = dio ; safe default, required for OTA updates to 0.16 fr [env:esp32c3dev_qio] extends = env:esp32c3dev -build_unflags = -D WLED_RELEASE_NAME -build_flags = ${env:esp32c3dev.build_flags} -D WLED_RELEASE_NAME=\"ESP32-C3-QIO\" +build_flags = ${common.build_flags} ${esp32c3.build_flags} -D WLED_RELEASE_NAME=\"ESP32-C3-QIO\" board_build.flash_mode = qio ; qio is faster and works on almost all boards (some boards may use dio to get 2 extra pins) [env:esp32s3dev_16MB_opi]