Sunday, October 31, 2010

Installing Angstrom on the BeagleBoard-xM

This tutorial will show you how to set up Angstrom Embedded Linux on the BeagleBoard-xM.  Thanks to the works of others this is a much easier process that it use to be.

I am using Ubuntu 10.4 as my development machine and I am using the BeagleBoard-xM as the target.  Most of this should apply to other Linux Distributions and the original BeagleBoard.

First, we need to find out where your sd-card is mounted.  Plug in a sd-card into your computer wait for it to mount.  Then run the following command.

df -h

You will see something like this:
/dev/sda5              98G   56G   38G  61% / 
none                  1.5G  316K  1.5G   1% /dev 
none                  1.5G  724K  1.5G   1% /dev/shm 
none                  1.5G  336K  1.5G   1% /var/run 
none                  1.5G     0  1.5G   0% /var/lock 
none                  1.5G     0  1.5G   0% /lib/init/rw 
none                   98G   56G   38G  61% /var/lib/ureadahead/debugfs 
/dev/sdb1              15G  8.0K   15G   1% /media/FAE3-DCE5 

Look for a line that starts with /dev/sdXX in it; generally it will be mounted to the /media directory (on Ubuntu anyway).  Make sure the size of the sd-card is right to verify.  My sd-card is /dev/sdb.   [/dev/sdb1 is the first partition of the /dev/sdb drive].  You will need this device directory further in this exercise.

Setting up the sd-card.

For Angstrom to run you will need to have a sd-card with two partitions; one fat partition to hold the boot files and then a ext3 partition with the root file system on it.  Thanks to Graeme Gregory there is a nice script to set up you sd-card.    Execute the following commands which will make a working directory, download Graeme's script and execute it.  Be sure to substitue your sd-card device directory (from above) for /dev/sdX below. 

mkdir ~/angstrom-wrk
cd ~/angstrom-wrk
chmod +x
sudo ./ /dev/sdX 
Remove the card, wait two/three seconds, plug it back in.  Wait a few seconds and verify the sd-card is mounted by executing:

df -h

You should have two new mounted partitions:


The card is now ready.  You only need to do this process once for the life of the card.

Generating a build:

 Go to the Narcissus website and generate a build.  A good place to start is to select: BeagleBoard (the original BeagleBoard and BeagleBoard-xM both use the same build); simple; and console only.  In the “Platform Specific Packages” check “Texas Instruments OMAP3x/AM3x family:-->Bootloader Files (x-load/u-boot/scripts)”.  Now click the “build me!” button on the bottom of the page and wait for the “builder” to generate the “*.tar.gz” file.  Download the “*.tar.gz” file into your working directory.  Don't worry about the second file.

Setup the boot partition:

There are only three files that are mandatory for boot partition.  The following lines will extract the files from the download build and copy those to the boot partition on the sd-card.

