diff --git a/core/SConscript.firmware b/core/SConscript.firmware index fe9843a1eb..7758b8a3b6 100644 --- a/core/SConscript.firmware +++ b/core/SConscript.firmware @@ -685,6 +685,8 @@ if FROZEN: bitcoin_only=BITCOIN_ONLY, backlight='backlight' in FEATURES_AVAILABLE, optiga='optiga' in FEATURES_AVAILABLE, + use_button='button' in FEATURES_AVAILABLE, + use_touch='touch' in FEATURES_AVAILABLE, ui_layout=ui.get_ui_layout(TREZOR_MODEL), thp=THP, ) diff --git a/core/SConscript.unix b/core/SConscript.unix index bc791f69d2..56fd8db372 100644 --- a/core/SConscript.unix +++ b/core/SConscript.unix @@ -444,18 +444,6 @@ env = Environment(ENV=os.environ, CFLAGS='%s -DCONFIDENTIAL= -DPYOPT=%s -DBITCOI FEATURES_AVAILABLE = models.configure_board(TREZOR_MODEL, HW_REVISION, FEATURES_WANTED, env, CPPDEFINES_HAL, SOURCE_UNIX, PATH_HAL) - -if 'sd_card' in FEATURES_AVAILABLE: - SDCARD = True -else: - SDCARD = False - -if 'optiga' in FEATURES_AVAILABLE: - OPTIGA = True -else: - OPTIGA = False - - env.Tool('micropython') env.Replace( @@ -629,7 +617,7 @@ if FROZEN: SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/*.py', exclude=[ SOURCE_PY_DIR + 'trezor/sdcard.py', - ] if not SDCARD else [] + ] if 'sd_card' not in FEATURES_AVAILABLE else [] )) SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/crypto/*.py')) SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/ui/*.py')) @@ -654,7 +642,7 @@ if FROZEN: SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'storage/*.py', exclude=[ SOURCE_PY_DIR + 'storage/sd_salt.py', - ] if not SDCARD else [] + ] if 'sd_card' not in FEATURES_AVAILABLE else [] )) SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/messages/__init__.py')) @@ -679,16 +667,16 @@ if FROZEN: SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/common/*.py', exclude=[ SOURCE_PY_DIR + 'apps/common/sdcard.py', - ] if not SDCARD else [] + ] if "sd_card" not in FEATURES_AVAILABLE else [] )) SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/debug/*.py')) SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/homescreen/*.py')) SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/management/*.py', exclude=[ SOURCE_PY_DIR + 'apps/management/sd_protect.py', - ] if not SDCARD else [] + [ + ] if "sd_card" not in FEATURES_AVAILABLE else [] + [ SOURCE_PY_DIR + 'apps/management/authenticate_device.py', - ] if not OPTIGA else []) + ] if "optiga" not in FEATURES_AVAILABLE else []) ) SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/management/*/*.py')) SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/misc/*.py')) @@ -763,7 +751,9 @@ if FROZEN: source_dir=SOURCE_PY_DIR, bitcoin_only=BITCOIN_ONLY, backlight='backlight' in FEATURES_AVAILABLE, - optiga=OPTIGA, + optiga='optiga' in FEATURES_AVAILABLE, + use_button='button' in FEATURES_AVAILABLE, + use_touch='touch' in FEATURES_AVAILABLE, ui_layout=ui.get_ui_layout(TREZOR_MODEL), thp=THP, ) diff --git a/core/embed/extmod/modtrezorutils/modtrezorutils.c b/core/embed/extmod/modtrezorutils/modtrezorutils.c index 21444bc5a7..bb882fc6f5 100644 --- a/core/embed/extmod/modtrezorutils/modtrezorutils.c +++ b/core/embed/extmod/modtrezorutils/modtrezorutils.c @@ -389,6 +389,10 @@ STATIC mp_obj_tuple_t mod_trezorutils_version_obj = { /// """Whether the hardware supports haptic feedback.""" /// USE_OPTIGA: bool /// """Whether the hardware supports Optiga secure element.""" +/// USE_TOUCH: bool +/// """Whether the hardware supports touch screen.""" +/// USE_BUTTON: bool +/// """Whether the hardware supports two-button input.""" /// MODEL: str /// """Model name.""" /// MODEL_FULL_NAME: str @@ -454,6 +458,16 @@ STATIC const mp_rom_map_elem_t mp_module_trezorutils_globals_table[] = { {MP_ROM_QSTR(MP_QSTR_USE_OPTIGA), mp_const_true}, #else {MP_ROM_QSTR(MP_QSTR_USE_OPTIGA), mp_const_false}, +#endif +#ifdef USE_TOUCH + {MP_ROM_QSTR(MP_QSTR_USE_TOUCH), mp_const_true}, +#else + {MP_ROM_QSTR(MP_QSTR_USE_TOUCH), mp_const_false}, +#endif +#ifdef USE_BUTTON + {MP_ROM_QSTR(MP_QSTR_USE_BUTTON), mp_const_true}, +#else + {MP_ROM_QSTR(MP_QSTR_USE_BUTTON), mp_const_false}, #endif {MP_ROM_QSTR(MP_QSTR_MODEL), MP_ROM_PTR(&mod_trezorutils_model_name_obj)}, {MP_ROM_QSTR(MP_QSTR_MODEL_FULL_NAME), diff --git a/core/mocks/generated/trezorutils.pyi b/core/mocks/generated/trezorutils.pyi index 5c497046ba..0607b5c91a 100644 --- a/core/mocks/generated/trezorutils.pyi +++ b/core/mocks/generated/trezorutils.pyi @@ -130,6 +130,10 @@ USE_HAPTIC: bool """Whether the hardware supports haptic feedback.""" USE_OPTIGA: bool """Whether the hardware supports Optiga secure element.""" +USE_TOUCH: bool +"""Whether the hardware supports touch screen.""" +USE_BUTTON: bool +"""Whether the hardware supports two-button input.""" MODEL: str """Model name.""" MODEL_FULL_NAME: str diff --git a/core/site_scons/site_tools/micropython/__init__.py b/core/site_scons/site_tools/micropython/__init__.py index 22e9feac91..ee5a0c80ab 100644 --- a/core/site_scons/site_tools/micropython/__init__.py +++ b/core/site_scons/site_tools/micropython/__init__.py @@ -46,6 +46,8 @@ def generate(env): optiga = env["optiga"] layout_tt = env["ui_layout"] == "UI_LAYOUT_TT" layout_tr = env["ui_layout"] == "UI_LAYOUT_TR" + touch = env["use_touch"] + button = env["use_button"] layout_mercury = env["ui_layout"] == "UI_LAYOUT_MERCURY" thp = env["thp"] interim = f"{target[:-4]}.i" # replace .mpy with .i @@ -56,6 +58,8 @@ def generate(env): rf"-e 's/utils\.UI_LAYOUT == \"TT\"/{layout_tt}/g'", rf"-e 's/utils\.UI_LAYOUT == \"TR\"/{layout_tr}/g'", rf"-e 's/utils\.UI_LAYOUT == \"MERCURY\"/{layout_mercury}/g'", + rf"-e 's/utils\.USE_BUTTON/{button}/g'", + rf"-e 's/utils\.USE_TOUCH/{touch}/g'", rf"-e 's/utils\.USE_THP/{thp}/g'", r"-e 's/if TYPE_CHECKING/if False/'", r"-e 's/import typing/# \0/'", diff --git a/core/src/trezor/utils.py b/core/src/trezor/utils.py index 134274db6c..7021759ba9 100644 --- a/core/src/trezor/utils.py +++ b/core/src/trezor/utils.py @@ -11,10 +11,12 @@ from trezorutils import ( # noqa: F401 SCM_REVISION, UI_LAYOUT, USE_BACKLIGHT, + USE_BUTTON, USE_HAPTIC, USE_OPTIGA, USE_SD_CARD, USE_THP, + USE_TOUCH, VERSION, bootloader_locked, check_firmware_header,