天天看點

openocd編譯安裝使用 (基于百問網openjtag工具 ftdi)

    1.下載下傳最新的openocd的代碼

    下載下傳代碼主要有兩種方式:

    a.從openocd的官網(http://openocd.berlios.de/web/)上下載下傳官方釋出的最新版本(0.5.0),下載下傳網址(http://developer.berlios.de/projects/openocd/),openocd的使用文檔的下載下傳位址為http://openocd.berlios.de/web/documentation/online-docs/

    這種代碼擷取方式下,解壓後裡面直接就有配置器腳本configure

    b.擷取官方正在維護的最新代碼(http://repo.or.cz/w/openocd.git),openocd采用的是git進行代碼維護

    使用git工具将代碼clone下來,git工具安裝方法 $ sudo apt-get install git

    擷取openocd代碼的指令:

    首先cd定位到你需要git代碼的位置然後執行如下指令

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

    git完以後,定位到openocd代碼的目錄下執行如下指令

    $ ./bootstrap  這個指令主要是用于生成configure檔案的,同時git出一些相關的代碼

    上面的指令執行完畢後,就要開始使用配置器腳本生成makefile檔案,這一步比較關鍵是以和前面一種代碼擷取方式相同,這裡單獨拿出來講解

    2.使用配置器腳本configure生成makefile

    在openocd的源碼目錄下有一個readme的檔案打開後有英文版的安裝使用說明

    這裡說明一下,由于我使用的是openjtag在百問網(http://www.100ask.net/)上有相關的介紹這裡就不做介紹了.

    這一款jtag工具采用了ftdi公司(http://www.ftdichip.com/FTSupport.htm)的一款晶片FT2232C,這款晶片的相關介紹感興趣的可以到它的官網上查閱相關資料

    關于檢視該晶片的型号的方法:可以直接打開工具的外殼檢視晶片型号,或者将確定已拔除,再插入等5s,輸入$dmesg 指令可以檢視到插入的裝置的一些資訊

    對于我的電腦如下

    [ 3330.464070] usb 6-2: new full speed USB device using uhci_hcd and address 2

    [ 3330.920844] usbcore: registered new interface driver usbserial

    [ 3330.920860] USB Serial support registered for generic

    [ 3330.920898] usbcore: registered new interface driver usbserial_generic

    [ 3330.920900] usbserial: USB Serial Driver core

    [ 3330.926470] USB Serial support registered for FTDI USB Serial Device

    [ 3330.926580] usb 6-2: Ignoring serial port reserved for JTAG

    [ 3330.926610] ftdi_sio 6-2:1.1: FTDI USB Serial Device converter detected

    [ 3330.926675] usb 6-2: Detected FT2232C

    [ 3330.926678] usb 6-2: Number of endpoints 2

    [ 3330.926680] usb 6-2: Endpoint 1 MaxPacketSize 64

    [ 3330.926682] usb 6-2: Endpoint 2 MaxPacketSize 64

    [ 3330.926684] usb 6-2: Setting MaxPacketSize 64

    [ 3330.928492] usb 6-2: FTDI USB Serial Device converter now attached to ttyUSB0

    [ 3330.928515] usbcore: registered new interface driver ftdi_sio

    [ 3330.928518] ftdi_sio: v1.6.0:USB FTDI Serial Converters Driver

    對于如上資訊可以看出該openjtag的核心晶片應該是FTDI公司提供的FT2232C,以及一些相關的資訊

    為了檢視關于這個USB openjtag的更加詳細的資訊,我們可以執行如下指令 $lsusb檢視裝置的相關簡要資訊

    我的電腦擷取到如下資訊

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

    為了擷取更加詳細的資訊我們可以采用如下指令

    $ sudo lsusb -v -D /dev/bus/006/002 (解釋:sudo是必須的,因為通路usb的一些操作需要超級使用者權限,lsusb的使用方法可以采用man lsusb檢視,006對應bus 006 ,002對應Device 002)

    擷取詳細資訊我隻截取一些關鍵資訊如下

    idVendor           0x1457 First International Computer, Inc.

    idProduct          0x5118 OpenMoko Neo1973 Debug board (V2+)

    iManufacturer           1 www.100ask.net

    iProduct           2 USB<=>JTAG&RS232

    iInterface              2 USB<=>JTAG&RS232

    現在知道這款openjtag工具采用的是ftdi公司的晶片,當然我們就可以需要在配置器腳本進行配置的時候加入一些相關的配置選項以支援ftdi的工具

    首先需要擷取晶片的相關的驅動分别在如下網站上有下載下傳

    http://www.ftdichip.com/Drivers/D2XX.htm

    http://www.intra2net.com/en/developer/libftdi/download.php

    直接apt-get擷取穩定的版本的方式(非ftdi官方驅動)

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

    如果采用直接apt-get擷取的方式獲得libftdi的驅動,配置器的配置選項如下(具體可以參照如下網站實作 http://fun-tech.se/stm32/OpenOCD/index.php)

    關于配置器的使用方法 可以直接運作如下指令 $./configure --help

    ./configure --enable-maintainer-mode \

            --enable-ft2232_libftdi

    --enable-maintainer-mode     enable make rules and dependencies not useful  (and sometimes confusing) to the casual installer 采用最舒适的配置方式

    --enable-ft2232_libftdi Enable building support for FT2232 based devices using the libftdi driver, opensource alternate of FTD2XX 采用FTD2XX開源的驅動解決方案

    如果采用FTDI官方的驅動可以采取如下方式(官方驅動方式)

    下載下傳網址  http://www.ftdichip.com/Drivers/D2XX.htm

    下載下傳完畢上述驅動後,名稱為libftd2xx1.0.4.tar.gz

    解壓後 将ftd2xx.h和WinTypes.h都拷貝到/usr/local/include/目錄下,并且在/usr/include/目錄下建立軟連結(需要超級使用者權限),主要原因是make編譯的時候需要用到這些頭檔案

    首先進入libftd2xx1.0.4.tar.gz解壓後的目錄假設為 libftd2xx1.0.4

    執行如下指令

    $sudo cp ./ftd2xxx.h /usr/local/include/ftd2xxx.h

    $sudo cp ./WinTypes.h /usr/local/include/WinTypes.h

    $sudo ln -s /usr/local/include/ftd2xx.h /usr/include/ftd2xx.h

    $sudo ln -s /usr/local/include/WinTypes.h /usr/include/WinTypes.h

    執行完畢後,就可以執行如下指令(之前先要進入openocd的源碼目錄,假設ftdi驅動檔案的檔案夾位于openocd源碼目錄下檔案名為libftd2xx1.0.4)

    $ ./configure --enable-maintainer-mode\

        --enable-ft2232_ftd2xx \

        --with-ft2xx-linux-tardir=./libftd2xx1.0.4

    --enable-ft2232_ftd2xx  Enable building support for FT2232 based devices the FTD2XX driver from ftdichip.com 采用ftdichip提供的驅動檔案

    --with-ft2xx-linux-tardir 後面接ftdichip公司提供的驅動檔案目錄

    按照上面的兩種方式最後都生成了所需要的makefile檔案,關于配置器的一些更多的配置選項請參見配置器的幫助./configure --help

    為了避免和你之前安裝的openocd沖突,你可以加入如下選項 --program-suffix=v5 ,這樣的話最後生成的目标檔案拷貝到系統的目錄下,就會加入v5的字尾就不會覆寫之前的版本了

    3.編譯安裝使用

    編譯,執行如下指令

    $make

    編譯完畢後,在源碼目錄下的src目錄下可以找到最後生成的執行檔案openocd

    将openocd安裝到系統目錄的方式的指令如下

    $sudo make install

    編譯成功後直接執行src目錄下的openocd,打住,這裡還缺一點需要寫一下配置檔案

    由于這裡我使用的是lpc2478的晶片,開發工具為百問網(100ask)出品的openjtag調試器這裡需要編寫配置檔案(openocd.cfg)如下:

    interface ft2232

    ft2232_vid_pid 0x1457 0x5118

    ft2232_device_desc "USB<=>JTAG&RS232 A"

    ft2232_layout "jtagkey"

    # jtag speed

    jtag_rclk 500

    這裡需要注意對于openocd0.4使用者可以在配置檔案的每個指令後進行注釋

    如下 jtag_rclk 500  # jtag speed

    但是對于openocd0.5版本就不可以這樣進行注釋了,如果需要注釋的話,必須另起一行如下

    # jtag speed

    jtag_rclk 500

    解釋上述配置檔案的含義

    interface 表示  type of debug adapter

    可以通過sudo openocd -c interface_list 擷取可用的interface的名稱,這裡擷取到為ft2232

    ft2232_vid_pid 表示的是The vendor ID and product ID of the FTDI FT2232 device

    VendorID和ProductID這個已經在前面擷取到了如下

    idVendor           0x1457 First International Computer, Inc.

    idProduct          0x5118 OpenMoko Neo1973 Debug board (V2+)

    是以配置如下 ft2232_vid_pid 0x1457 0x5118

    ft2232_device_desc 表示 Provides the USB device description (the iProduct string) of the FTDI FT2232 device. If not specified, the FTDI default value is used.

    這裡前面擷取到了相關的資訊如下

    iProduct           2 USB<=>JTAG&RS232

    ft2232_layout表示Each vendor’s FT2232 device can use different GPIO signals to control output-enables, reset signals, and LEDs

    這裡我們使用的産品是jtagkey的layout,是以這裡設定為jtagkey

    jtag_rclk表示fallback speed kHz,如果使能RTCK/RCLK失敗,就自動降低到設定的頻率

    最後按照上面的進行配置後運作如下指令(前提是在編譯生成有openocd的執行檔案的目錄下,切編寫好openocd配置檔案openocd.cfg,openjtag連接配接到電腦)

    $sudo ./openocd

    執行結果如下

    Open On-Chip Debugger 0.5.0 (2011-09-18-21:38)

    Licensed under GNU GPL v2

    For bug reports, read

http://openocd.berlios.de/doc/doxygen/bugs.html

    Info : only one transport option; autoselect 'jtag'

    RCLK - adaptive

    Error: unable to get latency timer: 0

    Error: ftd2xx 1.04 detected - this has known issues with FT_GetLatencyTimer, upgrade to a newer version

    Info : device: 4 "2232C"

    Info : deviceID: 341266712

    Info : SerialNumber: 

    Info : Description: USB<=>JTAG&RS232 A

    Info : RCLK (adaptive clock speed) not supported - fallback to 500 kHz

    Warn : There are no enabled taps.  AUTO PROBING MIGHT NOT WORK!!

    Warn : AUTO auto0.tap - use "jtag newtap auto0 tap -expected-id 0x4f1f0f0f ..."

    Warn : AUTO auto0.tap - use "... -irlen 4"

    Warn : gdb services need one or more targets defined

參考文獻

    解決ftd2xxx.h找不到的問題    http://ibot.rikers.org/%23openjtag/20081228.html.gz

    http://blog.ednchina.com/SimonQian/137397/message.aspx#

    http://elk.informatik.fh-augsburg.de/hhweb/doc/openocd/usbjtag/usbjtag.html

    http://archive.cnblogs.com/a/1953251/

    http://forum.ubuntu.org.cn/viewtopic.php?f=97&t=291845&p=2255874

    http://hi.baidu.com/ee_site/blog/item/de14d9445d787544510ffed5.html

    http://piconomic.co.za/fwlib/index.html

    http://www.downtowndougbrown.com/2011/08/cross-compiling-openocd-0-5-0-for-windows-7-64-bit-ftdis-ftd2xx-library-using-linux-and-mingw/

    http://fun-tech.se/stm32/OpenOCD/index.php

    http://www.plugcomputer.org/plugwiki/index.php/Setting_Up_OpenOCD_Under_Linux

    http://www.tincantools.com/wiki/Compiling_OpenOCD_Linux_D2XX

    Gentoo Linux USB指南 http://www.gentoo.org/doc/zh_cn/usb-guide.xml

繼續閱讀