Kernel

From OLPC
Jump to navigation Jump to search


The OLPC kernel

OLPC OS Releases use our OLPC-modified version of the Linux kernel.

The OLPC kernel is maintained in git:

Current maintainers: Chris Ball, Daniel Drake, Paul Fox

We work on specific git branches, which vary by hardware and operating system release.

operating system release git branches
Android ARM XO-4 arm-3.5-android
13.2.0 13.1.0 ARM XO-4 arm-3.5
13.2.0 13.1.0 12.1.0 i386 x86-3.3
13.2.0 13.1.0 12.1.0 11.3.1 ARM XO-1.75 arm-3.0-wip
11.2.0 i386 olpc-2.6.35
10.1.3 i386 olpc-2.6.31

Or looking at git history may identify which branches we are actively working on, and looking at the version of each branch compared to the kernel shipped in each release will help you identify which branch corresponds to which release(s).

OLPC-specific configurations can be found at arch/x86/configs/ and arch/arm/configs/, these are what we use for automated builds and official releases. This configuration is also installed in /boot in our software releases.

Questions and contributions should be sent to the devel mailing list.

Installing kernel RPMs

The following section only applies to pre-13.2 OS releases. On 13.2.0 and newer, installing a new kernel RPM on an XO will automatically activate it on the boot partition as well.

Due to OLPC's versioned filesystem layout, installing a new kernel RPM is not enough for it to become active on reboot. This is explained in detail in /boot/README. To summarise, after installing a kernel you must copy it to a special place:

If running a software release that uses partitions, first check to ensure that /bootpart is mounted (it should have several directories in it). If it isn't, mount it:

mount /dev/mmcblk0p1 /bootpart

Then:

rsync --delete-before -av /boot/ /bootpart/boot/

If running a software release that does not use partitions:

