mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-29 14:52:12 +01:00
Merged in f5soh/librepilot/LP-593_Uploader_firmware_check (pull request #506)
LP-593 Uploader firmware check Approved-by: Lalanne Laurent <f5soh@free.fr> Approved-by: Philippe Renon <philippe_renon@yahoo.fr>
This commit is contained in:
commit
fadfae3d7d
@ -2,7 +2,8 @@
|
||||
******************************************************************************
|
||||
*
|
||||
* @file firmwareiap.c
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2018.
|
||||
* The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief In Application Programming module to support firmware upgrades by
|
||||
* providing a means to enter the bootloader.
|
||||
*
|
||||
@ -47,7 +48,7 @@
|
||||
#define IAP_STATE_STEP_2 2
|
||||
#define IAP_STATE_RESETTING 3
|
||||
|
||||
#define RESET_DELAY 500 /* delay between sending reset ot INS */
|
||||
#define RESET_DELAY 500
|
||||
|
||||
#define TICKS2MS(t) ((t) / portTICK_RATE_MS)
|
||||
#define MS2TICKS(m) ((m) * portTICK_RATE_MS)
|
||||
@ -104,7 +105,7 @@ int32_t FirmwareIAPInitialize()
|
||||
}
|
||||
data.BootloaderRevision = bdinfo->bl_rev;
|
||||
data.ArmReset = 0;
|
||||
data.crc = 0;
|
||||
data.crc = PIOS_BL_HELPER_CRC_Memory_Calc();
|
||||
FirmwareIAPObjSet(&data);
|
||||
if (bdinfo->magic == PIOS_BOARD_INFO_BLOB_MAGIC) {
|
||||
FirmwareIAPObjConnectCallback(&FirmwareIAPCallback);
|
||||
@ -128,7 +129,6 @@ int32_t FirmwareIAPStart()
|
||||
static uint8_t iap_state = IAP_STATE_READY;
|
||||
static void FirmwareIAPCallback(UAVObjEvent *ev)
|
||||
{
|
||||
const struct pios_board_info *bdinfo = &pios_board_info_blob;
|
||||
static uint32_t last_time = 0;
|
||||
uint32_t this_time;
|
||||
uint32_t delta;
|
||||
@ -138,7 +138,6 @@ static void FirmwareIAPCallback(UAVObjEvent *ev)
|
||||
}
|
||||
|
||||
FirmwareIAPObjData data;
|
||||
FirmwareIAPObjGet(&data);
|
||||
|
||||
if (ev->obj == FirmwareIAPObjHandle()) {
|
||||
// Get the input object data
|
||||
@ -146,18 +145,6 @@ static void FirmwareIAPCallback(UAVObjEvent *ev)
|
||||
this_time = get_time();
|
||||
delta = this_time - last_time;
|
||||
last_time = this_time;
|
||||
if ((data.BoardType == bdinfo->board_type) && (data.crc != PIOS_BL_HELPER_CRC_Memory_Calc())) {
|
||||
PIOS_BL_HELPER_FLASH_Read_Description(data.Description, FIRMWAREIAPOBJ_DESCRIPTION_NUMELEM);
|
||||
PIOS_SYS_SerialNumberGetBinary(data.CPUSerial);
|
||||
data.BoardRevision = bdinfo->board_rev;
|
||||
data.BootloaderRevision = bdinfo->bl_rev;
|
||||
data.crc = PIOS_BL_HELPER_CRC_Memory_Calc();
|
||||
FirmwareIAPObjSet(&data);
|
||||
}
|
||||
if ((data.ArmReset == 1) && (iap_state != IAP_STATE_RESETTING)) {
|
||||
data.ArmReset = 0;
|
||||
FirmwareIAPObjSet(&data);
|
||||
}
|
||||
switch (iap_state) {
|
||||
case IAP_STATE_READY:
|
||||
if (data.Command == IAP_CMD_STEP_1) {
|
||||
@ -240,7 +227,7 @@ static uint32_t get_time(void)
|
||||
}
|
||||
|
||||
/**
|
||||
* Executed by event dispatcher callback to reset INS before resetting OP
|
||||
* Executed by event dispatcher callback to reset Board
|
||||
*/
|
||||
static void resetTask(__attribute__((unused)) UAVObjEvent *ev)
|
||||
{
|
||||
@ -252,18 +239,8 @@ static void resetTask(__attribute__((unused)) UAVObjEvent *ev)
|
||||
PIOS_LED_Toggle(PIOS_LED_ALARM);
|
||||
#endif /* PIOS_LED_ALARM */
|
||||
|
||||
FirmwareIAPObjData data;
|
||||
FirmwareIAPObjGet(&data);
|
||||
|
||||
if ((portTickType)(xTaskGetTickCount() - lastResetSysTime) > RESET_DELAY / portTICK_RATE_MS) {
|
||||
lastResetSysTime = xTaskGetTickCount();
|
||||
data.BoardType = 0xFF;
|
||||
data.ArmReset = 1;
|
||||
data.crc = reset_count; /* Must change a value for this to get to INS */
|
||||
FirmwareIAPObjSet(&data);
|
||||
++reset_count;
|
||||
if (reset_count > 3) {
|
||||
PIOS_SYS_Reset();
|
||||
}
|
||||
PIOS_SYS_Reset();
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,10 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file firmwareiap.c
|
||||
* @file firmwareiap.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief Example module to be used as a template for actual modules.
|
||||
* @brief In Application Programming module to support firmware upgrades by
|
||||
* providing a means to enter the bootloader.
|
||||
*
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
*
|
||||
|
@ -26,6 +26,7 @@
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#include "devicewidget.h"
|
||||
#include "version_info/version_info.h"
|
||||
|
||||
#include <QFileDialog>
|
||||
#include <QDebug>
|
||||
@ -216,10 +217,14 @@ bool DeviceWidget::populateBoardStructuredDescription(QByteArray desc)
|
||||
if (UAVObjectUtilManager::descriptionToStructure(desc, onBoardDescription)) {
|
||||
myDevice->lblGitTag->setText(onBoardDescription.gitHash);
|
||||
myDevice->lblBuildDate->setText(onBoardDescription.gitDate.insert(4, "-").insert(7, "-"));
|
||||
if (onBoardDescription.gitTag.startsWith("RELEASE", Qt::CaseSensitive)) {
|
||||
if ((onBoardDescription.gitTag == VersionInfo::tag()) && (onBoardDescription.gitHash == VersionInfo::hash8())) {
|
||||
myDevice->lblDescription->setText(onBoardDescription.gitTag);
|
||||
myDevice->lblCertified->setPixmap(QPixmap(":uploader/images/application-certificate.svg"));
|
||||
myDevice->lblCertified->setToolTip(tr("Tagged officially released firmware build"));
|
||||
} else if ((onBoardDescription.gitTag == VersionInfo::fwTag()) && (onBoardDescription.gitHash == VersionInfo::hash8())) {
|
||||
myDevice->lblDescription->setText(onBoardDescription.gitTag);
|
||||
myDevice->lblCertified->setPixmap(QPixmap(":uploader/images/dialog-apply.svg"));
|
||||
myDevice->lblCertified->setToolTip(tr("Matched firmware build"));
|
||||
} else {
|
||||
myDevice->lblDescription->setText(onBoardDescription.gitTag);
|
||||
myDevice->lblCertified->setPixmap(QPixmap(":uploader/images/warning.svg"));
|
||||
@ -239,11 +244,16 @@ bool DeviceWidget::populateLoadedStructuredDescription(QByteArray desc)
|
||||
if (UAVObjectUtilManager::descriptionToStructure(desc, LoadedDescription)) {
|
||||
myDevice->lblGitTagL->setText(LoadedDescription.gitHash);
|
||||
myDevice->lblBuildDateL->setText(LoadedDescription.gitDate.insert(4, "-").insert(7, "-"));
|
||||
if (LoadedDescription.gitTag.startsWith("RELEASE", Qt::CaseSensitive)) {
|
||||
if ((LoadedDescription.gitTag == VersionInfo::tag()) && (LoadedDescription.gitHash == VersionInfo::hash8())) {
|
||||
myDevice->lblDescritpionL->setText(LoadedDescription.gitTag);
|
||||
myDevice->description->setText(LoadedDescription.gitTag);
|
||||
myDevice->lblCertifiedL->setPixmap(QPixmap(":uploader/images/application-certificate.svg"));
|
||||
myDevice->lblCertifiedL->setToolTip(tr("Tagged officially released firmware build"));
|
||||
} else if ((LoadedDescription.gitTag == VersionInfo::fwTag()) && (LoadedDescription.gitHash == VersionInfo::hash8())) {
|
||||
myDevice->lblDescritpionL->setText(LoadedDescription.gitTag);
|
||||
myDevice->description->setText(LoadedDescription.gitTag);
|
||||
myDevice->lblCertifiedL->setPixmap(QPixmap(":uploader/images/dialog-apply.svg"));
|
||||
myDevice->lblCertifiedL->setToolTip(tr("Matched firmware build"));
|
||||
} else {
|
||||
myDevice->lblDescritpionL->setText(LoadedDescription.gitTag);
|
||||
myDevice->description->setText(LoadedDescription.gitTag);
|
||||
@ -347,7 +357,7 @@ void DeviceWidget::loadFirmware(QString fwfilename)
|
||||
} else if (QDateTime::fromString(onBoardDescription.gitDate) > QDateTime::fromString(LoadedDescription.gitDate)) {
|
||||
myDevice->statusLabel->setText(tr("The board has newer firmware than loaded. Are you sure you want to update?"));
|
||||
px.load(QString(":/uploader/images/warning.svg"));
|
||||
} else if (!LoadedDescription.gitTag.startsWith("RELEASE", Qt::CaseSensitive)) {
|
||||
} else if (!(LoadedDescription.gitTag == VersionInfo::tag()) && (onBoardDescription.gitHash == VersionInfo::hash8())) {
|
||||
myDevice->statusLabel->setText(tr("The loaded firmware is untagged or custom build. Update only if it was received from a trusted source (official website or your own build)."));
|
||||
px.load(QString(":/uploader/images/warning.svg"));
|
||||
} else {
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include "runningdevicewidget.h"
|
||||
#include "devicedescriptorstruct.h"
|
||||
#include "uploadergadgetwidget.h"
|
||||
#include "version_info/version_info.h"
|
||||
|
||||
RunningDeviceWidget::RunningDeviceWidget(QWidget *parent) :
|
||||
QWidget(parent)
|
||||
@ -135,15 +136,41 @@ void RunningDeviceWidget::populate()
|
||||
|
||||
deviceDescriptorStruct devDesc;
|
||||
if (UAVObjectUtilManager::descriptionToStructure(description, devDesc)) {
|
||||
if (devDesc.gitTag.startsWith("RELEASE", Qt::CaseSensitive)) {
|
||||
myDevice->lblFWTag->setText(tr("Firmware tag: ") + devDesc.gitTag);
|
||||
// Convert current QString uavoHashArray stored in GCS to QByteArray
|
||||
QString uavoHash = VersionInfo::uavoHashArray();
|
||||
|
||||
uavoHash.chop(2);
|
||||
uavoHash.remove(0, 2);
|
||||
uavoHash = uavoHash.trimmed();
|
||||
|
||||
QByteArray uavoHashArray;
|
||||
bool ok;
|
||||
foreach(QString str, uavoHash.split(",")) {
|
||||
uavoHashArray.append(str.toInt(&ok, 16));
|
||||
}
|
||||
|
||||
bool isCompatibleUavo = (uavoHashArray == devDesc.uavoHash);
|
||||
bool isTaggedGcs = (VersionInfo::tag() != "");
|
||||
bool isSameCommit = (devDesc.gitHash == VersionInfo::hash8());
|
||||
bool isSameTag = (devDesc.gitTag == VersionInfo::fwTag());
|
||||
|
||||
if (isTaggedGcs && isSameCommit && isSameTag && isCompatibleUavo) {
|
||||
// GCS tagged and firmware from same commit
|
||||
myDevice->lblCertified->setPixmap(QPixmap(":uploader/images/application-certificate.svg"));
|
||||
myDevice->lblCertified->setToolTip(tr("Tagged officially released firmware build"));
|
||||
} else {
|
||||
myDevice->lblFWTag->setText(tr("Firmware tag: ") + devDesc.gitTag);
|
||||
myDevice->lblCertified->setToolTip(tr("Matched firmware build with official tagged release"));
|
||||
} else if (!isTaggedGcs && isSameCommit && isSameTag && isCompatibleUavo) {
|
||||
// GCS untagged and firmware from same commit
|
||||
myDevice->lblCertified->setPixmap(QPixmap(":uploader/images/dialog-apply.svg"));
|
||||
myDevice->lblCertified->setToolTip(tr("Matched firmware build"));
|
||||
} else if ((!isSameCommit || !isSameTag) && isCompatibleUavo) {
|
||||
// firmware not matching current GCS but compatible UAVO
|
||||
myDevice->lblCertified->setPixmap(QPixmap(":uploader/images/warning.svg"));
|
||||
myDevice->lblCertified->setToolTip(tr("Untagged or custom firmware build"));
|
||||
} else {
|
||||
myDevice->lblCertified->setPixmap(QPixmap(":uploader/images/error.svg"));
|
||||
myDevice->lblCertified->setToolTip(tr("Uncompatible firmware build"));
|
||||
}
|
||||
myDevice->lblFWTag->setText(tr("Firmware tag: ") + devDesc.gitTag);
|
||||
myDevice->lblGitCommitTag->setText(tr("Git commit hash: ") + devDesc.gitHash);
|
||||
myDevice->lblFWDate->setText(tr("Firmware date: ") + devDesc.gitDate.insert(4, "-").insert(7, "-"));
|
||||
} else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user