1313constexpr size_t METADATA_OFFSET = 256 ; // ESP32: metadata appears after Espressif metadata
1414#define UPDATE_ERROR errorString
1515
16+ // Bootloader is at fixed offset 0x1000 (4KB), 0x0000 (0KB), or 0x2000 (8KB), and is typically 32KB
1617// Bootloader offsets for different MCUs => see https://github.com/wled/WLED/issues/5064
1718#if defined(CONFIG_IDF_TARGET_ESP32S3) || defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32C6)
1819constexpr size_t BOOTLOADER_OFFSET = 0x0000 ; // esp32-S3, esp32-C3 and (future support) esp32-c6
20+ constexpr size_t BOOTLOADER_SIZE = 0x8000 ; // 32KB, typical bootloader size
1921#elif defined(CONFIG_IDF_TARGET_ESP32P4) || defined(CONFIG_IDF_TARGET_ESP32C5)
2022constexpr size_t BOOTLOADER_OFFSET = 0x2000 ; // (future support) esp32-P4 and esp32-C5
23+ constexpr size_t BOOTLOADER_SIZE = 0x8000 ; // 32KB, typical bootloader size
2124#else
2225constexpr size_t BOOTLOADER_OFFSET = 0x1000 ; // esp32 and esp32-s2
26+ constexpr size_t BOOTLOADER_SIZE = 0x8000 ; // 32KB, typical bootloader size
2327#endif
2428
2529#elif defined(ESP8266)
@@ -289,9 +293,6 @@ static String bootloaderSHA256HexCache = "";
289293void calculateBootloaderSHA256 () {
290294 if (!bootloaderSHA256HexCache.isEmpty ()) return ;
291295
292- // Bootloader is at fixed offset 0x1000 (4KB) and is typically 32KB
293- const uint32_t bootloaderSize = 0x8000 ; // 32KB, typical bootloader size
294-
295296 // Calculate SHA256
296297 uint8_t sha256[32 ];
297298 mbedtls_sha256_context ctx;
@@ -301,8 +302,8 @@ void calculateBootloaderSHA256() {
301302 const size_t chunkSize = 256 ;
302303 uint8_t buffer[chunkSize];
303304
304- for (uint32_t offset = 0 ; offset < bootloaderSize ; offset += chunkSize) {
305- size_t readSize = min ((size_t )(bootloaderSize - offset), chunkSize);
305+ for (uint32_t offset = 0 ; offset < BOOTLOADER_SIZE ; offset += chunkSize) {
306+ size_t readSize = min ((size_t )(BOOTLOADER_SIZE - offset), chunkSize);
306307 if (esp_flash_read (NULL , buffer, BOOTLOADER_OFFSET + offset, readSize) == ESP_OK) {
307308 mbedtls_sha256_update (&ctx, buffer, readSize);
308309 }
0 commit comments