Wednesday, 3 September 2014

Yocto For Raspberry-Pi Build Guide



The Yocto Project is a Linux Foundationworkgroup whose goal is to produce tools and processes that will enable the creation ofLinux distributions for embedded softwarethat are independent of the underlying architecture of the embedded software itself. The project was announced by the Linux Foundation in 2010.[1] In March 2011, the project aligned itself with OpenEmbedded, an existing framework with similar goals, with the result being The OpenEmbedded-Core Project.

The Yocto Project is an open source project whose focus is on improving the software development process for embedded Linuxdistributions. The Yocto Project provides interoperable tools, metadata, and processes that enable the rapid, repeatable development of Linux-based embedded systems.

Source: http://en.m.wikipedia.org/wiki/Yocto_Project


1.     Clone the Yocto Project Git repo

We are going to download a beta version of the Yocto Project compilation which I have tested and is known to be working on the Pi.

First navigate to the directory you want to store your Yocto Project files and run the following command:

git clone git://git.yoctoproject.org/poky yoctoProject


This will clone the master version of the yocto project collection.

cd into the yoctoProject directory

cd yoctoProject

2.     Get the meta-raspberrypi layer

The meta-raspberrypi layer is a BSP layer, this is a layer which holds all the meta-data for building for the Raspberry Pi, most importantly the Kernel and architecture configuration. We're going to do a git clone of the meta-raspberrypi repository.

Clone the meta-raspberrypi repository:

git clone git://git.yoctoproject.org/meta-raspberrypi

3.     Setup the build environment

Go back to your yoctoProject directory, if you are still in the meta-raspberrypi directory then a simple:

cd ..


Next, setup the build environment variables by sourcing the build script:

source oe-init-build-env raspberryPiBuild/


You have now setup the environment, a new folder 'raspberryPiBuild' has been automatically created and you have then been placed into it.
4.     Configure the build

Now you have setup the environment, Bitbake can build for a number of architectures. You must configure it to build for the Raspberry Pi. Using your favourite text editor, edit the conf/local.conf file in your raspberryPiBuild directory.

nano conf/local.conf


In the conf file edit the following parameters:

Scroll down the file until you see the MACHINE definition variables. Add your own custom one right at the start that says:

MACHINE ?= "raspberrypi"


Ensure that all the following MACHINE variables are commented out.

5.     Next up, we need to add the meta-rasperrypi layer we cloned earlier to the file conf/bblayers.conf. Open this file:

nano conf/bblayers.conf


Add a line below the last entry in the BBLAYERS variable (it should end in meta-yocto) stating:

/path/to/meta-raspberrypi


Please not the format of the other lines in the BBLAYERS variable, it will be very similar to the ones above but with the meta-raspberrypi instead of meta-*.

You can see my example below:

BBLAYERS ?= "
/home/ric/Projects/yoctoProject/meta \
/home/ric/Projects/yoctoProject/meta-yocto \
/home/ric/Projects/yoctoProject/meta-yocto-bsp \
/home/ric/Projects/yoctoProject/meta-raspberrypi \
"
6.     Build a minimal distribution

To compile your new distribution a few development tools are required, the install procedure for a few common Linux distributions are listed below. If you do not run one of these distributions then you can try running the bitbake command below anyway and it will alert you to which dependencies your system is missing and you can then install them with the package manager of your choice.Packages required for Ubuntu:

sudo apt-get install sed wget cvs subversion git-core coreutils \
unzip texi2html texinfo libsdl1.2-dev docbook-utils gawk \
python-pysqlite2 diffstat help2man make gcc build-essential \
g++ desktop-file-utils chrpath libgl1-mesa-dev libglu1-mesa-dev \
mercurial autoconf automake groff libtool xterm


Packages required for Fedora:

sudo yum groupinstall "development tools"

sudo yum install python m4 make wget curl ftp hg tar bzip2 gzip \
unzip python-psyco perl texinfo texi2html diffstat openjade \
docbook-style-dsssl sed docbook-style-xsl docbook-dtds \
docbook-utils sed bc eglibc-devel ccache pcre pcre-devel quilt \
groff linuxdoc-tools patch linuxdoc-tools cmake help2man \
perl-ExtUtils-MakeMaker tcl-devel gettext chrpath ncurses apr \
SDL-devel mesa-libGL-devel mesa-libGLU-devel gnome-doc-utils \
autoconf automake libtool xterm


Packages required for openSUSE:

sudo zypper install python gcc gcc-c++ libtool \
subversion git chrpath automake make wget help2man \
diffstat texinfo mercurial freeglut-devel libSDL-devel


The meta-raspberrypi layer provides us with a very minimal image which will construct an image file that we can directly write onto our SD card.

To build the image we run

bitbake core-sato-image


Ensure, you are running this from your raspberryPiBuild directory.


Now, depending on the speed of your machine this could take anything from 3 hours (Quad Core i7, 3GHz) to 24hrs+.
*Ethernet will cause pi to hang at startup