diff --git a/.github/workflows/core.yml b/.github/workflows/core.yml index 335d5b78b6..9ec9236b78 100644 --- a/.github/workflows/core.yml +++ b/.github/workflows/core.yml @@ -226,7 +226,7 @@ jobs: with: submodules: recursive - uses: ./.github/actions/environment - - run: nix-shell --run "poetry run make -C core build_unix_frozen" + - run: nix-shell --run "poetry run make -C core build_unix" # Ensure that "cargo build" works when NOT executed through our makefiles, # indicating that it does not rely on particular envvars or other flags. # This makes sure that rust-analyzer will work on our codebase. diff --git a/common/tools/cointool.py b/common/tools/cointool.py index 42500cd748..7c760b0a68 100755 --- a/common/tools/cointool.py +++ b/common/tools/cointool.py @@ -137,6 +137,24 @@ MAKO_FILTERS = { "black_repr": black_repr_filter, } +ALTCOIN_PREFIXES = ( + "binance", + "cardano", + "eos", + "ethereum", + "fido", + "monero", + "nem", + "nostr", + "ripple", + "solana", + "stellar", + "tezos", + "u2f", +) + +DEBUG_PREFIXES = ("debug",) + def render_file( src: Path, dst: Path, coins: CoinsInfo, support_info: SupportInfo, models: list[str] @@ -156,6 +174,8 @@ def render_file( ethereum_defs_timestamp=int(eth_defs_date.timestamp()), THIS_FILE=this_file, ROOT=ROOT, + ALTCOIN_PREFIXES=ALTCOIN_PREFIXES, + DEBUG_PREFIXES=DEBUG_PREFIXES, **coins, **MAKO_FILTERS, ALL_MODELS=models, diff --git a/core/SConscript.firmware b/core/SConscript.firmware index f580009b26..c82cebf9c0 100644 --- a/core/SConscript.firmware +++ b/core/SConscript.firmware @@ -506,6 +506,8 @@ PROTO_SOURCES_DIR = '../../../common/protob/' exclude_list = [PROTO_SOURCES_DIR + 'messages-bootloader.proto'] if not THP: exclude_list.append(PROTO_SOURCES_DIR + 'messages-thp.proto') +if PYOPT != '0': + exclude_list.append(PROTO_SOURCES_DIR + 'messages-debug.proto') PROTO_SOURCES = Glob(PROTO_SOURCES_DIR + '*.proto', exclude=exclude_list @@ -602,12 +604,14 @@ if FROZEN: SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/wire/codec/*.py')) SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'storage/*.py', - exclude=[ - SOURCE_PY_DIR + 'storage/sd_salt.py', - ] if not SDCARD else [] + exclude=( + ([SOURCE_PY_DIR + 'storage/sd_salt.py'] if not SDCARD else []) + + ([SOURCE_PY_DIR + 'storage/debug.py'] if PYOPT != '0' else []) + ) )) SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/messages/__init__.py')) + SOURCE_PY_DEBUG_ENUMS = [SOURCE_PY_DIR + 'trezor/enums/Debug*.py'] SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/enums/*.py', exclude=[ SOURCE_PY_DIR + 'trezor/enums/Binance*.py', @@ -622,7 +626,7 @@ if FROZEN: SOURCE_PY_DIR + 'trezor/enums/Stellar*.py', SOURCE_PY_DIR + 'trezor/enums/Tezos*.py', SOURCE_PY_DIR + 'trezor/enums/Zcash*.py', - ]) + ] + (SOURCE_PY_DEBUG_ENUMS if PYOPT != '0' else [])) ) SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/*.py')) @@ -631,7 +635,8 @@ if FROZEN: SOURCE_PY_DIR + 'apps/common/sdcard.py', ] if not SDCARD else [] )) - SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/debug/*.py')) + if PYOPT == '0': + 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=[ diff --git a/core/SConscript.unix b/core/SConscript.unix index d2d60cb566..dc282f902d 100644 --- a/core/SConscript.unix +++ b/core/SConscript.unix @@ -559,6 +559,8 @@ PROTO_SOURCES_DIR = '../../../common/protob/' exclude_list = [PROTO_SOURCES_DIR + 'messages-bootloader.proto'] if not THP: exclude_list.append(PROTO_SOURCES_DIR + 'messages-thp.proto') +if PYOPT != '0': + exclude_list.append(PROTO_SOURCES_DIR + 'messages-debug.proto') PROTO_SOURCES = Glob(PROTO_SOURCES_DIR + '*.proto', exclude=exclude_list @@ -656,12 +658,14 @@ if FROZEN: SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/wire/codec/*.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 [] + exclude=( + ([SOURCE_PY_DIR + 'storage/sd_salt.py'] if 'sd_card' not in FEATURES_AVAILABLE else []) + + ([SOURCE_PY_DIR + 'storage/debug.py'] if PYOPT != '0' else []) + ) )) SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/messages/__init__.py')) + SOURCE_PY_DEBUG_ENUMS = [SOURCE_PY_DIR + 'trezor/enums/Debug*.py'] SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/enums/*.py', exclude=[ SOURCE_PY_DIR + 'trezor/enums/Binance*.py', @@ -676,7 +680,7 @@ if FROZEN: SOURCE_PY_DIR + 'trezor/enums/Stellar*.py', SOURCE_PY_DIR + 'trezor/enums/Tezos*.py', SOURCE_PY_DIR + 'trezor/enums/Zcash*.py', - ]) + ] + (SOURCE_PY_DEBUG_ENUMS if PYOPT != '0' else [])) ) SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/*.py')) @@ -685,7 +689,8 @@ if FROZEN: SOURCE_PY_DIR + 'apps/common/sdcard.py', ] if "sd_card" not in FEATURES_AVAILABLE else [] )) - SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/debug/*.py')) + if PYOPT == '0': + 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=[ diff --git a/core/embed/rust/librust_qstr.h b/core/embed/rust/librust_qstr.h index af2c848b55..c8ad911f01 100644 --- a/core/embed/rust/librust_qstr.h +++ b/core/embed/rust/librust_qstr.h @@ -235,8 +235,6 @@ static void _librust_qstrs(void) { MP_QSTR_danger; MP_QSTR_data_hash; MP_QSTR_data_len; - MP_QSTR_debug__loading_seed; - MP_QSTR_debug__loading_seed_not_recommended; MP_QSTR_decode; MP_QSTR_deinit; MP_QSTR_description; @@ -366,7 +364,6 @@ static void _librust_qstrs(void) { MP_QSTR_modify_fee__transaction_fee; MP_QSTR_more_info_callback; MP_QSTR_multiple_pages_texts; - MP_QSTR_nostr__event_kind_template; MP_QSTR_notification; MP_QSTR_notification_level; MP_QSTR_page_count; @@ -1130,6 +1127,7 @@ static void _librust_qstrs(void) { MP_QSTR_nem__under_namespace; MP_QSTR_nem__unencrypted; MP_QSTR_nem__unknown_mosaic; + MP_QSTR_nostr__event_kind_template; MP_QSTR_ripple__confirm_tag; MP_QSTR_ripple__destination_tag_template; MP_QSTR_solana__account_index; @@ -1245,4 +1243,8 @@ static void _librust_qstrs(void) { MP_QSTR_u2f__title_get; MP_QSTR_u2f__title_set; #endif +#if !PYOPT + MP_QSTR_debug__loading_seed; + MP_QSTR_debug__loading_seed_not_recommended; +#endif } diff --git a/core/embed/rust/librust_qstr.h.mako b/core/embed/rust/librust_qstr.h.mako index e5b41ea13c..4fe2b8b8cf 100644 --- a/core/embed/rust/librust_qstr.h.mako +++ b/core/embed/rust/librust_qstr.h.mako @@ -13,21 +13,6 @@ from typing import Union, Set RUST_SRC = THIS_FILE.parent / "src" -ALTCOIN_PREFIXES = ( - "binance", - "cardano", - "eos", - "ethereum", - "fido", - "monero", - "nem", - "ripple", - "solana", - "stellar", - "tezos", - "u2f", -) - def find_unique_patterns_in_dir(directory: Union[str, Path], pattern: str) -> Set[str]: command = f"grep -ro '{pattern}' {directory}" result = subprocess.run(command, stdout=subprocess.PIPE, text=True, shell=True) @@ -42,12 +27,18 @@ for prefix in ALTCOIN_PREFIXES: mp_prefix = f"MP_QSTR_{prefix}__" qstrings_universal |= {qstr for qstr in qstrings if qstr.startswith(mp_prefix)} -qstrings_btconly = qstrings - qstrings_universal +qstrings_debug = set() +for prefix in DEBUG_PREFIXES: + mp_prefix = f"MP_QSTR_{prefix}__" + qstrings_debug |= {qstr for qstr in qstrings if qstr.startswith(mp_prefix)} + +qstrings_btconly = qstrings - qstrings_universal - qstrings_debug # sort result alphabetically digits = range(10) qstrings_btconly_sorted = sorted(qstrings_btconly) qstrings_universal_sorted = sorted(qstrings_universal) +qstrings_debug_sorted = sorted(qstrings_debug) %>\ % for digit in digits: MP_QSTR_${digit}; @@ -60,4 +51,9 @@ qstrings_universal_sorted = sorted(qstrings_universal) ${qstr}; % endfor #endif +#if !PYOPT +% for qstr in qstrings_debug_sorted: + ${qstr}; +% endfor +#endif } diff --git a/core/embed/rust/src/translations/generated/translated_string.rs b/core/embed/rust/src/translations/generated/translated_string.rs index 99c6e280c1..8c227b39e8 100644 --- a/core/embed/rust/src/translations/generated/translated_string.rs +++ b/core/embed/rust/src/translations/generated/translated_string.rs @@ -354,7 +354,9 @@ pub enum TranslatedString { confirm_total__sending_from_account = 221, // "Sending from account:" confirm_total__title_fee = 222, // "Fee info" confirm_total__title_sending_from = 223, // "Sending from" + #[cfg(feature = "debug")] debug__loading_seed = 224, // "Loading seed" + #[cfg(feature = "debug")] debug__loading_seed_not_recommended = 225, // "Loading private seed is not recommended." device_name__change_template = 226, // "Change device name to {0}?" device_name__title = 227, // "Device name" @@ -1757,7 +1759,9 @@ impl TranslatedString { Self::confirm_total__sending_from_account => "Sending from account:", Self::confirm_total__title_fee => "Fee info", Self::confirm_total__title_sending_from => "Sending from", + #[cfg(feature = "debug")] Self::debug__loading_seed => "Loading seed", + #[cfg(feature = "debug")] Self::debug__loading_seed_not_recommended => "Loading private seed is not recommended.", Self::device_name__change_template => "Change device name to {0}?", Self::device_name__title => "Device name", @@ -3159,7 +3163,9 @@ impl TranslatedString { Qstr::MP_QSTR_confirm_total__sending_from_account => Some(Self::confirm_total__sending_from_account), Qstr::MP_QSTR_confirm_total__title_fee => Some(Self::confirm_total__title_fee), Qstr::MP_QSTR_confirm_total__title_sending_from => Some(Self::confirm_total__title_sending_from), + #[cfg(feature = "debug")] Qstr::MP_QSTR_debug__loading_seed => Some(Self::debug__loading_seed), + #[cfg(feature = "debug")] Qstr::MP_QSTR_debug__loading_seed_not_recommended => Some(Self::debug__loading_seed_not_recommended), Qstr::MP_QSTR_device_name__change_template => Some(Self::device_name__change_template), Qstr::MP_QSTR_device_name__title => Some(Self::device_name__title), diff --git a/core/embed/rust/src/translations/generated/translated_string.rs.mako b/core/embed/rust/src/translations/generated/translated_string.rs.mako index 62ac106a3f..cc10a9e03b 100644 --- a/core/embed/rust/src/translations/generated/translated_string.rs.mako +++ b/core/embed/rust/src/translations/generated/translated_string.rs.mako @@ -7,22 +7,6 @@ import json import re -ALTCOIN_PREFIXES = ( - "binance", - "cardano", - "eos", - "ethereum", - "fido", - "monero", - "nem", - "nostr", - "ripple", - "solana", - "stellar", - "tezos", - "u2f", -) - TR_DIR = ROOT / "core" / "translations" order_file = TR_DIR / "order.json" @@ -53,6 +37,9 @@ pub enum TranslatedString { %if any(name.startswith(prefix + "__") for prefix in ALTCOIN_PREFIXES): #[cfg(feature = "universal_fw")] %endif + %if any(name.startswith(prefix + "__") for prefix in DEBUG_PREFIXES): + #[cfg(feature = "debug")] + %endif ${name} = ${idx}, // ${encode_str(en_data.get(name))} % endfor } @@ -69,11 +56,15 @@ impl TranslatedString { continue layouts_dict = value if isinstance(value, dict) else None universal_fw = any(name.startswith(prefix + "__") for prefix in ALTCOIN_PREFIXES) + is_debug = any(name.startswith(prefix + "__") for prefix in DEBUG_PREFIXES) %>\ %if layouts_dict is not None: % for layout_name, layout_value in layouts_dict.items(): %if universal_fw: #[cfg(feature = "universal_fw")] + %endif + %if is_debug: + #[cfg(feature = "debug")] %endif #[cfg(feature = "${f"layout_{layout_name.lower()}"}")] Self::${name} => ${encode_str(layout_value)}, @@ -81,6 +72,9 @@ impl TranslatedString { %else: %if universal_fw: #[cfg(feature = "universal_fw")] + %endif + %if is_debug: + #[cfg(feature = "debug")] %endif Self::${name} => ${encode_str(value)}, %endif @@ -99,6 +93,9 @@ impl TranslatedString { %if any(name.startswith(prefix + "__") for prefix in ALTCOIN_PREFIXES): #[cfg(feature = "universal_fw")] %endif + %if any(name.startswith(prefix + "__") for prefix in DEBUG_PREFIXES): + #[cfg(feature = "debug")] + %endif Qstr::MP_QSTR_${name} => Some(Self::${name}), % endfor _ => None, diff --git a/core/src/trezor/enums/MessageType.py b/core/src/trezor/enums/MessageType.py index effd64f319..c47eb8aa29 100644 --- a/core/src/trezor/enums/MessageType.py +++ b/core/src/trezor/enums/MessageType.py @@ -82,26 +82,27 @@ SignIdentity = 53 SignedIdentity = 54 GetECDHSessionKey = 61 ECDHSessionKey = 62 -DebugLinkDecision = 100 -DebugLinkGetState = 101 -DebugLinkState = 102 -DebugLinkStop = 103 -DebugLinkLog = 104 -DebugLinkMemoryRead = 110 -DebugLinkMemory = 111 -DebugLinkMemoryWrite = 112 -DebugLinkFlashErase = 113 -DebugLinkLayout = 9001 -DebugLinkReseedRandom = 9002 -DebugLinkRecordScreen = 9003 -DebugLinkEraseSdCard = 9005 -DebugLinkWatchLayout = 9006 -DebugLinkResetDebugEvents = 9007 -DebugLinkOptigaSetSecMax = 9008 BenchmarkListNames = 9100 BenchmarkNames = 9101 BenchmarkRun = 9102 BenchmarkResult = 9103 +if __debug__: + DebugLinkDecision = 100 + DebugLinkGetState = 101 + DebugLinkState = 102 + DebugLinkStop = 103 + DebugLinkLog = 104 + DebugLinkMemoryRead = 110 + DebugLinkMemory = 111 + DebugLinkMemoryWrite = 112 + DebugLinkFlashErase = 113 + DebugLinkLayout = 9001 + DebugLinkReseedRandom = 9002 + DebugLinkRecordScreen = 9003 + DebugLinkEraseSdCard = 9005 + DebugLinkWatchLayout = 9006 + DebugLinkResetDebugEvents = 9007 + DebugLinkOptigaSetSecMax = 9008 if not utils.BITCOIN_ONLY: SetU2FCounter = 63 GetNextU2FCounter = 80 diff --git a/core/src/trezor/enums/_proto_enum_class.mako b/core/src/trezor/enums/_proto_enum_class.mako index 1ee5a6ce9f..e29b663697 100644 --- a/core/src/trezor/enums/_proto_enum_class.mako +++ b/core/src/trezor/enums/_proto_enum_class.mako @@ -6,12 +6,32 @@ from trezor import utils % endif -% for value in values_always: +<% +values_debug = [v for v in values_always if v.name.startswith('DebugLink')] +values_nondebug = [v for v in values_always if not v.name.startswith('DebugLink')] +%>\ +% for value in values_nondebug: ${value.name} = ${value.number} % endfor -% if values_altcoin: -if not utils.BITCOIN_ONLY: -% for value in values_altcoin: +% if values_debug: +if __debug__: +% for value in values_debug: ${value.name} = ${value.number} % endfor % endif +% if values_altcoin: +if not utils.BITCOIN_ONLY: +<% +values_debug = [v for v in values_altcoin if v.name.startswith('DebugLink')] +values_nondebug = [v for v in values_altcoin if not v.name.startswith('DebugLink')] +%>\ +% for value in values_nondebug: + ${value.name} = ${value.number} +% endfor +% if values_debug: + if __debug__: +% for value in values_debug: + ${value.name} = ${value.number} +% endfor +% endif +% endif