Introduction to Cross Compilation

If you need a customized root filesystem or need to compile packages that have many dependencies, see the How To explaining the OpenEmbedded Build System.  If you need to rapidly iterate in developing a small piece of C/C++ code, check out the guide to native compilation on a Gumstix COM.  The following guide explains how to set up a basic cross-compilation environment.  These instructions are given for a Debian-based host system, however they are similar for other Linux OS distributions.

Cross-Compiling the Linux Kernel

First, we explain how to cross-compile just the Linux kernel and run it on your Gumstix device without using a full buildsystem system.

Getting the Cross-Compiler

First, we need to get the cross-compiler.  From Debian, Ubuntu, or Mint, use the following command:

sudo apt-get install gcc-arm-linux-gnueabi uboot-mkimage

Getting the Kernel Source Code

Next, we need to download the kernel source code

Building the Kernel

Next you will need to get a default configuration (defconfig) for your architecture. We recommend you use the same defconfig Gumstix uses in its Yocto Project builds. Currently you can find this at:

https://github.com/gumstix/meta-gumstix/tree/dylan/recipes-kernel/linux

From these files, select the kernel version you are using, then your platform, and finally download the file defconfig. (E.g., for DuoVero, you will need the file https://github.com/gumstix/meta-gumstix/blob/dylan/recipes-kernel/linux/linux-gumstix-3.6/duovero/defconfig).

Rename this file to <platform>_defconfig (i.e., for DuoVero, rename it duovero_defconfig) and move it to the arch/arm/configs subdirectory in your kernel working directory. Overwrite anything already there.

You can now run the configuration. Replace <platform>_defconfig with the name of the file you renamed in the last step:

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- <platform>_defconfig

Then configure the kernel to your needs:

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

Compile it:

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- uImage -j4

Replace the -j4 option with however many threads you want GNU make to utilize.  Usually using twice as many threads as CPU cores available is good practice.  When finished, the uImage kernel file can be found in the arch/arm/boot directory.

Kernel modules can be similarly compiled:

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- modules -j4

The following command would then install these modules to a preformatted microSD card where the root file system is mounted at /media/rootfs.  Run depmod on the gumstix to make sure these new modules can be found.

sudo INSTALL_MOD_PATH=/media/rootfs make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- modules_install

Testing the Kernel on Physical Hardware

You can use your custom uImage with the guide here: http://gumstix.org/create-a-bootable-microsd-card.html

Grab any binary files that you don't build yourself from the downloads page section for Yocto Project.

You may want to write a script that copies over the kernel automatically each time you build.  If your kernel doesn't load, try using an earlier version.  If you can't login or the image freezes, try using a different rootfs.

Testing the Kernel on Emulated Hardware (Qemu)

If you want to test the kernel without access to physical hardware, you can emulate the system using Qemu.  You can make images for Qemu using this script: http://wiki.gumstix.org/index.php?title=Overo_qemu_script .  You use it like this:

# assemble-image.sh $OVEROTOP/overo.img $OEDONE/MLO-overo $OEDONE/u-boot-overo.bin $OEDONE/uImage-overo.bin $OEDONE/omap3-console-image-overo.tar.bz2

Again, use a combination of your custom files and prebuilt binaries from cumulus.

To run qemu, install it (see https://launchpad.net/qemu-linaro/ for details), and then run the following command:

qemu-system-arm -M overo -m 256 -sd ./overo.img -clock unix -serial stdio -device usb-mouse -device usb-kbd

If the qemu version you're using doesn't support the overo, try using qemu-linaro (https://launchpad.net/qemu-linaro/)

Note: this article is not yet finished and requires additional content. ·Thanks for your patience and check back soon.

Useful Links

A common case is building the Linux Kernel. ·These blogs offer good information and can be a valuable resource.  

  • Elphel
  • BEC·(note that the cross-compiler path has changed in recent versions of OE from something like·/oe/build/angstrom-2008.1/tmp/cross/armv7a/bin to something like oe/tmp/sysroots/i686-linux/usr/armv7a/bin)
  • AO2.
Home Introduction to cross-compilation