JTAG and Boundary Scan Testing: PCB and Chip-Level Verification
JTAG (IEEE 1149.1) is a serial protocol built into most modern chips that gives you direct access to I/O pins without physical probing. Boundary scan uses JTAG to test PCB interconnects: find solder bridges, open joints, stuck-at faults, and continuity problems. The same JTAG port that manufacturing uses to test bare boards is the one you use to debug firmware, program flash, and read CPU registers in the field.
A PCB arrives from manufacturing. It has 800 nets, 5 BGAs with 256 balls each, and 23 passive decoupling capacitors. You power it up and nothing works. Where do you start?
Before JTAG and boundary scan, the answer was a bed-of-nails fixture — a custom jig with spring-loaded probes touching test points on every net. You'd program the fixture, press the board into it, and the fixture would measure continuity on all nets simultaneously. It worked, but the fixtures cost $10,000–$50,000 each, took 6 weeks to build, and were obsolete the moment the board layout changed. BGA packages made it worse: you can't probe under a BGA. The solder balls are inaccessible.
Boundary scan was designed specifically to solve this problem. It uses a serial scan chain that was already present in the silicon for manufacturing test, making it accessible through four (or five) external pins that you can get to on any PCB.
JTAG Protocol Fundamentals (IEEE 1149.1)
JTAG defines a Test Access Port (TAP) with these signals:
| Signal | Direction | Description |
|---|---|---|
| TCK | Input | Test Clock — all TAP operations are synchronous to TCK |
| TMS | Input | Test Mode Select — controls the TAP state machine |
| TDI | Input | Test Data In — serial data shifts in on rising TCK edge |
| TDO | Output | Test Data Out — serial data shifts out on falling TCK edge |
| TRST# | Input (optional) | Test Reset — asynchronous reset of the TAP (pin 5) |
The TAP controller is a 16-state finite state machine defined by the standard. Every operation — selecting an instruction, loading data, reading data — is performed by navigating this state machine using the TMS signal:
Test-Logic-Reset
|
v (TMS=0)
Run-Test/Idle
|
+-- (TMS=1) --> Select-DR-Scan
| |
| (TMS=0) --> Capture-DR
| |
| (TMS=0) --> Shift-DR <--- serial data shifts here
| |
| (TMS=1) --> Exit1-DR
| |
| (TMS=1) --> Update-DR
|
+-- (TMS=1) --> Select-IR-Scan
|
(TMS=0) --> Capture-IR
|
(TMS=0) --> Shift-IR <--- instruction shifts hereTo perform a JTAG operation, you:
- Navigate to Shift-IR, clock in an instruction (e.g., BYPASS, EXTEST, SAMPLE)
- Navigate to Shift-DR, clock in/out data for that instruction
- Navigate to Update-DR to apply the data
Boundary Scan Architecture
Every JTAG-compliant chip has a Boundary Scan Register (BSR) — a shift register with one cell per I/O pin. Each BSR cell can:
- Capture the current state of the pin (sample the actual digital value)
- Drive the pin to a specified value (override the core logic)
- Observe the result
The BSR connects all pins into a single long shift register, accessible through TDI/TDO. The full register might be hundreds of bits long for a complex device.
TDI --> [Pin1_Cell] --> [Pin2_Cell] --> [Pin3_Cell] --> ... --> [PinN_Cell] --> TDOThe key JTAG instructions for boundary scan:
SAMPLE/PRELOAD — shifts the current state of all I/O pins into the BSR without affecting normal chip operation. Used to observe the live state of the board.
EXTEST — disconnects the core logic, drives BSR values onto the pins, and captures what comes back. Used to drive and observe PCB interconnects.
BYPASS — inserts a single-bit shift register (the Bypass Register) between TDI and TDO, allowing the chain to be shortened when a device doesn't need to participate in the current operation.
IDCODE — loads the device's 32-bit identification code into the data register. Used to identify which device is present on the JTAG chain.
What Boundary Scan Can Test
Interconnect (Net) Testing
The most common use: verify that every net connecting two JTAG-capable devices is correctly soldered and not shorted.
Procedure:
- Drive a pattern on device A's output pins via EXTEST
- Capture the result on device B's input pins
- Compare captured values to expected values
Device A PCB Trace Device B
[Output BSR cell] ---/\/\--- [Input BSR cell]
Drive '1' on Device A output
Capture Device B input: expect '1' (open/correct solder joint)
Capture Device B input: expect '0' (short to ground)
Capture Device B input: expect '1' always (stuck-at-1 fault)For N-to-M connections, you walk a '1' across all output pins and observe all input pins, detecting:
- Open joints: driven '1' but received '0' (or driven '0' but received '1')
- Short to power/ground: always reads '1' or '0' regardless of driven value
- Net shorts: two nets that should be independent both change together when one is driven
Stuck-At Fault Testing
A stuck-at fault means a signal is permanently stuck at '0' or '1' regardless of what is driven. Boundary scan can detect stuck-at faults on any pin that is directly in the scan chain:
# Pseudocode for stuck-at test
def test_stuck_at(jtag, device_a, device_b, net_a_pin, net_b_pin):
# Test stuck-at-0: drive 1, check if we read 1
jtag.extest_drive(device_a, net_a_pin, value=1)
result_high = jtag.extest_capture(device_b, net_b_pin)
# Test stuck-at-1: drive 0, check if we read 0
jtag.extest_drive(device_a, net_a_pin, value=0)
result_low = jtag.extest_capture(device_b, net_b_pin)
if result_high == 0 and result_low == 0:
return "STUCK_AT_0"
elif result_high == 1 and result_low == 1:
return "STUCK_AT_1"
elif result_high == 1 and result_low == 0:
return "PASS"
else:
return "UNKNOWN_FAULT"Flash and Memory Programming
JTAG is also the primary means of programming embedded flash. The chain access doesn't depend on firmware running — you can program a blank chip, recover a bricked device, or update firmware in the field without a bootloader.
JTAG flash programming works by:
- Halting the CPU via the debug access port
- Uploading a small RAM-resident algorithm (the flash algorithm) through JTAG
- Executing the flash algorithm to write sectors
- Verifying the written data by reading back through JTAG
BSDL Files
The Boundary Scan Description Language (BSDL) is a subset of VHDL that describes a device's JTAG implementation. Every JTAG-compliant device manufacturer provides a BSDL file. It specifies:
- Pin names and their BSR cell positions
- Supported JTAG instructions and their opcodes
- Register lengths
A fragment of a BSDL file:
-- Excerpt from a hypothetical BSDL file
entity MY_FPGA is
generic (PHYSICAL_PIN_MAP : string := "LQFP144");
port (
TDI : in bit;
TDO : out bit;
TMS : in bit;
TCK : in bit;
PA0 : inout bit;
PA1 : inout bit;
-- ... more pins
);
use STD_1149_1_2001.all;
attribute COMPONENT_CONFORMANCE of MY_FPGA : entity is "STD_1149_1_2001";
attribute INSTRUCTION_LENGTH of MY_FPGA : entity is 5;
attribute INSTRUCTION_OPCODE of MY_FPGA : entity is
"BYPASS (11111)," &
"EXTEST (00000)," &
"SAMPLE (00001)," &
"IDCODE (00010)";
attribute IDCODE_REGISTER of MY_FPGA : entity is
"0000" -- version
& "0001000000000010" -- part number
& "00001111111" -- manufacturer (JEDEC)
& "1"; -- required '1' bit
attribute BOUNDARY_LENGTH of MY_FPGA : entity is 6;
attribute BOUNDARY_REGISTER of MY_FPGA : entity is
-- num, cell type, port, function, safe, [control cell, disable value, disable result]
"0 (BC_1, PA0, INPUT, X)," &
"1 (BC_1, *, CONTROL, 1)," &
"2 (BC_1, PA0, OUTPUT3, X, 1, 1, Z)," &
"3 (BC_1, PA1, INPUT, X)," &
"4 (BC_1, *, CONTROL, 1)," &
"5 (BC_1, PA1, OUTPUT3, X, 4, 1, Z)";
end MY_FPGA;Test tools read BSDL files to understand the chain topology and generate correct bit patterns for each test.
SVF Files for Programming and Testing
Serial Vector Format (SVF) is the standard interchange format for JTAG operations. An SVF file contains a sequence of JTAG operations in a human-readable text format:
// SVF file: program_flash.svf
// Set TCK frequency
FREQUENCY 1E6 HZ;
// Reset TAP state machine
TRST ABSENT;
ENDIR IDLE;
ENDDR IDLE;
// Verify IDCODE
HDR 0;
HIR 0;
TDR 0;
TIR 0;
SIR 4 TDI (0E); // Shift in IDCODE instruction (4-bit opcode: 0b1110)
SDR 32 TDI (00000000) TDO (20DA041D) MASK (FFFFFFFF); // Verify device ID
// Select BYPASS for all other devices in chain
HIR 3 TDI (07); // 3 bits, all 1s = BYPASS for upstream devices
TIR 0;
// Load flash programming instruction
SIR 4 TDI (06); // PROG instruction
// Write first 4 bytes to address 0x00000000
SDR 64 TDI (0000000001234567); // addr[31:0] | data[31:0]
// Verify write
SIR 4 TDI (07); // READ instruction
SDR 64 TDI (0000000000000000) TDO (0000000001234567) MASK (00000000FFFFFFFF);
RUNTEST 1000 TCK; // Wait 1000 TCK cycles for flash write to completeSVF files are the standard way to deliver programming instructions from an EDA tool (Vivado, Quartus) to a JTAG adapter without caring about the adapter's specific API.
OpenOCD: Open-Source JTAG Control
OpenOCD (Open On-Chip Debugger) is the most widely used open-source JTAG tool. It supports hundreds of JTAG adapters (FTDI-based cables, J-Link, ST-Link, CMSIS-DAP) and dozens of targets (ARM Cortex-M/A/R, RISC-V, MIPS, AVR).
A typical OpenOCD configuration file for an ARM Cortex-M4 target:
# openocd.cfg
# Interface: FTDI-based adapter (e.g., Olimex ARM-USB-OCD-H)
interface ftdi
ftdi_device_desc "Olimex OpenOCD JTAG ARM-USB-OCD-H"
ftdi_vid_pid 0x15BA 0x002B
ftdi_layout_init 0x0c08 0x0f1b
ftdi_layout_signal nSRST -oe 0x0200
# Transport: SWD (Single Wire Debug, a 2-pin subset of JTAG common on Cortex-M)
transport select swd
# Target: STM32F4
source [find target/stm32f4x.cfg]
# Speed: 4 MHz
adapter speed 4000Run OpenOCD and connect with GDB:
# Terminal 1: start OpenOCD
openocd -f openocd.cfg
# Terminal 2: connect GDB
arm-none-eabi-gdb firmware.elf
(gdb) target extended-remote :3333
(gdb) monitor reset halt
(gdb) load
(gdb) monitor reset runFor automated testing without GDB, use OpenOCD's Tcl RPC interface:
import socket
import time
class OpenOCDClient:
"""Simple Python client for OpenOCD's Tcl RPC server."""
def __init__(self, host="localhost", port=6666):
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.sock.connect((host, port))
def send(self, command):
self.sock.send((command + "\x1a").encode()) # 0x1a = command terminator
response = b""
while True:
chunk = self.sock.recv(4096)
if b"\x1a" in chunk:
response += chunk[:chunk.index(b"\x1a")]
break
response += chunk
return response.decode().strip()
def halt(self):
return self.send("halt")
def resume(self):
return self.send("resume")
def read_memory(self, address, width=32):
result = self.send(f"mdw 0x{address:08X} 1")
# Parse "0x20000000: 12345678 " format
return int(result.split(":")[1].strip(), 16)
def write_memory(self, address, value, width=32):
return self.send(f"mww 0x{address:08X} 0x{value:08X}")
def read_register(self, reg_name):
result = self.send(f"reg {reg_name}")
return int(result.split(":")[1].strip(), 16)
def close(self):
self.sock.close()
# Example: automated memory test via JTAG
def test_sram_via_jtag():
ocd = OpenOCDClient()
ocd.halt()
SRAM_BASE = 0x20000000
SRAM_SIZE = 0x20000 # 128KB
# Walking 1 pattern test
errors = 0
for offset in range(0, SRAM_SIZE, 4):
addr = SRAM_BASE + offset
test_val = 1 << (offset % 32)
ocd.write_memory(addr, test_val)
readback = ocd.read_memory(addr)
if readback != test_val:
print(f"FAIL at 0x{addr:08X}: wrote 0x{test_val:08X}, read 0x{readback:08X}")
errors += 1
print(f"SRAM test complete: {errors} errors")
ocd.resume()
ocd.close()
return errors == 0UrJTAG for Boundary Scan
UrJTAG is an open-source tool focused specifically on boundary scan testing. It reads BSDL files and provides a command-line interface for driving and observing pins:
# Start UrJTAG
jtag
# Connect to JTAG adapter
jtag> cable ft2232 vid=0x0403 pid=0x6010 interface=0
# Detect the JTAG chain
jtag> detect
IR length: 10
Chain length: 2
Device Id: 0100001011011010000001000001101 (0x...) Parts: 1
Part 0: MY_FPGA (via BSDL)
# Load BSDL file
jtag> part 0
jtag> bsdl /path/to/MY_FPGA.bsd
# Sample current state of all pins
jtag> instruction SAMPLE/PRELOAD
jtag> shift ir
jtag> shift dr
jtag> print chain
# Drive pin PA0 high via EXTEST
jtag> instruction EXTEST
jtag> shift ir
jtag> set signal PA0 out 1
jtag> shift dr
# Read pin PA1 state
jtag> get signal PA1For automated boundary scan, UrJTAG can run scripts:
# boundary_scan_test.jtag
cable ft2232 vid=0x0403 pid=0x6010
detect
part 0
bsdl /path/to/DEVICE_A.bsd
part 1
bsdl /path/to/DEVICE_B.bsd
# Test net connecting Device A PA0 to Device B PB3
instruction EXTEST
shift ir
set signal PA0 out 1
shift dr
get signal PB3
# Expected: 1Lauterbach TRACE32
Lauterbach's TRACE32 is the premium commercial JTAG debugger used in automotive, aerospace, and high-reliability embedded development. It supports every ARM core variant, RISC-V, PowerPC, TriCore (automotive), and dozens of other architectures.
TRACE32's scripting language (PRACTICE) enables automated hardware verification:
; TRACE32 PRACTICE script: flash_and_test.cmm
; Connect to target
SYStem.CPU STM32F407VG
SYStem.JTAGclock 4MHz
SYStem.Mode Up
; Halt CPU
Break.direct
; Erase flash
FLASH.ReProgram ALL /Erase
FLASH.Program /TARGET firmware.bin 0x08000000
; Verify
FLASH.AUTO ALL
; Test: read back a known constant from firmware
DATA.LOAD.auto firmware.elf /noclear
Data.LONG 0x08000200 ; read 4 bytes at vector table + 8 (reset handler addr)
; Check register after brief execution
Go
Wait 100ms
Break.direct
; Read CPU register
Register.view
ENTRY &pc &sp
; Verify PC is in expected range (flash region)
IF (&pc<0x08000000)||(&pc>0x08080000)
(
PRINT "FAIL: PC out of flash range: " &pc
ENDDO 1
)
PRINT "PASS: PC=0x" &pc " is in flash"
ENDDO 0JTAG in Embedded Debugging vs Manufacturing Test
JTAG serves two distinct purposes that share the same four pins:
In development and debugging:
- Load firmware into flash without a bootloader
- Set breakpoints, single-step, read registers and memory
- Trace execution (ETM/ITM via SWO pin)
- Profile code (cycle-accurate instruction tracing on Lauterbach ETM)
- Read hardware fault registers (CFSR, HFSR on ARM) after a crash
In manufacturing test:
- Verify PCB interconnects via boundary scan (before any firmware is loaded)
- Program production firmware in-circuit (JTAG flash programming)
- Run built-in self-test (BIST) and read results
- Burn OTP fuses (device configuration, security settings)
- Run final functional test programs
The key difference: during debugging, you care about stopping the CPU and inspecting state. During manufacturing test, you care about testing every net on the board at the electrical level, verifying solder joint integrity on hundreds of BGAs, and doing this in under 10 seconds per board to meet production throughput requirements.
Modern boards often disable JTAG in production firmware for security reasons (JTAG can bypass secure boot). In these cases, JTAG access is locked via an OTP fuse or a vendor-specific debug authentication protocol. Manufacturing test must happen before the lock is applied, or through a separate secure debug authentication mechanism.
Practical JTAG Checklist for Hardware Bring-Up
When a new PCB arrives:
- Verify the JTAG chain is intact — use
openocdorUrJTAGto detect all devices. If any device is missing from the chain, you have a solder defect on that device's TCK/TMS/TDI/TDO or power/ground. - Run boundary scan on critical nets — especially BGA-to-BGA connections, DDR data/address lines, high-speed differential pairs. An open joint on a DDR address line will cause intermittent memory errors that are difficult to debug any other way.
- Program flash before testing firmware — always use JTAG to program the initial firmware. If the board was shipped with test firmware from the factory, erase and reprogram a known-good build.
- Check power supply sequencing — use SAMPLE/PRELOAD to read power-good indicator pins before enabling main rails. Verify the sequence is correct before you risk damaging any device.
- Save SVF files for field updates — generate SVF files for your production firmware during the build process and store them alongside the binary. Field technicians can re-flash any unit without a development environment.
JTAG is one of the most powerful tools in embedded hardware verification. It provides direct access to the silicon, the PCB interconnects, and the CPU's internal state — without any firmware running, without probes touching individual signals, and without removing the chip from the board.