From 73b0889c6b3250aabc1f425015c7defa97393ec4 Mon Sep 17 00:00:00 2001 From: "Jes B. Klinke" Date: Thu, 14 Nov 2024 11:36:36 -0800 Subject: [PATCH] [opentitantool] HyperDebug driver robustness 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 --- .../opentitanlib/src/transport/hyperdebug/mod.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/sw/host/opentitanlib/src/transport/hyperdebug/mod.rs b/sw/host/opentitanlib/src/transport/hyperdebug/mod.rs index 0a455f6ea95da6..c43790b71e262b 100644 --- a/sw/host/opentitanlib/src/transport/hyperdebug/mod.rs +++ b/sw/host/opentitanlib/src/transport/hyperdebug/mod.rs @@ -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 { @@ -642,7 +642,17 @@ impl Transport for Hyperdebug { } fn apply_default_configuration(&self) -> Result<()> { - self.inner.cmd_no_output("reinit") + let mut error: Option = 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.