Downloading the main line kernel source
A patch file on its own usually does not contain any compilable code. It is a machine-readable description of changes to make to a set of text files (in this case, the kernel source.) You need to obtain the main kernel source tree.The kernel source can be found on one of the kernel.org FTP sites. There are many sites scattered around the world, and are named according to a unified naming scheme. All sites start with 'ftp.' and end in '.kernel.org'. In the middle is placed a country identifier. For example:
- ftp.uk.kernel.org
- ftp.us.kernel.org
- ftp.de.kernel.org
and so forth. You can find out more information on these sites by looking at the main www.kernel.org site.
Once you have selected a site, you need to find the kernel sources. They will be stored in the subdirectories of /pub/linux/kernel. Each kernel release is accompanied by several files:
- linux-x.y.z.tar.gz
- linux-x.y.z.tar.bz2
- patch-x.y.z.gz
- patch-x.y.z.bz2
You will want to download the linux-x.y.z.tar.gz file, again into your $HOME directory. Again, you should look for a version which matches the version of the patch you obtained above. These files are large (about 14MB or more), so if you are on a slow connection, be prepared for it to take some time.
Unpacking the ARM kernel source
Unpack the tar archive you downloaded above using:bash$ cd $HOMEThis will create a directory called linux or linux-x.y.z in your home directory. Change into the newly created directory and apply the patch files, eg:
bash$ tar zxvf linux-x.y.z.tar.gz
bash$ cd linux-2.4.26The patches are heirarchial, so you need to apply them in the correct order. The patch files with more extensions depend on the ones with less extensions, so you need to apply, for example, the -rmk patch before the -rmk-np patch.
bash$ zcat ../patch-2.4.26-vrs1.gz | patch -p1
The kernel source tree is now ready to be configured.
Configuration of the kernel build environment
Normally, the kernel build system will build the kernel for the native machine architecture. This is not appropriate when cross compiling, so you will need to change two lines in the top level kernel Makefile. Examine the top level Makefile in an editor and find the definitions for ARCH and CROSS_COMPILE. On 2.4.x kernels, they will look like this:ARCH := $(shell uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ -e s/arm.*/arm/ -e s/sa110/arm/)[...]
CROSS_COMPILE =and on 2.6.x kernels:
ARCH ?= $(SUBARCH)
CROSS_COMPILE ?=
Edit these two lines to read:
ARCH ?= arm
CROSS_COMPILE ?= /usr/local/bin/arm-linux-
replacing /usr/local/bin/arm-linux- with the path to your ARM Linux toolchain.
This completes the configuration of the top level kernel makefile. The next step is to configure the kernel build to select the drivers that your platform requires.
You may like to read linux/README and linux/Documentation/arm/README before proceeding. Both these files provide further useful information which may be specific to your kernel version.
Configuration of the kernel sources
There are a range of 'make' targets which allow a set of defaults to be selected for the particular machine you are compiling the source for. The process is much simpler for 2.6 kernels.
Configuration of 2.4 kernels
For 2.4 kernels use <machinename>_config format, for example:- a5k_config
- ebsa110_config
- netwinder_config
- rpc_config
- assabet_config
You should select one of these as the "basic" configuration as follows, and run make oldconfig immediately afterwards:
bash$ make netwinder_configThe oldconfig step will prompt you for any new configuration options which may have been added since the default machine configuration file was submitted. It is normally safe to say 'N' to these new options.
bash$ make oldconfig
Note: If you want to change the configuration via make xxx_config, please remove the file linux/.config immediately prior to executing this command.
Configuration of 2.6 kernels
For 2.6 kernels, the process is similar. Use <machinename>_defconfig to select the machine, eg:bash$ make netwinder_defconfigIn this case, there is no need to run a separate oldconfig step.
Compiling the kernel source
If you are only installing the kernel source tree for other programs, then you have finished. If you want to compile up a new kernel, type the following commands:bash$ make cleanThe final two commands will actually compile the kernel and the kernel modules.
bash$ make dep
bash$ make zImage
bash$ make modules
Note: With 2.6 kernels, the make dep stage is not necessary.
Installing the kernel
After the kernel has successfully compiled, you should have the kernel image, arch/arm/boot/zImage. What you do next depends if you are cross compiling or not.If you are cross compiling, goto the section "Installing a cross compiled kernel".
If you are building natively (ie, for the target on the target), continue.
