Compiling the kernel

(Compilation)
(Serial Console)
 
(30 intermediate revisions not shown)
Line 1: Line 1:
-
=Introduction=
+
{{Midgard article}}
-
This document describes how a 3rd party developer can compile, modify and deploy the linux kernel if (s)he really wants to. First thing to consider is whether your own kernel is really needed. Most additional functionality can be provided with modules dynamically loaded into original kernel provided by Nokia. This may be easier for you and also easier for other users to install on their devices. Only if your change conflicts with original Nokia configuration or new feature cannot be compiled as a module, new kernel is needed.
+
-
If you choose to compile only additional modules then use the original n770_defconfig configuration as a base and enable new functionality as modules. Make sure you use compatible compiler with the one used for original kernel (currently gcc 3.4) otherwise your modules may produce errors when inserting into the kernel. The best may be to use exactly the same one - see /proc/version on device or use the one suggested in Section 2.
+
NOTE : THIS ARTICLE IS ONLY PARTLY UPDATED - DON'T EXPECT IT TO WORK.
-
If you choose to make a new kernel Section 2 describes the compilation procedure, Section 3 the modification procedure, and Section 4 the deployment procedure. The document finishes off by a section listing issues that should be taken into account when working with the kernel and Maemo.
 
-
=Compiling the Kernel=
+
This document describes how a 3rd party developer can compile, modify, and deploy the Linux kernel if (s)he really wants to. However, the first thing to consider is whether a custom kernel is really needed. Most additional functionality can be provided with modules dynamically loaded into the original kernel provided by Nokia. Modules may be both easier for you to create and easier for users to install on their devices. It is only if your change conflicts with the original Nokia configuration, or if the new feature cannot be compiled as a module, that a new kernel is needed.
-
The compilation procedure can be split into two phases; the preparation phase that needs to be done only once, and the actual compilation phase.
+
First see: http://maemo.org/maemo_release_documentation/maemo4.1.x/node12.html
-
=Preparations=
+
If you choose to compile only additional modules, then use the original Nokia configuration as a base and enable new functionality as modules. Make sure you use a compiler compatible with the one used for the original kernel (currently GCC 3.4), otherwise your modules may produce errors when inserted into the kernel. The best method may be to use exactly the same GCC version. See /proc/version on your device for this. Alternatively, use the GCC version suggested in Section 2.
-
A Scratchbox target with a compatible toolchain must be created in order to compile kernel images that can be used on the actual device. The following instructions assume that Scratchbox 0.9.8.5 has already been succesfully installed. In order to set up a target for kernel compilation, perform the following four steps:
+
-
'''1.''' Install a gcc 3.4 toolchain, for example this one
+
If you choose to make a new kernel, Section 2 describes the compilation procedure, Section 3 the modification procedure, and Section 4 the deployment procedure. The final section of this document lists issues that should be taken into account when working with the kernel and Maemo.
-
'''2.''' Start sbox and create a new target for kernel compilation
+
-
$ sbox-config -ct MAEMO_KERNEL
+
=Modifying Default Kernel Configuration=
-
*select newly installed gcc 3.4 toolchain
+
In order to modify the default kernel configuration, a few things need to be done. Assuming that the kernel has been built at least once, perform the following procedure to build a modified kernel for Maemo:
-
*select qemu-arm as CPU transparency mode
+
-
*select debian devkit
+
-
'''3.''' Select the newly created target, install ARM rootstrap, and finish toolchain setup
+
'''1.''' Edit ~/maemo-kernel/kernel-source-diablo-2.6.21/debian/rules so that modifications may be done.
-
$ sbox-config -st MAEMO_KERNEL $ sbox-config -er /scratchbox/packages/Maemo_Dev_Platform_RS_v1.1_arm.tgz
+
Make sure the following two lines are commented out or removed completely:
-
$ sbox-config -cc
+
* build-stamp section: tar jxf /usr/src/kernel-source-$(SOURCE_VERSION).tar.bz2
-
$ sbox-config -cf
+
* clean section: rm -rf kernel-source-$(SOURCE_VERSION)
-
'''4.''' Edit /etc/apt/sources.list to contains the following lines
+
'''2.''' Change file permissions for default config file.
-
  deb maemo1.1 free non-free deb-src maemo1.1 free non-free
