Friday, June 12, 2015

RaspberryPI and Yocto

NEW HOWTO FOR RaspberryPI3 available!

http://mytechpg.blogspot.com/2016/04/raspberrypi3-and-yocto.html


Updated to new Yocto Fido and Raspberry PI layers

The Yocto project (https://www.yoctoproject.org/) can be used to create a personal Linux distribution for the RaspberryPI device through few simple steps.

The aim of this post is to configure Yocto to build a minimal firmware for a RaspberryPI.

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

I used this README file: http://git.yoctoproject.org/cgit/cgit.cgi/meta-raspberrypi/tree/README
First, you have to download Yocto with this command:

git clone -b fido git://git.yoctoproject.org/poky

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

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

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

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 raspberrypi

The development system will be created into the raspberrypi 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 ?= "raspberrypi" 
  • 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 \
  /home/mytechpg/yocto/poki/meta-openembedded/meta-multimedia \
"
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