build(core): exclude haptic & led code if possible
What changed, and why it matters
This is a harmless build-system cleanup. It teaches the firmware build scripts to remove haptic (vibration) and RGB LED code from devices that do not have those hardware features, and it sorts the list of feature flags alphabetically for easier reading. There is no security bug being fixed here.
No security action required. Treat as a normal build optimization/refactoring commit.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit adds two new feature flags, use_haptic and use_rgb_led, to the MicroPython frozen-module preprocessing step in the SCons build scripts. These flags are passed through to a sed-based preprocessor that replaces runtime checks such as utils.USE_HAPTIC and utils.USE_RGB_LED with literal True/False constants, allowing dead-code elimination for hardware variants that lack haptic or RGB LED support. The change also reorders the existing feature variables alphabetically. No runtime behavior changes for already-supported features; only build-time code exclusion is affected.
Changed components
core/SConscript.firmwarecore/SConscript.unixcore/site_scons/site_tools/micropython/__init__.pyInspect captured patch +24 / −16
diff --git a/core/SConscript.firmware b/core/SConscript.firmware
index 5757e6ee..d8af60e6 100644
--- a/core/SConscript.firmware
+++ b/core/SConscript.firmware
@@ -861,6 +861,8 @@ if FROZEN:
tropic='tropic' in FEATURES_AVAILABLE,
use_ble='ble' in FEATURES_AVAILABLE,
use_button='button' in FEATURES_AVAILABLE,
+ use_haptic='haptic' in FEATURES_AVAILABLE,
+ use_rgb_led='rgb_led' in FEATURES_AVAILABLE,
use_touch='touch' in FEATURES_AVAILABLE,
ui_layout=ui.get_ui_layout(TREZOR_MODEL),
thp=THP,
diff --git a/core/SConscript.unix b/core/SConscript.unix
index 11f322e2..68085cfb 100644
--- a/core/SConscript.unix
+++ b/core/SConscript.unix
@@ -879,6 +879,8 @@ if FROZEN:
tropic='tropic' in FEATURES_AVAILABLE,
use_ble='ble' in FEATURES_AVAILABLE,
use_button='button' in FEATURES_AVAILABLE,
+ use_haptic='haptic' in FEATURES_AVAILABLE,
+ use_rgb_led='rgb_led' in FEATURES_AVAILABLE,
use_touch='touch' in FEATURES_AVAILABLE,
ui_layout=ui.get_ui_layout(TREZOR_MODEL),
thp=THP,
diff --git a/core/site_scons/site_tools/micropython/__init__.py b/core/site_scons/site_tools/micropython/__init__.py
index a5b89754..eb18dea1 100644
--- a/core/site_scons/site_tools/micropython/__init__.py
+++ b/core/site_scons/site_tools/micropython/__init__.py
@@ -47,41 +47,45 @@ def generate(env):
target = str(target[0])
source = str(source[0])
source_name = source.replace(env["source_dir"], "")
- # replace "utils.BITCOIN_ONLY" with literal constant (True/False)
+ # replace "utils.BITCOIN_ONLY" or "utils.USE_<FEATURE>" with literal constant (True/False)
# so the compiler can optimize out the things we don't want
- btc_only = env["bitcoin_only"] == "1"
backlight = env["backlight"]
- optiga = env["optiga"]
- tropic = env["tropic"]
- touch = env["use_touch"]
- button = env["use_button"]
ble = env["use_ble"]
+ btc_only = env["bitcoin_only"] == "1"
+ button = env["use_button"]
+ haptic = env["use_haptic"]
layout_bolt = env["ui_layout"] == "UI_LAYOUT_BOLT"
layout_caesar = env["ui_layout"] == "UI_LAYOUT_CAESAR"
layout_delizia = env["ui_layout"] == "UI_LAYOUT_DELIZIA"
layout_eckhart = env["ui_layout"] == "UI_LAYOUT_ECKHART"
- thp = env["thp"]
+ n4w1 = env["n4w1"]
+ optiga = env["optiga"]
power_manager = env["power_manager"]
+ rgb_led = env["use_rgb_led"]
telemetry = env["telemetry"]
- n4w1 = env["n4w1"]
+ thp = env["thp"]
+ touch = env["use_touch"]
+ tropic = env["tropic"]
include_source_lines = env["include_source_lines"]
interim = f"{target[:-4]}.i" # replace .mpy with .i
sed_scripts = [
- 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\.USE_TROPIC/{tropic}/g'",
+ rf"-e 's/utils\.USE_BLE/{ble}/g'",
+ rf"-e 's/utils\.BITCOIN_ONLY/{btc_only}/g'",
+ rf"-e 's/utils\.USE_BUTTON/{button}/g'",
+ rf"-e 's/utils\.USE_HAPTIC/{haptic}/g'",
rf"-e 's/utils\.UI_LAYOUT == \"BOLT\"/{layout_bolt}/g'",
rf"-e 's/utils\.UI_LAYOUT == \"CAESAR\"/{layout_caesar}/g'",
rf"-e 's/utils\.UI_LAYOUT == \"DELIZIA\"/{layout_delizia}/g'",
rf"-e 's/utils\.UI_LAYOUT == \"ECKHART\"/{layout_eckhart}/g'",
- rf"-e 's/utils\.USE_BLE/{ble}/g'",
- rf"-e 's/utils\.USE_BUTTON/{button}/g'",
- rf"-e 's/utils\.USE_TOUCH/{touch}/g'",
- rf"-e 's/utils\.USE_THP/{thp}/g'",
+ rf"-e 's/utils\.USE_N4W1/{n4w1}/g'",
+ rf"-e 's/utils\.USE_OPTIGA/{optiga}/g'",
rf"-e 's/utils\.USE_POWER_MANAGER/{power_manager}/g'",
+ rf"-e 's/utils\.USE_RGB_LED/{rgb_led}/g'",
rf"-e 's/utils\.USE_TELEMETRY/{telemetry}/g'",
- rf"-e 's/utils\.USE_N4W1/{n4w1}/g'",
+ rf"-e 's/utils\.USE_THP/{thp}/g'",
+ rf"-e 's/utils\.USE_TOUCH/{touch}/g'",
+ rf"-e 's/utils\.USE_TROPIC/{tropic}/g'",
r"-e 's/if TYPE_CHECKING/if False/'",
r"-e 's/import typing/# &/'",
r"-e '/from typing import (/,/^[[:space:]]*)/ {s/^/# /; }'",
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.