+
  $ chmod a+w ~/maemo-kernel/kernel-source-diablo-2.6.21/kernel-source/arch/arm/configs/n770_defconfig
-
The above lines should be adjusted as appropriate for newer versions of maemo, e.g. 2.0 or 2.1
+
'''3.''' Make your modifications to ~/maemo_kernel/kernel-source-diablo-2.6.21/kernel-source/arch/arm/configs/n770_defconfig
-
'''5.''' Create a directory to work in
+
'''4.''' Recompile the kernel image:
-
  $ mkdir ~/kernel-build
+
  $ cd
 +
$ dpkg-buildpackage -rfakeroot -uc -us -sa -d
-
=Compilation=
+
'''5.''' Install the kernel image in Scratchbox target
-
Now, after the target is properly set up, we are ready to compile the kernel. This is done by following these seven steps:
+
-
 
+
-
'''1.''' Select the Scrathbox target configured earlier, if not yet selected.
+
-
 
+
-
$ sbox-config -st MAEMO_KERNEL
+
-
 
+
-
'''2.''' Update package database
+
-
 
+
-
$ apt-get update
+
-
 
+
-
'''3.''' Go to the compilation directory
+
-
 
+
-
$ cd ~/kernel-build
+
-
 
+
-
'''4.''' Install kernel sources and debian tools for building the kernel image
+
-
 
+
-
$ fakeroot apt-get install kernel-source-2.6.12.3 kernel-package
+
-
 
+
-
The above command not work for me in maemo 2.1. I worked around this by installing only kernel source $ fakeroot apt-get install kernel-source-2.6.16 kernel-package should be in scratchbox toolbox
+
-
 
+
-
'''5.''' Get sources for su-18-kernel package
+
-
 
+
-
$ apt-get source su-18-kernel
+
-
 
+
-
'''6.''' Rebuild su-18-kernel package
+
-
 
+
-
$ cd su-18-kernel-2.6.12.3 $ dpkg-buildpackage -rfakeroot -uc -us -sa -d
+
-
 
+
-
'''7.''' Install the kernel image in Scratchbox target
+
  $ fakeroot dpkg -i ../su-18-kernel_*.deb
  $ fakeroot dpkg -i ../su-18-kernel_*.deb
-
=Modifying Default Kernel Configuration=
+
==Menuconfig==
 +
to
 +
make menuconfig
 +
you need to edit kernel-source/scripts/kconfig/lxdialog/check-lxdialog.sh
 +
and in the ldflags() function add these lines:
-
In order to modify the default kernel configuration, a few things needs to be done. Assuming that the kernel has been built at least once as described in Section 2, perform the following procedure to build a modified kernel for Maemo:
+
ldflags()
-
 
+
{
-
1 Edit ~/kernel-build/su-18-kernel-2.6.12.3/debian/rules so that modifications may be done
+
+ echo '-lncurses'
-
 
+
+ exit
-
Make sure the following two lines are commented or removed completely: * build-stamp section: tar jxf /usr/src/kernel-source-$(SOURCE_VERSION).tar.bz2 * clean section: rm -rf kernel-source-$(SOURCE_VERSION)
+
$cc -print-file-name=libncursesw.so | grep -q /
-
 
+
if [ $? -eq 0 ]; then
-
2 Change file permissions for default config file
+
-
 
+
-
$ chmod a+w ~/kernel-build/su-18-kernel-2.6.12.3/kernel-source-2.6.12.3/arch/arm/configs/n770_defconfig
+
-
 
+
-
3 Make your modifications to /kernel-build/su-18-kernel-2.6.12.3/kernel-source-2.6.12.3/arch/arm/configs/n770_defconfig
+
-
 
+
-
To make myself more comfortable with this step, I added a couple more steps: 1) I copied n770_defconfig to .config and ran make oldconfig. 2) then I copied .config back to n770_defconfig. This made me more confident that the changes I made in n770_defconfig were correct.
+
-
 
