Ubuntu 16.04下EasyOpenJTAG+OpenOCD的安装和使用【转】

本文转载自:http://www.linuxdiyf.com/linux/24086.html

Ubuntu 16.04下EasyOpenJTAG+OpenOCD的安装和使用

发布时间:2016-09-12 09:09:31来源:linux网站作者:heyuqian_csdn
操作系统:VMware fusion + Ubuntu 16.04.1 LTS
开发板:JZ2440 V3 + EasyOpenJTAG
 
设备连接:
Ubuntu 16.04下EasyOpenJTAG+OpenOCD的安装和使用
 
要烧写裸机程序离不开OpenJTAG,OpenJTAG包含了3大功能,USB 转串口、USB 转 JTAG、 在线调试。
借助OpenOCD等开源软件可以完成程序的下载、烧写、调试等任务:
首先安装libftdi和ftdi-eeprom 下载地址http://www.intra2net.com/en/developer/libftdi/download.php:
 
1、下载confuse-2.5.tar.gz  libftdi1-1.3.tar.bz2并解压:
root@ubuntu:/work/tmp# ls /mnt/hgfs/jz2440/download/  
confuse-2.5.tar.gz  libftdi1-1.3.tar.bz2 
root@ubuntu:/work/tmp# tar -jxvf /mnt/hgfs/jz2440/download/libftdi1-1.3.tar.bz2 -C ./  
root@ubuntu:/work/tmp# tar -zxvf /mnt/hgfs/jz2440/download/confuse-2.5.tar.gz -C ./  
 
2、安装libftdi,参考源码目录下的README.build:
root@ubuntu:/work/tmp/libftdi1-1.3# mkdir build; cd build:  
root@ubuntu:/work/tmp/libftdi1-1.3# cmake  -DCMAKE_INSTALL_PREFIX="/usr" ../; make; sudo make install  
 
3、安装ftdi-eeprom,参考源码目录下的INSTALL
root@ubuntu:/work/tmp# cd confuse-2.5/; ./configure; make; make install
 
然后安装OpenOCD
1]、下载OpenOCD
root@ubuntu:/work/tmp# git clone git://openocd.git.sourceforge.net/gitroot/openocd/openocd 
 
2]、编译并安装, 请参考源码目录下的README.build
root@ubuntu:/work/tmp/openocd# ./bootstrap  
root@ubuntu:/work/tmp/openocd# ./configure --enable-ftdi  
root@ubuntu:/work/tmp/openocd# make; make install  
编译后的版本为:
root@ubuntu:/work/tmp/openocd# openocd -v  
Open On-Chip Debugger 0.10.0-dev-00371-g81631e4 (2016-09-11-18:21)  
Licensed under GNU GPL v2  
For bug reports, read  
http://openocd.org/doc/doxygen/bugs.html  
 
3]、增加udev规则,以便使用普通用户权限操作调试器。以root权限创建/etc/udev/rules.d/45-openjtag.rules(文件名可以换成别的):
SYSFS{idProduct}=="5118", SYSFS{idVendor}=="1457", MODE="666", GROUP="plugdev"
 
