Windows GDB Debugger

From TinCanTools
Jump to: navigation, search

GDB, the GNU Project Debugger is a debugging tool provided with the GNU Compiler Collection (GCC). GDB allows you to stop and start a running program, examine its functioning, and make changes.

GDB Support in OpenOCD

The configure script provided with OpenOCD 0.5.0 already compiles OpenOCD to support the GDB debugger. If you have installed OpenOCD according to the guides on the Compiling OpenOCD page, your version of OpenOCD already supports GDB.

The -g flag tells the gcc compiler to build with GDB support. OpenOCD's configure script already includes the -g flag.

You will need to download or compile a version of GDB that supports embedded devices. One such GDB build is provided with the CodeSourcery ARM toolchain.

Installing the CodeSourcery ARM Toolchain

CodeSourcery provides development tools for use with embedded devices, including a GCC cross-compiler and a GDB build for ARM targets. Download the latest version of the .bin installer from http://www.codesourcery.com/sgpp/lite/arm/portal/release1592. Direct link to the Windows installer is here.

Download and run the installer. You should see a loading bar followed by an installer GUI. The installer is fairly straightforward. This guide will assume that you choose the default option on each page.

Sourcery-install win.png

The installer installs the CodeSourcery toolchain, by default to C:\Program Files\CodeSourcery\Sourcery G++ Lite (or C:\Program Files (x86)\CodeSourcery\Sourcery G++ Lite on 64-bit Windows). It also adds this path to your system PATH variable so you can run arm-none-eabi-gdb and other tools from any directory.

Starting GDB

In the windows command console, type arm-none-eabi-gdb and press Enter. You can do this from any directory. If you're unsure how to open the Windows command console, see Running OpenOCD on Windows. You can also run GDB directly from "Run" in the Start menu.

arm-none-eabi-gdb

Either way you should look like the image below, with a prompt reading (gdb) in place of the normal > command prompt.

Eabi-gdb startup win.png

Connecting to OpenOCD

Run OpenOCD as normal, as described in Running OpenOCD on Windows. To connect to OpenOCD, start GDB as above:

arm-none-eabi-gdb

