Allow flashing a bootloader which does not end on 1KB boundary or is shorter than the maximum size

Resolves #75
This commit is contained in:
Raphael Coeffic
2021-05-29 13:34:25 +02:00
committed by Raphael Coeffic
parent f5bc9f2124
commit 954758c770
+11 -2
View File
@@ -59,8 +59,11 @@ void BootloaderFirmwareUpdate::flashFirmware(const char * filename, ProgressHand
}
for (int i = 0; i < BOOTLOADER_SIZE; i += 1024) {
watchdogSuspend(1000/*10s*/);
if (f_read(&file, buffer, sizeof(buffer), &count) != FR_OK || count != sizeof(buffer)) {
memset(buffer, 0xFF, sizeof(buffer));
if (f_read(&file, buffer, sizeof(buffer), &count) != FR_OK) {
POPUP_WARNING(STR_SDCARD_ERROR);
break;
}
@@ -68,12 +71,18 @@ void BootloaderFirmwareUpdate::flashFirmware(const char * filename, ProgressHand
POPUP_WARNING(STR_INCOMPATIBLE);
break;
}
for (int j = 0; j < 1024; j += FLASH_PAGESIZE) {
for (UINT j = 0; j < count; j += FLASH_PAGESIZE) {
flashWrite(CONVERT_UINT_PTR(FIRMWARE_ADDRESS + i + j), CONVERT_UINT_PTR(buffer + j));
}
// TODO: use real bootloader size rather than the maximum size
progressHandler("Bootloader", STR_WRITING, i, BOOTLOADER_SIZE);
// Reached end-of-file
if (count != sizeof(buffer)) {
break;
}
#if defined(SIMU)
// add an artificial delay and check for simu quit
if (SIMU_SLEEP_OR_EXIT_MS(30))