Editing Documentation/Maemo 5 Developer Guide/Kernel and Debugging Guide/Maemo Kernel Guide

Warning: You are not logged in. Your IP address will be recorded in this page's edit history.
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 1: Line 1:
 +
= Kernel Guide =
 +
This chapter describes how to configure, compile and flash the Linux kernel for the Internet Tablet device. The chapter is targeted at developers wishing to compile their own custom kernels for the device.
This chapter describes how to configure, compile and flash the Linux kernel for the Internet Tablet device. The chapter is targeted at developers wishing to compile their own custom kernels for the device.
== Prerequisites ==
== Prerequisites ==
-
Before starting, set up the Maemo environment. The required GCC toolchain that is used to compile the kernel is included in Scratchbox by default.
+
Before starting, the maemo environment should be set up. The required GCC toolchain that is used to compile the kernel is included in the Scratchbox by default.
 +
 
 +
It is not mandatory to set up a separate target for kernel compilation, but this example does it in case the default armel target has been modified in some special way.
-
Setting up a separate target for kernel compilation is not mandatory, but this example does it in case the default armel target has been modified in some way.
 
<ul>
<ul>
Line 24: Line 27:
[sbox-FREMANTLE_ARMEL: ~] > sb-conf select MaemoKernel
[sbox-FREMANTLE_ARMEL: ~] > sb-conf select MaemoKernel
[sbox-MaemoKernel: ~] > sb-conf rs MaemoKernel \
[sbox-MaemoKernel: ~] > sb-conf rs MaemoKernel \
-
/home/&lt;username&gt;/maemo-sdk-rootstrap_5.0_armel.tgz
+
/home/&lt;username&gt;/maemo-sdk-rootstrap_5.0beta_armel.tgz
[sbox-MaemoKernel: ~] > sb-conf in MaemoKernel -edFL
[sbox-MaemoKernel: ~] > sb-conf in MaemoKernel -edFL
</pre></li>
</pre></li>
 +
</ul>
</ul>
 +
<div style="border: 2px solid rgb(255, 215, 0); background-color: rgb(252, 233, 79); margin-left: 25px; margin-right: 25px; padding: 2px"> N.B. <br /><br /> The &lt;username&gt; above refers to your login name in the environment. If you have used the maemo installer, the rootstraps are under your home directory. If you have performed a manual installation, the rootstrap is under /scratchbox/packages directory. This should be paid attention to, when running the sb-conf command above. </div>
-
{{ambox|text=The <username> above refers to your login name in the environment. If you have used the Maemo installer, the rootstraps are under your home directory. If you have performed a manual installation, the rootstrap is under the /scratchbox/packages directory. Keep this in mind when running the sb-conf command above.}}
 
<ul>
<ul>
<li>
<li>
-
Verify that the sources.list file inside the Scratchbox environment is correct. If the below lines are not in the /etc/apt/sources.list file, add them there.
+
Verify that the sources.list file inside the scratchbox environment is correct. If the below lines are not in the /etc/apt/sources.list file, add them there.
</li>
</li>
Line 54: Line 58:
== Getting Kernel Sources ==
== Getting Kernel Sources ==
-
Kernel sources are not included in the rootstrap. Therefore, you need to download them from the repository.
+
Kernel sources are not included in the rootstrap, and therefore need to be downloaded from the repository.
<ul>
<ul>
Line 62: Line 66:
[sbox-FREMANTLE_ARMEL: ~] > sb-conf select MaemoKernel
[sbox-FREMANTLE_ARMEL: ~] > sb-conf select MaemoKernel
</pre></li>
</pre></li>
 +
<li>Update the package database. This requires the earlier modifications in the sources.list file.</li>
<li>Update the package database. This requires the earlier modifications in the sources.list file.</li>
Line 82: Line 87:
<ul>
<ul>
-
<li>A source subdirectory is listed. Enter the directory and create the default configuration.</li>
+
<li>There is a source subdirectory. Enter the directory and create the default configuration.</li>
<li><pre>
<li><pre>
[sbox-MaemoKernel: ~/maemo_kernel ] > cd kernel-2.6.28
[sbox-MaemoKernel: ~/maemo_kernel ] > cd kernel-2.6.28
-
[sbox-MaemoKernel: ~/maemo_kernel/kernel-2.6.28] > make EXTRAVERSION=-omap1 rx51_defconfig
+
[sbox-MaemoKernel: ~/maemo_kernel/kernel-2.6.28] > make EXTRAVERSION=-maemo2 rx51_defconfig
  # lots of output from make program...
  # lots of output from make program...
