Skip to content

Commit

Permalink
Support bootloader.bin update.
Browse files Browse the repository at this point in the history
  • Loading branch information
BlueAndi committed Apr 25, 2024
1 parent 5448026 commit a7d7146
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 21 deletions.
5 changes: 4 additions & 1 deletion data/update.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ <h1 class="mt-5">Update</h1>

<div class="tab-pane fade active show" id="update" role="tabpanel" aria-labelledby="update-tab">
<br />
<p>Upload <u>~FIRMWARE_FILENAME~</u> file for software update or <u>~FILESYSTEM_FILENAME~</u> for updating the filesystem.</p>
<p>Upload <u>~FIRMWARE_FILENAME~</u> and <u>~BOOTLOADER_FILENAME~</u> file for software update or <u>~FILESYSTEM_FILENAME~</u> for updating the filesystem.</p>
<p>Use multi-select to upload both at once.</p>
<div class="input-group">
<div class="custom-file">
Expand Down Expand Up @@ -169,6 +169,7 @@ <h1 class="mt-5">Update</h1>
file = document.getElementById("inputFile").files[index];

if (("~FIRMWARE_FILENAME~" === file.name) ||
("~BOOTLOADER_FILENAME~" === file.name) ||
("~FILESYSTEM_FILENAME~" === file.name)) {

files.push(file);
Expand All @@ -190,6 +191,8 @@ <h1 class="mt-5">Update</h1>

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;
}
Expand Down
50 changes: 30 additions & 20 deletions src/Web/Pages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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/";

Expand All @@ -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()); },
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit a7d7146

Please sign in to comment.