Compiling OpenOCD for Windows XP (FTD2XX) - Pre June 2011

From eLinux.org
Revision as of 04:00, 11 April 2012 by Wmat (Talk | contribs) (Porting TinCanTools wiki content.)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

This guide is out of date. Because of the recent addition of a cross-compiler to Cygwin, these instructions apply only to a user with Cygwin already installed and last updated before June 2, 2011. An up-to-date guide will be available soon. For an up-to-date guide to an alternative libFTDI build, see Compiling OpenOCD for Windows XP (LibFTDI).


This guide will compile OpenOCD 0.4.0 for Windows XP with the FTD2XX driver library, for use with the TinCanTools Flyswatter. The process is identical on 32 and 64 bit versions of Windows.


Installing Cygwin

Download and install Cygwin 1.7.8-1 from http://www.cygwin.com. Cygwin provides a GNU development environment for Windows, which will allow you to compile OpenOCD using the GNU Compiler Collection (GCC). You will not need Cygwin to run OpenOCD. The Cygwin installer is available at http://cygwin.com/install.html.

Installing Cygwin Packages

In the Cygwin installer you will be prompted to select additional packages to install. Install the following optional packages, found under the Devel heading:

autoconf
automake
gcc-core
gcc-g++
libtool
libusb-1.0
libusb-win32
libusb-devel
make


Cygwin Changes May 2011

Until June 1, 2011, Cygwin is undergoing changes to improve its support for Windows cross-compilation. If you have downloaded or update Cygwin since May 1, 2011, you will need to make some changes to make the GCC C compiler support the -mno-cygwin flag. If you last updated Cygwin before May 1, 2011 or after June 1, 2011, you should skip this section.

Open the Cygwin command line interface. The default Cygwin install places a shortcut in Start Menu > All Programs > Cygwin > Cygwin Bash Shell. Navigate to /usr/i686-pc-mingw32/lib.

cd /usr/i686-pc-mingw32/lib

That directory contains several symbolic links. Redirect them by typing the following. Hit Return after typing each line. The loop will not execute until you type the last line and hit Return. Be sure to include the trailing period at the end of the third line.

for f in *.o ; do
rm -f $f
ln -fs /usr/lib/mingw/$f .
done

If you do not do this, every time you try to compile with the -mno-cygwin flag you will see this error:

configure: error: C compiler cannot create executables

For more information and alternative solutions, see this article: http://cygwin.com/ml/cygwin-announce/2011-04/msg00015.html. Refer to this more in-depth article if you see the above error.


Installing libusb

Libusb is a usb driver library you will need to communicate with the Flyswatter. You will need a newer version of libusb than the one distributed through the Cygwin installer, and you will need libusb for Windows as well. Download libusb-win32-1.2.4.0 from http://sourceforge.net/projects/libusb-win32/files/libusb-win32-releases/1.2.4.0/libusb-win32-bin-1.2.4.0.zip/download. Open the zip archive and extract the contents to C:\cygwin\home.

Navigate to the folder \libusb-win32-bin-1.2.2.0\lib\gcc. Copy the file libusb.a to C:\cygwin\lib and C:\cygwin\lib\mingw.

Navigate to \libusb-win32-bin-1.2.2.0\include. Copy the file usb.h to C:\cygwin\usr\include and C:\cygwin\usr\include\mingw.

Installing FTD2XX

Download version 2.08.14 of the D2XX Windows drivers from http://www.ftdichip.com/Drivers/D2XX.htm. Direct link is here: http://www.ftdichip.com/Drivers/CDM/CDM20814_WHQL_Certified.zip. Extract the contents to C:\cygwin\home\ftd2xx.

In Windows Explorer, open the ftd2xx folder and find the file ftd2xx.h. Copy this file to C:\cygwin\usr\include and C:\cygwin\usr\include\mingw.

The Found New Hardware Wizard

Navigate to C:\cygwin\home\ftd2xx\i386 and find the file ftd2xx.lib. Copy it, rename the copy ftd2xx.a and move the new file to C:\cygwin\usr\local\lib.

Plug the Flyswatter into your computer's USB port. The Windows Found New Hardware Wizard should appear. Choose "No, not this time" to decline to connect to Windows Update. On the next screen, choose "Install from a list of specific location." On the third screen, choose "Search for the best drivers in these locations," check "Include this location in the search," and enter C:\cygwin\home\ftd2xx.

Click Next. Windows should find and install the FTDI drivers. If you see a warning that the drivers have not passed Windows Logo testing, choose "Install Anyway."

The Found New Hardware Wizard should appear twice. The second time the wizard appears, repeat the process exactly as above.


Compiling OpenOCD

Download the OpenOCD 0.4.0 source from http://prdownload.berlios.de/openocd/openocd-0.4.0.zip and extract it to C:\cygwin\home\openocd-0.4.0. In the Cygwin command line interface, navigate to your openocd-0.4.0 directory.

cd /home/openocd-0.4.0

Compile OpenOCD with the following commands:

./configure --disable-werror --enable-ft2232_ftd2xx --with-ftd2xx-win32-zipdir=../ftd2xx 
       CC="gcc-3 -mno-cygwin -L/usr/lib/mingw -L/usr/lib/w32api -I/usr/include/mingw -I/usr/include/w32api"

Type the above all one one line. Note that "../ftd2xx" is the path to your ftd2xx directory. You may need to change this argument if you extracted ftd2xx to a different location. You may use either a relative path, as above, or an absolute path, such as C:\cygwin\home\ftd2xx. The argument --with-ftd2xx-win32-zipdir should be used even on 64 bit Windows XP.

Finish compiling as follows:

make
make install


Preparing to Run OpenOCD

Navigate to C:\cygwin\home\openocd-0.4.0\src to find openocd.exe. The executable can be run from the Windows command line and does not require Cygwin.

You can run openocd from C:\cygwin\home\openocd-0.4.0\src, but you may encounter problems with configuration files. For a more in-depth discussion of these issues, see OpenOCD Config File Paths. This guide recommends that you create a new folder containing OpenOCD and its config files. Go to Start Menu > My Computer and open your C: drive. Right-click anywhere in the C: drive window and select New > Folder. Rename the new folder openocd.

In another Windows Explorer window, open C:\cygwin\home\openocd-0.4.0\tcl. Click and drag to select all the contents of the folder. Right-click on any file and select Copy. Open C:\openocd, right-click anywhere, and select Paste.

Now go to C:\cygwin\home\openocd-0.4.0\src and copy openocd.exe to C:\openocd. The folder should now contain the following files and folders:

board
chip
cpld
cpu
openocd.exe
interface
target
test
bitsbytes.tcl
memory.tcl
mmr_helpers.tcl
readable.tcl

You can now run OpenOCD from C:\openocd. To get started running OpenOCD, see Running OpenOCD on Windows.


Installing LibUSB Device Filters

If the configure command above halts with an error stating that it is unable to compile and run a test program, or if openocd.exe compiles successfully but cannot open the FTDI device, you may need to install a libusb Device Filter.