一直想在ubuntu下调试arm.今天终于搞好了.
1.准备
1.1硬件
1.1.1 tiny6410.友善之臂的板子.
1.1.2 OpenJtag的下载器.
1.2 软件
1.2.1 openocd 0.5.0
1.2.2 crosstool
2.步骤
2.1 openocd
sudo openocd 应该是可以不用sudo的,要看看udev里的rules的文件是怎么写的./etc/udev/rules.d/50-ftdi.rules
[问题]
http://www.pdp8.net/other/freertos_linux/install.shtml
If you run as a non-root user you will likely get the following error:
Error: 3 1203871166 ft2232.c:1473 ft2232_init_libftdi(): unable to open ftdi device: unable to fetch product description
This is because the USB devices aren't normally accessible to non-root users. This can be changed but how is likely to be distribution specific.
For libftd2xx which uses the older /proc/bus/usb devices I changed the device permissions by putting 45-ft2232-libftd2xx.rules in /etc/udev/rules.d and setmode in /etc/udev then chmod +x /etc/udev/setmode.
For libftdi which uses /dev/bus/usb I changed the device permissions by putting 45-ft2232-libftdi.rules in /etc/udev/rules.d
then unplugging and plugging back in the board. You should then be able to run openocd as a user. If it doesn't work you can look in /proc/bus/usb/devices for "Stellaris Evaluation Board" or use lsusb and look for "Future Technology Devices International, Ltd." Verify that the vendor and prodid match the values in 45-ft2232.rules. The udev rule should change the /dev/bus/usb/###/### file to crw-rw-rw- The ### is system dependent and can be determined by lsusb or the devices file.
openocd.cfg
# 2011-02-15 19:59:30
# John Dong
# zhydong258@gmail.com
# openocd.cfg
# used for openJTAG simulator
# target: samsung6410
# board: FriendlyARM 6410 (RAM 128M, Flash 256M)
#
#-------------------------------------------------------------------------
# interface Setup
#-------------------------------------------------------------------------
interface ft2232
ft2232_device_desc "USB<=>JTAG&RS232"
ft2232_layout jtagkey
ft2232_vid_pid 0x1457 0x5118
#-------------------------------------------------------------------------
# Deamon Setup
#-------------------------------------------------------------------------
telnet_port 4444
tcl_port 6666
# GDB Setup
gdb_port 3333
gdb_breakpoint_override hard
#gdb_memory_map enable
#gdb_flash_program enable
# -*- tcl -*-
# Target configuration for the Samsung s3c6410 system on chip
# Tested on a SMDK6410
# Processor : ARM1176
# Info: JTAG device found: 0x0032409d (Manufacturer: 0x04e, Part: 0x0324, Version: 0x0)
# [Duane Ellis 27/nov/2008: Above 0x0032409d appears to be copy/paste from other places]
# [and I do not believe it to be accurate, hence the 0xffffffff below]
if { [info exists CHIPNAME] } {
set _CHIPNAME $CHIPNAME
} else {
set _CHIPNAME s3c6410
}
if { [info exists ENDIAN] } {
set _ENDIAN $ENDIAN
} else {
# this defaults to a bigendian
set _ENDIAN little
}
if { [info exists BSTAPID ] } {
set _BSTAPID $BSTAPID
} else {
# force an error till we get a good number
set _BSTAPID 0x2b900f0f
}
if { [info exists CPUTAPID ] } {
set _CPUTAPID $CPUTAPID
} else {
# force an error till we get a good number
set _CPUTAPID 0x07b76f0f
}
#jtag scan chain
# I think the "unknown" is the boundry scan tap
jtag newtap $_CHIPNAME etb -irlen 4 -expected-id $_BSTAPID
jtag newtap $_CHIPNAME cpu -irlen 5 -ircapture 0x1 -irmask 0x1f -expected-id $_CPUTAPID
set _TARGETNAME $_CHIPNAME.cpu
target create $_TARGETNAME arm11 -endian $_ENDIAN -chain-position $_TARGETNAME -variant arm1176
adapter_khz 6000
jtag_nsrst_delay 500
jtag_ntrst_delay 500
#reset configuration
reset_config trst_and_srst
# trace setup ... NOTE, "normal full" mode fudges the real ETMv3.1 mode
etm config $_TARGETNAME 16 normal full etb
etb config $_TARGETNAME $_CHIPNAME.etb
proc init_6410 {} {
halt
reg cpsr 0x1D3
arm mcr 15 0 15 2 4 0x70000013
#-----------------------------------------------
# Clock and Timer Setting
#-----------------------------------------------
mww 0x7e004000 0 ;# WATCHDOG - Disable
mww 0x7E00F120 0x0003 ;# MEM_SYS_CFG - CS0:8 bit, Mem1:32bit, CS2=NAND
#mww 0x7E00F120 0x1000 ;# MEM_SYS_CFG - CS0:16bit, Mem1:32bit, CS2=SROMC
#mww 0x7E00F120 0x1002 ;# MEM_SYS_CFG - CS0:16bit, Mem1:32bit, CS2=OND
mww 0x7E00F900 0x805e ;# OTHERS - Change SYNCMUX[6] to “1”
sleep 1000
mww 0x7E00F900 0x80de ;# OTHERS - Assert SYNCREQ&VICSYNCEN to “1”(rb1004modify)
sleep 1000 ;# - Others[11:8] to 0xF
mww 0x7E00F000 0xffff ;# APLL_LOCK - APLL LockTime
mww 0x7E00F004 0xffff ;# MPLL_LOCK - MPLL LockTime
mww 0x7E00F020 0x1047310 ;# CLK_DIV0 - ARMCLK:HCLK:PCLK = 1:4:16
mww 0x7E00F00c 0x81900302 ;# APLL_CON - A:400, P:3, S:2 => 400MHz
mww 0x7E00F010 0x81900303 ;# MPLL_CON - M:400, P:3, S:3 => 200MHz
mww 0x7E00F01c 0x3 ;# CLK_SRC - APLL,MPLL Clock Select
#-----------------------------------------------
# DRAM initialization
#-----------------------------------------------
mww 0x7e001004 0x4 ;# P1MEMCCMD - Enter the config state
mww 0x7e001010 0x30C ;# P1REFRESH - Refresh Period register (7800ns), 100MHz
# mww 0x7e001010 0x40e ;# P1REFRESH - Refresh Period register (7800ns), 133MHz
mww 0x7e001014 0x6 ;# P1CASLAT - CAS Latency = 3
mww 0x7e001018 0x1 ;# P1T_DQSS
mww 0x7e00101c 0x2 ;# P1T_MRD
mww 0x7e001020 0x7 ;# P1T_RAS - 45 ns
mww 0x7e001024 0xA ;# P1T_RC - 67.5 ns
mww 0x7e001028 0xC ;# P1T_RCD - 22.5 ns
mww 0x7e00102C 0x10B ;# P1T_RFC - 80 ns
mww 0x7e001030 0xC ;# P1T_RP - 22.5 ns
mww 0x7e001034 0x3 ;# P1T_RRD - 15 ns
mww 0x7e001038 0x3 ;# P1T_WR - 15 ns
mww 0x7e00103C 0x2 ;# P1T_WTR
mww 0x7e001040 0x2 ;# P1T_XP
mww 0x7e001044 0x11 ;# P1T_XSR - 120 ns
mww 0x7e001048 0x11 ;# P1T_ESR
#-----------------------------------------------
# Memory Configuration Registers
#-----------------------------------------------
mww 0x7e00100C 0x00010012 ;# P1MEMCFG - 1 CKE, 1Chip, 4burst, Alw, AP[10],ROW/Column bit
mww 0x7e00104C 0x0B41 ;# P1MEMCFG2 - Read delay 1 Cycle, mDDR, 32bit, Sync.
mww 0x7e001200 0x150F0 ;# CHIP_N_CFG - 0x150F0 for 256M, 0x150F8 for 128M
#-----------------------------------------------
# Memory Direct Commands
#-----------------------------------------------
mww 0x7e001008 0xc0000 ;# Chip0 Direct Command :NOP5
mww 0x7e001008 0x0 ;# Chip0 Direct Command :PreCharge al
mww 0x7e001008 0x40000 ;# Chip0 Direct Command :AutoRefresh
mww 0x7e001008 0x40000 ;# Chip0 Direct Command :AutoRefresh
mww 0x7e001008 0xA0000 ;# EMRS, DS:Full, PASR:Full
mww 0x7e001008 0x80032 ;# MRS, CAS3, BL4
mww 0x7e001004 0x0 ;# Enable DMC1
}
proc install_6410_uboot {} {
# write U-boot magic number
mww 0x50000000 0x24564236
mww 0x50000004 0x20764316
load_image /home/john/Work/u-boot.bin 0x50008000 bin
load_image /home/john/Work/u-boot.bin 0x57E00000 bin
#Kick in
reg pc 0x57E00000
resume
}
proc init_6410_flash {} {
halt
nand probe 0
nand list
}
nand device $_CHIPNAME.flash s3c6400 $_CHIPNAME.cpu
init
echo " "
echo " "
echo "-------------------------------------------------------------------"
echo "---- The following mini6410/tiny6410 functions are available: ----"
echo "---- init_6410 - initialize clock, timer, DRAM ----"
echo "---- init_6410_flash - initializes NAND flash support ----"
echo "---- install_6410_uboot - copies u-boot image into RAM and ----"
echo "---- runs it ----"
echo "-------------------------------------------------------------------"
echo " "
echo " "
2.2 gdb
在crosstool中应该有了arm-unknown-linux-gnueabi-gdb,其实就是一个针对arm的gdb.
2.3 crosstool
从crosstool-ng那里找到方法,自己编译一个crosstool chain.
3. 开始
3.1
sudo openocd
打开openocd,确保连上目标板.
3.2
telnet localhost 4444
telnet连上openocd.
3.3
arm-unknown-linux-gnueabi-gdb xxx.elf
[问题]
gdb老是无法连上,先要在telnet中reset目标板.然后用target remote localhost:3333多来几次.然后在telnet中用init_6410的命令.再在gdb中用load,多load几次
直到成功.
[2011.1.12]更新
关于GDB和OpenOCD的连接问题.在OpenOCD的manual(20章)中提到了.
OpenOCD can communicate with GDB in two ways:
A socket (TCP/IP) connection is typically started as follows:
target remote localhost:3333
This would cause GDB to connect to the gdbserver on the local pc using port 3333.
A pipe connection is typically started as follows:
target remote | openocd -c "gdb_port pipe; log_output openocd.log"
With the remote protocol, GDB sessions start a little differently than they do when you're debugging locally. Here's an examples showing how to start a debug session with a small ARM program. In this case the program was linked to be loaded into SRAM on a Cortex-M3. Most programs would be written into flash (address 0) and run from there.
$ arm-none-eabi-gdb example.elf
(gdb) target remote localhost:3333
Remote debugging using localhost:3333
...
(gdb) monitor reset halt
...
(gdb) load
Loading section .vectors, size 0x100 lma 0x20000000
Loading section .text, size 0x5a0 lma 0x20000100
Loading section .data, size 0x18 lma 0x200006a0
Start address 0x2000061c, load size 1720
Transfer rate: 22 KB/sec, 573 bytes/write.
(gdb) continue
Continuing.
...
不过在load之前,要先用init_6410的命令来初始化6410.