uClinux in the GDB/ARMulator

Here are some patches to GDB to allow the existing gdb ARM emulator to run uClinux targets. It can run both little-endian and big-endian code, as well as apcs-32/26 code and Thumb. I have tested little/big endian kernels but haven't played with thumb at this point.

The patch is heavily based on an ARM7100 patch that Ben Williamson produced back around 1999 for gdb-4.18. The changes include Atmel AT91 emulation for timers/system registers and serial ports, removal of Bens LCD support and porting to gdb-5.0.

News

Dec 2002
Many thanks to Yu Chen who has sent in build instructions for Cygwin targets. He has also provided precompiled binaries that can be extracted from "/".
Nov 2002

Fernando José Cardozo de Sá has been kind enough to send in his Win32 native port of the ARMulator. All the files needed are in the Win32 directory. The Win32 binaries work just like the unix versions, check the section below on Running the precompiled binaries.

Fixed the 'ls'/'ps' problem with big-endian targets by stealing a small bit of the patch provided by Daniel Versick's (http://mac.os.nctu.edu.tw/distfiles/4530.patch). More of this patch may be required I just haven't had time to digest it all.

Jan 2006

Wow an update :-) Needed to implement the IPR (Interrupt Pending Register) in order to work with a bug fix pending for the 2.4.x kernel.

Mar 2007

Here's a patch to fix problems compiling the armulator on newer systems (invalid lvalue error).

What you get

Here are some files you can use to put together uClinux running in the GDB/ARMulator.

gdb-5.0.tar.bz2
The orginal gdb-5.0 archive.

gdb-5.0-uclinux-armulator-20060104.patch.gz
Patches against gdb-5.0 based heavily on the ARMulator changes from Ben Williamson <benw@pobox.com> with changes to behave like an Atmel AT91 device.

uClinux-dist-20020927.patch.gz
The changes you will need to fix GDB/ARMulator-BE support in the 20020927 distro, specifically 'ps' and 'ls'. Big endian support is not as stable as the little endian GDB/ARMulator target and is only recommended if you really want to play with a big-endian system.

uClinux-20020701-20020816.patch.gz
The changes you will need to make XIP (execute in place) and big-endian targets work with the 20020701 distro. Choose the GDB/ARMulator-EB to build big-endian kernels and apps. Choose GDB/ARMulator for little endian targets.

linux.2.0.x.gz
linux.2.4.x.gz
A precompiled uClinux kernel binaries that you can run in the emulator.

romfs.2.0.x.gz
romfs.2.4.x.gz
romfs images to use with the above kernels.

linux.2.0.x-xip.gz
linux.2.4.x-xip.gz
A precompiled uClinux kernel binaries with XIP support that you can run in the emulator.

romfs.2.0.x-xip.gz
romfs.2.4.x-xip.gz
romfs images to use with the above kernels. Applications are XIP.

example-session.txt
An example session in the debugger.

Building the Debugger/Emulator

	bunzip2 < gdb-5.0.tar.bz2 | tar xvf -
	gunzip < gdb-5.0-uclinux-armulator-20060104.patch.gz | patch -p0
	cd gdb-5.0
	./configure --target=arm-elf
	make
	su root -c "make install"

Running the precompiled binaries

The ARMulator expects the romfs to be in a file called "boot.rom". You must use the matching kernel/romfs combo's.

	gunzip romfs.2.0.x
	gunzip linux.2.0.x
	ln -s romfs.2.0.x boot.rom
	arm-elf-gdb linux-2.0.x
	...
	gdb> target sim
	...
	gdb> load
	...
	gdb> run

And likewise for 2.4, just change the names.

Checkout the example-session.txt file to see what it looks like.

Using the Debugger

Just type ^C to drop into gdb. There are no symbols in the binaries provided above, but if you build your own your will have full source debugging of the kernel (and apps if you load their symbols appropriately). You can step and continue just like a normal debugger.

Building from Source

If you are using an older uClinux distro, just apply the patch and see how you go. Anything more recent than the patches mention will include the GDB/ARMulator target by default with the patches included. You can get the source from:

	http://www.uclinux.org/pub/uClinux/dist/
Be sure to check for any patches above that are required for the version you download. You can get the tools from:
	http://www.uclinux.org/pub/uClinux/arm-elf-tools/

Build as for any other target, the images above were built with uC-libc.

When building from source, create a file in the top directory called ".gdbinit" that contains:

	target sim
	load
to save some typing ;-) Then link the romfs.img to boot.rom with:
	ln -s images/romfs.img boot.rom
and run
	arm-elf-gdb linux-2.X.X/linux
to have full source debug of the kernel and friends.

Messing with the Emulator

If you want to see how much of a hack this really is, the main files to look at are:

	gdb-5.0/sim/arm/armmem.c
	gdb-5.0/sim/arm/armio.c

These still include the old 7100 code commented out and the Atmel emulation that is truly hacked in on top. You can add more memory and change the size of the rom in armmem.c. You can fix most bugs in the emulation in armio.c.

Thanks to

Patrick Doyle for the time.h patch to fixcompiling on RedHat 7.2/7.3
Fernando José Cardozo de Sá for his Native 32 port (and binaries).
Daniel Versick's big-endian patches for uaccess (taken from http://mac.os.nctu.edu.tw/distfiles/4530.patch).

Copyright (C) 2002,2005
David McCullough <davidm@snapgear.com>