Difference between revisions of "EBC Exercise 08a Cross-Compiling"

From eLinux.org
Jump to: navigation, search
(Step 4 - Start building)
(Step 4 - Start building)
Line 126: Line 126:
| T2600@2.16 GHz
| T2600@2.16 GHz
| PARALLEL_MAKE = "-j4"<br>BB_NUMBER_THREADS = "4"<br>Psyco? Yes.
| PARALLEL_MAKE = "-j4"<br>BB_NUMBER_THREADS = "4"<br>Psyco? Yes.
| ''pending''
| E5410@2.33 GHz (x2)
| PARALLEL_MAKE = "-j8"<br>BB_NUMBER_THREADS = "8"<br>Psyco? No.
| ''pending''
| ''pending''

Revision as of 01:38, 11 March 2010

This class is about developing software for embedded Linux. The eLinux site is a good source for embedded Linux in general. There are many ongoing embedded efforts going on many platforms. Poke around the site a while to get a feel for what's happening.

We are going to use the Ångström Distribution. It's available many platforms. Look around the site, you may recognize some of them.

Instructions for building Ångström are given here; however I'm going to present a Beagle-tuned version of those instructions on this page.

Step 1 - get Open Embedded metadata

First install git by running the following on your host computer.

sudo apt-get install git-core

Then run the following to load the meta data.

export OETREE="${HOME}/oe"
mkdir -p ${OETREE} && cd ${OETREE}
git clone git://git.openembedded.org/openembedded.git openembedded
cd openembedded
git checkout origin/stable/2009 -b stable/2009

If git://git.openembedded.org/openembedded.git does not work, you can also try http://repo.or.cz/r/openembedded.git.
The first git transfers some 336,000 object and takes about 18 minutes with the network running at 600 some KiB/s. Keep an eye on it, mine stopped about 23% in and I had to restart it. The second git takes almost no time.

Now run the following to update the metadata:

cd ${OETREE}/openembedded 
git pull

You've created a directory called oe. Go explore around it to see what is there. Be sure to look in oe/openembedded/recipes. These folders contain instructions on where to get and how to build various things. Look in recipes/Linux. Here are instructions for building various Linux kernels. We'll be using linux-omap-2.6.*. What's the highest version you can find?

Step 2 - Installing bitbake and friends

bitbake is the workhorse that knows where to get everything and how to compile it. The following will install bitbake and additional programs that bitbake needs. This may take 5 minutes.

sudo apt-get install bitbake
sudo apt-get install g++
sudo apt-get install help2man diffstat texi2html cvs texinfo subversion gawk
sudo apt-get autoremove

If you are running Ubuntu you will have to also do the following:

cd /bin
sudo mv sh sh.old
sudo ln -s bash sh
sudo sh -c "echo 0 > /proc/sys/vm/mmap_min_addr"

Finally edit the file /etc/sysctl.conf using:

sudo gedit /etc/sysctl.conf

Add the following at the end and save.

# This is for bitbake
vm.mmap_min_addr = 0

Now you should be ready to run bitbake.

Tools.svg Give to the community: Psyco JIT compiler
bitbake suggest loading a compiler. Load and test the compiler. If it's worth using, write instructions.

The Psyco JIT compiler should help speed up compilation times. To install, use

sudo apt-get install python-psyco

Step 3 - Setting up for the BeagleBoard

We need a small script to setup the environment, so download source-me.txt to ${OETREE}.

Now let's setup local.conf for our needs:

mkdir -p ${OETREE}/build/conf
cp ${OETREE}/openembedded/contrib/angstrom/local.conf ${OETREE}/build/conf/

Open ${OETREE}/build/conf/local.conf in your favourite editor and add the following to the end of the file.

MACHINE ?= "beagleboard" 

Also, look at this block of lines:

# Make use of SMP and fast disks

Here you can tell it how many parallel threads to run. If you have several cores on your machine, make this number big. If you have only one core, you might be better performance setting it to 1. More details are here.

Step 4 - Start building

Do the following...

# set environment variables
cd ${OETREE}
source source-me.txt 

#Go to the OE tree
cd ${OETREE}/openembedded 

