分类: 项目管理
2008-04-07 23:29:24
This guide will give you step by step instructions about compiling a kernel for ARM machines on the target platform. If you find something missing or unclear, please send a mail to the linux-arm list.
Here are some initial notes to help you understand the terminology and conventions used in this document:
However, please note that building a kernel in /usr/src/linux is highly discouraged.
For any kernel version x.y.z,
This version number represents the main line kernel version.
At the time of writing this document, the latest stable kernel on ARM is 2.6.6.
Under the ARM kernel tree, you will find a suffix to the kernel version number: -rmkN, or -vrsN where 'N' is the patch release number. For instance, 2.4.26-vrs1. This indicates the version of the main ARM kernel patch which should be applied. (note: kernels later than 2.6.0-test2 do not require a -rmk or -vrs patch to be applied since ARM architecture support is already merged.)
Other maintainers, such as Nicolas Pitre, may produce additional patches, and these will add an additional suffix to denote their version. Nicolas Pitre's patches add a -np suffix, eg 2.4.21-rmk2-np1.
This means that 2.4.21-rmk2-np1 is based upon 2.4.21-rmk2, which in turn is based upon the 2.4.21 kernel. Therefore, to get the kernel source for 2.4.21-rmk2-np1, you need the 2.4.21 main line kernel source, the 2.4.21-rmk2 patch and the 2.4.21-rmk2-np1 patch.
Therefore, if you need extra patches from other maintainers, you have to be careful to choose an appropriate kernel version. You will need to locate the maintainer patches first, and then work your way up through the version number towards the mainline kernel version.
Please refer to the machine list for information concerning extra patches.
You may need to download a kernel patch, which contains all the ARM specific updates for a particular kernel version. These can be found in . The kernel releases are separated out into directories corresponding to the major and minor version numbers of the kernel.
The individual files are named patch-x.y.z-rmkN.gz or patch-x.y.z-vrsN.gz, where 'x', 'y', 'z' and 'N' are the version numbers mentioned above. You should select and download the latest patch for the kernel into the $HOME directory. This is the one which will have either the most features, or the most bug fixes in. You will need the version of the patch later when downloading the main kernel source.
Note: Some files may be named (eg) pre-patch-x.y.z-rmkN.gz. These are alpha or beta patches, which are probably unstable. You should not use these unless you are sure that you know what you are doing, and you don't mind the target system being unstable. However, they are useful when new ideas need to be tested out.
Note2: Some kernels are based on the Alan Cox series of kernels. These have names similar to patch-x.y.z-acm-rmkN.gz where x.y.z is Linus' version number and m is Alan's version number. In this case, you will need to obtain Alan Cox's corresponding patch from the kernel.org servers, in the directory /pub/linux/kernel/people/alan/linux-2.4/.
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:
and so forth. You can find out more information on these sites by looking at the main 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:
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.
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.
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 and linux/Documentation/arm/README before proceeding. Both these files provide further useful information which may be specific to your kernel version.
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.
bash$ make netwinder_defconfigIn this case, there is no need to run a separate oldconfig step.
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.
If you are cross compiling, goto the section "".
If you are building natively (ie, for the target on the target), .
bash$ suIt is highly advisable to keep a backup of your current kernel and modules. What you need to do is machine dependent. Note that it is a good idea to always keep a known good previous version of the kernel and modules in case you need to back down to a previous version.
Password:
bash#
The following is given as an example (for a 2.4.3-rmk1 kernel):
bash# cd /lib/modulesNow, install the new kernel modules:
bash# mv 2.4.3-rmk1 2.4.3-rmk1.old
bash# cd /boot
bash# mv vmlinuz vmlinuz.bak
bash# mv System.map System.map.bak
bash#
bash# cd $HOME/linuxThis will copy the modules into the /lib/modules/x.y.z directory. Next, install the kernel image (normally into /boot):
bash# make modules_install
bash#
bash# cd /boot
bash# cat $HOME/linux/arch/arm/boot/zImage >vmlinuz
bash# cp $HOME/linux/System.map .
bash#
Note that the command to copy the new kernel image is cat and is not the usual cp. Unix traditionally will not allocate space on the filesystem to sections of files containing zero data, but instead creates "holes" in the file. Some kernel loaders do not understand files with holes in, and therefore using cat in this way ensures that this does not happen.
Edit the loader configuration file /etc/boot.conf so that you can boot either the vmlinuz.bak or vmlinuz images. If you place the vmlinuz kernel first, then this will be the default kernel which the kernel loader will use.
More information can be found by typing man boot.conf.
Run the boot loader map utility:
bash# loadmap -vto update the maps.
bash#
You have finished, and are now ready to reboot your machine and try out your new kernel! If you experience problems, please go to the "" step below.
Install the modules into $TARGETDIR as follows:
bash$ make modules_install INSTALL_MOD_PATH=$TARGETDIRThis will place the modules into the $TARGETDIR/lib/modules/x.y.z directory on the host, which can then be placed into an suitable filesystem, or transferred to the target machine. Please also note that you must not install these kernel modules into the hosts root filesystem (eg by omitting INSTALL_MOD_PATH or giving $TARGETDIR as "/"), since they are incompatible with your host kernel and therefore may leave you with an unbootable host system.
bash$
The kernel will be available in $HOME/linux/arch/arm/boot/zImage and the kernel symbol information in $HOME/linux/System.map. Exactly how do install this is outside the scope of this document.
It is important that you keep the System.map file safe - it contains the symbolic information for this kernel, which will be required if you need to debug or report a problem.