Skip to content

Lesson 2 of 14 · 18m

JTAG and SWD: When the CPU Itself Answers to You

Halt the processor, read live memory, and dump flash through the debug port — regardless of what the firmware wants.

UART gives you the console the firmware chose to expose. JTAG and SWD skip the firmware's opinion entirely — they talk to the CPU. Halt a running processor mid-instruction, single-step it, read and write registers and RAM, dump flash through the debug port. If the debug pins are alive, the software running on the device does not get a vote.

Two interfaces, same power

JTAG is IEEE 1149.1, originally designed for boundary-scan board test — verifying solder joints, not security. The debug line is four pins: TCK (clock), TMS (mode select), TDI (data in), TDO (data out), with TRST as an optional reset. ARM cores layered debug access on top of the boundary-scan machinery decades ago, and it never left.

SWD — Serial Wire Debug — is ARM's two-wire answer: SWDIO (data) and SWCLK (clock) plus ground. Every Cortex-M on earth has it. Same capabilities as JTAG with half the pins, which is why IoT-class ARM silicon almost always exposes SWD instead of full JTAG.

Finding and enumerating pins

SWD is easy: three pins, and a logic analyzer on the candidates during activity finds SWCLK (always clocking) immediately.

JTAG pin identification is harder because there are more pins and order matters. The tool built for it is the JTAGulator — Joe Grand's open-source enumerator. Wire every candidate pin to it and it brute-forces the pinout: it tries every combination of TCK/TMS/TDI/TDO looking for an IDCODE response, then maps the instruction register via BYPASS discovery. What used to be days of datasheet hunting is minutes of automated probing.

Driving the port: OpenOCD

The open-source driver for all of this is OpenOCD. You give it an interface config and a target config:

openocd -f interface/jtagulator.cfg -f target/stm32f4x.cfg
telnet localhost 4444

On the telnet console:

reset halt          # stop the CPU
flash probe 0       # enumerate onboard flash
mdw 0x08000000 16   # read 16 words of flash-mapped memory
dump_image fw.bin 0x08000000 0x00020000   # carve firmware out

GDB attaches on port 3333 if you want to debug the live firmware — set breakpoints in shipped code on shipped hardware.

What debug access actually reaches

Two things matter more than the mechanics.

First, it reads live state. On devices with flash encryption (ESP32-class, secure eMMC paths), the flash image at rest is ciphertext — but the memory a halted CPU holds is plaintext. Dump RAM over SWD and you have the decrypted secrets the encryption was supposed to protect. Encryption at rest is a storage control; the debug port is an execution control. Different layer, and a lot of threat models forget that.

Second, vendors know this, which is why readout protection exists: STM32's RDP levels, nRF52's APPROTECT, eFuse bits that disable the port. Those controls are real but finite. LimitedResults published voltage-glitching bypasses against the nRF52840's readout protection — fault injection rigs like ChipWhisperer exist precisely because "disabled" debug hardware can sometimes be glitched back open. On a high-value target, fused-off pins raise the cost of entry; they don't make it infinite.

The wrong model this kills

Teams treat "we locked the serial console" or "we removed the test pads" as closure. It isn't. The debug port is a separate input path that bypasses every software lock by construction — it operates on the CPU, not on the firmware's policy. A device with a dead UART and live SWD is not hardened; it's just quieter.

Practice

On your own silicon: enumerate the pins (JTAGulator or a datasheet plus a logic analyzer), attach OpenOCD, reset halt, dump the flash and RAM. Then check the protection state — RDP level, APPROTECT, DIS_JTAG-class eFuses — and decide what the production fuse policy should be. For shipping hardware the honest answer is: burn the debug-disable fuse in manufacturing, keep a test firmware that leaves it open on dev boards, and assume a funded attacker can glitch past it anyway. Defend the rest of the stack accordingly.

Was this lesson helpful?

Sign in to rate

Keep reading

Related articles from the SudoSecurity blog.