Allow firmware update with invalid magic header after user confirmation

This commit is contained in:
Jan Käberich 2024-01-13 19:08:51 +01:00
parent ee8188775a
commit ee16dbc070
3 changed files with 30 additions and 2 deletions

View File

@ -2,6 +2,7 @@
#include "ui_firmwareupdatedialog.h" #include "ui_firmwareupdatedialog.h"
#include "../../VNA_embedded/Application/Communication/PacketConstants.h" #include "../../VNA_embedded/Application/Communication/PacketConstants.h"
#include "CustomWidgets/informationbox.h"
#include <QFileDialog> #include <QFileDialog>
#include <QStyle> #include <QStyle>
@ -60,8 +61,25 @@ void FirmwareUpdateDialog::on_bStart_clicked()
char header[24]; char header[24];
file->read(header, sizeof(header)); file->read(header, sizeof(header));
if(strncmp(header, dev->getFirmwareMagicString().toStdString().c_str(), 4)) { if(strncmp(header, dev->getFirmwareMagicString().toStdString().c_str(), 4)) {
abortWithError("Invalid magic header constant"); // might be a firmware file for a wrong LibreVNA
return; if(dev->getProtocolVersion() == Protocol::Version) {
// we are talking to a LibreVNA with the correct protocol, this is definitely the wrong firmware file
abortWithError("Invalid magic header constant");
return;
} else {
// we might be talking to the correct hardware but with the wrong protocol version (which might result
// in the magic string check falsely failing. Process after user confirmation
auto confirm = InformationBox::AskQuestion("Continue?", "The firmware magic header constant does not match the expected"
" value for your LibreVNA. Either this is the wrong firmware file"
" or the hardware ID of your LibreVNA was read incorrectly. This"
" can happen if the LibreVNA uses a different protocol version than"
" what it expected by the GUI. Do you want to continue with the firmware update?", true);
if(!confirm) {
abortWithError("Aborted by user");
return;
}
}
} }
file->seek(0); file->seek(0);
state = State::ErasingFLASH; state = State::ErasingFLASH;

View File

@ -114,6 +114,7 @@ LibreVNADriver::LibreVNADriver()
skipOwnPacketHandling = false; skipOwnPacketHandling = false;
SApoints = 0; SApoints = 0;
hardwareVersion = 0; hardwareVersion = 0;
protocolVersion = 0;
setSynchronization(Synchronization::Disabled, false); setSynchronization(Synchronization::Disabled, false);
auto manual = new QAction("Manual Control"); auto manual = new QAction("Manual Control");
@ -589,6 +590,7 @@ void LibreVNADriver::handleReceivedPacket(const Protocol::PacketInfo &packet)
switch(packet.type) { switch(packet.type) {
case Protocol::PacketType::DeviceInfo: { case Protocol::PacketType::DeviceInfo: {
// Check protocol version // Check protocol version
protocolVersion = packet.info.ProtocolVersion;
if(packet.info.ProtocolVersion != Protocol::Version) { if(packet.info.ProtocolVersion != Protocol::Version) {
auto ret = InformationBox::AskQuestion("Warning", auto ret = InformationBox::AskQuestion("Warning",
"The device reports a different protocol" "The device reports a different protocol"
@ -703,6 +705,11 @@ QString LibreVNADriver::hardwareVersionToString(uint8_t version)
} }
} }
unsigned int LibreVNADriver::getProtocolVersion() const
{
return protocolVersion;
}
unsigned int LibreVNADriver::getMaxAmplitudePoints() const unsigned int LibreVNADriver::getMaxAmplitudePoints() const
{ {
return limits_maxAmplitudePoints; return limits_maxAmplitudePoints;

View File

@ -184,6 +184,8 @@ public:
QString getFirmwareMagicString(); QString getFirmwareMagicString();
unsigned int getProtocolVersion() const;
signals: signals:
void receivedAnswer(const LibreVNADriver::TransmissionResult &result); void receivedAnswer(const LibreVNADriver::TransmissionResult &result);
void receivedPacket(const Protocol::PacketInfo& packet); void receivedPacket(const Protocol::PacketInfo& packet);
@ -194,6 +196,7 @@ protected:
QString hardwareVersionToString(uint8_t version); QString hardwareVersionToString(uint8_t version);
bool connected; bool connected;
unsigned int protocolVersion;
QString serial; QString serial;
Info info; Info info;
uint8_t hardwareVersion; uint8_t hardwareVersion;