OpenOCD listens for GDB connections on port 3333. In GDB, connect to OpenOCD by typing target remote localhost:3333. (In this guide if you see (gdb) at the beginning of a command, that means enter that line into the GDB command prompt. Don't actually type the characters (gdb).)

(gdb) target remote localhost:3333

Before doing anything else, run reset init on the target. Use the monitor command to tell GDB to send the command to OpenOCD, like this:

(gdb) monitor reset init

Monitor reset init win.png

This is important. You need to do this while GDB is connected to the OpenOCD, or you won't be able to halt or reset the target. If you don't run monitor reset init, you will encounter errors like this:

Gdb packet err win.png

Sending Commands to OpenOCD

You can send commands to OpenOCD through GDB just like you can through a telnet connection. Type monitor, then the command, then enter. You can see a list of common OpenOCD commands here.

Gdb openocd commands win.png

You can use the Linux command cd to change the current working directory in GDB. This changes the current directory only for GDB, not for Linux; when you exit GDB, you will be back in the directory where you started.

To quit GDB, type quit.

.gdbinit

Instead of typing commands yourself every time you start GDB, you can create a script to always start GDB with the same series of commands. This script file is named .gdbinit. GDB looks for it in the current working directory.

You can use the script below to have GDB automatically connect to OpenOCD and run reset init on the target. Create a new folder on your C:\ drive called GDB_OpenOCD_init, and create a new text file in that folder. Copy the code below into the file:

echo Executing GDB with .gdbinit to connect to OpenOCD.\n
# Connect to OpenOCD
target remote localhost:3333
# Reset the target and call its init script
monitor reset init
# Halt the target. The init script should halt the target, but just in case
monitor halt

Save the file as .gdbinit and close it. Note that in Windows Explorer you can't give a file a name that begins with a period. You will need to save it with the name .gdbinit from within a text editor. Alternatively, name the file gdbinit without a period and then rename it from the command line:

cd C:\GDB_OpenOCD_init
move gdbinit .gdbinit

To test the init script, start OpenOCD as normal. Then in the command line, navigate to C:\GDB_OpenOCD_init and run CodeSourcery GDB.

cd C:\GDB_OpenOCD_init
arm-none-eabi-gdb

You should see something like the image below. (In this image the target device is the Beagleboard. With different hardware the output of reset init will be different.)

Gdbinit win.png

External Links

GDB man page

UNDERCONSTRUCTION Compiling OpenOCD Linux D2XX

From TinCanTools
Jump to: navigation, search

This guide will compile OpenOCD 0.5.0 for Ubuntu 10.04 with the FTD2XX driver library, for use with the TinCanTools Flyswatter.

Installing Packages

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/.

Installing libFTD2XX

Download version 1.0.4 of the D2XX Linux drivers from http://www.ftdichip.com. Direct link is here: http://www.ftdichip.com/Drivers/D2XX/Linux/libftd2xx1.0.4.tar.gz. Extract the contents to your home directory (/home/USERNAME, replacing USERNAME with your username.)

In the terminal window, navigate to ~/libftd2xx1.0.4 and copy the files ftd2xx.h and WinTypes.h to /usr/local/include. Then navigate to /usr/include and create symbolic links to the header files.

cd ~/libftd2xx1.0.4
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 ~/libftd2xx1.0.4 directory and copy the library file to /usr/local/lib. The libftd2xx directory contains both 32-bit and 64-bit library files. If in doubt, use the 32-bit library file. To install the 32-bit library, copy the file located in /build/i386:

cd ~/libftd2xx1.0.4/build/i386
sudo cp libftd2xx.so.1.0.4 /usr/local/lib

To install the 64-bit libraries, instead copy the file in /build/x86_64:

cd ~/libftd2xx/build/x86_64
sudo cp libftd2xx.so.1.0.4 /usr/local/lib

Regardless of which you install, create symbolic links to the file in /usr/lib and /usr/local/lib. Name the links libftd2xx.so.

cd /usr/local/lib
sudo ln -s libftd2xx.so.1.0.4 libftd2xx.so
cd /usr/lib
sudo ln -s /usr/local/lib/libftd2xx.so.1.0.4 libftd2xx.so

Downloading OpenOCD

Download the OpenOCD 0.5.0 source from http://prdownload.berlios.de/openocd/openocd-0.5.0.tar.gz and extract openocd-0.5.0 to your home directory (/home/USERNAME/openocd-0.5.0).

Patching OpenOCD

The OpenOCD Flyswatter 3 beta patch provides support for the Flyswatter3 and Flyswatter2 and updated config files for the original Flyswatter, the TinCanTools Hammer, and the Olimex PIC-P32MX board. Download the file Media:Tincantools-openocd-b0.12.patch. (Right click the link and select Save As.) Save the file to your new openocd-0.5.0 directory.

In the terminal window, navigate to the patch file and patch the source as follows:

cd ~/openocd-0.5.0
patch -p1 -i Tincantools-openocd-b0.12.patch

Even if you do not need Flyswatter3 or Flyswatter2 support, you will need the updated config files in this patch to use the Flyswatter with OpenOCD-0.5.0. If you do not wish to install the patch you can download the config files individually from OpenOCD Config Files.

Compiling OpenOCD

In the terminal window, navigate to the new folder containing the OpenOCD source and compile as follows.

cd ~/openocd-0.5.0
sudo ./configure --disable-werror --enable-ft2232_ftd2xx --with-ftd2xx-linux-tardir="../libftd2xx1.0.4"
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.5.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-0.5.0/tcl
cp -r * ~/openocd-bin
cd ~/openocd-0.5.0/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.

Troubleshooting: Device Not Found (Linux)

From TinCanTools
Jump to: navigation, search

On startup you see an error message indicating that OpenOCD cannot find the device. If your build of OpenOCD uses the libftdi driver library, the error message reads:

Error: unable to open ftdi device: device not found

Device Not Found error with libftdi

Follow these instructions to diagnose the problem.

Step 1: Make Sure the Device is Connected

Unplug your device, plug it back in, and check the all connections to make sure they are secure. Many devices also have LEDs to indicate that they are receiving power. The Flyswatter2 and Hammer all have red LEDs to indicate that they are powered. If you do not see a red light come on when you plug in the device, it isn't receiving power.

The Flyswatter and Flyswatter2 also have green LEDs to indicate active USB connections. If you do not see a green light on your Flyswatter, then the device does not have an active USB connection.

Step 2: Check your Driver Messages

Open a terminal window (Applications menu > Accessories > Terminal) and type:

dmesg

You will see a list of messages describing driver activity on your system. Look for a message indicating that Ubuntu has detected your device. If you have installed the D2XX drivers you should see something like the image to the right. (Even if you intend to run an OpenOCD build compiled with libftdi, seeing the D2XX drivers does not indicate that OpenOCD will fail.)

dmesg Shows a Connected FTDI Device

If do not see a message indicating that Ubuntu has detected a USB device with an FT2232 interface, or if the message is followed by another message indicating that the device has been disconnected, then Ubuntu does not currently recognize that the device is plugged in.

dmesg Shows a Disconnected FTDI Device

The dmesg command prints lots and lots of messages, often more than you can search through by hand. You can filter the output for messages related to your USB drivers by piping it to grep, like this:

dmesg | grep -i usb

Step 3: List USB Devices

Use lsusb to get information about your hardware. A guide to using lsusb is provided here. Follow the steps shown on the Lsusb page. If you encounter any problems, your hardware may be faulty or there may be a problem with your drivers.

Troubleshooting: Can’t Find File.cfg

From TinCanTools
Jump to: navigation, search

You attempt to run OpenOCD and it exits immediately with a warning:

Can't find [file].cfg

OpenOCD has failed to find one or more config files. This guide will help you diagnose and correct the problem.

Can't Find openocd.cfg

If you see this message, you have likely run OpenOCD with no command line arguments. OpenOCD requires at least one config file to tell it how to communicate with your hardware. If you don't specify any, it searches for openocd.cfg. However, OpenOCD doesn't provide openocd.cfg by default. Even if it did, it wouldn't do any good because it wouldn't be tailored to any particular hardware.

Find the config files with your hardware. If you have compiled OpenOCD from source, they are most likely located in your OpenOCD directory, at tcl/interface, tcl/board, or tcl/target. Run OpenOCD again, using the -f switch to specify the path to each config file. For example:

openocd -f interface/flyswatter2.cfg -f board/hammer.cfg

If you know how to write your own config files you can also write your own openocd.cfg and place it in the same directory as the OpenOCD binary, but this is not necessary. See the links at the bottom of this page for more information on config files.

Can't Find a File Specified with -f

You run OpenOCD with the -f switch and OpenOCD can't find the file. For example, suppose you ran OpenOCD as above and saw the following error:

Can't find board/hammer.cfg

Make sure the config file exists and the path you specified is correct. If the file is present on your computer, make sure OpenOCD can find it from one of its default search paths. See OpenOCD Config File Paths for information on how OpenOCD finds config files.

Can't Find Another Config File

OpenOCD prints a runtime error stating that it can't open a config file you didn't specify with -f. For example, suppose you ran OpenOCD as follows:

openocd -f interface/flyswatter2.cfg -f board/hammer.cfg

…and saw this error:

Runtime Error: embedded:startup.tcl:58: Can't find target/samsung_s3c2410.cfg

So why was OpenOCD looking for samsung_s3c2410.cfg? The hammer.cfg file contains the line:

source [find target/samsung_s3c2410.cfg]

…to load the config file for the Hammer's CPU. When OpenOCD parses hammer.cfg it also searches for target/samsung_s3c2410.cfg, just as if you had specified it with the -f switch.

If OpenOCD fails to find a file specified in another config file, make sure the file path is valid for OpenOCD's search paths. You may need to specify an additional search path with the -s switch. See OpenOCD Config File Paths for more information on search paths and the -s switch.

More Information

Running OpenOCD on Windows

Running OpenOCD on Linux

OpenOCD Config File Paths

TemplateTest

From TinCanTools
Jump to: navigation, search

This guide will compile OpenOCD {{{3}}} on Windows 7 with the FTD2XX driver library, for use with the TinCanTools Flyswatter. The executable created with this guide is compatible with Windows XP and Windows 7. The process is identical on 32 and 64 bit versions of Windows.

This guide makes use of the GCC cross-compiler added to Cygwin on June 2, 2011. The cross-compiler makes compiling OpenOCD for Windows much easier. Older instructions can be found at Compiling OpenOCD for Windows 7 (FTD2XX) – Pre June 2011.

Configuring Windows 7

OpenOCD uses a command line interface and accepts commands from a telnet client. To compile and use OpenOCD in Windows 7 you will need to enable the 'Run' command and telnet client. See Configuring Windows 7 for OpenOCD.

Installing Cygwin

Download and install Cygwin 1.7.9 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

If you already have Cygwin installed, this guide recommends that you delete it and reinstall completely. Close all Cygwin windows and services and delete your Cygwin directory (by default, C:\cygwin). Then find any packages downloaded but not installed and delete them as well. You set the location of these files when you installed Cygwin. By default they appear in My Documents/Downloads. If you don't wish to reinstall Cygwin you can find more information at http://cygwin.com/ml/cygwin/2011-06/msg00021.html.

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 (all packages)
  • automake (all packages)
  • binutils
  • gcc
  • gcc-core
  • gcc-g++
  • git
  • libtool
  • libusb-1.0
  • libusb-win32
  • libusb-devel
  • make
  • mingw-binutils
  • mingw-gcc
  • mingw-gcc-core
  • mingw-gcc-g++
  • mingw-pthreads
  • mingw-runtime
  • patch (found under the Utils heading)

Check all of these packages and click Next. Cygwin will inform you that it must install additional packages to satisfy the above packages' dependencies. Allow it to do so. Make sure that the Select Required Packages checkbox is checked before you proceed.

Installing libusb for the Flyswatter

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.4.0\lib\gcc. Copy the file libusb.a to C:\cygwin\lib and C:\cygwin\usr\i686-pc-mingw32\sys-root\mingw\lib.

Navigate to \libusb-win32-bin-1.2.4.0\include. Copy the file usb.h to C:\cygwin\usr\include and C:\cygwin\usr\i686-pc-mingw32\sys-root\mingw\include.

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\i686-pc-mingw32\sys-root\mingw\include.

Installing FTD2XX

Navigate to C:\cygwin\home\ftd2xx\i386 and find the file ftd2xx.lib. Copy it, rename the copy ftd2xx.a and copy the new file to C:\cygwin\usr\local\lib and C:\cygwin\usr\i686-pc-mingw32\sys-root\mingw\lib.

Plug the Flyswatter into your computer's USB port. Install FTD2XX as follows:

  • Open the Control Panel.
  • If the View By dropdown menu in the upper right shows Category, change it to Large Icons or Small Icons.
  • Click System.
  • Click Device Manager on the left.
  • Find the Flyswatter devices. There should be two of them.
  • Right click the first Flyswatter device and select Update Driver Software.
  • Choose Browse my computer for driver software.
  • Click Browse.
  • Navigate to C:/cygwin/home/ftd2xx.
  • Click OK. The panel should now look like the screenshot to the right.
  • Click Next and wait for the install to complete.
  • Repeat the process for the other Flyswatter device.

{{MAKEERRORNOTE_{{{3}}}}}

Downloading OpenOCD

Download the OpenOCD {{{3}}} source from http://prdownload.berlios.de/openocd/openocd-{{{3}}}.zip and extract it to /home/openocd-{{{3}}}.

{{FS3PATCH_{{{3}}}|WIN7|/home/openocd-{{{3}}}}}

Compiling OpenOCD

In the Cygwin command window, navigate to the new folder containing the OpenOCD source and compile as follows.

cd /home/openocd-{{{3}}}
./configure --disable-werror --enable-ft2232_ftd2xx 
             --with-ftd2xx-win32-zipdir=../ftd2xx  --build=i686-pc-cygwin --host=i686-pc-mingw32
make

Preparing to Run OpenOCD

Navigate to C:\cygwin\home\openocd\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\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-bin.

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

Now go to C:\cygwin\home\openocd\src and copy openocd.exe to C:\openocd-bin. 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-bin. To get started running OpenOCD, see Running OpenOCD on Windows.

Running OpenOCD on Linux with the Beagleboard

From TinCanTools
Jump to: navigation, search

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 OpenOCD Config Files and Telnet Connection headings.

This guide was written for the Ubuntu 10.04 LTS release. You may encounter differences on other Linux distributions. The instructions on this page use the Beagleboard 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.

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.

Command Prompt Basics – Paths and Navigation

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

…or relative…

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…

cd

If you need to go back to the parent of the current directory, you can type…

cd ..

You can even use this as part of a longer relative path. For example…

cd ../../TinCanTools

…would take you up two levels, and then into a folder called TinCanTools.

To reach your root directory, you can type:

cd /

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.

Running OpenOCD

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…

openocd

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…

openocd

…runs OpenOCD with your user permissions, and likely prevents OpenOCD from interacting with libUSB. However…

sudo openocd

…runs OpenOCD as root, with full permission to access your USB drivers.

When you use the sudo command, Linux will prompt you for the root user's password. If you do not have access to this password, 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.4.0 release, these files are found in openocd-0.4.0/tcl and its subdirectories. From the tcl directory, the configuration file for the Flyswatter is at interface/flyswatter.cfg. The file for the Beagleboard is at board/ti_beagleboard.cfg. If your copy of OpenOCD includes support for the Flyswatter2, its config file is at interface/flyswatter2.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 example, suppose you want to run OpenOCD for the Flyswatter and the Beagleboard. The current directory contains the OpenOCD executable and the board, interface, and target directories provided with the OpenOCD source. You would type:

sudo openocd -f interface/flyswatter.cfg -f board/ti_beagleboard.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/omap3530.cfg]

