Throughout this website we are going to use a Raspberry Pi 3 Yocto Based Embedded Linux system for all tutorials and examples so what better way to kick this section off than a quick howto on creating a simple console based image using Yocto. You will need a Raspberry Pi 3 with a debug console cable or if I can get it working I'll also show how to use with QEMU. I will not go into any great depth on Yocto and leave that to another article for another day.
Pre-requisites: Patience, sense of humour, around 30GB of free disk space and a PC that is not more than 2/3 years old preferably with at least 4 cores and a SSD drive. Yocto is tested on certain Linux distributions as listed in the Quick Start Guide.. This howto was created using Ubuntu 14.04, for other distro's refer to Reference Manual for the packages that you will need to install for Yocto to work.
First up install the required packages for your host system as described in the second link above. So for Ubuntu 14.04 we are going to install everything recommended:
sudo apt-get install gawk wget git-core diffstat unzip texinfo gcc-multilib \
build-essential chrpath socat
sudo apt-get install libsdl1.2-dev xtermsudo apt-get install libsdl1.2-dev xterm
sudo apt-get install make xsltproc docbook-utils fop dblatex xmlto
sudo apt-get install autoconf automake libtool libglib2.0-dev libarchive-dev
sudo apt-get install python-git
Next we are going to checkout the required meta-layers, for those not au fait with Yocto think of a meta-layer a way of organising all this Yocto magic into some semblance of order. We are going to create a layer that contains all the Raspberry Pi meta-data. Yocto maintains a reference distribution called Poky which we are going to use to create our basic console image which is one of the images contained within Poky so we are going to create a layer for Poky. The Poky layer also contains the OpenEmbedded Build System (BitBake and OpenEmbedded Core) so there is no need to create any other layers.
The directory structure is completely personal but I like to create a directory for the project and then within this directory create a sources directory that contains the layers and a build directory that contains all the builds. The reason I like a separate sources directory is that you can use find/grep within this directory to search Yocto meta-data without having to trawl through gigabytes of build directories. Within the build directory I like to create a directory for each target machine that I am building for which for this tutorial is only going to be one, the Raspberry Pi.
Enough babbling, here are the commands to do the above. I will assume you have created a directory for this with all the relevant permissions, and are happily sitting at a terminal session in this directory.
mkdir sources
cd sources
git clone -b krogoth git://git.yoctoproject.org/poky
git clone git://git.yoctoproject.org/meta-raspberrypi
At the time of writing Krogoth was the latest release of Yocto and whilst Poky had a krogoth branch, the Raspberry Pi meta-layer didn't but it seems that the master branch will suffice.
Now we have enough meta-layers to create our Linux Distribution for the Raspberry Pi we can now bootstrap our build directory by running the following command
cd ..
. sources/poky/oe-init-build-env build
You had no conf/local.conf file. This configuration file has therefore been
created for you with some default values. You may wish to edit it to, for
example, select a different MACHINE (target hardware). See conf/local.conf
for more information as common configuration options are commented.
You had no conf/bblayers.conf file. This configuration file has therefore been
created for you with some default values. To add additional metadata layers
into your configuration please add entries to conf/bblayers.conf.
The Yocto Project has extensive documentation about OE including a reference
manual which can be found at:
http://yoctoproject.org/documentation
For more information about OpenEmbedded see their website:
http://www.openembedded.org/
### Shell environment set up for builds. ###
You can now run 'bitbake '
Common targets are:
core-image-minimal
core-image-sato
meta-toolchain
meta-ide-support
You can also run generated qemu images with a command like 'runqemu qemux86'
Hey presto we have a build directory and in this build directory we have two important files that live in the conf directory. Change to build/conf and first lets check out the bblayers.conf file which is shown below for my setup
# POKY_BBLAYERS_CONF_VERSION is increased each time build/conf/bblayers.conf
# changes incompatibly
POKY_BBLAYERS_CONF_VERSION = "2"
BBPATH = "${TOPDIR}"
BBFILES ?= ""
BBLAYERS ?= " \
/ws/rpi3/sources/poky/meta \
/ws/rpi3/sources/poky/meta-poky \
/ws/rpi3/sources/poky/meta-yocto-bsp \
"
First thing we notice is that we have hard coded absolute paths which in fine if you are working on this completely by yourself but not so good if you are planning on working in a team. Second thing we notice is that we we need to add our Raspberry Pi layer. On the first point we can use the TOPDIR environment variable which points to our newly created build directory so we can use this to change bblayers.conf and while we are at it add the Raspberry Pi meta layer.
# POKY_BBLAYERS_CONF_VERSION is increased each time build/conf/bblayers.conf
# changes incompatibly
POKY_BBLAYERS_CONF_VERSION = "2"
BBPATH = "${TOPDIR}"
BBFILES ?= ""
BBLAYERS ?= " \
${TOPDIR}/../sources/poky/meta \
${TOPDIR}/../sources/poky/meta-poky \
${TOPDIR}/../sources/poky/meta-yocto-bsp \
${TOPDIR}/../sources/poky/meta-raspberrypi \
"
todo local.conf
todo kick off build
todo flash to SD card and boot
If it doesn't build yocto provides some very useful information so along with everyone's favourite support tool 'google' and if this fails post a message on the Yocto mailing list @todo link here or IRC @todo link here, there is a thriving community with lots of developers willing to help.
There is extensive documentation on Yocto which can be found @todo link
Blurb about build servers, amazon servers, toaster, going into detail on these things later