diff --git a/core/.changelog.d/1620.fixed b/core/.changelog.d/1620.fixed new file mode 100644 index 000000000..a9700add1 --- /dev/null +++ b/core/.changelog.d/1620.fixed @@ -0,0 +1 @@ +Unify Features.revision reporting with legacy diff --git a/core/Makefile b/core/Makefile index e78fdba4c..97ef9ab57 100644 --- a/core/Makefile +++ b/core/Makefile @@ -42,8 +42,7 @@ FIRMWARE_P1_MAXSIZE = 786432 FIRMWARE_P2_MAXSIZE = 917504 FIRMWARE_MAXSIZE = 1703936 -GITREV=$(shell git describe --always --dirty | tr '-' '_') -CFLAGS += -DGITREV=$(GITREV) +CFLAGS += -DSCM_REVISION='\"$(shell git rev-parse HEAD | sed 's:\(..\):\\x\1:g')\"' TESTPATH = $(CURDIR)/../tests diff --git a/core/embed/extmod/modtrezorutils/modtrezorutils.c b/core/embed/extmod/modtrezorutils/modtrezorutils.c index 421e6ca73..c76165709 100644 --- a/core/embed/extmod/modtrezorutils/modtrezorutils.c +++ b/core/embed/extmod/modtrezorutils/modtrezorutils.c @@ -17,6 +17,7 @@ * along with this program. If not, see . */ +#include "py/objstr.h" #include "py/runtime.h" #include "version.h" @@ -115,10 +116,13 @@ STATIC mp_obj_t mod_trezorutils_halt(size_t n_args, const mp_obj_t *args) { STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorutils_halt_obj, 0, 1, mod_trezorutils_halt); +STATIC mp_obj_str_t mod_trezorutils_revision_obj = { + {&mp_type_bytes}, 0, sizeof(SCM_REVISION) - 1, (const byte *)SCM_REVISION}; + #define PASTER(s) MP_QSTR_##s #define MP_QSTR(s) PASTER(s) -/// GITREV: str +/// SCM_REVISION: bytes /// VERSION_MAJOR: int /// VERSION_MINOR: int /// VERSION_PATCH: int @@ -132,7 +136,8 @@ STATIC const mp_rom_map_elem_t mp_module_trezorutils_globals_table[] = { {MP_ROM_QSTR(MP_QSTR_memcpy), MP_ROM_PTR(&mod_trezorutils_memcpy_obj)}, {MP_ROM_QSTR(MP_QSTR_halt), MP_ROM_PTR(&mod_trezorutils_halt_obj)}, // various built-in constants - {MP_ROM_QSTR(MP_QSTR_GITREV), MP_ROM_QSTR(MP_QSTR(GITREV))}, + {MP_ROM_QSTR(MP_QSTR_SCM_REVISION), + MP_ROM_PTR(&mod_trezorutils_revision_obj)}, {MP_ROM_QSTR(MP_QSTR_VERSION_MAJOR), MP_ROM_INT(VERSION_MAJOR)}, {MP_ROM_QSTR(MP_QSTR_VERSION_MINOR), MP_ROM_INT(VERSION_MINOR)}, {MP_ROM_QSTR(MP_QSTR_VERSION_PATCH), MP_ROM_INT(VERSION_PATCH)}, diff --git a/core/embed/trezorhal/common.c b/core/embed/trezorhal/common.c index cf20f07cc..55f9f9005 100644 --- a/core/embed/trezorhal/common.c +++ b/core/embed/trezorhal/common.c @@ -52,8 +52,10 @@ __fatal_error(const char *expr, const char *msg, const char *file, int line, if (func) { display_printf("func: %s\n", func); } -#ifdef GITREV - display_printf("rev : %s\n", XSTR(GITREV)); +#ifdef SCM_REVISION + const uint8_t *rev = (const uint8_t *)SCM_REVISION; + display_printf("rev : %02x%02x%02x%02x%02x\n", rev[0], rev[1], rev[2], rev[3], + rev[4]); #endif display_printf("\nPlease contact Trezor support.\n"); shutdown(); diff --git a/core/embed/trezorhal/common.h b/core/embed/trezorhal/common.h index d46bfb6e2..bcdaca919 100644 --- a/core/embed/trezorhal/common.h +++ b/core/embed/trezorhal/common.h @@ -24,9 +24,6 @@ #include #include "secbool.h" -#define XSTR(s) STR(s) -#define STR(s) #s - #ifndef MIN_8bits #define MIN_8bits(a, b) \ ({ \ diff --git a/core/embed/unix/common.c b/core/embed/unix/common.c index 370245232..8538422a6 100644 --- a/core/embed/unix/common.c +++ b/core/embed/unix/common.c @@ -58,9 +58,12 @@ __fatal_error(const char *expr, const char *msg, const char *file, int line, display_printf("func: %s\n", func); printf("func: %s\n", func); } -#ifdef GITREV - display_printf("rev : %s\n", XSTR(GITREV)); - printf("rev : %s\n", XSTR(GITREV)); +#ifdef SCM_REVISION + const uint8_t *rev = (const uint8_t *)SCM_REVISION; + display_printf("rev : %02x%02x%02x%02x%02x\n", rev[0], rev[1], rev[2], rev[3], + rev[4]); + printf("rev : %02x%02x%02x%02x%02x\n", rev[0], rev[1], rev[2], rev[3], + rev[4]); #endif display_printf("\n\n\nHint:\nIsn't the emulator already running?\n"); printf("Hint:\nIsn't the emulator already running?\n"); diff --git a/core/embed/unix/common.h b/core/embed/unix/common.h index 071df5733..f7040876c 100644 --- a/core/embed/unix/common.h +++ b/core/embed/unix/common.h @@ -23,9 +23,6 @@ #include #include "secbool.h" -#define XSTR(s) STR(s) -#define STR(s) #s - #ifndef MIN #define MIN(a, b) \ ({ \ diff --git a/core/mocks/generated/trezorutils.pyi b/core/mocks/generated/trezorutils.pyi index 820508f13..cce8392e3 100644 --- a/core/mocks/generated/trezorutils.pyi +++ b/core/mocks/generated/trezorutils.pyi @@ -32,7 +32,7 @@ def halt(msg: str | None = None) -> None: """ Halts execution. """ -GITREV: str +SCM_REVISION: bytes VERSION_MAJOR: int VERSION_MINOR: int VERSION_PATCH: int diff --git a/core/src/apps/base.py b/core/src/apps/base.py index 490c0b2a9..16b8ee966 100644 --- a/core/src/apps/base.py +++ b/core/src/apps/base.py @@ -36,7 +36,7 @@ def get_features() -> Features: major_version=utils.VERSION_MAJOR, minor_version=utils.VERSION_MINOR, patch_version=utils.VERSION_PATCH, - revision=utils.GITREV.encode(), + revision=utils.SCM_REVISION, model=utils.MODEL, device_id=storage.device.get_device_id(), label=storage.device.get_label(), diff --git a/core/src/trezor/utils.py b/core/src/trezor/utils.py index d076975d9..26039f6ba 100644 --- a/core/src/trezor/utils.py +++ b/core/src/trezor/utils.py @@ -3,8 +3,8 @@ import sys from trezorutils import ( # noqa: F401 BITCOIN_ONLY, EMULATOR, - GITREV, MODEL, + SCM_REVISION, VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH,