A - A - A

Compiling a Kernel

 
Search

Obtaining the Kernel Source

To compile your own kernel you need the source and the right set of patches. For all cases you need the base source tree and the ARM kernel patch. The SA1100 patches are usually a good idea too, and are necessary for SA1100 or later processors. For some devices, especially newly-supported ones, you may need a further patch for that device.

Kernel Source

Base source tree

linux-2.4.1-tar.bz2

or linux-2.4.1-tar.gz

ARM kernel (Russell King) patch

patch-2.4.1-rmk1.gz

SA1100 (Nico Pitre) patch

diff-2.4.0-rmk1-np2.gz

Each applied patch adds a suffix to the kernel name, so a kernel made with the 2.4.1 source with the rmk1 ARM kernel patch and the np2 SA1100 patch would be called zImage-2.4.1-rmk1-np2. The letters indicate the patch source. In the above cases they are the names of the patch maintainers Russell King and Nico Pitre respectively. Note that although they use different naming conventions, both patch files are of the same type.

The kernel source is normally available in both gzipped and bzip2 form. The latter is significantly smaller so that is normally the better one to download. You will need the bzip2 utility to decompress bzip2 files.

All these are on the CD but you will need to copy them into your development directory. Alternatively, obtain the latest version of kernel base, ARM kernel and SA1100 patches from these ftp sites but remember to use your local mirror, e.g. ftp://ftp.uk.kernel.org/ for the UK mirror.

Kernel Source - Current Version

Kernel Base

ftp://ftp.kernel.org/pub/linux/kernel/v2.4/

ARM kernel Patch

ftp://ftp.arm.linux.org.uk/pub/linux/arm/source/kernel-patches/v2.4/

SA1100 Patch

ftp://ftp.arm.linux.org.uk/pub/linux/arm/people/nico/

The source tree can then be unpacked into your development source directory. You can put this anywhere you like, but it must be kept separate from your native source tree in /usr/src/linux. This is because many systems expect the version of headers in /usr/src/linux to correspond to the version of the kernel and glibc being run on the host machine. This is usually different from the version you are using for ARMLinux development. We recommend putting your ARM kernel source tree in /usr/arm-linux/linux (this is alongside the toolchain in a cross-compilation environment). Note that you need a fair amount of disk space free. The unpacked 2.4.1 source is a little over 100MB, and you should have two copies of it, and configuring and compiling only makes it bigger.

In your development directory enter the following command to unpack the source:

tar -xzvf linux-2.4.1.tar.gz

Or if you have the bzipped version, use these options:

tar -xIvf linux-2.4.1.tar.bz2

Finally, unzip/untar the source before applying the ARM and SA1100 patches to give you a new kernel source tree. Using patch -p0 can confuse various versions of patch so its best to cd into the linux directory and use p1, thus:

cd linux
zcat ../patch-2.4.0-rmk1.gz | patch -p1 
zcat ../diff-2.4.0-rmk1-np2.gz | patch -p1 

Kernel source mangement

If you are intending to work on the kernel, the first thing you should do is take a copy of the pristine tree. This is so that you can generate patches against it after you have made changes. The simplest way to do this is simply to do:

cp -a linux linux-2.4.1.orig

However, as in practice you will only ever change a few files and having two copies of the whole thing, 99% of which are going to remain untouched, means that you may prefer to use hard links to create the copy as then only the changed files take up space. This method relies on the editor creating a new file after every save so that the original is preserved. If you have need of such an editor, take a look at MicroEmacs or GNU Emac's back-up-when-copying-when-linked facility. To create a hard-linked source copy do this:

cp -a -l linux linux-2.4.1.orig

Alternatively, you can use CVS to control your source versions, but that is not covered here.

Making a Kernel

First you should tidy up the source to get rid of old files and stale dependencies, especially if you have previously configured for a different device with make mrproper. You should then issue the appropriate make target-device_config command to set up a default configuration file for your target device. The list of possibilties for target-device is found in linux/arch/arm/def-configs/. You will then need to set up a kernel configurations file using the defaults which have just been created. This can be accomplished with the make oldconfig command. Finally, make dep sets up kernel dependencies and sub-configuration files on the basis of the specified config whilst make zImage builds the kernel image. The kernel should consequently appear in linux/arch/arm/boot/zImage. So, to summarise:

make mrproper
make target-device_config
make oldconfig
make dep
make zImage