Tag Archives: BeagleBone

Cross-Compiling for BeagleBone Using a Linux VM on the Mac

BeagleBone Cross Compiling using OSX on the Mac (using Linux)

Although it may seem more complicated, I decided the best way to cross-compile from my Mac would be to do it from a Linux system.

I would of course love to have my BeagleBone cross-development environment running directly on OSX, but that’s an effort for another day – my goal here was to be able to cross-compile for the BeagleBone.

Yes, in theory this should be possible on a Mac since it’s Unix-based, but it appears to me that may be more pain. More pain than just setting up an Ubuntu system using VMWare Fusion anyway. This is quite easy these days – both VMWare and Parallels make it almost effortless. There are many many resources on how to do this, so I’m not going to cover that here.

With Ubuntu 12.04 running happily in a VMWare VM on my MacBook Pro, away I went.

So to just cross-compile, it doesn’t appear that you really need the OpenEmbedded and Angstrom kernel stuff, so I went with just the Angstrom pre-built toolchain available at:
http://www.angstrom-distribution.org/toolchains/

I used angstrom-2011.03-i686-linux-armv7a-linux-gnueabi-toolchain.tar.bz2
This is the 32-bit version, which matches my Ubuntu VM setup. There is a 64-bit version there as well, if you are running a 64-bit version of Linux on your host system.

Step-by-Step

On the Cross-development Host

Extract the pre-built angstrom toolchain:

    $ cd /
    $ sudo tar -xf <path to the angstrom toolchain>

Which creates the new directories /usr/local/angstrom and /var/lib/opkg.

Run the environment setup script, which puts the new tools in the path as well as sets up several other environment variables:

    $ . /usr/local/angstrom/arm/environment-setup

Create a simple “Hello, world” program using whatever editor you prefer. I named mine “hello.c”.

    #include <stdio.h>

    int main()
    {
        printf( "Hello, worldn" );
    }

And finally, do a test build.

    $ arm-angstrom-linux-gnueabi-gcc hello.c -o hello

