1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-18 20:38:10 +00:00

build(core): improve model detection

instead of MODEL_IS_T2B1, we now catch INTERNAL_MODEL == Txyz

this is still not perfect because it can't detect 'in'/'not in', which
sucks but what can we do
This commit is contained in:
matejcik 2024-05-24 12:19:19 +02:00 committed by matejcik
parent 87619c19ee
commit 44a6696f24
5 changed files with 34 additions and 26 deletions

View File

@ -42,29 +42,41 @@ def generate(env):
# replace "utils.BITCOIN_ONLY" with literal constant (True/False) # replace "utils.BITCOIN_ONLY" with literal constant (True/False)
# so the compiler can optimize out the things we don't want # so the compiler can optimize out the things we don't want
btc_only = env["bitcoin_only"] == "1" btc_only = env["bitcoin_only"] == "1"
is_t2b1 = env["TREZOR_MODEL"] == "R"
backlight = env["backlight"] backlight = env["backlight"]
optiga = env["optiga"] optiga = env["optiga"]
layout_tt = env["ui_layout"] == "UI_LAYOUT_TT" layout_tt = env["ui_layout"] == "UI_LAYOUT_TT"
layout_tr = env["ui_layout"] == "UI_LAYOUT_TR" layout_tr = env["ui_layout"] == "UI_LAYOUT_TR"
thp = env["thp"] thp = env["thp"]
interim = f"{target[:-4]}.i" # replace .mpy with .i interim = f"{target[:-4]}.i" # replace .mpy with .i
sed_scripts = " ".join( sed_scripts = [
[ rf"-e 's/utils\.BITCOIN_ONLY/{btc_only}/g'",
rf"-e 's/utils\.MODEL_IS_T2B1/{is_t2b1}/g'", rf"-e 's/utils\.USE_BACKLIGHT/{backlight}/g'",
rf"-e 's/utils\.BITCOIN_ONLY/{btc_only}/g'", rf"-e 's/utils\.USE_OPTIGA/{optiga}/g'",
rf"-e 's/utils\.USE_BACKLIGHT/{backlight}/g'", rf"-e 's/utils\.UI_LAYOUT == \"TT\"/{layout_tt}/g'",
rf"-e 's/utils\.USE_OPTIGA/{optiga}/g'", rf"-e 's/utils\.UI_LAYOUT == \"TR\"/{layout_tr}/g'",
rf"-e 's/utils\.UI_LAYOUT == \"TT\"/{layout_tt}/g'", rf"-e 's/utils\.USE_THP/{thp}/g'",
rf"-e 's/utils\.UI_LAYOUT == \"TR\"/{layout_tr}/g'", r"-e 's/if TYPE_CHECKING/if False/'",
rf"-e 's/utils\.USE_THP/{thp}/g'", r"-e 's/import typing/# \0/'",
r"-e 's/if TYPE_CHECKING/if False/'", r"-e '/from typing import (/,/^\s*)/ {s/^/# /; }'",
r"-e 's/import typing/# \0/'", r"-e 's/from typing import/# \0/'",
r"-e '/from typing import (/,/^\s*)/ {s/^/# /; }'", ]
r"-e 's/from typing import/# \0/'",
] MODEL_SYMS = {
) "T": "T2T1",
return f"$SED {sed_scripts} {source} > {interim} && $MPY_CROSS -o {target} -s {source_name} {interim}" "R": "T2B1",
"T3T1": "T3T1",
}
for model_sym, internal_model in MODEL_SYMS.items():
model_matches = env["TREZOR_MODEL"] == model_sym
sed_scripts.extend(
(
rf"-e 's/utils\.INTERNAL_MODEL == \"{internal_model}\"/{model_matches}/g'",
rf"-e 's/utils\.INTERNAL_MODEL != \"{internal_model}\"/{not model_matches}/g'",
)
)
return f"$SED {' '.join(sed_scripts)} {source} > {interim} && $MPY_CROSS -o {target} -s {source_name} {interim}"
env["BUILDERS"]["FrozenModule"] = SCons.Builder.Builder( env["BUILDERS"]["FrozenModule"] = SCons.Builder.Builder(
generator=generate_frozen_module, generator=generate_frozen_module,

View File

@ -126,8 +126,8 @@ def get_features() -> Features:
Capability.Translations, Capability.Translations,
] ]
# We do not support some currencies on T2B1 # We don't support some currencies on later models (see #2793)
if not utils.MODEL_IS_T2B1: if utils.INTERNAL_MODEL == "T2T1":
f.capabilities.extend( f.capabilities.extend(
[ [
Capability.NEM, Capability.NEM,

View File

@ -30,10 +30,6 @@ from trezorutils import ( # noqa: F401
) )
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
# Will get replaced by "True" / "False" in the build process
# However, needs to stay as an exported symbol for the unit tests
MODEL_IS_T2B1: bool = INTERNAL_MODEL == "T2B1"
DISABLE_ANIMATION = 0 DISABLE_ANIMATION = 0
if __debug__: if __debug__:

View File

@ -1,6 +1,6 @@
from common import * # isort:skip from common import * # isort:skip
if not utils.MODEL_IS_T2B1: if utils.INTERNAL_MODEL not in ("T2B1", "T3T1"):
from trezor.crypto import bip39 from trezor.crypto import bip39
from trezor.enums import AmountUnit, OutputScriptType from trezor.enums import AmountUnit, OutputScriptType
from trezor.enums.RequestType import TXFINISHED, TXINPUT, TXMETA, TXOUTPUT from trezor.enums.RequestType import TXFINISHED, TXINPUT, TXMETA, TXOUTPUT
@ -405,5 +405,5 @@ class TestSignTxDecred(unittest.TestCase):
if __name__ == "__main__": if __name__ == "__main__":
if not utils.MODEL_IS_T2B1: if utils.INTERNAL_MODEL not in ("T2B1", "T3T1"):
unittest.main() unittest.main()

View File

@ -22,7 +22,7 @@ class TestCoins(unittest.TestCase):
("ZEC", "Zcash", 7352), ("ZEC", "Zcash", 7352),
("TAZ", "Zcash Testnet", 7461), ("TAZ", "Zcash Testnet", 7461),
] ]
if not utils.MODEL_IS_T2B1: if utils.INTERNAL_MODEL not in ("T2B1", "T3T1"):
ref.extend( ref.extend(
[ [
("NMC", "Namecoin", 52), ("NMC", "Namecoin", 52),