Skip to content

Commit 495c3dc

Browse files
authored
Have qspi take a slot argument (#585)
Hubris QSPI APIs target either flash slot 0 or flash slot 1. Currently `humility qspi` uses the version of the API that targets the active slot. This can be confusing if another command was run targeting the inactive slot. Have `humility qspi` take a slot argument to change the slot before running any commands.
1 parent 1202bcb commit 495c3dc

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

cmd/qspi/src/lib.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,10 @@ struct QspiArgs {
192192
/// persistently selects a storage slot
193193
#[clap(long, group = "command")]
194194
set_persistent_slot: Option<u8>,
195+
196+
/// Target a specific slot
197+
#[clap(long)]
198+
slot: Option<u8>,
195199
}
196200

197201
struct QspiDevice {
@@ -485,6 +489,27 @@ fn qspi(context: &mut ExecutionContext) -> Result<()> {
485489
let subargs = QspiArgs::try_parse_from(subargs)?;
486490
let mut context = HiffyContext::new(hubris, core, subargs.timeout)?;
487491

492+
match subargs.slot {
493+
None => humility::msg!("Using existing slot settings"),
494+
s @ (Some(0) | Some(1)) => {
495+
let s = s.unwrap();
496+
humility::msg!("Setting slot to {s}");
497+
let out = hiffy_call(
498+
hubris,
499+
core,
500+
&mut context,
501+
&hubris.get_idol_command("HostFlash.set_dev")?,
502+
&[("dev", IdolArgument::String(&format!("Flash{s}")))],
503+
None,
504+
None,
505+
)?;
506+
if let Err(e) = out {
507+
bail!("set_dev failed: {e}");
508+
}
509+
}
510+
_ => bail!("Bad slot setting"),
511+
}
512+
488513
const SECTOR_SIZE: u32 = 64 * 1024;
489514
const BLOCK_SIZE: u32 = 256; // Conflating flash block size with hubris scratch buffer.
490515

0 commit comments

Comments
 (0)