Compile a new kernel for BeagleBone

new-kernel

I can not count on one hand the number of days I spent trying to compile a new Linux kernel for BeagleBone. This was back in April 2012 when userspace SPI was not enabled in the kernel by default. I recently had to recompile a new kernel in order to enable SPI 2.1 for the Replicape and I documented the steps. Hopefully someone will save some time and agony by reading this.

Working setup for compiling a kernel using Ångström

Ok, first the Angstrom environment must be set up. Just follow the instructions on Building Ångström.

For Beaglebone this becomes:

git clone git://github.com/Angstrom-distribution/setup-scripts.git
cd setup-scripts
MACHINE=beaglebone ./oebb.sh config beaglebone
MACHINE=beaglebone ./oebb.sh update 
MACHINE=beaglebone ./oebb.sh bitbake virtual/kernel

Later that night… No really, it takes while, took me two hours on my slightly outdated Thinkstation.

You can remove the “MACHINE=beaglebone ./oebb.sh” part now, the instructions are displayed.

Once it’s done you should now have a Linux image (uImage) in:

build/tmp-angstrom_v2012_05-eglibc/deploy/images/beaglebone/

You will also have an image in:

build/tmp-angstrom_v2012_05-eglibc/work/beaglebone-angstrom-linux-gnueabi/linux-ti33x-psp-3.2.34-r18a+gitr720e07b4c1f687b61b147b31c698cb6816d72f01/git/arch/arm/boot

More on that later..

Make sure it is working
It’s good to check that this image is actually working as expected before making any changes by copying it to the /boot/ directory of your BeagleBone, linking to it and rebooting BeagleBone. Here is a short Make-script i use for deploying a new image. This script is very specific to my setup, using the IP my BB has and stuff, but it serves the purpose of showing what is going on. This Makefile is located in my setup-scripts folder:

IP=10.24.2.129
UIMAGE=uImage
IMG_PATH=build/tmp-angstrom_v2012_05-eglibc/deploy/images/beaglebone/
VERSION=3.2.34

image:
        scp $(IMG_PATH)$(UIMAGE) root@$(IP):/boot/uImage-$(VERSION)
        ssh root@$(IP) 'cd /boot/; rm uImage; ln -s uImage-$(VERSION) uImage'

So on calling “make image”, the image is uploaded to BB, and linked in as the working kernel image. In my case, the new kernel image was version 3.2.34 but the old version of the kernel was 3.2.18.

 Installing the modules

If the newly created kernel has a different version number than you previously had, you also need to install the modules for the new kernel. They are zipped and in the same folder as the image. They must be uploaded to /lib/modules/ folder.

scp -r build/tmp-angstrom_v2012_05-eglibc/deploy/images/beaglebone/lib/modules/3.2.34 root@10.24.2.129:/lib/modules/

Again, the Make-script is specific to my setup, so do not use it without changing paths etc. to match your setup.
Switch your IP for your BeagleBone’s obviously.

Now, on reboot you should see the

.---O---.                                           
|       |                  .-.           o o        
|   |   |-----.-----.-----.| |   .----..-----.-----.
|       |     | __  |  ---'| '--.|  .-'|     |     |
|   |   |  |  |     |---  ||  --'|  |  |  '  | | | |
'---'---'--'--'--.  |-----''----''--'  '-----'-'-'-'
                -'  |
                '---'

The Angstrom Distribution beaglebone ttyO0

Angstrom v2012.05 - Kernel 3.2.34

as you boot up. That means the new kernel is installed, but the modules are not enabled for this kernel version. If you do an”lsmod”, you see that no modules are loaded:

root@beaglebone:~# lsmod
Module                  Size  Used by
root@beaglebone:~#

To load the modules call:

root@beaglebone:~# depmod -a

and reboot the board again. The modules should now be loaded.

Making changes to the kernel and testing

Now that you have verified that everything is working as expected with the new kernel, you can start making changes. I recommend following the SlimLogic method, but there is one thing I never got to work. He says to use the command

bitbake virtual/kernel -c compile -f

to compile new changes and that is fine, that works for me (-f is for “force”), but to update the image he uses the command:

bitbake virtual/kernel -c deploy

I never got “deploy” to work. It is supposed to update the uImage in the folder named:

build/tmp-angstrom_v2012_05-eglibc/deploy/images/beaglebone/

It never did (even with the -f option) and I spent hours googling for it. Finally I found out that the uImage is also located in the arch/arm/boot folder of the Linux kernel. So in your make-script, just change the img_path:

IP=10.24.2.129
UIMAGE=uImage
IMG_PATH=build/tmp-angstrom_v2012_05-eglibc/work/beaglebone-angstrom-linux-gnueabi/linux-ti33x-psp-3.2.34-r18a+gitr720e07b4c1f687b61b147b31c698cb6816d72f01/git/arch/arm/boot/
VERSION=3.2.34

image:
        scp $(IMG_PATH)$(UIMAGE) root@$(IP):/boot/uImage-$(VERSION)
        ssh root@$(IP) 'cd /boot/; rm uImage; ln -s uImage-$(VERSION) uImage'

Happy kernel coding : )

