From a7d7146ff76383568b8f8184b4b941e5dbfe95ad Mon Sep 17 00:00:00 2001 From: BlueAndi Date: Fri, 26 Apr 2024 00:12:18 +0200 Subject: [PATCH] Support bootloader.bin update. --- data/update.html | 5 ++++- src/Web/Pages.cpp | 50 ++++++++++++++++++++++++++++------------------- 2 files changed, 34 insertions(+), 21 deletions(-) diff --git a/data/update.html b/data/update.html index 08844730..f387c53d 100644 --- a/data/update.html +++ b/data/update.html @@ -59,7 +59,7 @@

Update


-

Upload ~FIRMWARE_FILENAME~ file for software update or ~FILESYSTEM_FILENAME~ for updating the filesystem.

+

Upload ~FIRMWARE_FILENAME~ and ~BOOTLOADER_FILENAME~ file for software update or ~FILESYSTEM_FILENAME~ for updating the filesystem.

Use multi-select to upload both at once.

@@ -169,6 +169,7 @@

Update

file = document.getElementById("inputFile").files[index]; if (("~FIRMWARE_FILENAME~" === file.name) || + ("~BOOTLOADER_FILENAME~" === file.name) || ("~FILESYSTEM_FILENAME~" === file.name)) { files.push(file); @@ -190,6 +191,8 @@

Update

if ("~FIRMWARE_FILENAME~" === files[index].name) { fileHeaders["X-File-Size-Firmware"] = files[index].size; + } else if ("~BOOTLOADER_FILENAME~" === files[index].name) { + fileHeaders["X-File-Size-Bootloader"] = files[index].size; } else if ("~FILESYSTEM_FILENAME~" === files[index].name) { fileHeaders["X-File-Size-Filesystem"] = files[index].size; } diff --git a/src/Web/Pages.cpp b/src/Web/Pages.cpp index e91c4041..98fa409d 100644 --- a/src/Web/Pages.cpp +++ b/src/Web/Pages.cpp @@ -109,6 +109,9 @@ namespace tmpl /** Firmware binary filename, used for update. */ static const char* FIRMWARE_FILENAME = "firmware.bin"; +/** Bootloader binary filename, used for update. */ +static const char* BOOTLOADER_FILENAME = "bootloader.bin"; + /** Path to the plugin webpages. */ static const String PLUGIN_PAGE_PATH = "/plugins/"; @@ -125,6 +128,7 @@ static bool gIsUploadError = false; static TmplKeyWordFunc gTmplKeyWordToFunc[] = { "ARDUINO_IDF_BRANCH", []() -> String { return CONFIG_ARDUINO_IDF_BRANCH; }, + "BOOTLOADER_FILENAME", []() -> String { return BOOTLOADER_FILENAME; }, "ESP_CHIP_ID", tmpl::getEspChipId, "ESP_CHIP_REV", []() -> String { return String(ESP.getChipRevision()); }, "ESP_CPU_FREQ", []() -> String { return String(ESP.getCpuFreqMHz()); }, @@ -491,30 +495,36 @@ static void uploadHandler(AsyncWebServerRequest *request, const String& filename LOG_WARNING("Pending upload aborted."); } - /* Upload firmware or filesystem? */ - int cmd = (filename == FILESYSTEM_FILENAME) ? U_SPIFFS : U_FLASH; - - if (U_FLASH == cmd) + /* Upload firmware, bootloader or filesystem? */ + int cmd = U_FLASH; + AsyncWebHeader* headerXFileSize = nullptr; + + if (filename == FIRMWARE_FILENAME) { - AsyncWebHeader* headerXFileSizeFirmware = request->getHeader("X-File-Size-Firmware"); - - /* Firmware file size available? */ - if (nullptr != headerXFileSizeFirmware) - { - /* If conversion fails, it will contain UPDATE_SIZE_UNKNOWN. */ - (void)Util::strToUInt32(headerXFileSizeFirmware->value(), fileSize); - } + cmd = U_FLASH; + headerXFileSize = request->getHeader("X-File-Size-Firmware"); + } + else if (filename == BOOTLOADER_FILENAME) + { + cmd = U_FLASH; + headerXFileSize = request->getHeader("X-File-Size-Bootloader"); } - else if (U_SPIFFS == cmd) + else if (filename == FILESYSTEM_FILENAME) { - AsyncWebHeader* headerXFileSizeFilesystem = request->getHeader("X-File-Size-Filesystem"); + cmd = U_SPIFFS; + headerXFileSize = request->getHeader("X-File-Size-Filesystem"); + } + else + { + /* Unknown. */ + ; + } - /* Firmware file size available? */ - if (nullptr != headerXFileSizeFilesystem) - { - /* If conversion fails, it will contain UPDATE_SIZE_UNKNOWN. */ - (void)Util::strToUInt32(headerXFileSizeFilesystem->value(), fileSize); - } + /* File size available? */ + if (nullptr != headerXFileSize) + { + /* If conversion fails, it will contain UPDATE_SIZE_UNKNOWN. */ + (void)Util::strToUInt32(headerXFileSize->value(), fileSize); } if (UPDATE_SIZE_UNKNOWN == fileSize)