From 957912ae2603fc4add24f14c98cebc0d4449c582 Mon Sep 17 00:00:00 2001 From: matejcik Date: Thu, 21 Nov 2024 12:51:39 +0100 Subject: [PATCH] feat(core): disable animations in debug firmware by default This makes it possible to run HW tests on the T3T1 where animations mess things up. It also speeds up HW tests on other models slightly. export TREZOR_DISABLE_ANIMATION=0 to build a debug firmware with animations enabled --- core/Makefile | 2 ++ core/SConscript.firmware | 2 ++ core/embed/upymod/modtrezorutils/modtrezorutils.c | 10 ++++++++++ core/mocks/generated/trezorutils.pyi | 3 +++ core/src/trezor/ui/__init__.py | 2 +- core/src/trezor/utils.py | 11 +++++++---- 6 files changed, 25 insertions(+), 5 deletions(-) diff --git a/core/Makefile b/core/Makefile index 644cce206a..1578c8d16b 100644 --- a/core/Makefile +++ b/core/Makefile @@ -41,6 +41,7 @@ THP ?= 0 BENCHMARK ?= 0 TREZOR_EMULATOR_DEBUGGABLE ?= 0 QUIET_MODE ?= 0 +TREZOR_DISABLE_ANIMATION ?= $(if $(filter 0,$(PYOPT)),1,0) # OpenOCD interface default. Alternative: ftdi/olimex-arm-usb-tiny-h OPENOCD_INTERFACE ?= stlink @@ -143,6 +144,7 @@ SCONS_VARS = \ PYOPT="$(PYOPT)" \ QUIET_MODE="$(QUIET_MODE)" \ THP="$(THP)" \ + TREZOR_DISABLE_ANIMATION="$(TREZOR_DISABLE_ANIMATION)" \ TREZOR_EMULATOR_ASAN="$(ADDRESS_SANITIZER)" \ TREZOR_EMULATOR_DEBUGGABLE=$(TREZOR_EMULATOR_DEBUGGABLE) \ TREZOR_MEMPERF="$(TREZOR_MEMPERF)" \ diff --git a/core/SConscript.firmware b/core/SConscript.firmware index e95922f45a..902ea3285e 100644 --- a/core/SConscript.firmware +++ b/core/SConscript.firmware @@ -18,6 +18,7 @@ HW_REVISION = ARGUMENTS.get('HW_REVISION', None) THP = ARGUMENTS.get('THP', '0') == '1' # Trezor-Host Protocol MODEL_IDENTIFIER = models.get_model_identifier(TREZOR_MODEL) BENCHMARK = ARGUMENTS.get('BENCHMARK', '0') == '1' +DISABLE_ANIMATION = ARGUMENTS.get('TREZOR_DISABLE_ANIMATION', '0') == '1' if BENCHMARK and PYOPT != '0': print("BENCHMARK=1 works only with PYOPT=0.") @@ -69,6 +70,7 @@ CPPDEFINES_MOD += [ ('USE_CARDANO', '1' if EVERYTHING else '0'), ('USE_NEM', '1' if (EVERYTHING and TREZOR_MODEL == "T") else '0'), ('USE_EOS', '1' if (EVERYTHING and TREZOR_MODEL == "T") else '0'), + ('DISABLE_ANIMATION', '1' if DISABLE_ANIMATION else '0'), ] SOURCE_MOD += [ 'embed/upymod/trezorobj.c', diff --git a/core/embed/upymod/modtrezorutils/modtrezorutils.c b/core/embed/upymod/modtrezorutils/modtrezorutils.c index e60bd425dc..9b79c7a392 100644 --- a/core/embed/upymod/modtrezorutils/modtrezorutils.c +++ b/core/embed/upymod/modtrezorutils/modtrezorutils.c @@ -410,6 +410,9 @@ STATIC mp_obj_tuple_t mod_trezorutils_version_obj = { /// """UI layout identifier ("tt" for model T, "tr" for models One and R).""" /// USE_THP: bool /// """Whether the firmware supports Trezor-Host Protocol (version 2).""" +/// if __debug__: +/// DISABLE_ANIMATION: bool +/// """Whether the firmware should disable animations.""" STATIC const mp_rom_map_elem_t mp_module_trezorutils_globals_table[] = { {MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_trezorutils)}, @@ -502,6 +505,13 @@ STATIC const mp_rom_map_elem_t mp_module_trezorutils_globals_table[] = { #else #error Unknown layout #endif +#if !PYOPT +#if DISABLE_ANIMATION + {MP_ROM_QSTR(MP_QSTR_DISABLE_ANIMATION), mp_const_true}, +#else + {MP_ROM_QSTR(MP_QSTR_DISABLE_ANIMATION), mp_const_false}, +#endif // TREZOR_DISABLE_ANIMATION +#endif // PYOPT }; STATIC MP_DEFINE_CONST_DICT(mp_module_trezorutils_globals, diff --git a/core/mocks/generated/trezorutils.pyi b/core/mocks/generated/trezorutils.pyi index c8b55c2b9b..d97c2526e3 100644 --- a/core/mocks/generated/trezorutils.pyi +++ b/core/mocks/generated/trezorutils.pyi @@ -152,3 +152,6 @@ UI_LAYOUT: str """UI layout identifier ("tt" for model T, "tr" for models One and R).""" USE_THP: bool """Whether the firmware supports Trezor-Host Protocol (version 2).""" +if __debug__: + DISABLE_ANIMATION: bool + """Whether the firmware should disable animations.""" diff --git a/core/src/trezor/ui/__init__.py b/core/src/trezor/ui/__init__.py index a0ad35a338..115815c8a8 100644 --- a/core/src/trezor/ui/__init__.py +++ b/core/src/trezor/ui/__init__.py @@ -23,7 +23,7 @@ else: if __debug__: - trezorui2.disable_animation(bool(utils.DISABLE_ANIMATION)) + trezorui2.disable_animation(utils.DISABLE_ANIMATION) # all rendering is done through a singleton of `Display` diff --git a/core/src/trezor/utils.py b/core/src/trezor/utils.py index 7021759ba9..2f38aa9438 100644 --- a/core/src/trezor/utils.py +++ b/core/src/trezor/utils.py @@ -33,17 +33,20 @@ from trezorutils import ( # noqa: F401 ) from typing import TYPE_CHECKING -DISABLE_ANIMATION = 0 - if __debug__: if EMULATOR: import uos - DISABLE_ANIMATION = int(uos.getenv("TREZOR_DISABLE_ANIMATION") or "0") - LOG_MEMORY = int(uos.getenv("TREZOR_LOG_MEMORY") or "0") + DISABLE_ANIMATION = uos.getenv("TREZOR_DISABLE_ANIMATION") == "1" + LOG_MEMORY = uos.getenv("TREZOR_LOG_MEMORY") == "1" else: + from trezorutils import DISABLE_ANIMATION # noqa: F401 + LOG_MEMORY = 0 +else: + DISABLE_ANIMATION = False + if TYPE_CHECKING: from typing import Any, Iterator, Protocol, Sequence, TypeVar