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 libtoolsudo apt-get install autoconfsudo apt-get install texinfosudo 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/samplesudo cp ftd2xx.h /usr/includesudo cp WinTypes.h /usr/includecd /usr/local/includesudo ln -s /usr/include/ftd2xx.h ftd2xx.hsudo 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.16sudo cp libftd2xx.so.0.4.16 /usr/local/libcd /usr/local/libsudo ln -s libftd2xx.so.0.4.16 libftd2xx.so.0sudo ln -s libftd2xx.so.0.4.16 libftd2xx.socd /usr/libsudo ln -s /usr/local/lib/libftd2xx.so.0.4.16 libftd2xx.so.0sudo 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.0patch -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.0sudo ./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 makesudo 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-bincd ~/openocd/tclcp -r * ~/openocd-bincd ~/openocd/srccp openocd ~/openocd-bin
openocd-bin should now contain the following files and subdirectories: