How to debug linux application on beagle board using single com port 
------------------------------------------------------------- 

1. Install the compiler for arm linux 
===================================== 
ARM Linux GCC - codesourcery tool chain (Select GNU/Linux and download 
version 2007q3) 
download from: http://www.codesourcery.com/gnu_toolchains/arm/portal/release313 
297209683 Aug 11 11:08 arm-2007q3.tar.bz2 
and install 
so you could compile using the arm compiler using the command line: 
"arm-none-linux-gnueabi-gcc" 
(complete info at: http://code.google.com/p/beagleboard/wiki/BeagleSoftCompile

2. u-boot 
========= 

You need u-boot to be automated, for that recompile the u-boot after 
doing the following changes in 
the file ./include/configs/omap3530beagle.h 

        #define CONFIG_BOOTCOMMAND "mmcinit;fatload mmc 0 0x80300000 
uImage;fatload mmc 0 0x81600000 rd-ext2.bin;bootm 0x80300000;\0" 

        #define CONFIG_BOOTARGS "setenv bootargs console=ttyS1,115200n8 
ramdisk_size=8192 root=/dev/ram0 rw rootfstype=ext2 
initrd=0x81600000,8M nohz=off" 

and from /board/omap3530beagle/omap3530beagle.c 
comment the following two lines at the end of the function 
misc_init_r() 
        //      dss_init(); 
        //      audio_init(); 

Compile the u-boot to generate the u-boot.bin file 
        make CROSS_COMPILE=arm-none-linux-gnueabi- distclean 
        make CROSS_COMPILE=arm-none-linux-gnueabi- omap3530beagle_config 
        make CROSS_COMPILE=arm-none-linux-gnueabi- 

more info at: 
http://code.google.com/p/beagleboard/wiki/BeagleSoftCompile 

3. MLO 
====== 
MMC is the first step of the MMC based bootloader 
I did not bother to compile it, just downloaded it from: 
http://code.google.com/p/beagleboard/wiki/BeagleSourceCode (and rename 
MLO_revb to MLO) 

4. Kernel 
========= 
Download kernel from same place as above: Linux Kernel 2.6.22.18 
and compile it using: 
        make CROSS_COMPILE=arm-none-linux-gnueabi- distclean 
        make CROSS_COMPILE=arm-none-linux-gnueabi- omap3_beagle_defconfig 
        make CROSS_COMPILE=arm-none-linux-gnueabi- uImage 
or just use the compiled one from: 
http://code.google.com/p/beagleboard/wiki/BeagleSourceCode  (don't 
forget to rename it, if needed, to: uImage) 

5. The RAM files system (busybox) 
================================= 

download BusyBox (ramdisk) File System from the same place as above. 
filename: rd-ext2-8M.bin and rename it to rd-ext2.bin 

Changing the ramdisk to have it autostart the gdbserver: 
        cat rd-ext2-8M.bin | gunzip > myimagem 
        mkdir /mnt/tmp 
        mount myimage /mnt/tmp -t ext2 -o loop=/dev/loop3 

Now the full image is under /mnt/tmp, do the following changes there: 
change inside /mnt/tmp/etc/inittab 
from: 
        ::askfirst:-/bin/sh 
to: 
        ::respawn:-/bin/sh 
this is to avoid asking for the prompt "press..." on boot 

and at the end of the file /mnt/tmp/etc/profile add: 
        mount -t vfat /dev/mmcblk0p1 /mnt/mmc/ 
        cd /mnt/mmc 
        ./ycomarm /dev/ttyS2 
        ./gdbserver /dev/ttyS2 hello2 
This is to mount the mmc, and run gdbserver and have it ready to debug 
the hello2.c program 

Now pack the image back, and create a new rd-ext2.bin file 
        umount myimage  (before doing that, do cd to a different location) 
        cp myimage qqq 
        gzip qqq 
        rm rd-ext2.bin 
        mv qqq.gz rd-ext2.bin 

6. compiling the gdbserver and gdb for arm 
========================================== 

download the latest gdb-6.7.1.tar 
wget -c ftp://ftp.gnu.org/gnu/gdb/gdb-6.7.1.tar.bz2 

Place the downloaded file in /usr/src directory of your system. 
Under /usr/src, create a debug directory and extract the gdb package 
in this 
(/usr/src/debug) directory. 

[root at localhost]# cd /usr/src/debug 
[root at localhost]# tar jxf ../gdb-6.7.1.tar.bz2 

Build gdb debugger 

The debugger must be built into directories separate from the source. 
Thus, 
create a directory for gdb within the /usr/src/debug directory. 

[root at localhost]# mkdir /usr/src/debug/build_gdb 

Chose the prefix for the new debugger. This is a directory where the 
binary 
and other debugger files resides. This application report uses /opt/ 
gdebug 
for the new debugger. The directory is created by the installation of 
the 
tools. Go to the /usr/src/debug/gdb-6.3 directory to configure and 
then 
build the binary and other debugger files with the commands shown 
below. 

[root at localhost]# cd /usr/src/debug/build_gdb 
[root at localhost]# ../gdb-6.7.1/configure --target=arm-linux -- 
prefix=/opt/gdebug 
[root at localhost]# make 
[root at localhost]# make install 

The binary generated resides in /opt/gdebug and is fairly large. This 
is why 
the gdb binary can't be used as-is on the target and the gdbserver is 
used 
instead. 

Build gdb server 

The gdb server wasn't built earlier because it has to be cross- 
compiled for 
the target using the appropriate tools. To do so, create a directory 
to 
build the gdb server, move to it and build the gdb server: 

[root at localhost]# mkdir /usr/src/debug/build_gdbserver 
[root at localhost]# cd /usr/src/debug/build_gdbserver 
[root at localhost]# CC=arm-none-linux-gnueabi-gcc ../gdb-6.7.1/gdb/ 
gdbserver/configure 
--host=arm-linux --prefix=/opt/gdebug/arm-linux 
[root at localhost]# make 
[root at localhost]# make install 

The gdb server binary, 'gdbserver', has now been installed in your 
/opt/gdebug/arm-linux/bin directory. 

Once built, copy gdbserver to the MMC 

7. utility to setup the serial port 
=================================== 
compile ycom.c for both ARM and your PC using: 
arm-none-linux-gnueabi-gcc -o ycomarm ycom.c 
gcc -o ycom ycom.c 

This utility is used to setup the proper serial configuration BEFORE 
running gdb or gdbserver, and you can download it from: 
http://www.magniel.com/yuli/ycom.c 

8. Compiling the demo program hello2.c 
===================================== 
arm-none-linux-gnueabi-gcc -o hello2 hello2.c 
You can download it from: http://www.magniel.com/yuli/hello2.c 

9. Booting from MMC 
=================== 
Format MMC to FAT32 (use: HP MMC/SD Disk Format Tool) SP27213.exe 
Copy the following files to the MMC: 
MLO 
u-boot.bin   (the one that you modified) 
uImage 
rd-ext2.bin  (the one that you modified) 
ycomarm 
hello2.c 
hello2 
gdbserver 

Connect NULL modem cable to a PC, run hyperterminal: 115200,N,8,1 
Turn power to beagle, while pressing the 'USER' button 
It should run u-boot, and then execute the kernel, and at the end it 
should write: "TEST To send123" 

Connect the cable to a linux machine, login as root. 
Initialize the serial port for the proper speed, then envoke the gdb: 
        ./ycom /dev/ttyUSB1 
        /opt/gdebug/bin/arm-linux-gdbtui helloa 
and inside the gdb write: 
        target remote /dev/ttyUSB1 

you might use different serial port connection, so instead of ttyUSB1, 
the serial for your computer might be ttyS0 or similar. 
You can use the command "dmesg | grep tty" to display all available 
installed serial ports. 

10. Using the visual debugger ddd 
================================= 

download it, compile it, and use the following command line when 
running it: 
        ddd --debugger "/opt/gdebug/bin/arm-linux-gdb" 

Now power up beagle, wait a little (to ensure that the boot finished, 
and that gdbserver started to run), and then on the linux side start 
the debugger: 
        ./ycom /dev/ttyUSB1 
        ddd --debugger "/opt/gdebug/bin/arm-linux-gdb" 
and inside the gdb write: 
        target remote /dev/ttyUSB1 
        file hello2 

The file hello2 should be copied into the mmc. 

Yuli 
yk (at) magniel (dot) com 


Posted by kevino
,