</pre></li>
</pre></li>
-
<li>Compile the kernel image and check the image file timestamp to ensure that it is properly created.</li>
+
<li>Compile the kernel image, and check the image file timestamp to ensure that it is properly created.</li>
<li><pre>
<li><pre>
-
[sbox-MaemoKernel: ~/maemo_kernel/kernel-2.6.28] &gt; make EXTRAVERSION=-omap1 bzImage
+
[sbox-MaemoKernel: ~/maemo_kernel/kernel-2.6.28] &gt; make EXTRAVERSION=-maemo2 bzImage
# compilation output...
# compilation output...
[sbox-MaemoKernel: ~/maemo_kernel/kernel-2.6.28] &gt; ls -l arch/arm/boot/zImage
[sbox-MaemoKernel: ~/maemo_kernel/kernel-2.6.28] &gt; ls -l arch/arm/boot/zImage
Line 100: Line 105:
</ul>
</ul>
-
{{ambox|text=The kernel is very strict on versions. <code>EXTRAVERSION=-omap1</code> sets the version to match the default installation. Instead of always supplying it to the <code>make</code> command, as done in this chapter, it is possible to modify the kernel <code>Makefile</code>. Another alternative is to avoid using <code>make</code> directly and use <code>dpkg-buildpackage -rfakeroot -b</code> to compile the kernel.}}
+
<div style="border: 2px solid rgb(255, 215, 0); background-color: rgb(252, 233, 79); margin-left: 25px; margin-right: 25px; padding: 2px"> N.B. <br /><br /> The kernel is very strict on versions. <code>EXTRAVERSION=-maemo2</code> sets the version to match the default installation. Instead of always supplying it to the <code>make</code> command, as done in this chapter, it would be possible to modify the kernel <code>Makefile</code>. Another alternative would be to avoid using <code>make</code> directly and use <code>dpkg-buildpackage -rfakeroot -b</code> to compile the kernel. </div>
-
Now the device can be flashed with the new kernel image using the Flasher tool. This must be performed outside Scratchbox. For short instructions on flashing, see the [[Documentation/Maemo 5 Developer Guide/Development Environment/Maemo Flasher-3.5|Flashing Kernel]] section.
+
Now the device can be flashed with the new kernel image using the Flasher tool. This should be performed outside Scratchbox. See section [[Documentation/Maemo 5 Developer Guide/Development Environment/Maemo Flasher-3.5|Flashing Kernel]] for short flashing instructions.
== Changing Default Kernel Configuration ==
== Changing Default Kernel Configuration ==
Line 113: Line 118:
   
   
<li><pre>
<li><pre>
-
[sbox-MaemoKernel: ~/maemo_kernel/kernel-2.6.28] > make EXTRAVERSION=-omap1 \
+
[sbox-MaemoKernel: ~/maemo_kernel/kernel-2.6.28] > make EXTRAVERSION=-maemo2 \
rx51_defconfig
rx51_defconfig
</pre></li>
</pre></li>
-
<li>Edit the configuration file with your chosen editor. Editing the file is OK even though the system warns against it.</li>
+
<li>Edit the configuration file with your editor of choice. It is all right to edit the file, even though there is a warning against changing it included.</li>
   
   
<li><pre>
<li><pre>
Line 126: Line 131:
<li><pre>
<li><pre>
-
[sbox-MaemoKernel: ~/maemo_kernel/kernel-2.6.28] > make EXTRAVERSION=-omap1 oldconfig
+
[sbox-MaemoKernel: ~/maemo_kernel/kernel-2.6.28] > make EXTRAVERSION=-maemo2 oldconfig
</pre></li>
</pre></li>
</ul>
</ul>
-
Now a kernel image with modified configuration can be recompiled.
+
Now a kernel image with modified configuration can be recompiled, as described in the previous section.
-
 
