Saturday, September 25, 2010

Rebuilding the kernel

Although everything works so far out-of-the-box, I wanted to go through the exercise of building my own kernel, in case I need to change some of the configs or add any patches. Actually a PWM patch requires a change from the default Ubuntu kernel.

I tried a few ways of rebuilding the kernel, including the "old-fashioned Debian way", and using the automated Ubuntu scripts; however, I ran into various problems using these methods. I wanted to install the kernel on the SD card (not NAND) so that I could test different kernels out, while keeping the known good one in NAND in case the one on SD couldn't boot. The automated scripts would re-image NAND, and the "old-fashioned" way had various build/config issues and it was hard

The easiest way I found to rebuild the kernel is as follows. This keeps the kernel exactly as configured out of the box, allowing you to add your own patches on top.

1) install kernel sources on root filesystem with:
sudo apt-get build-dep --no-install-recommends linux-image-$(uname -r)
apt-get source linux-image-$(uname -r)
apt-get install qt3-dev-tools

2) copy over the old config
cp /boot/config-2.6.33-500-omap .config

3) configure the kernel
make xconfig

4) Build kernel and modules
make bzImage - builds vmlinuz
make modules - builds all the modules
make modules_install - installs modules in /lib/modules/

My kernel was named 2.6.33, so there are modules in /lib/modules/2.6.33

5) create an initramfs (similar to initrd) - I named mine "newinitramfs"
mkinitramfs -o newinitramfs 2.6.33

6) make a uboot compatible version of kernel - I called mine "newimage":
mkimage -A arm -O linux -T kernel -C none -a 0x80008000 -e 0x80008000 -n "new kernel" -d arch/arm/boot/zImage newimage

7) make a uboot compatible version of the initrd - I called mine "newinitrd":
mkimage -A arm -O linux -T ramdisk -C none -a 0x0 -e 0x0 -n initrd -d newinitramfs newinitrd

8) copy "newimage" and "newinitrd" to root SD card (mine was mounted in /media/4BD6-F1E1)


9) test loading it from uboot:
mmc init
fatload mmc 0 0x80000000 newkernel
fatload mmc 0 0x81600000 newinitrd
bootm 0x80000000 0x81600000
setenv bootargs console=ttyS2,115200 root=UUID= splash vram=12M omap fb.mode=dvi:1280x720MR-16@60 fixrtc

Note that the old uboot command to boot from the NAND was:
bootcmd=nand read 80000000 280000 400000;nand read 81600000 680000 1000000;bootm 80000000 81600000

10) If everything works, can now overwrite it with the following, to auto-boot from SD instead:

setenv bootcmd "mmc init; fatload mmc 0 0x80000000 newimage; fatload mmc 0 0x81600000 newinitrd; bootm 0x80000000 0x81600000"
saveenv


I now have an Ubuntu 10.04 kernel booting the BeagleBoard from the SD card, and can easily modify the kernel, rebuild, and copy it over to the SD card and reboot. The nice thing is that I can make a copy of the known good SD card, and use another one for development. Alternatively, if anything goes wrong, the bootcmd can be changed back to boot from NAND.

No comments:

Post a Comment