1212constexpr size_t METADATA_OFFSET = 256 ; // ESP32: metadata appears after Espressif metadata
1313#define UPDATE_ERROR errorString
1414
15+ // Bootloader is at fixed offset 0x1000 (4KB), 0x0000 (0KB), or 0x2000 (8KB), and is typically 32KB
1516// Bootloader offsets for different MCUs => see https://github.com/wled/WLED/issues/5064
1617#if defined(CONFIG_IDF_TARGET_ESP32S3) || defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32C6)
1718constexpr size_t BOOTLOADER_OFFSET = 0x0000 ; // esp32-S3, esp32-C3 and (future support) esp32-c6
19+ constexpr size_t BOOTLOADER_SIZE = 0x8000 ; // 32KB, typical bootloader size
1820#elif defined(CONFIG_IDF_TARGET_ESP32P4) || defined(CONFIG_IDF_TARGET_ESP32C5)
1921constexpr size_t BOOTLOADER_OFFSET = 0x2000 ; // (future support) esp32-P4 and esp32-C5
22+ constexpr size_t BOOTLOADER_SIZE = 0x8000 ; // 32KB, typical bootloader size
2023#else
2124constexpr size_t BOOTLOADER_OFFSET = 0x1000 ; // esp32 and esp32-s2
25+ constexpr size_t BOOTLOADER_SIZE = 0x8000 ; // 32KB, typical bootloader size
2226#endif
2327
2428#elif defined(ESP8266)
@@ -274,9 +278,6 @@ static String bootloaderSHA256HexCache = "";
274278void calculateBootloaderSHA256 () {
275279 if (!bootloaderSHA256HexCache.isEmpty ()) return ;
276280
277- // Bootloader is at fixed offset 0x1000 (4KB) and is typically 32KB
278- const uint32_t bootloaderSize = 0x8000 ; // 32KB, typical bootloader size
279-
280281 // Calculate SHA256
281282 uint8_t sha256[32 ];
282283 mbedtls_sha256_context ctx;
@@ -286,8 +287,8 @@ void calculateBootloaderSHA256() {
286287 const size_t chunkSize = 256 ;
287288 uint8_t buffer[chunkSize];
288289
289- for (uint32_t offset = 0 ; offset < bootloaderSize ; offset += chunkSize) {
290- size_t readSize = min ((size_t )(bootloaderSize - offset), chunkSize);
290+ for (uint32_t offset = 0 ; offset < BOOTLOADER_SIZE ; offset += chunkSize) {
291+ size_t readSize = min ((size_t )(BOOTLOADER_SIZE - offset), chunkSize);
291292#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 4, 0)
292293 if (esp_flash_read (NULL , buffer, BOOTLOADER_OFFSET + offset, readSize) == ESP_OK) { // use esp_flash_read for V4 framework (-S2, -S3, -C3)
293294#else
0 commit comments