Yocto for Raspberry Pi
上QQ阅读APP看书,第一时间看更新

Installing the required packages for the host system

The steps necessary for the configuration of the host system depend on the Linux distribution used. Indeed, it is advisable to use one of the Linux distributions maintained and supported by Poky. This is to avoid wasting time and energy in setting up the host system. Currently, the Yocto Project is supported on the following distributions:

  • Ubuntu 12.04 (LTS)
  • Ubuntu 13.10
  • Ubuntu 14.04 (LTS)
  • Fedora release 19 (Schrödinger's Cat)
  • Fedora release 21
  • CentOS release 6.4
  • CentOS release 7.0
  • Debian GNU/Linux 7.0 (Wheezy)
  • Debian GNU/Linux 7.1 (Wheezy)
  • Debian GNU/Linux 7.2 (Wheezy)
  • Debian GNU/Linux 7.3 (Wheezy)
  • Debian GNU/Linux 7.4 (Wheezy)
  • Debian GNU/Linux 7.5 (Wheezy)
  • Debian GNU/Linux 7.6 (Wheezy)
  • openSUSE 12.2
  • openSUSE 12.3
  • openSUSE 13.1

Note

Even if your distribution is not listed here, it does not mean that Poky will not work, but the outcome is not guaranteed. Throughout this book, you will be presented with instructions for using Poky with the Ubuntu distribution. If you want more information about the supported Linux distributions, you can visit this link: http://www.yoctoproject.org/docs/current/ref-manual/ref-manual.html.

Poky on Ubuntu

The following list shows you the packages required for Poky by function, given a supported Ubuntu or Debian Linux distribution:

  • Download tools: wget and git-core
  • Decompression tools: unzip and tar
  • Compilation tools: gcc-multilib, build-essential, and chrpath
  • String-manipulation tools: sed and gawk
  • Document-management tools: texinfo, xsltproc, docbook-utils, fop, dblatex, and xmlto
  • Patch-management tools: patch and diffstat

To summarize, here is the command to type on a headless system:

$ sudo apt-get install gawk wget git-core diffstat unzip texinfo gcc-multilib build-essential chrpath

Poky on Fedora

If you want to use Poky on Fedora, you just have to type this command line:

$ sudo yum install gawk make wget tar bzip2 gzip python unzip perl patch diffutils diffstat git cpp gcc gcc-c++ glibc-devel texinfo chrpath ccache perl-Data-Dumper perl-Text-ParseWords perl-Thread-Queue socat

Downloading the Poky metadata

After having installed all the necessary packages, it is time to download the source from Poky. This is done through the Git tool:

$ git clone git://git.yoctoproject.org/poky (branch master)

Note

Another method involves directly downloading a tar.bz2 file from this repository: https://www.yoctoproject.org/downloads

To avoid all hazardous and problematic manipulations, it is strongly recommended to create and switch to a specific local branch:

$ cd poky
$ git checkout daisy -b work_branch

Downloading the Raspberry Pi BSP metadata

At this stage, we only have the base of the reference system (Poky) and we have no support for the Broadcom BCM SoC. Basically, the BSP proposed by Poky only offers the following targets:

$ ls meta/conf/machine/*.conf
beaglebone.conf
edgerouter.conf
genericx86-64.conf
genericx86.conf
mpc8315e-rdb.conf

In addition, there are those provided by OE-Core:

$ ls meta/conf/machine/*.conf
qemuarm64.conf
qemuarm.conf
qemumips64.conf
qemumips.conf
qemuppc.conf
qemux86-64.conf
qemux86.conf

Tip

Detailed steps to download the code bundle are mentioned in the Preface of this book. Please have a look. The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Yocto-for-Raspberry-Pi. We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

In order to generate a compatible system for our target, we will spend more time in this stage and download the specific layer (BSP Layer) to the Raspberry PI:

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

Tip

If you want to learn more about git scm, you can visit the official website: http://git-scm.com/

Now, we can verify that we have the configuration metadata for our platform (the rasberrypi.conf file):

$ ls meta-raspberrypi/conf/machine/*.conf
raspberrypi.conf

The following screenshot shows the meta-raspberypi folder:

The examples and code presented in this and the following chapters use Yocto Project version 1.7 and Poky version 12.0. For reference, the code name is Dizzy.

Now that we have our environment freshly downloaded, we can proceed with the initialization of our environment and the configuration of our image through various configuration files.

The oe-init-build-env script

As can be seen in the screenshot before last, the Poky directory contains a script named oe-init-build-env. This is a script for the configuration/initialization of the build environment. It is not intended to be executed but must be the sourced. Its job, among others, is to initialize a certain number of environment variables and place itself in the build directory specified in the argument. The script must be run as follows:

$ source oe-init-build-env [build-directory]

Here, build-directory is an optional parameter for the name of the directory where the environment is set (for example, we can use several build directories in a single Poky source tree). In case it is not specified, it defaults to build. The build-directory folder is the place where we perform builds. But, in order to standardize the steps, we will use the following command throughout the book to initialize our environment:

$ source oe-init-build-env rpi-build
### Shell environment set up for builds. ###
You can now run 'bitbake <target>'
Common targets are:
core-image-minimal
core-image-sato
meta-toolchain
adt-installer
meta-ide-support
You can also run generated qemu images with a command like 'runqemu qemux86'

When we initialize a build environment, it creates a directory (the conf directory) inside rpi-build. This folder contains two important files:

  • local.conf: This contains parameters to configure Bitbake's behavior.
  • bblayers.conf: This lists the different layers that Bitbake takes into account in its implementation. The list is assigned to the BBLAYERS variable.

Editing the local.conf file

The rpi-build/conf/local.conf file is a file that can configure every aspect of the build process. It is through this file that we can choose the target machine (the MACHINE variable), the distribution (the DISTRO variable), the type of package (the PACKAGE_CLASSESvariable), and the host configuration (PARALLEL_MAKE, for example). The minimal set of variables we have to change from the default is the following:

BB_NUMBER_THREADS ?= "${@oe.utils.cpu_count()}" 
PARALLEL_MAKE ?= "-j ${@oe.utils.cpu_count()}" 
MACHINE ?= raspberrypi MACHINE ?= "raspberrypi" 

The BB_NUMBER_THREADS variable determines the number of tasks that BitBake will perform in parallel (these are tasks under Yocto; we're not necessarily talking compilation). By default, in build/conf/local.conf, this variable is initialized with ${@oe.utils.cpu_count()}, corresponding to the number of cores detected on the host system (/proc/cpuinfo).

The PARALLEL_MAKE variable corresponds to the -j to make option to specify the number of processes that GNU Make can run in parallel on a compilation task. Again, it is the number of available cores that defines the default value used.

The MACHINE variable is where we determine the target machine we wish to build for the Raspberry Pi (defined in the .conf file; in our case, it's raspberrypi.conf).

Editing the bblayers.conf file

Now we still have to add the specific layer to our target. This will have the effect of making recipes from this layer available to our build. Therefore, we should edit the build/conf/bblayers.conf file:

# LAYER_CONF_VERSION is increased each time build/conf /bblayers.conf
# changes incompatibly
LCONF_VERSION = "6" BBPATH = "${TOPDIR}" BBFILES ?= "" BBLAYERS ?= " \
/home/packt/RASPBERRYPI/poky/meta \
home/packt/RASPBERRYPI/poky/meta-yocto \
/home/packt/RASPBERRYPI/poky/meta-yocto-bsp \
"BBLAYERS_NON_REMOVABLE ?= " \
/home/packt/RASPBERRYPI/poky/meta \
/home/packt/RASPBERRYPI/poky/meta-yocto \
"

Add the following line:

 # LAYER_CONF_VERSION is increased each time build/conf /bblayers.conf
# changes incompatibly
LCONF_VERSION = "6" BBPATH = "${TOPDIR}" BBFILES ?= "" BBLAYERS ?= " \
/home/packt/RASPBERRYPI/poky/meta \
/home/packt/RASPBERRYPI/poky/meta-yocto \
/home/packt/RASPBERRYPI/poky/meta-yocto-bsp \
/home/packt/RASPBERRYPI/poky/meta-raspberrypi \
"BBLAYERS_NON_REMOVABLE ?= " \
/home/packt/RASPBERRYPI/poky/meta \
/home/packt/RASPBERRYPI/poky/meta-yocto \ "

Naturally, you have to adapt the absolute path (/home/packt/RASPBERRYPI here) depending on your own installation.