Skip to content

Lesson 6 of 13 · 18m

JTAG and SWD: Owning the Die

JTAG halts cores and reads memory through a debug state machine; readout protection slows a patient attacker by hours, not forever.

The debug port is a debugger

UART gives you what the firmware chose to print. JTAG gives you the CPU. The JTAG TAP is a state machine with four or five lines — TCK, TMS, TDI, TDO, optionally TRST — that shifts instructions and data through registers the silicon designer put there for exactly this: halt the core, single-step it, read and write registers, and on most SoCs reach the entire memory map through a debug access port without the core's cooperation. ARM's two-wire SWD (SWDIO, SWCLK) does the same job with fewer pins; on Cortex parts the MEM-AP can walk physical address space while the CPU keeps running.

Chips are daisy-chained on one TAP — SoC behind FPGA behind CPLD — each identified by an IR length and an IDCODE, and the hardware that talks to the chain is a J-Link, a Tigard, or a Bus Pirate. Finding the pins on an unlabeled board is what JTAGenum exists for: a script that brute-forces pin combinations on an Arduino or Pi header until an IDCODE answers — the 32-bit register encoding manufacturer, part, and revision that every TAP is required to expose. From there the tooling is OpenOCD: openocd -f interface/jlink.cfg -f target/stm32f1x.cfg opens a GDB server on 3333 and a telnet console on 4444. reset halt, mdw 0x08000000 64, dump_image flash.bin 0x08000000 0x100000 — that is the entire workflow. With GDB attached to port 3333 (target extended-remote localhost:3333) you get breakpoints, watchpoints, and load/mon dump_image on top. Firmware extraction without touching the flash chip, RAM dumps containing keys the software thought were memory-only, single-stepping through a secure-boot verification to watch it decide. Two different powers ride the same pins: boundary scan — the original JTAG purpose, driving and sampling device pins for board test — and core debug. Audits use both; dump_image against a halted core is the one that ends engagements — time the halt before software scrubs its buffers, because peripherals and DMA do not stop just because the core did.

The wrong mental model

"Readout protection means the flash is safe." RDP is a flag checked by code — and code executes on hardware that glitches. On STM32F1, RDP1 disables debug access, but voltage fault injection timed to the clock edge where the protection check runs skips it (LimitedResults' chip.fail work demonstrated this in 2019; a ChipWhisperer does it on a bench in an afternoon). Nordic's APPROTECT on the nRF52 was the same shape — a UICR flag, not a lock — and their 2020 debug-resurrection glitch re-opened it on shipping parts. RDP2 is marketed as permanent because the flag is one-way. It is an inconvenience, not a proof — the fault-injection literature keeps lengthening, and the honest model is "extraction requires a motivated attacker with modest equipment," not "extraction is impossible." Modern silicon answers differently where debug authentication exists (ARM ADIv6 debug authentication, NXP secure debug): the port stays physically live but opens only to a challenger holding the right credential — the model to ask for when a vendor insists they need JTAG in production.

The other direction is just as wrong: assuming JTAG is disabled because the header is unpopulated. The TAP is inside the die. Production eFuses are what disable it — a blown fuse, not a missing header.

What to actually do

As an auditor: enumerate the chain, dump flash via the core or the memory-mapped SPI window, dump RAM for keys, and treat every discovered TAP as an open door the vendor left.

As someone shipping product: blow the debug eFuse on production units and test that it took — this is a QA step, not a hope. If field debug is genuinely needed, use the silicon's authenticated debug (ARM DAP authentication, NXP secure debug) rather than leaving the port open and unauthenticated. And internalize the consequence for key management: anything readable by dump_image is readable by an attacker with the same four wires. Long-lived secrets belong in a secure element or fused key vault, not in flash the debug port can walk.

Was this lesson helpful?

Sign in to rate

Keep reading

Related articles from the SudoSecurity blog.