Skip to content

Commit

Permalink
AP_Bootloader: Add git_sha to the bootloader
Browse files Browse the repository at this point in the history
Allows for reading of the git sha from the bootloader to ascertain the sha the bootloader is built at
  • Loading branch information
joshanne committed Oct 31, 2024
1 parent be5c68d commit 50f1dd7
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 9 deletions.
7 changes: 6 additions & 1 deletion Tools/AP_Bootloader/AP_Bootloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
#include <AP_CheckFirmware/AP_CheckFirmware.h>
#include "network.h"

#define FORCE_VERSION_H_INCLUDE
#include "ap_version.h"
#undef FORCE_VERSION_H_INCLUDE

extern "C" {
int main(void);
}
Expand All @@ -47,7 +51,8 @@ struct boardinfo board_info = {
.board_type = APJ_BOARD_ID,
.board_rev = 0,
.fw_size = (BOARD_FLASH_SIZE - (FLASH_BOOTLOADER_LOAD_KB + FLASH_RESERVE_END_KB + APP_START_OFFSET_KB))*1024,
.extf_size = (EXT_FLASH_SIZE_MB * 1024 * 1024) - (EXT_FLASH_RESERVE_START_KB + EXT_FLASH_RESERVE_END_KB) * 1024
.extf_size = (EXT_FLASH_SIZE_MB * 1024 * 1024) - (EXT_FLASH_RESERVE_START_KB + EXT_FLASH_RESERVE_END_KB) * 1024,
.git_hash = GIT_VERSION_INT
};

#ifndef HAL_BOOTLOADER_TIMEOUT
Expand Down
34 changes: 26 additions & 8 deletions Tools/AP_Bootloader/bl_protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
// RESET finalise flash programming, reset chip and starts application
//

#define BL_PROTOCOL_VERSION 5 // The revision of the bootloader protocol
#define BL_PROTOCOL_VERSION 6 // The revision of the bootloader protocol
// protocol bytes
#define PROTO_INSYNC 0x12 // 'in sync' byte sent before status
#define PROTO_EOC 0x20 // end of command
Expand Down Expand Up @@ -122,14 +122,28 @@
#define PROTO_READ_MULTI_MAX 255 // size of the size field

/* argument values for PROTO_GET_DEVICE */
#define PROTO_DEVICE_BL_REV 1 // bootloader revision
#define PROTO_DEVICE_BOARD_ID 2 // board ID
#define PROTO_DEVICE_BOARD_REV 3 // board revision
#define PROTO_DEVICE_FW_SIZE 4 // size of flashable area
#define PROTO_DEVICE_VEC_AREA 5 // contents of reserved vectors 7-10
#define PROTO_DEVICE_EXTF_SIZE 6 // size of available external flash
#define PROTO_DEVICE_BL_REV 1 // bootloader revision
#define PROTO_DEVICE_BOARD_ID 2 // board ID
#define PROTO_DEVICE_BOARD_REV 3 // board revision
#define PROTO_DEVICE_FW_SIZE 4 // size of flashable area
#define PROTO_DEVICE_VEC_AREA 5 // contents of reserved vectors 7-10
#define PROTO_DEVICE_EXTF_SIZE 6 // size of available external flash
#define PROTO_DEVICE_BL_GIT_HASH 7 // git hash of bootloader build (requires > v5)

// all except PROTO_DEVICE_VEC_AREA and PROTO_DEVICE_BOARD_REV should be done
#define CHECK_GET_DEVICE_FINISHED(x) ((x & (0xB)) == 0xB)

// Convert the Device Info to a bitmask
#define REQUIRE_DEVICE_INFO(x) (1<<(x-1))

// Define the required device info as a mask
#define REQUIRED_DEVICE_INFO_MASK ( \
REQUIRE_DEVICE_INFO(PROTO_DEVICE_BL_REV) \
| REQUIRE_DEVICE_INFO(PROTO_DEVICE_BOARD_ID) \
| REQUIRE_DEVICE_INFO(PROTO_DEVICE_FW_SIZE) \
)

// Checks whether all required device info has been obtained
#define CHECK_GET_DEVICE_FINISHED(x) ((x & (REQUIRED_DEVICE_INFO_MASK)) == REQUIRED_DEVICE_INFO_MASK)

// interrupt vector table for STM32
#define SCB_VTOR 0xE000ED08
Expand Down Expand Up @@ -602,6 +616,10 @@ bootloader(unsigned timeout)
case PROTO_DEVICE_EXTF_SIZE:
cout((uint8_t *)&board_info.extf_size, sizeof(board_info.extf_size));
break;

case PROTO_DEVICE_BL_GIT_HASH:
cout((uint8_t *)&board_info.git_hash, sizeof(board_info.git_hash));
break;

default:
goto cmd_bad;
Expand Down
1 change: 1 addition & 0 deletions Tools/AP_Bootloader/support.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ struct boardinfo {
uint32_t board_rev;
uint32_t fw_size;
uint32_t extf_size;
uint32_t git_hash;
} __attribute__((packed));

extern struct boardinfo board_info;
Expand Down
18 changes: 18 additions & 0 deletions Tools/AP_Bootloader/wscript
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ def build(bld):
else:
flashiface_lib = []

_build_dynamic_sources(bld)

bld.ap_stlib(
name= 'AP_Bootloader_libs',
use='dronecan',
Expand All @@ -34,3 +36,19 @@ def build(bld):
use=['AP_Bootloader_libs', 'libcanard', 'dronecan'],
program_groups='bootloader'
)

def _build_dynamic_sources(bld):
def write_version_header(tsk):
bld = tsk.generator.bld
return bld.write_version_header(tsk.outputs[0].abspath())

bld(
name='ap_version',
target='ap_version.h',
vars=['AP_VERSION_ITEMS'],
rule=write_version_header,
)

bld.env.prepend_value('INCLUDES', [
bld.bldnode.abspath(),
])

0 comments on commit 50f1dd7

Please sign in to comment.