Building a Cross-Compilation Environment for the BeagleBone

Do What?

BeagleBone
BeagleBone

Want to write a native executable for the BeagleBone?  You have a few options.  One is to compile the code directly on the BeagleBone with the native compiler that is included with the BeagleBone distribution you are running (if it includes one).  The other is to use a cross-compiler and compile the code on another computer.  This first option will work fine for smaller programs and the official distribution for the BeagleBone is Angstrom Linux-based and includes a compiler.  However, compiling on the Bone itself will be slow for large code bases (like the whole Linux kernel.)  Cross-compiling is better suited for bigger software programs and is much faster on modern PCs.

Here are a simple set of instructions for building the cross-compiler tools for two of the more popular Linux distros to allow you to compile native applications for your BeagleBone.  This information isn’t new and I’ve included the links to the original material below.  However, I’ve added a few tidbits more of information for compiling in either an Ubuntu or CentOS.

What OS Do You Need?

This tutorial assumes you have already installed Linux natively on your hardware or as a virtual machine.  I used a VM in VirtualBox to accomplish these steps.  One VM was an Ubuntu variant (Xubuntu to be exact) and the other VM was CentOS.  Both worked well.  Ubuntu seems to cooperate better out of the box with the VirtualBox Guest Additions to allow the VM to operate more seamlessly.  This is primarily because the base Ubuntu distros include more packages.  CentOS is a slimmer default install but will work fine, too, with some manual tweaking.  The Guest Additions are helpful for things like cutting-and-pasting text to and from the guest OS and for resizing the VM to fit various window sizes.

I allotted both CPUs of my dual-core laptop as well as 2 GBs of memory to the VM.  This much memory is required for the build as the OpenEmbedded/Yocto compilation process builds up some large caches that require the memory.  Anything less than 2 GBs will likely cause build failures.  Once the cross compilation tools are built, you can reduce the amount of memory for the VM if need be.

Note, too, that the build process will generate almost  20 extra Gigabytes of data.  Therefore, count on sizing the virtual hard disk of your VM to be able to handle this file data.  I typically use a dynamic type disk in VirtualBox, but only allocate a small portion of it to the OS.  This let’s me grow it later.  I started out giving Linux only 40GB of a 120GB disk.  My CentOS VM started out at about 3 GB and grew to almost 23 GB.  In retrospect I probably should have gone ahead and given it 100 GB so as not to have to worry about do other kernel builds while maintaining my old ones.  I can always resize the partition later.

Get the Linux Packages You Need

Before the Angstrom Link process will completely build, you need to ensure you have all the required packages on your build OS/VM/PC/Computerthingy.

UbuntuPackages for Ubuntu

Using apt-get, acquire the following packages for your build:

sudo apt-get install git subversion gawk texinfo texi2html chrpath diffstat gcc gcc-c++ libgcc libstdc++ make

CentOSPackages for CentOS

Using the yum installer, acquire the packages below for your build.  Note that if you followed the CentOS instructions for setting up the Virtual Box Client Additions, then you will have already acquired some of these packages so this will progress quicker:

su -c 'yum install git subversion gawk texinfo texi2html chrpath diffstat gcc gcc-c++ libgcc libstdc++ make'

Grab the build scripts

To start the build process you’ll next need to grab the build scripts. These build scripts are based on the OpenEmbedded project’s build system of BitBake recipes.  This system is an alternative process of constructing Linux builds vs. the Buildroot method.  The build scripts are responsible for pulling down the required source, setting up the build environment, and then executing the build.  First, from your main user directory, make a directory to hold the build scripts.  I often named it “development” but you could name it “Francis”, “lemonmeringue”, or “portuguese_antelopes” if it makes you happy.

mkdir development

Change directories into this directory and retrieve the build scripts from the official Angstrom repository:

cd development
git clone git://github.com/Angstrom-distribution/setup-scripts.git

Note that the distribution of Angstrom Linux I was running on the BeagleBone which I was testing was an image created in November of 2012.  Since I pulled the latest version of the Angstrom distro and followed the generic instructions for building the BeagleBone kernel and libraries, I’m assuming it will work with the latest, too.  I had tried using the latest version of the official BeagleBone Angstrom distro (June 2013), but experienced trouble with the gadget driver not even showing up (at least when interfacing to my MacBook.)  This build compatibility implies that the kernel version has stayed similar enough to be binary compatible with BeagleBone builds in the last year or so.  If the builds aren’t binary compatible (compatible to the kernel headers) the application just won’t run.

