Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow retrieval of bootloader's git hash from bootloader #14768

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions Tools/AP_Bootloader/bl_protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,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 All @@ -105,6 +105,7 @@
#define PROTO_BOOT 0x30 // boot the application
#define PROTO_DEBUG 0x31 // emit debug information - format not defined
#define PROTO_SET_BAUD 0x33 // baud rate on uart
#define PROTO_GET_GIT_HASH 0x34 // read git hash

#define PROTO_PROG_MULTI_MAX 64 // maximum PROG_MULTI size
#define PROTO_READ_MULTI_MAX 255 // size of the size field
Expand All @@ -119,6 +120,13 @@
// interrupt vector table for STM32
#define SCB_VTOR 0xE000ED08

// git hash this binary was compiled from
#ifndef BOOTLOADER_GIT_HASH
#define BOOTLOADER_GIT_HASH 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19
#endif

uint8_t git_hash[20] { BOOTLOADER_GIT_HASH };

static virtual_timer_t systick_vt;

/*
Expand Down Expand Up @@ -930,7 +938,20 @@ bootloader(unsigned timeout)
// returning the response...
continue;
}

// read the git hash of the code the bootloader was compiled from
//
// command: GET_GIT_HASH/EOC
// reply: <value:20>/INSYNC/OK
case PROTO_GET_GIT_HASH: {
// expect EOC
if (!wait_for_eoc(2)) {
goto cmd_bad;
}

cout(git_hash, 20);
}
break;

default:
continue;
}
Expand Down
22 changes: 22 additions & 0 deletions Tools/scripts/uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ class uploader(object):

REBOOT = b'\x30'
SET_BAUD = b'\x33' # set baud
GIT_GIT_HASH = b'\x34' # get git hash of bootloader

INFO_BL_REV = b'\x01' # bootloader protocol revision
BL_REV_MIN = 2 # minimum supported bootloader protocol
Expand Down Expand Up @@ -564,6 +565,21 @@ def __setbaud(self, baud):
uploader.EOC)
self.__getSync()

# send the GET_CHIP command
def __getGitHash(self):
if self.bl_rev < 6:
return None
self.__send(uploader.GET_GIT_HASH + uploader.EOC)
length = self.__recv_int()
value = self.__recv(length)
self.__getSync()
# turn it back into a string
chars = ""
for i in range(0, length):
chars += chr(value[i] >> 4)
chars += chr(value[i] & 0x0f)
return chars

# get basic data about the board
def identify(self):
# make sure we are in sync before starting
Expand Down Expand Up @@ -671,6 +687,12 @@ def dump_board_info(self):
else:
print(" [unavailable; bootloader too old]")

if self.bl_rev >= 6:
h = self.__getGitHash()
if h is not None:
h = "[unavailable]"
print("BL Git hash: %s" % str(h))

print("Info:")
print(" flash size: %u" % self.fw_maxsize)
name = self.board_name_for_board_id(self.board_type)
Expand Down