cp -a /boot/* /versions/boot/current/boot/

Building a kernel RPM

  • If using OLPC OS on your build host, install general development packages needed for kernel compiling:
yum install -y git rpmdevtools gcc make ncurses-devel m4 redhat-rpm-config
  • Install build prerequisites:
yum install -y unifdef lzop dracut-modules-olpc
  • (be careful with dracut-modules-olpc.)
  • Install kernel prerequisites:
yum install -y libertas-usb8388-olpc-firmware \
               libertas-sd8686-firmware \
               libertas-sd8787-firmware
  • Clone the git repository; you will need at least 1.5 GBytes free:
git clone git://dev.laptop.org/olpc-kernel
  • Checkout the appropriate branch:
git checkout x86-3.3
  • Clean the source tree:
make clean distclean
  • Make your source changes,
  • Make any defconfig changes, for the laptop model,
    • XO-1: arch/x86/configs/xo_1_defconfig
    • XO-1.5: arch/x86/configs/xo_1.5_defconfig
    • XO-1.75: arch/arm/configs/xo_175_defconfig
    • XO-4: arch/arm/configs/xo_4_defconfig
  • Commit all your changes,
  • Run olpc/buildrpm, for the laptop model;
    • XO-1: olpc/buildrpm 1.0
    • XO-1.5: olpc/buildrpm 1.5
    • XO-1.75: olpc/buildrpm 1.75
    • XO-4: olpc/buildrpm 4

The output RPM files will be in olpc/RPMS/ which you can install on an XO, with the above versioned filesystem layout issues in mind.

Cross compiling

Compiling ARM kernels on ARM is sloooow. It's very easy to cross-compile from a faster box.

Another option (a little more tricky) would be to use crosstool-ng to build and install a cross-compiler.

Fedora

On Fedora 16 or later, you can install an ARM cross compiler with:

yum install gcc-arm-linux-gnu binutils-arm-linux-gnu

To build the kernel, set these environment variables:

export ARCH=arm
export CROSS_COMPILE=armv7-linux-gnu-

Ubuntu

On Ubuntu 13.04 or later, you can install an ARM cross compiler with:

apt-get install gcc-arm-linux-gnueabi

To build the kernel, set these environment variables:

export ARCH=arm
export CROSS_COMPILE=arm-linux-gnueabi-


Now you can compile kernels in the normal way. Here is a recipe:

mkdir -p /tmp/xo/lib/modules
mkdir -p /tmp/xo/bootpart/boot
cp arch/arm/configs/xo*fig .config
make oldconfig zImage
make modules
INSTALL_MOD_STRIP=1 INSTALL_MOD_PATH=/tmp/xo make modules_install
cp arch/arm/boot/zImage /tmp/xo/bootpart/boot/
(cd /tmp/xo/bootpart/boot/ && ln -sf zImage vmlinuz)

After this, /tmp/xo can be tar'd up and extracted on the XO, on USB media, or on an NFS mount point.

Automatic RPM generation

During development some branches are automatically built every 30 minutes (but only when there are new changes), the results are published at http://dev.laptop.org/~kernels/

The directories you see there are also linked to RPM dropboxes, therefore are automatically published for inclusion in development builds. In other words, to get your kernel changes included in the current software release development efforts, you simply have to push your changes to the correct branch.

The utility behind this magic is olpc-kernel-builder:

Install mock to use olpc-kernel-builder

yum install -y mock

Running development kernels

Starting with 13.1.0 development builds, the /boot (or /bootpart/boot) area of the OS images has changed layout slightly. The kernel and initramfs are now only shipped in zip files, in order to reduce duplication for signed builds, and to remove duplication of firmware code in the olpc.fth boot script.

Dropping your own vmlinuz in place (or booting one from USB as described below, pointing at the internal disk for the initrd.img initramfs) will no longer work as standard, since this will cause the system to start looking for an unzipped initramfs too. The story is similar for initramfs development - if you drop a "raw" initramfs in place, you will need to ensure that an unzipped kernel is also installed. Just run, once, as root:

# olpc-dev-kernel

This will unzip the initramfs from the zip file and save it as initrd.img, and similarly it will unzip the kernel from its zip file and save it as vmlinuz. In both cases, if an existing initrd.img/vmlinuz file is present, it will not be overwritten.

Now drop your files in place as you have done so before, and the system will pick up the "unzipped" partner initramfs/kernel file.

One more detail to be aware of: if you put "unzipped" initramfs/kernel files in place using this method, you will no longer receive automatic firmware updates from bootfw.zip. This should only affect cases where you drop your own development kernel/initramfs in place, then upgrade the olpc-firmware RPM package, and expect that firmware upgrade to be automatically installed.

For more details, read the original proposal: Removing duplication in /boot - affects kernel development.

Running vanilla kernels

In late 2010, OLPC started a focused effort to upstream its kernel patches so that unmodified "vanilla" kernels run with complete functionality on the XO-1 and XO-1.5.

As of Linux-3.5 these efforts are mostly concluded - OLPC only carries a small number of patches, which will be upstreamed as time permits.

You may have to hunt around a bit to satisfy the configuration options so that the relevant drivers get built. If in doubt, feel free to ask on the devel mailing list for someone's recent .config file.

Boot your development kernel from USB

When doing kernel development, it is time consuming to commit each small change, make an RPM, install RPM on the XO, reboot, and test. Instead, you can follow this procedure:

On your development system, prepare a USB disk as follows:

XO-1.75:

  • /boot/olpc.fth (download from here)
  • /boot/zImage (your kernel that you want to test)

XO-1.5 and XO-1

  • /boot/olpc.fth (download for XO-1 or XO-1.5, be sure to rename to olpc.fth)
  • /boot/irfs.img (download here - this is a hacked OLPC initramfs which doesn't require /ofw support)
  • /boot/bzImage (your kernel that you want to test)

Now plug this disk into your XO, turn it on, and the system will load the kernel from USB while booting the rest of the system as normal. If your new kernel crashes badly, just unplug the USB disk and boot the system again - it will revert to booting the "good" kernel from local disk.

Note: for XO-1 this only works with JFFS2. (small tweaks to olpc.fth or the hacked initramfs would be needed for ubifs).