在Ubutu14.04下,如何用OpenJTAG+OPENOCD烧写程序

时间:2022-11-12 19:46:23

OPENOCD INSTALL

[注]:请直接转到第二次安装详解。

[gif教程]翻到最后 20150419

第一次使用openocd。问题连篇! (JZ2440开发板,命令用蓝色粉刷)

一:安装openocd:


cd /path/you/install/openocd

(1) 通过 git 获取openocd


git clone git://openocd.git.sourceforge.net/gitroot/openocd/openocd

遇到问题:

Cloning into 'openocd'...
fatal: unable to connect to openocd.git.sourceforge.net:
openocd.git.sourceforge.net: No address associated with hostname

(2)源码编译安装


sudo apt-get install autoconf

./bootstrap

...

error: required directory ./jimtcl does not exist(安装失败,并且丢失了jimtcl)

./configure

configure: error: jimtcl not found, run git submodule init and git submodule update.丢失了jimtcl

sudo git submodule init

sudo git submodule update

Cloning into 'jimtcl'...
remote: Counting objects: 6287, done.
remote: Compressing objects: 100% (1595/1595), done.
Receiving objects:   2% (126/6287), 28.00 KiB | 3.00 KiB/s

下载完成后:

sudo ./bootstrap

xnus@xnus-P43E:/opt/openocd$ sudo ./bootstrap
[sudo] password for xnus:
+ aclocal
+ libtoolize --automake --copy
+ autoconf
+ autoheader
+ automake --gnu --add-missing --copy
Makefile.am:23: warning: wildcard $(srcdir: non-POSIX variable name
Makefile.am:23: (probably a GNU make extension)
Setting up submodules
Bootstrap complete. Quick build instructions:
./configure ....

(3) 驱动安装


sudo apt-get install libftdi-dev libftdi1 libtool git-core asciidoc

./configure --help

./configure  --enable-maintainer-mode --enable-usb_blaster_libftdi  --enable-openjtag_ftdi

(不行的话多试几次!)

make

make install

输出版本信息

openocd -v

Open On-Chip Debugger 0.9.0-dev-00251-g1fa4c72 (2015-01-30-19:44)

Licensed under GNU GPL v2
For bug reports, read
http://openocd.sourceforge.net/doc/doxygen/bugs.html

二:配置openocd.cfg

 参考百问网的配置修改

 
#
# 100ASK OpenJTAG
#
# http://www.100ask.net
#
# modified by xnus 2015
#
interface ft2232
ft2232_device_desc "USB<=>JTAG&RS232"
ft2232_layout jtagkey
ft2232_vid_pid 0x1457 0x5118

# 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 1
arm7_9 fast_memory_access enable

#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




大家可以到这个网站下载 
openocd.pdf以便参考。 

三:启动OpenOCD

将开发板连接的OpenJTAG的USB端口接入PC,终端输入openocd

xnus@xnus-P43E:~$openocd

Open On-Chip Debugger 0.8.0 (2015-01-30-21:54)Licensed under GNU GPL v2For bug reports, read    http://openocd.sourceforge.net/doc/doxygen/bugs.htmlInfo : only one transport option; autoselect 'jtag'adapter speed: 1234 kHzfast memory access is enabledtrst_and_srst separate srst_gates_jtag trst_push_pull srst_open_drain connect_deassert_srstWarn : Using DEPRECATED interface driver 'ft2232'Info : Consider using the 'ftdi' interface driver, with configuration files in interface/ftdi/...Info : clock speed 1200 kHzInfo : JTAG tap: s3c2440.cpu tap/device found: 0x0032409d (mfg: 0x04e, part: 0x0324, ver: 0x0)Info : Embedded ICE version 2Info : s3c2440.cpu: hardware has 2 breakpoint/watchpoint units

四:启动telnet

xnus@xnus-P43E:~$ telnet localhost 4444

Trying 127.0.0.1...Connected to localhost.Escape character is '^]'.Open On-Chip Debugger

>halt

target state: haltedtarget halted in ARM state due to debug-request, current mode: Supervisorcpsr: 0x900000d3 pc: 0x004f1c8cMMU: disabled, D-Cache: disabled, I-Cache: disabled

>nand probe 0

NAND flash device 'NAND 256MiB 3.3V 8-bit (Samsung)' found

>load_image /home/xnus/Downloads/leds.bin 0x0136 bytes written at address 0x00000000downloaded 136 bytes in 0.275141s (0.483 KiB/s)

> resume 0x0

可以看到灯开始闪烁了(注意,应设置为NAND启动)

========================分割线================================================华丽的=================================================

第二次使用openocd。问题亦是连篇!! (mini2440开发板,命令用绿色粉刷)

我在/home/xnus下新建了一个目录:InStall

cd InStall

git clone git://openocd.git.sourceforge.net/gitroot/openocd/openocd (注意:这个命令我至少尝试了5次!!不是链接超时就是检测不到目标地址!)

Cloning into 'openocd'...fatal: unable to connect to openocd.git.sourceforge.net:openocd.git.sourceforge.net[0: 218.85.65.150]: errno=Connection timed out

终于有一次链接上:

xnus@xnus-P43E:~/InStall$ git clone git://openocd.git.sourceforge.net/gitroot/openocd/openocd

Cloning into 'openocd'...remote: Counting objects: 50419, done.remote: Compressing objects: 100% (15403/15403), done.

下载速度及其的慢。苦逼等待中........下载完成

./bootstrap

+ aclocal+ libtoolize --automake --copy+ autoconf+ autoheader+ automake --gnu --add-missing --copyconfigure.ac:26: installing './compile'configure.ac:37: installing './config.guess'configure.ac:37: installing './config.sub'configure.ac:16: installing './install-sh'configure.ac:16: installing './missing'Makefile.am:23: warning: wildcard $(srcdir: non-POSIX variable nameMakefile.am:23: (probably a GNU make extension)Makefile.am: installing './INSTALL'doc/Makefile.am:1: installing 'doc/mdate-sh'doc/Makefile.am:1: installing 'doc/texinfo.tex'src/Makefile.am: installing './depcomp'Setting up submodulesSubmodule 'jimtcl' (http://repo.or.cz/r/jimtcl.git) registered for path 'jimtcl'Submodule 'tools/git2cl' (http://repo.or.cz/r/git2cl.git) registered for path 'tools/git2cl'Cloning into 'jimtcl'...fatal: unable to access 'http://repo.or.cz/r/jimtcl.git/': Could not resolve host: repo.or.czClone of 'http://repo.or.cz/r/jimtcl.git' into submodule path 'jimtcl' failed

./configure

...

...

configure: error: jimtcl not found, run git submodule init and git submodule update.

xnus@xnus-P43E:~/InStall/openocd$ git submodule init

xnus@xnus-P43E:~/InStall/openocd$git submodule update

Cloning into 'jimtcl'...remote: Counting objects: 6287, done.remote: Compressing objects: 100% (1595/1595), done.remote: Total 6287 (delta 4607), reused 6287 (delta 4607)Receiving objects: 100% (6287/6287), 6.51 MiB | 1024 bytes/s, done.Resolving deltas: 100% (4607/4607), done.Checking connectivity... done.Submodule path 'jimtcl': checked out '51f65c6d38fbf86e1f0b036ad336761fd2ab7fa0'Cloning into 'tools/git2cl'...fatal: unable to access 'http://repo.or.cz/r/git2cl.git/': Failed to connect to 127.0.0.1 port 80: Connection refusedClone of 'http://repo.or.cz/r/git2cl.git' into submodule path 'tools/git2cl' failedxnus@xnus-P43E:~/InStall/openocd$ git submodule updateCloning into 'tools/git2cl'...remote: Counting objects: 64, done.remote: Compressing objects: 100% (34/34), done.remote: Total 64 (delta 30), reused 64 (delta 30)Unpacking objects: 100% (64/64), done.Checking connectivity... done.Submodule path 'tools/git2cl': checked out '8373c9f74993e218a08819cbcdbab3f3564bbeba'

xnus@xnus-P43E:~/InStall/openocd$ ./bootstrap

+ aclocal+ libtoolize --automake --copy+ autoconf+ autoheader+ automake --gnu --add-missing --copyMakefile.am:23: warning: wildcard $(srcdir: non-POSIX variable nameMakefile.am:23: (probably a GNU make extension)Setting up submodulesBootstrap complete. Quick build instructions:./configure ....

./configure --enable-maintainer-mode --enable-legacy-ft2232_libftdi

make

sudo make install

xnus@xnus-P43E:~/InStall/openocd$ sudo openocd

Open On-Chip Debugger 0.9.0-dev-00358-gd3c2679 (2015-04-12-19:34)Licensed under GNU GPL v2For bug reports, readhttp://openocd.sourceforge.net/doc/doxygen/bugs.htmlInfo : only one transport option; autoselect 'jtag'adapter speed: 1234 kHzembedded:startup.tcl:20: Error: Unknown param: -variant, try one of: -type, -event, -work-area-virt, -work-area-phys, -work-area-size, -work-area-backup, -endian, -coreid, -chain-position, -dbgbase, or -rtosin procedure 'script' at file "embedded:startup.tcl", line 58in procedure 'target' called at file "openocd.cfg", line 46in procedure 'ocd_bouncer' at file "embedded:startup.tcl", line 20Warn : Using DEPRECATED interface driver 'ft2232'Info : Consider using the 'ftdi' interface driver, with configuration files in interface/ftdi/...Info : clock speed 1200 kHzInfo : JTAG tap: s3c2440.cpu tap/device found: 0x0032409d (mfg: 0x04e, part: 0x0324, ver: 0x0)Warn : gdb services need one or more targets defined

我的理解是没有检测到CPU,对openocd.cfg做部分修改:

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
保存,重新运行openocd->

sudo openocd

xnus@xnus-P43E:~/InStall/openocd$ sudo openocd
Open On-Chip Debugger 0.9.0-dev-00358-gd3c2679 (2015-04-12-19:34)
Licensed under GNU GPL v2
For bug reports, read
    http://openocd.sourceforge.net/doc/doxygen/bugs.html
Info : only one transport option; autoselect 'jtag'
adapter speed: 1234 kHz
trst_and_srst separate srst_gates_jtag trst_push_pull srst_open_drain connect_deassert_srst
Warn : Using DEPRECATED interface driver 'ft2232'
Info : Consider using the 'ftdi' interface driver, with configuration files in interface/ftdi/...
Info : clock speed 1200 kHz
Info : JTAG tap: s3c2440.cpu tap/device found: 0x0032409d (mfg: 0x04e, part: 0x0324, ver: 0x0)
Info : Embedded ICE version 2
Info : s3c2440.cpu: hardware has 2 breakpoint/watchpoint units

打开另一个终端:

telnet localhost 4444
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Open On-Chip Debugger
> halt
target state: halted
target halted in ARM state due to debug-request, current mode: System
cpsr: 0x6000005f pc: 0x33f09178
MMU: enabled, D-Cache: enabled, I-Cache: enabled
> nand probe 0
NAND flash device 'NAND 256MiB 3.3V 8-bit (Samsung)' found
> load_image /home/xnus/Documents/MINI2440/images/2440test/2440test_X35.bin 0x0
614972 bytes written at address 0x00000000
downloaded 614972 bytes in 25.278437s (23.758 KiB/s)
> resume 0x0
> led闪烁了~

总算成功了!在Ubutu14.04下,如何用OpenJTAG+OPENOCD烧写程序

总结了一下,关键的几个地方就是,configure的时候要把该config的都选上,如我们的(./configure --enable-maintainer-mode --enable-legacy-ft2232_libftdi)。还有就是

openocd.cfg文件的配置。以下贴出mini2440的配置文件->

#
# 100ASK OpenJTAG
#
# http://www.100ask.net
#
# modified by xnus 2015
#
interface ft2232
ft2232_device_desc "USB<=>JTAG&RS232"
ft2232_layout jtagkey
ft2232_vid_pid 0x1457 0x5118

# 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

我是参考上面的配置文件还有openocd.pdf写的。


续:

可以将openocd.cfg复制到/usr/local/openocd/script/ 目录下,这样就能在用户根目录或者其他目录下执行sudo openocd了。

下面我们将u-boot下载到?里面。(以下是Nor启动,将init,bin下载到0x40000000。如果是nand启动,则下载到0x0)

sudo openocd启动openocd

telent localhost 4444

halt

load_image /home/xnus/Bare/init.bin 0x40000000

resume 0x40000000

可以看到灯在闪,初始化存储控制器成功。

接下来我们先将minicom启动起来,设置好之后接着执行下面步骤

halt

load_image /home/xnus/Bare/u-boot 0x33f80000

resume 0x33f80000

可以在minicom中看到u-boot的消息了。

在Ubutu14.04下,如何用OpenJTAG+OPENOCD烧写程序



[gif教程]:

在Ubutu14.04下,如何用OpenJTAG+OPENOCD烧写程序

GOODLUCK