#Make sure it's up to date
git pull --rebase

#Start building
bitbake nano

This will take a while. bitbake is installing everything that is needed to compile the system. This includes cross compilers, assemblers, source, everything. I started at 10am and ended around 5:30pm. It was running on just one of the two cores on my laptop. How long did it take on your machine? I notice that an additional 600M of disk space is being used.

Tools.svg Give to the community: Keep track of you running times and configurations.
We'll use this data to see what the best settings are.
Initial bitbake nano runtime
Processor Settings Run Time
T2600@2.16 GHz PARALLEL_MAKE = "-j4"
Psyco? Yes.
2.5 hours
T2600@2.16 GHz PARALLEL_MAKE = "-j4"
Psyco? Yes.
E5410@2.33 GHz (x2) PARALLEL_MAKE = "-j8"
Psyco? No.

Step 5 - Building a complete image

Up to this point all we have done is load all the infrastructure needed and compiled the simple nano text editor. We don't even have the kernel yet. Do the following to build a basic console image.

bitbake console-image

This bitbake took 7 hours and 15 minutes. There are now some 7,700 directories with 67,000 files in the oe directory. An additional 1.5G of disk space is in use.

How did I know to use console-image? I ran the following to find what images were out there:

locate image | grep /oe/

This found every file with image in the name it that also had /oe/ in the path. From this I see that oe/openembedded/recipes/images has a bunch of files ending in -image. Take a look at console-image.bb and see what you can figure out.

Step 6 - Loading your SD card

The output of the bitbake command will ultimately be found under the $OE_HOME/angstrom-dev/deploy/glibc/images/beagleboard. In there you can find at least two interesting files:


The console image represents a full and self-contained file system, *including* a kernel. The uImage-beagleboard.bin is a Linux kernel image suitable for loading by the U-boot bootloader.

  • Rename uImage-beagleboard.bin as uImage and load on your SD as before (Getting your Beagle running).
  • Also load console-image-beagleboard.tar.bz2 on the 2nd partition like you did before. Did you notice it untar's very quickly? Why?
  • Boot and explore. What's there? What's missing?

Congratulations you've just build Linux from source. Try this:

beagleboard login: root
root@beagleboard:~# cd /sys/class
root@beagleboard:/sys/class# ls -F
bdi/          hwmon/        misc/         scsi_generic/ usb_device/
block/        i2c-adapter/  mmc_host/     scsi_host/    usb_endpoint/
bluetooth/    i2c-dev/      mtd/          sound/        usb_host/
bmi/          ieee80211/    net/          spi_master/   usbmon/
display/      input/        regulator/    spidev/       vc/
firmware/     leds/         rtc/          thermal/      vtconsole/
gpio/         mdio_bus/     scsi_device/  tty/
graphics/     mem/          scsi_disk/    ubi/

This is a list of low-level devices on the Beagle that you can access as files. Try:

root@beagleboard:/sys/class# cd leds/
root@beagleboard:/sys/class/leds# ls -F
beagleboard::usr0@ beagleboard::usr1@
root@beagleboard:/sys/class/leds# cd beagleboard\:\:usr0
root@beagleboard:/sys/devices/platform/leds-gpio/leds/beagleboard::usr0# cat trigger
none nand-disk mmc0 mmc1 [heartbeat]

This is a list of values you can assign to trigger. Notice LED0 is blinking on and off right now. Try:

root@beagleboard:/sys/devices/platform/leds-gpio/leds/beagleboard::usr0# echo none > trigger
root@beagleboard:/sys/devices/platform/leds-gpio/leds/beagleboard::usr0# echo 1 > brightness

What happens? Play around. Here are instructions on reading the USER switch. Try it. Can you make the LEDs blink in response to the button being pressed?

Step 7 - Building a complete Beagle demo image

Now let's build the how demo we were running before. We'll do this via bitbake, but argument do we give it? Try looking in oe/openembedded/recipes/images, do you see a recipe that might work? Hint: It has beagle in the name. Here's what I tried.

time bitbake beagle????-image

Replace ???? with the recipe name you found. I added the time command so I could see how long it takes to run. My run took some 7.5 hours.