Tweak It a Smidgen

The default build configuration will delete the kernel sources once the build is complete.  This might be annoying if you want to make any tweaks or changes.  So, you’ll want to edit the configuration to prevent this.  Open the file “conf/local.conf” file (that is within the “setup-scripts” directory) using your favorite text editor and comment-out or remove the following line:

INHERIT += “rm_work”

You can comment it out by inserting a hash, “#”, in front of the line.  I chose to comment it out.

Build It Already!

From the terminal prompt within the “setup-scripts” directory type the following three commands in succession.  The first will take about five minutes to execute (depending on the speediness of your computer).  The second less than a minute.  And the third will really depend on how fast your machine it.  My CentOS VirtualBox VM running in a host OS of OS X 10.8 on a 2.3 GHz Intel Core i5 took about 3 hours.  The three commands are:

MACHINE=beaglebone ./oebb.sh config beaglebone

… lots of output gets spit out after this one …

MACHINE=beaglebone ./oebb.sh update

… lots of output gets spit out after this one …

MACHINE=beaglebone ./oebb.sh bitbake virtual/kernel

… lots of output gets spit out after this one ….  Here are the last several lines of the output from my successful build:

NOTE: Preparing runqueue
NOTE: Executing SetScene Tasks
NOTE: Executing RunQueue Tasks
WARNING: Failed to fetch URL http://www.apache.org/dist/apr/apr-util-1.5.1.tar.gz, attempting MIRRORS if available
WARNING: Failed to fetch URL http://cbuild.validation.linaro.org/snapshots/gcc-linaro-4.7-2013.02-01.tar.bz2, attempting MIRRORS if available
WARNING: Failed to fetch URL ftp://ftp.ossp.org/pkg/lib/uuid/uuid-1.6.2.tar.gz, attempting MIRRORS if available
WARNING: QA Issue: linux-mainline: Files/directories were installed but not shipped
 /lib/firmware/korg
 /lib/firmware/sb16
 /lib/firmware/korg/k1212.dsp
 /lib/firmware/sb16/alaw_main.csp
 /lib/firmware/sb16/mulaw_main.csp
 /lib/firmware/sb16/ima_adpcm_capture.csp
 /lib/firmware/sb16/ima_adpcm_init.csp
 /lib/firmware/sb16/ima_adpcm_playback.csp
NOTE: Tasks Summary: Attempted 907 tasks of which 249 didn't need to be rerun and all succeeded.

Where Are They?

The cross-compiler executables are located in the directory listed below.  The path to this directory may be different for your build, but will still be similar.

~/development/setup-scripts/build/tmp-angstrom_v2012_12-eglibc/sysroots/x86_64-linux/usr/bin/armv7a-vfp-neon-angstrom-linux-gnueabi

The contents in this directory are:

arm-angstrom-linux-gnueabi-addr2line
arm-angstrom-linux-gnueabi-ar
arm-angstrom-linux-gnueabi-as
arm-angstrom-linux-gnueabi-c++
arm-angstrom-linux-gnueabi-c++filt
arm-angstrom-linux-gnueabi-cpp
arm-angstrom-linux-gnueabi-elfedit
arm-angstrom-linux-gnueabi-g++
arm-angstrom-linux-gnueabi-gcc
arm-angstrom-linux-gnueabi-gcc-4.7.3
arm-angstrom-linux-gnueabi-gcc-ar
arm-angstrom-linux-gnueabi-gcc-nm
arm-angstrom-linux-gnueabi-gcc-ranlib
arm-angstrom-linux-gnueabi-gcov
arm-angstrom-linux-gnueabi-gprof
arm-angstrom-linux-gnueabi-ld
arm-angstrom-linux-gnueabi-ld.bfd
arm-angstrom-linux-gnueabi-nm
arm-angstrom-linux-gnueabi-objcopy
arm-angstrom-linux-gnueabi-objdump
arm-angstrom-linux-gnueabi-ranlib
arm-angstrom-linux-gnueabi-readelf
arm-angstrom-linux-gnueabi-size
arm-angstrom-linux-gnueabi-strings
arm-angstrom-linux-gnueabi-strip

Build a Simple App

To test that the cross-compiler is working, let’s build an incredibly simple “Hello World!” type application.  First, make a new directory from beneath your development directory (or whatever you called it) and name it, “howdy”

