refactor(core): setup single-place layout selection

[no changelog]
pull/3285/head
tychovrahe 9 months ago committed by TychoVrahe
parent b9dbdc7057
commit 3c1236bf82

@ -380,6 +380,21 @@ env = Environment(ENV=os.environ, CFLAGS=f"{ARGUMENTS.get('CFLAGS', '')} -DPRODU
FEATURES_AVAILABLE = tools.configure_board(TREZOR_MODEL, FEATURES_WANTED, env, CPPDEFINES_HAL, SOURCE_HAL, PATH_HAL)
if TREZOR_MODEL in ('T', 'DISC1'):
UI_LAYOUT = 'UI_LAYOUT_TT'
ui_layout_feature = 'model_tt'
elif TREZOR_MODEL in ('1', 'R'):
UI_LAYOUT = 'UI_LAYOUT_TR'
ui_layout_feature = 'model_tr'
else:
raise ValueError('Unknown Trezor model')
if 'sd_card' in FEATURES_AVAILABLE:
SDCARD = True
else:
SDCARD = False
env.Tool('micropython')
env.Replace(
@ -430,6 +445,7 @@ env.Replace(
'FIRMWARE',
'TREZOR_MODEL_'+TREZOR_MODEL,
'USE_HAL_DRIVER',
UI_LAYOUT,
] + CPPDEFINES_MOD + CPPDEFINES_HAL,
ASFLAGS=env.get('ENV')['CPU_ASFLAGS'],
ASPPFLAGS='$CFLAGS $CCFLAGS',
@ -518,7 +534,7 @@ if FROZEN:
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/*.py',
exclude=[
SOURCE_PY_DIR + 'trezor/sdcard.py',
] if TREZOR_MODEL not in ('T',) else []
] if not SDCARD else []
))
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/crypto/*.py'))
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/ui/*.py'))
@ -529,27 +545,27 @@ if FROZEN:
SOURCE_PY_DIR + 'trezor/ui/layouts/fido.py',
] if not EVERYTHING else []
))
if TREZOR_MODEL in ('T', 'DISC1'):
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/ui/layouts/tt_v2/*.py',
if UI_LAYOUT == 'UI_LAYOUT_TT':
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/ui/layouts/tt/*.py',
exclude=[
SOURCE_PY_DIR + 'trezor/ui/layouts/tt_v2/fido.py',
SOURCE_PY_DIR + 'trezor/ui/layouts/tt/fido.py',
] if not EVERYTHING else []
))
elif TREZOR_MODEL in ('1', 'R'):
elif UI_LAYOUT == 'UI_LAYOUT_TR':
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/ui/layouts/tr/*.py',
exclude=[
SOURCE_PY_DIR + 'trezor/ui/layouts/tr/fido.py',
] if not EVERYTHING else []
))
else:
raise ValueError('Unknown Trezor model')
raise ValueError('Unknown layout')
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/wire/*.py'))
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'storage/*.py',
exclude=[
SOURCE_PY_DIR + 'storage/sd_salt.py',
] if "sd_card" not in FEATURES_AVAILABLE else []
] if not SDCARD else []
))
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/messages/__init__.py'))
@ -573,14 +589,14 @@ if FROZEN:
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/common/*.py',
exclude=[
SOURCE_PY_DIR + 'apps/common/sdcard.py',
] if "sd_card" not in FEATURES_AVAILABLE else []
] if not SDCARD 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 'sd_card' not in FEATURES_AVAILABLE else [])
] if not SDCARD else [])
)
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/management/*/*.py'))
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/misc/*.py'))
@ -645,7 +661,8 @@ if FROZEN:
source_dir=SOURCE_PY_DIR,
bitcoin_only=BITCOIN_ONLY,
backlight='backlight' in FEATURES_AVAILABLE,
optiga='optiga' in FEATURES_AVAILABLE
optiga='optiga' in FEATURES_AVAILABLE,
ui_layout=UI_LAYOUT,
)
source_mpyc = env.FrozenCFile(
@ -681,13 +698,7 @@ def cargo_build():
else:
profile = ''
# T1 does not have its own Rust feature, it shares it with TR
if TREZOR_MODEL in ('1', 'R'):
model_feature = 'model_tr'
else:
model_feature = 'model_tt'
features = ['micropython', 'protobuf', model_feature]
features = ['micropython', 'protobuf', ui_layout_feature]
if BITCOIN_ONLY == '1':
features.append('bitcoin_only')
features.append('ui')

@ -387,7 +387,6 @@ SOURCE_UNIX = [
if TREZOR_MODEL in ('T', 'R'):
SOURCE_UNIX += [
'embed/trezorhal/unix/sbu.c',
'embed/trezorhal/unix/sdcard.c',
]
if TREZOR_MODEL == 'R':
@ -424,6 +423,24 @@ else:
env = Environment(ENV=os.environ, CFLAGS='%s -DPYOPT=%s -DBITCOIN_ONLY=%s %s' % (ARGUMENTS.get('CFLAGS', ''), PYOPT, BITCOIN_ONLY, STATIC))
if TREZOR_MODEL in ('T',):
UI_LAYOUT = 'UI_LAYOUT_TT'
ui_layout_feature = 'model_tt'
elif TREZOR_MODEL in ('1', 'R'):
UI_LAYOUT = 'UI_LAYOUT_TR'
ui_layout_feature = 'model_tr'
else:
raise ValueError('Unknown Trezor model')
if TREZOR_MODEL in ('T',):
SDCARD = True
SOURCE_UNIX += [
'embed/trezorhal/unix/sdcard.c',
]
else:
SDCARD = False
env.Tool('micropython')
env.Replace(
@ -508,6 +525,7 @@ env.Replace(
'TREZOR_BOARD=\\"boards/board-unix.h\\"',
'MCU_TYPE='+CPU_MODEL,
('MP_CONFIGFILE', '\\"embed/unix/mpconfigport.h\\"'),
UI_LAYOUT,
] + CPPDEFINES_MOD,
ASPPFLAGS='$CFLAGS $CCFLAGS', )
@ -599,7 +617,7 @@ if FROZEN:
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/*.py',
exclude=[
SOURCE_PY_DIR + 'trezor/sdcard.py',
] if TREZOR_MODEL not in ('T',) else []
] if not SDCARD else []
))
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/crypto/*.py'))
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/ui/*.py'))
@ -610,27 +628,27 @@ if FROZEN:
SOURCE_PY_DIR + 'trezor/ui/layouts/fido.py',
] if not EVERYTHING else []
))
if TREZOR_MODEL in ('T',):
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/ui/layouts/tt_v2/*.py',
if UI_LAYOUT == 'UI_LAYOUT_TT':
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/ui/layouts/tt/*.py',
exclude=[
SOURCE_PY_DIR + 'trezor/ui/layouts/tt_v2/fido.py',
SOURCE_PY_DIR + 'trezor/ui/layouts/tt/fido.py',
] if not EVERYTHING else []
))
elif TREZOR_MODEL in ('R'):
elif UI_LAYOUT == 'UI_LAYOUT_TR':
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/ui/layouts/tr/*.py',
exclude=[
SOURCE_PY_DIR + 'trezor/ui/layouts/tr/fido.py',
] if not EVERYTHING else []
))
else:
raise ValueError('Unknown Trezor model')
raise ValueError('Unknown layout')
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/wire/*.py'))
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'storage/*.py',
exclude=[
SOURCE_PY_DIR + 'storage/sd_salt.py',
] if TREZOR_MODEL not in ('T',) else []
] if not SDCARD else []
))
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/messages/__init__.py'))
@ -654,14 +672,14 @@ if FROZEN:
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/common/*.py',
exclude=[
SOURCE_PY_DIR + 'apps/common/sdcard.py',
] if TREZOR_MODEL not in ('T',) else []
] if not SDCARD 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 TREZOR_MODEL not in ('T',) else [] + [
] if not SDCARD else [] + [
SOURCE_PY_DIR + 'apps/management/authenticate_device.py',
] if TREZOR_MODEL not in ('R',) else [])
)
@ -728,7 +746,8 @@ if FROZEN:
source_dir=SOURCE_PY_DIR,
bitcoin_only=BITCOIN_ONLY,
backlight=TREZOR_MODEL in ('T',),
optiga=TREZOR_MODEL in ('R',)
optiga=TREZOR_MODEL in ('R',),
ui_layout=UI_LAYOUT,
)
source_mpyc = env.FrozenCFile(
@ -764,9 +783,7 @@ RUST_LIB = 'trezor_lib'
RUST_LIBPATH = f'{RUST_LIBDIR}/lib{RUST_LIB}.a'
def cargo_build():
# T1 does not have its own Rust feature, it shares it with TR
model_feature = 'model_tr' if TREZOR_MODEL == '1' else f'model_t{TREZOR_MODEL.lower()}'
features = ['micropython', 'protobuf', model_feature]
features = ['micropython', 'protobuf', ui_layout_feature]
if BITCOIN_ONLY == '1':
features.append('bitcoin_only')
features.append('ui')

@ -292,6 +292,7 @@ STATIC mp_obj_str_t mod_trezorutils_revision_obj = {
/// INTERNAL_MODEL: str
/// EMULATOR: bool
/// BITCOIN_ONLY: bool
/// UI_LAYOUT: str
STATIC const mp_rom_map_elem_t mp_module_trezorutils_globals_table[] = {
{MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_trezorutils)},
@ -345,6 +346,13 @@ STATIC const mp_rom_map_elem_t mp_module_trezorutils_globals_table[] = {
#else
{MP_ROM_QSTR(MP_QSTR_BITCOIN_ONLY), mp_const_false},
#endif
#ifdef UI_LAYOUT_TT
{MP_ROM_QSTR(MP_QSTR_UI_LAYOUT), MP_ROM_QSTR(MP_QSTR_TT)},
#elif UI_LAYOUT_TR
{MP_ROM_QSTR(MP_QSTR_UI_LAYOUT), MP_ROM_QSTR(MP_QSTR_TR)},
#else
#error Unknown layout
#endif
};
STATIC MP_DEFINE_CONST_DICT(mp_module_trezorutils_globals,

@ -9,7 +9,7 @@ pub mod dma2d;
mod ffi;
pub mod io;
pub mod random;
#[cfg(feature = "model_tr")]
#[cfg(feature = "rgb_led")]
pub mod rgb_led;
pub mod slip39;
pub mod storage;

@ -98,3 +98,4 @@ MODEL: str
INTERNAL_MODEL: str
EMULATOR: bool
BITCOIN_ONLY: bool
UI_LAYOUT: str

@ -39,6 +39,8 @@ def generate(env):
is_t2b1 = env["TREZOR_MODEL"] == "R"
backlight = env["backlight"]
optiga = env["optiga"]
layout_tt = env["ui_layout"] == "UI_LAYOUT_TT"
layout_tr = env["ui_layout"] == "UI_LAYOUT_TR"
interim = f"{target[:-4]}.i" # replace .mpy with .i
sed_scripts = " ".join(
[
@ -46,6 +48,8 @@ def generate(env):
rf"-e 's/utils\.BITCOIN_ONLY/{btc_only}/g'",
rf"-e 's/utils\.USE_BACKLIGHT/{backlight}/g'",
rf"-e 's/utils\.USE_OPTIGA/{optiga}/g'",
rf"-e 's/utils\.UI_LAYOUT == \"TT\"/{layout_tt}/g'",
rf"-e 's/utils\.UI_LAYOUT == \"TR\"/{layout_tr}/g'",
r"-e 's/if TYPE_CHECKING/if False/'",
r"-e 's/import typing/# \0/'",
r"-e '/from typing import (/,/^\s*)/ {s/^/# /}'",

@ -173,18 +173,18 @@ trezor.ui.layouts.tr.recovery
import trezor.ui.layouts.tr.recovery
trezor.ui.layouts.tr.reset
import trezor.ui.layouts.tr.reset
trezor.ui.layouts.tt_v2
import trezor.ui.layouts.tt_v2
trezor.ui.layouts.tt_v2.fido
import trezor.ui.layouts.tt_v2.fido
trezor.ui.layouts.tt_v2.homescreen
import trezor.ui.layouts.tt_v2.homescreen
trezor.ui.layouts.tt_v2.progress
import trezor.ui.layouts.tt_v2.progress
trezor.ui.layouts.tt_v2.recovery
import trezor.ui.layouts.tt_v2.recovery
trezor.ui.layouts.tt_v2.reset
import trezor.ui.layouts.tt_v2.reset
trezor.ui.layouts.tt
import trezor.ui.layouts.tt
trezor.ui.layouts.tt.fido
import trezor.ui.layouts.tt.fido
trezor.ui.layouts.tt.homescreen
import trezor.ui.layouts.tt.homescreen
trezor.ui.layouts.tt.progress
import trezor.ui.layouts.tt.progress
trezor.ui.layouts.tt.recovery
import trezor.ui.layouts.tt.recovery
trezor.ui.layouts.tt.reset
import trezor.ui.layouts.tt.reset
trezor.ui.style
import trezor.ui.style
trezor.utils

@ -4,9 +4,9 @@ from .common import * # noqa: F401,F403
# NOTE: using any import magic probably causes mypy not to check equivalence of
# layout type signatures across models
if utils.INTERNAL_MODEL in ("T1B1", "T2B1"):
if utils.UI_LAYOUT == "TR":
from .tr import * # noqa: F401,F403
elif utils.INTERNAL_MODEL in ("T2T1", "D001"):
from .tt_v2 import * # noqa: F401,F403
elif utils.UI_LAYOUT == "TT":
from .tt import * # noqa: F401,F403
else:
raise ValueError("Unknown Trezor model")
raise ValueError("Unknown layout")

@ -1,6 +1,6 @@
from trezor import utils
if utils.INTERNAL_MODEL in ("T2T1", "D001"):
from .tt_v2.fido import * # noqa: F401,F403
elif utils.INTERNAL_MODEL in ("T2B1",):
if utils.UI_LAYOUT == "TT":
from .tt.fido import * # noqa: F401,F403
elif utils.UI_LAYOUT == "TR":
from .tr.fido import * # noqa: F401,F403

@ -1,6 +1,6 @@
from trezor import utils
if utils.INTERNAL_MODEL in ("T2T1", "D001"):
from .tt_v2.homescreen import * # noqa: F401,F403
elif utils.INTERNAL_MODEL in ("T2B1",):
if utils.UI_LAYOUT == "TT":
from .tt.homescreen import * # noqa: F401,F403
elif utils.UI_LAYOUT == "TR":
from .tr.homescreen import * # noqa: F401,F403

@ -1,6 +1,6 @@
from trezor import utils
if utils.INTERNAL_MODEL in ("T2T1", "D001"):
from .tt_v2.progress import * # noqa: F401,F403
elif utils.INTERNAL_MODEL in ("T2B1",):
if utils.UI_LAYOUT == "TT":
from .tt.progress import * # noqa: F401,F403
elif utils.UI_LAYOUT == "TR":
from .tr.progress import * # noqa: F401,F403

@ -1,6 +1,6 @@
from trezor import utils
if utils.INTERNAL_MODEL in ("T2T1", "D001"):
from .tt_v2.recovery import * # noqa: F401,F403
elif utils.INTERNAL_MODEL in ("T2B1",):
if utils.UI_LAYOUT == "TT":
from .tt.recovery import * # noqa: F401,F403
elif utils.UI_LAYOUT == "TR":
from .tr.recovery import * # noqa: F401,F403

@ -1,6 +1,6 @@
from trezor import utils
if utils.INTERNAL_MODEL in ("T2T1", "D001"):
from .tt_v2.reset import * # noqa: F401,F403
elif utils.INTERNAL_MODEL in ("T2B1",):
if utils.UI_LAYOUT == "TT":
from .tt.reset import * # noqa: F401,F403
elif utils.UI_LAYOUT == "TR":
from .tr.reset import * # noqa: F401,F403

@ -6,6 +6,7 @@ from trezorutils import ( # noqa: F401
INTERNAL_MODEL,
MODEL,
SCM_REVISION,
UI_LAYOUT,
USE_BACKLIGHT,
USE_OPTIGA,
USE_SD_CARD,

Loading…
Cancel
Save