From fcbe4572b890110740dfd4970d1938ed817bfdff Mon Sep 17 00:00:00 2001 From: Damjan Adamic Date: Wed, 14 Jan 2015 19:23:12 +0100 Subject: [PATCH] Fixes #1997: firmware upload failed when "Check Firmware Compatibility" was selected (ported from master) --- companion/src/flashfirmwaredialog.cpp | 16 +++++++++++++++- companion/src/helpers.cpp | 5 +++++ companion/src/helpers.h | 1 + companion/src/radiointerface.cpp | 4 ++++ 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/companion/src/flashfirmwaredialog.cpp b/companion/src/flashfirmwaredialog.cpp index 98d42b2a1..fd6effe1c 100755 --- a/companion/src/flashfirmwaredialog.cpp +++ b/companion/src/flashfirmwaredialog.cpp @@ -203,6 +203,8 @@ void FlashFirmwareDialog::on_burnButton_clicked() g.checkHardwareCompatibility(ui->checkHardwareCompatibility->isChecked()); g.backupOnFlash(ui->backupEEprom->isChecked()); + qDebug() << "FlashFirmwareDialog: flashing" << fwName; + if (imageSource != FIRMWARE) { // load the splash image const QPixmap * pixmap = ui->splash->pixmap(); @@ -220,6 +222,7 @@ void FlashFirmwareDialog::on_burnButton_clicked() tempFile = generateProcessUniqueTempFileName("flash.hex"); else tempFile = generateProcessUniqueTempFileName("flash.bin"); + qDebug() << "FlashFirmwareDialog: patching" << fwName << "with custom splash screen and saving to" << tempFile; FirmwareInterface firmware(fwName); firmware.setSplash(image); if (firmware.save(tempFile) <= 0) { @@ -253,15 +256,21 @@ void FlashFirmwareDialog::startFlash(const QString &filename) // check hardware compatibility if requested if (g.checkHardwareCompatibility()) { - QString tempFirmware = generateProcessUniqueTempFileName("flash.bin"); + QString tempFirmware = generateProcessUniqueTempFileName("flash-check.bin"); if (!readFirmware(tempFirmware, progressDialog.progress())) { QMessageBox::warning(this, tr("Firmware check failed"), tr("Could not check firmware from radio")); return; } FirmwareInterface previousFirmware(tempFirmware); + qunlink(tempFirmware); FirmwareInterface newFirmware(filename); + qDebug() << "startFlash: checking firmware compatibility between " << tempFirmware << "and" << filename; if (!newFirmware.isHardwareCompatible(previousFirmware)) { QMessageBox::warning(this, tr("Firmware check failed"), tr("New firmware is not compatible with the one currently installed!")); + if (isTempFileName(filename)) { + qDebug() << "startFlash: removing temporary file" << filename; + qunlink(filename); + } return; } } @@ -293,4 +302,9 @@ void FlashFirmwareDialog::startFlash(const QString &filename) progressDialog.progress()->setInfo(tr("Flashing done")); progressDialog.exec(); + + if (isTempFileName(filename)) { + qDebug() << "startFlash: removing temporary file" << filename; + qunlink(filename); + } } diff --git a/companion/src/helpers.cpp b/companion/src/helpers.cpp index 7f70a4fc4..5eca9b671 100644 --- a/companion/src/helpers.cpp +++ b/companion/src/helpers.cpp @@ -990,6 +990,11 @@ QString generateProcessUniqueTempFileName(const QString &fileName) return QDir::tempPath() + QString("/%1-").arg(QCoreApplication::applicationPid()) + sanitizedFileName; } +bool isTempFileName(const QString & fileName) +{ + return fileName.startsWith(QDir::tempPath()); +} + QString getSoundsPath(const GeneralSettings &generalSettings) { QString path = g.profile[g.id()].sdPath() + "/SOUNDS/"; diff --git a/companion/src/helpers.h b/companion/src/helpers.h index 757c41043..03c8578a4 100644 --- a/companion/src/helpers.h +++ b/companion/src/helpers.h @@ -152,6 +152,7 @@ class QTimeS : public QTime int qunlink(const QString & fileName); QString generateProcessUniqueTempFileName(const QString & fileName); +bool isTempFileName(const QString & fileName); QString getSoundsPath(const GeneralSettings &generalSettings); QSet getFilesSet(const QString &path, const QStringList &filter, int maxLen); diff --git a/companion/src/radiointerface.cpp b/companion/src/radiointerface.cpp index 9a304f20d..f10bcfbcb 100755 --- a/companion/src/radiointerface.cpp +++ b/companion/src/radiointerface.cpp @@ -251,12 +251,14 @@ bool readFirmware(const QString &filename, ProgressWidget *progress) if (IS_ARM(GetCurrentFirmware()->getBoard())) { QString path = findMassstoragePath("FIRMWARE.BIN"); if (!path.isEmpty()) { + qDebug() << "readFirmware: reading" << path << "into" << filename; CopyProcess copyProcess(path, filename, progress); result = copyProcess.run(); } } if (result == false) { + qDebug() << "readFirmware: reading" << filename << "with" << getRadioInterfaceCmd() << getReadFirmwareArgs(filename); FlashProcess flashProcess(getRadioInterfaceCmd(), getReadFirmwareArgs(filename), progress); result = flashProcess.run(); } @@ -273,11 +275,13 @@ bool writeFirmware(const QString &filename, ProgressWidget *progress) if (IS_ARM(GetCurrentFirmware()->getBoard())) { QString path = findMassstoragePath("FIRMWARE.BIN"); if (!path.isEmpty()) { + qDebug() << "writeFirmware: writing" << path << "from" << filename; CopyProcess copyProcess(filename, path, progress); return copyProcess.run(); } } + qDebug() << "writeFirmware: writing" << filename << "with" << getRadioInterfaceCmd() << getWriteFirmwareArgs(filename); FlashProcess flashProcess(getRadioInterfaceCmd(), getWriteFirmwareArgs(filename), progress); return flashProcess.run(); }