Compiling the Linux kernel for BeagleBoard-XM

First of all, this post is not about building an Angstrom distribution (Linux OS that is known to run well on embedded devices) from scratch. This about compiling a Linux kernel source which you can boot from using your Angstrom distro. I’m assuming that you already have a working Angstrom MMC with you. I used the one that came along with the BeagleBoard XM, pre-installed with Angstrom.

Before getting started, a few words regarding how the MicroSD card is structured. It has two partitions on it. A FAT partition and an ext partition. The FAT partition contains 4 files namely MLO, u-boot.bin, uEnv.txt and UIMAGE. The ext partition contains the root directory of the distribution. That means it contains ‘/‘.

The BeagleBoard boots from the Linux kernel within the /boot/ directory of the ext partition. That directory will contain a symbolic link called uImage which we will point to the kernel image we want the BB-XM to boot to.

It might be well to point out here that I tried 5 versions of the kernel from kernel.org and all of them failed to work and I was unable to debug the reason for that. However, it seems that there was a certain group of people working on patching up the kernel to make it compatible exactly for the BB-XM. We will be using their source in this post.

So let us get the tools ready. First you need to get the toolchain for doing the cross compilation. You can get it from here. Download the ones for ARM and GNU/Linux. You’ll need to register yourself to download it. Once downloaded, extract it to some convenient location and set your PATH environmental variable to point to there. Refer to the following figure:

Now we need to get the kernel source. As I said earlier, we are not going to use the source from kernel.org but instead, we are going to use the source from the following repository.

https://github.com/beagleboard/kernel

Clone that repository. At the time I was trying to compile the source, the stable branch was the 3.0 one. So I’ll be using the same for demonstrating in this post. Clone that repository and checkout the 3.0 branch. To checkout, run:

git checkout origin/beagleboard-3.0 -b beagleboard-3.0

Once you have checked out that branch, run the patch.sh file there.

./patch.sh

It will fetch a few patches and apply them in the source. Once you are through with that, you need to setup the configuration of the kernel. Normally, we do this by using the default omap2plus_defconfig configurationgiven in the kernel source but, try as I might, it did not work for me. Hence we will use the config file created by running the patch.sh file as our kernel configuration. But first, after running the patch file, your directory will look like below:

You can see the configurations that the kernel provides. You can see omap2plus_defconfig there. Now I will explain the 4 steps of kernel compilation.

Step 1

We need to give the kernel configuration. As stated before, we are going to use the configuration created by the patch.sh file. In order to do this, copy the configuration from the /patches/ directory to the .config file under the kernel source. Assuming you are in the kernel source directory (as given in the above figure) you would do:

cp ../patches/beagleboard/defconfig .config

However, keep in mind that this is not the standard way of doing things. Usually, we do the following:

make -j2 ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- <defconfig>

Where <defconfig> should be replaced by whichever configuration you want from the /arch/arm/configs/ directory.

Step 2

We can access the configuration file of the kernel as a menu and manipulate several options such as which all modules we want enabled as well as whether certain modules should be compiled as ‘built-in’ to the kernel or compiled as a separate module. In order to get the menu, we do:

make -j2 ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- menuconfig

After making the necessary changes, save and quit.

Step 3

Now we actually compile and make the Linux kernel image.

make -j2 ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- uImage

This will take a while. Once it is finished, you can get the kernel image called uImage under the /arch/arm/boot/ directory. Copy this image into the /boot/ directory of the ext partition of the MicroSD card. After copying, get the symbolic there called uImage to point to our new image. You can do this by:

sudo ln -sf <destination> <source>

Once that is done, we proceed to the next step.

Step 4

Here we compile the corresponding modules of the kernel separately. In oder to do this, you run:

make -j2 ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- modules

This will also take a while depending on how many modules you selected to be compiled in the menuconfig interface. Once this is finished, you have to install these modules. For that, you do:

make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- INSTALL_MOD_PATH=<path to where you mounted the mmc root diectory> modules_install

This will install the compiled modules under /lib in the path given. The path that I would give in my system would be /media/Narcissus-rootfs. Refer to the following figure. You can see the different directories corresponding to the different versions of the kernel I tried compiling.

