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, | + | Before starting, the Maemo environment must be set up. The required GCC toolchain that is used to compile the kernel is included in the Scratchbox by default. |
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. | 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/<username>/maemo-sdk-rootstrap_5. | + | /home/<username>/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> | ||
Line 30: | Line 33: | ||
{{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.}} | {{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> | ||
Line 54: | Line 58: | ||
== Getting Kernel Sources == | == 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. |
<ul> | <ul> | ||
Line 82: | Line 86: | ||
<ul> | <ul> | ||
- | <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=- | + | [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] > make EXTRAVERSION=- | + | [sbox-MaemoKernel: ~/maemo_kernel/kernel-2.6.28] > make EXTRAVERSION=-maemo2 bzImage |
# 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 | ||
Line 100: | Line 104: | ||
</ul> | </ul> | ||
- | |||
+ | {{ambox|text=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.}} | ||
- | 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 [[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=- | + | [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 | + | <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=- | + | [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. |
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
== 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 | + | 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> | ||
Line 148: | Line 146: | ||
<ol start=3> | <ol start=3> | ||
- | <li> Download the example files from | + | <li> Download the example files from maemo svn. |
<pre> | <pre> | ||
- | [sbox-MaemoKernel: ~/maemo_kernel] > svn export https:// | + | [sbox-MaemoKernel: ~/maemo_kernel] > svn export https://garage.maemo.org/svn/\ |
- | maemoexamples/ | + | 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=- | + | $(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] > make | [sbox-MaemoKernel: ~/maemo_kernel/hello-module] > make | ||
Line 242: | Line 238: | ||
</ol> | </ol> | ||
- | File <code>hello.ko</code> is the new module. | + | |
+ | 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 | + | and removed by calling |
Nokia-NXX-31-10:/home/user# rmmod hello.ko | 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 | 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 | + | 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] > 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 | + | 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 | + | 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 | + | <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> | ||
Line 293: | Line 292: | ||
</pre></li> | </pre></li> | ||
- | <li>As described in | + | <li>As described in previous sections, refresh the configuration and build new modules.</li> |
<li><pre> | <li><pre> | ||
- | [sbox-MaemoKernel: ~/maemo_kernel/kernel-2.6.28] > make EXTRAVERSION=- | + | [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=- | + | [sbox-MaemoKernel: ~/maemo_kernel/kernel-2.6.28] > make EXTRAVERSION=-maemo2 modules |
</pre></li> | </pre></li> | ||
- | <li>Check with the find command to see | + | <li>Check with the find command to see what kernel object files (extension .ko) there now are.</li> |
<li><pre> | <li><pre> | ||
Line 317: | Line 316: | ||
</ul> | </ul> | ||
- | The list of .ko files is quite long, depending on whether | + | 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. |
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
== Flashing Kernel == | == Flashing Kernel == | ||
- | + | The custom kernel can be flashed from outside the Scratchbox with the flasher tool via USB. | |
- | # flasher | + | # flasher -f -k /scratchbox/users/<username>/home/<username>/\ |
maemo_kernel/kernel-2.6.28/arch/arm/boot/zImage | maemo_kernel/kernel-2.6.28/arch/arm/boot/zImage | ||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- |
Learn more about Contributing to the wiki.