Difference between revisions of "Building the Linux Kernel"

From wiki.emacinc.com
Jump to: navigation, search
m
(33 intermediate revisions by 6 users not shown)
Line 1: Line 1:
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:  
+
{{#seo:
 +
|title=Building the Linux Kernel
 +
|titlemode=append
 +
|keywords=Building Linux Kernel,Configuring Kernel,Loading Kernel Modules
 +
|description=Process of configuring and compiling the Linux kernel using the EMAC kernel build script.
 +
}}
 +
This page covers the process of configuring and compiling the Linux kernel using the EMAC kernel build script. This process assumes that you have already acquired the following software:  
  
# Software Development Kit for target hardware
+
# EMAC Software Development Kit [[ Installing_EMAC_OE_4.0_SDK | OE 4 ]] or [[Installing_EMAC_OE_5.0_SDK | OE 5 ]]
# Linux kernel source for target hardware (generally provided via EMAC public SVN server)
+
# Linux kernel source for target hardware (provided via EMAC public [http://git.emacinc.com/ GIT server] )
# Kernel build script for target hardware
+
# [ftp://ftp.emacinc.com/EMAC_Linux/SDK/kernel-build-cross.tar.gz Kernel build script]
  
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-9x25 module will be created, although the instructions apply to other hardware as well assuming that the correct SDK, kernel tree, and build script is used.
 
 
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.
 
  
 
==Setup==
 
==Setup==
  
The current kernel tree for the [[SoM]]-9307 is </code>linux-2.6.25-ep93xx</code>. The
+
The steps below assume that the <code>kernel-build-cross.sh</code> script is
current SDK is the EMAC OE arm SDK, which should be configured for the
+
located in the same directory as the kernel tree. Be sure to modify the <code>environment.cfg.sh</code> script for the correct
SoM-9307. The steps below assume that the <code>kernel-build-cross.sh</code> script is
+
architecture and EMAC OE version.
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 <code>/bin/bash</code>
 
rather than <code>/bin/sh</code>.
 
  
 
==Configuring the Kernel==
 
==Configuring the Kernel==
  
