MTDKernelRebuild: Difference between revisions

From OLPC
Jump to navigation Jump to search
 
Line 194: Line 194:


;Note: this seems to be taken from http://lists.laptop.org/pipermail/devel/2007-April/004705.html .
;Note: this seems to be taken from http://lists.laptop.org/pipermail/devel/2007-April/004705.html .

[[Category:Build system]]

Latest revision as of 19:44, 15 April 2009

We use a modified version of the Linux kernel on the OLPC laptop.

Note: You will not be able to boot a new kernel on your XO until you have a Developer Key.

The OLPC kernel git repository

We use git to track changes that we've made, as well as to easily merge with Linus's (and others!) kernel tree. The git repository can be downloaded with the following command:

git clone git://dev.laptop.org/olpc-2.6

Alternatively, you can use gitweb to view and search changes by going to:

http://dev.laptop.org/git?p=olpc-2.6;a=summary

Note that at the bottom of that page, there is a list of branches. We keep around different branches for a number of reasons; within a cloned git repository, you can switch to branch 'FOO' by running:

git checkout FOO

The branches to note are:

  • master - this is the default branch, and is the equivalent of cvs's HEAD. Code that we want in our future releases goes into this branch, and needs to be vetted before being committed.
  • stable - this is the branch that we automatically pull kernels from when we build a release. It is usually a snapshot of the 'master' branch, although we sometimes cherry-pick fixes into it.
  • testing - this is the branch for joyride kernels. It is usually more recently updated than stable but not as recently updated as master.

The other branches can be ignored - if you don't already know what they are, they're not going to be of any use to you.

OLPC kernel configuration

The Linux kernel has a config file that describes the various options that are built into the kernel. For OLPC, we store that in the root of the git repository, in the 'arch/i386/configs/olpc_defconfig' file. Via gitweb, it can be viewed (for the 'master' branch) here:

http://dev.laptop.org/git?p=olpc-2.6;a=blob;f=arch/i386/configs/olpc_defconfig;h=f1675e86312eee9c1cc9e59ebefca91ff8afe979;hb=HEAD

For official OLPC kernel RPMS (and on OLPC OS images), the config ends up being installed as /boot/config-$VERS. This allows you to see how the currently running kernel is configured.

Installing OLPC kernel RPMs (and SRPMs)

We auto-build kernel RPMs every 30 mins, which means that new, shiny commit that just occurred will show up in the following places (depending upon branch):

The SRPMs (Source RPMs) are available in the same place.

The RPMs have the dates they were built, and the number of the build. For example, 'kernel-2.6.21-20070322.4.olpc.5fe63334a44da42.i586.rpm' was built on March 22, 2007. It was the 4th build on that day. The '5fe63334a44da42' is part of the git commit ID, if you're trying to match up what specific commits made it into the kernel.

The 'kernel-' RPMs contains all you need to boot into that new kernel; simply install it, reboot, and you're set. The 'kernel-devel-' RPMs contain headers necessary for building out-of-tree kernel modules. The 'kernel-debuginfo-' RPMs contain debugging info necessary for debugging the kernel with, say, systemtap.

To install your rpm:

