1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-12-02 10:24:11 +01:00

Now check board model and SHA1 hash of the file when uploading a packaged firmware.

This commit is contained in:
elafargue 2011-05-08 21:22:00 +02:00
parent 4af0c562e3
commit 4d58967e49
2 changed files with 24 additions and 1 deletions

View File

@ -261,12 +261,34 @@ void deviceWidget::uploadFirmware()
QByteArray desc = arr.right(100);
if (populateStructuredDescription(desc)) {
descriptionArray = desc;
// Now do sanity checking:
// - Check whether board type matches firmware:
int board = m_dfu->devices[deviceID].ID;
int firmwareBoard = ((desc.at(12)&0xff)<<8) + (desc.at(13)&0xff);
if (firmwareBoard != board) {
status("Error: firmware does not match board", STATUSICON_FAIL);
return;
}
// Check the firmware embedded in the file:
QByteArray firmwareHash = desc.mid(40,20);
QByteArray fileHash = QCryptographicHash::hash(arr.left(arr.length()-100), QCryptographicHash::Sha1);
if (firmwareHash != fileHash) {
status("Error: firmware file corrupt", STATUSICON_FAIL);
return;
}
} else {
// TODO : tell the user that the firmware is not packaged.
// The firmware is not packaged, just upload the text in the description field
// if it is there.
descriptionArray.clear();
}
status("Starting firmware upload", STATUSICON_RUNNING);
// We don't know which device was used previously, so we
// are cautious and reenter DFU for this deviceID:

View File

@ -37,6 +37,7 @@
#include <QByteArray>
#include <QtSvg/QGraphicsSvgItem>
#include <QtSvg/QSvgRenderer>
#include <QCryptographicHash>
using namespace OP_DFU;