build(core): exclude src if feature not available
What changed, and why it matters
This is a routine build-system cleanup for the Trezor hardware wallet firmware. It makes sure that certain device-specific source files (for example, code that talks to a security chip called Optiga, or code that adjusts screen backlight) are only included in firmware builds for devices that actually have those hardware features. There is no indication this fixes a security vulnerability or changes runtime behavior on supported devices.
No security action required. Treat as normal build maintenance.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit modifies SCons build scripts (core/SConscript.firmware and core/SConscript.unix) to consistently exclude Python source modules from frozen firmware images when the corresponding hardware feature is unavailable. It introduces boolean variables (SDCARD, OPTIGA, SERIAL_NUMBER, BACKLIGHT) derived from FEATURES_AVAILABLE and uses them to exclude apps/management/authenticate_device.py when Optiga is absent, apps/management/set_brightness.py when backlight is absent, and refactors existing sd_card/serial_number exclusions. It also passes precomputed BACKLIGHT/OPTIGA booleans to the frozen manifest generator instead of recomputing feature membership. The commit message explicitly states the handlers were already correctly excluded from workflow_handlers.py, so this is purely a build hygiene change.
Changed components
core/SConscript.firmwarecore/SConscript.unixInspect captured patch +23 / −16
diff --git a/core/SConscript.firmware b/core/SConscript.firmware
index 78c70225..898cac99 100644
--- a/core/SConscript.firmware
+++ b/core/SConscript.firmware
@@ -475,7 +475,9 @@ SOURCE_FIRMWARE = [
]
SDCARD = ('sd_card' in FEATURES_AVAILABLE)
+OPTIGA = ('optiga' in FEATURES_AVAILABLE)
SERIAL_NUMBER = ('serial_number' in FEATURES_AVAILABLE)
+BACKLIGHT = ('backlight' in FEATURES_AVAILABLE)
env.Tool('micropython')
@@ -740,7 +742,9 @@ if FROZEN:
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/management/*.py',
exclude=(
([SOURCE_PY_DIR + 'apps/management/sd_protect.py'] if not SDCARD else []) +
- ([SOURCE_PY_DIR + 'apps/management/get_serial_number.py'] if not SERIAL_NUMBER else [])
+ ([SOURCE_PY_DIR + 'apps/management/authenticate_device.py'] if not OPTIGA else []) +
+ ([SOURCE_PY_DIR + 'apps/management/get_serial_number.py'] if not SERIAL_NUMBER else []) +
+ ([SOURCE_PY_DIR + 'apps/management/set_brightness.py'] if not BACKLIGHT else [])
)
))
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/management/*/*.py',
@@ -832,13 +836,13 @@ if FROZEN:
source=SOURCE_PY,
source_dir=SOURCE_PY_DIR,
bitcoin_only=BITCOIN_ONLY,
- backlight='backlight' in FEATURES_AVAILABLE,
- optiga='optiga' in FEATURES_AVAILABLE,
+ backlight=BACKLIGHT,
+ optiga=OPTIGA,
+ tropic='tropic' in FEATURES_AVAILABLE,
use_ble='ble' in FEATURES_AVAILABLE,
use_button='button' in FEATURES_AVAILABLE,
use_touch='touch' in FEATURES_AVAILABLE,
ui_layout=ui.get_ui_layout(TREZOR_MODEL),
- tropic='tropic' in FEATURES_AVAILABLE,
thp=THP,
power_manager='power_manager' in FEATURES_AVAILABLE,
)
diff --git a/core/SConscript.unix b/core/SConscript.unix
index 3674d5f3..bdb74aa5 100644
--- a/core/SConscript.unix
+++ b/core/SConscript.unix
@@ -460,6 +460,11 @@ env = Environment(
FEATURES_AVAILABLE = models.configure_board(TREZOR_MODEL, HW_REVISION, FEATURES_WANTED, env, CPPDEFINES_HAL, SOURCE_UNIX, PATH_HAL)
+SDCARD = ('sd_card' in FEATURES_AVAILABLE)
+OPTIGA = ('optiga' in FEATURES_AVAILABLE)
+SERIAL_NUMBER = ('serial_number' in FEATURES_AVAILABLE)
+BACKLIGHT = ('backlight' in FEATURES_AVAILABLE)
+
env.Tool('micropython')
env.Replace(
@@ -663,7 +668,7 @@ if FROZEN:
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/*.py',
exclude=[
SOURCE_PY_DIR + 'trezor/sdcard.py',
- ] if 'sd_card' not in FEATURES_AVAILABLE 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'))
@@ -699,7 +704,7 @@ if FROZEN:
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 []) +
+ ([SOURCE_PY_DIR + 'storage/sd_salt.py'] if not SDCARD else []) +
([SOURCE_PY_DIR + 'storage/debug.py'] if PYOPT != '0' else []) +
([
SOURCE_PY_DIR + 'storage/cache_codec.py',
@@ -742,7 +747,7 @@ if FROZEN:
SOURCE_PY_DIR + 'apps/common/definitions.py',
SOURCE_PY_DIR + 'apps/common/definitions_constants.py',
] + (
- [SOURCE_PY_DIR + 'apps/common/sdcard.py'] if "sd_card" not in FEATURES_AVAILABLE else []
+ [SOURCE_PY_DIR + 'apps/common/sdcard.py'] if not SDCARD else []
)
))
if PYOPT == '0':
@@ -754,14 +759,12 @@ if FROZEN:
)
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 []
- ) + (
- [SOURCE_PY_DIR + 'apps/management/authenticate_device.py'] if "optiga" not in FEATURES_AVAILABLE else []
- ) + (
- [SOURCE_PY_DIR + 'apps/management/get_serial_number.py'] if "serial_number" not in FEATURES_AVAILABLE else []
+ ([SOURCE_PY_DIR + 'apps/management/sd_protect.py'] if not SDCARD else []) +
+ ([SOURCE_PY_DIR + 'apps/management/authenticate_device.py'] if not OPTIGA else []) +
+ ([SOURCE_PY_DIR + 'apps/management/get_serial_number.py'] if not SERIAL_NUMBER else []) +
+ ([SOURCE_PY_DIR + 'apps/management/set_brightness.py'] if not BACKLIGHT else [])
)
- )
- )
+ ))
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/management/*/*.py',
exclude=(
[SOURCE_PY_DIR + 'apps/management/ble/*.py'] if "ble" not in FEATURES_AVAILABLE else []
@@ -855,8 +858,8 @@ if FROZEN:
source=SOURCE_PY,
source_dir=SOURCE_PY_DIR,
bitcoin_only=BITCOIN_ONLY,
- backlight='backlight' in FEATURES_AVAILABLE,
- optiga='optiga' in FEATURES_AVAILABLE,
+ backlight=BACKLIGHT,
+ optiga=OPTIGA,
tropic='tropic' in FEATURES_AVAILABLE,
use_ble='ble' in FEATURES_AVAILABLE,
use_button='button' in FEATURES_AVAILABLE,
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.