ubuntu下配置openocd+FT2232

本文原地址  http://www.cnblogs.com/jacob1934/p/4075184.html
請勿轉載
【1】確認調試器方案
將調試器插到電腦上,lsusb看一下:html

Bus 003 Device 009: ID 1457:5118 First International Computer, Inc. OpenMoko Neo1973 Debug board (V2+)

dmesg看一下:git

[ 1223.230752] usb 3-12: new full-speed USB device number 7 using xhci_hcd [ 1223.364173] usb 3-12: New USB device found, idVendor=1457, idProduct=5118 [ 1223.364181] usb 3-12: New USB device strings: Mfr=1, Product=2, SerialNumber=0 [ 1223.364185] usb 3-12: Product: USB<=>JTAG&RS232 [ 1223.364188] usb 3-12: Manufacturer: www.100ask.net [ 1223.366931] usb 3-12: Ignoring serial port reserved for JTAG [ 1223.369248] ftdi_sio 3-12:1.1: FTDI USB Serial Device converter detected [ 1223.369341] usb 3-12: Detected FT2232C [ 1223.369349] usb 3-12: Number of endpoints 2 [ 1223.369356] usb 3-12: Endpoint 1 MaxPacketSize 64 [ 1223.369362] usb 3-12: Endpoint 2 MaxPacketSize 64 [ 1223.369369] usb 3-12: Setting MaxPacketSize 64 [ 1223.369636] usb 3-12: FTDI USB Serial Device converter now attached to ttyUSB0

OK,確認爲FT2232C方案(其實是FT2232D,二者相似),後面要根據這個配置OPENOCD。bootstrap

【2】增長udev規則,以便使用普通用戶權限操做咱們的調試器。ubuntu

插上openocd,dmesg看一下:session

以root權限建立/etc/udev/rules.d/45-openjtag.rules(文件名能夠換成別的),內容以下:測試

SYSFS{idProduct}=="5118", SYSFS{idVendor}=="1457", MODE="666", GROUP="plugdev"

添加規則文件後,從新插拔調試器生效。spa

【3】確認JTAG線序,並鏈接設備與調試器。如下是100ask.com的OPENJTAG線序。可能須要使用轉接板或杜邦線鏈接設備和調試器,EB-SAM9G45須要使用自帶的20pin-10pin轉接板。.net

信號名
方向
說 明
Vref
cpu->jtag
接口電平參考電壓。20pin中爲1腳。ft2232不支持接口電平檢測,實際中用3.3V接口電壓的較多
Vsupply
cpu->jtag
電源。20pin中爲2腳
nTRST
jtag->cpu
(可選項) TAP reset,低電平有效,用來複位目標板上的tap控制器,能夠經過tms完成。在目標端應加適當的上拉電阻以防止誤觸發。
TDI
jtag->cpu
測試數據輸入
TMS
jtag->cpu
測試模式選擇
TCK
jtag->cpu
測試時鐘
RTCK
cpu->jtag
(可選項)反饋測試時鐘。由目標端反饋給jtag板的時鐘信號,實現TCK的自適應。不使用時能夠直接接地。
TDO
cpu->jtag
測試數據輸出
nSRST
Input/Output
(可選項) system reset,與目標板上的系統復位信號相連。能夠直接對目標系統復位,同時能夠檢測目標系統的復位狀況。爲了防止誤觸發,應在目標端加上適當的上拉電阻。

JTAG引腳說明debug

【4】安裝openocd。調試

【4.1】ubuntu 14.10的版本庫中,openocd的當前版本是0.8。ubuntu 14.04中是0.7。

apt-get install openocd

【4.2】下載源碼包安裝

sourceforge頁面:http://sourceforge.net/projects/openocd/
openocd-0.10.0正式版已經於2017.1.22發佈
我下載的文件爲openocd-0.8.0.tar.bz2,解壓出來的文件爲:

openocd-0.8.0:
aclocal.m4    config.sub        Doxyfile.in  missing     NEWTAPS
AUTHORS       config_subdir.m4  HACKING      NEWS        README
BUGS          configure         INSTALL      NEWS-0.2.0  README.OSX
ChangeLog     configure.ac      install-sh   NEWS-0.3.0  README.Windows
common.mk     contrib           jimtcl       NEWS-0.4.0  src
compile       COPYING           ltmain.sh    NEWS-0.5.0  tcl
config.guess  depcomp           Makefile.am  NEWS-0.6.0  TODO
config.h.in   doc               Makefile.in  NEWS-0.7.0  tools