+
-
4 Recompile the kernel image
+
-
 
+
-
$ cd su-18-kernel-2.6.12.3 $ dpkg-buildpackage -rfakeroot -uc -us -sa -d
+
-
 
+
-
5 Install the kernel image in Scratchbox target
+
-
 
+
-
$ fakeroot dpkg -i ../su-18-kernel_*.deb
+
-
 
+
-
=Deploying the Kernel Onto the Device=
+
-
 
+
-
The kernel kernel image is deployed onto the device by issuing the following command:
+
-
 
+
-
# flasher -f -k /scratchbox/users/<username>/targets/MAEMO_KERNEL/usr/share/osso/kernels/zImage-su-18-<yyyyww>
+
-
 
+
-
This command is executed outside Scratchbox, assuming that the flasher utility is in $PATH.
+
-
 
+
-
Or if you want to be safe, you can test boot it with: (without actually permanently modifying the kernel)
+
-
 
+
-
# flasher -l -b -k /scratchbox/users/<username>/targets/MAEMO_KERNEL/usr/share/osso/kernels/zImage-su-18-<yyyyww>
+
-
 
+
-
instead.
+
-
 
+
-
If that doesn't work (hangs indefinitely while trying to find device), try "mount -t usbfs none /proc/bus/usb/".
+
=Things to Remember When Working with Linux Kernel and Maemo=
=Things to Remember When Working with Linux Kernel and Maemo=
Line 115: Line 54:
Below is a list of things that should be taken into consideration when working with the Linux kernel and Maemo.
Below is a list of things that should be taken into consideration when working with the Linux kernel and Maemo.
-
=Modules and initfs=
+
=Modules and Initfs=
-
Your kernel image have to be compatible with modules in initfs image on the device. If you flash custom kernel image incompatible with modules in this initfs you may see constants reboots. This can be fixed either by making the kernel compatible (use same or very similar gcc compiler and kernel configuration) or by rebuilding initfs image with your version of modules. For a list of those essential modules see /lib/modules/current in the initfs image or /mnt/initfs/lib/modules/current directly on the device. Also if you enabled some additional functionality as modules you may need to copy them manually to the initfs on the device (if there is free space) or better put them somewhere in the root filesystem.
+
Your kernel image must be compatible with the modules in the initfs image on the device. If you flash a custom kernel image that is incompatible with the modules in initfs, you may see constants reboots. This can be fixed either by making the kernel compatible (use same or very similar gcc compiler and kernel configuration) or by rebuilding the initfs image with your version of modules. For a list of essential modules see: '''/lib/modules/current''' in the initfs image or '''/mnt/initfs/lib/modules/current''' directly on the device. Also, if you enabled some additional functionality as modules, you may need to copy them manually to the initfs on the device (if there is free space) or put them somewhere in the root filesystem of the device.
=Kernel Partition Size=
=Kernel Partition Size=
 +
The size of the kernel partition on the device is limited. When enabling additional features to be compiled directly into kernel the image may quite easily exceed the size of the partition and thus flashing an oversized image to the kernel partition may render the device useless. It is advised to use modules as much as possible to keep kernel size down and prevent this from happening. If this happens, see next item.
The size of the kernel partition on the device is limited. When enabling additional features to be compiled directly into kernel the image may quite easily exceed the size of the partition and thus flashing an oversized image to the kernel partition may render the device useless. It is advised to use modules as much as possible to keep kernel size down and prevent this from happening. If this happens, see next item.
Line 124: Line 64:
For example, flashing an oversized kernel image renders the device useless. In order to get the device working again, select one of the following two options.
For example, flashing an oversized kernel image renders the device useless. In order to get the device working again, select one of the following two options.
-
==Flash Kernel Image from Maemo.org==
+
==Flash Kernel Image from maemo.org==
You can install a fully working kernel image by installing the su-18-kernel image available on maemo.org. Issue the following command in Scratchbox:
You can install a fully working kernel image by installing the su-18-kernel image available on maemo.org. Issue the following command in Scratchbox:
-
$ apt-get install su-18-kernel
+
$ apt-get install su-18-kernel
After this, flash the kernel image as instructed in Section 4.
After this, flash the kernel image as instructed in Section 4.
 +
 +