4]、添加OpenOCD配置文件openocd.cfg:
interface ftdi  
#通过描述来指定设备,应当和dmesg中的Product一致  
#ftdi_device_desc "USB<=>JTAG&RS232"  
#通过PID VID指定调试器,比描述更准确些  
ftdi_vid_pid 0x1457 0x5118  
#如果有多个同样的调试器,还可以指定要使用的调试器序列号  
#ftdi_serial  
#引脚定义,相当于旧版中的 ft2232_layout jtagkey  
ftdi_layout_init 0x0c08 0x0f1b  
ftdi_layout_signal nTRST -data 0x0100 -noe 0x0400  
ftdi_layout_signal nSRST -data 0x0200 -noe 0x0800 
# Target configuration for the Samsung 2440 system on chip  
# Tested on a S3C2440 Evaluation board by keesj  
# Processor   : ARM920Tid(wb) rev 0 (v4l)  
# Info:   JTAG tap: s3c2440.cpu tap/device found: 0x0032409d (Manufacturer: 0x04e, Part: 0x0324, Version: 0x0)
if { [info exists CHIPNAME] } {  
set  _CHIPNAME $CHIPNAME  
} else {  
set  _CHIPNAME s3c2440  
}
if { [info exists ENDIAN] } {  
set  _ENDIAN $ENDIAN  
} else {  
# this defaults to a bigendian  
set  _ENDIAN little  
}
if { [info exists CPUTAPID ] } {  
set _CPUTAPID $CPUTAPID  
} else {  
# force an error till we get a good number  
set _CPUTAPID 0x0032409d  
#jtag scan chain  
jtag newtap $_CHIPNAME cpu -irlen 4 -ircapture 0x1 -irmask 0x0f -expected-id $_CPUTAPID
#  
#jtag_rclk 3000  
adapter_khz 1234
#set _TARGETNAME $_CHIPNAME.cpu  
#target create $_TARGETNAME arm920t -endian $_ENDIAN -chain-position $_TARGETNAME -variant arm920t  
#$_TARGETNAME configure -work-area-phys 0x200000 -work-area-size 0x4000 -work-area-backup 0  
#arm7_9 fast_memory_access enable 
set _TARGETNAME $_CHIPNAME.cpu  
target create $_TARGETNAME arm920t -chain-position $_TARGETNAME  
$_TARGETNAME configure -work-area-phys 0x00200000  
-work-area-size 0x4000 -work-area-backup 0 
#reset configuration  
reset_config trst_and_srst
#Flash CFG<openocd.pdf P[74~]  
#flash bank name driver base size chip_width bus_width target [driver_options]  
#usage: flash bank <name> <driver> <base> <size> <chip_width> <bus_width> <target>  
#flash bank bank_id driver_name base_address size_bytes chip_width_bytes bus_width_bytes target [driver_options ...]  
flash bank 0 cfi 0x0 0x200000 2 2 $_TARGETNAME
#NAND CFG <openocd.pdf P[88~92]>  
#nand device name driver target [ configparams... ]  
nand device 0 s3c2440 $_TARGETNAME 
root@ubuntu:~# telnet localhost 4444  
Trying 127.0.0.1...  
Connected to localhost.  
Escape character is '^]'.  
Open On-Chip Debugger  
> halt  
> nand probe 0  
NAND flash device 'NAND 256MiB 3.3V 8-bit (Samsung)' found  
> load_image leds.bin  
136 bytes written at address 0x00000000  
downloaded 136 bytes in 0.015671s (8.475 KiB/s)  
> resume 0x0
最后启动OpenOCD:首先将EasyOpenJTAG USB连接至PC,然后开发板上电,最后在和配置文件openocd.cfg相同目录执行openocd
root@ubuntu:~# openocd   
Open On-Chip Debugger 0.10.0-dev-00371-g81631e4 (2016-09-11-22:15)  
Licensed under GNU GPL v2  
For bug reports, read  
http://openocd.org/doc/doxygen/bugs.html  
Info : auto-selecting first available session transport "jtag". To override use 'transport select <transport>'.  
adapter speed: 1234 kHz  
trst_and_srst separate srst_gates_jtag trst_push_pull srst_open_drain connect_deassert_srst  
Info : clock speed 1234 kHz  
Info : JTAG tap: s3c2440.cpu tap/device found: 0x0032409d (mfg: 0x04e (Samsung), part: 0x0324, ver: 0x0)  
Info : Embedded ICE version 2  
Info : s3c2440.cpu: hardware has 2 breakpoint/watchpoint units
可以看到设备已经识别成功。
 
原文地址:https://www.cnblogs.com/zzb-Dream-90Time/p/9588983.html