Saturday, August 23, 2014

Deploying Yocto on Beaglebone Black

Hello everybody! This is my first blog about embedded Linux. I'll discuss about how to use Yocto project to build different embedded Linux images for Beagle bone Black and keep it as simple and descriptive as possible.

The latest Yocto release is 1.6 (Daisy) which can be used for BBB as it has the required BSP for BBB. The different types of images that can be built depends on your needs. The common ones are "core-image-minimal","core-image-base" and "core-image-sato". All of these differ by the packages they include hence the size of the final image. If cross-compilation as well as other building tools are required than "core-image-sato-sdk" should be built. I'll describe here how to build "core-image-basic" and boot from a micro-SD card.

Setting Up:

There are some basic packages that need to be installed on your system. You can achieve that by executing:       
~$ sudo apt-get install chrpath gawk diffstat texinfo g++

I would recommend making a separate directory for this task.
~$ mkdir yocto
~$ cd yocto
~/yocto$ git clone -b daisy git://git.yoctoproject.org/poky.git


The last command will make a directory named poky inside yocto. Enter that directory.
~/yocto$ cd poky

Now to build the image we need to source an environment script present in the poky directory by the name "oe-init-build-env".
~/yocto/poky$ . oe-init-build-env build

This will execute the script,make a directory named build (you can write any name instead of build in the above mentioned command) and enter that directory automatically. At this point there are two options available to build the image. One is to continue using terminal window and make the image while the second one is to use a GUI version named "Hob". For using GUI just type
~/yocto/poky/build$ hob

This will start the GUI. There select BBB from drop-down menu,the image type and start building it. You can change the included packages in the image by selecting "View Recipes".

I'll now explain the method of using terminal window. We need to edit two text files named "layers.conf" and "bblayers.conf" in the conf directory.
~/yocto/poky/build$ vim conf/local.conf

Find the variable named MACHINE and uncomment it by removing # such as
#MACHINE ?= "beaglebone"

to make it
MACHINE ?= "beaglebone"

This will configure the tool to build for BBB. You can also uncomment the lines BB_NUMBER_THREADS and PARALLEL_MAKE variables and set them equal to twice the number of cores used by your host machine. The number set to these variables will define how many simultaneous tasks be executed,though it is not compulsory to edit these. Before BBB like the beaglebone or beagleboard,a line needed to be added to "conf/bblayers.conf" file for an extra layer named "meta-ti". However,for BBB no such editing is needed.

Building and Deploying:

Finally execute the command to start building the image.
~/yocto/poky/build$ bitbake core-image-base

The time taken depends on the value assigned to BB_NUMBER_THREADS and PARALLEL_MAKE variables as well as the image type. After the build has finished successfully the binary output images will be present in ~/yocto/poky/build/tmp/deploy/images/beaglebone

Now it's time to copy the required files onto a micro-SD card. The important binary files in the above directory are:
*MLO-beaglebone
*u-boot-beaglebone.img
(Different stages bootloaders)
*uImage
(Linux kernel image for u-boot bootloader)
*core-image-base-beaglebone.tar.bz2
(Compressed root filesysytem)

To prepare your micro-SD card following tasks should be done:
*Install gparted in your system
*Using gparted make two partitions.
*Format them using ext4 and fat32 type filesystem
*Set appropriate boot flag
*Copy the files to the appropriate directories

Now explaining a little about each step. Installing and running gparted is accomplished by
~ $ sudo apt-get install gparted
~ $ gparted


The next three steps are easily accomplished by exploring this tool. Lastly to copy the files lets suppose the two partitions were named as "boot" and "root". Execute the following commands:
~$ cd yocto/poky/build/tmp/deploy/images/beaglebone
~/yocto/poky/build/tmp/deploy/images/beaglebone$ cp MLO-beaglebone /media/boot/MLO
~/yocto/poky/build/tmp/deploy/images/beaglebone$ cp u-boot-beaglebone.img /media/boot/u-boot.img
~/yocto/poky/build/tmp/deploy/images/beaglebone$ sudo tar -xf core-image-base-beaglebone.tar.bz2 -C /media/root


Your micro-SD card is ready to be booted from. Insert it in the BBB and press the boot button for about 5 seconds to boot from micro-SD card rather than
the eMMC flash which contains the Angstrom image. To see the output either connect a screen via micro-hdmi plug or connect to the host machine through a serial adapter and a serial program like minicom or putty.

I hope this guide will be useful for everyone to explain deploying Yocto on BBB. Feedback will be appreciated. I'll describe how to boot BBB from NFS server in my next post.