Tuesday, April 26, 2016

RaspberryPI3 and Yocto

The aim of this post is to describe how to build a firmware for a RaspberryPI3 using Yocto Jethro 2.0.1, with kernel 4.1.21.

Configuring the host

I used Ubuntu 15.04 to generate the image and first I have installed the required packages on Ubuntu to build the Yocto image. As mentioned in the Yocto Project Quick Start the command to install the essential Ubuntu packages is:

sudo apt-get install gawk wget git-core diffstat unzip texinfo \
 build-essential chrpath libsdl1.2-dev xterm

Preparing the environment

To build my Yocto firmware, I used as main reference this README: http://git.yoctoproject.org/cgit/cgit.cgi/meta-raspberrypi/tree/README
First, you have to download Yocto from this page: https://www.yoctoproject.org/downloads; I am using Jethro 2.0.1; if you want, you can download directly the file with this command:

wget http://downloads.yoctoproject.org/releases/yocto/yocto-2.0.1/poky-jethro-14.0.1.tar.bz2

Then you have to decompress it and move into poky directory and download the required layers: meta-raspberrypi and meta-openembedded, with these commands:

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

git clone git://git.openembedded.org/meta-openembedded

For meta-raspberrypi, I am using the sha dedd75f08ffe3360722ab761da18987aa681edd1, for meta-openembedded, the sha is 57a687bc554cc15de9fc6c17aec7a3ea9175abbd.

Configuring Yocto

Then  you have to create your build directory and configure the system to build a Yocto image for a RaspberryPI board with the command:

source oe-init-build-env rpi3_bin

The development system will be created into the rpi3_bin directory. If you want, you can chose another name for this directory. You have to repeat this command every time you use a new shell (e.g. after a reboot), to reconfigure the build environment.

At the end of the execution, oe-init-build-env leaves you inside the raspberrypi directory.

In the conf directory there are the two configuration files: local.conf and bblayers.conf.
The main parameter that you can customize in the local.conf are:
  • MACHINE ?= "raspberrypi3" 
  • DL_DIR ?= "/home/mytechpg/dl"
  • IMAGE_FEATURES += "package-management"
  • PACKAGE_CLASSES ?= "package_ipk"
MACHINE is used to specify the target type.
DL_DIR can be used to specify the directory where source tarballs are downloaded during the build process. I suggest to specify a path outside Yocto directory because it could be shared between multiple builds on the same host.
IMAGE_FEATURES is used to install rpm tool, to add to the image new packages

In the bblayers.conf file you have to add the path for the new layers to BBLAYER variable:

BBLAYERS ?= " \
  /home/mytechpg/yocto/poki/meta \
  /home/mytechpg/yocto/poki/meta-yocto \
  /home/mytechpg/yocto/poki/meta-yocto-bsp \
  /home/mytechpg/yocto/poki/meta-raspberrypi \
"
In this case, I have added the latest two lines, with meta-raspberrypi and meta-openembedded layers.

You can download my config files from GitHub.

Build and install the system

To build the system you have to use the command bitbake from the /home/mytechpg/yocto/poki/raspberrypi/ directory.
You can use:

bitbake rpi-hwup-image

to build a minimal system, without the graphical environment 


You can find the images in poky/raspberrypi/tmp/deploy/images/raspberrypi and copy:

rpi-hwup-image-raspberrypi.rpi-sdimg


on a SD with the dd command.

The syntax of dd command is:

sudo dd if=<image file> of=/dev/<SD name>

You can discover the correct dev with the dmesg command.

To build a more complete environment you can use this command:
bitbake core-image-full-cmdline

Other available images are:
- rpi-basic-image
- core-image-sato