This should result in an executable file named hello. (This is a Csource file, so I used gcc, but you can also change the gcc at the end of the command to g++ to compile C++ source code.

On the BeagleBone

If you transfer the executable binary output file hello to your BeagleBone (e.g. via FTP), you should be able to run it and see the text “Hello, world” printed out in the BeagleBone terminal.

    $ ./hello
    Hello, world

Resources

This guide is based on bits of information gleaned from a variety of sources, including:

Linux To Go
electrons on radio
Trey Weaver’s Blog
gpio.kaltpost.de

Thanks to everyone who has blogged about their experiences with the BeagleBone!

Writing a BeagleBone SD Card Image From the Mac Revisited

Since I last dealt with writing an SD card image to update the BeagleBone software, some things have changed. So, here’s an updated guide to the process.

Download the Image

The latest images are available here: http://beagleboard.org/latest-images

The one I downloaded was named: Angstrom-Cloud9-IDE-GNOME-eglibc-ipk-v2012.05-beaglebone-2012.11.22.img.xz

Uncompress the Image

The latest BeagleBone images are not compressed in a format that tar or unzip can deal with. Fortunately there is a free application The Unarchiver that can. It’s available here: The Unrchiver.

Run this application on the .xz image file to get a (much larger) file that ends in .img. This is the file you’ll write to the SD card.

Unmount the SD Card

To write the image to the SD card, it first needs to be unmounted.

    $ diskutil unmount /volumes/YourCardNameHere

Find the Device Name

This step is critical.

Using the wrong device name can destroy the data on your computer’s hard drive, so be very very sure to get the device name correct in the following steps!

This can be found in a couple of ways. You can use the “Disk Utility” application, or the command line diskutil or df commands.

Diskutil

From the command line:

    $ diskutil list

df

    $ df

This may show you the partition, something like disk7s2. You want to entire SD card, not any partitions so drop the s2 part.

Write the Image

Then, write the image to your SD card. Note that the diskXXX should be the actual disk device assigned when the SD card is connected, and Angstrom-XXX should be the name of the actual card image you downloaded and extracted previously.

Again be sure to use the right device name for the SD card in this step!

Don’t be surprised if this takes a while – on my system it took about 37 minutes, and there are no “in progress” indications of any sort, so be patient! (note that this time is more a function of how big the image is – ~3.4G – and the speed of your micro-SD card then how fast your computer is)

    $  dd if=Angstrom-XXX.img of=/dev/diskXXX bs=4096

If you aren’t logged in as root, you may need to use sudo, in which case the command is:

    $  sudo dd if=Angstrom-XXX.img of=/dev/diskXXX bs=4096

BeagleBone FTP Server

BeagleBone FTP Server

The BeagleBone has multiple text editors available onboard, including vi and vim. I can stumble around (badly) in vi. Using Vim is a little prettier, but not much – I’m really much more of a modal-editor guy. On the Mac, I use BBEdit when I’m not using XCode for iPhone and iPad development.

So my goal is to be able to easily edit on my Mac. BBEdit has a very slick ability to edit files via FTP, so that’s my next step.

Oddly, the BeagleBone doesn’t have an FTP server available in the default distribution. (or if it does, I couldn’t find it)

One skill I know I need to brush up on is acquiring, building, and installing packages in Linux. Since I wanted a quick-and-dirty FTP server running without too much fuss, I naturally looked to Python.

Python is a terrific “scripting” language, and my go-to tool for a lot of tasks.

There is a very nice FTP Server library available: pyftpdlib.

I grabbed this using wget, then did the unzip/untar dance:

    gunzip pyftp*
    tar -xf pyftp*.tar

Installation was simple. The setup python program failed, so I just manually moved the pyftpdlib directory into /usr/lib/python2.7/.

Last but not least, I whipped up a small Python program by modifying the quickstart and demo examples just a bit:

    # FTP server

    from pyftpdlib import ftpserver
    authorizer = ftpserver.DummyAuthorizer()
    authorizer.add_user("root", "12345", "/home/root", perm="elradfmw")
    handler = ftpserver.FTPHandler
    handler.authorizer = authorizer
    address = ("", 21)
    ftpd = ftpserver.FTPServer(address, handler)
    ftpd.serve_forever()

Take that code, stuff it into a file with a .py extension (e.g. ftpserver.py), and invoke it:

    python ftpserver.py

And there you go – FTP access to the home directory of user root.

Now, is this what you’d use to server files to the world at large? Maybe – it looks like a very complete implementation, although I’m no FTP expert.
But it’s perfect for my local development purposes.

The only thing that would be nice is to have it auto-start. That’s pretty easy to do as well, at least in the simple case.

The directory /etc/init.d contains scripts that are executed upon system startup. We place a very simple shell script there, which I called ftpserver:

    #!/bin/sh
    python /home/root/ftpserver.py

This will run the Python FTP server program (which in this case is located in the root account’s home directory – it could be located elsewhere of course).
Once you create this script, don’t forget to make it executable by doing chmod +x ftpserver.

Although this works, our script should really be more compliant and let us stop and restart the server. I plan to address that soon!

BeagleBone and the Mac – Part 2

The ongoing BeagleBone saga, part 2

(As viewed from a Mac)

SSH

To connect an SSH terminal session from the Mac is as easy as:

    ssh root@beaglebone.local

This is typed in a Terminal shell on the Mac of course.

To terminate the session, type the “escape” character followed by a period. The escape character is tilde by default, so type this to end the session:

    ~.

Lua

To install Lua on the BeagleBone:

    opkg install lua5.1

Ò

BeagleBone and the Mac

Last week, my cool little BeagleBone arrived from Adafruit. This post is my attempt to describe getting the BeagleBone set up on a Mac with OSX.

Not everything I’ll be writing about is necessarily unique to using it with a Mac (versus say, Windows or Linux), but that’s obviously going to be my perspective since I’m a Mac guy 100%.

The general tasks look like this:

  • Download the latest OS to a Micro-SD card.
  • Install USB serial driver on the Mac
  • Connect the BeagleBone to the USB port
  • Open a serial terminal to the USB port
  • Talk to the BeagleBone!

Out of the Box

A New Pre-Built Linux Image

As the BeagleBone “Getting Started” guide suggests, the Linux image that comes pre-installed on the SD card that comes with the BeagleBone may not be the latest available.
You can download a more recent image from the links in the guide. Once you do, it needs to be written to the SD card.

To write the image to the SD card, it first needs to be unmounted.

    diskutil unmount /volumes/YourCardNameHere

Then, write the image to your SD card. Note that the diskXXX should be the actual disk device assigned when the SD card is connected.
This can be found a couple ways. You can use the “Disk Utility” application, or the command line df command.
These may show you the partition, something like disk7s2. You want to entire SD card, not any partitions so drop the s2 part.

    gunzip -c Angstrom-Cloud9-IDE-eglibc-ipk-v2012.01-core-beaglebone-2012.01.11.img.gz | dd of=/dev/diskXXX bs=4096

USB Serial Drivers

For my Lion setup, all I needed to install were the drivers that came with the BeagleBone.

These were on the USB “drive” that appears when you connect the BeagleBone to your Mac, as well as available from the BeagleBone website FTDI_Ser.dmg

Serial Terminal

The command line program screen makes a pretty handy serial terminal.

    screen /dev/tty.usb*B 115200

I set up my ~/.screenrc file as follows:

    termcapinfo xterm* ti@:te@
    autodetach off

The first line causes the scrollbars in the terminal window to work for scrolling back the serial terminal text lines. (See this stackoverflow post for details on why this is needed)

The second line will cause the screen session to terminate (rather than just “detach”) when you close the Terminal window.

Both of these are behaviors you probably want.

Custom Terminal Settings

You can also set up a custom set of terminal settings. I defined a set that made the window larger, and – most importantly – executed the screen command automatically.

SSH

ssh root@beaglebone.local

Ethernet Connection

The BeagleBone uses DHCP to get an IP address from your local network. (assumes your local network is set up to do that of course – most are)
To connect to it via a browser etc you need to know its IP address. Here are three ways to do that.

  1. Use a local name
  2. Display the assigned IP address using the USB-serial shell
  3. Look at the addresses assigned by your router

In my case, the router on my network is an Apple Time Capsule. I mention this just in case your router works differently.

The “local name” scheme works great. The BeagleBone identifies itself as “beaglebone” to the DHCP server. I can connect to my BeagleBone as beaglebone.local.

Alternately, using the command ifconfig via the USB-serial shell will display the IP address assigned to the BeagleBone’s ethernet port. (at the moment, mine is 10.0.1.2)

The third option is router-spcific. In the case of the Time Capsule, run the Airport Utility application on the Mac. Select “Manual Setup” for the TimeCapsule, got to the “Advanced” tab, then “Logging & Statistics”. On that screen, select DHCP Clients and you’ll see a list of devices and their assigned IP addresses. You will also see the client ID, which in this case is “beaglebone”.


Next Steps

These will include an FTP server, Mercurial, and perhaps an editor like pico.