diff --git a/Makefile b/Makefile index 58f849bf7..7388b6767 100644 --- a/Makefile +++ b/Makefile @@ -563,7 +563,7 @@ $$(UAVO_COLLECTION_DIR)/$(1)/uavohash: $$(UAVO_COLLECTION_DIR)/$(1)/uavo-xml # The sed bit truncates the UAVO hash to 16 hex digits $$(V1) $$(VERSION_INFO) \ --uavodir=$$(UAVO_COLLECTION_DIR)/$(1)/uavo-xml/shared/uavobjectdefinition \ - --format='$$$${UAVOSHA1TXT}' | \ + --format='$$$${UAVO_HASH}' | \ $(SED) -e 's|\(................\).*|\1|' > $$@ $$(V0) @$(ECHO) " UAVOHASH $(1) ->" $$$$(cat $$(UAVO_COLLECTION_DIR)/$(1)/uavohash) diff --git a/flight/templates/firmware_info.c.template b/flight/templates/firmware_info.c.template index babc4eff3..4fe8842f3 100644 --- a/flight/templates/firmware_info.c.template +++ b/flight/templates/firmware_info.c.template @@ -30,7 +30,6 @@ /** * We have 100 bytes for the whole description. * - * * Structure is: * 4 bytes: header: "OpFw". * 4 bytes: GIT commit tag (short version of SHA1). @@ -66,6 +65,6 @@ const struct fw_version_info fw_version_blob __attribute__((used)) __attribute__ .board_type = ${BOARD_TYPE}, .board_revision = ${BOARD_REVISION}, .commit_tag_name = "${FWTAG}", - .sha1sum = { ${SHA1} }, - .uavosha1 = { ${UAVOSHA1} }, + .sha1sum = { ${IMAGE_HASH_ARRAY} }, + .uavosha1 = { ${UAVO_HASH_ARRAY} }, }; diff --git a/ground/openpilotgcs/src/libs/version_info/version_info.cpp.template b/ground/openpilotgcs/src/libs/version_info/version_info.cpp.template index 214ad7b3b..6486eb9a3 100644 --- a/ground/openpilotgcs/src/libs/version_info/version_info.cpp.template +++ b/ground/openpilotgcs/src/libs/version_info/version_info.cpp.template @@ -27,22 +27,102 @@ VersionInfo::VersionInfo() { } +QString VersionInfo::origin() +{ + return "${ORIGIN}"; +} + QString VersionInfo::revision() { return "${REVISION}"; } +QString VersionInfo::hash() +{ + return "${HASH}"; +} + +QString VersionInfo::uavoHash() +{ + return "${UAVO_HASH}"; +} + +QString VersionInfo::uavoHashArray() +{ + return "{ ${UAVO_HASH_ARRAY} }"; +} + +QString VersionInfo::label() +{ + return "${LABEL}"; +} + +QString VersionInfo::tag() +{ + return "${TAG}"; +} + +QString VersionInfo::tagOrBranch() +{ + return "${TAG_OR_BRANCH}"; +} + +QString VersionInfo::tagOrHash8() +{ + return "${TAG_OR_HASH8}"; +} + +QString VersionInfo::hash8() +{ + return "${HASH8}"; +} + +QString VersionInfo::fwTag() +{ + return "${FWTAG}"; +} + +QString VersionInfo::unixTime() +{ + return "${UNIXTIME}"; +} + +QString VersionInfo::dateTime() +{ + return "${DATETIME}"; +} + +QString VersionInfo::date() +{ + return "${DATE}"; +} + +QString VersionInfo::day() +{ + return "${DAY}"; +} + +QString VersionInfo::month() +{ + return "${MONTH}"; +} + QString VersionInfo::year() { return "${YEAR}"; } -QString VersionInfo::origin() +QString VersionInfo::hour() { - return "${ORIGIN}"; + return "${HOUR}"; } -QString VersionInfo::uavoHash() +QString VersionInfo::minute() { - return "{ ${UAVOSHA1} }"; + return "${MINUTE}"; +} + +QString VersionInfo::dirty() +{ + return "${DIRTY}"; } diff --git a/ground/openpilotgcs/src/libs/version_info/version_info.h b/ground/openpilotgcs/src/libs/version_info/version_info.h index b517e7307..ede18e81c 100644 --- a/ground/openpilotgcs/src/libs/version_info/version_info.h +++ b/ground/openpilotgcs/src/libs/version_info/version_info.h @@ -27,12 +27,40 @@ #include +/** + * @class VersionInfo + * @brief Library class to provide version info information extracted from a git repository. + * + * Class static members return read-only strings extracted from a git repository at compile time. + * The content is generated by the version-info.py utility using template. + * + * @note If repository or git utility is unavailable, strings can be empty or be "None". + * So do not assume they have some particular format when used, use them as strings only. + * + * More info: http://wiki.openpilot.org/display/Doc/Building+and+Packaging+Overview + */ class VersionInfo { public: - static QString revision(); - static QString year(); static QString origin(); + static QString revision(); + static QString hash(); static QString uavoHash(); + static QString uavoHashArray(); + static QString label(); + static QString tag(); + static QString tagOrBranch(); + static QString tagOrHash8(); + static QString hash8(); + static QString fwTag(); + static QString unixTime(); + static QString dateTime(); + static QString date(); + static QString day(); + static QString month(); + static QString year(); + static QString hour(); + static QString minute(); + static QString dirty(); private: VersionInfo(); }; diff --git a/ground/openpilotgcs/src/plugins/config/configpipxtremewidget.cpp b/ground/openpilotgcs/src/plugins/config/configpipxtremewidget.cpp index 9bbbab0d9..27f0603ac 100644 --- a/ground/openpilotgcs/src/plugins/config/configpipxtremewidget.cpp +++ b/ground/openpilotgcs/src/plugins/config/configpipxtremewidget.cpp @@ -234,15 +234,15 @@ void ConfigPipXtremeWidget::updateStatus(UAVObject *object) UAVObjectField *descField = object->getField("Description"); if (descField) { /* - * This looks like a binary with a description at the end - * 4 bytes: header: "OpFw" - * 4 bytes: git commit hash (short version of SHA1) - * 4 bytes: Unix timestamp of last git commit - * 2 bytes: target platform. Should follow same rule as BOARD_TYPE and BOARD_REVISION in board define files. - * 26 bytes: commit tag if it is there, otherwise "Unreleased". Zero-padded - * ---- 40 bytes limit --- + * This looks like a binary with a description at the end: + * 4 bytes: header: "OpFw". + * 4 bytes: GIT commit tag (short version of SHA1). + * 4 bytes: Unix timestamp of compile time. + * 2 bytes: target platform. Should follow same rule as BOARD_TYPE and BOARD_REVISION in board define files. + * 26 bytes: commit tag if it is there, otherwise branch name. '-dirty' may be added if needed. Zero-padded. * 20 bytes: SHA1 sum of the firmware. - * 40 bytes: free for now. + * 20 bytes: SHA1 sum of the uavo definitions. + * 20 bytes: free for now. */ char buf[OPLinkStatus::DESCRIPTION_NUMELEM]; for (unsigned int i = 0; i < 26; ++i) { diff --git a/ground/openpilotgcs/src/plugins/coreplugin/authorsdialog.cpp b/ground/openpilotgcs/src/plugins/coreplugin/authorsdialog.cpp index 847fb5369..13af48f34 100644 --- a/ground/openpilotgcs/src/plugins/coreplugin/authorsdialog.cpp +++ b/ground/openpilotgcs/src/plugins/coreplugin/authorsdialog.cpp @@ -75,31 +75,10 @@ AuthorsDialog::AuthorsDialog(QWidget *parent) // : This gets conditionally inserted as argument %8 into the description string. ideRev = tr("From revision %1
").arg(VersionInfo::revision().left(10)); - QString uavoHashStr; - if (VersionInfo::uavoHash().length() > 15) { - // : This gets conditionally inserted as argument %11 into the description string. - QByteArray uavoHashArray; - QString uavoHash = VersionInfo::uavoHash(); - uavoHash.chop(2); - uavoHash.remove(0, 2); - uavoHash = uavoHash.trimmed(); - bool ok; - foreach(QString str, uavoHash.split(",")) { - uavoHashArray.append(str.toInt(&ok, 16)); - } - QString gcsUavoHashStr; - foreach(char i, uavoHashArray) { - gcsUavoHashStr.append(QString::number(i, 16).right(2)); - } - uavoHashStr = gcsUavoHashStr; - } else { - uavoHashStr = "N/A"; - } - const QString description = tr( "

