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

(Placeholder page created)
(initial version; at least some layout fixing is needed)
Line 1: Line 1:
-
Placeholder for Maemo Kernel Guide.
+
= Kernel Guide =
-
How to develop maemo kernel and kernel modules...
+
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 =
 +
 
 +
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.
 +
 
 +
* Start Scratchbox. <br /><br />
 +
 +
$ scratchbox
 +
 
 +
* Create a new target called MaemoKernel with qemu-arm CPU transparency. The second command installs the armel rootstraps to the target. The last command installs the C-library, /etc, devkits and fakeroot. <br /><br />
 +
 +
[sbox-FREMANTLE_ARMEL: ~] &gt; sb-conf setup MaemoKernel \
 +
-c cs2007q3-glibc2.5-arm7 \
 +
-d qemu:perl:svn:apt-https -t /scratchbox/devkits/qemu/bin/qemu-arm-sb
 +
[sbox-FREMANTLE_ARMEL: ~] &gt; sb-conf select MaemoKernel
 +
[sbox-MaemoKernel: ~] &gt; sb-conf rs MaemoKernel \
 +
/home/&lt;username&gt;/maemo-sdk-rootstrap_5.0beta_armel.tgz
 +
[sbox-MaemoKernel: ~] &gt; sb-conf in MaemoKernel -edFL
 +
<br /><br /><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>
 +
* 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. <br /><br />
 +
 +
deb http://repository.maemo.org/ fremantle/sdk free non-free
 +
deb-src http://repository.maemo.org/ fremantle/sdk free
 +
 +
deb http://repository.maemo.org/ fremantle/tools free non-free
 +
deb-src http://repository.maemo.org/ fremantle/tools free
 +
 
 +
* Create a working directory (inside Scratchbox) for the kernel sources. <br /><br />
 +
 +
[sbox-MaemoKernel: ~] &gt; mkdir ~/maemo_kernel
 +
 
 +
 
 +
The Scratchbox environment is now ready for compiling the kernel.
 +
 
 +
= Getting Kernel Sources =
 +
 
 +
Kernel sources are not included in the rootstrap, and therefore need to be downloaded from the repository.
 +
 
 +
* Select the kernel compilation target, if not selected already. <br /><br />
 +
 +
[sbox-FREMANTLE_ARMEL: ~] &gt; sb-conf select MaemoKernel
 +
 
 +
* Update the package database. This requires the earlier modifications in the sources.list file. <br /><br />
 +
 +
[sbox-MaemoKernel: ~] &gt; fakeroot apt-get update
 +
 
 +
* Go to the working directory and fetch the sources. <br /><br />
 +
 +
[sbox-MaemoKernel: ~] &gt; cd ~/maemo_kernel
 +
[sbox-MaemoKernel: ~/maemo_kernel ] &gt; apt-get source kernel
 +
 
 +
 
 +
Kernel sources should now be fetched and ready to be compiled.
 +
 
 +
= Configuring Source Tree and Compiling Kernel =
 +
 
 +
* There is a source subdirectory. Enter the directory and create the default configuration. <br /><br />
 +
<nowiki>
 +
[sbox-MaemoKernel: ~/maemo_kernel ] &gt; cd kernel-2.6.28
 +
[sbox-MaemoKernel: ~/maemo_kernel/kernel-2.6.28] &gt; make EXTRAVERSION=-maemo2 rx51_defconfig
 +
# lots of output from make program...
 +
</nowiki>
 +
 
 +
* Compile the kernel image, and check the image file timestamp to ensure that it is properly created. <br /><br />
 +
<nowiki>
 +
[sbox-MaemoKernel: ~/maemo_kernel/kernel-2.6.28] &gt; make EXTRAVERSION=-maemo2 bzImage
 +
# compilation output...
 +
[sbox-MaemoKernel: ~/maemo_kernel/kernel-2.6.28] &gt; ls -l arch/arm/boot/zImage
 +
-rwxrwxr-x  1 maemo maemo 1717620 Jul 29 18:10 arch/arm/boot/zImage
 +