# extract the files to the ./boot directory
tar --wildcards -xjvf [YOUR-DOWNLOAD-FILE].tar.bz2 ./boot/*

# copy the files to sc-card boot partition.
cp boot/MLO-* /media/boot/MLO
cp boot/uImage-* /media/boot/uImage
cp boot/u-boot-*.bin /media/boot/u-boot.bin

Last thing to do is to copy the root filesystem over.

sudo tar -xvj -C /media/Angstrom -f [YOUR-DOWNLOAD-FILE].tar.bz2

Now make it safe to remove your sd-card.

umount /media/boot
umount /media/Angstrom

Your done; remove the sd-card and plug it into your BeagleBoard-xM and apply power to the board.

Friday, October 29, 2010

Setting Up Qt Development Environment for BeagleBoard-xM

This blog will show you how to set up Qt Creator to Develop Qt code for the Beagleboard-xM that is running Angstrom Linux.  In addition I will show you what you need to setup on your Beagleboard-xM to execute those programs.

I am developing my QT code under Linux, specifically Ubuntu 10.4.  IMHO it is a mistake to develop Qt natively on the Beagleboard except for trivial applications.  Although this blog discusses Ubuntu 10.4 as the development environment and Beagle-xM as the target this blog should be valuable when it is applied to other Linux and the original Beagleboard.

Be ready to spend a few hours getting this set up!

Useful Links:

Angstrom Angstrom Embedded Linux OS.
Angstrom Manual 
Qt Embedded Website
Qt Site on BeagleBoard   Includes specific instructions for the SGX GPU
TI's Building Qt Website  Texas Instruments excellent site for getting started.

Installing Qt-Creator:

I prefer to get Qt-Creator from their website rather than Ubuntu's Software Center because you get the latest version and it is easy to install.  Go to to download Qt.  Get the latest version of Qt for Linux; be sure to get the appropriate 32bit or 64bit version.  [This blog assumes that you are using the 32 bit version.]  Once downloaded go to the download directory and execute the following using your download file name:
chmod u+x qt-sdk-linux-x86-opensource-2010.05.1.bin

Installing the Cross-Compiler:

You will need to install a toolchain that will compile code on your Linux box that is intended to run on the ARM processor on your BeagleBoard.  Different arm processors need different compiler options.  So the easiest way to do this is to download a pre-configured toolchain for the Embedded OS and processor you are using.  Go to the Angstrom toolchain website and download a toolchain.  The ARM Processor on the BeagleBoard-xM is a Texas Instruments DM3730 which uses a ARM 7a Core.

For 32-bit Ubuntu you will want to download this file:
For 64-bit Ubuntu you will want to download this file:

Go to the download directory and run:
sudo tar -xvj -C / -f [DownloadFileName]

Building Qt:

Now that you have your cross compiler installed it is time to compile Qt with it.  First thing to do is to download the Open Source LGPL version of Qt libraries 4.6.2 for Embedded Linux here.  Remember your download directory, you will need it for the following steps.

First; unzip the tar file you just downloaded.  Go into the download directory and execute:
tar -xvzf qt-everywhere-opensource-src-4.6.2.tar.gz

You need to create a new make.conf.  Run the following line to make a new mkspecs directory for the BeagleBoard Processor.
cp -R [DownloadDirectory]/mkspecs/qws/linux-arm-g++/ [DownloadDirectory]/mkspecs/qws/linux-DM3730-g++/

Edit the qmake.conf file found in [DownloadDirectory]/mkspecs/qws/linux-DM3730-g++/ to look like the following.
# qmake configuration for building with arm-linux-g++


# modifications to g++.conf

#Compiler Flags to take advantage of the ARM architecture
QMAKE_CFLAGS_RELEASE =   -O3 -march=armv7-a -mtune=cortex-a8 -mfpu=neon -mfloat-abi=softfp
QMAKE_CXXFLAGS_RELEASE = -O3 -march=armv7-a -mtune=cortex-a8 -mfpu=neon -mfloat-abi=softfp

QMAKE_CC = /usr/local/angstrom/arm/arm-angstrom-linux-gnueabi/bin/gcc
QMAKE_CXX = /usr/local/angstrom/arm/arm-angstrom-linux-gnueabi/bin/g++
QMAKE_LINK = /usr/local/angstrom/arm/arm-angstrom-linux-gnueabi/bin/g++
QMAKE_LINK_SHLIB = /usr/local/angstrom/arm/arm-angstrom-linux-gnueabi/bin/g++

# modifications to linux.conf
QMAKE_AR = /usr/local/angstrom/arm/arm-angstrom-linux-gnueabi/bin/ar cqs
QMAKE_OBJCOPY = /usr/local/angstrom/arm/arm-angstrom-linux-gnueabi/bin/objcopy
QMAKE_STRIP = /usr/local/angstrom/arm/arm-angstrom-linux-gnueabi/bin/strip


We are just about ready to compile Qt.  You can look at the configuration options before you start by running the following command.
cd [DownloadDirectory]
./configure --help

Now run the configure command [this can take many minutes]:
./configure -opensource -confirm-license -prefix /opt/qt-arm -no-qt3support -embedded arm -little-endian -xplatform qws/linux-DM3730-g++ -qtlibinfix E

See this website for more details if needed.  [Note:  If you are using a 64-bit version of the compiler you will need to use "-platform /qws/linux-x86_64-g++" instead of "-platform '/qws/linux-x86-g++" in the above. ]

Once this is complete you can run make and make install [make can take many hours]:
make install

Setting Up Qt-Creator

Once make and make install are complete you can add the Arm tools to Qt-Creator.  Start Qt-Creator select Tools->Options->Qt4->Qt Versions.  Press the + button and fill out the form as show below.

Setting up the BeagleBoard-xM

Now it is time to set up the Beagleboard. All of the Qt files that you need to move to the BeagleBoard can be found in the /opt/qt-arm/lib directory on your Linux Build System.

Unfortunately Qt expects the library and font files to have the same directory structure on your build machine and your target machine.  On our systems that directory is /opt/qt-arm/lib because we used "-prefix /opt/qt-arm" in our configuration. So on your Beagleboard you need create the /opt/qt-arm/lib directory.
cd /
mkdir opt
cd opt
mkdir qt-arm
cd qt-arm
mkdir lib
cd lib

Now you need to copy all the files out of your build system's /opt/qt-arm/lib directory and put those into the BeagleBoard-xM's /opt/qt-arm/lib directory. You can get the files to the Beagleboard by either networking, using a usb drive or plug the SD card into your Linux Build System.

You will now need to set up the BeagleBoard's path to point to this library directory. Edit the PATH statement in /etc/profile to the following:

There are a few packages you need to install on your BeagleBoard-xM to support Qt.
Connect your BeagleBoard to the Internet.

If you have not updated your opkg mangers library in a while then run:
opkg update

To get the packages run:
opkg install libgles-omap3
opkg install libstdc++6
opkg install libpng12-0

These packages are the ones that I found I needed when running a Qt program that uses the QtCore andQtGUI; other packages may need to be added as your Qt program uses more Qt libraries.

If you are unable to connect the BeagleBoard to Internet you can go here to download the packages.

Building and Running a Qt Program.

Start Qt-Creator; Create a new project. Go to Projects and make sure your Build Settings is set to QT BeagleBoard 4.6.2. Build your project. Copy your executable to the BeagleBoard and execute it. Normally you will be running the program (if it is a GUI application) using the Frame Buffer and you will need to use the -qws option.
My-First-BB-Program -qws

Good Luck! be sure to comment below. As people provide input I will modify this document.