feat(core/build): add reset command to xtask
What changed, and why it matters
This commit adds a new 'reset' command to the Trezor firmware's internal xtask build tool. It lets developers reset a connected Trezor device during development using OpenOCD, a hardware debugging tool. There is no indication this is a security fix or introduces a vulnerability.
No security action required. This is a routine developer-tooling feature addition.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change extends the xtask CLI (a Rust-based task runner used during Trezor firmware development) with a reset subcommand. It adds ResetArgs to the argument parser, dispatches the command in main.rs, and implements flash::reset() which invokes OpenOCD with init; reset; exit against the selected device model’s target config. The functionality is development/debugging tooling only and requires physical hardware access via an ST-Link debugger.
Changed components
core/embed/xtask/src/args.rscore/embed/xtask/src/flash.rscore/embed/xtask/src/main.rsInspect captured patch +31 / −1
diff --git a/core/embed/xtask/src/args.rs b/core/embed/xtask/src/args.rs
index d153ce38..7ca5f5f6 100644
--- a/core/embed/xtask/src/args.rs
+++ b/core/embed/xtask/src/args.rs
@@ -141,6 +141,8 @@ pub enum Cmd {
Flash(FlashArgs),
/// Erase flash or part of it using OpenOCD
FlashErase(FlashEraseArgs),
+ /// Reset the connected device using OpenOCD
+ Reset(ResetArgs),
/// Upload firmware to device
Upload(UploadArgs),
/// Combine multiple firmware projects into a single binary for flashing
@@ -326,6 +328,13 @@ pub struct FlashEraseArgs {
pub model: Model,
}
+#[derive(Args, Debug)]
+pub struct ResetArgs {
+ /// Target model
+ #[arg(long, short = 'm', ignore_case = true)]
+ pub model: Model,
+}
+
#[derive(Args, Debug)]
pub struct UploadArgs {
pub project: Project,
diff --git a/core/embed/xtask/src/flash.rs b/core/embed/xtask/src/flash.rs
index 598c211d..b20effb9 100644
--- a/core/embed/xtask/src/flash.rs
+++ b/core/embed/xtask/src/flash.rs
@@ -5,7 +5,7 @@ use std::{
};
use crate::{
- args::{FlashArgs, FlashEraseArgs, FlashSection},
+ args::{FlashArgs, FlashEraseArgs, FlashSection, ResetArgs},
helpers,
};
@@ -74,6 +74,26 @@ pub fn flash_erase(args: FlashEraseArgs) -> Result<()> {
Ok(())
}
+/// Resets the connected device using OpenOCD.
+pub fn reset(args: ResetArgs) -> Result<()> {
+ let model_config = args.model.config()?;
+
+ println!("Resetting `{:?}`", args.model);
+
+ let status = process::Command::new("openocd")
+ .args(["-f", "interface/stlink.cfg"])
+ .args(["-c", "transport select hla_swd"])
+ .args(["-f", model_config.openocd_target()?])
+ .arg("-c")
+ .arg("init; reset; exit")
+ .status()
+ .context("Failed to spawn `openocd`")?;
+
+ ensure!(status.success(), "`openocd` failed with status: {status}");
+
+ Ok(())
+}
+
fn build_flash_write_instruction(binary: &Path, address: u32) -> String {
format!(
"init; reset halt; flash write_image erase {} 0x{:X}; exit",
diff --git a/core/embed/xtask/src/main.rs b/core/embed/xtask/src/main.rs
index 7f375711..277a427f 100644
--- a/core/embed/xtask/src/main.rs
+++ b/core/embed/xtask/src/main.rs
@@ -18,6 +18,7 @@ fn main() -> Result<()> {
Cmd::Fmt => cargo::fmt(),
Cmd::Flash(args) => flash::flash(args),
Cmd::FlashErase(args) => flash::flash_erase(args),
+ Cmd::Reset(args) => flash::reset(args),
Cmd::Upload(args) => upload::upload(args),
Cmd::Combine(args) => combine::combine(args),
}
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.