diff --git a/libraries/AP_CheckFirmware/AP_CheckFirmware.cpp b/libraries/AP_CheckFirmware/AP_CheckFirmware.cpp index 9e1deece6e5050..0939333e62436e 100644 --- a/libraries/AP_CheckFirmware/AP_CheckFirmware.cpp +++ b/libraries/AP_CheckFirmware/AP_CheckFirmware.cpp @@ -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 diff --git a/libraries/AP_CheckFirmware/AP_CheckFirmware.h b/libraries/AP_CheckFirmware/AP_CheckFirmware.h index a9812a20e33eb7..deffec6a1e6375 100644 --- a/libraries/AP_CheckFirmware/AP_CheckFirmware.h +++ b/libraries/AP_CheckFirmware/AP_CheckFirmware.h @@ -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; diff --git a/libraries/AP_CheckFirmware/AP_CheckFirmwareDefine.h b/libraries/AP_CheckFirmware/AP_CheckFirmwareDefine.h new file mode 100644 index 00000000000000..0daf7733a5b8d0 --- /dev/null +++ b/libraries/AP_CheckFirmware/AP_CheckFirmwareDefine.h @@ -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 \ No newline at end of file