Skip to content

Commit 984f230

Browse files
committed
Allow OpenOCD to return hex formatted values
OpenOCD may return hex values from mem2array or mrw, so allow those. mem2array output: 0 0xb8 1 0xba 2 0xc 3 0x0 4 0xb8 5 0xba This might depend on the particular adapter driver being used but parsing either is more robust. The problem was observed with OpenOCD 0.12.0 and cmsis-dap. Failed with: cargo xtask humility app/.../recovery.toml -- tasks Finished `dev` profile [optimized + debuginfo] target(s) in 0.09s Running `target/debug/xtask humility app/.../recovery.toml -- tasks` humility: attached via OpenOCD humility tasks failed: failed to read image ID at 0xcaec0; board mismatch? Caused by: invalid digit found in string Error: humility failed
1 parent 9948f3f commit 984f230

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

humility-core/src/core.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ impl Core for OpenOCDCore {
627627

628628
fn read_word_32(&mut self, addr: u32) -> Result<u32> {
629629
let result = self.sendcmd(&format!("mrw 0x{:x}", addr))?;
630-
Ok(result.parse::<u32>()?)
630+
Ok(parse_int::parse::<u32>(&result)?)
631631
}
632632

633633
fn read_8(&mut self, addr: u32, data: &mut [u8]) -> Result<()> {
@@ -671,10 +671,12 @@ impl Core for OpenOCDCore {
671671
// in strict alphabetical order by index (!!). (That is, index 100
672672
// comes before, say, index 11.)
673673
//
674+
// In some cases the output may have index as decimal, but value
675+
// as 0x-prefixed hexadecimal.
674676
for val in result.split(' ') {
675677
match index {
676678
None => {
677-
let idx = val.parse::<usize>()?;
679+
let idx = parse_int::parse::<usize>(val)?;
678680

679681
if idx >= data.len() {
680682
bail!("\"{}\": illegal index {}", cmd, idx);
@@ -689,7 +691,7 @@ impl Core for OpenOCDCore {
689691
}
690692

691693
Some(idx) => {
692-
data[idx] = val.parse::<u8>()?;
694+
data[idx] = parse_int::parse::<u8>(val)?;
693695
index = None;
694696
}
695697
}

0 commit comments

Comments
 (0)