Debugging With JTAG
Debugging With JTAG
Agenda
What is JTAG? How does it work? JTAG use cases JTAG tools overview Working examples using Eclipse + CDT Hardware Debug Plugin Questions and Answers
JTAG commands
Standard required commands:
BYPASS EXTTEST SAMPLE 111...1 "all ones" command, 000 ..0 "all zeros" command 000...1 "one in last bit" command the TAP command register is filled with ones connects "boundary scan" register between TDI and TDO connects 1-bit "bypass" register between TDI and TDO TAP behaves as transparent 1-bit shift register
Daisy Chain
Several chips on your Print Circuit Board (PCB) can be connected TDO of previous to TDI of the next creating a daisy chain".
JTAG enables us to choose which chips in the daisy chain to deal with.
Flashprogramming
Flash programming algorithm controls our chip output pin-s state using JTAG EXTTEST mode Pins logic state is set to 0,1 or high impedance state according to signal diagrams in FLASH chip datasheet
Flashprogramming(codesnippetfrom OpenOCD)
static void pxa250_bus_write( bus_t *bus, uint32_t adr, uint32_t data ) { part_t *p = PART; chain_t *chain = CHAIN; if (adr >= 0x04000000) return; part_set_signal( p, nCS[0], 1, 0 ); part_set_signal( p, DQM[0], 1, 0 ); part_set_signal( p, DQM[1], 1, 0 ); part_set_signal( p, DQM[2], 1, 0 );
Flashprogramming(codesnippetfrom OpenOCD)
part_set_signal( p, DQM[3], 1, 0 ); part_set_signal( p, RDnWR, 1, 0 ); part_set_signal( p, nWE, 1, 1 ); part_set_signal( p, nOE, 1, 1 ); part_set_signal( p, nSDCAS, 1, 0 ); setup_address( bus, adr ); setup_data( bus, adr, data ); chain_shift_data_registers( chain, 0 ); part_set_signal( p, nWE, 1, 0 ); chain_shift_data_registers( chain, 0 ); part_set_signal( p, nWE, 1, 1 ); chain_shift_data_registers( chain, 0 ); }
Step-by-stepdebugging
Usually an internal capability of commercial JTAG devices OpenOCD (http://openhardware.net/Embedded_ARM/OpenOCD_JTAG/) is an implementation of JTAG algorithms
Codesnippet
public class ARMICE { // Instruction register size public static final int IR_SIZE = 4; // Instruction register values public static final String EXTEST = "0000", // External test SCAN_N = "0010", // Select scan chain SAMPLE_PRELOAD = "0011", RESTART = "0100", // Restart core CLAMP = "0101", // Clamp pins HIGHZ = "0111", // HiZ pins CLAMPZ = "1001", // Clamp, HiZ pins INTEST = "1100", // Internal test IDCODE = "1110", // Read ID code BYPASS = "1111"; // Bypass core
Codesnippet(continued)
// Scan chains public static final String SCAN0 = "0000", // Macrocell scan test SCAN1 = "0001", // Debug SCAN2 = "0010", // EmbeddedICE-RT registers SCAN3 = "0011"; // External boundary-scan /** JTAG controller */ JTAGController controller; /** Constructor - we provide an implementation-independent controller */ public ARMICE(JTAGController c) { controller = c; }
Codesnippet(continued)
/* Some helper functions */ String shift(byte ir, String dr) { controller.jump(ir); return controller.tdi(dr); } String shiftIR(String b) { return shift(SHIFT_IR, b); } String shiftDR(String b) { return shift(SHIFT_DR, b); } void selectScan(String s) { shiftIR(SCAN_N); shiftDR(s); shiftIR(INTEST); controller.jump(RUN_TEST_IDLE); }
Company Logo Here
Codesnippet(continued)
String idcode() { controller.jump(SHIFT_IR); controller.tdi(IDCODE); controller.jump(SHIFT_DR); return controller.tdi(new Bits(0, 32)).toString(); } public static void main(String[] args) throws Exception { ARMICE ai = new ARMICE(new JTAGWiggler(0x378)); // reset the controller, set idle signal values ai.controller.initialize(); // soft-reset the TAP, just in case ai.controller.reset(); String c = ai.idcode(), ch = Integer.toHexString((int)Long.parseLong(c, 2)); System.out.println("IDCODE: " + c + ", " + ch); System.out.println( "Controller is in state: " + description[ai.controller.state]); }
Company Logo Here
Chip-specific usages
Today, as custom logic in hardware using FPGA and ASIC becomes more commonly used, the JTAG increases its importance as a tool for debugging interaction of programmable code with custom hardware. Final application developers want to see JTAG TAP controllers not only in processor part of the project but also in their custom logic. Xilinx provides primitives making it possible to embed TAP controller registers to custom logic and link them to daisy chain.
Commercial equipment
There are a lot of offerings with varying functionality and price.
Conclusions
JTAG is very simple at the hardware level as it is controlled by "trivial FSM" JTAGs real expertise lies with upper-level algorithms hidden inside commercial and open source tools, which provide JTAG tools the ability to control FLASHes, processor machine instruction stepping, memory controller registers, and other facilities needed for the board initial startup (tunning SDRAM timings, GPIO multiplexing, initial console UART, etc.)
OpenOCDproject
The Open On-Chip Debugger (openocd) aims to provide debugging, in-system programming, and boundary-scan testing for embedded target devices. Openocd currently supports Wiggler (clones), FTDI FT2232-based JTAG interfaces, the Amontec JTAG Accelerator, and the Gateworks GW1602. It allows ARM7 (ARM7TDMI and ARM720t), ARM9 (ARM920t, ARM922t, ARM926ej-s, ARM966e-s), XScale (PXA25x, IXP42x) and Cortex-M3 (Luminary Stellaris LM3 and ST STM32) based cores to be debugged. Flash writing is supported for external CFI compatible flashes (Intel and AMD/Spansion command set) and several internal flashes (LPC2000, AT91SAM7, STR7x, STR9x, LM3 and STM32x). Preliminary support for using the LPC3180's NAND flash controller is included.
OpenOCDproject(continued)
The OpenOCD runs as a daemon, waiting for connections from clients (Telnet or GDB). It reads its configuration by default from the file openocd.cfg located in the current working directory. This may be overwritten with the '-f <configfile>' command-line switch.
There is no single opensource or commercial solution for all JTAG use cases or any JTAG device. Vendors of cables/devices usually provide some software tools and GUI with their product for an additional price. Some such as Abatron (BDIx000 devices vendor) provide terminal UI and support for GDB compatible tools communication, so that a number of opensource tools such as Eclipse, OpenOCD, DDD may be used with such devices. User may also buy or assemble low-cost LPT JTAG cables, but these have low performance. For the purpose of software debugging with JTAG, opensource provides multiple solutions usable with numerous commercial JTAG cables/devices.
Questions?
Acknowledgements
We would like to thank Dina Kommar (MontaVista) for testing Olimex Arm-USB-OCD with openOCD and Eclipse CDT Hardware Debugging plug-in Laurette Wharton (MontaVista) for language and style of this presentation