Building OpenOCD with libfti/libusb for Windows 64

[UPDATED - 2009.11.05 as the Win x64 patch has also been integrated in the latest GIT source for libftdi]

[UPDATED - 2009.10.20 as the MinGW-W64 patches have now been integrated in the latest GIT source for OpenOCD]

PREREQUISITES:

  • o [WPG System64 (MinGW x64) installed in C:\msys\

    o [Optional - Only needed if you want to recompile libusb-win32] [libusb-win32-src-0.1.12.2.tar.gz extracted in C:\msys\src\libusb-win32-src-0.1.12.2\

    o The latest sources for libftdi should be downloaded from git (they contain important fixes for Win x64!) and installed in C:\msys\src\libftdi\

    If you have git installed you can retrieve the latest source with:```
    git clone git://developer.intra2net.com/libftdi

    
    o The latest sources for OpenOCD <B>**should**</B> also be downloaded from git and installed in C:\msys\src\openocd with:```
    git clone git://openocd.git.sourceforge.net/gitroot/openocd/openocd
    ```Note that OpenOCD has recently been updated with patches to ensure successful compilation on MinGW, so if you are using the svn source or an archive version lower than 0.3.0, you will encounter issues. Using git is the only way to avoid these issues right now.</LI>[/list]</LIST>
    
    <B>**STEP 0 - OPTION A: Installing pre-compiled libusb-win32 drivers for Windows x64**</B><LIST><LI>o Download the libusb-win32_ft2232 x64 drivers from [[here](http://nil.rpc1.org/files/sheeva/libusb-win32_ft2232_drivers_x64.zip) and follow the instructions.</LI>[/list]</LIST>
    <B>**STEP 0 - OPTION B: Building and installing the libusb-win32 drivers from scratch**</B><LIST><LI>o Download and install [[Windows Driver Kit Version 7.0.0](http://www.microsoft.com/downloads/details.aspx?FamilyID=2105564e-1a9a-4bf4-8d74-ec5b52da3d00&displaylang=en). Please note that this is a 700 MB ISO image, so it might take a while
    
    o (Building of 32 bit drivers) Open Windows Drivers Kits -> WDK 7600.16385.0 -> Build Environments -> Windows 7 -> x86 Free Build Environment (And yes, this will create Vista compatible drivers too!)
    
    o In the command prompt, navigate to C:\msys\src\libusb-win32-src-0.1.12.2\ddk_make\ and run the command```
    make_all.bat
    ```You should now have a libusb0.sys and libusb0.dll in C:\msys\src\libusb-win32-src-0.1.12.2\ddk_make\. You can now close the "x86 Free Build Environment" command prompt window.
    
    o (Building of the 64 bit drivers) Open Windows Drivers Kits -> WDK 7600.16385.0 -> Build Environments -> Windows 7 -> x64 Free Build Environment
    
    o Rename libusb0.def and libusb0_drv.def in C:\msys\src2\libusb-win32-src-0.1.12.2\ to libusb0_x64.def libusb0_x64_drv.def respectively
    
    o Edit C:\msys\src\libusb-win32-src-0.1.12.2\ddk_make\sources_<B>**dll**</B> and change the line```
    TARGETNAME = libusb0
    ```to```
    TARGETNAME = libusb0_x64
    

    o Edit C:\msys\src\libusb-win32-src-0.1.12.2\ddk_make\sources_drv and change the lineTARGETNAME = libusb0to```
    TARGETNAME = libusb0_x64

    o In the command prompt, navigate to C:\msys\src\libusb-win32-src-0.1.12.2\ddk_make\ and run the command```
    make_all.bat
    ```You should now have a libusb0_x64.sys and libusb0_x64.dll in C:\msys\src\libusb-win32-src-0.1.12.2\ddk_make\. You can now close the "x64 Free Build Environment" command prompt window.
    
    o Copy the [[following inf file](http://nil.rpc1.org/files/sheeva/libusb-win32_ft2232_driver_x64.inf) to your C:\msys\src\libusb-win32-src-0.1.12.2\ddk_make\ directory. Edit it as appropriate according to your USB device (The LibUSB-Win32 drivers we built are not exclusive to FTDI USB devices)
    
    o Still in the ddk_make\ directory, create 2 empty files, named: "libusb_x64.cat" and "libusb.cat" (or edit the inf file to remove the .cat references)
    
    o Navigate to <your_WinDDK_install_dir>\7600.16385.0\bin\amd64\ and copy the files CertMgr.exe, MakeCert.exe and SignTool.exe to the C:\msys\src\libusb-win32-src-0.1.12.2\ddk_make\ directory
    
    o Follow the steps highlighted [[here](http://nil-techno.blogspot.com/2008/08/installing-unsigned-drivers-on-vista-64.html) to sign your drivers.
    
    o Remove any existing FTDI drivers, plug in your system, and install the libUSB drivers. One the drivers have been installed, you should have libusb0_x64.dll in C:\Windows\System32</LI>[/list]</LIST>
    <B>**STEP 1: Compiling libftdi**</B><LIST><LI>o Make sure you have the LibUSB Win32 x64 driver installed, with libusb0_x64.dll in C:\Windows\System32\
    
    o Navigate to the directory where you have the libusb0_x64.def from the LibUSB-Win32 driver files and issue the command:```
    dlltool.exe -d libusb0_x64.def -l /usr/local/lib/libusb.a
    ```This will create the library interface for the LibUSBWin32 DLL
    
    IMPORTANT NOTE: If you are using the libsub-win32 source def file (i.e. you used OPTION B for STEP 0), you need to add the line ```
    LIBRARY libusb0_x64.dll
    ```at the beginning of your def file. If not, you are likely to get the error "The application failed to start because "(null).dll" was not found" later on, as the DLL needs to be referenced in the lib file. 
    
    o Copy the file usb.h from your libusb drivers to /usr/local/include (or C:\msys\local\include in Windows - create the directory if it doesn't exist)
    
    o <B>**[OPTIONAL]**</B> You might also want to check that libUSB is working using the libfti test programs (which is a wise thing to do before compiling OpenOCD), so before compiling libfti, you should retrieve the Vendor ID and Product ID of your USB device, and edit src/examples/find_all.c to update line #24.
    
    For instance, for the SheevaPlug dev kit:```
    if ((ret = ftdi_usb_find_all(&ftdic, &devlist, 0x0403, 0x6001)) < 0)
    ```becomes```
    if ((ret = ftdi_usb_find_all(&ftdic, &devlist, 0x9E88, 0x9E8F)) < 0)
    ```You can find the vendor ID & product ID in the Device Manager by going to: LibUSB-Win32 Devices -> <your device name> -> Properties -> Details -> Hardware ID. There you should see something like USB\VID_AAAA&PID_BBBB with AAAA being the vendor ID and BBBB the product ID. (For the SheevaPlug Dev Kit, the like is: "USB\VID_9E88&PID_9E8F&REV_0500&MI_00")
    
    o Issue the command```
    ./configure --build=x86_64-w64-mingw32 CFLAGS="-I/usr/local/include" LDFLAGS="-L/usr/local/lib" LIBS="-lusb"
    ```Note that if you want to debug OpenOCD/libftdi, you can add "-O0 -g -Wall" to CFLAGS
    
    o You will get some warnings during configure, but you can ignore them. Then run
    
    

    make
    make install

    
    Libftdi should compile without error, and will install in /usr/local
    
    o <B>**[OPTIONAL]**</B> To test that libUSB is working, provided you modified find_all.c accordingly:
    
    

    $ /usr/local/bin/find_all.exe
    Number of FTDI devices found: 1
    Checking device: 0
    Manufacturer: FTDI, Description: SheevaPlug JTAGKey FT2232D B

    
    Time to compile OpenOCD</LI></LIST>
    <B>**STEP 2: Compiling OpenOCD**</B><LIST><LI>o If you are using the latest GIT sources, you should not have to patch anything. Just run:
    
    

    ./bootstrap
    ./configure --enable-maintainer-mode --build=x86_64-w64-mingw32 --enable-ft2232_libftdi CFLAGS=“-I/usr/local/include” LDFLAGS=“-L/usr/local/lib”
    make

    
    (Once again, you can add a CFLAGS="-O0 -g -Wall" in there to compile with debug, so that you can use gdb)
    
    o Once the compilation has completed successfully, run make install. You should now be able to run a fully GPL compliant version of openocd on Windows 64 systems.</LI></LIST>](http://nil-techno.blogspot.com/2008/08/installing-unsigned-drivers-on-vista-64.html)](http://nil.rpc1.org/files/sheeva/libusb-win32_ft2232_driver_x64.inf)](http://www.microsoft.com/downloads/details.aspx?FamilyID=2105564e-1a9a-4bf4-8d74-ec5b52da3d00&displaylang=en)](http://nil.rpc1.org/files/sheeva/libusb-win32_ft2232_drivers_x64.zip)](http://code.google.com/p/msysgit/)](http://sourceforge.net/projects/libusb-win32/files/)](http://www.cadforte.com/system64.html)
  • Hi !!

    i was trying to use the drivers provided here with Windows 7 x64 and my amontec jtag key tiny and they did not work … the installer fails during insalling the driver. I got the message that someting in the service installation sector is invalid (sorry for this crude translation, i have a german windows and thats what M$ call it ggg)

    can you help me with this problem?

    julian

    Hi,

    Have you checked that the Vendor ID and Product ID for your amontec jtag key tiny matched the ones reported by the Device Manager.

    Also, unless I’m mistaken, I don’t think you have used the right set of files for your driver installation (you need to download the [libusb-win32_ft2232_drivers_x64.zip archive, and then run the various cmd file as administrator, as indicated in INSTALL.txt), because the original batch files I gave in the archive did not work with Windows 7.

    I have now fixed them, but I don’t really see how you could have installed the driver on Windows 7 with the previous archive, as you should have seen errors when trying to run the .cmd files.

    Remember that, before you can install the driver on Windows x64, you must:

    1. run the Windows_Enable_Test_Mode.cmd file as administrator and reboot your machine, if your machine is not already in Test Mode (you must see Test Mode displayed on your wallpaper before you attempt to install the drivers)

    2. run the Sign_Drivers.cmd as administrator, before attempting to install the driver. This is because you cannot use the .sys files provided in the archive unless they are signed, and the original files from the zip are unsigned.

    If you do just that, and have the proper VID and PID for your USB device in the .inf, then the driver installation should work.](http://nil.rpc1.org/files/sheeva/libusb-win32_ft2232_drivers_x64.zip)

    thanks very good :)[[u]learn hypnosis free[/u]](http://theartofcoverthypnosis.com/)

    seraulu1: You might want to see this topic for a pre-built OpenOCD and drivers that work with Win Vista/7 64 bit: viewtopic.php?t=19358

    As my reply in that other thread says, the instructions in this thread didn’t quite work for driver installation.

    i have read all the posted msgs it helps me a lot with some of my problems… thanks for the informations you have shared… [[u]master resell rights[/u]](http://rebrandableproducts.com/)

    Nutter:
    As my reply in that other thread says, the instructions in this thread didn’t quite work for driver installation.

    As per my reply in the other thread, I believe that **Nutter**'s problem stem from the fact that the OpenOCD package didn't include the latest version of the scripts published in the driver files above.

    The instructions from this thread should work for driver installation, but by all means, if they don’t, please provide a detailed report of any error you see, so that I can attempt to address them.

    Pretty interesting stuff. I got answers to my unsolved questions. Thanks for this help.

    Cheers

    [Jack the ripper Walk](http://www.rippervision.com/)[/u]