Building the Linux Kernel

Revision as of 21:31, 25 September 2013 by Mdean (talk | contribs) (Setup: Fixed incorrect code tag.)
Jump to: navigation, search

This page covers the process of configuring and compiling the Linux kernel for a particular board using the standard EMAC kernel build script. This process assumes that you have already acquired the following software:

  1. Software Development Kit for target hardware
  2. Linux kernel source for target hardware (generally provided via EMAC public SVN server)
  3. Kernel build script for target hardware

If you do not know where to access the items above for your board, contact EMAC for more information.

The example below will assume that a kernel image for the SoM-9307 module will be created, but the instructions apply to other hardware as well assuming that the correct SDK, kernel tree, and build script is used.


The current kernel tree for the SoM-9307 is linux-2.6.25-ep93xx. The current SDK is the EMAC OE arm SDK, which should be configured for the SoM-9307. The steps below assume that the script is located in the same directory as the kernel tree. Be sure to modify the script so that the CROSS variable references the location of the SDK on your system. Also note that you may have difficulties using this script with the dash shell (default on Ubuntu Linux variants and some other distributions). If this is the case, change the top line of the kernel build script to reference /bin/bash rather than /bin/sh.

Configuring the Kernel

The first step for building the kernel is to configure it as desired. EMAC provides default configuration files for each board as a part of the kernel tree. For the SoM-9307, this file is linux-2.6.25-ep93xx/arch/arm/configs/som9307_defconfig. When configuring the kernel it is important to remember that many configuration options are necessary to have a working kernel image. Use the following steps to configure the kernel:

  1. Copy the default configuration file to .config in the kernel source tree. This only needs to be done the first time that you start a new build from a blank configuration.

    developer@ldc:~$ cp linux-2.6.25-ep93xx/arch/arm/configs/som9307_defconfig linux-2.6.25-ep93xx/.config
  2. Run the kernel build script with the config option to bring up the kernel “menuconfig”. The first argument to the script is the kernel source tree. The second option is one of config or build. The final option is a build-suffix; this is used as a tag for the directory that the kernel will be built in. You may use any string that you like, such as a date tag (20090101) or machine name (som9307). Using som9307 as the build-suffix will cause the kernel to be built in a directory named build-2.6.25-som9307.

    developer@ldc:~$ ./ linux-2.6.25-ep93xx config som9307
  3. This will bring up the kernel menu-driven configuration utility. Make any configuration changes desired, selecting features as a built-in or as modules (when available). The space bar is used to select an option, the 'm' key can be used to configure the selected option as a module. After you are finished, select Exit. The new configuration will be saved as .config under the newly created build directory. When you use the same build-suffix with the kernel build script in the future, this configuration will be used. Note that the build script removes the .config file from the kernel source tree and saves it to a file called prevconfig in the kernel source tree.

Building the Kernel

Once the kernel is configured, a new image can be built. Use the following steps to build a new kernel image:

  1. Run the kernel build script with the build option, using the same build-suffix used in the configuration step.

    developer@ldc:~$ ./ linux-2.6.25-ep93xx build som9307
  2. The kernel should begin compiling now. This will take several minutes to complete depending on your configuration and the speed of the development machine that you are using. Only move on to the next step if the build completes with no errors.

  3. The new kernel image is located in the build directory, the exact location depending on your architecture and image type. For the SoM-9307, the image is under build-2.6.25-som9307/arch/arm/boot/zImage. This is the image that will get loaded onto the board and executed by the bootloader. Another important file created by the build script is an archive of all of the modules that were created during the build process. This file is stored under the build directory. From the build steps above, the archive would be build-2.6.25-som9307/kernel-2.6.25.tar.gz.


Kernel Image

This step is highly architecture dependent. On most x86 boards and some other systems, the kernel image is stored and loaded from the root flash. If this is the case, the only step required is to load the kernel archive (i.e. kernel-2.6.25.tar.gz) onto the system and extract it. Many ARM systems typically store the kernel in a binary partition on the flash storage device separate from the root filesystem. In this case, the kernel image file must be loaded onto the system and written to the flash. The basic process for loading and testing the new kernel is as follows:

  1. Load the kernel modules archive onto the board. The example below assumes that the IP address of the board is

    developer@ldc:~$ scp build-2.6.25-som9307/kernel-2.6.25.tar.gz root@
  2. Extract the kernel modules archive to / on the board. Make sure that the root flash is mounted read/write and run the following on the board after logging in as root:

    root@emac-oe:~# cd /
    root@emac-oe:~# tar xzvf /tmp/kernel-2.6.25.tar.gz /lib/modules