From 877177ab51320e49cb1ac8632ed7a32c31f27c36 Mon Sep 17 00:00:00 2001 From: Laurent Lalanne Date: Tue, 10 Apr 2018 12:00:35 +0200 Subject: [PATCH 1/3] LP-593 Basic check for firmware, tagged and matched firmware with GCS --- .../gcs/src/plugins/uploader/devicewidget.cpp | 16 ++++++-- .../plugins/uploader/runningdevicewidget.cpp | 37 ++++++++++++++++--- 2 files changed, 45 insertions(+), 8 deletions(-) diff --git a/ground/gcs/src/plugins/uploader/devicewidget.cpp b/ground/gcs/src/plugins/uploader/devicewidget.cpp index e207f4940..0b9587dca 100644 --- a/ground/gcs/src/plugins/uploader/devicewidget.cpp +++ b/ground/gcs/src/plugins/uploader/devicewidget.cpp @@ -26,6 +26,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "devicewidget.h" +#include "version_info/version_info.h" #include #include @@ -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 { diff --git a/ground/gcs/src/plugins/uploader/runningdevicewidget.cpp b/ground/gcs/src/plugins/uploader/runningdevicewidget.cpp index 58372ed18..9d6512e72 100644 --- a/ground/gcs/src/plugins/uploader/runningdevicewidget.cpp +++ b/ground/gcs/src/plugins/uploader/runningdevicewidget.cpp @@ -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 { From 4c83f0a844b4b9ce722168a05e10c40b093132a6 Mon Sep 17 00:00:00 2001 From: Laurent Lalanne Date: Wed, 11 Apr 2018 19:30:46 +0200 Subject: [PATCH 2/3] LP-593 Set firmware Crc at init --- flight/modules/FirmwareIAP/firmwareiap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flight/modules/FirmwareIAP/firmwareiap.c b/flight/modules/FirmwareIAP/firmwareiap.c index f60dea395..60300f4f0 100644 --- a/flight/modules/FirmwareIAP/firmwareiap.c +++ b/flight/modules/FirmwareIAP/firmwareiap.c @@ -104,7 +104,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); From bbb0c7fb253551007e247ac8175d02b3fcf57c48 Mon Sep 17 00:00:00 2001 From: Laurent Lalanne Date: Thu, 12 Apr 2018 14:52:12 +0200 Subject: [PATCH 3/3] LP-593 firmwareIAP cleanup, remove code for old AHRS --- flight/modules/FirmwareIAP/firmwareiap.c | 33 +++----------------- flight/modules/FirmwareIAP/inc/firmwareiap.h | 5 +-- 2 files changed, 8 insertions(+), 30 deletions(-) diff --git a/flight/modules/FirmwareIAP/firmwareiap.c b/flight/modules/FirmwareIAP/firmwareiap.c index 60300f4f0..3164f3281 100644 --- a/flight/modules/FirmwareIAP/firmwareiap.c +++ b/flight/modules/FirmwareIAP/firmwareiap.c @@ -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) @@ -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(); } } diff --git a/flight/modules/FirmwareIAP/inc/firmwareiap.h b/flight/modules/FirmwareIAP/inc/firmwareiap.h index 81c39d880..08841d89c 100644 --- a/flight/modules/FirmwareIAP/inc/firmwareiap.h +++ b/flight/modules/FirmwareIAP/inc/firmwareiap.h @@ -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 *