Skip to content
Draft
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
3 changes: 3 additions & 0 deletions rules/opentitan/qemu.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,9 @@ def _test_dispatch(ctx, exec_env, firmware):
# Create a chardev for the SPI device:
qemu_args += ["-chardev", "pty,id=spidev"]

# Create a chardev for the RV_DM JTAG TAP:
qemu_args += ["-chardev", "socket,id=taprbb,path=qemu-jtag.sock,server=on,wait=off"]

# Scale the Ibex clock by an `icount` factor.
qemu_args += ["-icount", "shift={}".format(param["icount"])]

Expand Down
28 changes: 28 additions & 0 deletions sw/host/opentitanlib/src/transport/qemu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ pub mod reset;
pub mod spi;

use std::cell::RefCell;
use std::path::PathBuf;
use std::rc::Rc;
use std::str::FromStr;

use anyhow::{Context, bail};

use crate::backend::qemu::QemuOpts;
use crate::debug::openocd::OpenOcdJtagChain;
use crate::io::gpio::{GpioError, GpioPin};
use crate::io::jtag::{JtagChain, JtagParams};
use crate::io::uart::Uart;
use crate::transport::Target;
use crate::transport::common::uart::SerialPortUart;
Expand Down Expand Up @@ -49,6 +52,9 @@ pub struct Qemu {
/// QEMU log modelled as a UART.
log: Option<Rc<dyn Uart>>,

/// Debug module JTAG.
jtag_sock: Option<PathBuf>,

/// Whether to quit QEMU when dropped.
quit: bool,
}
Expand Down Expand Up @@ -119,6 +125,15 @@ impl Qemu {
}
};

// Debug module JTAG tap:
let jtag_sock = match find_chardev(&chardevs, "taprbb") {
Some(ChardevKind::Socket { path }) => Some(path.clone()),
_ => {
log::info!("could not find socket chardev with id=taprbb, skipping JTAG");
None
}
};

let monitor = Rc::new(RefCell::new(monitor));

// Resetting is done over the monitor, but we model it like a pin to enable strapping it.
Expand All @@ -131,6 +146,7 @@ impl Qemu {
console,
log,
spi,
jtag_sock,
quit: options.qemu_quit,
})
}
Expand Down Expand Up @@ -194,4 +210,16 @@ impl Transport for Qemu {
fn spi(&self, _instance: &str) -> anyhow::Result<Rc<dyn Target>> {
Ok(Rc::clone(self.spi.as_ref().unwrap()))
}

fn jtag(&self, opts: &JtagParams) -> anyhow::Result<Box<dyn JtagChain>> {
let jtag = OpenOcdJtagChain::new(
&format!(
"adapter driver remote_bitbang; remote_bitbang port 0; remote_bitbang host {sock}",
sock = self.jtag_sock.as_ref().unwrap().display(),
),
opts,
)?;

Ok(Box::new(jtag))
}
}
5 changes: 5 additions & 0 deletions sw/host/opentitanlib/src/transport/qemu/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ pub struct Chardev {
#[derive(Clone, Debug)]
pub enum ChardevKind {
Pty { path: PathBuf },
Socket { path: PathBuf },
Other,
}

Expand All @@ -252,6 +253,10 @@ impl TryFrom<ChardevJson> for Chardev {
let kind = if let Some(path) = json.filename.strip_prefix("pty:") {
let path = PathBuf::from(path);
ChardevKind::Pty { path }
} else if let Some(sock) = json.filename.strip_prefix("disconnected:unix:") {
let path = sock.split(',').next().unwrap();
let path = PathBuf::from(path);
ChardevKind::Socket { path }
} else {
ChardevKind::Other
};
Expand Down
Loading