jtag¶
JTAGCartridge
¶
Agentic JTAG operations driven through OpenOCD.
The cartridge composes an :class:OpenOCDTransport with a
:class:~wintermute.utils.blob_manager.WorkspaceManager so that bulk
artefacts (for example, firmware dumps) bypass the LLM context window
entirely and instead surface as compact descriptors.
Each public method is strictly typed and carries a Google-style docstring
so that :func:wintermute.ai.utils.tool_factory.function_to_tool can
expose it to the AI as a JSON-schema tool.
Source code in wintermute/cartridges/jtag.py
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 | |
dump_firmware(start_address, size_bytes, filename='firmware.bin')
¶
Dump a memory region directly to disk via OpenOCD's dump_image.
dump_image writes the requested range straight to a file inside
the workspace directory, so multi-megabyte firmware blobs never
traverse Python memory or the LLM context. Once the dump finishes,
the file is adopted by the
:class:~wintermute.utils.blob_manager.WorkspaceManager (which
renames it to a content-addressed slot) and a JSON descriptor is
returned.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start_address
|
str
|
Memory address to start dumping from, as a string.
Hex literals ( |
required |
size_bytes
|
int
|
Number of bytes to dump. Must be positive. |
required |
filename
|
str
|
Hint for the output filename. Only the basename and suffix are honoured; the file is renamed to its SHA-256 digest after the dump completes. |
'firmware.bin'
|
Returns:
| Type | Description |
|---|---|
Dict[str, Union[str, int]]
|
A descriptor dictionary with the keys |
Dict[str, Union[str, int]]
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
OpenOCDError
|
If |
RuntimeError
|
If OpenOCD claims success but the expected file is missing. |
ConnectionError
|
If the transport cannot reach the daemon. |
TimeoutError
|
If the daemon does not respond in time. |
Source code in wintermute/cartridges/jtag.py
395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 | |
halt_core()
¶
Halt the target CPU at its current instruction.
Sends OpenOCD's halt command, which stops execution and lets the
debugger inspect or modify state. Useful before reading registers,
dumping memory, or single-stepping.
Returns:
| Type | Description |
|---|---|
bool
|
|
Raises:
| Type | Description |
|---|---|
OpenOCDError
|
If OpenOCD's response contains an |
ConnectionError
|
If the transport cannot reach the daemon. |
TimeoutError
|
If the daemon does not respond in time. |
Source code in wintermute/cartridges/jtag.py
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 | |
read_memory(address, word_count=1)
¶
Read one or more 32-bit words from target memory.
Sends OpenOCD's mdw <address> <word_count> command. The response
is returned verbatim (with the prompt stripped) so the caller can
present the original ADDR: word0 word1 ... layout to the LLM.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
address
|
str
|
Target address as a string. Hex literals ( |
required |
word_count
|
int
|
Number of 32-bit words to read. Must be at least 1. |
1
|
Returns:
| Type | Description |
|---|---|
str
|
The cleaned text body of OpenOCD's response, including the |
str
|
address prefix and the space-separated hex words. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
OpenOCDError
|
If OpenOCD reports an error in its response. |
ConnectionError
|
If the transport cannot reach the daemon. |
TimeoutError
|
If the daemon does not respond in time. |
Source code in wintermute/cartridges/jtag.py
337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 | |
read_registers()
¶
Read every general-purpose register from the halted target.
Sends OpenOCD's reg command, which prints one register per line in
the form (<idx>) <name> (/<bits>): 0x<value>. The output is
parsed into a flat {name: hex_value} mapping suitable for
downstream JSON serialisation.
Returns:
| Type | Description |
|---|---|
Dict[str, str]
|
A dictionary mapping each register name (e.g. |
Dict[str, str]
|
|
Raises:
| Type | Description |
|---|---|
OpenOCDError
|
If OpenOCD reports an error in its response. |
ConnectionError
|
If the transport cannot reach the daemon. |
TimeoutError
|
If the daemon does not respond in time. |
Source code in wintermute/cartridges/jtag.py
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 | |
resume_core()
¶
Resume execution of a previously-halted target.
Sends OpenOCD's resume command. Pair with :meth:halt_core when
you need a temporary debug window.
Returns:
| Type | Description |
|---|---|
bool
|
|
Raises:
| Type | Description |
|---|---|
OpenOCDError
|
If OpenOCD's response contains an |
ConnectionError
|
If the transport cannot reach the daemon. |
TimeoutError
|
If the daemon does not respond in time. |
Source code in wintermute/cartridges/jtag.py
293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 | |
write_memory(address, hex_value)
¶
Write a single 32-bit word to target memory.
Sends OpenOCD's mww <address> <hex_value> command. The target
usually needs to be halted via :meth:halt_core before the write
will take effect.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
address
|
str
|
Target address (hex or decimal) as a string. |
required |
hex_value
|
str
|
32-bit value to write, as a hex literal
(e.g. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
Raises:
| Type | Description |
|---|---|
OpenOCDError
|
If OpenOCD reports an error in its response. |
ConnectionError
|
If the transport cannot reach the daemon. |
TimeoutError
|
If the daemon does not respond in time. |
Source code in wintermute/cartridges/jtag.py
367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 | |
OpenOCDConfig
¶
Bases: BaseModel
Connection settings for the OpenOCD telnet/RPC console.
OpenOCD's default telnet console listens on localhost:4444 and
terminates each response with a > prompt. The values here are the
OpenOCD defaults; override them to point at a remote rig or a custom
build that uses a different prompt.
Source code in wintermute/cartridges/jtag.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 | |
OpenOCDError
¶
Bases: RuntimeError
Raised when OpenOCD reports an error in a command response.
Source code in wintermute/cartridges/jtag.py
89 90 | |
OpenOCDTransport
¶
Manages a TCP socket connection to OpenOCD's telnet console.
The transport is lazy: the socket is opened on the first call to
:meth:execute_command. The banner and any pre-prompt chatter are
drained automatically so callers only ever see the cleaned response
body for the command they issued.
Source code in wintermute/cartridges/jtag.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 | |
connected
property
¶
Whether the underlying socket is currently open.
close()
¶
Close the underlying socket if it is open.
Source code in wintermute/cartridges/jtag.py
143 144 145 146 147 148 149 150 151 | |
connect()
¶
Open the socket and consume the OpenOCD banner.
Subsequent calls are no-ops while the socket stays alive.
Raises:
| Type | Description |
|---|---|
ConnectionError
|
If the OpenOCD daemon cannot be reached. |
TimeoutError
|
If the banner does not appear within
|
Source code in wintermute/cartridges/jtag.py
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | |
execute_command(cmd, timeout=5)
¶
Send cmd to OpenOCD and return the cleaned response text.
The transport connects on first use, sends cmd followed by a
newline, and reads bytes until OpenOCD emits its > prompt. Both
the trailing prompt and any echoed command line are stripped before
the response is returned.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cmd
|
str
|
The OpenOCD command to send (without a trailing newline). |
required |
timeout
|
int
|
Maximum seconds to wait for the prompt before raising
:class: |
5
|
Returns:
| Type | Description |
|---|---|
str
|
The response body stripped of the prompt and surrounding |
str
|
whitespace. |
Raises:
| Type | Description |
|---|---|
ConnectionError
|
If the daemon cannot be reached or drops the connection mid-read. |
TimeoutError
|
If OpenOCD does not return a prompt in time. |
Source code in wintermute/cartridges/jtag.py
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 | |