OpenOCD¶
Experimental
Tested against a simulated OpenOCD server only so far; the API may change in minor releases.
See the JTAG / SWD guide for an introduction.
openocd
¶
Client for OpenOCD's TCL RPC server (default port 6666).
Example
from hwntools import OpenOCD
ocd = OpenOCD() # openocd -f interface/... -f target/... running locally
ocd.halt()
boot = ocd.read_memory(0x08000000, 0x100)
ocd.dump(0x08000000, 0x10000, out="flash.bin")
OpenOCD
¶
Talk to a running OpenOCD instance over its TCL RPC socket.
Each command is sent as <cmd>\x1a and the reply is read until \x1a. Errors are
detected by wrapping commands in catch so they are reported as OpenOCDError.
raw
¶
Send a raw TCL command and return OpenOCD's reply (no error checking).
cmd
¶
Run command; raise OpenOCDError if it fails. Returns its result.
halt
¶
Halt the current target, waiting up to timeout_ms milliseconds.
read_memory
¶
Read size bytes at address.
Uses read_memory (OpenOCD >= 0.12) and falls back to mem2array on older
builds. width is the access width in bits (8/16/32/64); size must be a multiple
of width // 8.
write_memory
¶
Write data at address (RAM / MMIO; use flash_write_image for flash).
read_u32
¶
Read one little-endian 32-bit word at address (32-bit access).
write_u32
¶
Write one little-endian 32-bit word at address (32-bit access).
dump
¶
dump(address: int, size: int, out: str | PathLike[str] | None = None, chunk: int = 4096, width: int = 8) -> bytes
Read a large region over RPC in chunks with progress; optionally save it.
dump_image
¶
Have OpenOCD write memory to path on the OpenOCD host (fast, server side).
load_image
¶
Load an image file (on the OpenOCD host) into target RAM.
flash_read_bank
¶
Dump a flash bank to path on the OpenOCD host.
flash_write_image
¶
Program flash from an image file. Destructive: requires force=True.