安裝依賴庫:

apt-get install libusb-1.0-0-dev libftdi-dev

編譯安裝,這裏安裝到了/opt/openocd

./configure --enable-ftdi --prefix=/opt/openocd
make
sudo mkdir /opt/openocd
sudo chmod a+w opt/openocd
make install

【4.3】經過git獲取最新開發版:

git clone git://git.code.sf.net/p/openocd/code openocd-code

獲得的文件爲:

openocd-code:
AUTHORS            configure.ac  jimtcl       NEWS-0.6.0      src
AUTHORS.ChangeLog  contrib       Makefile.am  NEWS-0.7.0      tcl
bootstrap          COPYING       NEWS         NEWS-0.8.0      testing
BUGS               doc           NEWS-0.2.0   NEWTAPS         TODO
ChangeLog          Doxyfile.in   NEWS-0.3.0   README          tools
common.mk          guess-rev.sh  NEWS-0.4.0   README.OSX      uncrustify.cfg
config_subdir.m4   HACKING       NEWS-0.5.0   README.Windows

下載子模塊,編譯安裝:

./bootstrap
./configure --enable-ftdi --prefix=/opt/openocd
make
sudo mkdir /opt/openocd
sudo chmod a+w opt/openocd
make install

【5】配置openocd
【5.1】接口部分,我這裏的配置文件路徑爲 ~/.openocd/openjtag.cfg,內容以下:

#openocd 0.8中默認使用新的ftdi接口,若是但願使用舊的ft2232接口,須要在編譯openocd時指定。 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

此時能夠嘗試運行一下openocd,以檢查鏈接和配置狀況:

1.關閉設備電源,
2.連接設備、調試器、PC
3.打開設備電源(由於沒有指定處理器,只能先打開設備以進行自動探測)
4.運行openocd:

openocd -f ~/.openocd/openjtag.cfg -c jtag_rclk 3000

該命令中,  -f 指定配置文件,能夠如 -f a.cfg -f b.cfg指定多個配置文件;
       -c 執行一條命令,這裏是處理器不支持RCLK時,調試器使用的時鐘。
openocd的打印以下:

Open On-Chip Debugger 0.8.0 (2014-05-10-23:20)
Licensed under GNU GPL v2
For bug reports, read
    http://openocd.sourceforge.net/doc/doxygen/bugs.html
Info : only one transport option; autoselect 'jtag'
RCLK - adaptive
RCLK - adaptive
Info : RCLK (adaptive clock speed) not supported - fallback to 3000 kHz
Warn : There are no enabled taps.  AUTO PROBING MIGHT NOT WORK!!
Warn : AUTO auto0.tap - use "jtag newtap auto0 tap -expected-id 0x0792603f ..."
Warn : AUTO auto0.tap - use "... -irlen 4"
Warn : gdb services need one or more targets defined

這裏自動探測出一個TAP(Test Access Ports,設備上的JTAG核心,一個芯片中可能有多個TAP)出來,expected-id與預計(若是openocd支持該處理器,能夠翻閱配置文件,不然請翻看datasheet等)的相同,這證實JTAG接口是鏈接和配置正確的。
若是是相似這樣的打印,請檢查JTAG線序、openocd配置的接口定義、目標板電源等:

Error: JTAG scan chain interrogation failed: all zeroes
Error: Check JTAG interface, timings, target power, etc.
Error: Trying to use configured scan chain anyway...
Error: IR capture error at bit 0, saw 0x00 not 0x...3
Warn : Bypassing JTAG setup events due to errors
Warn : gdb services need one or more targets defined

  我以前遇到的狀況是線序和ftdi_layout都不對……

【5.2】處理器部分。
openocd 0.8已經支持sam9g45,配置文件爲 target/at91sam9g45.cfg,該文件引用了同目錄下的at91sam9.cfg。整理後內容以下:

#嘗試使用設備提供的調試時鐘(RTCK引腳),失敗則使用指定的頻率(單位KHZ)
adapter_khz 3

