So, a few weeks ago, I got my hands on a Beaglebone for getting myself into Embedded Linux world again. I have messed with Gumstix Overo series during my thesis so I had some knowledge. But my previous experience was limited as I was not able to compile kernels and I only managed to compile things on board (which is slow for computer vision programs) as I had limited time and no knowledge of cross-compile.
But things have changed: My Linux-fu is definitely better compared to a few years ago, I have more experience in electronics & programming and also I got my hands onto a fast PC which I can use for kernel compiling, cross compiling and other tasks which take lots of time. Believe me, I tried compiling kernel with my trusty EeePC (which was my only Linux running PC at that time) and it was still not half done after 6 hours. Now I have a 6 core 64-bit AMD machine which is used for all this stuff. Still it takes some time but at least watching a movie or two will be enough.🙂
So, here we go: I will talk about backing up the uSD cards that came with the Beaglebone, talk about compiling the kernel, formatting the uSD card if you are using a brand new one, copying files to your uSD card and then booting up the system and playing around for a while. I don’t claim any originality in the work presented here, I will present here a collection of information scattered around the web that I had to find out after following may links so that others can access it easily and I don’t have to search around again if I cannot remember something.🙂 So as references, the backup part is from a Coder’s Talk blog post and the rest is from BeagleBone demo files page.
I’m using an EeePC as my main machine as it has an SD card slot and I’ll SSH into the AMD PC for compiling and transfer files by SCP. I’ll also power up my Beaglebone by a DC adapter and SSH into it to test out the system. Why? Because I’m comfortable with that, but you can just use one PC for compiling and preparing the uSD card.
Backup the uSD Card
First thing I’ll do is to back up one of the two uSD cards that arrived with my Beaglebone. One of them was labeled and had an Angstrom distribution on it and the other one was not marked. It contained some files related to Beaglebone and apparently an Angstrom distribution too but I was not able to boot my Beaglebone with the unmarked one. So I’ll use that for my new kernel. But before I want to have a backup in case things go south.
As I’m running Linux, I have some really nice tools in my system by default. The two I’ll be using for this is dd and tar. Also dmesg is useful for seeing which drive name is assigned for the uSD card but I usually check out /dev/ directory for it. Whatever suits your needs. So upon inserting the card, I learn that my uSD card is at /dev/sdb with some partitions mapped as /dev/sdb1, /dev/sdb2 etc. which are automatically mounted. Do not safely remove these partitions, the following codes will not work. Create a new folder for Beaglebone related things and get an image of the uSD card. It will take ~4 GB of space (size of the uSD card) so it is better to use tar and gzip to compress the file and remove the uncompressed image afterwards to free up some space.
$ mkdir beaglebone
$ cd beaglebone
$ sudo dd if=/dev/sdb of=unmarked_sd
$ tar zcvf unmarked_sd.tar.gz
$ sudo rm unmarked_sd
If you want to have this original copy on the uSD card again, you can use the following command. Be sure to use a card with same size or bigger.
$ sudo su
# tar Ozxf unmarked_sd.tar.gz | dd of=/dev/sdb
Compile a Brand New Angstrom Image
For this I SSH into my AMD PC and do things there. It is a good idea to use screen for this step as if you lose your connection somehow, the process stops. So we SSHed into the machine, we have a beaglebone folder under our home directory and we are under that. And of course we are using screen while running these commands because especially the last one takes a long one and if your SSH connection drops, everything stops, I cannot stress this enough as I have left it running during my sleep and I had nothing in the morning as my laptop went to sleep and I’ve lost my connection. Also a fast internet connection is a good thing as you’ll download lots of things during this step. So go ahead and run these commands:
$ git clone git://github.com/Angstrom-distribution/setup-scripts.git
$ cd setup-scripts
$ ./oebb.sh config beaglebone
$ MACHINE=beaglebone ./oebb.sh bitbake systemd-image
Now go sleep, clean up the house, go for a walk, watch a movie or take a hint from the comic down there. It’ll take a while.
Once the kernel is compiled, I like to transfer them to another folder under my beaglebone folder so that I can transfer all of them to my EeePC by SCP using one command and the files are hidden pretty down below. Believe me, you don’t want to enter the whole path while using SCP. Also during this step I rename these files so that I can transfer them to the uSD card without changing their names. We are under the beaglebone folder while running these.
$ mkdir image
$ cd image
$ cp ../setup-scripts/build/tmp-angstrom_2010_x-eglibc/deploy/images/beaglebone/MLO ./
$ cp ../setup-scripts/build/tmp-angstrom_2010_x-eglibc/deploy/images/beaglebone/u-boot.img ./
$ cp ../setup-scripts/build/tmp-angstrom_2010_x-eglibc/deploy/images/beaglebone/uImage-beaglebone.bin ./uImage
$ cp ../setup-scripts/build/tmp-angstrom_2010_x-eglibc/deploy/images/beaglebone/Angstrom*.tar.bz2 ./
Format the uSd Card and Unpack the Angstrom Image
For formatting, you have two options: Doing it manually by fdisk or using the nice mkcard.txt script provided by Angstrom. I have tried both but instead of calculating values and entering them, I really prefer the script. Unmount your uSD card if you didn’t and run it by typing
$ sudo sh mkcard.txt /dev/sdb
You remembered my uSD card is at /dev/sdb, right? Good, if yours is different, just change it. Then go ahead and remount the partitions, mine mount automatically to /media/boot/ (FAT32 partition) and /media/Angstrom/ (ext3 partition), to transfer the files. We are under the beaglebone/image/ folder where my files are.
$ cp MLO /media/boot/
$ cp u-boot.img /media/boot/
$ cp uImage /media/boot/
$ sudo tar -xjv -C /media/Angstrom/ -f Angstrom*.tar.bz2
Boot Up and Play a Little
Unmount your uSD card partitions (I just use safely remove, it syncs up the partitions and unmounts all partitions associated with that drive automatically). Then plug it to your Beaglebone, plug in an Ethernet cable and the 5V adapter. You have to wait a little for the initial boot. Once you see one of the LEDs blinking on and off (called heartbeat) you can SSH into your Beaglebone! To learn the IP of your Beaglebone, you can use various methods, I use the following nmap command before turning my Beaglebone on and after the heartbeat to find its IP address.
$ nmap -sP 192.168.1.*
Just to test it out, I’ll turn on LED3 on and then off from the shell after getting connected to it over SSH. Username is root and there is no password. These commands are run on the Beaglebone. The first command shows you possible options (LED0 is set to heartbeat, LED1 to mmc0), the second turn on the LED3 and third one turns it off.
# cat /sys/class/leds/beaglebone\:\:usr3/trigger
[none] mmc0 timer heartbeat backlight gpio default-on
# echo default-on > /sys/class/leds/beaglebone\:\:usr3/trigger
# echo none > /sys/class/leds/beaglebone\:\:usr3/trigger
If you want to mess around a little more, Make Magazine has a nice blog post & video about using GPIO pins.