@@ -12,6 +12,7 @@ pub mod usbdev;
1212
1313use std:: cell:: RefCell ;
1414use std:: collections:: HashMap ;
15+ use std:: path:: PathBuf ;
1516use std:: rc:: Rc ;
1617use std:: str:: FromStr ;
1718use std:: thread;
@@ -20,7 +21,9 @@ use std::time::Duration;
2021use anyhow:: { Context , bail} ;
2122
2223use crate :: backend:: qemu:: QemuOpts ;
24+ use crate :: debug:: openocd:: OpenOcdJtagChain ;
2325use crate :: io:: gpio:: { GpioError , GpioPin } ;
26+ use crate :: io:: jtag:: { JtagChain , JtagParams } ;
2427use crate :: io:: uart:: Uart ;
2528use crate :: transport:: Bus ;
2629use crate :: transport:: Target ;
@@ -72,6 +75,9 @@ pub struct Qemu {
7275
7376 /// QEMU log modelled as a UART.
7477 log : Option < Rc < dyn Uart > > ,
78+
79+ /// Debug module JTAG.
80+ jtag_sock : Option < PathBuf > ,
7581}
7682
7783impl Qemu {
@@ -209,6 +215,15 @@ impl Qemu {
209215 }
210216 } ;
211217
218+ // Debug module JTAG tap:
219+ let jtag_sock = match find_chardev ( & chardevs, "taprbb" ) {
220+ Some ( ChardevKind :: Socket { path } ) => Some ( path. clone ( ) ) ,
221+ _ => {
222+ log:: info!( "could not find socket chardev with id=taprbb, skipping JTAG" ) ;
223+ None
224+ }
225+ } ;
226+
212227 // Resetting is done over the monitor, but we model it like a pin to enable strapping it.
213228 let reset = QemuReset :: new ( Rc :: clone ( & monitor) ) ;
214229 let reset = Rc :: new ( reset) ;
@@ -226,6 +241,7 @@ impl Qemu {
226241 spi,
227242 i2cs,
228243 gpio,
244+ jtag_sock,
229245 } )
230246 }
231247}
@@ -307,4 +323,16 @@ impl Transport for Qemu {
307323 fn spi ( & self , _instance : & str ) -> anyhow:: Result < Rc < dyn Target > > {
308324 Ok ( Rc :: clone ( self . spi . as_ref ( ) . unwrap ( ) ) )
309325 }
326+
327+ fn jtag ( & self , opts : & JtagParams ) -> anyhow:: Result < Box < dyn JtagChain > > {
328+ let jtag = OpenOcdJtagChain :: new (
329+ & format ! (
330+ "adapter driver remote_bitbang; remote_bitbang port 0; remote_bitbang host {sock}" ,
331+ sock = self . jtag_sock. as_ref( ) . unwrap( ) . display( ) ,
332+ ) ,
333+ opts,
334+ ) ?;
335+
336+ Ok ( Box :: new ( jtag) )
337+ }
310338}
0 commit comments