Compiling OpenOCD Linux for Flyswatter2
This guide will compile OpenOCD for Ubuntu 10.04 using the libFTDI driver library, for use with the TinCanTools Flyswatter2. Unlike the Compiling OpenOCD Linux guide, these instructions use the most recent version of OpenOCD from the git repository to take advantage of adaptive clocking support not available in the OpenOCD 0.4.0 stable release.
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 git-core libtool autoconf texinfo libusb-dev
If you prefer to compile libusb yourself, you can find the source at http://sourceforge.net/projects/libusb/files/libusb-1.0/.
Downloading and Compiling libFTDI
libFTDI is an open source FTDI driver you will need to compile OpenOCD. Download libftdi-0.18 from http://www.intra2net.com/en/developer/libftdi/download.php, and extract it to your home directory, (/home/USERNAME, replacing USERNAME with your username.
Navigate to home/USERNAME/libftdi-0.19/src, and copy ftdi.h to your /usr/include directory. Then create a symbolic link to ftdi.h in /usr/local/include. In the terminal window:
cd ~/libftdi-0.18/src sudo cp ftdi.h /usr/include cd /usr/local/include sudo ln -s /usr/include/ftdi.h ftdi.h
Return to your libftdi-0.18 directory and compile.
cd ~/libftdi-0.18 ./configure make sudo make install
This will install the necessary library files to /usr/local/lib. Navigate to /usr/lib and create symbolic links to the new files.
cd /usr/lib sudo ln -s /usr/local/lib/libftdi.a libftdi.a sudo ln -s /usr/local/lib/libftdi.la libftdi.la sudo ln -s /usr/local/lib/libftdi.so.1.18.0 libftdi.so.1.18.0 sudo ln -s /usr/local/lib/libftdi.so.1.18.0 libftdi.so sudo ln -s /usr/local/lib/libftdi.so.1.18.0 libftdi.so.1
In the terminal window, navigate back to /home/USERNAME and download the most recent OpenOCD source using git.
cd ~ sudo git clone git://openocd.git.sourceforge.net/gitroot/openocd/openocd
This will create a directory called openocd containing the OpenOCD source. Change the permissions on this folder and all of its contents to allow non-administrators to read, write, and execute:
sudo chmod -R 777 openocd
Download media:Openocd-flyswatter2.patch. (Right click on the link and select "Save Link As.") This patch will modify the OpenOCD source for Flyswatter2 support and create a flyswatter2.cfg file in the openocd/tcl/interface directory. Copy the patch to your /home/USERNAME/openocd directory.
In the terminal window, navigate to /home/USERNAME/openocd and apply the patch:
cd ~/openocd patch -p1 < ./Openocd-flyswatter2.patch
The output in the terminal window should show changes to the file ft2232.c and a new file called flyswatter2.cfg.
You are finally ready to compile OpenOCD. Still in the /home/USERNAME/openocd directory, run the following commands:
sudo ./bootstrap sudo ./configure --enable-maintainer-mode --disable-werror --enable-ft2232_libftdi sudo make sudo make install
Preparing to Run OpenOCD
Navigate to /home/USERNAME/openocd/src to find the openocd binary. You will need superuser priveleges to run OpenOCD.
You can run openocd from /home/USERNAME/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
You can now run OpenOCD from /home/USERNAME/openocd-bin. To get started running OpenOCD, see Running OpenOCD on Linux. A user will need the root password to run OpenOCD (with the sudo command). You can allow a user to run OpenOCD without sudo for specific hardware by creating a udev rule.
If you encounter problems with OpenOCD communicating with your hardware, you can verify that Ubuntu "sees" your hardware with the lsusb command.