From 4a1532ef24e2e54de37737d3845ab67a325716e1 Mon Sep 17 00:00:00 2001 From: Eric Callahan Date: Tue, 6 Aug 2024 10:47:33 -0400 Subject: [PATCH] flashcmd: add support for reporting software version Signed-off-by: Eric Callahan --- protocol.md | 6 ++++-- scripts/flashtool.py | 21 +++++++++++++++------ scripts/make-version.sh | 12 ++++++++++++ src/Kconfig | 6 +++++- src/command.h | 2 +- src/flashcmd.c | 9 +++++++-- 6 files changed, 44 insertions(+), 12 deletions(-) create mode 100755 scripts/make-version.sh diff --git a/protocol.md b/protocol.md index 863156c..9681366 100644 --- a/protocol.md +++ b/protocol.md @@ -34,11 +34,11 @@ Initiates communication with the bootloader. This command has no payload: <0x01><0x88><0x11><0x00><0x99><0x03> ``` -Responds with [acknowledged](#acknowledged-0xa0) containing a 16 byte payload +Responds with [acknowledged](#acknowledged-0xa0) containing a variable length payload in the following format: ``` -<4 byte orig_command><4 byte protocol_version><4 byte start_address><4 byte block_size> +<4 byte orig_command><4 byte protocol_version><4 byte start_address><4 byte block_size><1 null byte> ``` - `orig_command` - must be `0x11` @@ -51,6 +51,8 @@ in the following format: - `block_size` - the size of a block (in bytes) expected in the `send block` and `request block` commands. Typically this should be 64 bytes. - `mcu_type_string` - The type of micro-controller (eg, "stm32f103xe"). +- `software_version_string` - The software version as reported by + `git describe --tags --always --long --dirty`. #### Send Block: `0x12` diff --git a/scripts/flashtool.py b/scripts/flashtool.py index 8f043f7..7b2f76d 100755 --- a/scripts/flashtool.py +++ b/scripts/flashtool.py @@ -89,17 +89,26 @@ class CanFlasher: output_line("Attempting to connect to bootloader") ret = await self.send_command('CONNECT') pinfo = ret[:12] - mcu_type = ret[12:] + mcu_info = ret[12:] + ver_bytes: bytes ver_bytes, start_addr, self.block_size = struct.unpack("<4sII", pinfo) self.app_start_addr = start_addr - proto_version = ".".join([str(v) for v in reversed(ver_bytes[:3])]) + self.software_version = "?" + self.proto_version = tuple([v for v in reversed(ver_bytes[:3])]) + proto_version_str = ".".join([str(v) for v in self.proto_version]) if self.block_size not in [64, 128, 256, 512]: raise FlashError("Invalid Block Size: %d" % (self.block_size,)) - while mcu_type and mcu_type[-1] == 0x00: - mcu_type = mcu_type[:-1] - mcu_type = mcu_type.decode() + mcu_info.rstrip(b"\x00") + if self.proto_version >= (1, 1, 0): + mcu_bytes, sv_bytes = mcu_info.split(b"\x00", maxsplit=1) + mcu_type = mcu_bytes.decode() + self.software_version = sv_bytes.decode() + else: + mcu_type = mcu_info.decode() output_line( - f"Katapult Connected\nProtocol Version: {proto_version}\n" + f"Katapult Connected\n" + f"Software Version: {self.software_version}\n" + f"Protocol Version: {proto_version_str}\n" f"Block Size: {self.block_size} bytes\n" f"Application Start: 0x{self.app_start_addr:4X}\n" f"MCU type: {mcu_type}" diff --git a/scripts/make-version.sh b/scripts/make-version.sh new file mode 100755 index 0000000..ba57239 --- /dev/null +++ b/scripts/make-version.sh @@ -0,0 +1,12 @@ +#!/bin/sh +# Detect the version of Katapult + +a="/$0"; a="${a%/*}"; a="${a:-.}"; a="${a##/}/"; SRCDIR=$(cd "$a/.."; pwd) + +if [ -e "${SRCDIR}/.git" ]; then + git describe --tags --long --always --dirty +elif [ -f "${SRCDIR}/.version" ]; then + cat "${SRCDIR}/.version" +else + echo "?" +fi diff --git a/src/Kconfig b/src/Kconfig index 390fb04..ceaf6c8 100644 --- a/src/Kconfig +++ b/src/Kconfig @@ -1,6 +1,6 @@ # Main Kconfig settings -VERSION := $(shell, git describe --tags --long --always --dirty 2> /dev/null) +VERSION := $(shell, ./scripts/make-version.sh 2> /dev/null) mainmenu "Katapult Configuration $(VERSION)" @@ -120,3 +120,7 @@ config BUILD_DEPLOYER config HAVE_CHIPID bool default n + +config KATAPULT_VERSION + string + default "$(VERSION)" diff --git a/src/command.h b/src/command.h index c2083e3..d56cd0b 100644 --- a/src/command.h +++ b/src/command.h @@ -23,7 +23,7 @@ #define shutdown(msg) do { } while (1) #define try_shutdown(msg) do { } while (0) -#define PROTO_VERSION 0x00010000 // Version 1.0.0 +#define PROTO_VERSION 0x00010100 // Version 1.1.0 #define CMD_CONNECT 0x11 #define CMD_RX_BLOCK 0x12 #define CMD_RX_EOF 0x13 diff --git a/src/flashcmd.c b/src/flashcmd.c index 5aff334..58578de 100644 --- a/src/flashcmd.c +++ b/src/flashcmd.c @@ -19,12 +19,17 @@ void command_connect(uint32_t *data) { uint32_t mcuwords = DIV_ROUND_UP(strlen(CONFIG_MCU), 4); - uint32_t out[6 + mcuwords]; - memset(out, 0, (6 + mcuwords) * 4); + uint32_t version_words = DIV_ROUND_UP(strlen(CONFIG_KATAPULT_VERSION), 4); + uint32_t out[7 + mcuwords + version_words]; + memset(out, 0, (7 + mcuwords + version_words) * 4); out[2] = cpu_to_le32(PROTO_VERSION); out[3] = cpu_to_le32(CONFIG_LAUNCH_APP_ADDRESS); out[4] = cpu_to_le32(CONFIG_BLOCK_SIZE); memcpy(&out[5], CONFIG_MCU, strlen(CONFIG_MCU)); + memcpy( + &out[6 + mcuwords], CONFIG_KATAPULT_VERSION, + strlen(CONFIG_KATAPULT_VERSION) + ); command_respond_ack(CMD_CONNECT, out, ARRAY_SIZE(out)); }