</nowiki>
 +
 
 +
 
 +
<br /><br /><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 should be performed outside Scratchbox. See section [[#Flashing Kernel]] for short flashing instructions.
 +
 
 +
= Changing Default Kernel Configuration =
 +
 
 +
The following steps describe how to change the default kernel configuration.
 +
 
 +
* Restore the original default configuration, just in case it has been changed. <br /><br />
 +
 +
[sbox-MaemoKernel: ~/maemo_kernel/kernel-2.6.28] &gt; make EXTRAVERSION=-maemo2 \
 +
rx51_defconfig
 +
 
 +
* 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. <br /><br />
 +
 +
[sbox-MaemoKernel: ~/maemo_kernel/kernel-2.6.28] &gt; vi .config
 +
 
 +
* Include your changes for compilation. <br /><br />
 +
 +
[sbox-MaemoKernel: ~/maemo_kernel/kernel-2.6.28] &gt; make EXTRAVERSION=-maemo2 oldconfig
 +
 
 +
 
 +
Now a kernel image with modified configuration can be recompiled, as described in the previous section.
 +
 
 +
= 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. The example is originally based on code [http://koltsoff.com/pub/hello-n800 here]. A real external kernel module could be a driver for an uncommon or new device or somespecial service for a system, but this example code only prints some helloworlds to kernel ring buffer.
 +
 
 +
# As before, start in the work directory. <pre>[sbox-MaemoKernel: ~/maemo_kernel] &gt;</pre>
 +
# Install the kernel-headers package. <pre>[sbox-MaemoKernel: ~/maemo_kernel] &gt; fakeroot apt-get install kernel-headers</pre>
 +
# Create a folder for the example. <pre>[sbox-MaemoKernel: ~/maemo_kernel] &gt; mkdir hello-module&#13;[sbox-MaemoKernel: ~/maemo_kernel] &gt; cd hello-module</pre>
 +
 
 +
<ol start=4>
 +
<li>Save the following code example as <code>hello.c</code> in the new folder:
 +
<pre>
 +
/* hello-module.c, an example kernel module */
 +
 
 +
#include &lt;linux/module.h&gt; /* needed by all kernel modules */
 +
#include &lt;linux/init.h&gt;  /* needed for custom init/exit functions */
 +
#include &lt;linux/kernel.h&gt; /* needed for KERN_ALERT macro */
 +
 
 +
/* Special macro to indicate license (to avoid tainting the kernel) */
 +
MODULE_LICENSE("GPLv2");
 +
 
 +
static int hello_init(void) {
 +
  printk(KERN_ALERT "Hello, world\n"); /* top priority message */
 +
  return 0;
 +
}
 +
 
 +
static void hello_exit(void)
 +
{
 +
printk(KERN_INFO "Goodbye, world\n");
 +
}
 +
 
 +
/* macros to mark modules init/exit funcs (run on insmod/rmmod) */
 +
module_init(hello_init);
 +
module_exit(hello_exit);
 +
</pre>
 +
</li>
 +
<li> Save the following code example as <code>Makefile</code><nowiki>: </nowiki>
 +
<pre>
 +
# Makefile for building the hello kernel module outside the kernel tree
 +
 
 +
KERNELDIR := /usr/src/kernel-headers
 +
 
 +
obj-m := hello.o
 +
 
 +
# default build target (uses kernel build (kbuild) system)
 +
all:
 +
$(MAKE) -C $(KERNELDIR) M=`pwd` EXTRAVERSION=-maemo2 modules
 +
 
 +
# target for cleaning up
 +
clean:
 +
$(RM) *.o .depend .*.cmd *.ko *.mod.c Module.symvers modules.order
 +
$(RM) -R .tmp_versions
 +
</pre></li>
 +
 
 +
<li> Compile the module.
 +
<pre>
 +
[sbox-MaemoKernel: ~/maemo_kernel/hello-module] &gt; make
 +
make -C /usr/src/kernel-headers M=`pwd` modules
 +
make[1]: Entering directory `/targets/MaemoKernel/usr/src/kernel-headers'
 +
  CC [M]  /home/maemo/maemo_kernel/hello-module/hello.o
 +
  Building modules, stage 2.
 +
  MODPOST 1 modules
 +
  CC      /home/maemo/maemo_kernel/hello-module/hello.mod.o
 +
  LD [M]  /home/maemo/maemo_kernel/hello-module/hello.ko
 +
make[1]: Leaving directory `/targets/MaemoKernel/usr/src/kernel-headers'
 +
[sbox-MaemoKernel: ~/maemo_kernel/hello-module] &gt;
 +
</pre></li>
 +
<li> Check the results.
 +
<pre>
 +
[sbox-MaemoKernel: ~/maemo_kernel/hello-module] &gt; ls -l
 +
total 148
 +
-rw-rw-r--  1 maemo maemo  223 Aug  6 14:51 Makefile
 +
-rw-rw-r--  1 maemo maemo    0 Aug  6 14:51 Module.symvers
 +
-rw-rw-r--  1 maemo maemo  692 Aug  6 14:50 hello.c
 +
-rw-rw-r--  1 maemo maemo 64037 Aug  6 14:51 hello.ko
 +
-rw-rw-r--  1 maemo maemo  663 Aug  6 14:51 hello.mod.c
 +
-rw-rw-r--  1 maemo maemo 32656 Aug  6 14:51 hello.mod.o
 +
-rw-rw-r--  1 maemo maemo 32400 Aug  6 14:51 hello.o
 +
-rw-rw-r--  1 maemo maemo    57 Aug  6 14:51 modules.order
 +
</pre></li>
 +
</ol>
 +
<br /><br /> File <code>hello.ko</code> is the new module. It can be installed by copying it to the device and running <br />
 +
Nokia-NXX-31-10:/home/user# insmod hello.ko
 +
and removed by calling
 +
Nokia-NXX-31-10:/home/user# rmmod hello.ko
 +
 
 +
<br />You can check that the module worked properly by examining the kernel ring buffer:
 +
 +
Nokia-NXX-31-10:/home/user# dmesg | tail
 +
...
 +
[11921.578338] Hello, world
 +
[11928.357696] Goodbye, world
 +
 
 +
<br />If there is a slight version mismatch betweeen 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 \
 +
-R .modinfo -R __versions hello.ko
 +
 
 +
<br /><br /> 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]
 +
* <nowiki>/scratchbox/users/&lt;username&gt;/home/&lt;username&gt;/maemo_kernel/kernel-2.6.28/Documentation/kbuild/modules.txt</nowiki>
 +
 
 +
 
 +
 
 +
= 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. 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.
 +
 
 +
* Go to your working directory with kernel sources. <br /><br />
 +
 +
[sbox-MaemoKernel:]&gt; cd  ~/maemo_kernel/kernel-2.6.28
 +
 
 +
* Edit the configuration file and define that the NFSD will be a kernel module. <br /><br />
 +
 +
[sbox-MaemoKernel: ~/maemo_kernel/kernel-2.6.28] &gt; vi .config
 +
<br /><br /> Find the location of the NFSD configuration. <br /><br />
 +
<nowiki>
 +
# CONFIG_NFSD is not set
 +
</nowiki>
 +
<br /><br /> Enable NFSD support as a module (m for module, Y for built-in). <br /><br />
 +
 +
CONFIG_NFSD=m
 +
 
 +
* As described in previous sections, refresh the configuration and build new modules. <br /><br />
 +
<nowiki>
 +
[sbox-MaemoKernel: ~/maemo_kernel/kernel-2.6.28] &gt; make EXTRAVERSION=-maemo2 oldconfig
 +
# lots of output here. Answer Y to NFSD_V3, default to others.
 +
[sbox-MaemoKernel: ~/maemo_kernel/kernel-2.6.28] &gt; make EXTRAVERSION=-maemo2 modules
 +
</nowiki>
 +
 
 +
* Check with the find command to see what kernel object files (extension .ko) there now are. <br /><br />
 +
 +
[sbox-MaemoKernel: ~/maemo_kernel/kernel-2.6.28] &gt; find . -name "*.ko" -ls
 +
  655362  804 -rw-rw-r--  1 maemo maemo  817889 Aug  4 16:57 ./fs/ext2/ext2.ko
 +
  630786  108 -rw-rw-r--  1 maemo maemo  106187 Aug  4 16:57 ./fs/exportfs/exp
 +
ortfs.ko
 +
1335340  144 -rw-rw-r--  1 maemo maemo  141168 Aug  4 16:57 ./fs/fat/vfat.ko
 +
...
 +
4595743 1328 -rw-rw-r--  1 maemo maemo  1354124 Aug  4 16:57 ./fs/nfsd/nfsd.ko
 +
...
 +
4074612  104 -rw-rw-r--  1 maemo maemo    98930 Aug  4 16:57 ./arch/arm/mach-o
 +
map2/dspbridge.ko
 +
<br /><br /> 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 where they have been saved in.
 +
 
 +
= Flashing Kernel =
 +
 
 +
The custom kernel can be flashed from outside the Scratchbox with the flasher tool via USB. <br />
 +
 
 +
<br />
 +
 
 +
<nowiki>
 +
# flasher -f -k /scratchbox/users/&lt;username&gt;/home/&lt;username&gt;/\
 +
maemo_kernel/kernel-2.6.28/arch/arm/boot/zImage
 +
</nowiki>

Revision as of 20:58, 26 August 2009

Contents

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.

Prerequisites

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.

  • Start Scratchbox.

$ scratchbox
  • Create a new target called MaemoKernel with qemu-arm CPU transparency. The second command installs the armel rootstraps to the target. The last command installs the C-library, /etc, devkits and fakeroot.

[sbox-FREMANTLE_ARMEL: ~] > sb-conf setup MaemoKernel \
-c cs2007q3-glibc2.5-arm7 \
-d qemu:perl:svn:apt-https -t /scratchbox/devkits/qemu/bin/qemu-arm-sb
[sbox-FREMANTLE_ARMEL: ~] > sb-conf select MaemoKernel
[sbox-MaemoKernel: ~] > sb-conf rs MaemoKernel \
/home/<username>/maemo-sdk-rootstrap_5.0beta_armel.tgz
[sbox-MaemoKernel: ~] > sb-conf in MaemoKernel -edFL


N.B.

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 /scratchbox/packages directory. This should be paid attention to, when running the sb-conf command above.
  • 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.

deb http://repository.maemo.org/ fremantle/sdk free non-free
deb-src http://repository.maemo.org/ fremantle/sdk free

deb http://repository.maemo.org/ fremantle/tools free non-free
deb-src http://repository.maemo.org/ fremantle/tools free
  • Create a working directory (inside Scratchbox) for the kernel sources.

[sbox-MaemoKernel: ~] > mkdir ~/maemo_kernel


The Scratchbox environment is now ready for compiling the kernel.

Getting Kernel Sources

Kernel sources are not included in the rootstrap, and therefore need to be downloaded from the repository.

  • Select the kernel compilation target, if not selected already.

[sbox-FREMANTLE_ARMEL: ~] > sb-conf select MaemoKernel
  • Update the package database. This requires the earlier modifications in the sources.list file.

[sbox-MaemoKernel: ~] > fakeroot apt-get update
  • Go to the working directory and fetch the sources.

[sbox-MaemoKernel: ~] > cd ~/maemo_kernel
[sbox-MaemoKernel: ~/maemo_kernel ] > apt-get source kernel


Kernel sources should now be fetched and ready to be compiled.

Configuring Source Tree and Compiling Kernel

  • There is a source subdirectory. Enter the directory and create the default configuration.

 [sbox-MaemoKernel: ~/maemo_kernel ] > cd kernel-2.6.28
 [sbox-MaemoKernel: ~/maemo_kernel/kernel-2.6.28] > make EXTRAVERSION=-maemo2 rx51_defconfig
 # lots of output from make program...
 
  • Compile the kernel image, and check the image file timestamp to ensure that it is properly created.

 [sbox-MaemoKernel: ~/maemo_kernel/kernel-2.6.28] > make EXTRAVERSION=-maemo2 bzImage
 # compilation output...
 [sbox-MaemoKernel: ~/maemo_kernel/kernel-2.6.28] > ls -l arch/arm/boot/zImage
 -rwxrwxr-x  1 maemo maemo 1717620 Jul 29 18:10 arch/arm/boot/zImage
 




N.B.

The kernel is very strict on versions. EXTRAVERSION=-maemo2 sets the version to match the default installation. Instead of always supplying it to the make command, as done in this chapter, it would be possible to modify the kernel Makefile. Another alternative would be to avoid using make directly and use dpkg-buildpackage -rfakeroot -b to compile the kernel.

Now the device can be flashed with the new kernel image using the Flasher tool. This should be performed outside Scratchbox. See section #Flashing Kernel for short flashing instructions.

Changing Default Kernel Configuration

The following steps describe how to change the default kernel configuration.

  • Restore the original default configuration, just in case it has been changed.

[sbox-MaemoKernel: ~/maemo_kernel/kernel-2.6.28] > make EXTRAVERSION=-maemo2 \
rx51_defconfig
  • 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.

[sbox-MaemoKernel: ~/maemo_kernel/kernel-2.6.28] > vi .config
  • Include your changes for compilation.

[sbox-MaemoKernel: ~/maemo_kernel/kernel-2.6.28] > make EXTRAVERSION=-maemo2 oldconfig


Now a kernel image with modified configuration can be recompiled, as described in the previous section.

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. The example is originally based on code here. A real external kernel module could be a driver for an uncommon or new device or somespecial service for a system, but this example code only prints some helloworlds to kernel ring buffer.

  1. As before, start in the work directory.
    [sbox-MaemoKernel: ~/maemo_kernel] >
  2. Install the kernel-headers package.
    [sbox-MaemoKernel: ~/maemo_kernel] > fakeroot apt-get install kernel-headers
  3. Create a folder for the example.
    [sbox-MaemoKernel: ~/maemo_kernel] > mkdir hello-module
[sbox-MaemoKernel: ~/maemo_kernel] > cd hello-module
  1. Save the following code example as hello.c in the new folder:
    /* hello-module.c, an example kernel module */
    
    #include <linux/module.h> /* needed by all kernel modules */
    #include <linux/init.h>   /* needed for custom init/exit functions */
    #include <linux/kernel.h> /* needed for KERN_ALERT macro */
    
    /* Special macro to indicate license (to avoid tainting the kernel) */
    MODULE_LICENSE("GPLv2");
    
    static int hello_init(void) {
      printk(KERN_ALERT "Hello, world\n"); /* top priority message */
      return 0;
    }
    
    static void hello_exit(void)
    {
    	printk(KERN_INFO "Goodbye, world\n");
    }
    
    /* macros to mark modules init/exit funcs (run on insmod/rmmod) */
    module_init(hello_init);
    module_exit(hello_exit);
    
  2. Save the following code example as Makefile:
    # Makefile for building the hello kernel module outside the kernel tree
    
    KERNELDIR := /usr/src/kernel-headers
    
    obj-m := hello.o
    
    # default build target (uses kernel build (kbuild) system)
    all:
    	$(MAKE) -C $(KERNELDIR) M=`pwd` EXTRAVERSION=-maemo2 modules
    
    # target for cleaning up
    clean:
    	$(RM) *.o .depend .*.cmd *.ko *.mod.c Module.symvers modules.order
    	$(RM) -R .tmp_versions
    
  3. Compile the module.
     
    [sbox-MaemoKernel: ~/maemo_kernel/hello-module] > make
    make -C /usr/src/kernel-headers M=`pwd` modules
    make[1]: Entering directory `/targets/MaemoKernel/usr/src/kernel-headers'
      CC [M]  /home/maemo/maemo_kernel/hello-module/hello.o
      Building modules, stage 2.
      MODPOST 1 modules
      CC      /home/maemo/maemo_kernel/hello-module/hello.mod.o
      LD [M]  /home/maemo/maemo_kernel/hello-module/hello.ko
    make[1]: Leaving directory `/targets/MaemoKernel/usr/src/kernel-headers'
    [sbox-MaemoKernel: ~/maemo_kernel/hello-module] >
    
  4. Check the results.
     
    [sbox-MaemoKernel: ~/maemo_kernel/hello-module] > ls -l
    total 148
    -rw-rw-r--  1 maemo maemo   223 Aug  6 14:51 Makefile
    -rw-rw-r--  1 maemo maemo     0 Aug  6 14:51 Module.symvers
    -rw-rw-r--  1 maemo maemo   692 Aug  6 14:50 hello.c
    -rw-rw-r--  1 maemo maemo 64037 Aug  6 14:51 hello.ko
    -rw-rw-r--  1 maemo maemo   663 Aug  6 14:51 hello.mod.c
    -rw-rw-r--  1 maemo maemo 32656 Aug  6 14:51 hello.mod.o
    -rw-rw-r--  1 maemo maemo 32400 Aug  6 14:51 hello.o
    -rw-rw-r--  1 maemo maemo    57 Aug  6 14:51 modules.order
    



File hello.ko is the new module. It can be installed by copying it to the device and running

Nokia-NXX-31-10:/home/user# insmod hello.ko

and removed by calling

Nokia-NXX-31-10:/home/user# rmmod hello.ko


You can check that the module worked properly by examining the kernel ring buffer:

Nokia-NXX-31-10:/home/user# dmesg | tail
...
[11921.578338] Hello, world
[11928.357696] Goodbye, world


If there is a slight version mismatch betweeen SDK's kernel headers and the running kernel on device, insmod 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] > objcopy --strip-debug \
-R .modinfo -R __versions hello.ko



For additional reading on kernel modules, see, e.g.:


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. 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.

  • Go to your working directory with kernel sources.

[sbox-MaemoKernel:]> cd  ~/maemo_kernel/kernel-2.6.28
  • Edit the configuration file and define that the NFSD will be a kernel module.

[sbox-MaemoKernel: ~/maemo_kernel/kernel-2.6.28] > vi .config



Find the location of the NFSD configuration.

 # CONFIG_NFSD is not set
 



Enable NFSD support as a module (m for module, Y for built-in).

CONFIG_NFSD=m
  • As described in previous sections, refresh the configuration and build new modules.

 [sbox-MaemoKernel: ~/maemo_kernel/kernel-2.6.28] > make EXTRAVERSION=-maemo2 oldconfig
 # lots of output here. Answer Y to NFSD_V3, default to others.
 [sbox-MaemoKernel: ~/maemo_kernel/kernel-2.6.28] > make EXTRAVERSION=-maemo2 modules
 
  • Check with the find command to see what kernel object files (extension .ko) there now are.

[sbox-MaemoKernel: ~/maemo_kernel/kernel-2.6.28] > find . -name "*.ko" -ls
 655362  804 -rw-rw-r--   1 maemo maemo   817889 Aug  4 16:57 ./fs/ext2/ext2.ko
 630786  108 -rw-rw-r--   1 maemo maemo   106187 Aug  4 16:57 ./fs/exportfs/exp
ortfs.ko
1335340  144 -rw-rw-r--   1 maemo maemo   141168 Aug  4 16:57 ./fs/fat/vfat.ko
...
4595743 1328 -rw-rw-r--   1 maemo maemo  1354124 Aug  4 16:57 ./fs/nfsd/nfsd.ko
...
4074612  104 -rw-rw-r--   1 maemo maemo    98930 Aug  4 16:57 ./arch/arm/mach-o
map2/dspbridge.ko



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 /lib/modules/. However, the insmod command can be used to load the modules into the running kernel from any directory where they have been saved in.

Flashing Kernel

The custom kernel can be flashed from outside the Scratchbox with the flasher tool via USB.


 # flasher -f -k /scratchbox/users/<username>/home/<username>/\
 maemo_kernel/kernel-2.6.28/arch/arm/boot/zImage