Difference between revisions of "Building the Linux Kernel"

From wiki.emacinc.com
Jump to: navigation, search
 
(11 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{todo|SEOKWREV (11.26.13-22:10->MD+)(12.10.13-14:45->MG+);(12.17.13-12:10->KY+);(03.04.14-16:30->BS-);(03.26.14-17:10->BS+)|Mike Dean|project=md,oe 4,oe 5,SEOKWREV,mg,ky,bs}}
 
 
 
{{#seo:
 
{{#seo:
 
|title=Building the Linux Kernel  
 
|title=Building the Linux Kernel  
Line 9: Line 7:
 
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:  
 
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:  
  
# EMAC Software Development Kit [ftp://ftp.emacinc.com/Controllers/Development_Kits/EMAC_Open_Tools/Linux/EMAC-OE-arm-linux-gnueabi-SDK_4.0.r3.tar.bz2 SDK]
+
# 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 (provided via EMAC public [https://svn.emacinc.com/listing.php?repname=EMAC+Public+Repository&path=%2F&sc=0 SVN server ] )
+
# Linux kernel source for target hardware (provided via EMAC public [http://git.emacinc.com/Linux-Kernel GIT server] )
# [ftp://ftp.emacinc.com/Controllers/Development_Kits/EMAC_Open_Tools/Linux/kernel-build-cross_svn-r1897.tar.gz Kernel build script]
+
# [ftp://ftp.emacinc.com/EMAC_Linux/SDK/kernel-build-cross.tar.gz Kernel build script]
 
 
The example below will assume that a kernel image for the SoM-9307 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-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==
 
==Setup==
  
 
The steps below assume that the <code>kernel-build-cross.sh</code> script is
 
The steps below assume that the <code>kernel-build-cross.sh</code> script is
located in the same directory as the kernel tree. Be sure to modify the <code>environment.cfg.sh</code> script
+
located in the same directory as the kernel tree. Be sure to modify the <code>environment.cfg.sh</code> script for the correct
so that the SDKLOC variable references the location of the SDK and that the appropriate ARCH_FLAGS and CROSS variables are used.
+
architecture and EMAC OE version.
  
 
==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.0, the kernel configuration can be
provides default configuration files as a part of the kernel tree. For the SoM-9307, this file is
+
obtained on a running board from /proc/config.gz. Please contact [http://www.emacinc.com/support EMAC support]
<code>linux-2.6.25-ep93xx/arch/arm/configs/som9307_defconfig</code>. The following are steps to configure
+
for earlier EMAC OE versions.
the kernel:
+
<br >
 
+
The following are steps to configure the kernel:
 
<cl>
 
<cl>
1. Copy the default configuration file to the kernel source tree and rename it .config.  
+
1. Copy the default configuration file to the same directory as the kernel source tree and kernel-build-cross.sh and rename it defconfig.  
  
<syntaxhighlight lang="bash">
+
* 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 tag or machine name to a build.
developer@ldc:~$ cp linux-2.6.25-ep93xx/arch/arm/configs/som9307_defconfig linux-2.6.25-ep93xx/.config
 
</syntaxhighlight>
 
  
* 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-emac config som9x25}}
 
 
<syntaxhighlight lang="bash">
 
developer@ldc:~$ ./kernel-build-cross.sh linux-2.6.25-ep93xx config som9307
 
</syntaxhighlight>
 
  
 
* 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.  
 
* 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. }}
{{ imbox | type = speedy | style = margin-bottom: 0.5em; | text = 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 <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.  
 
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.  
Line 53: Line 42:
  
 
<cl>
 
<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.  
+
1. Run the kernel-build-cross script again with the build option, this time using the same build-suffix used in the configuration step.  
  
<syntaxhighlight lang="bash">
+
{{cli | username=developer | hostname=ldc |./kernel-build-cross.sh linux-emac build som9x25}}
developer@ldc:~$ ./kernel-build-cross.sh linux-2.6.25-ep93xx build som9307
 
</syntaxhighlight>
 
  
* The kernel will begin compiling now. This will take several minutes to complete depending 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 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-2.6.25-BUILD_SUFFIX/arch/arm/boot</code> directory called uImage. 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 new kernel image will be in the <code>build-4.9.224-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.
  
The build script will also create an archive of all of the modules created during the build process and place it in the build directory. The archive will be called <code>build-2.6.25-BUILD_SUFFIX/kernel-2.6.25.tar.gz</code>.
+
{{clo}}
 +
{{clio | username=developer | hostname=ldc |cd build-4.9.224-som9x25/Install/boot}}
 +
{{clio | username=developer | hostname=ldc |cat zImage-4.9.224 som-9x25-150es.dtb > zImage-som9x25}}
 +
{{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-4.9.225-som9x25/Install/</code> directory. The archive will be called <code>modules.tar.gz</code>.
 
</cl>
 
</cl>
  
 
==Loading Kernel Modules==
 
==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.
+
After re-compiling the kernel, it is recommended to load the corresponding kernel modules.
 +
 
 
To reload the modules:
 
To reload the modules:
 
<cl>
 
<cl>
1. Copy the archive to the root of the filesystem of the target machine
+
1. Make sure that the root flash is mounted read/write before copying the modules to the target.
  
<syntaxhighlight lang="bash">
+
* Copy the archive to the root of the filesystem of the target machine
developer@ldc:~$ scp build-2.6.25-som9307/kernel-2.6.25.tar.gz root@1IP_ADDRESS:/  
+
 
</syntaxhighlight>
+
{{cli | username=developer | hostname=ldc |scp build-4.9.224-som9x25/Install/modules.tar.gz root@1IP_ADDRESS:/ }}
  
 
* Log onto the target machine
 
* Log onto the target machine
  
<syntaxhighlight lang="bash">
+
{{cli | username=developer | hostname=ldc |ssh root@IP_ADDRESS}}
developer@ldc:~$ ssh root@IP_ADDRESS</syntaxhighlight>
 
  
* 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.
+
* Extract the kernel modules archive and force the kernel to reload the modules.
  
<syntaxhighlight lang="bash">
+
{{clo}}
root@emac-oe:~# cd /
+
{{clio |cd /}}
root@emac-oe:~# tar xzvf kernel-2.6.25.tar.gz
+
{{clio |tar xzvf modules.tar.gz}}
root@emac-oe:~# depmod -a
+
{{clio |depmod -a}}
</syntaxhighlight>
+
{{clio |reboot}}
 +
{{clos}}
 
</cl>
 
</cl>
<!--
+
 
[[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]]

Latest revision as of 11:32, 26 September 2020

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.0, 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 tag or machine name to a build.

    developer@ldc:~# ./kernel-build-cross.sh linux-emac 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-emac 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-4.9.224-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-4.9.224-som9x25/Install/boot
    developer@ldc:~# cat zImage-4.9.224 som-9x25-150es.dtb > zImage-som9x25

    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-4.9.225-som9x25/Install/ directory. The archive will be called modules.tar.gz.

Loading Kernel Modules

After re-compiling the kernel, it is recommended to load the corresponding kernel modules.

To reload the modules:

  1. Make sure that the root flash is mounted read/write before copying the modules to the target.

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

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

    developer@ldc:~# ssh root@IP_ADDRESS
  4. Extract the kernel modules archive and force the kernel to reload the modules.

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

Further Information

Where to Go Next