From 82f4ec8778257e0ef0b2fd60411fa1e38b08b9f2 Mon Sep 17 00:00:00 2001 From: lihuanhuan Date: Fri, 6 Dec 2024 14:47:12 +0800 Subject: [PATCH] Add version number to the firmware header. && bump version to 2.3.3 (#52) * Add version number to the firmware header. * bump firmware version to 2.3.3 --- app/firmware_config.h | 2 +- utils/ota_to_onekey_bin.py | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/app/firmware_config.h b/app/firmware_config.h index 97c18b9..75ffce9 100644 --- a/app/firmware_config.h +++ b/app/firmware_config.h @@ -11,7 +11,7 @@ 0xEEBBEE /**< DUMMY Organisation Unique ID. Will be passed to Device Information Service. You shall use the \ Organisation Unique ID relevant for your Company */ #define HW_REVISION "1.0.0" -#define FW_REVISION "2.3.2" +#define FW_REVISION "2.3.3" #define SW_REVISION "s132_nrf52_7.0.1" #define BT_REVISION "1.0.1" diff --git a/utils/ota_to_onekey_bin.py b/utils/ota_to_onekey_bin.py index a8c9d48..3c73296 100755 --- a/utils/ota_to_onekey_bin.py +++ b/utils/ota_to_onekey_bin.py @@ -5,6 +5,7 @@ import struct import zipfile import click +import re # input_file = "../artifacts_signed/ota.zip" # output_file = "../artifacts_signed/ota.bin" @@ -12,6 +13,9 @@ INIT_DATA_SIZE = 512 OFFSET_MAGIC = 0x00 +OFFSET_VERSION_MAJOR = 0x10 +OFFSET_VERSION_MINOR = 0x11 +OFFSET_VERSION_PATCH = 0x12 OFFSET_HASHES = 0x20 OFFSET_NRF_DAT_SIZE = 0x400 OFFSET_NRF_DAT = 0x404 @@ -50,11 +54,34 @@ def gen_hashes(data: bytes) -> bytes: return hashes def gen_onekey_bin(nrf_dat: bytes, nrf_bin: bytes) -> bytes: + + header_file = "../app/firmware_config.h" + + with open(header_file, "r") as file: + content = file.read() + + match = re.search(r'#define\s+FW_REVISION\s+"([^"]+)"', content) + + major = 0 + minor = 0 + patch = 0 + + if match: + version_string = match.group(1) + major, minor, patch = map(int, version_string.split('.')) + buffer = io.BytesIO() buffer.seek(OFFSET_MAGIC, 0) buffer.write(b"5283") + buffer.seek(OFFSET_VERSION_MAJOR, 0) + buffer.write(struct.pack("B", major)) + buffer.seek(OFFSET_VERSION_MINOR, 0) + buffer.write(struct.pack("B", minor)) + buffer.seek(OFFSET_VERSION_PATCH, 0) + buffer.write(struct.pack("B", patch)) + buffer.seek(OFFSET_NRF_DAT_SIZE, 0) buffer.write(struct.pack("i", len(nrf_dat))) buffer.seek(OFFSET_NRF_DAT, 0)