Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions cmd/diagnose/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,7 @@ fn diagnose(
}
}

// This is a bit of a hack, but, we can detect core dumps by going...
if core.info().0 == "core dump" {
if core.is_dump() {
section("This Is A Core Dump");
println!("You're running this on a dump; that's all we can do.");
println!("Connect to a live system for more output.");
Expand Down
8 changes: 0 additions & 8 deletions cmd/hydrate/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,12 @@ macro_rules! unsupported{
impl humility::core::Core for DryCore {
unsupported!(run());
unsupported!(halt());
unsupported!(step());
unsupported!(write_8(_addr: u32, _data: &[u8]));
unsupported!(op_done());
unsupported!(op_start());
unsupported!(read_reg(_reg: ARMRegister) -> Result<u32>);
unsupported!(write_reg(_reg: ARMRegister, _value: u32));
unsupported!(write_word_32(_addr: u32, _data: u32));

fn info(&self) -> (String, Option<String>) {
("DryCore".to_owned(), None)
}
fn is_archive(&self) -> bool {
false
}
Expand All @@ -83,9 +78,6 @@ impl humility::core::Core for DryCore {
fn is_net(&self) -> bool {
false
}
fn vid_pid(&self) -> Option<(u16, u16)> {
None
}

fn read_8(&mut self, addr: u32, data: &mut [u8]) -> Result<()> {
if self.flash.read(addr, data).is_some() {
Expand Down
4 changes: 2 additions & 2 deletions cmd/probe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ fn probecmd(subargs: ProbeArgs, context: &mut ExecutionContext) -> Result<()> {

if subargs.environment {
match (info.1, core.vid_pid()) {
(Some(ref serial), Some((vid, pid))) => {
println!("HUMILITY_PROBE={vid:04x}:{pid:04x}:{serial}");
(Some(ref serial), vidpid) => {
println!("HUMILITY_PROBE={vidpid}:{serial}");
return Ok(());
}
_ => {
Expand Down
3 changes: 2 additions & 1 deletion cmd/rebootleby/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ description = "Do something kind of like embootleby to recover a device with bad
[dependencies]
humility.workspace = true
humility-arch-arm.workspace = true
humility-cortex.workspace = true
humility-cli.workspace = true
humility-cortex.workspace = true
humility-probes-core.workspace = true
Comment thread
mkeeter marked this conversation as resolved.

anyhow.workspace = true
clap.workspace = true
Expand Down
3 changes: 2 additions & 1 deletion cmd/rebootleby/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use humility::{
};
use humility_arch_arm::ARMRegister;
use humility_cli::{ExecutionContext, humility_cmd};
use humility_probes_core::ProbeCore;
use std::io::Read;
use std::ops::RangeInclusive;
use std::path::PathBuf;
Expand Down Expand Up @@ -151,7 +152,7 @@ const LOCKOUTSETTINGS: u32 = 0x0;
const BANKENABLESETTINGS: u32 = 0xaa0;

struct FlashHack<'a> {
core: &'a mut dyn Core,
core: &'a mut ProbeCore,
log: Logger,
Comment thread
mkeeter marked this conversation as resolved.
}

Expand Down
19 changes: 17 additions & 2 deletions cmd/reset/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ fn reset(subargs: ResetArgs, context: &mut ExecutionContext) -> Result<()> {
Behavior::Reset => c.reset(),
}
} else {
let mut c = humility_probes_core::attach_to_probe(
let mut probe = humility_probes_core::attach_to_probe(
probe,
context.cli.speed,
log,
Expand All @@ -110,7 +110,22 @@ fn reset(subargs: ResetArgs, context: &mut ExecutionContext) -> Result<()> {
Behavior::Halt | Behavior::ResetWithHandoff(..) => {
unreachable!()
}
Behavior::Reset => c.reset(),
Behavior::Reset => {
probe
.target_reset_assert()
.map_err(anyhow::Error::from)
.and_then(|()| {
// The closest available documentation on hold time is
// a comment giving a timeout
// https://open-cmsis-pack.github.io/Open-CMSIS-Pack-Spec/main/html/debug_description.html#resetHardwareDeassert
std::thread::sleep(std::time::Duration::from_millis(
1000,
));

probe.target_reset_deassert()?;
Ok(())
})
}
}
};

Expand Down
1 change: 1 addition & 0 deletions cmd/stmsecure/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ parse_int.workspace = true
humility.workspace = true
humility-arch-arm.workspace = true
humility-cli.workspace = true
humility-probes-core.workspace = true
Comment thread
mkeeter marked this conversation as resolved.
25 changes: 13 additions & 12 deletions cmd/stmsecure/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ use clap::Parser;
use humility::core::Core;
use humility_arch_arm::ARMRegister;
use humility_cli::{ExecutionContext, humility_cmd};
use humility_probes_core::ProbeCore;

const FLASH_OPT_KEY1: u32 = 0x0819_2A3B;
const FLASH_OPT_KEY2: u32 = 0x4C5D_6E7F;
Expand Down Expand Up @@ -90,19 +91,19 @@ pub enum StmSecureCmd {
SwapBanks,
}

fn stmsecure_unlock_flash(core: &mut dyn Core) -> Result<()> {
fn stmsecure_unlock_flash(core: &mut ProbeCore) -> Result<()> {
Comment thread
mkeeter marked this conversation as resolved.
core.write_word_32(FLASH_KEYR1, FLASH_KEY1)?;
core.write_word_32(FLASH_KEYR1, FLASH_KEY2)?;
Ok(())
}

fn stmsecure_unlock_option(core: &mut dyn Core) -> Result<()> {
fn stmsecure_unlock_option(core: &mut ProbeCore) -> Result<()> {
core.write_word_32(FLASH_OPT_KEYR, FLASH_OPT_KEY1)?;
core.write_word_32(FLASH_OPT_KEYR, FLASH_OPT_KEY2)?;
Ok(())
}

fn stmsecure_commit_option(core: &mut dyn Core) -> Result<()> {
fn stmsecure_commit_option(core: &mut ProbeCore) -> Result<()> {
// set start bit
core.write_word_32(FLASH_OPT_CR, 0x2)?;

Expand All @@ -115,7 +116,7 @@ fn stmsecure_commit_option(core: &mut dyn Core) -> Result<()> {
Ok(())
}

fn stmsecure_rdpset(core: &mut dyn Core) -> Result<()> {
fn stmsecure_rdpset(core: &mut ProbeCore) -> Result<()> {
println!("setting rdp to level 1 (You will not be able to read the flash)");
stmsecure_unlock_option(core)?;
let optsr = core.read_word_32(FLASH_OPTSR_CUR)?;
Expand All @@ -125,13 +126,13 @@ fn stmsecure_rdpset(core: &mut dyn Core) -> Result<()> {
Ok(())
}

fn stmsecure_rdpunset_nocommit(core: &mut dyn Core) -> Result<()> {
fn stmsecure_rdpunset_nocommit(core: &mut ProbeCore) -> Result<()> {
let optsr = core.read_word_32(FLASH_OPTSR_CUR)?;
core.write_word_32(FLASH_OPTSR_PRG, (optsr & !0x0000_ff00) | 0x0000_aa00)?;
Ok(())
}

fn stmsecure_rdpunset(core: &mut dyn Core) -> Result<()> {
fn stmsecure_rdpunset(core: &mut ProbeCore) -> Result<()> {
println!(
"setting rdp level to 0. This may also erase the flash depending
on your system settings!"
Expand All @@ -143,7 +144,7 @@ fn stmsecure_rdpunset(core: &mut dyn Core) -> Result<()> {
Ok(())
}

fn stmsecure_lockbit_set(core: &mut dyn Core) -> Result<()> {
fn stmsecure_lockbit_set(core: &mut ProbeCore) -> Result<()> {
println!("Setting the secure option bit");
stmsecure_unlock_option(core)?;
let optsr = core.read_word_32(FLASH_OPTSR_CUR)?;
Expand All @@ -153,7 +154,7 @@ fn stmsecure_lockbit_set(core: &mut dyn Core) -> Result<()> {
Ok(())
}

fn stmsecure_lockbit_unset(core: &mut dyn Core) -> Result<()> {
fn stmsecure_lockbit_unset(core: &mut ProbeCore) -> Result<()> {
println!("Unsetting the secure option bit");
stmsecure_unlock_option(core)?;
let optsr = core.read_word_32(FLASH_OPTSR_CUR)?;
Expand All @@ -163,7 +164,7 @@ fn stmsecure_lockbit_unset(core: &mut dyn Core) -> Result<()> {
Ok(())
}

fn stmsecure_status(core: &mut dyn Core) -> Result<()> {
fn stmsecure_status(core: &mut ProbeCore) -> Result<()> {
let optsr = core.read_word_32(FLASH_OPTSR_CUR)?;
let rdp = (optsr & 0x0000_ff00) >> 8;
let sec_en = (optsr & 0x20_0000) == 0x20_0000;
Expand All @@ -182,7 +183,7 @@ fn stmsecure_status(core: &mut dyn Core) -> Result<()> {
}

fn stmsecure_setsecureregion(
core: &mut dyn Core,
core: &mut ProbeCore,
address: u32,
size: u32,
commit: bool,
Expand Down Expand Up @@ -253,7 +254,7 @@ fn stmsecure_setsecureregion(
Ok(())
}

fn stmsecure_unsetsecureregion(core: &mut dyn Core) -> Result<()> {
fn stmsecure_unsetsecureregion(core: &mut ProbeCore) -> Result<()> {
println!("Unsetting the secure region. This will erase the bank!");

// This sequence is from the manual section 4.3.10
Expand Down Expand Up @@ -283,7 +284,7 @@ fn stmsecure_unsetsecureregion(core: &mut dyn Core) -> Result<()> {
Ok(())
}

fn stmsecure_swapbanks(core: &mut dyn Core) -> Result<()> {
fn stmsecure_swapbanks(core: &mut ProbeCore) -> Result<()> {
println!("Swapping banks");
stmsecure_unlock_option(core)?;
let optsr = core.read_word_32(FLASH_OPTSR_CUR)?;
Expand Down
30 changes: 21 additions & 9 deletions humility-bin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,13 @@ cmd-console-proxy = { workspace = true }
cmd-counters = { workspace = true }
cmd-dashboard = { workspace = true }
cmd-diagnose = { workspace = true }
cmd-debugmailbox = { workspace = true, optional = true }
cmd-discover = { workspace = true }
cmd-doc = { workspace = true }
cmd-dump = { workspace = true }
cmd-tofino-eeprom = { workspace = true }
cmd-ereport = { workspace = true }
cmd-exec = { workspace = true }
cmd-extract = { workspace = true }
cmd-flash = { workspace = true, optional = true }
cmd-gimlet = { workspace = true }
cmd-gpio = { workspace = true }
cmd-hash = { workspace = true }
Expand All @@ -59,7 +57,6 @@ cmd-i2c = { workspace = true }
cmd-ibc = { workspace = true }
cmd-jefe = { workspace = true }
cmd-lpc55gpio = { workspace = true }
cmd-lsusb = { workspace = true, optional = true }
cmd-manifest = { workspace = true }
cmd-map = { workspace = true }
cmd-monorail = { workspace = true }
Expand All @@ -68,13 +65,10 @@ cmd-net = { workspace = true }
cmd-pmbus = { workspace = true }
cmd-power = { workspace = true }
cmd-powershelf = { workspace = true }
cmd-probe = { workspace = true }
cmd-qspi = { workspace = true }
cmd-readmem = { workspace = true }
cmd-readvar = { workspace = true }
cmd-rebootleby.workspace = true
cmd-registers = { workspace = true }
cmd-reset = { workspace = true, optional = true }
cmd-rencm = { workspace = true }
cmd-rendmp = { workspace = true }
cmd-ringbuf = { workspace = true }
Expand All @@ -84,12 +78,20 @@ cmd-spctrl = { workspace = true }
cmd-spd = { workspace = true }
cmd-spi = { workspace = true }
cmd-stackmargin = { workspace = true }
cmd-stmsecure = { workspace = true }
cmd-tasks = { workspace = true }
cmd-test = { workspace = true }
cmd-validate = { workspace = true }
cmd-vpd = { workspace = true }
cmd-writeword = { workspace = true }

# Subcommand which require the `probes` feature
cmd-debugmailbox = { workspace = true, optional = true }
cmd-flash = { workspace = true, optional = true }
cmd-lsusb = { workspace = true, optional = true }
cmd-probe = { workspace = true, optional = true }
cmd-rebootleby = { workspace = true, optional = true }
cmd-reset = { workspace = true, optional = true }
cmd-stmsecure = { workspace = true, optional = true }
cmd-writeword = { workspace = true, optional = true }

anyhow = { workspace = true }
bitfield = { workspace = true }
Expand All @@ -114,7 +116,17 @@ trycmd = { workspace = true }

[features]
default = ["probes"]
probes = ["humility-cli/probes", "cmd-reset", "cmd-lsusb", "cmd-flash", "cmd-debugmailbox"]
probes = [
"humility-cli/probes",
"cmd-debugmailbox",
"cmd-flash",
"cmd-lsusb",
"cmd-probe",
"cmd-rebootleby",
"cmd-reset",
"cmd-stmsecure",
"cmd-writeword",
]

[[bin]]
name = "humility"
Expand Down
44 changes: 34 additions & 10 deletions humility-bin/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,43 @@ pub enum Subcommand {{
"##
)?;

//
let banned = if std::env::var_os("CARGO_FEATURE_PROBES").is_none() {
// These are everything that can potentially pull in libusb
["probe-rs", "humility-probes-core", "rusb"].into_iter().collect()
} else {
BTreeSet::new()
};
let (banned_deps, disabled_cmds) =
if std::env::var_os("CARGO_FEATURE_PROBES").is_none() {
// These are everything that can potentially pull in libusb
let banned_deps = ["probe-rs", "humility-probes-core", "rusb"]
.into_iter()
.collect();
// We also look at which commands are enabled by the `probes`
// feature on the `humility-bin` crate, then remove them.
let disabled_cmds = metadata
.workspace_members
.iter()
.find(|p| metadata[p].name == "humility-bin")
.map(|p| metadata[p].clone())
.expect(
"could not find package named `humility-bin` while \
executing its own build script; has it been renamed?",
)
.features["probes"]
.iter()
.flat_map(|p| {
p.strip_prefix("cmd-").map(|p| format!("humility-cmd-{p}"))
})
.collect::<BTreeSet<_>>();
(banned_deps, disabled_cmds)
} else {
(BTreeSet::new(), BTreeSet::new())
};

for id in &metadata.workspace_members {
let package =
metadata.packages.iter().find(|p| &p.id == id).unwrap().clone();
let package = metadata[id].clone();

if let Some(cmd) = package.name.strip_prefix("humility-cmd-")
&& !package.dependencies.iter().any(|d| banned.contains(&*d.name))
&& !package
.dependencies
.iter()
.any(|d| banned_deps.contains(&*d.name))
&& !disabled_cmds.contains(package.name.as_str())
{
cmds.insert(cmd.to_string());
}
Expand Down
Loading
Loading