diff --git a/core/Makefile b/core/Makefile index a47adaa70b..f98c31ed0e 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 0140bab9ee..4840d4b36a 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..43ba838d29 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 1e2b6973a3..25f9c1b611 100644 --- a/core/src/trezor/ui/__init__.py +++ b/core/src/trezor/ui/__init__.py @@ -24,7 +24,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 0162d4b8d5..694bae2cb9 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