[Verilator] Unable to connect to virtual JTAG port with OpenOCD
Nobody has claimed this yet.
- Dominant language
- SystemVerilog
- Stars
- 3.6k
- Forks
- 1.1k
- Avg merge
- 2d 22h
- Merged PRs (30d)
- 141
Description
### Description
OpenOCD is unable to connect to a running Verilator instance using the Virtual JTAG port. This prevents Verilator simulation runs being able to be debugged from GDB.
The commands used were [adapted from the 'Getting Started' guide](https://opentitan.org/book/doc/getting_started/setup_verilator.html):
- `bazel run //sw/device/tests:uart_smoketest_sim_verilator` to run the test in Verilator.
- `bazel run //third_party/openocd -- -s util/openocd -f board/lowrisc-earlgrey-verilator.cfg` to run our vendored OpenOCD.
(Note that both need to be ran with `bazel run`, as bazel will otherwise wait for the `test` to finish before running other commands, whereas we need these both to run at the same time.)
```
$ bazel run //third_party/openocd -- -s util/openocd -f board/lowrisc-earlgrey-verilator.cfg
...
Open On-Chip Debugger 0.12.0
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
Info : only one transport option; autoselect 'jtag'
DEPRECATED! use 'remote_bitbang port' not 'remote_bitbang_port'
DEPRECATED! use 'remote_bitbang host' not 'remote_bitbang_host'
Info : Hardware thread awareness created
force hard breakpoints
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Warn : An adapter speed is not selected in the init scripts. OpenOCD will try to run the adapter at the low speed (100 kHz)
Warn : To remove this warnings and achieve reasonable communication speed with the target, set "adapter speed" or "jtag_rclk" in the init scripts.
Info : Initializing remote_bitbang driver
Info : Connecting to localhost:44853
Info : remote_bitbang driver initialized
Info : This adapter doesn't support configurable speed
```
This then freezes until the Verilator process exits, breaking the socket that OpenOCD was using:
```
Error: Error on socket 'remote_bitbang_fill_buf': errno==104, message: Connection reset by peer.
Error: Trying to use configured scan chain anyway...
Error: Error on socket 'remote_bitbang_putc': errno==32, message: Broken pipe.
Error: Error on socket 'remote_bitbang_putc': errno==32, message: Broken pipe.
Warn : Bypassing JTAG setup events due to errors
Error: Error on socket 'remote_bitbang_putc': errno==32, message: Broken pipe.
Error: failed jtag scan: -4
Error: Unsupported DTM version: 12
Warn : target riscv.tap.0 examination failed
Info : starting gdb server for riscv.tap.0 on 3333
Info : Listening on port 3333 for gdb connections
shutdown command invoked
Error: Unsupported DTM version: 12
Error: Error on socket 'remote_bitbang_putc': errno==32, message: Broken pipe.
Error: failed: -4
```
The current vendored version of OpenOCD is `0.12`. Using [binary releases provided by xpack](https://github.com/xpack-dev-tools/openocd-xpack), the same behaviour was exhibited back up to version `0.11.3`. Before `0.11.3`, OpenOCD does not support some of the `riscv` subcommands that are used. I think this indicates that the Verilator sim is not implementing the remote bitbang protocol in the JTAG correctly.
See also https://github.com/lowRISC/opentitan/issues/17406.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the issue with the two `bazel run` commands in the report, then inspect `util/openocd` and `board/lowrisc-earlgrey-verilator.cfg`. Trace the remote bitbang connection between the running Verilator simulation and vendored OpenOCD, using issue 17406 for context. Done means OpenOCD completes JTAG setup and GDB can connect without the socket errors.
Written by the indexing model from the issue text.
Assessment
- Domain
- devtools, embedded-iot
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100