When you run OpenOCD with the ti_beagleboard.cfg file, OpenOCD searches from the current directory for target/omap3530.cfg. If the current directory does not contain OpenOCD's target directory, it may not find the omap3530.cfg file, or it may find a different omap3530.cfg file elsewhere on your system. For more information, see OpenOCD Config File Paths.

If you have compiled OpenOCD yourself, the easiest way to avoid these issues is to copy the openocd binary from your openocd-0.4.0/src directory to your openocd-0.4.0/tcl directory. To run OpenOCD, navigate to openocd-0.4.0/tcl in the command terminal and run OpenOCD as above. You can also create a new directory anywhere on your system, and copy the openocd binary and the contents of openocd-0.4.0/tcl to the new directory.

Telnet Connection

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.

Running OpenOCD

From TinCanTools
Jump to: navigation, search

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 your operating system's command line interface. Unless otherwise noted, commands are identical in Linux and in Windows. If you are already proficient with the command line, you can find information specific to OpenOCD under the OpenOCD Config Files and Telnet Connection headings.

Opening the Command Prompt

In Ubuntu, open the Applications menu from the menu bar on your desktop, and choose Accessories > Terminal.

In Windows, open the Start Menu and click on Run… A small dialog box will appear. Type:

cmd

…and click OK. In Windows 7/Vista, the Run command does not appear in the Start Menu by default. To enable it, see Configuring Windows 7 for OpenOCD.

