1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-19 14:25:11 +03:00

Fixes #1997: firmware upload failed when "Check Firmware Compatibility" was selected (ported from master)

This commit is contained in:
Damjan Adamic 2015-01-14 19:23:12 +01:00
parent 27314d04cf
commit fcbe4572b8
4 changed files with 25 additions and 1 deletions

View file

@ -203,6 +203,8 @@ void FlashFirmwareDialog::on_burnButton_clicked()
g.checkHardwareCompatibility(ui->checkHardwareCompatibility->isChecked()); g.checkHardwareCompatibility(ui->checkHardwareCompatibility->isChecked());
g.backupOnFlash(ui->backupEEprom->isChecked()); g.backupOnFlash(ui->backupEEprom->isChecked());
qDebug() << "FlashFirmwareDialog: flashing" << fwName;
if (imageSource != FIRMWARE) { if (imageSource != FIRMWARE) {
// load the splash image // load the splash image
const QPixmap * pixmap = ui->splash->pixmap(); const QPixmap * pixmap = ui->splash->pixmap();
@ -220,6 +222,7 @@ void FlashFirmwareDialog::on_burnButton_clicked()
tempFile = generateProcessUniqueTempFileName("flash.hex"); tempFile = generateProcessUniqueTempFileName("flash.hex");
else else
tempFile = generateProcessUniqueTempFileName("flash.bin"); tempFile = generateProcessUniqueTempFileName("flash.bin");
qDebug() << "FlashFirmwareDialog: patching" << fwName << "with custom splash screen and saving to" << tempFile;
FirmwareInterface firmware(fwName); FirmwareInterface firmware(fwName);
firmware.setSplash(image); firmware.setSplash(image);
if (firmware.save(tempFile) <= 0) { if (firmware.save(tempFile) <= 0) {
@ -253,15 +256,21 @@ void FlashFirmwareDialog::startFlash(const QString &filename)
// check hardware compatibility if requested // check hardware compatibility if requested
if (g.checkHardwareCompatibility()) { if (g.checkHardwareCompatibility()) {
QString tempFirmware = generateProcessUniqueTempFileName("flash.bin"); QString tempFirmware = generateProcessUniqueTempFileName("flash-check.bin");
if (!readFirmware(tempFirmware, progressDialog.progress())) { if (!readFirmware(tempFirmware, progressDialog.progress())) {
QMessageBox::warning(this, tr("Firmware check failed"), tr("Could not check firmware from radio")); QMessageBox::warning(this, tr("Firmware check failed"), tr("Could not check firmware from radio"));
return; return;
} }
FirmwareInterface previousFirmware(tempFirmware); FirmwareInterface previousFirmware(tempFirmware);
qunlink(tempFirmware);
FirmwareInterface newFirmware(filename); FirmwareInterface newFirmware(filename);
qDebug() << "startFlash: checking firmware compatibility between " << tempFirmware << "and" << filename;
if (!newFirmware.isHardwareCompatible(previousFirmware)) { if (!newFirmware.isHardwareCompatible(previousFirmware)) {
QMessageBox::warning(this, tr("Firmware check failed"), tr("New firmware is not compatible with the one currently installed!")); 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; return;
} }
} }
@ -293,4 +302,9 @@ void FlashFirmwareDialog::startFlash(const QString &filename)
progressDialog.progress()->setInfo(tr("Flashing done")); progressDialog.progress()->setInfo(tr("Flashing done"));
progressDialog.exec(); progressDialog.exec();
if (isTempFileName(filename)) {
qDebug() << "startFlash: removing temporary file" << filename;
qunlink(filename);
}
} }

View file

@ -990,6 +990,11 @@ QString generateProcessUniqueTempFileName(const QString &fileName)
return QDir::tempPath() + QString("/%1-").arg(QCoreApplication::applicationPid()) + sanitizedFileName; 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 getSoundsPath(const GeneralSettings &generalSettings)
{ {
QString path = g.profile[g.id()].sdPath() + "/SOUNDS/"; QString path = g.profile[g.id()].sdPath() + "/SOUNDS/";

View file

@ -152,6 +152,7 @@ class QTimeS : public QTime
int qunlink(const QString & fileName); int qunlink(const QString & fileName);
QString generateProcessUniqueTempFileName(const QString & fileName); QString generateProcessUniqueTempFileName(const QString & fileName);
bool isTempFileName(const QString & fileName);
QString getSoundsPath(const GeneralSettings &generalSettings); QString getSoundsPath(const GeneralSettings &generalSettings);
QSet<QString> getFilesSet(const QString &path, const QStringList &filter, int maxLen); QSet<QString> getFilesSet(const QString &path, const QStringList &filter, int maxLen);

View file

@ -251,12 +251,14 @@ bool readFirmware(const QString &filename, ProgressWidget *progress)
if (IS_ARM(GetCurrentFirmware()->getBoard())) { if (IS_ARM(GetCurrentFirmware()->getBoard())) {
QString path = findMassstoragePath("FIRMWARE.BIN"); QString path = findMassstoragePath("FIRMWARE.BIN");
if (!path.isEmpty()) { if (!path.isEmpty()) {
qDebug() << "readFirmware: reading" << path << "into" << filename;
CopyProcess copyProcess(path, filename, progress); CopyProcess copyProcess(path, filename, progress);
result = copyProcess.run(); result = copyProcess.run();
} }
} }
if (result == false) { if (result == false) {
qDebug() << "readFirmware: reading" << filename << "with" << getRadioInterfaceCmd() << getReadFirmwareArgs(filename);
FlashProcess flashProcess(getRadioInterfaceCmd(), getReadFirmwareArgs(filename), progress); FlashProcess flashProcess(getRadioInterfaceCmd(), getReadFirmwareArgs(filename), progress);
result = flashProcess.run(); result = flashProcess.run();
} }
@ -273,11 +275,13 @@ bool writeFirmware(const QString &filename, ProgressWidget *progress)
if (IS_ARM(GetCurrentFirmware()->getBoard())) { if (IS_ARM(GetCurrentFirmware()->getBoard())) {
QString path = findMassstoragePath("FIRMWARE.BIN"); QString path = findMassstoragePath("FIRMWARE.BIN");
if (!path.isEmpty()) { if (!path.isEmpty()) {
qDebug() << "writeFirmware: writing" << path << "from" << filename;
CopyProcess copyProcess(filename, path, progress); CopyProcess copyProcess(filename, path, progress);
return copyProcess.run(); return copyProcess.run();
} }
} }
qDebug() << "writeFirmware: writing" << filename << "with" << getRadioInterfaceCmd() << getWriteFirmwareArgs(filename);
FlashProcess flashProcess(getRadioInterfaceCmd(), getWriteFirmwareArgs(filename), progress); FlashProcess flashProcess(getRadioInterfaceCmd(), getWriteFirmwareArgs(filename), progress);
return flashProcess.run(); return flashProcess.run();
} }