Skip to content

Commit

Permalink
AP_CheckFirmware: add separate AP_CheckFirmwareDefine for correctly s…
Browse files Browse the repository at this point in the history
…etting firmware versions
  • Loading branch information
bugobliterator committed Feb 8, 2024
1 parent db84c27 commit 065eb53
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 29 deletions.
9 changes: 0 additions & 9 deletions libraries/AP_CheckFirmware/AP_CheckFirmware.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,16 +208,7 @@ check_fw_result_t check_good_firmware(void)

#if !defined(HAL_BOOTLOADER_BUILD)
extern const AP_HAL::HAL &hal;

/*
declare constant app_descriptor in flash
*/
extern const app_descriptor_t app_descriptor;
#if CONFIG_HAL_BOARD == HAL_BOARD_CHIBIOS
const app_descriptor_t app_descriptor __attribute__((section(".app_descriptor")));
#else
const app_descriptor_t app_descriptor;
#endif

/*
this is needed to ensure we don't elide the app_descriptor
Expand Down
40 changes: 20 additions & 20 deletions libraries/AP_CheckFirmware/AP_CheckFirmware.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,45 +57,45 @@ enum class check_fw_result_t : uint8_t {
#define AP_APP_DESCRIPTOR_SIGNATURE_UNSIGNED { 0x40, 0xa2, 0xe4, 0xf1, 0x64, 0x68, 0x91, 0x06 }

struct app_descriptor_unsigned {
uint8_t sig[8] = AP_APP_DESCRIPTOR_SIGNATURE_UNSIGNED;
uint8_t sig[8];
// crc1 is the crc32 from firmware start to start of image_crc1
uint32_t image_crc1 = 0;
uint32_t image_crc1;
// crc2 is the crc32 from the start of version_major to the end of the firmware
uint32_t image_crc2 = 0;
uint32_t image_crc2;
// total size of firmware image in bytes
uint32_t image_size = 0;
uint32_t git_hash = 0;
uint32_t image_size;
uint32_t git_hash;

// software version number
uint8_t version_major = APP_FW_MAJOR;
uint8_t version_minor = APP_FW_MINOR;
uint8_t version_major;
uint8_t version_minor;
// APJ_BOARD_ID (hardware version). This is also used in CAN NodeInfo
// with high byte in HardwareVersion.major and low byte in HardwareVersion.minor
uint16_t board_id = APJ_BOARD_ID;
uint8_t reserved[8] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
uint16_t board_id;
uint8_t reserved[8];
};

struct app_descriptor_signed {
uint8_t sig[8] = AP_APP_DESCRIPTOR_SIGNATURE_SIGNED;
uint8_t sig[8];
// crc1 is the crc32 from firmware start to start of image_crc1
uint32_t image_crc1 = 0;
uint32_t image_crc1;
// crc2 is the crc32 from the start of version_major to the end of the firmware
uint32_t image_crc2 = 0;
uint32_t image_crc2;
// total size of firmware image in bytes
uint32_t image_size = 0;
uint32_t git_hash = 0;
uint32_t image_size;
uint32_t git_hash;

// firmware signature
uint32_t signature_length = 0;
uint8_t signature[72] = {};
uint32_t signature_length;
uint8_t signature[72];

// software version number
uint8_t version_major = APP_FW_MAJOR;
uint8_t version_minor = APP_FW_MINOR;
uint8_t version_major;
uint8_t version_minor;
// APJ_BOARD_ID (hardware version). This is also used in CAN NodeInfo
// with high byte in HardwareVersion.major and low byte in HardwareVersion.minor
uint16_t board_id = APJ_BOARD_ID;
uint8_t reserved[8] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
uint16_t board_id;
uint8_t reserved[8];
};

extern const struct app_descriptor_signed *signed_app_descriptor;
Expand Down
44 changes: 44 additions & 0 deletions libraries/AP_CheckFirmware/AP_CheckFirmwareDefine.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#ifndef FORCE_VERSION_H_INCLUDE
#error AP_CheckFirmwareDefines.h should never be included directly. You probably want to include AP_Common/AP_FWVersion.h
#endif
#include "AP_CheckFirmware.h"

#if AP_CHECK_FIRMWARE_ENABLED
/*
declare constant app_descriptor in flash
*/
#if CONFIG_HAL_BOARD == HAL_BOARD_CHIBIOS
extern const app_descriptor_t app_descriptor;
const app_descriptor_t app_descriptor __attribute__((section(".app_descriptor"))) = {
.sig = AP_APP_DESCRIPTOR_SIGNATURE_UNSIGNED,
.image_crc1 = 0,
.image_crc2 = 0,
.image_size = 0,
.git_hash = 0,
#if AP_SIGNED_FIRMWARE
.signature_length = 0,
.signature = {},
#endif
.version_major = APP_FW_MAJOR,
.version_minor = APP_FW_MINOR,
.board_id = APJ_BOARD_ID,
.reserved = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }
};
#else
const app_descriptor_t app_descriptor = {
.sig = AP_APP_DESCRIPTOR_SIGNATURE_UNSIGNED,
.image_crc1 = 0,
.image_crc2 = 0,
.image_size = 0,
.git_hash = 0,
#if AP_SIGNED_FIRMWARE
.signature_length = 0,
.signature = {},
#endif
.version_major = APP_FW_MAJOR,
.version_minor = APP_FW_MINOR,
.board_id = APJ_BOARD_ID,
.reserved = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }
};
#endif
#endif

0 comments on commit 065eb53

Please sign in to comment.