Various fixes around flashing bootloader

This commit is contained in:
Raphael Coeffic
2021-05-29 13:34:25 +02:00
committed by Raphael Coeffic
parent 8e57090d66
commit 351173a509
8 changed files with 52 additions and 28 deletions
+2
View File
@@ -71,6 +71,7 @@ inline void POPUP_INFORMATION(const char * message)
{
auto popup = createPopupInformation(message);
while (popup->getParent()) {
WDG_RESET();
MainWindow::instance()->run(false);
}
}
@@ -82,6 +83,7 @@ inline void POPUP_WARNING(const char * message, const char * info = nullptr)
popup->setInfoText(std::string(info));
}
while (popup->getParent()) {
WDG_RESET();
MainWindow::instance()->run(false);
}
}
@@ -34,6 +34,7 @@ MessageDialog::MessageDialog(Window* parent, const char* title,
width(), PAGE_LINE_HEIGHT},
info, 0, CENTERED);
setCloseWhenClickOutside(true);
setFocus();
}
#if defined(HARDWARE_KEYS)
+7
View File
@@ -36,6 +36,13 @@ class MessageDialog: public Dialog {
StaticText * messageWidget;
StaticText * infoWidget;
#if defined(DEBUG_WINDOWS)
std::string getName() const override
{
return "MessageDialog";
}
#endif
#if defined(HARDWARE_KEYS)
void onEvent(event_t event) override;
#endif
+33 -23
View File
@@ -97,6 +97,7 @@ class FlashDialog: public FullScreenDialog
device(device),
progress(this, {LCD_W / 2 - 50, LCD_H / 2, 100, 15})
{
setFocus();
}
void deleteLater(bool detach = true, bool trash = true) override
@@ -105,17 +106,20 @@ class FlashDialog: public FullScreenDialog
return;
progress.deleteLater(true, false);
FullScreenDialog::deleteLater(detach, trash);
}
void flash(const char * filename)
{
device.flashFirmware(filename, [=](const char * title, const char * message, int count, int total) -> void {
setMessage(message);
progress.setValue(total > 0 ? count * 100 / total : 0);
MainWindow::instance()->run(false);
});
TRACE("flashing '%s'", filename);
device.flashFirmware(
filename,
[=](const char *title, const char *message, int count,
int total) -> void {
setMessage(message);
progress.setValue(total > 0 ? count * 100 / total : 0);
MainWindow::instance()->run(false);
});
deleteLater();
}
@@ -188,9 +192,11 @@ void RadioSdManagerPage::build(FormWindow * window)
if (information.readMultiFirmwareInformation(name.data()) == nullptr) {
#if defined(INTERNAL_MODULE_MULTI)
menu->addLine(STR_FLASH_INTERNAL_MULTI, [=]() {
MultiDeviceFirmwareUpdate deviceFirmwareUpdate(INTERNAL_MODULE, MULTI_TYPE_MULTIMODULE);
auto dialog = new FlashDialog<MultiDeviceFirmwareUpdate>(deviceFirmwareUpdate);
dialog->flash(getFullPath(name));
MultiDeviceFirmwareUpdate deviceFirmwareUpdate(
INTERNAL_MODULE, MULTI_TYPE_MULTIMODULE);
auto dialog = new FlashDialog<MultiDeviceFirmwareUpdate>(
deviceFirmwareUpdate);
dialog->flash(getFullPath(name));
});
#endif
menu->addLine(STR_FLASH_EXTERNAL_MULTI, [=]() {
@@ -219,29 +225,33 @@ void RadioSdManagerPage::build(FormWindow * window)
if (!READ_ONLY() && !strcasecmp(ext, FIRMWARE_EXT)) {
if (isBootloader(name.data())) {
menu->addLine(STR_FLASH_BOOTLOADER, [=]() {
BootloaderFirmwareUpdate bootloaderFirmwareUpdate;
auto dialog = new FlashDialog<BootloaderFirmwareUpdate>(bootloaderFirmwareUpdate);
dialog->flash(getFullPath(name));
BootloaderFirmwareUpdate bootloaderFirmwareUpdate;
auto dialog = new FlashDialog<BootloaderFirmwareUpdate>(
bootloaderFirmwareUpdate);
dialog->flash(getFullPath(name));
TRACE("### finished flashing ###");
});
}
}
else if (!READ_ONLY() && !strcasecmp(ext, SPORT_FIRMWARE_EXT)) {
} else if (!READ_ONLY() && !strcasecmp(ext, SPORT_FIRMWARE_EXT)) {
if (HAS_SPORT_UPDATE_CONNECTOR()) {
menu->addLine(STR_FLASH_EXTERNAL_DEVICE, [=]() {
FrskyDeviceFirmwareUpdate deviceFirmwareUpdate(SPORT_MODULE);
auto dialog = new FlashDialog<FrskyDeviceFirmwareUpdate>(deviceFirmwareUpdate);
dialog->flash(getFullPath(name));
FrskyDeviceFirmwareUpdate deviceFirmwareUpdate(SPORT_MODULE);
auto dialog = new FlashDialog<FrskyDeviceFirmwareUpdate>(
deviceFirmwareUpdate);
dialog->flash(getFullPath(name));
});
}
menu->addLine(STR_FLASH_INTERNAL_MODULE, [=]() {
FrskyDeviceFirmwareUpdate deviceFirmwareUpdate(INTERNAL_MODULE);
auto dialog = new FlashDialog<FrskyDeviceFirmwareUpdate>(deviceFirmwareUpdate);
dialog->flash(getFullPath(name));
FrskyDeviceFirmwareUpdate deviceFirmwareUpdate(INTERNAL_MODULE);
auto dialog = new FlashDialog<FrskyDeviceFirmwareUpdate>(
deviceFirmwareUpdate);
dialog->flash(getFullPath(name));
});
menu->addLine(STR_FLASH_EXTERNAL_MODULE, [=]() {
FrskyDeviceFirmwareUpdate deviceFirmwareUpdate(EXTERNAL_MODULE);
auto dialog = new FlashDialog<FrskyDeviceFirmwareUpdate>(deviceFirmwareUpdate);
dialog->flash(getFullPath(name));
FrskyDeviceFirmwareUpdate deviceFirmwareUpdate(EXTERNAL_MODULE);
auto dialog = new FlashDialog<FrskyDeviceFirmwareUpdate>(
deviceFirmwareUpdate);
dialog->flash(getFullPath(name));
});
}
#if defined(LUA)
+6 -1
View File
@@ -58,6 +58,11 @@ void BootloaderFirmwareUpdate::flashFirmware(const char * filename, ProgressHand
unlockFlash();
}
UINT flash_size = file.obj.objsize;
if (flash_size > BOOTLOADER_SIZE) {
flash_size = BOOTLOADER_SIZE;
}
for (int i = 0; i < BOOTLOADER_SIZE; i += 1024) {
watchdogSuspend(1000/*10s*/);
@@ -79,7 +84,7 @@ void BootloaderFirmwareUpdate::flashFirmware(const char * filename, ProgressHand
for (UINT j = 0; j < count; j += FLASH_PAGESIZE) {
flashWrite(CONVERT_UINT_PTR(FIRMWARE_ADDRESS + i + j), CONVERT_UINT_PTR(buffer + j));
}
progressHandler("Bootloader", STR_WRITING, i, file.obj.objsize);
progressHandler("Bootloader", STR_WRITING, i, flash_size);
// Reached end-of-file
if (f_eof(&file)) break;
+1 -2
View File
@@ -514,8 +514,7 @@ const char * FrskyDeviceFirmwareUpdate::flashFirmware(const char * filename, Pro
if (result) {
POPUP_WARNING(STR_FIRMWARE_UPDATE_ERROR, result);
}
else {
} else {
POPUP_INFORMATION(STR_FIRMWARE_UPDATE_SUCCESS);
}
+1 -1
View File
@@ -706,7 +706,7 @@ void lockFlash()
void flashWrite(uint32_t *address, const uint32_t *buffer)
{
simuSleep(100);
simuSleep(10);
}
uint32_t isBootloaderStart(const uint8_t * block)