----
 +
 +
----
==Flash from Fiasco Image==
==Flash from Fiasco Image==
-
The other way around the problem is to install the latest Fiasco image available from Nokia Support or maemo.org downloads. Please see this How-To for more information how to do this. You can use flasher to unpack firmware *.bin image and flash only kernel or initfs or both.
+
The other way around the problem is to install the latest Fiasco image available from Nokia Support or maemo.org downloads. Please see this How To Flash from Linux How To for more information how to do this. You can use flasher to unpack firmware *.bin image and flash only kernel or initfs or both.
=Serial Console=
=Serial Console=
 +
When hacking the kernel, you may need the serial console. You may have noticed an 11 pins conector (pad) in the battery compartment of the device:
When hacking the kernel, you may need the serial console. You may have noticed an 11 pins conector (pad) in the battery compartment of the device:
Line 152: Line 97:
  4
  4
-
There is an other 4 Pin connector near on booth th n800 and n810. those are related to usb.(we did get some bus reset signals when playing with them)
+
There is another 4 Pin connector nearby, on both the n800 and n810. those are related to usb.(we did get some bus reset signals when playing with them)
   1
   1
Line 160: Line 105:
Once your done with your cable, enable the R&D mode and set the serial console flag and connect via 8N1,115200.
Once your done with your cable, enable the R&D mode and set the serial console flag and connect via 8N1,115200.
<pre>
<pre>
-
$sudo ./flasher <del>enable-rd-mode </del>set-rd-flags=serial-console
+
$sudo ./flasher --enable-rd-mode --set-rd-flags=serial-console
Password:
Password:
Suitable USB device not found, waiting
Suitable USB device not found, waiting
Line 171: Line 116:
-
[[Category:HowTos]]
+
[[Category:HowTo]]
 +
[[Category:Midgard wiki]]

Latest revision as of 17:06, 16 February 2016

Image:Ambox_content.png
This is an article from the old midgard wiki that hasn't yet been fully updated for this wiki, please update it.
Please see the talk page for discussion.


NOTE : THIS ARTICLE IS ONLY PARTLY UPDATED - DON'T EXPECT IT TO WORK.


This document describes how a 3rd party developer can compile, modify, and deploy the Linux kernel if (s)he really wants to. However, the first thing to consider is whether a custom kernel is really needed. Most additional functionality can be provided with modules dynamically loaded into the original kernel provided by Nokia. Modules may be both easier for you to create and easier for users to install on their devices. It is only if your change conflicts with the original Nokia configuration, or if the new feature cannot be compiled as a module, that a new kernel is needed.

First see: http://maemo.org/maemo_release_documentation/maemo4.1.x/node12.html

If you choose to compile only additional modules, then use the original Nokia configuration as a base and enable new functionality as modules. Make sure you use a compiler compatible with the one used for the original kernel (currently GCC 3.4), otherwise your modules may produce errors when inserted into the kernel. The best method may be to use exactly the same GCC version. See /proc/version on your device for this. Alternatively, use the GCC version suggested in Section 2.

If you choose to make a new kernel, Section 2 describes the compilation procedure, Section 3 the modification procedure, and Section 4 the deployment procedure. The final section of this document lists issues that should be taken into account when working with the kernel and Maemo.

Contents

[edit] Modifying Default Kernel Configuration

In order to modify the default kernel configuration, a few things need to be done. Assuming that the kernel has been built at least once, perform the following procedure to build a modified kernel for Maemo:

1. Edit ~/maemo-kernel/kernel-source-diablo-2.6.21/debian/rules so that modifications may be done.

Make sure the following two lines are commented out or removed completely:

  • build-stamp section: tar jxf /usr/src/kernel-source-$(SOURCE_VERSION).tar.bz2
  • clean section: rm -rf kernel-source-$(SOURCE_VERSION)

