Running OpenOCD on Linux with the Beaglebone
OpenOCD provides a command line interface for interacting with embedded devices. To use OpenOCD you will need to run it from the command line. This guide includes basic information about using the Ubuntu command line interface, the terminal window. If you are already proficient with the command line, you can find information specific to OpenOCD under the Installing FTDI Drivers and Telnet Connection headings.
This guide was written for the Ubuntu 11.10 release. You may encounter differences on other Linux distributions. The instructions on this page use the Beaglebone as an example embedded chip target. The instructions are otherwise identical to those at Running OpenOCD on Linux, which provides examples for the TinCanTools Hammer.
If you're using the Optional JTAG Header on the BeagleBone, please see the following page:
The following guide assumes that you have followed the instructions in main OpenOCD page to install the application. You can choose to build OpenOCD from source or download a pre-built package. If you do not build from source, you may still need to download the board and platform specific scripts for the Beaglebone.
Opening the Command Prompt
Open the Applications menu from the menu bar on your desktop, and choose Accessories > Terminal. Ubuntu should open black window with white text and a prompt.
The command prompt displays your current directory location. You will need to navigate to the OpenOCD directory to run it. To change directories, type 'cd followed by a file path. File paths can be absolute...
cd /home cd /usr/local/lib
cd lib/mingw cd TinCanTools/openocd
Absolute paths are from your root directory, and begin with a slash. Relative paths are from the current directory and do not begin with a slash. File paths are case sensitive.
If you need to navigate to your home directory, type cd by itself like this...
If you need to go back to the parent of the current directory, you can type...
You can even use this as part of a longer relative path. For example...
...would take you up two levels, and then into a folder called TinCanTools.
To reach your root directory, you can type:
If you need to include your home directory in a path (home/USERNAME, replacing USERNAME with the name of your account), you can type it out as normal, or you can use the tilde key (~) as shorthand. For example:
cd /home/USERNAME/TinCanTools cd ~/TinCanTools
...both take you to the same place.
Installing FTDI Drivers
The Beaglebone is very nice since it provides its JTAG interface directly through the USB so you don't need an external JTAG board. The JTAG support is provided through the FTDI chipset on the Beaglebone. You need to ensure that you have the FTDI drivers installed in your Linux host system.
You can grab the drivers from FTDI's website (for the FTDI D2XX). http://www.ftdichip.com/Drivers/D2XX.htm
Read the README in the driver install package for background information on how to install it. You may neeed to install libusb also. To do this, type the following:
sudo apt-get install libusb
Once you've installed the drivers, you can run lsusb to check that the FTDI interface is working on your connected Beaglebone:
~$ lsusb Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 002 Device 002: ID 80ee:0021 VirtualBox USB Tablet Bus 001 Device 002: ID 0403:6010 Future Technology Devices International, Ltd FT2232C Dual USB-UART/FIFO IC
You should note the USB PID/VID of the FTDI interface is actually 0403:6010 (shown above). This can cause problems later. This is because there was a problem in newer board revisions (A5) that the FTDI chipset reported an incorrect PID/VID. You should copy down the information, since you will need it later.
Installing Beaglebone Scripts
You will need to download the source for OpenOCD to get the scripts. You can download the source to any directory that you want, since it will be temporary (unless you are building the source). The following example downloads the source to you current directory into a directory called openocd...
git clone git://openocd.git.sourceforge.net/gitroot/openocd/openocd openocd
Once the source is downloaded, you will need to copy the two script files necessary for the Beaglebone to your OpenOCD directories. This assumes you have installed OpenOCD to /usr/share/openocd/. In the following example, replace <Path to git clone openocd> with the path of the downloaded source...
> sudo cp <path to git clone openocd>/tcl/board/ti_beaglebone.cfg /usr/share/openocd/scripts/board
> sudo cp <path to git clone openocd>/tcl/target/am335x.cfg /usr/share/openocd/scripts/target
Editing the Beaglebone Script
You may need to edit the ti_beaglebone.cfg script file to corret the USB PID/VID issue mentioned above. Edit the file using a text editor such as gedit. (Remember, it should be run as root to have proper permissions)
> sudo gedit /usr/share/openocd/scripts/board/ti_beaglebone.cfg
You are looking for the following line in the cfg file:
ft2232_vid_pid 0x0403 0xa6d0
If the two hex values do not match the values you wrote when you ran lsusb mentioned in the previous section, you will need to edit it. For the A5 revision, I had to change this to...
ft2232_vid_pid 0x0403 0x6010
Once you save the file, you are ready to run OpenOCD. If you did not edit this file, when you ran the application it would complain that there are no available interfaces when the Beaglebone was connected.
Navigate to the directory containing your openocd executable. If you have just compiled OpenOCD according to the instructions on this wiki, the executable is located in openocd/src or openocd-0.4.0/src. In that directory, simply type...
To run the program. It won't do anything though, because you need the appropriate permissions and config files. To exit openocd, press CTRL + C.
OpenOCD and Permissions
OpenOCD needs administrator privileges to interact with your USB drivers. Even Linux users with administrator privileges do not typically log on with those privileges active. However, Linux provides commands to run another command as the root user. On Ubuntu, this command is sudo. To run a program as root, type sudo, then a space, then the name of the program. For example...
...runs OpenOCD as root, with full permission to access your USB drivers.
When you use the sudo command, Linux will prompt you for your password, not the root user's password. If you cannot use sudo, contact your system administrator. You can also configure Linux to allow OpenOCD to access specific hardware devices without sudo. See Accessing Devices without Sudo.
OpenOCD Config Files
Each time you use OpenOCD you will need to configure it by passing it paths to configuration files. In the OpenOCD 0.5.0 release, these files are found in openocd/scripts and its subdirectories. From the scripts directory, the configuration file for the Beaglebone is at board/ti_beaglebone.cfg. It can also be viewed on this wiki here: ti_beaglebone.cfg
When you start OpenOCD, you tell it to use the config files for your hardware with the -f switch, like this:
sudo openocd -f path_to/cfg_file [-f path_to/other_cfg_file]
For the Beaglebone, you would type:
sudo openocd -f board/ti_beaglebone.cfg
Be aware that config files may contain paths to other config files. For example ti_beagleboard.cfg, the config file for the Beagleboard, contains this line:
source [find target/am335x.cfg]
When you run OpenOCD with the ti_beaglebone.cfg file, OpenOCD searches from the current directory for target/am335x.cfg. If the current directory does not contain OpenOCD's target directory, it may not find the am335x.cfg file, or it may find a different am335x.cfg file elsewhere on your system. For more information, see OpenOCD Config File Paths.
OpenOCD runs as a daemon. It accepts connections from other programs, but does not provide any means for you to give it commands directly. Once OpenOCD is running on your computer you will need to connect to it through another program, such as telnet.
To run telnet and connect to OpenOCD, open a new command prompt. From any directory, type:
telnet localhost 4444
You may need to run telnet as root:
sudo telnet localhost 4444
You should see a simple prompt (>). From this prompt you will be able to send commands to OpenOCD. To exit the telnet prompt, press CTRL + C.
JTAG Sticky Errors
As of revision 0.5.0 of OpenOCD, there is a bug that causes a number of errors to be shown when running OpenOCD. This will not cause any problems unless you have disconnected and reconnected the Beaglebone. You can read more about this issue at OpenOCD Troubleshooting