首先我们来看看怎么用手动方式调试:
将光盘附带的friendly-arm/leds复制到工作目录/home/derekhe/workspace/leds,然后再命令行中输入make编译程序,得到leds_elf文件和leds.bin文件。连接好OpenJTAG和开发板,打开电源,然后插上OpenJTAG。在终端中运行
view sourceprint?1.derekhe@ubuntu:~/workspace$ openocd -f ~/workspace/openocd.cfg注意将-f 后面修改为你openocd.cfg所在真实路径。如果此文件在当前目录下(如本例),可以直接运行openocd。
我的openocd.cfg如下:
view sourceprint?01.telnet_port 444402.gdb_port 333303.interface ft223204.jtag_speed 005.ft2232_vid_pid 0x1457 0x511806.ft2232_layout "jtagkey_prototype_v1"07.reset_config trst_and_srst08.jtag_device 4 0x1 0xf 0xe09.daemon_startup attach10.target arm920t little reset_run 0 arm920t11.arm7_9 fast_memory_access enable12.working_area 0 0x200000 0x4000 backup13.#flash bank cfi 0 0x100000 2 2 014.#debug_level 315.nand device s3c2440 016.run_and_halt_time 0 500017.ft2232_device_desc "USB<=>JTAG&RS232"此时会显示:
view sourceprint?1.Info: options.c:50 configuration_output_handler(): jtag_speed: 0, 02.Info: options.c:50 configuration_output_handler(): Open On-Chip Debugger 1.0 (2008-10-04-09:26) svn:7173.Info: options.c:50 configuration_output_handler(): fast memory access is enabled4.Info: jtag.c:1389 jtag_examine_chain(): JTAG device found: 0x0032409d (Manufacturer: 0x04e, Part: 0x0324, Version: 0x0)说明jtag已经找到了,可以开始调试了。 下一步开启另外一个终端,开始运行telnet程序,链接OpenJTAG服务器
view sourceprint?1.derekhe@ubuntu:~/workspace$ telnet localhost 4444终端输出:
view sourceprint?1.derekhe@ubuntu:~$ telnet localhost 44442.Trying ::1...3.Trying 127.0.0.1...4.Connected to localhost.5.Escape character is '^]'.6.Open On-Chip Debugger7.>由于上电以后NAND的程序会自动运行,所以必须先使用halt命令暂停:
view sourceprint?1.> halt2.target state: halted3.target halted in ARM state due to debug request, current mode: Supervisor4.cpsr: 0x60000013 pc: 0x300011505.MMU: enabled, D-Cache: enabled, I-Cache: enabled6.>此时可以看到,MMU和Cache处于enable状态。在下载程序之前要清除这两个状态才行。运行arm920t cp15 2 0和step指令,可以将MMU和Cache清除:
view sourceprint?1.> arm920t cp15 2 02.2: 000000003.> step4.target state: halted5.target halted in ARM state due to single step, current mode: Supervisor6.cpsr: 0x60000013 pc: 0x300011547.MMU: disabled, D-Cache: disabled, I-Cache: disabled8.>然后载入image(似乎只有用绝对路径才行):
view sourceprint?1.> load_image /home/derekhe/workspace/leds/leds_elf2.172 byte written at address 0x000000003.downloaded 172 byte in 0.007424s4.>然后开始运行:
view sourceprint?1.> resume 0x0程序就开始运行,可见开发板上灯不停闪烁。
好,了解整个过程后,我们再来看看OpenJTAG怎么和GDB一起使用:
OpenOCD的GDB服务端在3333端口,可以在openocd.cfg里面配置。
重启开发板。在OpenOCD服务端运行的情况下,打开另外一个终端。在shell中输入:
view sourceprint?1.derekhe@ubuntu:~$ arm-linux-gdb我使用的arm-linux-gdb是友善提供的交叉编译器里面的,版本比较新:
view sourceprint?01.GNU gdb (Sourcery G++ Lite 2008q3-72) 6.8.50.20080821-cvs02.Copyright (C) 2008 Free Software Foundation, Inc.03.License GPLv3+: GNU GPL version 3 or later04.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
view sourceprint?1.(gdb) target remote localhost:33332.Remote debugging using localhost:33333.warning: while parsing target memory map (at line 2): Required element is missing4.0x00000000 in ?? ()5.(gdb)此时已经连接上远程调试服务器。我们来看看目前的状态,使用monitor poll来运行OpenOCD状态显示命令。
view sourceprint?1.(gdb) monitor poll2.target state: halted3.target halted in ARM state due to debug request, current mode: Supervisor4.cpsr: 0x60000013 pc: 0x300011505.MMU: enabled, D-Cache: enabled, I-Cache: enabled6.(gdb)此时可以看出MMU和Cache已经开启。下载程序前先停止程序并关闭MMU和Cache:
view sourceprint?01.(gdb) monitor halt02.(gdb) monitor arm920t cp15 2 003.2: 0000000004.(gdb) monitor step05.(gdb) monitor poll06.target state: halted07.target halted in ARM state due to single step, current mode: Supervisor08.cpsr: 0x60000013 pc: 0x3000115409.MMU: disabled, D-Cache: disabled, I-Cache: disabled此时MMU和Cache已经关闭。下面我们载入文件leds_elf文件:
view sourceprint?1.(gdb) file ~/workspace/leds/leds_elf2.A program is being debugged already.3.Are you sure you want to change the file? (y or n) y4.Reading symbols from /home/derekhe/workspace/leds/leds_elf...done.5.(gdb)打开软件中断:
view sourceprint?1.(gdb) monitor arm7_9 sw_bkpts enable2.software breakpoints enabled3.(gdb)将文件载入内存:
view sourceprint?1.(gdb) load2.Loading section .text, size 0xac lma 0x03.Start address 0x0, load size 1724.Transfer rate: 20 KB/sec, 172 bytes/write.重新从0x0开始运行:
view sourceprint?1.(gdb) monitor resume 0x0此时会看到灯在闪烁了。
剩下的功能就和eclipse的基本使用一致了,这里不再阐述。
另外我发现一些问题,restart按钮不能用,提示:
Exception(s) occurred attempting to restart.
Target request failed: The "remote" target does not support "run". Try "help target" or "continue".
The "remote" target does not support "run". Try "help target" or "continue".
还不知道怎么配置eclipse使用另外的命令。
作者:april1985
原文链接:http://www.april1985.com/2009/08 ... pse-3-5gdbmini2440/
《-= April 1985 =-》版权所有,转载时必须以链接形式注明作者和原始出处及本声明。