Compiling OpenOCD v04 Linux D2XX
This guide will compile OpenOCD 0.4.0 for Ubuntu 10.04 with the FTD2XX driver library, for use with the TinCanTools Flyswatter.
You will need to install several packages to compile and run OpenOCD. Open a terminal window (Applications menu > Accessories > Terminal) and type:
sudo apt-get install libtool sudo apt-get install autoconf sudo apt-get install texinfo sudo apt-get install libusb-dev
If you prefer to compile libusb yourself, you can find the source at http://sourceforge.net/projects/libusb/files/libusb-1.0/.
Download version 0.4.16 of the D2XX Linux drivers from http://www.ftdichip.com. Direct link is here: http://www.ftdichip.com/Drivers/D2XX/Linux/libftd2xx0.4.16.tar.gz. This is not the most recent version of the ftd2xx library, but you will need the older version. Extract the contents to your home directory (/home/USERNAME, replacing USERNAME with your username.)
In the terminal window, navigate to ~/libftd2xx0.4.16/sample and copy the files ftd2xx.h and WinTypes.h to /usr/include. Then navigate to /usr/local/include and create symbolic links to the header files.
cd ~/libftd2xx0.4.16/sample sudo cp ftd2xx.h /usr/include sudo cp WinTypes.h /usr/include cd /usr/local/include sudo ln -s /usr/include/ftd2xx.h ftd2xx.h sudo ln -s /usr/include/WinTypes.h WinTypes.h
Now return to the ~/libftd2xx0.4.16 directory and copy the library file to /usr/local/lib. Then create symbolic links to the file in /usr/lib and /usr/local/lib:
cd ~/libftd2xx0.4.16 sudo cp libftd2xx.so.0.4.16 /usr/local/lib cd /usr/local/lib sudo ln -s libftd2xx.so.0.4.16 libftd2xx.so.0 sudo ln -s libftd2xx.so.0.4.16 libftd2xx.so cd /usr/lib sudo ln -s /usr/local/lib/libftd2xx.so.0.4.16 libftd2xx.so.0 sudo ln -s /usr/local/lib/libftd2xx.so.0.4.16 libftd2xx.so
Download the OpenOCD 0.4.0 source from http://prdownload.berlios.de/openocd/openocd-0.4.0.tar.gz and extract openocd-0.4.0 to your home directory (/home/USERNAME/openocd-0.4.0).
Installing the Flyswatter 2 / Flyswatter 3 Patch (Optional)
The OpenOCD Flyswatter 3 beta patch provides support for the Flyswatter3 and Flyswatter2, a config file for the Olimex PIC-P32MX development board, and an updated config file for the TinCanTools Hammer. Download the file Media:Openocd-fs3-b0.1.patch. (Right click the link and select Save As.) Save the file to your new openocd-0.4.0 directory.
In the terminal window, navigate to the patch file and patch the source as follows:
cd ~/openocd-0.4.0 patch -p1 -i Openocd-fs3-b0.1.patch
For more information on the config files added by this patch, see OpenOCD Config Files.
In the terminal window, navigate to the new folder containing the OpenOCD source and run the configure script.
cd ~/openocd-0.4.0 sudo ./configure --disable-werror --enable-ft2232_ftd2xx --with-ftd2xx-linux-tardir="../libftd2xx0.4.16"
This assumes that you followed this guide exactly and extracted libftd2xx0.4.16 to your /home/USERNAME directory, one level above the OpenOCD source. If this is not the case, change the value of --with-ftd2xx-linux-tardir to the path to your libftd2xx0.4.16 directory.
The configure script creates a makefile and a file called libtool, which is used to compile OpenOCD. However, a bug in libtool causes the libopenocd and ftd2xx libraries to be compiled out of order, which will cause compile errors. To fix this, open libtool in a text editor...
sudo gedit libtool
...and use the text editor's Find command to search for...
This text should appear near the end of the file, at about line 7500. Directly under this line, add the following:
compile_command='gcc -std=gnu99 -g -O2 -I~/libftd2xx0.4.16 -Wall -Wstrict-prototypes -Wformat-security -Wextra -Wno-unused-parameter -Wbad-function-cast -Wcast-align -Wredundant-decls -o openocd main.o ./.libs/libopenocd.a ~/libftd2xx0.4.16/static_lib/libftd2xx.a.0.4.16 -ldl -lpthread'
This puts the libopenocd and libftd2xx libraries in the correct order. Important: If you copy the above text directly from this page, be sure to delete the newlines from the text, so that it all appears as one line in libtool. The file paths in the code above assume that you have followed this guide exactly, and extracted libftd2xx to your /home directory. If this is not the case, change the file paths above to match the location of your libftd2xx0.4.16 directory.
Compile OpenOCD as follows:
sudo make sudo make install
Preparing to Run OpenOCD
Navigate to ~/openocd/src to find the openocd binary. You will need superuser priveleges to run OpenOCD.
You can run openocd from ~/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 directory containing OpenOCD and its config files.
Create a new directory in /home/USERNAME called openocd-bin, and copy the openocd binary and the contents of /home/USERNAME/openocd/tcl to the new directory. You can do this from the terminal window with the collowing commands:
cd ~ mkdir openocd-bin cd ~/openocd/tcl cp -r * ~/openocd-bin cd ~/openocd/src cp openocd ~/openocd-bin
openocd-bin should now contain the following files and subdirectories:
board chip cpld cpu openocd interface target test bitsbytes.tcl mem_helper.tcl memory.tcl mmr_helpers.tcl