mkdir ~/development/howdy

Then cut and paste this text into a text editor and save it as howdy.c in your newly created directory:

#include <stdio.h>

int main(void)
{
   printf("Hey you!  Yes, you, the big nerd in front of this monitor!  This program worked.\n");
   return 0;
}

Next, update your path environment variable like so (you can make it permanent if you want by adding it to your .bashrc file.):

PATH=$PATH:~/development/setup-scripts/build/tmp-angstrom_v2012_12-eglibc/sysroots/x86_64-linux/usr/bin/armv7a-vfp-neon-angstrom-linux-gnueabi

Then compile your file to get a simple executable:

arm-angstrom-linux-gnueabi-gcc -o howdy howdy.c

You should see that a “hello” executable file is created.  One that you can’t run on your Linux build box, by the way, since it is for the BeagleBone.  Next, copy this file to your BeagleBone (using “scp” if you have a network connection is the easiest).  Try to run it and it should spit out the the correct text.  That’s it!  Here’s the “scp” command I used to copy my compiled file from my VM to my network connected BeagleBone whose IP address was 192.168.1.86:

scp howdy root@192.168.1.86:howdy

And here’s the output on the BeagleBone:

root@beaglebone:~# ls -al
total 32
drwxr-xr-x 3 root root 4096 Jul 14 02:09 .
drwxr-sr-x 3 root root 4096 Nov 21 2012 ..
-rw------- 1 root root 139 Jul 14 02:05 .bash_history
-rw-r--r-- 1 root root 20 Nov 22 2012 .bashrc
-rw------- 1 root root 623 Nov 22 2012 .viminfo
drwxr-xr-x 2 root root 4096 Jan 1 2000 Desktop
-rwxr-xr-x 1 root root 7866 Jul 14 02:06 howdy
root@beaglebone:~# ./howdy
Hey you! Yes, you, the big nerd in front of this monitor! This program worked.
root@beaglebone:~#

References

Much thanks to these two posts from where I regurgitated all this material.

Advertisements

6502 Was The Second Assembly Language I Learned

Saw this link today and it took me back 20 years.

http://hackaday.com/2013/02/05/learn-a-little-assembly-language-for-the-6502-processor

The first assembly language I learned was for the Motorola 68000 as part of a college class (circa 1992).   Motorola 68000 assembly is a beauty of clarity to behold and quite easy to learn.  I came home for the Christmas break and saw my old Commodore 64 sitting on my desk.  Thinking, “Dang, now this thing makes sense!” I ordered a $15 C compiler and assembler for it.  I wrote a few small programs in 6502 assembly and then never used it again, but had tons fun over Christmas break basking in my new computer enlightenment.

I had written Basic programs on the C64 that “PEEKed” and “POKEd” values into memory, but I never quite understood those machine language programs and how they related to assembly language.  Even after reading tons of computer magazines as a high schooler, the relationship between machine language and assembly language never really “clicked” in my head.  What was lacking in my reading was a nice tutorial like the one above in book form.  Of course, there were no computer classes of that level available to me in rural Western North Carolina and I was hacking in a vacuum.

The 6502 has an X and Y general register, an accumulator (A), a stack pointer (SP) and a program counter (PC).  That’s it!  It doesn’t get more simple than that.  8-bits of glory!

An Easier Way to View All Your Google Calendars on Your iPhone

So Google now provides a tool to allow you to pick the calendars that sync to your iPhone.  It is:

https://www.google.com/calendar/iphoneselect

Once you’ve added your main Exchange gmail account, use this link to pick which calendars sync.  I just saw this link today via lifehacker.com and have not yet tried it, but it looks a lot easier than my previous post.

Chipping Away

I’m a lucky individual.  I grew up in a stable household with two parents that loved me.  I never doubted that love or that security.  I have two loving sisters with whom I still place great trust and hold great admiration.  My family continues to be amongst the most favorite people I’ve ever known.

I’m a blessed individual.  My parents example helped me pick a perfect mate and the love they parented deep into me now keeps me focused to work to be a caring spouse and loving parent to my children.  Note that I said “work” as in a “work in progress.”  My parents example proved to me that it was worthwhile and rewarding work.

Bouncing on Papa J's knee.
Bouncing on Papa J’s knee.

