openjtag openocd libftd2xx

来源:互联网 发布:俊平大魔王 知乎 编辑:程序博客网 时间:2024/06/09 11:11

    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.1.0.tar.gz
    解压后 将ftd2xx.h和WinTypes.h都拷贝到/usr/local/include/目录下,并且在/usr/include/目录下建立软链接(需要超级用户权限),主要原因是make编译的时候需要用到这些头文件
    首先进入libftd2xx1.1.0.tar.gz解压后的目录假设为 libftd2xx1.1.0
    执行如下命令
    $sudo cp ./ftd2xxx.h /usr/local/include/ftd2xx.h

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

    $sudo cp ./libftd2xx.so.1.1.0 /usr/local/lib/libftd2xx.so.1.1.0

  sudo ln -s /usr/local/lib/libftd2xx.so.1.1.0 /usr/lib/libftd2xx.so

  sudo ln -s /usr/lib/libftd2xx.so /usr/lib/libftd2xx.so.0

    $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.1.0)
    $ ./configure --enable-maintainer-mode\
        --enable-ft2232_ftd2xx \
        --with-ft2xx-linux-tardir=./libftd2xx1.1.0
    --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
原创粉丝点击