The first step for building the kernel is to [[configure it]] as desired. EMAC
+
The first step for building the kernel is to configure it as desired. It is recommended to start with the kernel configuration file used by EMAC to build the kernel for the target device. Starting with EMAC OE 5, the kernel configuration can be
provides default configuration files for each board as a part of the kernel
+
obtained on a running board from /proc/config.gz. Please contact [http://www.emacinc.com/support EMAC support]
tree. For the SoM-9307, this file is
+
for earlier EMAC OE versions.
<code>linux-2.6.25-ep93xx/arch/arm/configs/som9307_defconfig</code>. When configuring the
+
<br >
kernel it is important to remember that many configuration options are
+
The following are steps to configure the kernel:
necessary to have a working kernel image. Use the following steps to configure
+
<cl>
the kernel:
+
1. Copy the default configuration file to the same directory as the kernel source tree and kernel-build-cross.sh and rename it defconfig.
 +
 
 +
* The kernel-build-cross script accepts the SOURCE_TREE as the first argument and either config or build as the second argument. Optionally, a third argument, BUILD_SUFFIX may be supplied as a suffix to add to the build directory. BUILD_SUFFIX is commonly used to add a date tag or machine name to a build.
 +
 
 +
{{cli | username=developer | hostname=ldc |./kernel-build-cross.sh linux-at91 config som9x25}}
 +
 
 +
* The kernel menu-driven configuration utility will be displayed. Features can be selected/deselected to be built into the kernel. Some features can be built as a loadable module, denoted by < >, and not built directly into the kernel.  
 +
{{ warning | Disabling  or modularizing some kernel features may prevent the kernel from starting correctly or at all. }}
  
# Copy the default configuration file to <code>.config</code> in the kernel source tree. This only needs to be done the first time that you start a new build from a blank configuration.
+
Use the space bar to select an option or the 'm' key to configure the selected option as a module. Select <code>Exit</code> to close the kernel configuration menu and save the configuration to the newly created build directory. When the same build-suffix is used for subsequent builds, this configuration will be used.  
<syntaxhighlight lang="bash">
+
</cl>
developer@ldc:~$ cp linux-2.6.25-ep93xx/arch/arm/configs/som9307_defconfig linux-2.6.25-ep93xx/.config
 
</syntaxhighlight>
 
# 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 <code>config</code> or <code>build</code>. 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 (<code>20090101</code>) or machine
 
name (<code>som9307</code>). Using <code>som9307</code> as the build-suffix will cause the kernel to be
 
built in a directory named <code>build-2.6.25-som9307</code>.
 
<syntaxhighlight lang="bash">
 
developer@ldc:~$ ./kernel-build-cross.sh linux-2.6.25-ep93xx config som9307
 
</syntaxhighlight>
 
# 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 <code>Exit</code>. The new configuration will be saved as <code>.config</code> 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 <code>.config</code> file from the kernel source tree and saves it to a file called <code>prevconfig</code> in the kernel source tree.
 
  
 
==Building the Kernel==
 
==Building the Kernel==
  
Once the kernel is configured, a new image can be built. Use the following steps to build a new kernel image:
+
<cl>
 +
1. Run the kernel-build-cross script again with the build option, this time using the same build-suffix used in the configuration step.
 +
 
 +
{{cli | username=developer | hostname=ldc |./kernel-build-cross.sh linux-at91 build som9x25}}
 +
 
 +
* The kernel will begin compiling now. This will take several minutes to complete depending on the kernel configuration and the speed of the development machine. Only move on to the next step if the build completes with no errors.
 +
 
 +
* The new kernel image will be in the <code>build-3.10.0-som9x25/Install/boot</code> directory. For the 3.10 and later device tree enabled ARM kernels, the image name will be a zImage. Also, the desired device tree blob (*.dtb) needs to be appended to the kernel. For earlier versions of the kernel, a uImage will be generated that can be loaded directly from U-Boot. X86 boards use a bzImage.
 +
 
 +
{{clo}}
 +
{{clio | username=developer | hostname=ldc |cd build-3.10.0-som9x25/Install/boot}}
 +
{{clio | username=developer | hostname=ldc |cat zImage-3.10.0 som-9x25-150es.dtb > zImage-boot}}
 +
{{clos}}
 +
 
 +
This is the image that will get loaded onto the board and executed by the bootloader. To load the new kernel onto the target machine, see the [[Loading Linux Kernels Onto a Board]] page.
 +
 
 +
The build script will also create an archive of all of the modules created during the build process and place it in the <code>build-3.10.0-som9x25/Install/</code> directory. The archive will be called <code>modules.tar.gz</code>.
 +
</cl>
 +
 
 +
==Loading Kernel Modules==
  
# Run the kernel build script with the build option, using the same build-suffix used in the configuration step.  
+
If the kernel is recompiled without changing the configuration or source code for any modules, it is not necessary to reload the modules archive. Alternatively, if a module was modified or added, it is only necessary to reload the modules archive.
<syntaxhighlight lang="bash">
+
To reload the modules:
developer@ldc:~$ ./kernel-build-cross.sh linux-2.6.25-ep93xx build som9307
+
<cl>
</syntaxhighlight>
+
1. Copy the archive to the root of the filesystem of the target machine
# 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.
 
# 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 <code>build-2.6.25-som9307/arch/arm/boot/zImage</code>. 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 <code>build-2.6.25-som9307/kernel-2.6.25.tar.gz</code>.
 
  
{{mbox | type = notice | text = Note that if you recompile the kernel but do not change the configuration or source code for any of the modules, it may not be necessary to reload the modules archive. This is often the case for custom driver development.}}
+
{{cli | username=developer | hostname=ldc |scp build-3.10.0-som9x25/Install/modules.tar.gz root@1IP_ADDRESS:/ }}
  
==Loading==
+
* Log onto the target machine
  
===Kernel Image===
+
{{cli | username=developer | hostname=ldc |ssh root@IP_ADDRESS}}
  
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. <code>kernel-2.6.25.tar.gz</code>) 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:
+
* Extract the kernel modules archive and force the kernel to reload the modules. Make sure that the root flash is mounted read/write before extracting.
  
# Load the kernel modules archive onto the board. The example below assumes that the IP address of the board is <code>10.0.2.41</code>.
+
{{clo}}
<syntaxhighlight lang="bash">
+
{{clio |cd /}}
developer@ldc:~$ scp build-2.6.25-som9307/kernel-2.6.25.tar.gz root@10.0.2.41:/tmp
+
{{clio |tar xzvf modules.tar.gz}}
</syntaxhighlight>
+
{{clio |depmod -a}}
# Extract the kernel modules archive to <code>/</code> 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:
+
{{clio |reboot}}
<syntaxhighlight lang="bash">
+
{{clos}}
root@emac-oe:~# cd /
+
</cl>
root@emac-oe:~# tar xzvf /tmp/kernel-2.6.25.tar.gz /lib/modules
 