+
-
If you have a local repository, by default extra information will be appended to the kernel version. This will stop the kernel version from matching the default install.  To keep it from doing so, change scripts/setlocalversion to add "exit" to the beginning:
+
-
<source lang="bash">
+
-
#!/bin/sh
+
-
# Print additional version information for non-release trees.
+
-
exit
+
-
</source>
+
== Compiling External Kernel Modules ==
== Compiling External Kernel Modules ==
-
In this section, a simple external, or out-of-tree, kernel module is built against the kernel-headers. This is the recommended way of building new modules. A real external kernel module can be a driver for an uncommon or new device or some special service for a system, but this example code only prints some helloworlds to the kernel ring buffer.
+
In this section, a simple external, or out-of-tree, kernel module is built against the kernel-headers. This is the recommended way of building new modules. A real external kernel module could be a driver for an uncommon or new device or some special service for a system, but this example code only prints some helloworlds to the kernel ring buffer.
# As before, start in the work directory. <pre>[sbox-MaemoKernel: ~/maemo_kernel] ></pre>
# As before, start in the work directory. <pre>[sbox-MaemoKernel: ~/maemo_kernel] ></pre>
-
# Install the kernel-headers package. <pre>[sbox-MaemoKernel: ~/maemo_kernel] > fakeroot apt-get install kernel-headers</pre>
+
# Install the kernel-headers package. <pre>[sbox-MaemoKernel: ~/maemo_kernel] &gt; fakeroot apt-get install kernel-headers</pre>
<ol start=3>  
<ol start=3>  
-
<li> Download the example files from the Maemo svn.
+
<li> Download the example files from maemo svn.
<pre>
<pre>
-
[sbox-MaemoKernel: ~/maemo_kernel] > svn export https://vcs.maemo.org/svn/\
+
[sbox-MaemoKernel: ~/maemo_kernel] > svn export https://garage.maemo.org/svn/\
-
maemoexamples/tags/maemo_5.0/hello-module/
+
maemoexamples/trunk/hello-module/
[sbox-MaemoKernel: ~/maemo_kernel] > cd hello-module
[sbox-MaemoKernel: ~/maemo_kernel] > cd hello-module
Line 188: Line 186:
module_exit(hello_exit);
module_exit(hello_exit);
</pre>
</pre>
-
 
+
Compiling kernel modules differs from compiling  
-
Compiling kernel modules differs from compiling normal programs. That is reflected in the <code>Makefile</code>:
+
normal programs. That is reflected in the <code>Makefile</code>:
-
 
+
<pre>
<pre>
[sbox-MaemoKernel: ~/maemo_kernel/hello-module] > cat Makefile
[sbox-MaemoKernel: ~/maemo_kernel/hello-module] > cat Makefile
Line 201: Line 198:
# default build target (uses kernel build (kbuild) system)
# default build target (uses kernel build (kbuild) system)
all:
all:
-
$(MAKE) -C $(KERNELDIR) M=`pwd` EXTRAVERSION=-omap1 modules
+
$(MAKE) -C $(KERNELDIR) M=`pwd` EXTRAVERSION=-maemo2 modules
# target for cleaning up
# target for cleaning up
Line 208: Line 205:
$(RM) -R .tmp_versions
$(RM) -R .tmp_versions
</pre>
</pre>
-
 
The <code>all:</code> target compiles the module, not using this <code>Makefile</code>,
The <code>all:</code> target compiles the module, not using this <code>Makefile</code>,
but a <code>Makefile</code> in the kernel headers folder set in variable  
but a <code>Makefile</code> in the kernel headers folder set in variable  
Line 214: Line 210:
</li>
</li>
-
<li>Compile the module.
+
<li> Compile the module.
-
<pre>
+
<pre>  
[sbox-MaemoKernel: ~/maemo_kernel/hello-module] &gt; make
[sbox-MaemoKernel: ~/maemo_kernel/hello-module] &gt; make
make -C /usr/src/kernel-headers M=`pwd` modules
make -C /usr/src/kernel-headers M=`pwd` modules
Line 228: Line 224:
</pre></li>
</pre></li>
<li> Check the results.  
<li> Check the results.  
-
<pre>
+
<pre>  
[sbox-MaemoKernel: ~/maemo_kernel/hello-module] &gt; ls -l
[sbox-MaemoKernel: ~/maemo_kernel/hello-module] &gt; ls -l
total 148
total 148
Line 242: Line 238:
</ol>
</ol>
-
File <code>hello.ko</code> is the new module. Install it by copying it to the device and running it (as root)
+
 
 +
