How metagur/nds-openocd works
Project type and purpose
• OpenOCD is an open-source, command-line on-chip debugger and programmer.
• It provides a layered architecture of:
• Transport and adapter drivers (e.g. USB, FTDI, bit-bang)
• A JTAG/SWD core with TAP and target support
• Flash and (X)SVF/CPLD programming engines
• Embedded Tcl interpreter and network servers (GDB, Telnet, TCL)
Main architectural components
a. User Interfaces (CLI & Scripting)
• openocd.c / main.c: command-line entry point
• Embedded Jim-Tcl interpreter (in jimtcl/, tcl/)
• Network servers: GDB server, Telnet server, Tcl server (src/server/)
b. Command Dispatcher & Configuration
• Parses CLI args and config scripts (src/helper/ modules)
• Loads board/interface/target config files (tcl/board/, tcl/interface/, tcl/target/)
c. Transport Layer
• Abstraction in src/transport/
• Supports USB, parallel, sysfs-GPIO, etc.
d. Adapter Drivers (JTAG/SWD Interfaces)
• src/jtag/transport and src/jtag/drivers/
• Plugin-style drivers for FTDI, CMSIS-DAP, Bus Pirate, OpenOCD-USB, etc.
e. JTAG/SWD Core & TAP Engine
• src/jtag/core.c, src/jtag/interface.c, src/jtag/adapter.c
• Manages TAP state machine, IR/DR shifts
f. Target Support
• src/target/: per-architecture modules (ARMv7, RISC-V, MIPS, etc.)
• Implements register access, semihosting, simulators, caches, breakpoints
g. Flash Programming & SVF Engines
• src/flash/: NOR & NAND flash drivers, src/svf/ and src/xsvf/
h. Optional RTOS Helpers & RTT
• src/rtos/, src/rtt/ for RTOS hooks and real-time trace
i. TCL Scripts
• High-level procedure scripts under tcl/ for board, chip, interface, etc.
j. Contrib and Tooling
• Build helpers, cross-build scripts, testing examples in contrib/, tools/, testing/
Relationships & Data Flow
• User invokes openocd → CLI
• CLI → Command Dispatcher loads Tcl scripts/configs
• Dispatcher → initializes Transport + Adapter Driver
• Adapter → drives signals into JTAG/SWD Core
• Core → uses TAP engine to communicate with Target modules
• Target modules → optional Flash/SVF engines for memory programming
• Meanwhile, the Network Servers expose GDB/Telnet/Tcl protocols to clients, routing commands into the Dispatcher and back out to the Target layer
• All components can be treated as loadable “plugins”
Architectural Patterns & Principles
• Layered architecture: clear separation of UI, dispatch, transport, core, target
• Plugin/extensibility: adapters, targets, flash drivers, network servers loaded at runtime
• Interpreter pattern: embedded Tcl for scriptable control
• Autotools build: modular Makefile.am in each directory