mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-14 11:39:03 +00:00
refactor(core): setup single-place layout selection
[no changelog]
This commit is contained in:
parent
5d58ed90fc
commit
bf03407426
@ -378,6 +378,19 @@ 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'):
|
||||
LAYOUT = 'LAYOUT_TTV2'
|
||||
elif TREZOR_MODEL in ('1', 'R'):
|
||||
LAYOUT = 'LAYOUT_TR'
|
||||
else:
|
||||
raise ValueError('Unknown Trezor model')
|
||||
|
||||
if 'sd_card' in FEATURES_AVAILABLE:
|
||||
SDCARD = True
|
||||
else:
|
||||
SDCARD = False
|
||||
|
||||
env.Tool('micropython')
|
||||
|
||||
env.Replace(
|
||||
@ -428,6 +441,7 @@ env.Replace(
|
||||
'FIRMWARE',
|
||||
'TREZOR_MODEL_'+TREZOR_MODEL,
|
||||
'USE_HAL_DRIVER',
|
||||
LAYOUT,
|
||||
] + CPPDEFINES_MOD + CPPDEFINES_HAL,
|
||||
ASFLAGS=env.get('ENV')['CPU_ASFLAGS'],
|
||||
ASPPFLAGS='$CFLAGS $CCFLAGS',
|
||||
@ -482,6 +496,7 @@ env.Ignore(qstr_collected, qstr_generated)
|
||||
moduledefs_collected = env.CollectModules(
|
||||
target='genhdr/moduledefs.collected.h', source=SOURCE_QSTR)
|
||||
|
||||
|
||||
hdr_moduledefs = env.Command(
|
||||
target='genhdr/moduledefs.h',
|
||||
source=moduledefs_collected,
|
||||
@ -516,7 +531,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'))
|
||||
@ -527,27 +542,27 @@ if FROZEN:
|
||||
SOURCE_PY_DIR + 'trezor/ui/layouts/fido.py',
|
||||
] if not EVERYTHING else []
|
||||
))
|
||||
if TREZOR_MODEL in ('T', 'DISC1'):
|
||||
if LAYOUT == 'LAYOUT_TTV2':
|
||||
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/ui/layouts/tt_v2/*.py',
|
||||
exclude=[
|
||||
SOURCE_PY_DIR + 'trezor/ui/layouts/tt_v2/fido.py',
|
||||
] if not EVERYTHING else []
|
||||
))
|
||||
elif TREZOR_MODEL in ('1', 'R'):
|
||||
elif LAYOUT == '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'))
|
||||
@ -571,14 +586,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'))
|
||||
@ -639,7 +654,8 @@ if FROZEN:
|
||||
source=SOURCE_PY,
|
||||
source_dir=SOURCE_PY_DIR,
|
||||
bitcoin_only=BITCOIN_ONLY,
|
||||
backlight='backlight' in FEATURES_AVAILABLE
|
||||
backlight='backlight' in FEATURES_AVAILABLE,
|
||||
layout=LAYOUT,
|
||||
)
|
||||
|
||||
source_mpyc = env.FrozenCFile(
|
||||
|
@ -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 DMA2D:
|
||||
@ -416,6 +415,22 @@ 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',):
|
||||
LAYOUT = 'LAYOUT_TTV2'
|
||||
elif TREZOR_MODEL in ('1', 'R'):
|
||||
LAYOUT = 'LAYOUT_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(
|
||||
@ -500,6 +515,7 @@ env.Replace(
|
||||
'TREZOR_BOARD=\\"boards/board-unix.h\\"',
|
||||
'MCU_TYPE='+CPU_MODEL,
|
||||
('MP_CONFIGFILE', '\\"embed/unix/mpconfigport.h\\"'),
|
||||
LAYOUT,
|
||||
] + CPPDEFINES_MOD,
|
||||
ASPPFLAGS='$CFLAGS $CCFLAGS', )
|
||||
|
||||
@ -591,7 +607,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'))
|
||||
@ -602,27 +618,27 @@ if FROZEN:
|
||||
SOURCE_PY_DIR + 'trezor/ui/layouts/fido.py',
|
||||
] if not EVERYTHING else []
|
||||
))
|
||||
if TREZOR_MODEL in ('T',):
|
||||
if LAYOUT == 'LAYOUT_TTV2':
|
||||
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/ui/layouts/tt_v2/*.py',
|
||||
exclude=[
|
||||
SOURCE_PY_DIR + 'trezor/ui/layouts/tt_v2/fido.py',
|
||||
] if not EVERYTHING else []
|
||||
))
|
||||
elif TREZOR_MODEL in ('R'):
|
||||
elif LAYOUT == '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'))
|
||||
@ -646,14 +662,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.extend(Glob(SOURCE_PY_DIR + 'apps/management/*/*.py'))
|
||||
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/misc/*.py'))
|
||||
@ -714,7 +730,8 @@ if FROZEN:
|
||||
source=SOURCE_PY,
|
||||
source_dir=SOURCE_PY_DIR,
|
||||
bitcoin_only=BITCOIN_ONLY,
|
||||
backlight=TREZOR_MODEL in ('T',)
|
||||
backlight=TREZOR_MODEL in ('T',),
|
||||
layout=LAYOUT,
|
||||
)
|
||||
|
||||
source_mpyc = env.FrozenCFile(
|
||||
|
@ -269,6 +269,7 @@ STATIC mp_obj_str_t mod_trezorutils_revision_obj = {
|
||||
/// INTERNAL_MODEL: str
|
||||
/// EMULATOR: bool
|
||||
/// BITCOIN_ONLY: bool
|
||||
/// 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)},
|
||||
@ -325,6 +326,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 LAYOUT_TTV2
|
||||
{MP_ROM_QSTR(MP_QSTR_LAYOUT), MP_ROM_QSTR(MP_QSTR_TTV2)},
|
||||
#elif LAYOUT_TR
|
||||
{MP_ROM_QSTR(MP_QSTR_LAYOUT), MP_ROM_QSTR(MP_QSTR_TR)},
|
||||
#else
|
||||
#error Unknown layout
|
||||
#endif
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(mp_module_trezorutils_globals,
|
||||
|
@ -91,3 +91,4 @@ MODEL: str
|
||||
INTERNAL_MODEL: str
|
||||
EMULATOR: bool
|
||||
BITCOIN_ONLY: bool
|
||||
LAYOUT: str
|
||||
|
@ -37,11 +37,15 @@ def generate(env):
|
||||
# so the compiler can optimize out the things we don't want
|
||||
btc_only = env["bitcoin_only"] == "1"
|
||||
backlight = env["backlight"]
|
||||
layout_ttv2 = env["layout"] == "LAYOUT_TTV2"
|
||||
layout_tr = env["layout"] == "LAYOUT_TR"
|
||||
interim = f"{target[:-4]}.i" # replace .mpy with .i
|
||||
sed_scripts = " ".join(
|
||||
[
|
||||
rf"-e 's/utils\.BITCOIN_ONLY/{btc_only}/g'",
|
||||
rf"-e 's/utils\.USE_BACKLIGHT/{backlight}/g'",
|
||||
rf"-e 's/utils\.LAYOUT == \"TTV2\"/{layout_ttv2}/g'",
|
||||
rf"-e 's/utils\.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/^/# /}'",
|
||||
|
@ -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.LAYOUT == "TR":
|
||||
from .tr import * # noqa: F401,F403
|
||||
elif utils.INTERNAL_MODEL in ("T2T1", "D001"):
|
||||
elif utils.LAYOUT == "TTV2":
|
||||
from .tt_v2 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"):
|
||||
if utils.LAYOUT == "TTV2":
|
||||
from .tt_v2.fido import * # noqa: F401,F403
|
||||
elif utils.INTERNAL_MODEL in ("T2B1",):
|
||||
elif utils.LAYOUT == "TR":
|
||||
from .tr.fido import * # noqa: F401,F403
|
||||
|
@ -1,6 +1,6 @@
|
||||
from trezor import utils
|
||||
|
||||
if utils.INTERNAL_MODEL in ("T2T1", "D001"):
|
||||
if utils.LAYOUT == "TTV2":
|
||||
from .tt_v2.homescreen import * # noqa: F401,F403
|
||||
elif utils.INTERNAL_MODEL in ("T2B1",):
|
||||
elif utils.LAYOUT == "TR":
|
||||
from .tr.homescreen import * # noqa: F401,F403
|
||||
|
@ -1,6 +1,6 @@
|
||||
from trezor import utils
|
||||
|
||||
if utils.INTERNAL_MODEL in ("T2T1", "D001"):
|
||||
if utils.LAYOUT == "TTV2":
|
||||
from .tt_v2.progress import * # noqa: F401,F403
|
||||
elif utils.INTERNAL_MODEL in ("T2B1",):
|
||||
elif utils.LAYOUT == "TR":
|
||||
from .tr.progress import * # noqa: F401,F403
|
||||
|
@ -1,6 +1,6 @@
|
||||
from trezor import utils
|
||||
|
||||
if utils.INTERNAL_MODEL in ("T2T1", "D001"):
|
||||
if utils.LAYOUT == "TTV2":
|
||||
from .tt_v2.recovery import * # noqa: F401,F403
|
||||
elif utils.INTERNAL_MODEL in ("T2B1",):
|
||||
elif utils.LAYOUT == "TR":
|
||||
from .tr.recovery import * # noqa: F401,F403
|
||||
|
@ -1,6 +1,6 @@
|
||||
from trezor import utils
|
||||
|
||||
if utils.INTERNAL_MODEL in ("T2T1", "D001"):
|
||||
if utils.LAYOUT == "TTV2":
|
||||
from .tt_v2.reset import * # noqa: F401,F403
|
||||
elif utils.INTERNAL_MODEL in ("T2B1",):
|
||||
elif utils.LAYOUT == "TR":
|
||||
from .tr.reset import * # noqa: F401,F403
|
||||
|
@ -4,6 +4,7 @@ from trezorutils import ( # noqa: F401
|
||||
BITCOIN_ONLY,
|
||||
EMULATOR,
|
||||
INTERNAL_MODEL,
|
||||
LAYOUT,
|
||||
MODEL,
|
||||
SCM_REVISION,
|
||||
USE_BACKLIGHT,
|
||||
|
Loading…
Reference in New Issue
Block a user