Using Yocto Project With BeagleBone Black - Sample Chapter
Using Yocto Project With BeagleBone Black - Sample Chapter
pl
C o m m u n i t y
Create a home surveillance solution
using a webcam attached to the
BeagleBone USB port
$ 39.99 US
26.99 UK
H M Irfan Sadiq
P U B L I S H I N G
Sa
m
ee
E x p e r i e n c e
D i s t i l l e d
H M Irfan Sadiq
Preface
Using Yocto Project with BeagleBone Black is intended to be training material for
newbies using Yocto Project. For this purpose, the hardware used is BeagleBone.
The book is written keeping reader engagement a top priority. By the end of the first
chapter, you will have a working Yocto Project build running on BeagleBone and
ready for further experimentation on the host side. Initially, we used existing examples
and projects created by Yocto Project scripts to avoid any duplication, save time,
and get things functional quickly while performing rigorous changes to learn about
multiple scenarios. We won't use graphical tools, even if they are available, in order
to avoid making things misleading as well as to avoid a shallow understanding. Also,
sometimes, they sometime create confusion by overriding user customizations.
By the end of the book, you will have the necessary skill set, exposure, and
experience required to grab any professional grade project based on Yocto Project
and BeagleBone.
Preface
Chapter 5, Creating and Exploring Layers, teaches you how to override functionalities
of recipe files available in the existing layers. We will also look at various techniques
used in different scenarios, along with the pros and cons of such techniques.
Chapter 6, Your First Console Game, helps with creating recipes for some of the popular
console-based gamesfor example, MyMan.
Chapter 7, Turning BeagleBone into a Home Surveillance System, teaches you how to
create an advanced project using BeagleBone and Yocto Project. We will create a
home surveillance solution using a webcam attached to the BeagleBone USB port.
Chapter 8, BeagleBone as a Wi-Fi Access Point, guides you to create an advanced Project
using BeagleBone and Yocto Project. We will turn our BeagleBone into a Wi-Fi access
point by attaching a USB dongle.
That is not to say that Yocto Project will not work on other distributions, but the
given distributions are the ones on which it is verified to work successfully.
Ubuntu 13.10
For Poky Daisy 1.6.1, the list is long. We will stick to Ubuntu 14.04 (LTS) for the rest
of the book. For this release, package dependencies that need to be taken care of are
divided into the following four subcategories.
Essentials
These are the core tools and packages that are required to build Yocto Project. These
include a GNU compiler, versioning control system, and other packages that are
required to build an environment on host. Here's the command to get the essentials:
$ sudo apt-get install gawk wget git-core diffstat unzip texinfo gccmultilib \
build-essential chrpath
Graphics
If you want to use graphics support or you intend to use Eclipse IDE, then you need
to install these packages:
$
Documentation
These packages are required if you want to build a Yocto Project documentation:
$
[2]
Chapter 1
If you are using any distribution other than those previously listed, you will
find similar commands can be used on Debian distributions, as well. For other
supported distributions, consult the Yocto Project Reference Manual.
mkdir yocto
cd yocto
cd poky
What is the next logical step? Have a look at the directory contents using the
ls command to see what we got. Welcome! We are in good place. Let's enjoy
our journey.
[3]
The build_bbb argument can be anything you want. I wanted to keep it simply
bbb. However, I cannot do this as my Git Aware Prompt keeps complaining about
new content. If you inspect .gitignore, you will see that it has build* in it. So,
the directory prefixed with build will be ignored. This command will land you in
the newly created build directory. Before moving further, we need to examine this
directory. Here, we have a subdirectory named conf and two files, bblayers.conf
and local.conf. We will look into bblayers.conf in the upcoming chapters. For
now, we will go through the contents of local.conf.
Local.conf
First, we will encounter the following two options, which are related to each other.
These options are here to tune the level of parallelism used by BitBake, the actual
driver behind Yocto Project. The two options are:
BB_NUMBER_THREADS ?= "${@oe.utils.cpu_count()}"
You will find these variables twice in this file: once in the preceding form and once in
the following form:
#BB_NUMBER_THREADS ?= "4"
#PARALLEL_MAKE ?= "-j 4"
We are telling BitBake about the maximum number of threads it should use for the
job and the maximum of jobs run in parallel. Most of the Yocto Project manuals and
blogs say both of these should be equal to the number of cores available on your
system. However, my experience has proven that the following formula gives the
maximum throughput, that is, the minimum time of execution:
BB_NUMBER_THREADS ?= "1.5 * Number of cores"
PARALLEL_MAKE ?= "-j 2 * Number of cores"
On a 16-core server, we will use the combinations of 24 and 32, whereas on an 8-core
machine we will use 12 and 16. For a 4-core machine, we will use 6 and 8 as follows:
BB_NUMBER_THREADS ?= "6"
PARALLEL_MAKE ?= "-j 8"
[4]
Chapter 1
Next, we need to select the machine. Here, we will set BeagleBone, which is already
available to us. So, we will uncomment it and comment out the default selection,
which is the qemux86 selection. Commenting out an existing selection is not strictly
necessary since it is assigned using the ?? operator, which we will discuss in the
upcoming chapters.
MACHINE ?= "beaglebone"
#MACHINE ??= "qemux86"
Next, we will set our downloads directory. This directory will be used to download
sources for packages. The available configuration variable to set this configuration is
DL_DIR. If we don't set this, its default value would be used as our build directory.
So, we will have this directory created under the build directory. We usually don't
care much in case of Board Support Packages (BSPs) running rm-rf on our build
directory to start a fresh build. In such cases, not caring about this variable can cause
regrets, as it will download all the sources again and again, causing longer build
times. We set it up in the top-level directory, which contains the poky directory itself,
so that we don't ever accidentally delete it with other expendable stuff.
DL_DIR ?= "${TOPDIR}/../../downloads"
Next, we have SSTATE_DIR, TMPDIR, and DISTRO, which we will leave unchanged for
now. SSTATE_DIR is related to the shared state feature of Yocto Project. Yocto Project
has a mechanism to check whether some package is already built and available, it
uses the existing package and doesn't build it. TMPDIR is the directory that contains a
lot of build stuff. We will go through its contents in the upcoming chapters. Then, we
have PACKAGE_CLASSES, as follow:
PACKAGE_CLASSES ?= "package_ipk"
[5]
bblayers.conf
As the name suggests, bblayers.conf is there to provide us with a mechanism to
configure our Yocto Project layers. This file has configurations related to layers. We
can add extra layers to this file to use the metadata available in these layers. This file
further classifies layers into removable and non-removable ones, as you can see in
the following code snippet:
BBLAYERSBBLAYERSBBLAYERS ?= " \
/home/irfan/yocto/poky/meta \
/home/irfan/yocto/poky/meta-yocto \
/home/irfan/yocto/poky/meta-yocto-bsp \
"
BBLAYERS_NON_REMOVABLE ?= " \
/home/irfan/yocto/poky/meta \
/home/irfan/yocto/poky/meta-yocto \
"
Since we are not using any extra layers, we will leave this file unchanged.
site.conf
This file is optional. You won't find it created by the build environment creation
script. We mostly use system-wide or other configurations common across different
builds and targets are put in this file. For example, we would use the toolchain path
if we were using an external toolchain. Another option could be specifying mirror
sites, we case it for this purpose. If we have this file created, BitBake looks for it and
uses common configurations from this file. We override any configuration that we
want modified in conf/local.conf.
auto.conf
This is an optional file. Just like the previous file, you won't find it created by the
build environment creation script. We can use this file to set our custom options so
that we don't have to modify local.conf manually. In most of the cases, this file
is used by build systems such as Jenkins. For example, if we don't want our build
directory size to explode due to space constraints, we could use the following code
file in the local.conf or auto.conf file:
INHERIT += "rm_work"
For now, we don't need to set this. I am just mentioning it here to elaborate the
preceding point. Since we will analyze the contents of the tmp/work directory in the
upcoming chapters, I would suggest that you do not use this option for the time being.
[6]
Chapter 1
Trigger build
Now that we have set all the configurations, let's start our build. You can choose any
of the images to build. I will prefer core-image-sato:
$
bitbake core-image-sato
Building images for our desired target may take some time, depending on network
speed and processing power. After the build is complete, you will have your images
ready at tmp/deploy/images/beaglebone/ under your build directory, as shown
in the following screenshot. This contains first-level bootloader MLO, second-level
bootloader u-boot, kernel image, device tree blobs, a root filesystem archive, and a
modules archive.
Here, you will notice that we have symbolic links as well as full names of the files,
with time stamp information in most of the cases. Symbolic links always point to the
latest file created. We should always try to use a symbolic link for copying to avoid
any confusion.
Now that we have our images created by Yocto Project, we are ready to verify these
images on our BeagleBone board:
dmesg | tail
mmcblk0: p1
You can also use fdisk -l to check what device is created for your card. Now, you
can use the fdisk utility as root or with sudo to create our required partitions, using
the following steps:
1. Unmount any mounted partition, using the umount command:
$
umount /dev/mmcblk0p1
2. Launch the fdisk utitility and delete the previous partition(s); in our case,
it is just one:
$
extended
Chapter 1
Partition number (1-4, default 1):
Using default value 1
First sector (2048-7774207, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-7774207, default
7774207): +32M
4. Create a second partition to hold rootfs. We will give all the remaining
space to this partition:
Command (m for help): n
Partition type:
p
extended
7. We are done with the filesystem modification. So, let's write it by issuing
the w command:
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[9]
8. Format the first partition as FAT, using the following command. We will
set the label as BOOT so that we know what directory it will be mounted
to by udisks:
$
I have created a simple script to perform all the preceding steps. I am listing these
steps here for your understanding, so that you can do any adjustments if required.
Downloading the example code
Most of the implementation code is kept at https://github.
com/YoctoForBeaglebone/ and can be pulled directly from
there. If you have something to add, feel free to add it. While
adding something to any repository, kindly avoid pushing
directly to the repository and use Git pull request mechanism
supported by GitHub.
[ 10 ]
Chapter 1
Remove the card from the host machine, and insert it into the SD card slot on
BeagleBone Black. We have a simple script named copy_images.sh for these
steps as well.
You can download the script for copying images the SD card from here:
https://github.com/YoctoForBeaglebone/BeagleScripts
Hardware setup
To boot BeagleBone Black, we need the following hardware:
BeagleBone Black
[ 11 ]
A power adapter that can supply 5V or a micro USB cable; we should use a
5V power adapter in order to avoid a decrease in the operating frequency
GND Ground
RXL
TXL
A micro USB cable should be enough in most of the cases to provide power.
However, for more resource-intensive tasks, for example, if additional peripherals
are required, you will need to connect a power adapter.
Be careful when using PL2303 pins for current; otherwise,
you may end up damaging your BeagleBone.
Serial setup
BeagleBone Black uses a serial debug port to communicate with the host machine.
We will use minicom as a serial terminal client to communicate over the serial port.
To set up minicom, perform the following steps:
1. Run this setup command as a privileged user:
$
sudo minicom -s
[ 12 ]
Chapter 1
A menu will appear on the terminal with nine different options, as shown
in the preceding screenshot. We won't be changing many of these. The up
and down arrow keys can be used to select these options. We will select the
third option, Serial port setup. Choose this option by pressing the Enter key.
You will enter into another menu in which each option is listed, along with
a corresponding key on the keyboard on the left-hand side to choose the
option. Press the A key on the keyboard to set your serial device to /dev/
ttyUSB0, and then press Enter. If you are not sure which device is created
in your case, you could find this out by using the following command
combination on another terminal:
$
2. Press E to set the baud rate. Use the A and B keys to navigate the baud rate
values. A corresponds to next and B to previous. Keep pressing B till you
get 115200 8N1. Then, press Enter to choose this setting and go back to the
previous menu.
3. Next, we need to press F and G to change enablement statuses of hardware
flow control and software flow control. Both need to be set to No. Finally,
the settings should look as shown in this screenshot:
4. Choose Save setup as dfl to avoid reconfiguring every time and choose Exit
to go to minicom. Don't exit from it if you want to observe whether there is
any activity on the serial port.
[ 13 ]
Booting BeagleBone
Now that we have everything set up, we are ready to boot. We can just insert this
card, and our board should boot from it. There might be only one issue if you have
the eMMC (embedded MultiMediaCard) boot selected by default. You will have to
disable it by booting up the board from the images you already have and renaming
the MLO file from the eMMC partition. Alternatively, you can simply execute the
following two commands on the u-boot prompt. To stop at the u-boot prompt,
simply press Enter after powering up the board before timeout:
# mmc dev 1
# mmc erase 0 512
The first command will select the eMMC card, and the second one will do the erasing
so that BeagleBone doesn't try to boot from eMMC.
Insert our prepared SD card and power up BeagleBone. You should get an output
similar to the following one on minicom:
Booting from mmc ...
## Booting kernel from Legacy Image at 82000000 ...
Image Name:
Linux-3.14.0-yocto-standard
Image Type:
Data Size:
80008000
[ 14 ]
Chapter 1
machine.conf
You won't find a file with this name. Here, machine is a placeholder for the
target board we are preparing our images for. For example, in our case, this file is
beaglebone.conf and in the preceding configuration, it is available as beaglebone.
conf in the poky/meta-yocto-bsp/conf/machine/ directory.
All of the machine- specific configurations are done in this file. We need to know
about it and have some basic understanding of its contents so that we can modify it,
if required. Let's go through it. The top-level header contains information in tags
for documentation:
#@TYPE: Machine
#@NAME: Beaglebone machine
#@DESCRIPTION: Machine configuration for http://beagleboard.org/bone
and http://beagleboard.org/black boards
Architecture-specific configurations are found in tune files. Here, we will set the
available one that will fulfill our requirements:
DEFAULTTUNE ?= "cortexa8hf-neon"
include conf/machine/include/tune-cortexa8.inc
[ 15 ]
These tune files are present under Poky on the path that we are using in
include directive.
Here, we will specify the type of filesystem images we want to create for our
machine. There are other options to choose from. Also, here, we will set extra
image commands in the case of the jffs2 image:
IMAGE_FSTYPES += "tar.bz2 jffs2"
EXTRA_IMAGECMD_jffs2 = "-lnp "
One of the most important options is the serial debug console. Here, we are
defining our eyes with which to peek inside the board:
SERIAL_CONSOLE = "115200 ttyO0"
Here, we are tweaking our kernel options to see what recipe should be used for
kernel compilation and what version of kernel needs to be built. For this, we will
use the Yocto Project keywords, PREFERRED_PROVIDER and PREFERRED_VERSION:
PREFERRED_PROVIDER_virtual/kernel ?= "linux-yocto"
PREFERRED_VERSION_linux-yocto ?= "3.14%"
We can also create another kernel image, zImage. Since this is a generic machine
for BeagleBone Black and White versions, we will create device tree binary files
for both of the target. You can opt not to build DTB for BeagleBone White, but
this won't make much difference in terms of build time or cleanliness, if you are
considering such things. Also, we can set any extra arguments that need to be
passed to KERNEL:
KERNEL_IMAGETYPE = "uImage"
KERNEL_DEVICETREE = "am335x-bone.dtb am335x-boneblack.dtb"
KERNEL_EXTRA_ARGS += "LOADADDR=${UBOOT_ENTRYPOINT}"
Here, we will configure most of the aspects of our bootloaders. We will set MLO as
the binary name for stage-one bootloader so that we will have it created as MLO, as
we saw in the images directory. We will specify a u-boot suffix, img, to be used so
that we have the u-boot.img file created. Other options are also related to u-boot,
such as these:
SPL_BINARY = "MLO"
UBOOT_SUFFIX = "img"
UBOOT_MACHINE = "am335x_evm_config"
UBOOT_ENTRYPOINT = "0x80008000"
UBOOT_LOADADDRESS = "0x80008000"
[ 16 ]
Chapter 1
Now, we will determine the features that we want our machine to support or, more
precisely, the features it has the ability to support. We will also determine which
features we want turn on:
MACHINE_FEATURES = "usbgadget usbhost vfat alsa"
bitbake.conf
As the name signifies, this file is related to BitBake, the real engine behind Yocto
Project, which is responsible for the simplification of our build process. This file is
parsed first and then the rest of the configuration files listed in it are parsed. This file
is found under poky/meta/conf/ as bitbake.conf. This is not a small file, so we
cannot go through it line by line. It contains more than 700 lines of configuration and
metadata. Almost all the metadata used in our recipes is defined in this file.
It is not a standalone file. Instead, it includes other files from the conf directory. We
can find all the files that were described earlier in it. So, bitbake.conf uses these
files and the metadata definitions in them. For example, if you remember, we used
some variables such as DL_DIR, TOPDIR, and TMPDIR, You can find all these variables
in this file, along with their default values. This file has all the metadata arranged
in different sections. It contains about 20 different sections. Variables defined in one
section are used in other sections. Let's have a brief look at some of these sections.
[ 17 ]
[ 18 ]
Chapter 1
Summary
In this chapter, you learned how to prepare our host system to use it as a Yocto
Project development host. You also learned how to build BeagleBone images using
Yocto Project, prepare an SD card, boot the board from this card, and set up serial
communication to the board to take a sneak peek into it. We discussed most of the
configuration files in this chapter. We took a brief look at some extra configuration
files, as well. In the next chapter, you will learn about the core tool behind Yocto
Project, which is BitBake, in detail. You will also learn about its various options and
how we can use them to make our lives easier.
[ 19 ]
www.PacktPub.com
Stay Connected: