<div class="SECT2"><h2 class="SECT2"><a name="AEN1555">Obtaining the Kernel Source</a></h2><p>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. </p><dl><p><b>Kernel Source</b></p><dt>Base source tree</dt><dd><p><tt class="FILENAME">linux-2.4.1-tar.bz2</tt></p><p>or <tt class="FILENAME">linux-2.4.1-tar.gz</tt></p></dd><dt>ARM kernel (Russell King) patch</dt><dd><p><tt class="FILENAME">patch-2.4.1-rmk1.gz</tt></p></dd><dt>SA1100 (Nico Pitre) patch</dt><dd><p><tt class="FILENAME">diff-2.4.0-rmk1-np2.gz</tt></p></dd></dl><p>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.</p><p>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.</p><p>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.</p><dl><p><b>Kernel Source - Current Version</b></p><dt>Kernel Base</dt><dd><p><a target="_top" href="ftp://ftp.kernel.org/pub/linux/kernel/v2.4/">ftp://ftp.kernel.org/pub/linux/kernel/v2.4/</a></p></dd><dt>ARM kernel Patch</dt><dd><p><a target="_top" href="ftp://ftp.arm.linux.org.uk/pub/linux/arm/source/kernel-patches/v2.4/">ftp://ftp.arm.linux.org.uk/pub/linux/arm/source/kernel-patches/v2.4/</a></p></dd><dt>SA1100 Patch</dt><dd><p><a target="_top" href="ftp://ftp.arm.linux.org.uk/pub/linux/arm/people/nico/">ftp://ftp.arm.linux.org.uk/pub/linux/arm/people/nico/</a></p></dd></dl><p>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 <tt class="FILENAME">/usr/arm-linux/linux</tt> (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.</p><p>In your development directory enter the following command to unpack the source:</p><p><b class="COMMAND">tar -xzvf linux-2.4.1.tar.gz</b></p><p>Or if you have the bzipped version, use these options:</p><p><b class="COMMAND">tar -xIvf linux-2.4.1.tar.bz2</b></p><p>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:</p><p>  </p><p class="LITERALLAYOUT"><b class="COMMAND">cd linux</b><br /> <b class="COMMAND">zcat ../patch-2.4.0-rmk1.gz | patch -p1</b>&nbsp;<br /> <b class="COMMAND">zcat ../diff-2.4.0-rmk1-np2.gz | patch -p1</b>&nbsp;</p><div class="SECT3"><h3 class="SECT3"><a name="AEN1625">Kernel source mangement</a></h3><p>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:</p><p class="LITERALLAYOUT"><b class="COMMAND">cp</b>&nbsp;<tt class="OPTION">-a</tt>&nbsp;linux&nbsp;linux-2.4.1.orig</p><p>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 Micro<span class="ACRONYM">Emac</span>s or <span class="ACRONYM">GNU</span> <span class="ACRONYM">Emac</span>'s <i class="EMPHASIS">back-up-when-copying-when-linked</i> facility. To create a hard-linked source copy do this:</p><p class="LITERALLAYOUT"><b class="COMMAND">cp</b>&nbsp;<tt class="OPTION">-a</tt>&nbsp;<tt class="OPTION">-l</tt>&nbsp;linux&nbsp;linux-2.4.1.orig</p><p>Alternatively, you can use CVS to control your source versions, but that is not covered here.</p></div></div> <div class="SECT2"><h2 class="SECT2"><a name="AEN1641">Making a Kernel</a></h2><p>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 <b class="COMMAND">make mrproper</b>. You should then issue the appropriate <b class="COMMAND">make <i class="EMPHASIS">target-device</i>_config</b> command to set up a default configuration file for your target device. The list of possibilties for <i class="EMPHASIS">target-device</i> is found in <tt class="FILENAME">linux/arch/arm/def-configs/</tt>. 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 <b class="COMMAND">make oldconfig</b> command. Finally, <b class="COMMAND">make dep</b> sets up kernel dependencies and sub-configuration files on the basis of the specified config whilst <b class="COMMAND">make zImage</b> builds the kernel image. The kernel should consequently appear in <tt class="FILENAME">linux/arch/arm/boot/zImage</tt>. So, to summarise:</p><p class="LITERALLAYOUT"><b class="COMMAND">make mrproper</b><br /> <b class="COMMAND">make <i class="EMPHASIS">target-device</i>_config</b><br /> <b class="COMMAND">make oldconfig</b><br /> <b class="COMMAND">make dep</b><br /> <b class="COMMAND">make zImage</b></p></div> 