OpenPilot Ground Control Station

" "GCS Revision: %1
" - "UAVO Hash: %2
" + "UAVO Hash: %2
" "
" "Built from %3
" "Built on %4 at %5
" @@ -117,7 +96,7 @@ AuthorsDialog::AuthorsDialog(QWidget *parent) "PARTICULAR PURPOSE." ).arg( VersionInfo::revision().left(60), // %1 - uavoHashStr, // %2 + VersionInfo::uavoHash().left(8), // %2 VersionInfo::origin(), // $3 QLatin1String(__DATE__), // %4 QLatin1String(__TIME__), // %5 diff --git a/ground/openpilotgcs/src/plugins/coreplugin/versiondialog.cpp b/ground/openpilotgcs/src/plugins/coreplugin/versiondialog.cpp index 8fb160ef3..cd3e2b192 100644 --- a/ground/openpilotgcs/src/plugins/coreplugin/versiondialog.cpp +++ b/ground/openpilotgcs/src/plugins/coreplugin/versiondialog.cpp @@ -59,31 +59,10 @@ VersionDialog::VersionDialog(QWidget *parent) QGridLayout *layout = new QGridLayout(this); layout->setSizeConstraint(QLayout::SetFixedSize); - QString uavoHashStr; - if (VersionInfo::uavoHash().length() > 15) { - // : This gets conditionally inserted as argument %11 into the description string. - QByteArray uavoHashArray; - QString uavoHash = VersionInfo::uavoHash(); - uavoHash.chop(2); - uavoHash.remove(0, 2); - uavoHash = uavoHash.trimmed(); - bool ok; - foreach(QString str, uavoHash.split(",")) { - uavoHashArray.append(str.toInt(&ok, 16)); - } - QString gcsUavoHashStr; - foreach(char i, uavoHashArray) { - gcsUavoHashStr.append(QString::number(i, 16).right(2)); - } - uavoHashStr = gcsUavoHashStr; - } else { - uavoHashStr = "N/A"; - } - const QString description = tr( "