Now everything is set. There are a few more points to note however. You can find the following line in the uEnv.txt file within the FAT partition.

console=”tty0 console=ttyS2,115200n8″

Change it into

console=”tty0 console=ttyO2,115200n8″

One more thing. Within the /etc/inittab file of  your MicroSD card’s root directory, you can find the following line:

S:2345:respawn:/sbin/getty 115200 ttyS2

Chang it into:

S:2345:respawn:/sbin/getty 115200 ttyO2

Basically, what you did in the above two steps is to replace the places where ttyS2 is present with ttyO2. I think this is because kernel versions from 2.6 onwards use ttyO2 as their console. If you do not do the above change, you might get the following error in the middle of booting the kernel:

INIT: Id “S” respawnin too fast: disabled for 5 minutes

——————————————

You are good to go. You can now boot from the new kernel.

Happy hacking!

Advertisements

6 thoughts on “Compiling the Linux kernel for BeagleBoard-XM

  1. Hi ! many thanks for sharing I’m desparatly tryning to fin a valid kernel for xM in order to make dsp video tests.
    omappedia wiki does not provide a valid git tree or branch so I harldy could put their kernel working (still no video output).
    I hope this time I got a working stuff (still patchin).
    Anyway I got some error executing the patch :
    1) there’s a call to “git clone git://….linux.git .” that leads to a fatal error ( ‘.’ exists). We must replace this line with “git clone git://…/linux.git foo ; mv foo/* foo/.git* .; rm -rf foo”.
    2) when applying patch there is the use of the -q (quiet) option not supported by my git version (1.6.0.4) (ubuntu 9.04 I shall update it :D). Just skip the -q version and go on.

    • My pleasure that my post was of help to you. Good of you to share the errors that you encountered. Even though I did not have any of the errors above while running the patch script, I’m sure it will be helpful to those people who do get stuck with it.

      Cheers!

      PS: Yes, don’t think twice, do go and update your Ubuntu!

  2. More notes : by the time I’m writing this comments the config file is not under beagleboard but beaglebone but the config file should work (I’ve seen the beagleboard board selected in it)
    I used the las Code Sourcery release recommended : 2012.03-57
    Instead of calling make with ARCH and CROSS_COMPILE variable you can export them once in your shell (and for the shell only) or in your bashrc.
    Just in case : -he -j option is the number of jobs, best value is number of proc+1

    Pb at compilation :
    I just got an error when compiling kernel : firmware/am335x-pm-firmware.bin is missing, do you have it ? I have no .bin file in any directory. In fact in this google group there is a git link for downloading this file (https://groups.google.com/forum/#!topic/beagleboard/zzY2FB2_aAw).

    I got also an error when executing this step at the end : “LZO arch/arm/boot/compressed/piggy.lzo”, lzop unknown command. Just install in your distrib lzop package. And also tghe mkimage util.

    PB a launch :
    After first compilation & launch got à kernel “oops” : Linux version 3.2.25+ (sli@SLI-V420) (gcc version 4.6.3 (Sourcery CodeBench Lite 2012.03-57) ) #1 Thu Sep 6 11:09:11 CEST 2012
    [ 1.464323] CPU: 0 Not tainted (3.2.25+ #1)
    [ 1.469114] PC is at omap2_prm_read_mod_reg+0x6/0x10

    After waving around I decided to modify by myself the .config file as some critical device selection may be specifif to the beaglebone (and some other stuff).

    But there is still no improvement. Using default omap2 config file doesn’t not even compile.

    ==> I think this repository has moved to beaglebone support only. I’ve gone to the IRC chat and one of the maintainer suggested me trying another repository.

    • Thanks mate for taking the time to help out.

      I have a few .bin files with me, but not the one you asked for. As for the error that you encountered while maing the uImage, it is due to the absence of a package that helps in making U-boot images. I believe in Debian based distros, it is uboot-mkimage.

      If they have shifted support entirely for Beaglebone boards, then that kernel might not work.

      Thanks for the link! I’m sure people who visit this page will find it useful.

      Cheers!

Hey! What do you think? Share your thoughts. :)

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s