Proposal to Extend RISC-V DMI Transport in OpenOCD #1175
Replies: 15 comments 37 replies
-
It might be a good idea to also run your proposal by the upstream OpenOCD community in case they have any views on it or anybody there might be undertaking similar work? |
Beta Was this translation helpful? Give feedback.
-
Thanks for this proposal! I believe it will be a great improvement. First of all, I'd like to support @TommyMurphyTM1234's suggestion to post this in the mainline's mailing list. I think you will be able to get a lot of valuable feedback there.
I'd like to disagree.
I'm a bit concerned with this part. OpenOCD benefits a whole lot from bundling a bunch of RISC-V DMI transactions into a single USB packet. This is possible thanks to sticky error state of RISC-V JTAG DTM. What I'm trying to say is: efficient communication over USB or TCP/IP will require a more complex interface then the pair of I'd suggest you to look into target/riscv/batch.h. This is the interface currently used to access DMI over JTAG. Though it is a bit JTAG-specific and there are parts that are done separately (e.g. the |
Beta Was this translation helpful? Give feedback.
-
Just to clarify, my reasoning is that the suggested changes sound broad enough that that will most likely require changes beyond the RISC-V target specific parts of OpenOCD and, as such, will benefit from input from, and require acceptance by, the wider OpenOCD community and developers. If the changes were restricted to OpenOCD's RISC-V target specific support then this would be less critical, albeit still a good idea and good manners. 🙂 |
Beta Was this translation helpful? Give feedback.
-
Actually we were thinking, this proposal might be restricted to RISC V
implementation since we were gonna make DMI as the transport module API
interface. Since other Arch dont directly support DMI, we might need to
provide a different abstraction if we want to extend this beyond RISC V
support.
Below is a graphical overview of what we are thinking in terms of how the
newly proposed Transport layer would interface with RISCV specific
implementation.
[image: Screenshot 2024-11-26 at 11.25.56 AM.png]
Pls let us know your thoughts. Thank you
WR
~S
…On Tue, Nov 26, 2024 at 10:01 AM Tommy Murphy ***@***.***> wrote:
First of all, I'd like to support @TommyMurphyTM1234
<https://github.com/TommyMurphyTM1234>'s suggestion to post this in the
mainline's mailing list. I think you will be able to get a lot of valuable
feedback there.
Just to clarify, my reasoning is that the suggested changes sound broad
enough that that will most likely require changes beyond the RISC-V target
specific parts of OpenOCD and, as such, will benefit from input and require
acceptance by the wider OpenOCD community and developers. If the changes
were restricted to OpenOCD's RISC-V target specific support then this would
be less critical, albeit still a good idea.
—
Reply to this email directly, view it on GitHub
<#1175 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/APHNMDUCIQL6IOZLDMH35RT2CSZN5AVCNFSM6AAAAABSQZV64WVHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTCMZYGY3DKNI>
.
You are receiving this because you were mentioned.Message ID:
***@***.***
.com>
|
Beta Was this translation helpful? Give feedback.
-
This new diagram (#1175 (reply in thread)) makes much more sense, though it may still require some adjustments.
If it comes to RISC-V implementation - we'll have the concern raised by @en-sc (#1175 (comment)):
Regarding this point:
There are at least two issues known to me :
SWD had DAP (debug access point), JTAG has TAP (test access point). If you introduce, say PCIe interface - it does not make sense to configure jtag scan-chain that consists of TAPs (and each TAP requires certain transport-specific characteristics like IRLEN to be set). To me it looks like the presence of these new transports may require introduction of "access points" types - and this is the change that should be definitely discussed with upstream OpenOCD folks. |
Beta Was this translation helpful? Give feedback.
-
Thanks for your answer Anatoly. Ideally, we want to limit all of the changes in this proposal to remain within the RISCV port. Here are a few proposals:
Example of config file:
What do you think about this proposal? |
Beta Was this translation helpful? Give feedback.
-
Hi @anicic-nikola and all, General comments Overall, I like this proposal of having a higher-level RISC-V debug transport in OpenOCD very much. In fact, we have developed something similar in Codasip internally. It would be beneficial for the whole community to have a unified solution. Also thank you for describing the proposal in a very clear and understandable manner. Where to make the change - riscv-openocd vs. vanilla openocd.org Since there would be target-independent changes (in the transports), I am slightly more inclined to suggest the vanilla openocd.org upstream. I don't feel strongly, though. I will be happy to provide code reviews in either place. Comments to the concrete proposal I have posted my recommendation in a separate comment. Thanks and regards |
Beta Was this translation helpful? Give feedback.
-
Hi @JanMatCodasip @TommyMurphyTM1234 @en-sc @aap-sc Firstly thank you so much for reviewing this proposal. This is very helpful for us. Meantime we made some comments Pls take a look and let us know what you think Regards, Shankar/Nikola |
Beta Was this translation helpful? Give feedback.
-
Thanks for the proposal! If we consider running OpenOCD on a RISC-V hart, debug other RISC-V harts on the same chip. Assume the hardware is implemented in the most direct way, allowing hart to access the DMI bus, then OpenOCD can directly read and write the specified physical memory address equivalent to reading and writing the registers of the DMs. |
Beta Was this translation helpful? Give feedback.
-
Hi, guys, @TommyMurphyTM1234 @en-sc @JanMatCodasip @aap-sc @zqb-all We appreciate a lot your proposals. Here is the structure of the files added for this prototype:
and of course Makefiles updated. The interface of the dtm.h looks like this: // Defines the abstract interface for the Debug Transport Module (DTM)
#ifndef RISCV_TRANSPORT_DTM_H
#define RISCV_TRANSPORT_DTM_H
#include <stdint.h>
#include <stdbool.h>
typedef struct dtm_driver {
const char *name; // e.g., "jtag", "pcie", "socket"
int (*init)(struct dtm_driver *driver);
int (*deinit)(struct dtm_driver *driver);
int (*read_dmi)(struct dtm_driver *driver, uint32_t *data, uint32_t address);
int (*write_dmi)(struct dtm_driver *driver, uint32_t address, uint32_t data);
void *priv; // Private data for the driver
} dtm_driver_t;
int register_dtm_driver(dtm_driver_t *driver);
dtm_driver_t *get_dtm_driver(const char *name);
int select_dtm_driver(const char *name);
dtm_driver_t *get_active_dtm_driver(void);
#endif /* RISCV_TRANSPORT_DTM_H */ And then in
static const char * const riscv_dtm_transports[] = { "jtag", "socket", "pcie", NULL };
static dtm_driver_t socket_driver = {
.name = "socket",
.init = socket_dmi_init,
.deinit = socket_dmi_deinit,
.read_dmi = socket_dmi_read_dmi,
.write_dmi = socket_dmi_write_dmi,
.priv = NULL
}; to be compatible to this driver, so all these methods to create a socket, or send/receive dmi commands are registered to the driver itself. |
Beta Was this translation helpful? Give feedback.
-
Hi, guys @TommyMurphyTM1234 @JanMatCodasip @en-sc @aap-sc @zqb-all |
Beta Was this translation helpful? Give feedback.
-
Hi, guys @TommyMurphyTM1234 @zqb-all @aap-sc @en-sc @JanMatCodasip As you can see from this commit from my forked repo (that had some previous commits to it, too) I went around it in some hacky way to just see what needs to be changed and to later examine all of the necessary changes.
To halt a RISC-V core via DMI, we typically need to write to the Instead of just hacking around the JTAG dependencies, I'm exploring how we can extend OpenOCD to better support non-JTAG transports like our socket-based DMI communication. One idea is to introduce somehow a more abstract interface for target operations (halt, resume, etc.) that isn't tied to JTAG specifics. This would allow us to implement these operations in our custom transport driver. What are your thoughts on it? In the end, the idea is to bypass the JTAG if it is not needed, like it is logically not needed for the socket DMI communication with some server that accepts DMI commands, it does not make sense to have JTAG interface here in our case. |
Beta Was this translation helpful? Give feedback.
-
Hello. I have made a fork with the changes that I would like to enter the pull request for this repo to discuss how to tackle them. This is directly connected to this proposal: Summary
This is for public use. Since public repository will be referenced and changes needed will remain public, this document can be shared online without restrictions.
Motivation for the changeOpenOCD serves as a bridge between debuggers (e.g., GDB) and target hardware, enabling communication via configurable transports (e.g., JTAG, SWD) and adapters. It uses hardware-specific configuration files to manage the debugging process, including core halting, register access, and command execution. For RISC-V architectures, OpenOCD interacts with the target’s Debug Module Interface (DMI) to exchange messages, which involve abstract commands like reading/writing registers or controlling execution. The goal is to decouple DMI messaging from JTAG entirely, enabling alternative transport protocols (e.g., WebSocket, USB, or direct memory-mapped I/O) to send "raw" DMI requests to the target. This would bypass JTAG-specific logic (e.g., scan chain shifting) and streamline communication by sending structured DMI packets (address + data + opcode, per the RISC-V debug specification) directly. Examples of those are:
This approach simplifies OpenOCD’s codebase by isolating transport logic (JTAG, WebSocket, etc.) from the DMI protocol layer. Future contributors could more easily add new transports without inheriting JTAG’s complexity, while legacy JTAG workflows remain supported. The result aims to be cleaner, more extensible architecture that aligns with modern RISC-V hardware trends. Plan for RISCV specific changesAs per RISCV debug system overview - this is the graph representing how the debug information flows from the Debug Host via transport module to RISCV platform: The standard RISC-V debug architecture remains unchanged, top-level, but the implementation decouples the Debug Transport Hardware and Debug Transport Module (DTM) from a JTAG-specific dependency. Instead, a transport-agnostic interface exposes the Debug Module Interface (DMI), enabling alternative transport layers (e.g., socket, PCIe, or custom interfaces) to be implemented while preserving compliance with the specification (see the image below). The workflow would be: Current OpenOCD implementation is quite tied to the JTAG transport, data is sent in a way that is mean for a TAP controller of JTAG to be read, weather it is over the wire or via socket, but it is sent in a form of bytes like it would be over the wire to JTAG. We can do better than that and be more flexible. This is shown in the following image: Key Changes to the Diagram in the new approach (bypassing JTAG)
The DMI is a protocol (defined in the RISC-V debug specification) for reading/writing debug registers in the Debug Module (DM). An example use case would be an OpenOCD that sends DMI packets directly over a socket to the simulator’s debug interface instead of translating DMI commands to JTAG signals (via remote bitbang). Another example is a RISC-V chip with a socket-based debug backend (e.g., a UART-to-DMI bridge or Ethernet interface) that skips JTAG entirely. What has been done so far (in Esperanto technologies)Initial implementation and testing strategyPrototype developmentThe initial phase focuses on establishing a proof-of-concept simulation environment to validate OpenOCD’s ability to communicate Debug Module Interface (DMI) messages over a WebSocket transport, bypassing traditional JTAG/remote bitbang workflows.
To enable WebSocket transport support, targeted changes were made to OpenOCD’s RISC-V debug subsystem (see diff), including:
Current Progress and Next StepsThis work establishes a preliminary foundation for decoupling DMI from JTAG, with critical milestones achieved:
Outstanding tasks for future iterations include:
Changes done so far on the simulated server (Python server)As referenced above, all of the changes are in this python file.
DMI read handling (
|
Feature | Status | Notes |
---|---|---|
Register read/write | ✅ Done | Already implemented in execute_abstract_command() |
CSR read/write | ✅ Done | MISA, DCSR, DPC, MSTATUS etc |
Memory read | ✅ Done | Added postexec + lw/ld emulation |
Memory write | 🟡 Partial | Add sw/sd support in postexec |
Halt/resume | ✅ Done | DMCONTROL logic is good, just track target_state |
Reset | ✅ Done | ndmreset is handled in the python code |
progbuf support | ✅ Needed | Minimal support already there, just add instruction decode logic |
AbstractCS | ✅ Good | Keep updating busy, cmderr |
I would like to know where I might seek the approval to try to make this PR to this fork.
Thanks.
Beta Was this translation helpful? Give feedback.
-
As I said before, to have any chance of these sorts of extensive additions/changes to the general source base (not just RISC-V target specific support code) being accepted upstream in the master OpenOCD project, you should probably (also?) raise the discussion upstream in the OpenOCD mailing lists. No point in coming to some agreement here only for the resulting source code additions/changes being vetoed upstream. |
Beta Was this translation helpful? Give feedback.
-
@anicic-nikola (@anicicn84), AFAIU, to create a pull request you will need to use a different branch name. The error you are getting seems to be caused by the |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Why?
Our company, Esperanto Technologies, is actively working with RISC-V hardware and identified a need to support alternative transport methods for Debug Module Interface (DMI) communication beyond JTAG. While JTAG serves many use cases, expanding the supported transport layers to PCIe and Socket would enable:
Flexibility for developers with varying hardware setups.
Networking capabilities through socket-based communication.
Easier integration for RISC-V devices using PCIe for debugging.
These additions would not only meet our internal needs but also benefit the broader OpenOCD and RISC-V communities by demonstrating how to extend transport layers and enabling similar contributions from others.
What?
We propose introducing PCIe and Socket as new transport layers for OpenOCD in the riscv-openocd repository.
Key changes include:
transport select socket
. For the socket layer, additional configuration options like host and port will be added.dmi_read
anddmi_write
functions for RISC-V will dynamically route to the appropriate transport implementation (JTAG, PCIe, or socket) based on user configuration.The selected transport implementation will be injected into the RISCV_INFO structure, ensuring seamless functionality during debugging.
How?
Implementation: We plan on introducing modular transport layers, starting with PCIe and socket, under
src/transport
. Then to modify RISC-V-specificdmi_read
anddmi_write
to invoke the correct transport function dynamically.Extending the OpenOCD configuration parser to allow transport selection (jtag, pcie, socket) will be done if needed, but we believe the transport selection function should follow OpenOCD transport infrastructure pattern. and additional parameters for the socket transport will be done.
Our goal is also to engage the OpenOCD community early, seeking feedback on design and implementation to align with the project's goals and to maintain high code quality.
We believe these changes will make OpenOCD more flexible and powerful for RISC-V developers, both inside and outside of our organization.
Does this proposal align with the community's goals?
Are there additional considerations we should address before proceeding?
Looking forward to your thoughts and suggestions!
Best regards,
Nikola Anicic and Shankar Jayaratnam @NinjaDev108
Esperanto Technologies
Beta Was this translation helpful? Give feedback.
All reactions