Skip to content

Commit fadfae3

Browse files
f5sohfilnet
authored andcommitted
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>
2 parents 1563033 + bbb0c7f commit fadfae3

4 files changed

Lines changed: 54 additions & 39 deletions

File tree

flight/modules/FirmwareIAP/firmwareiap.c

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
******************************************************************************
33
*
44
* @file firmwareiap.c
5-
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
5+
* @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2018.
6+
* The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
67
* @brief In Application Programming module to support firmware upgrades by
78
* providing a means to enter the bootloader.
89
*
@@ -47,7 +48,7 @@
4748
#define IAP_STATE_STEP_2 2
4849
#define IAP_STATE_RESETTING 3
4950

50-
#define RESET_DELAY 500 /* delay between sending reset ot INS */
51+
#define RESET_DELAY 500
5152

5253
#define TICKS2MS(t) ((t) / portTICK_RATE_MS)
5354
#define MS2TICKS(m) ((m) * portTICK_RATE_MS)
@@ -104,7 +105,7 @@ int32_t FirmwareIAPInitialize()
104105
}
105106
data.BootloaderRevision = bdinfo->bl_rev;
106107
data.ArmReset = 0;
107-
data.crc = 0;
108+
data.crc = PIOS_BL_HELPER_CRC_Memory_Calc();
108109
FirmwareIAPObjSet(&data);
109110
if (bdinfo->magic == PIOS_BOARD_INFO_BLOB_MAGIC) {
110111
FirmwareIAPObjConnectCallback(&FirmwareIAPCallback);
@@ -128,7 +129,6 @@ int32_t FirmwareIAPStart()
128129
static uint8_t iap_state = IAP_STATE_READY;
129130
static void FirmwareIAPCallback(UAVObjEvent *ev)
130131
{
131-
const struct pios_board_info *bdinfo = &pios_board_info_blob;
132132
static uint32_t last_time = 0;
133133
uint32_t this_time;
134134
uint32_t delta;
@@ -138,26 +138,13 @@ static void FirmwareIAPCallback(UAVObjEvent *ev)
138138
}
139139

140140
FirmwareIAPObjData data;
141-
FirmwareIAPObjGet(&data);
142141

143142
if (ev->obj == FirmwareIAPObjHandle()) {
144143
// Get the input object data
145144
FirmwareIAPObjGet(&data);
146145
this_time = get_time();
147146
delta = this_time - last_time;
148147
last_time = this_time;
149-
if ((data.BoardType == bdinfo->board_type) && (data.crc != PIOS_BL_HELPER_CRC_Memory_Calc())) {
150-
PIOS_BL_HELPER_FLASH_Read_Description(data.Description, FIRMWAREIAPOBJ_DESCRIPTION_NUMELEM);
151-
PIOS_SYS_SerialNumberGetBinary(data.CPUSerial);
152-
data.BoardRevision = bdinfo->board_rev;
153-
data.BootloaderRevision = bdinfo->bl_rev;
154-
data.crc = PIOS_BL_HELPER_CRC_Memory_Calc();
155-
FirmwareIAPObjSet(&data);
156-
}
157-
if ((data.ArmReset == 1) && (iap_state != IAP_STATE_RESETTING)) {
158-
data.ArmReset = 0;
159-
FirmwareIAPObjSet(&data);
160-
}
161148
switch (iap_state) {
162149
case IAP_STATE_READY:
163150
if (data.Command == IAP_CMD_STEP_1) {
@@ -240,7 +227,7 @@ static uint32_t get_time(void)
240227
}
241228

242229
/**
243-
* Executed by event dispatcher callback to reset INS before resetting OP
230+
* Executed by event dispatcher callback to reset Board
244231
*/
245232
static void resetTask(__attribute__((unused)) UAVObjEvent *ev)
246233
{
@@ -252,18 +239,8 @@ static void resetTask(__attribute__((unused)) UAVObjEvent *ev)
252239
PIOS_LED_Toggle(PIOS_LED_ALARM);
253240
#endif /* PIOS_LED_ALARM */
254241

255-
FirmwareIAPObjData data;
256-
FirmwareIAPObjGet(&data);
257-
258242
if ((portTickType)(xTaskGetTickCount() - lastResetSysTime) > RESET_DELAY / portTICK_RATE_MS) {
259243
lastResetSysTime = xTaskGetTickCount();
260-
data.BoardType = 0xFF;
261-
data.ArmReset = 1;
262-
data.crc = reset_count; /* Must change a value for this to get to INS */
263-
FirmwareIAPObjSet(&data);
264-
++reset_count;
265-
if (reset_count > 3) {
266-
PIOS_SYS_Reset();
267-
}
244+
PIOS_SYS_Reset();
268245
}
269246
}

flight/modules/FirmwareIAP/inc/firmwareiap.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
/**
22
******************************************************************************
33
*
4-
* @file firmwareiap.c
4+
* @file firmwareiap.h
55
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
6-
* @brief Example module to be used as a template for actual modules.
6+
* @brief In Application Programming module to support firmware upgrades by
7+
* providing a means to enter the bootloader.
78
*
89
* @see The GNU Public License (GPL) Version 3
910
*

ground/gcs/src/plugins/uploader/devicewidget.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2727
*/
2828
#include "devicewidget.h"
29+
#include "version_info/version_info.h"
2930

3031
#include <QFileDialog>
3132
#include <QDebug>
@@ -216,10 +217,14 @@ bool DeviceWidget::populateBoardStructuredDescription(QByteArray desc)
216217
if (UAVObjectUtilManager::descriptionToStructure(desc, onBoardDescription)) {
217218
myDevice->lblGitTag->setText(onBoardDescription.gitHash);
218219
myDevice->lblBuildDate->setText(onBoardDescription.gitDate.insert(4, "-").insert(7, "-"));
219-
if (onBoardDescription.gitTag.startsWith("RELEASE", Qt::CaseSensitive)) {
220+
if ((onBoardDescription.gitTag == VersionInfo::tag()) && (onBoardDescription.gitHash == VersionInfo::hash8())) {
220221
myDevice->lblDescription->setText(onBoardDescription.gitTag);
221222
myDevice->lblCertified->setPixmap(QPixmap(":uploader/images/application-certificate.svg"));
222223
myDevice->lblCertified->setToolTip(tr("Tagged officially released firmware build"));
224+
} else if ((onBoardDescription.gitTag == VersionInfo::fwTag()) && (onBoardDescription.gitHash == VersionInfo::hash8())) {
225+
myDevice->lblDescription->setText(onBoardDescription.gitTag);
226+
myDevice->lblCertified->setPixmap(QPixmap(":uploader/images/dialog-apply.svg"));
227+
myDevice->lblCertified->setToolTip(tr("Matched firmware build"));
223228
} else {
224229
myDevice->lblDescription->setText(onBoardDescription.gitTag);
225230
myDevice->lblCertified->setPixmap(QPixmap(":uploader/images/warning.svg"));
@@ -239,11 +244,16 @@ bool DeviceWidget::populateLoadedStructuredDescription(QByteArray desc)
239244
if (UAVObjectUtilManager::descriptionToStructure(desc, LoadedDescription)) {
240245
myDevice->lblGitTagL->setText(LoadedDescription.gitHash);
241246
myDevice->lblBuildDateL->setText(LoadedDescription.gitDate.insert(4, "-").insert(7, "-"));
242-
if (LoadedDescription.gitTag.startsWith("RELEASE", Qt::CaseSensitive)) {
247+
if ((LoadedDescription.gitTag == VersionInfo::tag()) && (LoadedDescription.gitHash == VersionInfo::hash8())) {
243248
myDevice->lblDescritpionL->setText(LoadedDescription.gitTag);
244249
myDevice->description->setText(LoadedDescription.gitTag);
245250
myDevice->lblCertifiedL->setPixmap(QPixmap(":uploader/images/application-certificate.svg"));
246251
myDevice->lblCertifiedL->setToolTip(tr("Tagged officially released firmware build"));
252+
} else if ((LoadedDescription.gitTag == VersionInfo::fwTag()) && (LoadedDescription.gitHash == VersionInfo::hash8())) {
253+
myDevice->lblDescritpionL->setText(LoadedDescription.gitTag);
254+
myDevice->description->setText(LoadedDescription.gitTag);
255+
myDevice->lblCertifiedL->setPixmap(QPixmap(":uploader/images/dialog-apply.svg"));
256+
myDevice->lblCertifiedL->setToolTip(tr("Matched firmware build"));
247257
} else {
248258
myDevice->lblDescritpionL->setText(LoadedDescription.gitTag);
249259
myDevice->description->setText(LoadedDescription.gitTag);
@@ -347,7 +357,7 @@ void DeviceWidget::loadFirmware(QString fwfilename)
347357
} else if (QDateTime::fromString(onBoardDescription.gitDate) > QDateTime::fromString(LoadedDescription.gitDate)) {
348358
myDevice->statusLabel->setText(tr("The board has newer firmware than loaded. Are you sure you want to update?"));
349359
px.load(QString(":/uploader/images/warning.svg"));
350-
} else if (!LoadedDescription.gitTag.startsWith("RELEASE", Qt::CaseSensitive)) {
360+
} else if (!(LoadedDescription.gitTag == VersionInfo::tag()) && (onBoardDescription.gitHash == VersionInfo::hash8())) {
351361
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)."));
352362
px.load(QString(":/uploader/images/warning.svg"));
353363
} else {

ground/gcs/src/plugins/uploader/runningdevicewidget.cpp

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "runningdevicewidget.h"
2929
#include "devicedescriptorstruct.h"
3030
#include "uploadergadgetwidget.h"
31+
#include "version_info/version_info.h"
3132

3233
RunningDeviceWidget::RunningDeviceWidget(QWidget *parent) :
3334
QWidget(parent)
@@ -135,15 +136,41 @@ void RunningDeviceWidget::populate()
135136

136137
deviceDescriptorStruct devDesc;
137138
if (UAVObjectUtilManager::descriptionToStructure(description, devDesc)) {
138-
if (devDesc.gitTag.startsWith("RELEASE", Qt::CaseSensitive)) {
139-
myDevice->lblFWTag->setText(tr("Firmware tag: ") + devDesc.gitTag);
139+
// Convert current QString uavoHashArray stored in GCS to QByteArray
140+
QString uavoHash = VersionInfo::uavoHashArray();
141+
142+
uavoHash.chop(2);
143+
uavoHash.remove(0, 2);
144+
uavoHash = uavoHash.trimmed();
145+
146+
QByteArray uavoHashArray;
147+
bool ok;
148+
foreach(QString str, uavoHash.split(",")) {
149+
uavoHashArray.append(str.toInt(&ok, 16));
150+
}
151+
152+
bool isCompatibleUavo = (uavoHashArray == devDesc.uavoHash);
153+
bool isTaggedGcs = (VersionInfo::tag() != "");
154+
bool isSameCommit = (devDesc.gitHash == VersionInfo::hash8());
155+
bool isSameTag = (devDesc.gitTag == VersionInfo::fwTag());
156+
157+
if (isTaggedGcs && isSameCommit && isSameTag && isCompatibleUavo) {
158+
// GCS tagged and firmware from same commit
140159
myDevice->lblCertified->setPixmap(QPixmap(":uploader/images/application-certificate.svg"));
141-
myDevice->lblCertified->setToolTip(tr("Tagged officially released firmware build"));
142-
} else {
143-
myDevice->lblFWTag->setText(tr("Firmware tag: ") + devDesc.gitTag);
160+
myDevice->lblCertified->setToolTip(tr("Matched firmware build with official tagged release"));
161+
} else if (!isTaggedGcs && isSameCommit && isSameTag && isCompatibleUavo) {
162+
// GCS untagged and firmware from same commit
163+
myDevice->lblCertified->setPixmap(QPixmap(":uploader/images/dialog-apply.svg"));
164+
myDevice->lblCertified->setToolTip(tr("Matched firmware build"));
165+
} else if ((!isSameCommit || !isSameTag) && isCompatibleUavo) {
166+
// firmware not matching current GCS but compatible UAVO
144167
myDevice->lblCertified->setPixmap(QPixmap(":uploader/images/warning.svg"));
145168
myDevice->lblCertified->setToolTip(tr("Untagged or custom firmware build"));
169+
} else {
170+
myDevice->lblCertified->setPixmap(QPixmap(":uploader/images/error.svg"));
171+
myDevice->lblCertified->setToolTip(tr("Uncompatible firmware build"));
146172
}
173+
myDevice->lblFWTag->setText(tr("Firmware tag: ") + devDesc.gitTag);
147174
myDevice->lblGitCommitTag->setText(tr("Git commit hash: ") + devDesc.gitHash);
148175
myDevice->lblFWDate->setText(tr("Firmware date: ") + devDesc.gitDate.insert(4, "-").insert(7, "-"));
149176
} else {

0 commit comments

Comments
 (0)