From eb5ba6b0e6d5922f7cda8163ea1a4dc44fd02819 Mon Sep 17 00:00:00 2001 From: LeoYan Date: Thu, 3 Nov 2022 08:53:21 +0800 Subject: [PATCH] fixed ESP32-C3: "app image at 0x10000 has invalid magic byte" if the app image flashed at first #48 --- ESPLoader.js | 5 ++++- targets/esp32c3.js | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/ESPLoader.js b/ESPLoader.js index bee8e18..fcdca0e 100644 --- a/ESPLoader.js +++ b/ESPLoader.js @@ -777,7 +777,10 @@ class ESPLoader { let image, address; for (var i = 0; i < fileArray.length; i++) { console.log("Data Length " + fileArray[i].data.length); - image = fileArray[i].data + '\xff\xff\xff\xff'.substring(0, 4 - fileArray[i].data.length % 4); + + image = fileArray[i].data; + const reminder = fileArray[i].data.length % 4; + if (reminder > 0) image += '\xff\xff\xff\xff'.substring(4 - reminder); address = fileArray[i].address; console.log("Image Length " + image.length); if (image.length === 0) { diff --git a/targets/esp32c3.js b/targets/esp32c3.js index 2a8f26f..a1d4cc4 100644 --- a/targets/esp32c3.js +++ b/targets/esp32c3.js @@ -8,7 +8,7 @@ export default class ESP32C3ROM { static UART_DATE_REG_ADDR = 0x6000007c; static FLASH_WRITE_SIZE = 0x400; - static BOOTLOADER_FLASH_OFFSET = 0x1000; + static BOOTLOADER_FLASH_OFFSET = 0; static FLASH_SIZES = { "1MB": 0x00,