2. Change file permissions for default config file.

$ chmod a+w ~/maemo-kernel/kernel-source-diablo-2.6.21/kernel-source/arch/arm/configs/n770_defconfig 

3. Make your modifications to ~/maemo_kernel/kernel-source-diablo-2.6.21/kernel-source/arch/arm/configs/n770_defconfig

4. Recompile the kernel image:

$ cd 
$ dpkg-buildpackage -rfakeroot -uc -us -sa -d 

5. Install the kernel image in Scratchbox target

$ fakeroot dpkg -i ../su-18-kernel_*.deb

[edit] Menuconfig

to

make menuconfig

you need to edit kernel-source/scripts/kconfig/lxdialog/check-lxdialog.sh and in the ldflags() function add these lines:

ldflags()
{
+	echo '-lncurses'
+	exit
	$cc -print-file-name=libncursesw.so | grep -q /
	if [ $? -eq 0 ]; then

[edit] Things to Remember When Working with Linux Kernel and Maemo

Below is a list of things that should be taken into consideration when working with the Linux kernel and Maemo.

[edit] Modules and Initfs

Your kernel image must be compatible with the modules in the initfs image on the device. If you flash a custom kernel image that is incompatible with the modules in initfs, you may see constants reboots. This can be fixed either by making the kernel compatible (use same or very similar gcc compiler and kernel configuration) or by rebuilding the initfs image with your version of modules. For a list of essential modules see: /lib/modules/current in the initfs image or /mnt/initfs/lib/modules/current directly on the device. Also, if you enabled some additional functionality as modules, you may need to copy them manually to the initfs on the device (if there is free space) or put them somewhere in the root filesystem of the device.

[edit] Kernel Partition Size

The size of the kernel partition on the device is limited. When enabling additional features to be compiled directly into kernel the image may quite easily exceed the size of the partition and thus flashing an oversized image to the kernel partition may render the device useless. It is advised to use modules as much as possible to keep kernel size down and prevent this from happening. If this happens, see next item.

[edit] What To Do When Flashing Breaks the Device

For example, flashing an oversized kernel image renders the device useless. In order to get the device working again, select one of the following two options.

[edit] Flash Kernel Image from maemo.org

You can install a fully working kernel image by installing the su-18-kernel image available on maemo.org. Issue the following command in Scratchbox:

$ apt-get install su-18-kernel

After this, flash the kernel image as instructed in Section 4.



[edit] Flash from Fiasco Image

The other way around the problem is to install the latest Fiasco image available from Nokia Support or maemo.org downloads. Please see this How To Flash from Linux How To for more information how to do this. You can use flasher to unpack firmware *.bin image and flash only kernel or initfs or both.

[edit] Serial Console

When hacking the kernel, you may need the serial console. You may have noticed an 11 pins conector (pad) in the battery compartment of the device:

1-2-3-4-5-6
-7-8-9-A-B- 

Pin 9 is RxD (Nokia receive input) and pin A is TxD (Nokia transmit output). Pin 8 and 3 are the ground. The outputs are evidently 3.3v - Some used a USB-mobile phone cable as described in and to connect to the device.

On the N800 this connector contains only 7 pins and it located near the battery. Pin 7 is RxD (Nokia receive input) and pin 6 is TxD (Nokia transmit output). Pin 3 and 4 are the ground. It looks like pin 5 is connected to the battery over current indicator.

1
  5
2
  6
3
  7
4

There is another 4 Pin connector nearby, on both the n800 and n810. those are related to usb.(we did get some bus reset signals when playing with them)

  1
  2
3-4

Once your done with your cable, enable the R&D mode and set the serial console flag and connect via 8N1,115200.

$sudo ./flasher --enable-rd-mode --set-rd-flags=serial-console
Password:
Suitable USB device not found, waiting
USB device found found at bus 002, device address 011
Found board Nokia 770 (F5)
NOLO version 0.9.0
The device is now in R&D mode
Set R&D flags: 0010