From fa4e362029b75216d4f9f08a4f5bba3fc50cafe7 Mon Sep 17 00:00:00 2001 From: Matt Johnston Date: Fri, 26 Jul 2024 13:00:30 +0800 Subject: [PATCH 1/2] 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 --- humility-core/src/core.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/humility-core/src/core.rs b/humility-core/src/core.rs index d4f355633..96afdf442 100644 --- a/humility-core/src/core.rs +++ b/humility-core/src/core.rs @@ -627,7 +627,7 @@ impl Core for OpenOCDCore { fn read_word_32(&mut self, addr: u32) -> Result { let result = self.sendcmd(&format!("mrw 0x{:x}", addr))?; - Ok(result.parse::()?) + Ok(parse_int::parse::(&result)?) } fn read_8(&mut self, addr: u32, data: &mut [u8]) -> Result<()> { @@ -671,10 +671,12 @@ impl Core for OpenOCDCore { // in strict alphabetical order by index (!!). (That is, index 100 // comes before, say, index 11.) // + // In some cases the output may have index as decimal, but value + // as 0x-prefixed hexadecimal. for val in result.split(' ') { match index { None => { - let idx = val.parse::()?; + let idx = parse_int::parse::(val)?; if idx >= data.len() { bail!("\"{}\": illegal index {}", cmd, idx); @@ -689,7 +691,7 @@ impl Core for OpenOCDCore { } Some(idx) => { - data[idx] = val.parse::()?; + data[idx] = parse_int::parse::(val)?; index = None; } } From 5232aea444c0cdf7523d24aa3a49b1ad3c87ec13 Mon Sep 17 00:00:00 2001 From: Matt Johnston Date: Thu, 1 Aug 2024 11:14:08 +0800 Subject: [PATCH 2/2] Use OpenOCD read_memory rather than mrw `mrw` requires that mem_helper.tcl is sourced, whereas read_memory can be used without any config. --- humility-core/src/core.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/humility-core/src/core.rs b/humility-core/src/core.rs index 96afdf442..d07a19aff 100644 --- a/humility-core/src/core.rs +++ b/humility-core/src/core.rs @@ -626,7 +626,7 @@ impl Core for OpenOCDCore { } fn read_word_32(&mut self, addr: u32) -> Result { - let result = self.sendcmd(&format!("mrw 0x{:x}", addr))?; + let result = self.sendcmd(&format!("read_memory 0x{:x} 32 1", addr))?; Ok(parse_int::parse::(&result)?) }