Linux on Flash for bifferboard HOWTO
This document describes how to setup what you need to compile a Linux kernel with a root file system that is embedded in the kernel image and expands to a RAM disk when the kernel has booted.
The bifferboard has 1 MB of flash which can sound quite small but it is actually possible to fit quite a lot on it. My own projects use wget to fetch additional software from the LAN once the bifferboard has booted.
The files provided with this document can be downloaded from the attachments area below and gives you a kernel image around 890 kb. The contents of the kernel will probably not be exactly right for your project but provides a base from which you can experiment with different settings.
The size of the kernel and other software is kept down by cross-compiling and linking with uClibc, a light version of the C library.
These instructions are tested on Ubuntu 8.10.
The following steps will be needed to create your kernel image:
1. Install buildroot
2. Install BusyBox
3. Create your root file system
4. Compile the kernel image
Buildroot is the cross-compilation environment used to compile the rest of the software and the kernel.
The buildroot website URL is: http://buildroot.uclibc.org/
Download buildroot using this link: http://buildroot.uclibc.org/downloads/buildroot-2009.02.tar.bz2
Unpack the archive.
From the files provided with this document, copy the file "dot.config" from the "buildroot" directory to the directory where you unpacked the buildroot archive. Rename this file to ".config".
Follow the instructions in the README file provided with buildroot to build the buildroot toolchain.
Your toolchain will reside in the subdirectory "build_i386/staging_dir/usr/bin".
Add the full path to this directory to the PATH environment variable.
BusyBox is a clever piece of software which combines all the core Linux utilities like ls, cp etc. into one executable, saving space. We will compile it using the buildroot toolchain and link it statically against uClibc. This means we don't have to bother with shared libraries at all.
The BusyBox website URL is: http://www.busybox.net/
Download BusyBox using this link: http://busybox.net/downloads/busybox-1.14.0.tar.bz2
Unpack the archive.
From the files provided with this document, copy the file "dot.config" from the "busybox" directory to the directory where you unpacked the BusyBox archive. Rename this file to ".config".
Follow the instructions in the INSTALL file provided with BusyBox to build the executable.
Creating the root file system
The root file system will be created on disk and compressed to a cpio archive which can be used in the kernel compilation process.
From the files provided with this document, cd to the "ramdisk" directory.
The script "mkbiffrd.sh" will take care of building the ramdisk image. It needs to be adapted whenever the contents of the BusyBox executable changes. Line 31 needs to be changed to reflect the path to the busybox executable on your system.
The "files" directory contains configuration files that will be copied to the root file system and used at runtime.
You will probably only need to change "rcS" and "start.sh"
/etc/group Translates group IDs to group names.
/etc/hosts Associaties 127.0.0.1 with localhost.
/etc/mdev.conf Needed to make ALSA sound devices install correctly.
/etc/passwd Translates user IDs to user names.
/etc/init.d/rcS This script is run at bootup. Use it to initialize your bifferboard.
/home/start.sh This script is used to download and run the application software for my project.
/usr/share/udhcpc This script is used by the DCHP client.
Run "mkbiffrd.sh" to build the ramdisk image. The created image will be called "initramfs.cpio".
Compiling the kernel image
The kernel version I am using is 18.104.22.168 with a few patches applied.
The Linux Kernel Archives URL is: http://kernel.org/
Download the kernel using this link: http://www.kernel.org/pub/linux/kernel/v2.6/linux-22.214.171.124.tar.bz2
Unpack the archive.
From the files provided with this document, copy the files in the directory "kernel/patches" to the directory where you unpacked the kernel archive.
Copy the file "dot.config" from the "kernel" directory to the directory where you unpacked the kernel archive. Rename this file to ".config".
Copy the file "make_bifferboard" from the "kernel" directory to the directory where you unpacked the kernel archive.
Apply the patches using the command "patch -p1 <name-of-patch.patch" for the three patch files.
Run "make menuconfig".
Go to "General Setup".
Scroll down to the menu item "Initramfs source file(s)" and enter the path to the initramfs.cpio on your system.
Exit the config system.
Run "./make_bifferboard" to compile the kernel.
The finished kernel image will be located at "arch/x86/boot/bzImage". This can now be flashed to your bifferboard!
Notes on size constraints
The kernel and ramdisk is limited to 974848 bytes with Biffboot v2.0 and 983040 with BiffBoot v1.X. Adding HTTP server with CGI to the above instructions results in a firmware 893072 bytes in size, 81776 bytes short of the maximum. That means a reasonably large uncompressed application can theoretically be added, but it would have to extend Busybox, rather than be stand-alone.
Don't hesitate to leave comments and feedback on how this works for you.
I will try to address any faults in the instructions.
Kernel command line paramteres
Running scripts as non-root user
See cpiofix.py. This can be run instead of mkbiffrd.sh, but edit it first to set the busybox bin location (near the bottom of the file)
I've added a patch that allows one to disable the math emulation and still get a boot (125-no-math-emu.patch). I guess horrible things will happen if software then attempts to use math co-processor, but for many applications this will be OK (e.g. NAS, or other data shifting apps). This saves over 21K flash space.