EBC Exercise 08a Cross-Compiling

From eLinux.org
Revision as of 06:52, 22 October 2012 by Yoder (talk | contribs) (Finding the Kernel for the ETC 2012 image: Removed)
Jump to: navigation, search

thumb‎ Embedded Linux Class by Mark A. Yoder

This class is about developing software for embedded Linux. So far we have been doing all of our development on the Beagle. This works well for small (and not so small) programs. However, we are now moving into kernel development and that's best done on a more powerful host computer. In EBC Exercise 08 Installing Development Tools you learned how to download and install the cross-compilers and the source for kernel and u-boot. Now we'll use those tools.

First we'll check everything by compiling the Hello World program, then we'll try the kernel and u-boot.

Cross-compiling Hello World

Listing 2-4 on page 29 of the text is an embedded version of Hello World. If you've set up your git repository you will find it in helloWorld.c when you do a git pull. Compile and run it on your host to be sure it works.

host$ gcc helloWorld.c
host$ ./a.out
Hello, World! Main is executing at 0x400524
This address (0x7fff8260bdf8) is in our stack frame
This address (0x601038) is in our bss section
This address (0x601020) is in our data section

Now that you know it's working, let's cross compile it. First set the paths to find the cross-compilers. Put the following in a file, call it ~/.oe/crossCompileEnv.sh. Make sure the path is correct for your system. This is for a 32-bit linux.

# add cross tools to your path
export ARM_TOOLCHAIN_PATH=~/BeagleBoard/oe/build/tmp-angstrom_v2012_05-eglibc/sysroots/i686-linux/usr/bin/armv7a-angstrom-linux-gnueabi
export ARCH=arm
export CROSS_COMPILE=arm-angstrom-linux-gnueabi-

Here it is for 64-bit

# add cross tools to your path
export ARM_TOOLCHAIN_PATH=~/BeagleBoard/oe/build/tmp-angstrom_v2012_05-eglibc/sysroots/x86_64-linux/usr/bin/armv7a-angstrom-linux-gnueabi
export ARCH=arm
export CROSS_COMPILE=arm-angstrom-linux-gnueabi-

Now source the file and compile again. (Note: you only have to source once per terminal session.)

host$ source ~/.oe/crossCompileEnv.sh
host$ ${CROSS_COMPILE}gcc helloWorld.c
host$ file a.out
a.out: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.16, not stripped

The file command tells what's in the file. In this case we have an ARM executable. Success! Now copy to your Beagle and run

host$ scp a.out root@beagle:.
host$ ssh root@beagle ./a.out
Hello, World! Main is executing at 0x8374
This address (0xbeb32d4c) is in our stack frame
This address (0x10650) is in our bss section
This address (0x10648) is in our data section

The scp copies a.out to the beagle and the ssh runs the a.out on the beagle. Notice the address are very different from the host version.

Stop Here, the rest hasn't been updated

Installing a New U-boot

While we're at it, let's install a new U-boot. Note: The new U-boot runs for me, but doesn't boot the kernel, yet.

host$ cd ~/BeagleBoard/oe/build/tmp-angstrom_2010_x-eglibc/work/beagleboard-angstrom-linux-gnueabi/
host$ ls -F

There's the U-boot directory.

host$ cd u-boot-2011.09-r4/git/; ls -F
api/        COPYING    fs/          mkconfig*     post/            tools/
arch/       CREDITS    include/     mmc_spl/      README           u-boot*
board/      disk/      lib/         nand_spl/     rules.mk         u-boot.bin
boards.cfg  doc/       MAINTAINERS  net/          snapshot.commit  u-boot.lds
common/     drivers/   MAKEALL*     onenand_ipl/  spl/             u-boot.map
config.mk   examples/  Makefile     patches/      System.map       u-boot.srec

The file we want is right on the top level.

host$ scp u-boot.bin root@beagle:.
host$ ssh -X root@beagle
beagle$ cd /media/mmcblk0p1/; ls -F
MLO*         u-boot.bin.broken*  uEnv.txt*
U-BOOT.BIN*  UIMAGE*             uEnv/

Be sure you are logged into the Beagle via the serial port, rather than using ssh. Otherwise you won't see the boot sequence that appears before the kernel is running.

Here we've changed to the FAT partition which is where u-boot lives. Back it up and install the new one.

beagle$ mv U-BOOT-BIN u-boot-bin.orig
beagle$ mv ~/.u-boot-bin .
beagle$ shutdown -r now

You should now see the new u-boot running if you are logged in via the serial port.

Compile via make

When you use bitbake it sets up all the paths to use the correct cross compilers. You can also build the kernel or u-boot by using make if you set the paths like we did above.

If you haven't already, source the file and cd to the kernel directory and try a make.

host$ source ~/.oe/crossCompileEnv.sh
host$ cd ~/BeagleBoard/oe/build/tmp-angstrom_2010_x-eglibc/work/beagleboard-angstrom-linux-gnueabi/linux-omap-psp-2.6.32-r110b+gitr5fc29e7b2a76a64a739f857858ef0b98294aa155/git
host$ make xconfig

(EBC Exercise 13 Configuring the Kernel has details on configuring the kernel.)

To make the kernel run

host$ make uImage

Now, follow the instructions above to install your freshly compiled kernel.

Getting the A6A Kernel

beagle$ cat /etc/angstrom-build-info 
Configured Openembedded layers:
meta-angstrom     = angstrom-v2012.05-yocto1.2:a029f5f5d19f788e2ab17227f35350ff5b6ca125
meta-multimedia   = denzil:b4488f4c012a64604b28bd2b6e93de411c34466d
meta-opie         = master:efa3892b20a4ef80274e56e5633ebd62c16f9731
meta-java         = master:3386ea6c96096f107f43f282f654e5afa456109e
meta-browser      = master:c47f59df2e723495679c751cbdf6a8c6adec4b6a
meta-mono         = master:83f8233b0498aadb18bf7605c3ba6c71d9e13a3a
meta-kde          = master:5b0882d951cfd71886d423c190faaa7c7f932333
meta-ti           = angstrom-staging:5364d0795bb27c2deb5a4e2df7d2f01ffb394cca
meta-efikamx      = master:2c09a3a780b23448e8a6ca964256ff7f5ccba65d
meta-nslu2        = master:3d9fc951b05b4df476374b6fc3085ebac7f293ee
meta-palm         = master:2b106be01228f64298d6cb338f93088806594344
meta-handheld     = master:1f05a15aceb4c3a19fa070463b58125b5658b2a9
meta-raspberrypi  = denzil:34eef2ea4f5f24630dbb73b386861430167b8431
meta-n450         = master:f75f9b6f68473eb0efac802409608f8389be0030
meta              = denzil:b052427a6678b1b696f8c64cf0fdc55e6af86c48 
host$ cd BeagleBoard/oe/sources/meta-ti
host$ git checkout master

thumb‎ Embedded Linux Class by Mark A. Yoder