将OpenJTAG插入后,会多出来一个USB设备,在/dev/ttyUSB0。说明连接正常。
我的开发板拨到NAND档的,里面有一个2440test程序,会在一开机就启动,会设置MMU、Cache等。这点对于后来的JTAG调试造成了一些麻烦,要比说明书多一些步骤才能正确运行调试。
首先我们来看看怎么用手动方式调试:
将光盘附带的friendly-arm/leds复制到工作目录/home/derekhe/workspace/leds,然后再命令行中输入 make编译程序,得到leds_elf文件和leds.bin文件。连接好OpenJTAG和开发板,打开电源,然后插上OpenJTAG。在终端中运行
1
derekhe@ubuntu:~/workspace$ openocd -f ~/workspace/openocd.cfg
注意将-f 后面修改为你openocd.cfg所在真实路径。如果此文件在当前目录下(如本例),可以直接运行openocd。
我的openocd.cfg如下:
01
telnet_port 4444
02
gdb_port 3333
03
interface ft2232
04
jtag_speed 0
05
ft2232_vid_pid 0x1457 0x5118
06
ft2232_layout "jtagkey_prototype_v1"
07
reset_config trst_and_srst
08
jtag_device 4 0x1 0xf 0xe
09
daemon_startup attach
10
target arm920t little reset_run 0 arm920t
11
arm7_9 fast_memory_access enable
12
working_area 0 0x200000 0x4000 backup
13
#flash bank cfi 0 0x100000 2 2 0
14
#debug_level 3
15
nand device s3c2440 0
16
run_and_halt_time 0 5000
17
ft2232_device_desc "USB<=>JTAG&RS232"
此时会显示:
1
Info: options.c:50 configuration_output_handler(): jtag_speed: 0, 0
2
Info: options.c:50 configuration_output_handler(): Open On-Chip Debugger 1.0 (2008-10-04-09:26) svn:717
3
Info: options.c:50 configuration_output_handler(): fast memory access is enabled
4
Info: jtag.c:1389 jtag_examine_chain(): JTAG device found: 0x0032409d (Manufacturer: 0x04e, Part: 0x0324, Version: 0x0)
说明jtag已经找到了,可以开始调试了。 下一步开启另外一个终端,开始运行telnet程序,链接OpenJTAG服务器
1
derekhe@ubuntu:~/workspace$ telnet localhost 4444
终端输出:
1
derekhe@ubuntu:~$ telnet localhost 4444
2
Trying ::1...
3
Trying 127.0.0.1...
4
Connected to localhost.
5
Escape character is '^]'.
6
Open On-Chip Debugger
7
>
由于上电以后NAND的程序会自动运行,所以必须先使用halt命令暂停:
1
> halt
2
target state: halted
3
target halted in ARM state due to debug request, current mode: Supervisor
4
cpsr: 0x60000013 pc: 0x30001150
5
MMU: enabled, D-Cache: enabled, I-Cache: enabled
6
>
此时可以看到,MMU和Cache处于enable状态。在下载程序之前要清除这两个状态才行。运行arm920t cp15 2 0和step指令,可以将MMU和Cache清除:
1
> arm920t cp15 2 0
2
2: 00000000
3
> step
4
target state: halted
5
target halted in ARM state due to single step, current mode: Supervisor
6
cpsr: 0x60000013 pc: 0x30001154
7
MMU: disabled, D-Cache: disabled, I-Cache: disabled
8
>
然后载入image(似乎只有用绝对路径才行):
1
> load_image /home/derekhe/workspace/leds/leds_elf
2
172 byte written at address 0x00000000
3
downloaded 172 byte in 0.007424s
4
>
然后开始运行:
1
> resume 0x0
程序就开始运行,可见开发板上灯不停闪烁。
好,了解整个过程后,我们再来看看OpenJTAG怎么和GDB一起使用:
OpenOCD的GDB服务端在3333端口,可以在openocd.cfg里面配置。
重启开发板。在OpenOCD服务端运行的情况下,打开另外一个终端。在shell中输入:
1
derekhe@ubuntu:~$ arm-linux-gdb
我使用的arm-linux-gdb是友善提供的交叉编译器里面的,版本比较新:
01
GNU gdb (Sourcery G++ Lite 2008q3-72) 6.8.50.20080821-cvs
02
Copyright (C) 2008 Free Software Foundation, Inc.
03
License GPLv3+: GNU GPL version 3 or later
04
This is free software: you are free to change and redistribute it.
05
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
06
and "show warranty" for details.
07
This GDB was configured as "--host=i686-pc-linux-gnu --target=arm-none-linux-gnueabi".
08
For bug reporting instructions, please see:
09
.
10
(gdb)
首先链接OpenOCD,输入:target remote localhost:3333
1
(gdb) target remote localhost:3333
2
Remote debugging using localhost:3333
3
warning: while parsing target memory map (at line 2): Required element is missing
4
0x00000000 in ?? ()
5
(gdb)
此时已经连接上远程调试服务器。我们来看看目前的状态,使用monitor poll来运行OpenOCD状态显示命令。
1
(gdb) monitor poll
2
target state: halted
3
target halted in ARM state due to debug request, current mode: Supervisor
4
cpsr: 0x60000013 pc: 0x30001150
5
MMU: enabled, D-Cache: enabled, I-Cache: enabled
6
(gdb)
此时可以看出MMU和Cache已经开启。下载程序前先停止程序并关闭MMU和Cache:
1
(gdb) monitor halt
2
(gdb) monitor arm920t cp15 2 0
3
2: 00000000
4
(gdb) monitor step
5
(gdb) monitor poll
6
target state: halted
7
target halted in ARM state due to single step, current mode: Supervisor
8
cpsr: 0x60000013 pc: 0x30001154
9
MMU: disabled, D-Cache: disabled, I-Cache: disabled
此时MMU和Cache已经关闭。下面我们载入文件leds_elf文件:
1
(gdb) file ~/workspace/leds/leds_elf
2
A program is being debugged already.
3
Are you sure you want to change the file? (y or n) y
4
Reading symbols from /home/derekhe/workspace/leds/leds_elf...done.
5
(gdb)
打开软件中断:
1
(gdb) monitor arm7_9 sw_bkpts enable
2
software breakpoints enabled
3
(gdb)
将文件载入内存:
1
(gdb) load
2
Loading section .text, size 0xac lma 0x0
3
Start address 0x0, load size 172
4
Transfer rate: 20 KB/sec, 172 bytes/write.
重新从0x0开始运行:
1
(gdb) monitor resume 0x0
此时会看到灯在闪烁了。