Deeply Embedded Linux

David McCullough

Deeply Embedded Linux is a term used to describe a level of device not accustomed to running linux. More often than not this means a device with very little RAM, limited or no storage and most likely no display devices attached. Some examples of deeply embedded devices may be printers, mobile phones, home gateway appliances. Quite often a good indication of a deeply embedded device is one which lacks memory management (ie., the processor does not have a Memory Management Unit or MMU). Although this is not always the case, the cost sensitivity and smaller footprint of MMU-less devices sees them used for this kind of application more often than not.

When linux is to be used for CPUs without an MMU, uClinux becomes the linux of choice. uClinux is a version of Linux for CPUs without an MMU and is typically targeted at deeply embedded systems with very little memory or permanent storage. Like its big brother, uClinux provides the developer with a number of options. The broad range of these options is what contributes to the strength of the uClinux solution.

uClinux comes in three kernel flavours, 2.0.x, 2.4.x and 2.5.x. The 2.0.x versions (based on linux-2.0) are the smallest kernels and considered very stable. They provide full TCP/IP networking and firewall capabilities. The 2.4.x kernels are also considered very stable. They are larger than the 2.0 kernels but with the increased size bring a wealth of networking and device support. Finally the 2.5.x kernels are very experimental and best avoided for real-world development.

On top of the kernels options are the libc options. Typically uClinux systems use either the uC-libc or uClibc 'C' libraries. uC-libc is usually a little smaller, with restricted functionality, while uClibc attempts to provide a more complete 'C' API. There is also a large number of applications that can be combined to create the system of your choice.

A practical Example

Rather than discuss the theoretical advantages and disadvantages of the uClinux solution, a real world example will be discussed here and highlights along the way will help others determine if uClinux is suitable for their application.

This solution will show how to get uClinux running on a 3com PalmPilot. Specifically the PalmIIIx. This device is based on the Motorola Dragonball CPU (MC68EZ328), a low power member of the 68000 range of CPU's which was designed with PDA devices in mind.

To emphasize the flexibility of the environment, a graphical programming environment, Microwindows/Nano-X, will be compiled and loaded onto the device to run a small application. Microwindows is a full featured windowing system which , although small, is full featured enough to be used on a PC or a PDA. It provides two API's, one which is similar to that of a Windows platform, and another more familiar to X11 developers.

Firstly, the sources and tools needed to build for the platform need to be downloaded. All the following instructions assume a linux development platform. While it is possible to do this on Windows and Other operating systems the process is more complex and beyond the scope of this document.

uClinux Compilers
Download and install the latest m68k-elf-tools from:

http://www.uclinux.org/pub/uClinux/m68k-elf-tools.

The pre-compiled binaries need to be installed by root from the '/' directory with:

gunzip < m68k-elf-tools-20020410.tar.gz | tar xf -
PalmOS Tools
Get the following files from:

http://www.uclinux.org/pub/uClinux/palm-tools/

m68k-palmos-coff.tools-990108-linux-x86-glibc.tar.gz
prc-tools-0.5.0-5.i386.rpm
Install with:

rpm -i prc-tools-0.5.0-5.i386.rpm
cd /; gunzip < m68k-palmos-coff.tools-990108-linux-x86-glibc.tar.gz | tar xf -

In order for the coff tools to work correctly you will have to ensure that /usr/local/bin is the first directory in your PATH. For example:

PATH="/usr/local/bin:$PATH"
export PATH

will be sufficient for the current login shell, although it should be added to you .profile or equivalent for a more permanent solution.

uClinux-dist Sources
Get the following file:

http://www.uclinux.org/pub/uClinux/dist/uClinux-dist-20020701.tar.gz

And install into an appropriate directory for development. This package does not need to be installed as root, so it can go in the users directory.

gunzip < uClinux-dist-20020701.tar.gz | tar xf -

Now that all the tools are installed, it's time to build the sources. Due to the small memory footprint of the PalmPilot, the 2.0 kernel and uC-libc will be used for this exercise.

