Skip to content

Commit

Permalink
[opentitantool] HyperDebug driver robustness
Browse files Browse the repository at this point in the history
When the driver reads a command response from the HyperDebug text
console, it no longer relies on getting timeout to recognize when the
output is complete.  (Instead if it sees the prompt "> " as the final
two characters in any chunk received, it is all.)

With that in mind, there is no reason to have the timeout as low as
100ms.  In particular the `reinit` command executed as part of
"transport init" takes a little while to calibrate ADC and reset various
circuits in HyperDebug, and could get more responsiblities in the
future.  And on top of that, the USB bus introduces sometimes
unpredictable delays.

This CL increase the general delay for HyperDebug console response to 3
seconds.  And also propagates any error messages from `reinit` in a
slightly better way.

Change-Id: I3ecb17a3ad32f923b240d0dcce76e6d40938e4c8
Signed-off-by: Jes B. Klinke <[email protected]>
  • Loading branch information
jesultra committed Nov 14, 2024
1 parent 1ea1c43 commit 73b0889
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions sw/host/opentitanlib/src/transport/hyperdebug/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ impl Inner {
.to_str()
.ok_or(TransportError::UnicodePathError)?;
let port =
TTYPort::open(&serialport::new(port_name, 115_200).timeout(Duration::from_millis(100)))
TTYPort::open(&serialport::new(port_name, 115_200).timeout(Duration::from_millis(3000)))
.context("Failed to open HyperDebug console")?;
flock_serial(&port, port_name)?;
let conn = Rc::new(Conn {
Expand Down Expand Up @@ -642,7 +642,17 @@ impl<T: Flavor> Transport for Hyperdebug<T> {
}

fn apply_default_configuration(&self) -> Result<()> {
self.inner.cmd_no_output("reinit")
let mut error: Option<String> = None;
self.inner.execute_command("reinit", |line| {
log::warn!("Unexpected HyperDebug output: {}", line);
if line.starts_with("Error: ") {
error = Some(line.to_string());
}
})?;
if let Some(err) = error {
bail!(TransportError::CommunicationError(err));
}
Ok(())
}

// Create SPI Target instance, or return one from a cache of previously created instances.
Expand Down

0 comments on commit 73b0889

Please sign in to comment.