« OpenStreetMapping with a FreeRunner | Home | KMS Running on Openmoko »

June 30, 2009

GDB + Debug Board

In addition to the information on the wiki, here are my instructions for getting GDB to work with an OpenMoko debug board for the purposes of debugging the kernel.

Debugging requires three things: libftdi (the library which facilitates access to the JTAG chip used in the debug board), OpenOCD (which turns GDB-speak into JTAG-speak) and a GDB which understands ARM-speak.

First, download gdb-6.8.tar.bz2 from the GDB homepage.  That's the latest stable version at the time of writing.  Later versions, if and when available, should also work.  Configure GDB to target an ARM processor running a Linux kernel and using the GNU EABI, and get it compiling:

$ ./configure --disable-werror --target=arm-linux-gnueabi
$ make

While that's cooking, get libftdi and libftdi-devel from your distro repositories.  Version 0.8 or later is required.  Version 0.13, as found in Ubuntu Jaunty (9.04) works fine.  Failing that, get the source code and build it yourself.  Having installed that, get OpenOCD from the SVN repository and compile it.  Revision 130 is known to work.  The syntax of the configuration file has been changed in later versions - the wiki has some information about how to use the new format as well.  You must tell OpenOCD that you want to enable ft2232 via libftdi:

$ svn checkout -r130 svn://svn.berlios.de/openocd/trunk openocd
$ ./bootstrap
$ ./configure --enable-ft2232_libftdi
$ make
$ sudo make install

By the time you've done that, GDB has hopefully finished compiling.  Install it in the usual way - the name of the executable will be prefixed with the host triplet, i.e. it will be called "arm-linux-gnueabi-gdb", so you don't need to worry about overwriting your "conventional" GDB version already installed:

$ sudo make install

You're all set for some debugging action.  To run GDB, first connect the debug board to the phone using the FPC cable (otherwise known as the Flimsy Plastic Cable - take care with it), connect the debug board to a USB socket on your computer, start the phone then start OpenOCD.  If you got your permissions right, you won't have to run it as root:

$ sudo openocd

If you don't get error messages from OpenOCD, it's working.  Note that the debug board must be powered up and the phone switched on before OpenOCD can be started.  If you're debugging things which happen soon after startup, you just have to get quick at doing this and the next step.

Now start GDB, giving it the path to the "vmlinux" file which corresponds to your running uImage:

$ gdb GTA02_drm-kms/vmlinux

Tell GDB to connect to OpenOCD with

(gdb) target remote localhost:3333

and you should see GDB halt the processor at a particular point, with it telling you where that is.

Note that you can do all of this whilst watching the serial console with a terminal emulator such as GtkTerm.

Leave a comment