BTW, the new kernel enables pin-muxing via EEPROM, a nice feature. I don’t know what version kernel you crazy kids are running these days, but my previous version (3.2.18 did not do this I think). Of course if you just want the newest stable version of the kernel for Angstrom, you culd always use the built in package manager to upgrade..

Troubleshooting
If you link to a kernel that is not working and you get a kernel panic, you might “brick” your BeagleBone. If that happens, just remove the SD-card, place it in an SD-card reader and access it though your computer. Once it is mounted, you can cd to it from a shell, but you need to be root to be able to change anything.

cd /mount/Angstrom/boot/
rm uImage
ln -s uImage-3.2.18 uImage

Once that is done, put the SD-card back in your BeagleBone and start her up. You should be back to scratch, but no harm done.

13 thoughts on “Compile a new kernel for BeagleBone

  1. Hi, Slimlogic here, the guide is quite old now and the guts of openembedded have changed a lot since I wrote it. When I get time I shall have to revisit and check if there is a new method to do it.

    • Great! It’s a nice guide you have, so it would be good to have it as a reference. All I got when trying to do the “deploy” command was “no tasks deeded to rerun” or whatever it says..

    • Janson, I will definitely submit my patches upstream, but I accidentally ordered a 16K EEPROM instead of the required 256K, so I need to get it working with the 256K before submitting. BTW I like that pin-muxing is now being read from the EEPROM great progress! Are there any plans for configuring the different buses based on the EEPROM as well? Like I need SPI 2.0 and SPI 2.1 enabled, but I have to recompile the kernel for that. Should be a way to do some more configuration based on the EEPROM, right?

  2. Pingback: Enable spi2.1 on BeagleBone | Hipstercircuits

  3. These instructions have worked wonderfully: I now see kernels built with the configuration I’ve specified in the arch/arm/boot directory and am now ready to write my module! Yes! Thank you all!

      • Thanks! Even better news:
        bitbake virtual/kernel -c install
        left me with a correctly installed target in
        $HOME/oe/setup-scripts/build/tmp-angstrom_v2012_05-eglibc/work/beagleboard-angstrom-linux-gnueabi/linux-mainline-3.2.28-r122a/image/boot

        I do think the correct OE-Core task is install and not deploy any longer.

        I finally found the OpenEmbedded User’s guide with a link to the bitbake tasks.

        • Tony, the “install” command does indeed produce an image in the folder you have described. I was only able to do it when adding the “-f” option to force it to install. It did take an inordinate amount of time, though, like several minutes.. Can you verify that you get an updated image with a
          bitbake virtual/kernel -c compile -f
          bitbake virtual/kernel -c install
          cycle? Or do you need to force the install command as well. If so, how long doews it take?

          • I performed your steps as requested. I received an updated image.

            I ran this:
            date; bitbake virtual/kernel -c clean; ls -l $HOME/oe/setup-scripts/build/tmp-angstrom_v2012_05-eglibc/work/beagleboard-angstrom-linux-gnueabi/linux-mainline-3.2.28-r122a/image/boot; date; bitbake virtual/kernel -c compile -f ; date; bitbake virtual/kernel -c install; ls -l $HOME/oe/setup-scripts/build/tmp-angstrom_v2012_05-eglibc/work/beagleboard-angstrom-linux-gnueabi/linux-mainline-3.2.28-r122a/image/boot ; date

            starting: Mon Jan 28 18:24:47 EST 2013
            after kernel build: Mon Jan 28 19:22:11 EST 2013
            after install: Mon Jan 28 21:39:52 EST 2013

            Here’s the output of ls:

            total 18144
            drwxr-xr-x 2 tonyr tonyr 4096 Jan 28 21:25 ./
            drwxr-xr-x 6 tonyr tonyr 4096 Jan 28 21:25 ../
            -rw-r--r-- 1 tonyr tonyr 97978 Jan 28 21:25 config-3.2.28
            -rw-r--r-- 1 tonyr tonyr 521360 Jan 28 21:25 Module.symvers-3.2.28
            -rw-r--r-- 1 tonyr tonyr 1908747 Jan 28 21:25 System.map-3.2.28
            -rw-r--r-- 1 tonyr tonyr 4388848 Jan 28 21:25 uImage-3.2.28
            -rw-r--r-- 1 tonyr tonyr 11601708 Jan 28 21:25 vmlinux-3.2.28

            My system is a lot slower than yours– it’s some old Celeron. It works in a pinch, though.

  4. If you clean in between every build it is gonna take a lot of time. It’s impossible to get any work done at that rate. My recommendation is still compile -f and fetching the image from the folder described above, that is the fastest ~ 2min compared with ~2 hours : )

    • Agree. I did a clean to ensure the test fit the style Graeme had created on his site. My install task time is around 2 hours. I do not yet understand what’s going on in this situation so I am just going to run two install tasks in a row. Nothing should be changing so the total time to install should be the two minutes you are experiencing… just enough time to get the cache, look at all the timestamps, declare no work, and mention 318/318 tasks done.

      Thanks for the discussion.
      T

      • Without -f, bitbake did nothing for two installs in a row. I did bitbake virtual/kernel -c -f install to get it to put a new set of files into the install directory.

        Time before: Tue Jan 29 18:11:52 EST 2013
        Time after: Tue Jan 29 18:30:43 EST 2013

        Takes a bit but it’s nice to see kernels.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>