OpenPilot Ground Control Station

" "GCS Revision: %1
" - "UAVO Hash: %2
" + "UAVO Hash: %2
" "
" "Built from %3
" "Built on %4 at %5
" @@ -101,7 +80,7 @@ VersionDialog::VersionDialog(QWidget *parent) "PARTICULAR PURPOSE." ).arg( VersionInfo::revision().left(60), // %1 - uavoHashStr, // %2 + VersionInfo::uavoHash().left(8), // %2 VersionInfo::origin(), // $3 QLatin1String(__DATE__), // %4 QLatin1String(__TIME__), // %5 diff --git a/ground/openpilotgcs/src/plugins/uavobjectutil/uavobjectutilmanager.cpp b/ground/openpilotgcs/src/plugins/uavobjectutil/uavobjectutilmanager.cpp index c89683412..34133de24 100644 --- a/ground/openpilotgcs/src/plugins/uavobjectutil/uavobjectutilmanager.cpp +++ b/ground/openpilotgcs/src/plugins/uavobjectutil/uavobjectutilmanager.cpp @@ -423,14 +423,14 @@ bool UAVObjectUtilManager::descriptionToStructure(QByteArray desc, deviceDescrip { if (desc.startsWith("OpFw")) { /* - * This looks like a binary with a description at the end - * 4 bytes: header: "OpFw" - * 4 bytes: git commit hash (short version of SHA1) - * 4 bytes: Unix timestamp of last git commit - * 2 bytes: target platform. Should follow same rule as BOARD_TYPE and BOARD_REVISION in board define files. - * 26 bytes: commit tag if it is there, otherwise "Unreleased". Zero-padded + * This looks like a binary with a description at the end: + * 4 bytes: header: "OpFw". + * 4 bytes: GIT commit tag (short version of SHA1). + * 4 bytes: Unix timestamp of compile time. + * 2 bytes: target platform. Should follow same rule as BOARD_TYPE and BOARD_REVISION in board define files. + * 26 bytes: commit tag if it is there, otherwise branch name. '-dirty' may be added if needed. Zero-padded. * 20 bytes: SHA1 sum of the firmware. - * 20 bytes: SHA1 sum of the UAVO definition files. + * 20 bytes: SHA1 sum of the uavo definitions. * 20 bytes: free for now. */ diff --git a/ground/openpilotgcs/src/plugins/uavsettingsimportexport/uavsettingsimportexportfactory.cpp b/ground/openpilotgcs/src/plugins/uavsettingsimportexport/uavsettingsimportexportfactory.cpp index f54317daa..d5b1c7e9a 100644 --- a/ground/openpilotgcs/src/plugins/uavsettingsimportexport/uavsettingsimportexportfactory.cpp +++ b/ground/openpilotgcs/src/plugins/uavsettingsimportexport/uavsettingsimportexportfactory.cpp @@ -241,20 +241,18 @@ QString UAVSettingsImportExportFactory::createXMLDocument(const enum storedData versionInfo.appendChild(hw); QDomElement fw = doc.createElement("firmware"); + QString uavo = board.uavoHash.toHex(); + fw.setAttribute("tag", board.gitTag); fw.setAttribute("date", board.gitDate); fw.setAttribute("hash", board.gitHash); - fw.setAttribute("tag", board.gitTag); + fw.setAttribute("uavo", uavo.left(8)); versionInfo.appendChild(fw); - QString gcsRevision = VersionInfo::revision(); - QString gcsGitDate = gcsRevision.mid(gcsRevision.indexOf(" ") + 1, 14); - QString gcsGitHash = gcsRevision.mid(gcsRevision.indexOf(":") + 1, 8); - QString gcsGitTag = gcsRevision.left(gcsRevision.indexOf(":")); - - QDomElement gcs = doc.createElement("gcs"); - gcs.setAttribute("date", gcsGitDate); - gcs.setAttribute("hash", gcsGitHash); - gcs.setAttribute("tag", gcsGitTag); + QDomElement gcs = doc.createElement("gcs"); + gcs.setAttribute("tag", VersionInfo::tagOrBranch() + VersionInfo::dirty()); + gcs.setAttribute("date", VersionInfo::dateTime()); + gcs.setAttribute("hash", VersionInfo::hash().left(8)); + gcs.setAttribute("uavo", VersionInfo::uavoHash().left(8)); versionInfo.appendChild(gcs); // create settings and/or data elements diff --git a/ground/openpilotgcs/src/plugins/uploader/uploadergadgetwidget.cpp b/ground/openpilotgcs/src/plugins/uploader/uploadergadgetwidget.cpp index 1bdc0e4ef..2b26332c4 100644 --- a/ground/openpilotgcs/src/plugins/uploader/uploadergadgetwidget.cpp +++ b/ground/openpilotgcs/src/plugins/uploader/uploadergadgetwidget.cpp @@ -957,7 +957,7 @@ void UploaderGadgetWidget::versionMatchCheck() UAVObjectUtilManager *utilMngr = pm->getObject(); deviceDescriptorStruct boardDescription = utilMngr->getBoardDescriptionStruct(); QByteArray uavoHashArray; - QString uavoHash = VersionInfo::uavoHash(); + QString uavoHash = VersionInfo::uavoHashArray(); uavoHash.chop(2); uavoHash.remove(0, 2); diff --git a/make/scripts/version-info.py b/make/scripts/version-info.py index 4b9d366f3..79cf95904 100644 --- a/make/scripts/version-info.py +++ b/make/scripts/version-info.py @@ -271,7 +271,7 @@ def xtrim(string, suffix, length): assert n > 0, "length of truncated string+suffix exceeds maximum length" return ''.join([string[:n], '+', suffix]) -def get_hash_of_dirs(directory, verbose = 0, raw = 0): +def get_hash_of_dirs(directory, verbose = 0, raw = 0, n = 40): """Return hash of XML files from UAVObject definition directory""" import hashlib, os SHAhash = hashlib.sha1() @@ -322,7 +322,7 @@ def get_hash_of_dirs(directory, verbose = 0, raw = 0): print 'Final hash is', SHAhash.hexdigest() if raw == 1: - return SHAhash.hexdigest() + return SHAhash.hexdigest()[:n] else: hex_stream = lambda s:",".join(['0x'+hex(ord(c))[2:].zfill(2) for c in s]) return hex_stream(SHAhash.digest()) @@ -417,9 +417,10 @@ string given. MINUTE = r.time('%M'), BOARD_TYPE = args.type, BOARD_REVISION = args.revision, - SHA1 = sha1(args.image), - UAVOSHA1TXT = get_hash_of_dirs(args.uavodir, verbose = 0, raw = 1), - UAVOSHA1 = get_hash_of_dirs(args.uavodir, verbose = 0, raw = 0), + UAVO_HASH = get_hash_of_dirs(args.uavodir, verbose = 0, raw = 1), + UAVO_HASH8 = get_hash_of_dirs(args.uavodir, verbose = 0, raw = 1, n = 8), + UAVO_HASH_ARRAY = get_hash_of_dirs(args.uavodir, verbose = 0, raw = 0), + IMAGE_HASH_ARRAY = sha1(args.image), ) # Process positional arguments in the form of: diff --git a/make/templates/build-info.txt b/make/templates/build-info.txt index ce348b86c..4f9b9d75c 100644 --- a/make/templates/build-info.txt +++ b/make/templates/build-info.txt @@ -15,7 +15,7 @@ ORIGIN='${ORIGIN}' REVISION='${REVISION}' HASH='${HASH}' -UAVOSHA1='${UAVOSHA1TXT}' +UAVO_HASH='${UAVO_HASH}' LABEL='${LABEL}' TAG='${TAG}' TAG_OR_BRANCH='${TAG_OR_BRANCH}'