File <code>hello.ko</code> is the new module. It can be installed by copying it to the device and running (as root)
  Nokia-NXX-31-10:/home/user# insmod hello.ko
  Nokia-NXX-31-10:/home/user# insmod hello.ko
-
and remove it by calling  
+
and removed by calling  
  Nokia-NXX-31-10:/home/user# rmmod hello.ko
  Nokia-NXX-31-10:/home/user# rmmod hello.ko
-
Check that the module worked properly by examining the kernel ring buffer:
+
 
 +
You can check that the module worked properly by examining the kernel ring buffer:
   
   
  Nokia-NXX-31-10:/home/user# dmesg | tail
  Nokia-NXX-31-10:/home/user# dmesg | tail
Line 254: Line 252:
  [11928.357696] Goodbye, world
  [11928.357696] Goodbye, world
-
If there is a slight version mismatch between SDK's kernel headers and the running kernel on device, <code>insmod</code> refuses to install the module with the error message <code>insmod: error inserting '<module>': -1 Invalid module format</code>. In this case, install the module by stripping version info from it before installation:
+
If there is a slight version mismatch between SDK's kernel headers and the running kernel on device, <code>insmod</code> refuses to install the module. In this case, you can install the module by stripping version info from it before installation:
   
   
  [sbox-FREMANTLE_ARMEL: ~/maemo_kernel/hello-module] &gt; objcopy --strip-debug \  
  [sbox-FREMANTLE_ARMEL: ~/maemo_kernel/hello-module] &gt; objcopy --strip-debug \  
  -R .modinfo -R __versions hello.ko
  -R .modinfo -R __versions hello.ko
