Skip to content

Commit a0eec81

Browse files
committed
allow different bootloader sizes for each MCU
not needed yet, but will make maintenance easier in the future, and avoid confusion.
1 parent 9eda32b commit a0eec81

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

wled00/ota_update.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,17 @@
1313
constexpr 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)
1819
constexpr 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)
2022
constexpr 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
2225
constexpr 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 = "";
289293
void 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

Comments
 (0)