The picture I have posted here is of my father with my firstborn son in 2008.  Dad had already been living with cancer since 2004.  It was because of experimental treatment funded by efforts at the Preston Robert Tisch Brain Center at Duke that he was able to live with an incredibly agressive cancer for almost five years.   18 months of that time he was in remission.  The treatment he received gave him time. It gave us more precious time with him.

Cancer took my father from this world far earlier than he should have gone.  Dad passed away on June 19th, 2009.  He fought to the end, until he knew it was time to turn and go home.  I’m so grateful for the time we had.  I’m so blessed to have been given that time.  But, I confess, I wanted more.  I miss my father, especially those times when I need advice that I know only he could have given.

We’re lucky individuals.  We live in a time when the prospect of finding a cure for cancer is real.  And we can be a part of making it happen.  Once again this year I’m raising money for the Angels Among Us 5K and Family Fun Walk.  The money raised goes directly for finding a cure for brain cancer.  All donations chip away at the wall that keeps us from the knowledge of the cure.  Finding a cure means providing more time with our loved ones, it means more life and more living. That’s worth fighting for.  Won’t you join me?

To donate to the Angels Among Us 5K and Family Fun Walk simply follow the links in this post.  Thank you for your help.

Swiped!

Lion Upgrade

I upgraded to OS X 10.7 Lion a few weeks back and have been “enjoying” its new characteristics.  I have a few complaints, but overall I am generally happy.  I used to suggest to most folks considering an Apple OS upgrade to wait for the first OS update from Apple (10.7.0 to 10.7.1) before upgrading so that the “paint can dry.”  The same holds true with Lion.  That update has since been released and the next is on the way.  However, this time I would also suggest that unless there is some specific feature that Lion offers that you need, wait an update or two more.  Here are the problems/quirks I’ve encountered so far.

Numero Uno Complainto

I tried very hard to get used to the “natural scrolling”.  This new feature basically makes the touchpad scroll like the iOS devices do (which is backward than the way it used to work.)  This actually makes a lot of sense and I found that only after an hour or my mind got the hang of it.  I think it really is better.  I thought, “This will really work because I don’t use my trackpad on my Windows laptop at work so my brain won’t have to adjust.”  Except….

For some unknown ergonomically-challenged reason Apple chose to also apply “natural scrolling” to the mouse wheel.  Reversing the mouse scrolling is not intuitive at all!  While it might make sense for the multi-touch magic mouse it doesn’t not make mental sense for a standard scroll wheel.  Add on to that the fact the I use my scroll wheel on my work laptop all the time.  There was no way my brain could switch back and forth between them.  As of now there is not a way to independently leave natural scrolling on for the trackpad and turn it off for the mouse.  Although, the system preferences imply you can because there are two independent checkboxes in the trackpad settings and the mouse settings.  However, these separate checkboxes affect the same setting (and don’t update the other checkbox to reflect the change–bad UI design Apple!!)  I haven’t found a online hack to allow this other than having to buy a third party mouse utility like USB Overdrive.

I was pretty bummed by this limitation and had to switch natural scrolling off.  Boo, Apple!

Complainto Duo

The second issue I had was merely a default setting that needed to be corrected.  The default setting for: System Preferences->Trackpad->More Gestures->Swipe Between Pages is “Swipe left or right with two fingers”.  This seems to disable multitouch swiping in all other applications except Safari.  Thus I noticed swiping to navigate was no longer working in iPhoto.  I needed only change it to “Swipe with two or three fingers” and things were back to normal.  My complaint is that it took me doing a Google search regarding iPhoto before I figured it out.  It seems counterintuitive to me that Apple would enable this setting such that it affected so many other applications.  I’m sure newer Apple applications will make use of the new gesture.

On the positive note, Preview now has a nifty set of screenshot options in the “File” menu with which I made the screenshot above.

Los Tres Complaintos

OK, enough insulting Spanish speaking people.  My last issue is with iCal.  I’m not a fan of the new look.  I realize Apple is trying to help transition customers to the whole new iPad and touch ethos (and new customers coming in from that world.)  However, making iCal look like a real leather desktop calendar is, well, cheesy.  I’m using one of the worlds most advanced laptops.  Same complaint goes for the Address Book app.  Why the heck would I want my calendar app to look like a leather desktop calendar which I haven’t used since…ever.

I find the delay imposed by transitioning between months (in month view) a needless delay.  I did find that once I adjusted the scroll setting listed above that I can transition between months without the animation by using a three finger swipe instead of a two finger swipe.  I do like the new day view, however.