Command Prompt Basics – Paths and Navigation

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 /usr/local/lib
cd \Program Files\TinCanTools
cd C:

…or relative…

cd Program Files
cd TinCanTools
cd lib/mingw

Absolute paths are from your root directory, and begin with a slash (or the current drive letter, on Windows). Relative paths are from the current directory and do not begin with a slash. On Windows, absolute paths use forward slashes (\) and relative paths use backslashes (/). On Linux, absolute and relative paths both use backslashes.

If you need to move to a new drive, type the drive letter followed by a colon…

E:

If you need to go back to the parent of the current directory, you can type…

cd ..

You can even use this as part of a longer relative path. For example…

cd ../../TinCanTools

…would take you up two levels, and then into a folder called TinCanTools.

Running OpenOCD

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…

openocd

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. On Windows, you will need to be logged onto an account with administrator privileges. If you do not have access to such an account, contact your system administrator.

On Ubuntu, even 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…

openocd

…runs OpenOCD with your user permissions, and likely prevents OpenOCD from interacting with libUSB. However…

sudo openocd

…runs OpenOCD as root, with full permission to access your USB drivers.

When you use the sudo command, Linux will prompt you for the root user's password. If you do not have access to this password, contact your system administrator.

OpenOCD Config Files

OpenOCD uses files with the .cfg extension to communicate with embedded devices. In the OpenOCD 0.4.0 release, these files are found in openocd-0.4.0/tcl and its subdirectories. From the tcl directory, the configuration file for the Flyswatter is at interface/flyswatter.cfg. The file for the TinCanTools Hammer is at board/hammer.cfg. If your copy of OpenOCD includes support for the Flyswatter2, its config file is at interface/flyswatter2.cfg.

