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