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 29, 2024
1 parent a6f00a3 commit 4367132
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 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
7 changes: 6 additions & 1 deletion 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 @@ -128,6 +128,7 @@
#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
// all except PROTO_DEVICE_VEC_AREA and PROTO_DEVICE_BOARD_REV should be done
#define CHECK_GET_DEVICE_FINISHED(x) ((x & (0xB)) == 0xB)

Expand Down Expand Up @@ -602,6 +603,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 4367132

Please sign in to comment.