My last issue with iCal is not new and that is the event editor needs popup calendars when choosing dates.  Also, a quicker method for choosing the time for the event could be handy.  I did go to Apple and give them feedback about the iCal issues.  I should do the same for the mouse and trackpad issues rather than just complaining to the intergooglewebs.

Last One

Lion won’t allow backing up via Time Machine to a networked Samba share.  Only AFP (Apple Filing Protocol) shares will work.  While this may seem like a niche geeky requirement (OK, it is) the fact that I used-to-could do this in Snow Leopard and can’t now has forced me to go out and buy an Apple Airport Extreme primarily to serve as my network attached storage.  Of course, this was probably Apple’s intent.

Granted, there were still other options like me setting up a Linux box to serve this function.  But, my intent was to backup to my media computer (the kid’s computer) which is acting as my always-on iTunes server for my Apple TV.  Since it is a Windows computer (unfortunately) I can’t just setup a share from it to which to backup my laptop.  And, I didn’t want to have to run yet-another-power-hungery-computer all the time.  So, my compromised was a refurbished (purchased from OWC) not-so-power-hungry Apple Airport Extreme which will have two laptop hard drives hanging off of it via a USB hub.

As an aside, Apple updated their version of AFP (the Apple Filing Protocol) in Lion and NAS providers that used the open-source version of AFP (netatalk) were scrambling for awhile awaiting the open source version to be updated.  There was a bit of a saga about this hiccup.  Though a temporary glitch, it was a glitch nonetheless.

Summary

Though those are several fairly significant (in my little universe) complaints, I do like many of the new Lion features.  Mission Control is cool.  Versions is sweet.  Time Machine backup from an encrypted home folder while logged in is much needed.  The list goes on.

P.S. Here are honorable mentions in the complaint contest:

  1. The “clickable area” around most of Apple’s controls is too small.  I’ve noticed that Windows is much more forgiving about clicks in that it give you the whole button area on which to click.  OS X tends to require you to click dead-center on things.  Combine that with the very small editing area in things like iCal’s event editor and it’s darn right frustrating.
  2. Safari 5.1 eats memory like a hungry elephant.  Their “enhancements” must mean “enhanced eating of memory usage”.  5.1 seems worse in Snow Leopard.  I switched my wife to using Chrome until they’ve resolved it.  I bumped both our machines to 8G and that’s helped.  I’m hopeful Apple will rectify this in an update soon.

unDock Is Quite Handy

So you are like many who have one or more hard drives attached to your MacBook via Firewire or USB?  And, like most folks in that situation you inevitably forget to eject those hard drives before you leave and thus you see the annoying error message after closing your MacBook and yanking out all the cables the next time you open it up.  In walks “unDock”.  A very handy and inexpensive tool available at the App store:

Follow this link to unDock at the Mac App Store

Alarm/Reminder Quirks with iCal and Google Calendars

Journey to iCal Land

iCal iconI’m a big fan of Google Calendar and the flexibility it provides.  In particular, I like the ease in which I can create new calendars for each of my family members to help us to track our appointments.  As mentioned in a previous post, I like to be able to view my personal calendars in conjunction with my professional work calendar, but keep them separate.  When I existed in the Windows OS world I would use a purchased add-on by CompanionLink that allowed me to sync all my myriad of shared Google calendars as items on my Outlook in different categories.  Once I transitioned to a Mac I was elated to learn how easy it was to add my primary and shared Google calendars to iCal via simply adding my Google account.  Equally giddiness-inducing was that when moving to Snow Leopard I could also interface to my work’s Exchange server in both Mail and iCal.

Burned

However, I learned a hard lesson after not receiving an alarm reminder on my iPhone for one of my synced Google Calendars for which I knew I had set to remind me.  it seems that there is a quirk when using iCal to view your Google calendars that you need to remember to avoid when setting alarms.

Why!? Tell Me, Why!

It seems that, if you want to set an alarm (to fire-off an alert on your iPhone and make a reminder noise) you have to set the calendar event alarm to only “Message.”  If you set it to “Message with Sound” it won’t add a reminder to the even that is created on the iPhone.  Now, it’s possible this has since been fixed, but I have since changed my preferences in iCal to not set a default alarm, and thus I’ve gotten into the habit of manually setting a “Message” reminder.

It’s not ideal, but it works.

Note, in this scenario the iPhone is pulling down the Google calendar events from the cloud.