-
For more information on kernel modules, see the following:
+
For additional reading on kernel modules, see, e.g.:
* [http://www.tldp.org/LDP/lkmpg/2.6/html/index.html The Linux Kernel Module Programming Guide]
* [http://www.tldp.org/LDP/lkmpg/2.6/html/index.html The Linux Kernel Module Programming Guide]
Line 266: Line 264:
== Compiling Internal Kernel Modules ==
== Compiling Internal Kernel Modules ==
-
This section explains how to configure and compile additional kernel modules included in the kernel source tree for the Internet Tablet in the Maemo environment. The NFSD module is used as an example. In this section, the modules are compiled against the full kernel source tree, not the kernel headers package. This example compiles all configured modules at once.
+
This section explains how to configure and compile additional kernel modules included in the kernel source tree for the Internet Tablet in the maemo environment. NFSD module is used as an example. In this section, the modules are compiled against the full kernel source tree, not the kernel headers package. This example compiles all configured modules at once.
 +
 
<ul>
<ul>
Line 275: Line 274:
</pre></li>
</pre></li>
-
<li> Edit the configuration file and define that the NFSD is a kernel module.</li>
+
<li> Edit the configuration file and define that the NFSD will be a kernel module.</li>
<li><pre>
<li><pre>
Line 287: Line 286:
</pre></li>
</pre></li>
-
<li>Enable NFSD support as a module (m for module, Y for built-in).
+
<li>Enable NFSD support as a module (m for module, Y for built-in). </pre>
   
   
<li><pre>
<li><pre>
CONFIG_NFSD=m
CONFIG_NFSD=m
-
</pre></li>
+
</li></pre>
 +
 
 +
<li>As described in previous sections, refresh the configuration and build new modules.</li>
-
<li>As described in the previous sections, refresh the configuration and build new modules.</li>
 
<li><pre>
<li><pre>
-
[sbox-MaemoKernel: ~/maemo_kernel/kernel-2.6.28] > make EXTRAVERSION=-omap1 oldconfig
+
[sbox-MaemoKernel: ~/maemo_kernel/kernel-2.6.28] > make EXTRAVERSION=-maemo2 oldconfig
# lots of output here. Answer Y to NFSD_V3, default to others.
# lots of output here. Answer Y to NFSD_V3, default to others.
-
[sbox-MaemoKernel: ~/maemo_kernel/kernel-2.6.28] > make EXTRAVERSION=-omap1 modules
+
[sbox-MaemoKernel: ~/maemo_kernel/kernel-2.6.28] > make EXTRAVERSION=-maemo2 modules
-
</pre></li>
+
</li></pre>
-
<li>Check with the find command to see which kernel object files (extension .ko) now exist.</li>
+
<li>Check with the find command to see what kernel object files (extension .ko) there now are.</li>
   
   
<li><pre>
<li><pre>
Line 314: Line 314:
4074612  104 -rw-rw-r--  1 maemo maemo    98930 Aug  4 16:57 ./arch/arm/mach-o
4074612  104 -rw-rw-r--  1 maemo maemo    98930 Aug  4 16:57 ./arch/arm/mach-o
map2/dspbridge.ko
map2/dspbridge.ko
-
</pre></li>
+
</li></pre>
</ul>
</ul>
-
The list of .ko files is quite long, depending on whether or not some additional changes were made to the .config file. Module <code>nfsd.ko</code> is the one just added.
+
The list of .ko files is will be quite long, depending on whether some additional changes were made to the .config file. Module nfsd.ko is the one just added.
-
The kernel modules are kept under <code>/lib/modules/</code>. However, the <code>insmod</code> command can be used to load the modules into the running kernel from any directory they have been saved in.
+
The kernel modules are kept under <code>/lib/modules/</code>. However, the <code>insmod</code> command can be used to load the modules into the running kernel from any directory where they have been saved in.
-
 
+
-
== Using make menuconfig ==
+
-
 
+
-
'make menuconfig' fails to autodetect the ncurses library available in Scratchbox and exits with an error.  If you want to use 'make menuconfig', first edit <code>scripts/kconfig/lxdialog/check-lxdialog.sh</code> and change
+
-
 
+
-
<pre>
+
-
# What library to link
+
-
ldflags()
+
-
{
+
-
for ext in so a dylib ; do
+
-
</pre>
+
-
 
+
-
to
+
-
 
+
-
<pre>
+
-
# What library to link
+
-
ldflags()
+
-
{
+
-
# XXX autodetection fails in scratchbox
+
-
echo -lncurses
+
-
exit
+
-
for ext in so a dylib ; do
+
-
</pre>
+
== Flashing Kernel ==
== Flashing Kernel ==
-
You can flash the custom kernel from outside Scratchbox with the flasher tool using USB.
+
The custom kernel can be flashed from outside the Scratchbox with the flasher tool via USB.
-
  # flasher-3.5 -f -k /scratchbox/users/&lt;username&gt;/home/&lt;username&gt;/\
+
  # flasher -f -k /scratchbox/users/&lt;username&gt;/home/&lt;username&gt;/\
  maemo_kernel/kernel-2.6.28/arch/arm/boot/zImage
  maemo_kernel/kernel-2.6.28/arch/arm/boot/zImage
-
 
-
== Testing kernel ==
 
-
 
-
It is possible to try the custom kernel without flashing it by temporarily changing arch/arm/plat-omap/bootreason.c as follows:
 
-
 
-
<pre>
 
-
// len += sprintf(page + len, "%s\n", boot_reason);
 
-
len += sprintf(page + len, "pwr_key\n");
 
-
</pre>
 
-
 
-
For the flasher tool, use
 
-
 
-
# flasher-3.5 -l -b -k /scratchbox/users/&lt;username&gt;/home/&lt;username&gt;/\
 
-
maemo_kernel/kernel-2.6.28/arch/arm/boot/zImage
 
-
 
-
[[Category:Development]]
 
-
[[Category:Documentation]]
 
-
[[Category:Fremantle]]
 

Learn more about Contributing to the wiki.


Please note that all contributions to maemo.org wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see maemo.org wiki:Copyrights for details). Do not submit copyrighted work without permission!


Cancel | Editing help (opens in new window)

Templates used on this page: