【轉(zhuǎn)】ubuntu linux下openocd + gdb-insight 用Jlink調(diào)試arm程序
http://yutoufishhead.spaces.live.com/blog/cns!4FF22CD714478E54!361.entry
openocd版本為svn 1214,insight版本為6.8 開(kāi)發(fā)環(huán)境為ubuntu-8.04 包都升級(jí)到最新。2008.12.8
板子為自己設(shè)計(jì)的LPC2294的板子,BANK0 為SST39VF1601,BANK1為issi61lv25616al。
首先安裝usb驅(qū)動(dòng)庫(kù):
下載libusb-0.1.12 (地址google上搜)
解壓
./configure
make
make install
openocd 安裝
#./bootstrap
#./configure --enable-jlink (我使用的jtag調(diào)試工具是jlink)
#make
#make install
卸載時(shí)使用make uninstall即可,當(dāng)然別刪了makefile文件
insight安裝
下載 解壓
yu@yu-desktop:~/e-work/insight-6.8$ cd ..
yu@yu-desktop:~/e-work$ mkdir insight-arm
yu@yu-desktop:~/e-work$ cd insight-arm
yu@yu-desktop:~/e-work/insight-arm$
../insight-6.8/configure --target=arm-linux-gnueabi --enable-sim --prefix=/usr/local/insight-arm-6.8 --with-termlib=ncurses
我使用的edlk-4.2編譯的arm程序,工具前綴都是arm-linux-gnueabi, 所以--target=arm-linux-gnueabi,我們安裝到/usr/local/insight-arm-6.8,
因?yàn)槲覀儼惭b的是交叉工具鏈,有時(shí)候需要安裝多個(gè)版本,所以每個(gè)分別安裝的不同目錄,使用時(shí)把相應(yīng)的目錄加入PATH,避免版本之間出錯(cuò)。在工作目錄建立source文件,內(nèi)容為:
///////////////////////////////////////////////////////////////////////
#export CROSS_COMPILE=arm-elf-
export CROSS_COMPILE=arm-linux-
export PATH=/home/yu/e-work/eldk/usr/bin:/usr/local/insight-arm-6.8/bin:${PATH}
#export PATH=/home/yu/e-work/eldk/usr/bin:/usr/local/insight-arm-6.6/bin:${PATH}
#export GUI_LIBRARY=/usr/local/insight-arm-6.8/lib
echo "Altered environment for u-boot Development"
//////////////////////////////////////////////////////////////////////
當(dāng)然要先安裝libncurses5及l(fā)ibncurses5-dev(頭文件 庫(kù)等),在新立德軟件管理器內(nèi)搜即可。
在工作目錄(我的是/home/yu/e-work)建立openocd.cfg,內(nèi)容如下:
////////////////////////////////////////////////////////////////////////////////////////////
#daemon configuration
telnet_port 4444
gdb_port 1000
tcl_port 6666
# GDB can also flash my flash!
#gdb_memory_map enable
gdb_memory_map disable #我的insight不支持
#gdb_flash_program enable
gdb_breakpoint_override soft
#gdb_detach reset
#interface
interface jlink
#jtag_speed 0 #Note that the JTAG speed is given in kHz with 0 meaning to autodetect.
#may be I should use jtag_speed 3000, because the speed is too slow!!!! usb drivers's fault???
#jtag_rclk 3000
jtag_speed 3000
#delays on reset lines
jtag_nsrst_delay 200
jtag_ntrst_delay 200
#use combined on interfaces or targets that can't set TRST/SRST separately
#reset_config trst_and_srst srst_pulls_trst
reset_config trst_and_srst
#hard reset the system to a reliable state
#jtag_reset srst
#sleep 500
# It has atmel lpc2294 chip.
source [find lpc2294.cfg]
# The board has a NOR flash on CS0
#flash configuration
#flash bank <driver> <base> <size> <chip_width> <bus_width> [driver_options ...]
#flash bank cfi 0x80000000 0x00200000 2 2 0 #jedec_probe #haven't surport FOR sst39vf1601
#Enable use of the DBGRQ bit to force entry into debug mode. This should be safe for all but ARM7TDMI–S cores
# (like Philips LPC).
#arm7_9 dbgrq enable
#if set this command in the upper line, openocd willn't recognize this command!
arm7_9 dbgrq disable
proc psm-c30-a_init { } {
# Force target into ARM state
soft_reset_halt
#force cpu go into Supervisor Mode, and disable IRQ and FIQ
#mww cpsr 0xd3 use this command will make cpu issue data abort
arm7_9 write_xpsr 0xd3 0
#Disable PLL
mww 0xe01fc080 0x0
#remap interrupt vector to onchip flash
mww 0xe01fc040 0x00000001
#init the bus
mww 0xe002c014 0x0f810914
#BCFG0
mww 0xffe00000 0x1000feff
#BFG1
mww 0xffe00004 0x1000feff
#probe on chip flash
flash probe 0
}
$_TARGETNAME configure -event gdb-attach psm-c30-a_init #gdb來(lái)連接的時(shí)候執(zhí)行這個(gè)事件!
init
//////////////////////////////////////////////////////////////////////////////////////
openocd的文檔沒(méi)有很仔細(xì)的看,但是感覺(jué)各版本的命令區(qū)別很大。
mww命令如果不再事件函數(shù)中就會(huì)不能識(shí)別此指令。arm7_9 dbgrq disable如果放在source [find lpc2294.cfg]前也會(huì)不能識(shí)別。
所以指令的次序也很重要!可能在搜索到tap之前有些指令還不能執(zhí)行!
gdb_memory_map disable 是因?yàn)槲业膇nsight帶的gdb編譯時(shí)默認(rèn)沒(méi)有打開(kāi)parse XML memory map選項(xiàng),具體怎么打開(kāi),還沒(méi)有看,configure --help應(yīng)該有。arm7_9 dbgrq disable因?yàn)閘pc必須關(guān)閉。使用arm7_9 write_xpsr 0xd3 0,而不使用mww寫(xiě)cpsr是因?yàn)槭褂煤笳邥?huì)報(bào)錯(cuò),提示引起data abort。
reset_config trst_and_srst 我的jtag復(fù)位和系統(tǒng)復(fù)位是分別控制的。
發(fā)現(xiàn)如果使用jtag_rclk 3000,即先使用rclk自己搜索jtag工作頻率,速度會(huì)很慢。另外我的sst39vf1601不是cfi全兼容的,目前openocd還不支持,但是openocd的maillist上有人修改源碼支持,還沒(méi)有進(jìn)一步的分析。lpc2294.cfg在openocd源代碼的src/target/target目錄下有。也要放在當(dāng)前工作目錄,從而使得openocd能找到,我的lpc2294.cfg的內(nèi)容:
if { [info exists CHIPNAME] } {
set _CHIPNAME $CHIPNAME
} else {
set _CHIPNAME lpc2294
}
if { [info exists ENDIAN] } {
set _ENDIAN $ENDIAN
} else {
set _ENDIAN little
}
if { [info exists CPUTAPID ] } {
set _CPUTAPID $CPUTAPID
} else {
# force an error till we get a good number
# set _CPUTAPID 0xffffffff
set _CPUTAPID 0x4f1f0f0f #此處要修改成你的cpu的id
}
#jtag scan chain
jtag newtap $_CHIPNAME cpu -irlen 4 -ircapture 0x1 -irmask 0xf -expected-id $_CPUTAPID
set _TARGETNAME [format "%s.cpu" $_CHIPNAME]
target create $_TARGETNAME arm7tdmi -endian $_ENDIAN -chain-position $_TARGETNAME -variant arm7tdmi-s_r4
$_TARGETNAME configure -work-area-virt 0 -work-area-phys 0x40000000 -work-area-size 0x4000 -work-area-backup 0
#flash configuration
#flash bank lpc2000 <base> <size> 0 0 <target#> <variant>
#flash bank lpc2000 0x0 0x40000 0 0 0 lpc2000_v1 14765 calc_checksum
#主頻要修改成此時(shí)你的處理器的頻率,特別是如果處理器內(nèi)部已經(jīng)燒寫(xiě)了程序時(shí),要設(shè)置成你的那個(gè)程序設(shè)置的頻率。
#而不是gdb attach時(shí)的頻率。
#內(nèi)部flash配置
flash bank lpc2000 0x0 0x40000 0 0 0 lpc2000_v1 48000 calc_checksum
# For more information about the configuration files, take a look at:
# openocd.texi
我的gdb初始化腳本文件:
/////////////////////////////////////////////////////
#GDB 6.8 and higher set any memory area not in the memory map as inaccessible, this can be changed to the old behaviour by #using the following gdb command.
set mem inaccessible-by-default off
#Previous versions of OpenOCD required the following gdb options to increase the packet size and speed up gdb communication.
#This is now handled in the qSupported PacketSize.
#但是現(xiàn)在如果去掉,還是出現(xiàn)(openocd那邊):Warning:acknowledgment received, but no packet pending
#Warning:negative reply, retrying
#Error: GDB missing ack(2) - assumed good
#Warning:negative reply, retrying
#之類(lèi)的錯(cuò)誤,gdb的console窗口也會(huì)出現(xiàn)錯(cuò)誤。
set remote memory-write-packet-size 1024
set remote memory-write-packet-size fixed
set remote memory-read-packet-size 1024
set remote memory-read-packet-size fixed
target remote localhost:1000
monitor sleep 500
monitor poll
monitor soft_reset_halt
#set fuction breakpoints
#break main
#No symbol table is loaded. Use the "file" command.
#how to load symbol table ???
#load /home/yu/e-work/u-boot-2008.10/u-boot
#continue to run the program
#continue
////////////////////////////////////////////////////
然后在openocd.cfg所在的目錄執(zhí)行openocd即可啟動(dòng)gdbserver。
然后在工作目錄執(zhí)行source source 建立path,然后執(zhí)行arm-linux-gnueabi-insight -x insight.gdb /home/yu/e-work/u-boot-2008.10/u-boot
即可啟動(dòng)insight,再dowload即可調(diào)試了??梢栽趇nsight的cosole窗口通過(guò)monitor step等執(zhí)行openocd的命令,monitor help看看都可以執(zhí)行那些openocd的指令,help看看可以執(zhí)行那些gdb的指令。
現(xiàn)在有一個(gè)問(wèn)題是,我編譯的insight的tcp端口輸入框,watch窗口輸入框,無(wú)法輸入,懷疑是編譯器或tcl庫(kù)的bug。
安裝預(yù)編譯的gnuarm-3.4,其自帶的insight-6.1情況依舊,故應(yīng)該是庫(kù)的緣故!
也可以使用ddd來(lái)調(diào)試!
ddd只是各種gdb的一個(gè)x-window前端, ddd --debugger arm-linux-gdb -x insight.gdb /home/yu/e-work/u-boot-2008.10/u-boot可啟動(dòng)arm的gdb,所以不用交叉編譯。
使用新立德安裝即可??!
聯(lián)系客服