# riscv-collab/riscv-openocd architecture

> Architecture diagram of the GitHub repository riscv-collab/riscv-openocd, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-02-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/riscv-collab/riscv-openocd
- Repository: https://github.com/riscv-collab/riscv-openocd

## Overview

##### Core Components (Main Layers)

a. Interface Layer
- Supported hardware interfaces (JTAG, SWD, etc.)
- Interface adapter drivers (FTDI, CMSIS-DAP, ST-LINK, etc.)

b. Transport Layer
- Above the interface layer
- JTAG and SWD protocol implementations
- Debug transport abstractions

c. Target Layer
- Above the transport layer
- CPU architecture support (ARM, RISC-V, MIPS, etc.)
- Flash drivers and target-specific implementations

d. Server Layer
- Supported protocols (GDB, Telnet, TCL)
- Command interpreter

##### Cross-cutting Components

a. Helper/Utility Services
- On the side
- Common utilities (logging, configuration, etc.)

b. TCL Scripting Engine
- As an interconnecting component
- How it interfaces with all layers
- Use a distinctive pattern or border

##### Key Interactions

a. Data Flow
- Direction from interface through layers to servers
- Bidirectional communication where applicable

b. Control Flow
- Configuration and command paths
- Initialization sequences

##### External Interfaces

a. Client Tools
- GDB, IDEs, and other tools at the top
- To appropriate server interfaces
- Use external entity symbols

b. Hardware Connections
- Debug adapters at the bottom
- Target devices
- Use hardware symbols

##### Important Details

a. Configuration System
- How config files are processed
- Board, target, and interface configs
- Where TCL scripts integrate

b. Flash Programming
- Flash algorithm loading path
- Flash driver architecture
- Memory access paths

##### Implementation Notes

- Clear labels for all components
- Version or date of the architecture
- Brief descriptions of key components

##### Architectural Patterns

- Layered architecture
- Plugin system for drivers
- Command handling flow
- Demonstrate extensibility points

Remember to:
- Sufficient detail for implementation understanding
- Both static structure and dynamic interactions

This architecture reflects OpenOCD's modular design and its ability to support multiple debug adapters, targets, and client protocols while maintaining a clean separation of concerns.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Define styles
    classDef server fill:#b3d9ff,stroke:#333,stroke-width:2px
    classDef transport fill:#90EE90,stroke:#333,stroke-width:2px
    classDef adapter fill:#FFE5B4,stroke:#333,stroke-width:2px
    classDef dmi fill:#FFA07A,stroke:#333,stroke-width:2px
    classDef target fill:#FFB6C1,stroke:#333,stroke-width:2px
    classDef config fill:#E6E6FA,stroke:#333,stroke-width:2px

    subgraph GDB
        GS["GDB Server (RSP)"]:::server
        click GS "https://github.com/riscv-collab/riscv-openocd/blob/riscv/src/server/gdb_server.c"
    end

    subgraph Transport
        JT["JTAG Transport"]:::transport
        SW["SWD Protocol"]:::transport
        click JT "https://github.com/riscv-collab/riscv-openocd/blob/riscv/src/jtag/jtag.h"
        click SW "https://github.com/riscv-collab/riscv-openocd/blob/riscv/src/jtag/swd.h"
    end

    subgraph Adapters
        FTDI["FTDI"]:::adapter
        CMSIS["CMSIS-DAP"]:::adapter
        STLINK["ST-LINK"]:::adapter
        JLINK["J-LINK"]:::adapter
        click FTDI "https://github.com/riscv-collab/riscv-openocd/blob/riscv/src/jtag/drivers/ftdi.c"
        click CMSIS "https://github.com/riscv-collab/riscv-openocd/blob/riscv/src/jtag/drivers/cmsis_dap.c"
        click STLINK "https://github.com/riscv-collab/riscv-openocd/blob/riscv/src/jtag/drivers/stlink_usb.c"
        click JLINK "https://github.com/riscv-collab/riscv-openocd/blob/riscv/src/jtag/drivers/jlink.c"
    end

    subgraph DMI
        ADI["ARM ADI v5"]:::dmi
        DAP["ARM DAP"]:::dmi
        click ADI "https://github.com/riscv-collab/riscv-openocd/blob/riscv/src/target/arm_adi_v5.c"
        click DAP "https://github.com/riscv-collab/riscv-openocd/blob/riscv/src/target/arm_dap.c"
    end

    subgraph Target
        ARM["ARM Core"]:::target
        RISCV["RISC-V Core"]:::target
        click ARM "https://github.com/riscv-collab/riscv-openocd/blob/riscv/src/target/arm.h"
        click RISCV "https://github.com/riscv-collab/riscv-openocd/blob/riscv/src/target/riscv/riscv.c"
    end

    %% Command flow (downward)
    GS -->|"Debug Commands"| JT & SW
    JT --> FTDI & CMSIS & STLINK & JLINK
    SW --> FTDI & CMSIS & STLINK & JLINK
    FTDI & CMSIS & STLINK & JLINK --> ADI
    ADI --> DAP
    DAP --> ARM & RISCV

    %% Response flow (upward)
    ARM & RISCV -.->|"Debug Response"| DAP
    DAP -.-> ADI
    ADI -.-> FTDI & CMSIS & STLINK & JLINK
    FTDI & CMSIS & STLINK & JLINK -.-> JT & SW
    JT & SW -.-> GS

    %% Legend
    subgraph Legend
        L1[GDB Server]:::server
        L2[Transport]:::transport
        L3[Adapter]:::adapter
        L4[DMI]:::dmi
        L5[Target]:::target
        L6["---> Command Flow"]
        L7["--> Response Flow"]
    end
```
