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 = | |
- | Before starting, | + | 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: ~] > sb-conf setup MaemoKernel \ | |
- | + | -c cs2007q3-glibc2.5-arm7 \ | |
- | + | -d qemu:perl:svn:apt-https -t /scratchbox/devkits/qemu/bin/qemu-arm-sb | |
- | 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 select MaemoKernel |
- | </ | + | [sbox-MaemoKernel: ~] > sb-conf rs MaemoKernel \ |
- | + | /home/<username>/maemo-sdk-rootstrap_5.0beta_armel.tgz | |
- | < | + | [sbox-MaemoKernel: ~] > sb-conf in MaemoKernel -edFL |
- | [sbox-FREMANTLE_ARMEL: ~] | + | <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 <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. </div> |
- | -c cs2007q3-glibc2.5-arm7 \ | + | * 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 /> |
- | -d qemu:perl:svn:apt-https -t /scratchbox/devkits/qemu/bin/qemu-arm-sb | + | |
- | [sbox-FREMANTLE_ARMEL: ~] | + | deb http://repository.maemo.org/ fremantle/sdk free non-free |
- | [sbox-MaemoKernel: ~] | + | deb-src http://repository.maemo.org/ fremantle/sdk free |
- | /home/<username>/maemo-sdk-rootstrap_5. | + | |
- | [sbox-MaemoKernel: ~] | + | deb http://repository.maemo.org/ fremantle/tools free non-free |
- | </ | + | deb-src http://repository.maemo.org/ fremantle/tools free |
- | </ | + | |
- | + | ||
- | + | ||
- | + | ||
- | < | + | |
- | + | ||
- | Verify that the sources.list file inside the | + | |
- | </ | + | |
- | + | ||
- | < | + | |
- | 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: ~] > mkdir ~/maemo_kernel | |
- | + | ||
The Scratchbox environment is now ready for compiling the kernel. | The Scratchbox environment is now ready for compiling the kernel. | ||
- | + | = Getting Kernel Sources = | |
- | Kernel sources are not included in the rootstrap | + | 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: ~] > sb-conf select MaemoKernel | |
- | [sbox-FREMANTLE_ARMEL: ~] | + | |
- | + | ||
- | + | * Update the package database. This requires the earlier modifications in the sources.list file. <br /><br /> | |
- | + | [sbox-MaemoKernel: ~] > fakeroot apt-get update | |
- | [sbox-MaemoKernel: ~] | + | |
- | + | ||
- | + | * Go to the working directory and fetch the sources. <br /><br /> | |
- | + | [sbox-MaemoKernel: ~] > cd ~/maemo_kernel | |
- | [sbox-MaemoKernel: ~] | + | [sbox-MaemoKernel: ~/maemo_kernel ] > apt-get source kernel |
- | [sbox-MaemoKernel: ~/maemo_kernel ] | + | |
- | + | ||
- | + | ||
Kernel sources should now be fetched and ready to be compiled. | 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 ] > cd kernel-2.6.28 | |
- | < | + | [sbox-MaemoKernel: ~/maemo_kernel/kernel-2.6.28] > make EXTRAVERSION=-maemo2 rx51_defconfig |
- | [sbox-MaemoKernel: ~/maemo_kernel ] | + | |
- | [sbox-MaemoKernel: ~/maemo_kernel/kernel-2.6.28] | + | |
# lots of output from make program... | # 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] > make EXTRAVERSION=-maemo2 bzImage |
- | [sbox-MaemoKernel: ~/maemo_kernel/kernel-2.6.28] > make EXTRAVERSION=- | + | # compilation output... |
- | # compilation output... | + | [sbox-MaemoKernel: ~/maemo_kernel/kernel-2.6.28] > ls -l arch/arm/boot/zImage |
- | [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 |
- | -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 | + | 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. | 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] > make EXTRAVERSION=-maemo2 \ | |
- | [sbox-MaemoKernel: ~/maemo_kernel/kernel-2.6.28] | + | rx51_defconfig |
- | 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] > vi .config | |
- | [sbox-MaemoKernel: ~/maemo_kernel/kernel-2.6.28] | + | |
- | + | ||
- | + | * Include your changes for compilation. <br /><br /> | |
+ | |||
+ | [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 [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] ></pre> | |
- | + | # Install the kernel-headers package. <pre>[sbox-MaemoKernel: ~/maemo_kernel] > fakeroot apt-get install kernel-headers</pre> | |
- | + | # Create a folder for the example. <pre>[sbox-MaemoKernel: ~/maemo_kernel] > mkdir hello-module [sbox-MaemoKernel: ~/maemo_kernel] > cd hello-module</pre> | |
- | + | ||
- | # As before, start in the work directory. <pre>[sbox-MaemoKernel: ~/maemo_kernel] | + | |
- | # Install the kernel-headers package. <pre>[sbox-MaemoKernel: ~/maemo_kernel] | + | |
- | + | ||
- | + | ||
- | + | ||
- | <pre> | + | |
- | [sbox-MaemoKernel: ~/maemo_kernel] | + | |
- | + | ||
- | + | ||
- | [sbox-MaemoKernel: ~/maemo_kernel] | + | |
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | </pre> | + | |
- | + | <ol start=4> | |
+ | <li>Save the following code example as <code>hello.c</code> in the new folder: | ||
<pre> | <pre> | ||
- | |||
/* hello-module.c, an example kernel module */ | /* hello-module.c, an example kernel module */ | ||
Line 188: | Line 134: | ||
module_exit(hello_exit); | module_exit(hello_exit); | ||
</pre> | </pre> | ||
- | + | </li> | |
- | + | <li> Save the following code example as <code>Makefile</code><nowiki>: </nowiki> | |
- | + | ||
<pre> | <pre> | ||
- | |||
# Makefile for building the hello kernel module outside the kernel tree | # Makefile for building the hello kernel module outside the kernel tree | ||
Line 201: | Line 145: | ||
# default build target (uses kernel build (kbuild) system) | # default build target (uses kernel build (kbuild) system) | ||
all: | all: | ||
- | $(MAKE) -C $(KERNELDIR) M=`pwd` EXTRAVERSION=- | + | $(MAKE) -C $(KERNELDIR) M=`pwd` EXTRAVERSION=-maemo2 modules |
# target for cleaning up | # target for cleaning up | ||
Line 207: | Line 151: | ||
$(RM) *.o .depend .*.cmd *.ko *.mod.c Module.symvers modules.order | $(RM) *.o .depend .*.cmd *.ko *.mod.c Module.symvers modules.order | ||
$(RM) -R .tmp_versions | $(RM) -R .tmp_versions | ||
- | </pre> | + | </pre></li> |
- | + | <li> Compile the module. | |
- | + | <pre> | |
- | + | ||
- | + | ||
- | + | ||
- | <li>Compile the module. | + | |
- | <pre> | + | |
[sbox-MaemoKernel: ~/maemo_kernel/hello-module] > make | [sbox-MaemoKernel: ~/maemo_kernel/hello-module] > make | ||
make -C /usr/src/kernel-headers M=`pwd` modules | make -C /usr/src/kernel-headers M=`pwd` modules | ||
Line 228: | Line 167: | ||
</pre></li> | </pre></li> | ||
<li> Check the results. | <li> Check the results. | ||
- | <pre> | + | <pre> |
[sbox-MaemoKernel: ~/maemo_kernel/hello-module] > ls -l | [sbox-MaemoKernel: ~/maemo_kernel/hello-module] > ls -l | ||
total 148 | total 148 | ||
Line 241: | Line 180: | ||
</pre></li> | </pre></li> | ||
</ol> | </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 /> | |
- | File <code>hello.ko</code> is the new module. | + | |
Nokia-NXX-31-10:/home/user# insmod hello.ko | Nokia-NXX-31-10:/home/user# insmod hello.ko | ||
- | and | + | and removed by calling |
Nokia-NXX-31-10:/home/user# rmmod hello.ko | 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 | Nokia-NXX-31-10:/home/user# dmesg | tail | ||
Line 254: | Line 192: | ||
[11928.357696] Goodbye, world | [11928.357696] Goodbye, world | ||
- | If there is a slight version mismatch | + | <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] > objcopy --strip-debug \ | + | [sbox-FREMANTLE_ARMEL: ~/maemo_kernel/hello-module] > objcopy --strip-debug \ |
-R .modinfo -R __versions hello.ko | -R .modinfo -R __versions hello.ko | ||
- | For | + | <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] | * [http://www.tldp.org/LDP/lkmpg/2.6/html/index.html The Linux Kernel Module Programming Guide] | ||
* <nowiki>/scratchbox/users/<username>/home/<username>/maemo_kernel/kernel-2.6.28/Documentation/kbuild/modules.txt</nowiki> | * <nowiki>/scratchbox/users/<username>/home/<username>/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: ~/maemo_kernel/kernel-2.6.28 | + | |
- | + | [sbox-MaemoKernel:]> 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] > vi .config |
- | CONFIG_NFSD | + | <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] > 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 | ||
+ | </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] > find . -name "*.ko" -ls | |
- | [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 | |
- | ortfs.ko | + | 1335340 144 -rw-rw-r-- 1 maemo maemo 141168 Aug 4 16:57 ./fs/fat/vfat.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 |
- | 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 |
- | 4074612 104 -rw-rw-r-- 1 maemo maemo 98930 Aug 4 16:57 ./arch/arm/mach-o | + | map2/dspbridge.ko |
- | 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 | + | 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/<username>/home/<username>/\ | |
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | # flasher | + | |
maemo_kernel/kernel-2.6.28/arch/arm/boot/zImage | maemo_kernel/kernel-2.6.28/arch/arm/boot/zImage | ||
- | + | </nowiki> | |
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | < | + | |
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + |
Learn more about Contributing to the wiki.