Here is the sequence of commands required to build the sources and load them into the PalmPilot.


	cd uClinux-dist
	make xconfig

		
	
	select the "Target Platform Selection" button.
	choose the 3com/PalmIIIx target and the uClinux-2.0 kernel
	select "customise kernel settings"
	select "customise Vendor/user settings"
		
		

	return to the main menu, "save and exit".

		

	Select the "Platform Dependant Setup" button,  change the CPU type to
	"MC68EZ328" and select the "PalmV support" options.

		
	
	scroll to the bottom of this screen and select "Kernel executes from RAM"

		
	
	return to the main menu and select the "General Setup" button,  select
	the "Enable ZFLAT support" option.  return to the main menu.

		

	Select the "Networking options" button and disable TCP/IP networking.
	return to the main menu.

		
	
	Select the "Network devices" button and disable all devices by select 'n'
	for the "Network Devices Support" option.

		
	
	Select "save and exit" and then "ok".
	Now the user configuration will appear.

		
	
	select the Microwindows button and enable Ntest.

		

	return to main menu,  "save and exit", select "ok".

	make dep

	make

	flthdr -z romfs/bin/*
	ln -s /var/tmp romfs/tmp

	make image

At this point you will have a PalmPilot application in the images directory called "uClinuxPalm.prc". Before uClinux can be run on the PalmPilot this image must be loaded into the device.

WARNING Running uClinux on a PalmPilot ERASES ALL INFORMATION in the PalmPilot. It is best to run this on a device that contains no important information.

	hook up Palm to serial port and run the following command:

		PILOTRATE=57600 pilot-xfer -p /dev/ttyS0 -i images/uClinuxPalm.prc
	
	You will need to change the port to ttyS1 if you are using the second
	serial port.

This will use the pilot-xfer application to transmit the application to the PalmPilot. Once the transferr has completed there will be a small penguin faced icon on the Pilot. Running this application will start uClinux. Before running uClinux a warning screen is displayed about the loss of data stored in the PalmPilot. You should also connect to the serial port with a terminal program to see the console output. The UUCP program "cu" can be used to do this with a command like "cu -l /dev/ttyS0 -s 9600".

There should be a shell prompt on the serial console eventually. Be patient, it takes a little while to boot. Once there the graphical programs can be started:

 /> nano-X &
 /> nanowm &
 /> ntetris &
 /> nxclock &

Here is a screen shot of the console output:

Here is a screen shot of the boot screen:

Here is a screen shot of the screen with some nanoX applications running:

Summary

uClinux on the PalmPilot shows the ability of linux to adapt to small resource limited devices. The linux configuration for the PalmPilot weighs in at a reasonably heavy size of:

	548K - linux kernel (453K text and 95K data)
	286K - ROM filesystem
	834K - total

This is the size for a full TCP/IP enabled kernel with shell and MicroWindows applications. The size of this image can be reduced by removing networking support. A quick rebuild without networking support shows that this total can be reduced by about 120K. The smallest linux 2.0 kernel that can be built for this particular target is about 230K of text and 38K of data. At this size linux is little more than a multi processing kernel core with very little device support included.

Although an older PalmPilot like a PalmIIIx is a good example of a deeply embedded device, newer PDA's are becoming more powerful, have MMU support and generally have much more storage than the older PDA's. Their increased resources means they can support a much larger number of protocols and devices. The PalmIIIx example does show that linux is possible of quite small footprint devices and can still offer good network and device support in such small footprint devices.

Another part of this exercise that makes the example less real-world is that the uClinux image is only loaded into RAM. This makes the experiment safe in that the PalmPilot cannot be rendered in-operational after running uClinux, but is hardly realistic. A real system would normally have uClinux stored in ROM of Flash. This would free up considerable resources in the PalmPilot for more applications and storage. For example the entire linux text section and the ROM filesystem can be stored in ROM. This would immediately free up at least 700K of memory for use by running applications. Once the system is separated into ROM and RAM components it becomes much more useful for deeply embedded applications.