#復位配置 reset_config trst_and_srst separate trst_push_pull srst_open_drain adapter_nsrst_delay
300 jtag_ntrst_delay 200 #給即將添加的TAP配置起個名字 set _CHIPNAME at91sam9g45 #芯片TAP的識別ID,整個AT91SAM9系列都是用這個TAP ID set _CPUTAPID 0x0792603f #小端存儲 set _ENDIAN little #以$_CHIPNAME爲名,建立一個新的tap jtag newtap $_CHIPNAME cpu -irlen 4 -ircapture 0x1 -irmask 0xf -expected-id $_CPUTAPID #目標處理器定義 set _TARGETNAME $_CHIPNAME.cpu target create $_TARGETNAME arm926ejs -endian $_ENDIAN -chain-position $_TARGETNAME -variant arm926ejs # 處理器內建SRAM $_TARGETNAME configure -work-area-phys 0x00300000 -work-area-size 0x200000 -work-area-backup 1

嘗試運行openocd:
1.關閉設備電源,
2.連接設備、調試器、PC
3.打開設備電源
4.運行openocd:

openocd -f ~/.openocd/openjtag.cfg -f target/at91sam9g45.cfg
target/at91sam9g45.cfg實際上在/usr/share/openocd/scripts/中,這裏使用默認的搜索路徑。

openocd的打印以下:

Info : only one transport option; autoselect 'jtag'
RCLK - adaptive
trst_and_srst separate srst_gates_jtag trst_push_pull srst_open_drain connect_deassert_srst
adapter_nsrst_delay: 300
jtag_ntrst_delay: 200
adapter speed: 3 kHz
1
Info : clock speed 3 kHz
Info : JTAG tap: at91sam9g45.cpu tap/device found: 0x0792603f (mfg: 0x01f, part: 0x7926, ver: 0x0)
Info : Embedded ICE version 6
Info : at91sam9g45.cpu: hardware has 2 breakpoint/watchpoint units

得到了ICE版本號,沒有報錯。

5.保持openocd運行,給設備從新上電。openocd在設備上電後,打印以下:

Error: invalid mode value encountered 0
target state: halted
target halted in Thumb state due to debug-request, current mode: Thread
cpsr: 0x00000020 pc: 0xffffffee
MMU: disabled, D-Cache: disabled, I-Cache: disabled

若是在設備斷電的狀況下啓動openocd,打印的結果如5.1中所述。此時給設備上電,openocd也會打印上面的信息,一樣能夠證實工做正常(有調試器的狀況下上電,停在最初的狀態下)。

【5.3】板子部分。這部分能夠定義板載的外設(如NAND)、設定一些事件發生(如CPU復位)後執行的動做等。
nand的設置:

set _NANDNAME $_TARGETNAME.nand
nand device $_NANDNAME at91sam9 $_TARGETNAME 0x40000000 0xFFFFE800

【5.4】telnet監聽端口設置。

#telnet的監聽端口,默認4444.能夠經過telnet執行jtag指令,openocd文檔中有jtag指令的解釋。
#telnet_port 4444

【5.5】gdb監聽端口設置。

#gdbsever的TCP/IP監聽端口,默認3333.設定爲disable,關閉gdbserver;pipe爲標準輸入輸出,也就是管道
#gdb_port 3333

 【6】nand操做
首先打開一個終端,連接openocd的telnet

telnet 127.0.0.1 4444

在telnet中,將設備復位並馬上中止運行,探查nand。reset;halt須要寫在一塊兒,以保證mmu是關閉的,不然nand probe可能會返回 Address translation failure

reset;halt
nand probe 0

讀寫nand

nand dump 0 ~/uboot_old.bin 0 0x40000
nand erase 0 0 0x40000
nand write 0 ~/uboot_new.bin 0

 



 

 

 

 

【】SWD
transport select swd 須要寫在 interface ftdi 後,不然會提示

Error: Debug adapter doesn't support any transports?

0.8版本中會作以下提示,也許只能支持特定的interface。

Info : only one transport option; autoselect 'jtag'
Error: session's transport is already selected.

0.9-dev版本中,會提示:

Info : FTDI SWD mode enabled
swd
Error: SWD mode is active but SWD_EN signal is not defined
in procedure 'init'

接下來須要設置引腳上的信號,之後再研究。

本文原地址  http://www.cnblogs.com/jacob1934/p/4075184.html請勿轉載

相關文章
相關標籤/搜索