Practical JTAG: : From 0 to 1
HyperChem Tencent’s Xuanwu Lab http://xlab.tencent.com @XuanwuLab
Practical JTAG: : From 0 to 1 HyperChem Tencents Xuanwu Lab - - PowerPoint PPT Presentation
Practical JTAG: : From 0 to 1 HyperChem Tencents Xuanwu Lab http://xlab.tencent.com @XuanwuLab >#whoami Security Researcher@ Used to doing Chemistry; Interested in: Console Hacking; Embedded Device Security;
HyperChem Tencent’s Xuanwu Lab http://xlab.tencent.com @XuanwuLab
Game Hacking Unbrick Embedded Development
Integrated Circuit peripherals Digital Output Pin 1 1 1 0 0 0 0 0 0 1 1 1 0 0 0 1 1 1 0 0 0 1 1 1 0 0 0 1 1 1
TDO TDI
Boundary Scan Chain Shift data in 1bit/clk Shift data out 1bit/clk
Connect to the head and tail of Scan Chain
TAP Controller
Selection Circultry Selection Circultry 0 1 0 1 . . . . . . . . . . 1 0 Boundary Scan Chain 0 1 0 1 . . . . . . . . . 1 0 IDCode Register 0 1 0 1 . . . . . . . 1 0 Instruction Register Bypass Register TCK TMS TDI TDO Test Access Port
Run-Test/IDLE Test Logic Reset
Select-DR-SCAN
Shift-DR Capture-DR Exit1-DR Exit2-DR Pause-DR Update-DR Select-IR-SCAN Shift-IR Capture-IR Exit1-IR Exit2-IR Pause-IR Update-IR 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Change TMS signal by TCK
diagnosis, and fault isolation;
Len:33bits, include: 32bits data bus, 1bit BREAKPT signal;
Fetch Decode Execute
CPU DO We DO Read Instruction From Memory To Data Bus Change Instruction to Memory writing on Data Bus Decode Instruction to determine what to do Wait… Execute Instruction: set registers, calculation, memory access Value of registers appears on Data Bus Change registers, wait for accessing, read result.
Jtag_SelectScanN(1); Jtag_ShiftIR(ARMJTAG_INTEST,UpdateIR); //INTEST means no outer access. Jtag_ChangeData(0xe8900003,FALSE); //LDMIA r0, {r0, r1} Jtag_ChangeData(ARM_INSTR_NOP,FALSE); //NOP Jtag_ChangeData(ARM_INSTR_NOP,FALSE); //NOP Jtag_ChangeData(address,FALSE); //set r0=address Jtag_ChangeData(data,FALSE); // set r1=data Jtag_ChangeData(ARM_INSTR_NOP,FALSE); //NOP Jtag_ChangeData(ARM_INSTR_NOP,FALSE); //NOP // set brkpt to enable outer access for once Jtag_ChangeData(ARM_INSTR_NOP,TRUE); Jtag_ChangeData(0xe4801000,FALSE,FALSE);//STR r1, [r0] // do mem write
about ISA;
Are you ready for JTAG debugging?
Where are the PINs of JTAG
Target board
Do I need CPU info for JTAG?
JTAG PINs
JTAG reset;
Ver. Design Center Core Number Chip Derivative Manufacturer ID Fixed 31.. 28 27..22 21..17 16..12 11..1 0 0010 010101 00100 00010 00010111111 1
Jtagulator does this too
Create Cfg File For JTAG debugging
Who help me translate Binary to signal?
JTAG PINs CPU Info
Much Cheaper ~5$ Canada
Define an adapter?
JTAG PINs CPU Info Adapter
ftdi;
communicate with adapter;
adapter Pins;
interface ftdi ftdi_device_desc "Dual RS232-HS" ftdi_vid_pid 0x0403 0x6014 ftdi_layout_init {levelbits} {direction bits} ftdi_layout_signal nTRST -data 0x0100 -noe 0x0400 ftdi_layout_signal nSRST -data 0x0200 -noe 0x0800
level
Pin Name Direction Level TCK
low TDI
low TDO input low TMS
low GPIOL0
high GPIOL1 input low GPIOL2 input low GPIOL2 input low
LevelBits: 0x0010
Direction Bits: 0x001b
Who knows My adapter?
JTAG PINs CPU Info Adapter Adapter cfg
Anything left?
JTAG PINs CPU Info Adapter Adapter cfg Software
Seems Done!?
JTAG PINs CPU Info Adapter Adapter cfg Software Reset
Software
Pack JTAG sequence to readable cmds
Reset
Some tricky pins What for? Actions PC CPU
JTAG PINs
Get Pins for connection I know how to connect
CPU Info
Know CPU Core to inject code I know your ISA
Adapter
Signal Conversion You Know my language
Adapter cfg
Let Software recognize Adapter Power on my translator Talk in English Reset Connection Hello World!
OpenOCD;