refactor(core): remove model feature dependencies
What changed, and why it matters
This commit is a build-system cleanup. It removes duplicated 'model' and 'privilege mode' feature flags from several Rust package files and makes those packages inherit them from a shared 'models' crate instead. It also replaces a hard-coded list of Trezor model names with code that reads them from a directory, and splits a couple of cryptocurrency features (NEM, EOS, Decred) out from being tied to a specific model. There is no user-facing bug fix or security patch here.
No security action required. Treat as ordinary build-system maintenance. Reviewers may verify that the new feature forwarding still produces the same firmware variants as before, but this is a correctness/QA concern, not a security issue.
Security signals we found
No security-relevant code change: purely build/feature refactoring
No changelog entry indicates not treated as a fix by the vendor
No references to vulnerabilities, CVEs, or security researchers
Feature gating for NEM/EOS/Decred is reorganized but equivalent in intent
Evidence from the diff
The change refactors Cargo.toml feature forwarding in core/embed/{rtl,sec,sys,upymod}. Model features (model_t2t1, model_t3w1, etc.) and privilege features (kernel_mode, secure_mode) are removed from intermediate crates and forwarded directly through the workspace ‘models’ crate. The xbuild helper gains a model_ids() function that scans ../models/*/model.toml instead of using a hard-coded array. upymod/build.rs now uses current_model_id() and explicit coin features (eos, nem, decred) rather than gating those coins on model_t2t1. The commit is tagged [no changelog] and contains no runtime logic changes.
Changed components
core/embed/rtl/Cargo.tomlcore/embed/rtl/build.rscore/embed/sec/Cargo.tomlcore/embed/sys/Cargo.tomlcore/embed/upymod/Cargo.tomlcore/embed/upymod/build.rscore/embed/xbuild/src/trezor.rscore/embed/xbuild/src/lib.rscore/embed/Cargo.lockInspect captured patch +72 / −88
diff --git a/core/embed/Cargo.lock b/core/embed/Cargo.lock
index dfcf5776..7882a814 100644
--- a/core/embed/Cargo.lock
+++ b/core/embed/Cargo.lock
@@ -425,6 +425,7 @@ name = "io"
version = "0.0.0"
dependencies = [
"color-eyre",
+ "models",
"sec",
"sys",
"xbuild",
diff --git a/core/embed/rtl/Cargo.toml b/core/embed/rtl/Cargo.toml
index 5618fa4c..81ee9a82 100644
--- a/core/embed/rtl/Cargo.toml
+++ b/core/embed/rtl/Cargo.toml
@@ -14,34 +14,6 @@ models.workspace = true
[features]
-# --------------------------------------------------------------------------
-# Model features
-# --------------------------------------------------------------------------
-
-model_d001 = ["models/model_d001"]
-model_d002 = ["models/model_d002"]
-model_t2t1 = ["models/model_t2t1"]
-model_t2b1 = ["models/model_t2b1"]
-model_t3b1 = ["models/model_t3b1"]
-model_t3t1 = ["models/model_t3t1"]
-model_t3w1 = ["models/model_t3w1"]
-
-# --------------------------------------------------------------------------
-# MCU features
-# --------------------------------------------------------------------------
-
-mcu_stm32f427 = ["models/mcu_stm32f427"]
-mcu_stm32f429 = ["models/mcu_stm32f429"]
-mcu_stm32u58 = ["models/mcu_stm32u58"]
-mcu_stm32u5g = ["models/mcu_stm32u5g"]
-
-# --------------------------------------------------------------------------
-# Privilege mode features
-# --------------------------------------------------------------------------
-
-kernel_mode = ["models/kernel_mode"]
-secure_mode = ["models/secure_mode"]
-
# --------------------------------------------------------------------------
# Selectable features
# --------------------------------------------------------------------------
@@ -49,8 +21,10 @@ secure_mode = ["models/secure_mode"]
aes_gcm = []
ed25519_no_precomp = []
emulator = ["insecure_prng", "models/emulator"]
+eos = []
insecure_prng = []
mldsa = []
+nem = []
noise = ["aes_gcm"]
production = ["models/production"]
secp256k1_zkp = []
@@ -59,9 +33,9 @@ sprintf = []
universal_fw = []
test = [
- "mcu_stm32u5g",
- "model_t3w1",
+ "models/model_t3w1",
"emulator",
- "kernel_mode",
- "secure_mode",
]
+
+
+
diff --git a/core/embed/rtl/build.rs b/core/embed/rtl/build.rs
index 42dc63a6..6299f66a 100644
--- a/core/embed/rtl/build.rs
+++ b/core/embed/rtl/build.rs
@@ -90,9 +90,10 @@ fn add_crypto(lib: &mut xbuild::CLibrary) -> Result<()> {
("USE_CARDANO", val),
]);
- let val = cfg!(feature = "universal_fw") && cfg!(feature = "model_t2t1");
- let val = Some(if val { "1" } else { "0" });
- lib.add_defines([("USE_NEM", val), ("USE_EOS", val)]);
+ let nem = cfg!(feature = "universal_fw") && cfg!(feature = "nem");
+ lib.add_define("USE_NEM", Some(if nem { "1" } else { "0" }));
+ let eos = cfg!(feature = "universal_fw") && cfg!(feature = "eos");
+ lib.add_define("USE_EOS", Some(if eos { "1" } else { "0" }));
if cfg!(feature = "ed25519_no_precomp") {
lib.add_define("ED25519_NO_PRECOMP", None);
diff --git a/core/embed/sec/Cargo.toml b/core/embed/sec/Cargo.toml
index e5874a96..b0c2b2de 100644
--- a/core/embed/sec/Cargo.toml
+++ b/core/embed/sec/Cargo.toml
@@ -15,18 +15,6 @@ models.workspace = true
[features]
-# --------------------------------------------------------------------------
-# Model features
-# --------------------------------------------------------------------------
-
-model_d001 = ["sys/model_d001"]
-model_d002 = ["sys/model_d002"]
-model_t2t1 = ["sys/model_t2t1"]
-model_t2b1 = ["sys/model_t2b1"]
-model_t3b1 = ["sys/model_t3b1"]
-model_t3t1 = ["sys/model_t3t1"]
-model_t3w1 = ["sys/model_t3w1"]
-
# --------------------------------------------------------------------------
# MCU features
# --------------------------------------------------------------------------
@@ -77,7 +65,7 @@ trustzone = ["sys/trustzone"]
test = [
"mcu_stm32u5g",
- "model_t3w1",
+ "models/model_t3w1",
"emulator",
"kernel_mode",
"secure_mode",
diff --git a/core/embed/sys/Cargo.toml b/core/embed/sys/Cargo.toml
index ff9fe015..60029463 100644
--- a/core/embed/sys/Cargo.toml
+++ b/core/embed/sys/Cargo.toml
@@ -18,17 +18,17 @@ models.workspace = true
# MCU features
# --------------------------------------------------------------------------
-mcu_stm32f427 = ["rtl/mcu_stm32f427", "mcu_stm32f4"]
-mcu_stm32f429 = ["rtl/mcu_stm32f429", "mcu_stm32f4"]
-mcu_stm32u58 = ["rtl/mcu_stm32u58", "mcu_stm32u5"]
-mcu_stm32u5g = ["rtl/mcu_stm32u5g", "mcu_stm32u5"]
+mcu_stm32f427 = ["models/mcu_stm32f427", "mcu_stm32f4"]
+mcu_stm32f429 = ["models/mcu_stm32f429", "mcu_stm32f4"]
+mcu_stm32u58 = ["models/mcu_stm32u58", "mcu_stm32u5"]
+mcu_stm32u5g = ["models/mcu_stm32u5g", "mcu_stm32u5"]
# --------------------------------------------------------------------------
# Privilege mode features
# --------------------------------------------------------------------------
-kernel_mode = ["rtl/kernel_mode"]
-secure_mode = ["rtl/secure_mode"]
+kernel_mode = ["models/kernel_mode"]
+secure_mode = ["models/secure_mode"]
# --------------------------------------------------------------------------
# Selectable components
diff --git a/core/embed/upymod/Cargo.toml b/core/embed/upymod/Cargo.toml
index 176e6d71..b97992e1 100644
--- a/core/embed/upymod/Cargo.toml
+++ b/core/embed/upymod/Cargo.toml
@@ -16,18 +16,6 @@ io.workspace = true
[features]
-# --------------------------------------------------------------------------
-# Model features
-# --------------------------------------------------------------------------
-
-model_d001 = ["io/model_d001"]
-model_d002 = ["io/model_d002"]
-model_t2t1 = ["io/model_t2t1"]
-model_t2b1 = ["io/model_t2b1"]
-model_t3b1 = ["io/model_t3b1"]
-model_t3t1 = ["io/model_t3t1"]
-model_t3w1 = ["io/model_t3w1"]
-
# --------------------------------------------------------------------------
# MCU features
# --------------------------------------------------------------------------
@@ -46,9 +34,11 @@ backlight = ["io/backlight"]
benchmark = []
ble = ["io/ble"]
button = ["io/button"]
+decred = []
disable_animation = []
enable_source_lines = []
emulator = ["io/emulator"]
+eos = []
frozen = []
haptic = ["io/haptic"]
layout_bolt = []
@@ -59,6 +49,7 @@ log_stack_usage = []
mcu_attestation = ["sec/mcu_attestation"]
memperf = []
n4w1 = []
+nem = []
optiga = ["sec/optiga"]
power_manager = ["io/power_manager"]
pyopt = []
diff --git a/core/embed/upymod/build.rs b/core/embed/upymod/build.rs
index 7cad7fa8..484b67bf 100644
--- a/core/embed/upymod/build.rs
+++ b/core/embed/upymod/build.rs
@@ -7,7 +7,10 @@ use std::{
path::{Path, PathBuf},
};
-use xbuild::{CLibrary, InputFiles, Result, WrapErr, bail, bail_unsupported, ensure};
+use xbuild::{
+ CLibrary, InputFiles, Result, WrapErr, bail, bail_unsupported, current_model_id, ensure,
+ model_ids,
+};
fn main() -> Result<()> {
xbuild::build(|lib| {
@@ -402,6 +405,7 @@ struct MpyBuilder<'a> {
genhdr_dir: PathBuf,
py_src_dir: PathBuf,
scm_revision_xor2: u8,
+ current_model: String,
}
impl<'a> MpyBuilder<'a> {
@@ -411,6 +415,7 @@ impl<'a> MpyBuilder<'a> {
let py_src_dir = crate_dir.join("../../src");
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
let genhdr_dir = out_dir.join("genhdr");
+ let current_model = current_model_id()?;
Self {
lib,
@@ -420,6 +425,7 @@ impl<'a> MpyBuilder<'a> {
genhdr_dir,
py_src_dir,
scm_revision_xor2,
+ current_model,
}
}
@@ -962,17 +968,9 @@ impl<'a> MpyBuilder<'a> {
r"s/from typing import/# &/".to_string(),
];
- for model in ["T2T1", "T2B1", "T3T1", "T3B1", "T3W1"] {
- let model_matches = match model {
- "D001" => cfg!(feature = "model_d001"),
- "D002" => cfg!(feature = "model_d002"),
- "T2T1" => cfg!(feature = "model_t2t1"),
- "T2B1" => cfg!(feature = "model_t2b1"),
- "T3T1" => cfg!(feature = "model_t3t1"),
- "T3B1" => cfg!(feature = "model_t3b1"),
- "T3W1" => cfg!(feature = "model_t3w1"),
- _ => bail_unsupported!(),
- };
+ let models_dir = self.crate_dir.join("../models");
+ for model in model_ids(&models_dir)? {
+ let model_matches = model == self.current_model;
let model_cond = py_bool(model_matches);
let not_model_cond = py_bool(!model_matches);
@@ -995,6 +993,7 @@ impl<'a> MpyBuilder<'a> {
let mut files = InputFiles::new();
let src = &self.py_src_dir;
+ let current_model = &self.current_model;
files.add(src, "*.py")?;
@@ -1110,14 +1109,14 @@ impl<'a> MpyBuilder<'a> {
if cfg!(not(feature = "pyopt")) {
files.add(src, "apps/debug/*.py")?;
- if cfg!(not(feature = "model_t3w1")) {
+ if current_model != "T3W1" {
files.remove(src, "apps/debug/n4w1_mock.py");
}
}
files.add(src, "apps/homescreen/*.py")?;
- if cfg!(not(feature = "model_t3w1")) {
+ if current_model != "T3W1" {
files.remove(src, "apps/homescreen/device_menu.py");
}
@@ -1181,7 +1180,7 @@ impl<'a> MpyBuilder<'a> {
files.add(src, "apps/cardano/*/*.py")?;
files.add(src, "trezor/enums/Cardano*.py")?;
- if cfg!(feature = "model_t2t1") {
+ if cfg!(feature = "eos") {
files.add(src, "apps/eos/*.py")?;
files.add(src, "apps/eos/*/*.py")?;
files.add(src, "trezor/enums/Eos*.py")?;
@@ -1196,7 +1195,7 @@ impl<'a> MpyBuilder<'a> {
files.add(src, "trezor/enums/DebugMonero*.py")?;
files.add(src, "trezor/enums/Monero*.py")?;
- if cfg!(feature = "model_t2t1") {
+ if cfg!(feature = "nem") {
files.add(src, "apps/nem/*.py")?;
files.add(src, "apps/nem/*/*.py")?;
files.add(src, "trezor/enums/NEM*.py")?;
@@ -1229,7 +1228,7 @@ impl<'a> MpyBuilder<'a> {
files.add(src, "apps/webauthn/*.py")?;
- if cfg!(feature = "model_t2t1") {
+ if cfg!(feature = "decred") {
files.add(src, "apps/bitcoin/sign_tx/decred.py")?;
}
diff --git a/core/embed/xbuild/src/lib.rs b/core/embed/xbuild/src/lib.rs
index 8ea44068..9e3f67bb 100644
--- a/core/embed/xbuild/src/lib.rs
+++ b/core/embed/xbuild/src/lib.rs
@@ -27,6 +27,7 @@ pub use parallel::run_parallel;
pub use trezor::build;
pub use trezor::build_and_link;
pub use trezor::current_model_id;
+pub use trezor::model_ids;
pub use trezor::vendor_header_path;
// Re-exports from color_eyre
diff --git a/core/embed/xbuild/src/trezor.rs b/core/embed/xbuild/src/trezor.rs
index 4dc83e52..7327dafb 100644
--- a/core/embed/xbuild/src/trezor.rs
+++ b/core/embed/xbuild/src/trezor.rs
@@ -6,11 +6,14 @@
//! them together.
use std::{
- env,
+ env, fs,
path::{Path, PathBuf},
};
-use color_eyre::{Result, eyre::bail};
+use color_eyre::{
+ Result,
+ eyre::{WrapErr, bail},
+};
use crate::CLibrary;
use crate::helpers::{is_rust_analyzer, links_name};
@@ -21,10 +24,36 @@ fn package_name() -> Result<String> {
/// Returns the current model id (T2T1, ..) from the DEP_MODELS_MODEL
/// environment variable emitted by the `models` crate's build script.
+///
+/// The variable is empty when no model feature is selected; that is treated as
+/// an error since callers need a concrete model.
pub fn current_model_id() -> Result<String> {
- env::var("DEP_MODELS_MODEL").map_err(|_| {
- color_eyre::eyre::eyre!("DEP_MODELS_MODEL not set — is `models` a direct dependency?")
- })
+ let model = env::var("DEP_MODELS_MODEL").unwrap_or_default();
+ if model.is_empty() {
+ bail!(
+ "DEP_MODELS_MODEL is unset or empty — is `models` a direct dependency with a model feature selected?"
+ );
+ }
+ Ok(model)
+}
+
+/// Returns the sorted list of model ids found in `models_dir` — the names of
+/// subdirectories that contain a `model.toml`. Emits `rerun-if-changed` for the
+/// directory and each `model.toml` so callers rebuild when the model set changes.
+pub fn model_ids(models_dir: &Path) -> Result<Vec<String>> {
+ println!("cargo::rerun-if-changed={}", models_dir.display());
+ let mut models = Vec::new();
+ for entry in fs::read_dir(models_dir).context("Failed to read models directory")? {
+ let entry = entry?;
+ let model_toml = entry.path().join("model.toml");
+ if !model_toml.exists() {
+ continue;
+ }
+ println!("cargo::rerun-if-changed={}", model_toml.display());
+ models.push(entry.file_name().to_string_lossy().into_owned());
+ }
+ models.sort();
+ Ok(models)
}
/// Returns the path to the vendor header binary for the given build target.
Why this scored 12/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.