When you start OpenOCD, you tell it to use the config files for your hardware with the -f switch, like this:

openocd -f path_to/cfg_file [-f path_to/other_cfg_file]

For example, suppose you want to run OpenOCD for the Flyswatter2 and the Hammer. The current directory contains the OpenOCD executable and the tcl directory. You would type:

openocd -f tcl/interface/flyswatter2.cfg -f tcl/board/hammer.cfg

On Ubuntu, remember to use the sudo command to run OpenOCD as root:

sudo openocd -f tcl/interface/flyswatter2.cfg -f tcl/board/hammer.cfg

Telnet Connection

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.

Ubuntu and Windows XP provide a telnet client by default. To use telnet in Windows 7/Vista you will need to enable it manually. The Configuring Windows 7 for OpenOCD page will show you how to enable the telnet client.

To run telnet and connect to OpenOCD, open a new command prompt. From any directory, type:

telnet localhost 4444

On Linux, 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.

OpenOCD Troubleshooting: JTAG TAP SCRATCH

From TinCanTools
Jump to: navigation, search

You start OpenOCD with the Flyswatter or Flyswatter2 and the Beagleboard and see an error like this:

beagle ocdstartup jtagfailed.png

Info : JTAG tap: omap3530.jrc tap/device found: 0x000000ff (mfg: 0x07f, part: 0x0000, ver: 0x0)
Warn : JTAG tap: omap3530.jrc       UNEXPECTED: 0x000000ff (mfg: 0x07f, part: 0x0000, ver: 0x0)
Error: JTAG tap: omap3530.jrc  expected 1 of 1: 0x0b7ae02f (mfg: 0x017, part: 0xb7ae, ver: 0x0)