</syntaxhighlight>
 
  
[[Category::Custom Development]]
+
{{:Templateimpl:moreinfo | initials=MG | title=System Logging | desc=The page describes how to build the linux kernel. | project=OE 5.0 }}
 +
* [[Loading_Linux_Kernels_Onto_a_Board | Loading Linux Kernels Onto a Board]]

Revision as of 10:24, 29 August 2017

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

  1. EMAC Software Development Kit OE 4 or OE 5
  2. Linux kernel source for target hardware (provided via EMAC public GIT server )
  3. Kernel build script

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

Setup

The steps below assume that the kernel-build-cross.sh script is located in the same directory as the kernel tree. Be sure to modify the environment.cfg.sh script for the correct architecture and EMAC OE version.

Configuring the Kernel

The first step for building the kernel is to configure it as desired. It is recommended to start with the kernel configuration file used by EMAC to build the kernel for the target device. Starting with EMAC OE 5, the kernel configuration can be obtained on a running board from /proc/config.gz. Please contact EMAC support for earlier EMAC OE versions.
The following are steps to configure the kernel:

  1. Copy the default configuration file to the same directory as the kernel source tree and kernel-build-cross.sh and rename it defconfig.

  2. The kernel-build-cross script accepts the SOURCE_TREE as the first argument and either config or build as the second argument. Optionally, a third argument, BUILD_SUFFIX may be supplied as a suffix to add to the build directory. BUILD_SUFFIX is commonly used to add a date tag or machine name to a build.

    developer@ldc:~# ./kernel-build-cross.sh linux-at91 config som9x25
  3. The kernel menu-driven configuration utility will be displayed. Features can be selected/deselected to be built into the kernel. Some features can be built as a loadable module, denoted by < >, and not built directly into the kernel.


    WARNING!
    Disabling or modularizing some kernel features may prevent the kernel from starting correctly or at all.


    Use the space bar to select an option or the 'm' key to configure the selected option as a module. Select Exit to close the kernel configuration menu and save the configuration to the newly created build directory. When the same build-suffix is used for subsequent builds, this configuration will be used.

Building the Kernel

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

    developer@ldc:~# ./kernel-build-cross.sh linux-at91 build som9x25
  2. The kernel will begin compiling now. This will take several minutes to complete depending on the kernel configuration and the speed of the development machine. Only move on to the next step if the build completes with no errors.

  3. The new kernel image will be in the build-3.10.0-som9x25/Install/boot directory. For the 3.10 and later device tree enabled ARM kernels, the image name will be a zImage. Also, the desired device tree blob (*.dtb) needs to be appended to the kernel. For earlier versions of the kernel, a uImage will be generated that can be loaded directly from U-Boot. X86 boards use a bzImage.

    developer@ldc:~# cd build-3.10.0-som9x25/Install/boot
    developer@ldc:~# cat zImage-3.10.0 som-9x25-150es.dtb > zImage-boot

    This is the image that will get loaded onto the board and executed by the bootloader. To load the new kernel onto the target machine, see the Loading Linux Kernels Onto a Board page.

    The build script will also create an archive of all of the modules created during the build process and place it in the build-3.10.0-som9x25/Install/ directory. The archive will be called modules.tar.gz.

Loading Kernel Modules

If the kernel is recompiled without changing the configuration or source code for any modules, it is not necessary to reload the modules archive. Alternatively, if a module was modified or added, it is only necessary to reload the modules archive. To reload the modules:

  1. Copy the archive to the root of the filesystem of the target machine

    developer@ldc:~# scp build-3.10.0-som9x25/Install/modules.tar.gz root@1IP_ADDRESS:/
  2. Log onto the target machine

    developer@ldc:~# ssh root@IP_ADDRESS
  3. Extract the kernel modules archive and force the kernel to reload the modules. Make sure that the root flash is mounted read/write before extracting.

    root@som9x25:~# cd /
    root@som9x25:~# tar xzvf modules.tar.gz
    root@som9x25:~# depmod -a
    root@som9x25:~# reboot

Further Information

Where to Go Next