rpm -ivh kernel-....rpm
cp -a /boot/* /versions/boot/current/boot/

(If you omit the -a in the above recipe, the vmlinuz symlink will not be updated correctly)

See the instructions at Kernel Building if you need to update modules in the initramfs. If you don't do this, you will likely get modprobe warnings at boot (before the initramfs starts); they are harmless.

Building an OLPC kernel RPM from the SRPM

You will want to do this on a Fedora 6 or 7 machine. If you have Fedora 8, you have to so more: see F8 notes.

You will need more than 4 GB of disk space for this (2 for the build artifacts themselves and more than 2 for the git clone and intermediate source).

The OLPC kernel sources

The first step involves grabbing the kernel sources by installing the kernel SRPM from the appropriate location

If you're trying to rebuild a kernel based on your XO's, you can check the git sha hash at the end of your XO's kernel version (from uname -r) to find which kernel you're interested in.

Installing the SRPM will place the sources in /usr/src/redhat/SOURCES/olpc-2.6.tar.bz2

Building the RPM

After installing the srpm, you run the rpmbuild command to build the rpms. The "dist", "olpc", and "head" macros should be defined when building:

  • rpm -ivh kernel-2.6.*-20061026_dc5079fafb767e4olpc1.src.rpm
  • rpmbuild -ba --define "dist olpc1" --define "olpc 1" --define "head dc5079fafb767e4" --target=i586 /usr/src/redhat/SPECS/olpc-2.6.spec

After the build finishes, the newly built RPMs will be in /usr/src/redhat/RPMS, and the build tree that was used will be in /usr/src/redhat/BUILD. To make quick changes to the source, for example you can:

# cd /usr/src/redhat/BUILD/kernel-2.6.18/linux-2.6.18.i586
# vi drivers/video/geode/gxfb_dcon.c
# make
# scp drivers/video/geode/gxfb_dcon.ko testboard:
# ssh testboard "rmmod gxfb_dcon; insmod ./gxfb_dcon.ko"

Fedora 8 (FC8) Notes

On May 1, 2008, Chris Ball mentioned that FC6 is still being used on the build server. Some things have improved since his mail but one still has to do:

  • Add:
  %define _enable_debug_packages 0

to the top of the specfile disables the failing debuginfo part of the build, and produces a working kernel package.

Building an OLPC kernel from scratch

This is the way that the official kernel RPMs are built, but are you sure you want to build an OLPC kernel from scratch? Really? The kernel is filled with arcane magic and sharp pointy things that may draw blood. It is recommended that you build an RPM (Rebuilding OLPC kernel) unless you are already familiar with kernel development!

Note that this allows you to build within a subdirectory somewhere (rather than using /usr/src/redhat).

Getting the source to build from scratch

First, grab the kernel sources:

git clone --quiet git://dev.laptop.org/olpc-2.6 linux-2.6.25

Note that the name of the directory these sources are cloned into is important. It must start with linux.2.6., followed by two numbers identifying the sublevel. These must match the sublevel defined in olpc-2.6/Makefile. Optionally check out a particular branch using:

git checkout origin/stable

Setting up the directory structure

Now construct the build directory structure:

BASE=`pwd`/build; CUR=0
git clone --quiet git://dev.laptop.org/users/dilinger/olpc-2.6-rpm $BASE
(cd $BASE && mkdir -p BUILD  RPMS  SOURCES  SPECS  SRPMS)
tar -jc --exclude=.git -f $BASE/SOURCES/olpc-2.6.tar.bz2 linux-2.6.25

Setting up the kernel configuration

You need to build a config file for the kernel. This is done in the source directory checked out using git:

make ARCH=i386 -C linux-2.6.25 olpc_defconfig
cp linux-2.6.25/.config $BASE/SOURCES/kernel-olpc-custom.config

If building for a school server, make xs_defconfig instead:

make ARCH=i386 -C linux-2.6.25 xs_defconfig
cp linux-2.6.25/.config $BASE/SOURCES/kernel-olpc-custom.config

Building the kernel and packaging the RPM

Now you can actually build the kernel and package it into an RPM:

rpmbuild -ba --define "dist 3.olpc" --define "olpc 3" --define "head `echo $CUR|cut -b1-15`" --target=i586 --define "_topdir $BASE" $BASE/SPECS/olpc-2.6.spec

The git://dev.laptop.org/users/dilinger/olpc-2.6-rpm repository contains the RPM SPEC file and other things necessary to bootstrap the RPM. When complete, the RPMs will be in build/RPMS/i586/.

Incremental re-building after a git-pull

First pull down the newest kernel sources, and tar them up:

BASE=`pwd`/build; CUR=0
pushd linux-2.6.25; git pull ; popd
tar -jc --exclude=.git -f $BASE/SOURCES/olpc-2.6.tar.bz2 linux-2.6.25

Now do the Setting up the kernel configuration step:

make ARCH=i386 -C linux-2.6.25 olpc_defconfig
cp linux-2.6.25/.config $BASE/SOURCES/kernel-olpc-custom.config

Delete the directory from a previous build (don't forget this step):

rm -r $BASE/BUILD/*

And now do the Building the kernel and packaging the RPM step:

rpmbuild -ba --define "dist 3.olpc" --define "olpc 3" --define "head `echo $CUR|cut -b1-15`" --target=i586 --define "_topdir $BASE" $BASE/SPECS/olpc-2.6.spec

Building an OLPC kernel, the quick and dirty way

After obtaining the OLPC source (and if desired, making changes), the following steps can be taken to build a kernel on any Fedora Core 6 machine:

make oldconfig
make
make modules_install  # as root
tar zcvf kern.tar.gz arch/x86/boot/bzImage System.map /lib/modules/$VERS
Warning!
this needs root and will trash your /lib/modules, if you happen to already have same version. Use "make INSTALL_MOD_PATH=/somewhere modules_install" if you want to avoid using root).

Replace $VERS above with the proper kernel version that has been built.

Assuming everything builds correctly, you will be left with kern.tar.gz. This can be copied over to an XO laptop, and the following steps will install the kernel (again, replacing $VERS with the kernel version):

cd /
tar zxvf .../kern.tar.gz
mv System.map /versions/boot/current/boot/System.map-$VERS
mv arch/i386/boot/bzImage /versions/boot/current/boot/vmlinuz-$VERS
ln -sf /versions/boot/current/boot/vmlinuz-$VERS /versions/boot/current/boot/vmlinuz

If not booting off NAND, you'll probably want to skip the /versions/boot/current/ prefix on the paths above. A limited number of kernel modules are required by the ramdisk during the boot process; if you need to update the ramdisk, these additional steps are also necessary:

# mkdir /tmp/X ; cd /tmp/X
# zcat /versions/boot/current/boot/olpcrd.img | cpio -i
# rm -r lib/modules
# cp -r /lib/modules lib/
# find . -print | cpio -H newc -o | gzip -9 > /versions/boot/current/boot/olpcrd.img
Note
this seems to be taken from http://lists.laptop.org/pipermail/devel/2007-April/004705.html .