openocdの始めの一歩

ビルドできたのでAR531xなターゲットで試してみます。

![OPENOCD-FIRST.png](https://qiita-image-store.s3.amazonaws.com/0/104066/cd4ef163-f4eb-4fb0-cdb9-2d5782512c3d.png)

FT232Hの設定ファイル

```:ft232h.cfg
interface ftdi
ftdi_vid_pid 0x0403 0x6014
ftdi_device_desc "Single RS232-HS"

ftdi_layout_init 0x0c08 0x0f1b
ftdi_layout_signal nTRST -data 0x0100 -noe 0x0400
ftdi_layout_signal nSRST -data 0x0200 -noe 0x0800

adapter_khz 15000
```

とりあえずar71xx.cfgで実行してみる。

```
bash-3.2$ ./openocd -f ft232h.cfg -f ../tcl/target/ar71xx.cfg 
Open On-Chip Debugger 0.10.0
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
adapter speed: 15000 kHz
adapter_nsrst_delay: 100
Info : auto-selecting first available session transport "jtag". To override use 
'transport select <transport>'.
jtag_ntrst_delay: 100
trst_and_srst separate srst_gates_jtag trst_push_pull srst_open_drain connect_de
assert_srst
131072
Info : ftdi: if you experience problems at higher adapter clocks, try the comman
d "ftdi_tdo_sample_edge falling"
Info : clock speed 15000 kHz
Info : JTAG tap: ar71xx.cpu tap/device found: 0x00000001 (mfg: 0x000 (<invalid>)
, part: 0x0000, ver: 0x0)
```

他の端末でtelnetを実行してcpuを止めてレジスタを確認して再開する。

```
bash-3.2$ telnet localhost 4444
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Open On-Chip Debugger
> halt
target halted in MIPS32 mode due to debug-request, pc: 0x80281010
> reg
===== mips32 registers
(0) r0 (/32): 0x00000000
(1) r1 (/32): 0x80360000
(2) r2 (/32): 0x00000000
(3) r3 (/32): 0x00000020
(4) r4 (/32): 0x8043EB40
(5) r5 (/32): 0x803F9C90
(6) r6 (/32): 0x00000000
(7) r7 (/32): 0x00000000
(8) r8 (/32): 0x00009400
(9) r9 (/32): 0x00009401
(10) r10 (/32): 0x8041DE48
(11) r11 (/32): 0x00000000
(12) r12 (/32): 0x00000000
(13) r13 (/32): 0x00004000
(14) r14 (/32): 0x00000000
(15) r15 (/32): 0x00000000
(16) r16 (/32): 0x00000003
(17) r17 (/32): 0x8043EB40
(18) r18 (/32): 0xC1F6FE98
(19) r19 (/32): 0x00000000
(20) r20 (/32): 0x8013276C
(21) r21 (/32): 0x00000000
(22) r22 (/32): 0x00000000
(23) r23 (/32): 0x00000000
(24) r24 (/32): 0xA417CF06
(25) r25 (/32): 0x802A27E8
(26) r26 (/32): 0x00009403
(27) r27 (/32): 0x80281000
(28) r28 (/32): 0x00000000
(29) r29 (/32): 0xC1F6FE08
(30) r30 (/32): 0x00000000
(31) r31 (/32): 0x802853B8
(32) status (/32): 0x00009401
(33) lo (/32): 0x00000000
(34) hi (/32): 0x00000000
(35) badvaddr (/32): 0x405FE8F0
(36) cause (/32): 0x50008000
(37) pc (/32): 0x80281010
(38) f0 (/32): 0x00000000
(39) f1 (/32): 0x00000000
(40) f2 (/32): 0x00000000
(41) f3 (/32): 0x00000000
(42) f4 (/32): 0x00000000
(43) f5 (/32): 0x00000000
(44) f6 (/32): 0x00000000
(45) f7 (/32): 0x00000000
(46) f8 (/32): 0x00000000
(47) f9 (/32): 0x00000000
(48) f10 (/32): 0x00000000
(49) f11 (/32): 0x00000000
(50) f12 (/32): 0x00000000
(51) f13 (/32): 0x00000000
(52) f14 (/32): 0x00000000
(53) f15 (/32): 0x00000000
(54) f16 (/32): 0x00000000
(55) f17 (/32): 0x00000000
(56) f18 (/32): 0x00000000
(57) f19 (/32): 0x00000000
(58) f20 (/32): 0x00000000
(59) f21 (/32): 0x00000000
(60) f22 (/32): 0x00000000
(61) f23 (/32): 0x00000000
(62) f24 (/32): 0x00000000
(63) f25 (/32): 0x00000000
(64) f26 (/32): 0x00000000
(65) f27 (/32): 0x00000000
(66) f28 (/32): 0x00000000
(67) f29 (/32): 0x00000000
(68) f30 (/32): 0x00000000
(69) f31 (/32): 0x00000000
(70) fcsr (/32): 0x00000000
(71) fir (/32): 0x00000000
> resume
```

このターゲットではFreeBSDが動いていて、haltするとLEDの点滅が停止して、ちゃんと止まっている事が確認できます。

RT1310(armv5te)ではこんな感じです。

```
$ telnet localhost 4444
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Open On-Chip Debugger
> halt
target halted in ARM state due to debug-request, current mode: Abort
cpsr: 0x600000d7 pc: 0x00001c2c
MMU: enabled, D-Cache: enabled, I-Cache: enabled
> regs
invalid command name "regs"
> reg
===== ARM registers
(0) r0 (/32): 0x4073FFB8 (dirty)
(1) r1 (/32): 0x00000000
(2) r2 (/32): 0x40790738
(3) r3 (/32): 0x40790738
(4) r4 (/32): 0x00800040
(5) r5 (/32): 0x40790738
(6) r6 (/32): 0x407A37C0
(7) r7 (/32): 0x00000002
(8) r8 (/32): 0x4073FFDC
(9) r9 (/32): 0x00000000
(10) r10 (/32): 0x4073EDB0
(11) r11 (/32): 0x407A37C0
(12) r12 (/32): 0xFFFFFFFF
(13) sp_usr (/32)
(14) lr_usr (/32)
(15) pc (/32): 0x00001C2C (dirty)
(16) r8_fiq (/32)
(17) r9_fiq (/32)
(18) r10_fiq (/32)
(19) r11_fiq (/32)
(20) r12_fiq (/32)
(21) sp_fiq (/32)
(22) lr_fiq (/32)
(23) sp_irq (/32)
(24) lr_irq (/32)
(25) sp_svc (/32)
(26) lr_svc (/32)
(27) sp_abt (/32): 0xF92613DC
(28) lr_abt (/32): 0x0000400C
(29) sp_und (/32)
(30) lr_und (/32)
(31) cpsr (/32): 0x600000D7
(32) spsr_fiq (/32)
(33) spsr_irq (/32)
(34) spsr_svc (/32)
(35) spsr_abt (/32): 0x600000D7
(36) spsr_und (/32)
(37) sp (/32)
(38) lr (/32)
===== EmbeddedICE registers
(39) debug_ctrl (/6): 0x05
(40) debug_status (/10)
(41) comms_ctrl (/6)
(42) comms_data (/32)
(43) watch_0_addr_value (/32)
(44) watch_0_addr_mask (/32)
(45) watch_0_data_value (/32)
(46) watch_0_data_mask (/32)
(47) watch_0_control_value (/9)
(48) watch_0_control_mask (/8)
(49) watch_1_addr_value (/32)
(50) watch_1_addr_mask (/32)
(51) watch_1_data_value (/32)
(52) watch_1_data_mask (/32)
(53) watch_1_control_value (/9)
(54) watch_1_control_mask (/8)
(55) vector_catch (/8)
```