From 83811861cc160561ec011643257a0fcc8e63f20c Mon Sep 17 00:00:00 2001 From: Nemanja Nedeljkovic Date: Fri, 11 Aug 2023 18:01:02 +0200 Subject: [PATCH 1/2] Add git version command --- firmware/Makefile.defs | 4 ++++ firmware/application/Makefile | 3 +++ firmware/application/src/app_cmd.c | 8 ++++++++ firmware/application/src/data_cmd.h | 1 + 4 files changed, 16 insertions(+) diff --git a/firmware/Makefile.defs b/firmware/Makefile.defs index 89fec0a..7023b1d 100644 --- a/firmware/Makefile.defs +++ b/firmware/Makefile.defs @@ -22,4 +22,8 @@ LD_DIR := $(SRC_COMMON) CHAMELEON_ULTRA := ultra CHAMELEON_LITE := lite # What device is it? + CURRENT_DEVICE_TYPE ?= ${CHAMELEON_ULTRA} + +# Versioning information +GIT_VERSION := "$(shell git describe --abbrev=7 --dirty --always --tags)" diff --git a/firmware/application/Makefile b/firmware/application/Makefile index f248a1a..9ca868a 100644 --- a/firmware/application/Makefile +++ b/firmware/application/Makefile @@ -311,6 +311,9 @@ CFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16 CFLAGS += -ffunction-sections -fdata-sections -fno-strict-aliasing CFLAGS += -fno-builtin -fshort-enums +# Versioning flags +CFLAGS += -DGIT_VERSION=\"$(GIT_VERSION)\" + # C++ flags common to all targets CXXFLAGS += $(OPT) # Assembler flags common to all targets diff --git a/firmware/application/src/app_cmd.c b/firmware/application/src/app_cmd.c index 2eb7559..c33f50d 100644 --- a/firmware/application/src/app_cmd.c +++ b/firmware/application/src/app_cmd.c @@ -27,6 +27,13 @@ data_frame_tx_t* cmd_processor_get_version(uint16_t cmd, uint16_t status, uint16 return data_frame_make(cmd, status, 2, (uint8_t*)&version); } + +data_frame_tx_t* cmd_processor_get_git_version(uint16_t cmd, uint16_t status, uint16_t length, uint8_t *data) { + uint32_t* version = (uint32_t*)GIT_VERSION; + return data_frame_make(cmd, status, 7, (uint8_t*)version); +} + + data_frame_tx_t* cmd_processor_change_device_mode(uint16_t cmd, uint16_t status, uint16_t length, uint8_t *data) { #if defined(PROJECT_CHAMELEON_ULTRA) if (length == 1) { @@ -524,6 +531,7 @@ static cmd_data_map_t m_data_cmd_map[] = { { DATA_CMD_ENTER_BOOTLOADER, NULL, cmd_processor_enter_bootloader, NULL }, { DATA_CMD_GET_DEVICE_CHIP_ID, NULL, cmd_processor_get_device_chip_id, NULL }, { DATA_CMD_GET_DEVICE_ADDRESS, NULL, cmd_processor_get_device_address, NULL }, + { DATA_CMD_GET_GIT_VERSION, NULL, cmd_processor_get_git_version, NULL }, #if defined(PROJECT_CHAMELEON_ULTRA) diff --git a/firmware/application/src/data_cmd.h b/firmware/application/src/data_cmd.h index e5437ae..9a5e8c8 100644 --- a/firmware/application/src/data_cmd.h +++ b/firmware/application/src/data_cmd.h @@ -20,6 +20,7 @@ #define DATA_CMD_ENTER_BOOTLOADER (1010) #define DATA_CMD_GET_DEVICE_CHIP_ID (1011) #define DATA_CMD_GET_DEVICE_ADDRESS (1012) +#define DATA_CMD_GET_GIT_VERSION (1013) // // ****************************************************************** From ee8990aacd75849b64c1551b8344a4b6f835ab16 Mon Sep 17 00:00:00 2001 From: Augusto Zanellato Date: Fri, 11 Aug 2023 18:55:29 +0200 Subject: [PATCH 2/2] fw git version fixes, client support Fix git version string length handling Add git to docker fw-builder image Add git version command to client Add client support --- firmware/Dockerfile | 3 ++- firmware/application/src/app_cmd.c | 3 +-- software/script/chameleon_cli_main.py | 1 + software/script/chameleon_cli_unit.py | 10 ++++++++++ software/script/chameleon_cmd.py | 6 +++++- 5 files changed, 19 insertions(+), 4 deletions(-) diff --git a/firmware/Dockerfile b/firmware/Dockerfile index bc38922..1646b91 100644 --- a/firmware/Dockerfile +++ b/firmware/Dockerfile @@ -6,7 +6,8 @@ ARG NRF_CLT_URL=https://nsscprodmedia.blob.core.windows.net/prod/software-and-ot RUN set -xe; \ DEBIAN_FRONTEND=noninteractive; \ apt update -q; \ - apt install -qy --no-install-recommends ca-certificates curl xz-utils make; \ + apt install -qy --no-install-recommends ca-certificates curl xz-utils make git; \ + git config --global --add safe.directory /workdir; \ curl -sLo /usr/bin/nrfutil https://developer.nordicsemi.com/.pc-tools/nrfutil/x64-linux/nrfutil; \ curl -sLo /tmp/nrf-clt.deb $NRF_CLT_URL; \ apt install -qfy /tmp/nrf-clt.deb; \ diff --git a/firmware/application/src/app_cmd.c b/firmware/application/src/app_cmd.c index c33f50d..ef48978 100644 --- a/firmware/application/src/app_cmd.c +++ b/firmware/application/src/app_cmd.c @@ -29,8 +29,7 @@ data_frame_tx_t* cmd_processor_get_version(uint16_t cmd, uint16_t status, uint16 data_frame_tx_t* cmd_processor_get_git_version(uint16_t cmd, uint16_t status, uint16_t length, uint8_t *data) { - uint32_t* version = (uint32_t*)GIT_VERSION; - return data_frame_make(cmd, status, 7, (uint8_t*)version); + return data_frame_make(cmd, status, strlen(GIT_VERSION), (uint8_t*)GIT_VERSION); } diff --git a/software/script/chameleon_cli_main.py b/software/script/chameleon_cli_main.py index 83fba87..53289bf 100755 --- a/software/script/chameleon_cli_main.py +++ b/software/script/chameleon_cli_main.py @@ -86,6 +86,7 @@ class ChameleonCLI: 'openall': new_uint(chameleon_cli_unit.HWSlotOpenAll, "Open all slot and set to default data"), 'help': "Emulation tag slot.", }, + 'version': new_uint(chameleon_cli_unit.HWVersion, "Get current device firmware version"), 'dfu': new_uint(chameleon_cli_unit.HWDFU, "Restart application to bootloader mode(Not yet implement dfu)."), 'help': "hardware controller", }, diff --git a/software/script/chameleon_cli_unit.py b/software/script/chameleon_cli_unit.py index 4cb0ded..0a8aabe 100644 --- a/software/script/chameleon_cli_unit.py +++ b/software/script/chameleon_cli_unit.py @@ -253,6 +253,16 @@ class HWAddressGet(DeviceRequiredUnit): def on_exec(self, args: argparse.Namespace): print(f' - Device address: ' + self.cmd_positive.get_device_address()) +class HWVersion(DeviceRequiredUnit): + + def args_parser(self) -> ArgumentParserNoExit or None: + return None + + def on_exec(self, args: argparse.Namespace): + fw_version_int = self.cmd_positive.get_firmware_version() + fw_version = f'v{fw_version_int // 256}.{fw_version_int % 256}' + git_version = self.cmd_positive.get_git_version() + print(f' - Version: {fw_version} ({git_version})') class HF14AScan(ReaderRequiredUint): def args_parser(self) -> ArgumentParserNoExit or None: diff --git a/software/script/chameleon_cmd.py b/software/script/chameleon_cmd.py index 0f793d5..cb32228 100644 --- a/software/script/chameleon_cmd.py +++ b/software/script/chameleon_cmd.py @@ -19,6 +19,7 @@ DATA_CMD_SLOT_DATA_CONFIG_SAVE = 1009 DATA_CMD_ENTER_BOOTLOADER = 1010 DATA_CMD_GET_DEVICE_CHIP_ID = 1011 DATA_CMD_GET_DEVICE_ADDRESS = 1012 +DATA_CMD_GET_GIT_VERSION = 1013 DATA_CMD_SCAN_14A_TAG = 2000 DATA_CMD_MF1_SUPPORT_DETECT = 2001 @@ -108,7 +109,10 @@ class BaseChameleonCMD: """ resp = self.device.send_cmd_sync(DATA_CMD_GET_DEVICE_ADDRESS, 0x00, None) return resp.data[::-1].hex() - + + def get_git_version(self) -> str: + resp = self.device.send_cmd_sync(DATA_CMD_GET_GIT_VERSION, 0x00, None) + return resp.data.decode('utf-8') def is_reader_device_mode(self) -> bool: """