OpenOCD has read the board's CPU tap ID as 0x000000ff. This value means OpenOCD has failed to read the tap ID correctly. This guide will walk you through troubleshooting the issue.

Solution 1: Restart with -c "init" -c "reset init"

An issue with OpenOCD and the Beagleboard sometimes prevents OpenOCD from initializing the JTAG chain correctly. As described in the Flyswatter How To, you can prevent the issue by running the init and reset init commands on OpenOCD startup.

  • Unplug the USB cable from the Flyswatter or Flyswatter2.
  • Unplug the power cable from the Beagleboard.
  • Plug both devices back in.
  • Start OpenOCD as follows:

(with the Flyswatter2)

openocd -f interface/flyswatter2.cfg -f board/ti_beagleboard.cfg -c "init" -c "reset init"

(with the Flyswatter)

openocd -f interface/flyswatter.cfg -f board/ti_beagleboard.cfg -c "init" -c "reset init"

If using Ubuntu, use the sudo command as normal.

 sudo openocd -f interface/flyswatter2.cfg -f board/ti_beagleboard.cfg -c "init" -c "reset init"

Solution 2: Check the JTAG Cable Connections

OpenOCD won't be able to read the Beagleboard's CPU tap ID if the JTAG ribbon cable is connected incorrectly. Make sure the cable is secured at both ends and aligned correctly on the pins.

Make sure the JTAG cable isn't connected backwards. The pin numbers are marked on the Beagleboard in small print around the JTAG header. On the ribbon cable included with the Beagleboard Adapter Kit, Pin 1 is marked with a red stripe. Make sure it aligns with Pin 1 on the board.

Beagle jtag wrong.png Beagle jtag wrong2.png Beagle jtag correct.png

Solution 3: Disable Adaptive Clocking

OpenOCD sometimes has issues initializing the Beagleboard's JTAG with adaptive clocking enabled. Adaptive clocking is enabled in the config file omap3530.cfg, called from ti_beagleboard.cfg. You will need to run OpenOCD with a modified config file that doesn't enable adaptive clocking.

Download omap3530_norclk.cfg
Right-click the link and select "Save As"

  • Download the file above to OpenOCD's /target folder:
  • Unplug the USB cable from the Flyswatter or Flyswatter2.
  • Unplug the power cable from the Beagleboard.
  • Plug both devices back in.
  • Start OpenOCD as follows:

(with the Flyswatter2)

openocd -f interface/flyswatter2.cfg -f target/omap3530_norclk.cfg -c "init" -c "reset init"

(with the Flyswatter)

openocd -f interface/flyswatter.cfg -f target/omap3530_norclk.cfg -c "init" -c "reset init"

If using Ubuntu, use the sudo command as normal.

 sudo openocd -f interface/flyswatter2.cfg -f target/omap3530_norclk.cfg -c "init" -c "reset init"

After OpenOCD starts successfully the first time you may be able to start it again as normal. Unplug the Flyswatter/Flyswatter2 and the Beagleboard and restart as in Solution 1. If you need to resort to disabling adaptive clocking again, you can still enable adaptive clocking manually once OpenOCD starts. Connect to OpenOCD via telnet or GDB as normal and enter the following command:

jtag_rclk 1000