Close

Chapter 3 - JTAG

A project log for Wi-Fi Router Autopsy

Breathe new life into an old Wi-Fi router: explore hardware - software connections, reverse engineer components, and test security.

yalukeyaluke 03/25/2025 at 19:380 Comments

As I found in chapter 1, my TP-Link TL-WR1043ND ver 1.8 router has a JTAG port available on the board. This discovery opens up exciting possibilities for deeper exploration and manipulation of the device. JTAG (Joint Test Action Group) is a powerful interface that allows direct access to the router's hardware, enabling advanced debugging, firmware extraction, and even potential security research.

In this chapter, we'll delve into connecting to the JTAG port using a Raspberry Pi 5 as our debugging tool. This approach offers a cost-effective and accessible method for hardware enthusiasts and security researchers to interact with the router at a low level. We'll explore the capabilities of JTAG, from basic connectivity to more advanced operations like dumping the router's flash memory.

Let's embark on this journey to unlock the full potential of our TP-Link router through the power of JTAG interfacing.

What is JTAG?

JTAG, which stands for Joint Test Action Group, is a powerful and versatile hardware interface standard that has become integral to electronics testing, debugging, and programming. Originally developed in the 1980s, JTAG was designed to address the challenges of testing increasingly complex printed circuit boards (PCBs) with densely packed components.

At its core, JTAG provides a standardized method for accessing and controlling the pins of integrated circuits (ICs) on a PCB without the need for physical probing. This is achieved through a simple serial interface, typically consisting of four or five pins:

JTAG's primary functions include:

The JTAG interface has become so ubiquitous that it's now found in most modern microprocessors, FPGAs, and many other types of ICs. Its versatility has made it an essential tool for hardware developers, allowing them to test, debug, and program devices throughout the development lifecycle and even after product deployment.

Raspberry Pi 5 as a JTAG debugging tool

The Raspberry Pi 5, released in late 2023, introduces a powerful yet cost-effective platform for JTAG debugging, particularly suited for enthusiasts and researchers working on projects like our TP-Link TL-WR1043ND router exploration. Priced at around $80 USD, it offers an accessible entry point into advanced hardware debugging.

Key features of the Raspberry Pi 5 as a JTAG debugging tool include:

However, the platform does come with some limitations:

Despite these challenges, the Raspberry Pi 5 excels in firmware extraction tasks, achieving speeds of approximately 850 KB/s. However, it may show some limitations in real-time register access compared to dedicated professional debuggers.

The platform's versatility and low cost make it an attractive option for hobbyists and researchers, especially those working on projects like our router exploration. While it requires some additional configuration and workarounds, the Raspberry Pi 5 offers a powerful and flexible solution for JTAG debugging tasks.

Physical Connection: Raspberry Pi 5 to TP-Link JTAG Interface

JTAG Connector Identification

The TP-Link TL-WR1043ND v1.8 features a 14-pin EJTAG 2.6 standard header located near the serial port (labeled “JP1" on PCB):

This aligns with OpenWRT documentation confirming MIPS EJTAG compliance. The JTAG 2.6 header follows this pin arrangement:

PinSignalFunction
1nTRSTTest Reset (Optional)
3TDITest Data In
5TDOTest Data Out
7TMSTest Mode Select
9TCKTest Clock
11nSRSTSystem Reset (optional)
2, 4, 6, 8, 10GNDGround
14VREFVoltage Reference (3.3V)
12, 13Not used

Minimal Raspberry Pi 5 Connection Scheme

Router JTAG PinRPi 5 GPIOPhysical PinSignal Voltage
3 (TDI)GPIO26Pin 373.3V
5 (TDO)GPIO24Pin 183.3V
7 (TMS)GPIO27Pin 133.3V
9 (TCK)GPIO25Pin 223.3V
2 (GND)GNDPin 39-

Connection notes:

Raspberry Pi 5 software configuration

With physical connections established, we configure Raspberry Pi OS (Bookworm) for JTAG operation. On a fresh, updated system:
Enable JTAG in boot configuration:

sudo nano /boot/firmware/config.txt

 Add following lines under [all] section:

enable_jtag_gpio=1
gpio=22-27=a4

And reboot RPi.

To connect to the router OpenOCD (Open On-Chip Debugger) will be used. OpenOCD is a tool for debugging, in-system programming, and boundary-scan testing for embedded devices. Install dependencies first, then clone and build the tool

sudo apt install git libtool pkg-config autoconf automake texinfo libusb-1.0-0-dev libgpiod-dev build-essential
git clone https://github.com/raspberrypi/openocd.git
cd openocd
./bootstrap
./configure --enable-linuxgpiod
make -j$(nproc)
sudo make install

 After successful installing OpenOCD create configuration file for this tool - name it rpi5-jtag.cfg and add following content:

adapter driver linuxgpiod

adapter gpio tck 25 -chip 4
adapter gpio tms 27 -chip 4
adapter gpio tdi 26 -chip 4
adapter gpio tdo 24 -chip 4
adapter gpio trst 22 -chip 4

transport select jtag

source [find target/atheros_ar9331.cfg]

Last, optional line add hardware specific configuration to this file - as there is no config for Atheros AR9132, similar (working) chipset is used. To verify if it works type: 

sudo openocd -f rpi5-jtag.cfg

 And check if there are no warnings or errors in the output:

Open On-Chip Debugger 0.12.0+dev-gcf9c0b41c (2025-03-24-21:05)
Licensed under GNU GPL v2
For bug reports, read
    http://openocd.org/doc/doxygen/bugs.html
ar9331_ddr2_init
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : Linux GPIOD JTAG/SWD bitbang driver
Info : Note: The adapter "linuxgpiod" doesn't support configurable speed
Info : JTAG tap: ar9331.cpu tap/device found: 0x00000001 (mfg: 0x000 (<invalid>), part: 0x0000, ver: 0x0)
Info : [ar9331.cpu] Examination succeed
Info : starting gdb server for ar9331.cpu on 3333
Info : Listening on port 3333 for gdb connections

Now OpenOCD runs and waits for connection.

Dumping flash using JTAG

As OpenOCD reported, it listening on port 4444 for telnet connection. Let’s switch to another terminal; after  installing telnet and connecting to our device using following commands:

sudo apt install telnet

telnet localhost 4444

 We should see:

Trying ::1...
Connection failed: Connection refused
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Open On-Chip Debugger
> 

We are in! Now we can  play with the router - check available commands with help (there are a lot more possibilities than using UART). To dump flash content (without custom script with error handling as we did in the chapter 1) type: 

> halt
> dump_image full_flash.bin 0xbf000000 0x800000

And after around 40 minutes binary file is on the disk.

This configuration leverages the RP1's GPIO interface despite its performance limitations, providing a functional open-source alternative to commercial JTAG debuggers. The GPIO mapping reflects physical constraints of the Pi 5's revised layout compared to earlier models.

Discussions