Reader small image

You're reading from  Yocto for Raspberry Pi

Product typeBook
Published inJun 2016
PublisherPackt
ISBN-139781785281952
Edition1st Edition
Concepts
Right arrow
Authors (2):
TEXIER Pierre-Jean
TEXIER Pierre-Jean
author image
TEXIER Pierre-Jean

Pierre-Jean TEXIER has been an embedded Linux engineer at Amplitude Systèmes (Amplitude Systèmes was a pioneer in the marketing of Ytterbium femtosecond lasers) since 2014 where he maintains a custom system on chip i.MX6 with the Yocto project (meta-fsl-arm), which is made by a French company: EUKREA. He is a graduate of ESTEI school at Bordeaux where he spent 3 years as a student in order to become an embedded Linux Engineer. He is a big ardent of the world of free software and the embedded world. His knowledge background includes C/C++, Yocto, Linux, Bash, Kernel development but he is also open to trying new things and testing new technologies. First, I want to thank my patience wife for her during my writing sessions. I also give thanks my parents and my brother, who without them, this book possibly would not have happened. I would also like to thank all of the mentors that I've had over the years. Mentors such as Cyril SAGONERO, Sylvain LE HENAFF, Pierre BORDELAIS, Vincent POULAILLEAU, Fabrice BONNET, Jean-Claude PERESSINOTTO, Pierre AUBRY. Without learning from these teachers, there is not a chance I could be doing what I do today. To finish I would like to thanks Eric MOTTAY the CEO of Amplitude Systèmes, Luca TESTA the head of Electronics team at Amplitude Systèmes for his trust, Hitesham WOODHOO, Alexandre GAMONET, Kevin PINTO and Guillaume MACHINET For the various discussions about the raspberry pi during coffee breaks.
Read more about TEXIER Pierre-Jean

Petter Mabäcker
Petter Mabäcker
author image
Petter Mabäcker

Petter Mabcker is a senior software developer specializing in embedded Linux systems. For the past 8 years, he has been working with embedded Linux professionally. Currently, Petter works as a Scrum Master and senior software developer at Ericsson AB. Additionally, his knowledge includes C/C++, shell scripting, Yocto Project (including BitBake and OpenEmbedded), Scrum, and Git. In 2013, Petter started the small business Technux, which he runs as a side project in parallel with his duties at Ericsson. Some of the focus areas of the business are open source embedded Linux projects, such as the Yocto Project, together with different projects that involve the Raspberry Pi. As part of the work with Technux, Petter works as a contributer to the Yocto Project (including the Raspberry Pi BSP layer, known as meta-raspberrypi).
Read more about Petter Mabäcker

View More author details
Right arrow

Chapter 4. Understanding BitBake

In this chapter, we will initially explore the metadata (the basic concept) and recipes that are used by Poky (the dependencies among them). We will then look at the different ways in which BitBake downloads source code. We will end this chapter by presenting the tasks used by BitBake to get to the creation of the root filesystem image.

BitBake


As presented in Chapter 1, Meeting the Yocto Project, BitBake is a task scheduler (like GNU Make) that parses shell and Python scripts. The code parsed generates and runs tasks (configure, compile, and so on), which are basically sets of steps ordered according to the code's dependencies.

Here are some points taken directly from the BitBake user manual:

  • BitBake executes tasks according to the provided metadata, which builds up the tasks. Metadata is stored in recipe (.bb), configuration (.conf), and class (.bbclass) files and provides BitBake with instructions on what tasks to run and the dependencies between those tasks.

  • BitBake includes a fetcher library for obtaining source code from various places, such as source control systems or websites.

  • The instructions for each unit to be built (such as a piece of software) are known as recipe files and contain all the information about the unit (dependencies, source file locations, checksums, description, and so on).

  • BitBake includes a client...

Metadata


The metadata used by BitBake can be in several distinct forms; they are as follows:

  • Configuration (.conf) files

  • Recipes (.bb and .bbappend files)

  • Classes (.bbclass files)

  • Include (.inc) files

Configuration

Configuration files, which are denoted by the .conf extension, define various configuration variables that govern the project's build process. These files fall into several areas that define machine configuration options, distribution configuration options, compiler tuning options, general common configuration options, and user configuration options.

Classes

Class files, which are denoted by the .bbclass extension, contain information that is useful to share between metadata files. The BitBake source tree currently comes with one class metadata file called base.bbclass. You can find this file in the classes directory. The base.bbclass file is special since it is always included automatically for all recipes and classes. This class contains definitions for standard basic tasks such as...

Parsing metadata


The first thing BitBake does is parse base configuration metadata (.conf files). Base configuration metadata consists of the bblayers.conf file to determine what layers BitBake needs to recognize, all necessary layer.conf files (one from each layer), and bitbake.conf. The data itself is of various types:

  • Recipes: These contain details about particular pieces of software.

  • Class data: This provides an abstraction of common build information (for example, how to build a Linux kernel).

  • Configuration data: This provides machine-specific settings, policy decisions, and so forth. Configuration data acts as the glue that binds everything together.

The layer.conf files are used to construct key variables such as BBPATH and BBFILES. BBPATH is used to search for configuration and class files under the conf/ and class/ directories, respectively. BBFILES is used to find recipe files (.bb and .bbappend). If there is no bblayers.conf file, it is assumed that the user has set the BBPATH and...

Preferences and providers


Once BitBake has realized the "parsing" step (analyzing all the recipes), it must know how to build the target. It starts by looking through the PROVIDES variable set in the recipe files. The default PROVIDES value for a recipe is its name ( PN ).

Note

PN represents the name of the recipe; PR, the revision of the recipe; and PV, the version of the recipe. For example, when using the recipe rpio-gpio_0.5.9.bb, here is what the values will be:

${PN} = rpi-gpio

${PV} = 0.5.9

Sometimes, a target might have multiple providers. A common example is virtual/kernel, which is provided by each kernel recipe (check out meta-raspberrypi/tree/master/recipes-kernel/linux for further information). Each machine often selects the best kernel provider by using a line similar to the following in the machine configuration file. If we look into this following file (meta-raspberrypi / conf / machine / include /rpi-default-providers.inc), we can see some variables:

# RaspberryPi...

Dependencies


In order to satisfy dependencies, the recipes must declare what they need to have available during the build process.

BitBake use a special mechanism that allows us to list the build-time dependencies and then checks whether all of the rules are satisfied before the build step. For example, if you work with canutils ( http://pengutronix.de/software/socket- can/download/canutils/ ), you have to set this following variable:

DEPENDS = "libsocketcan" 

In this example, CANUTILS needs libsocketcan; therefore, BitBake will start by building the libsocketcan package (and installing the headers into rootfs) before building canutils and linking.

When an application depends on something to run, it is called a runtime dependency (these are packages necessary on the target in order to guarantee proper functioning). In this case, we don't need to set the DEPENDS variable but the RDEPENDS variable in a recipe in order to inform BitBake.

Fetching


The mechanism used by BitBake to fetch source code is internally called the fetcher backend. There are several fetcher backends supported, which can be configured to align user requirements and optimize source code fetching.

BitBake supports several protocols for remote file downloads. The most commonly used are http://, https://, and git://. When BitBake executes the do_fetch task in a recipe, it checks the contents of SRC_URI. We will discover, through the various fetchers, how to proceed based on our need.

The local file fetcher

The local file fetcher submodule handles URLs that begin with file://. The filename you specify within the URL can either be an absolute or relative path to a file. For example, with a file called my_source_file.c, we must write the SRC_URI attribute's content like this:

SRC_URI = "file://my_source_file.c" 

The HTTP fetcher

The HTTP fetcher obtains files from web servers. Internally, the fetcher uses the wget utility.

In this example, we will use the...

Understanding BitBake's tasks


The bitbake command is the primary interface to the BitBake tool. This chapter presents the bitbake command syntax and provides several execution examples.

For example, if you want to build a specific recipe, run the following command:

$ bitbake <recipe>

BitBake runs a set of scheduled tasks. When we wish to run a specific task, we can use the following command:

$ bitbake <recipe> -c <task>

If you want to clean a specific package (spitools , for example), you just have to run this:

$ bitbake spitools -c clean

To list the tasks defined for a recipe, we can use the following command:

$ bitbake <recipe> -c listtasks

Here is a description of BitBake tasks:

  • do_fetch: The first step when building a recipe is fetching the required source. This is done using the fetching backend feature we discussed previously. It is important to point out that fetching source or a file does not mean it is a remote source. In fact, every file required during the...

Summary


In this chapter, we discovered most of BitBake's functionalities. We also learned how BitBake works in order for us to generate some packages for our Raspberry Pi.

In the next chapter, we will learn how to develop within the Yocto Project. We will write recipes, create SDKs, and more.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Yocto for Raspberry Pi
Published in: Jun 2016Publisher: PacktISBN-13: 9781785281952
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Authors (2)

author image
TEXIER Pierre-Jean

Pierre-Jean TEXIER has been an embedded Linux engineer at Amplitude Systèmes (Amplitude Systèmes was a pioneer in the marketing of Ytterbium femtosecond lasers) since 2014 where he maintains a custom system on chip i.MX6 with the Yocto project (meta-fsl-arm), which is made by a French company: EUKREA. He is a graduate of ESTEI school at Bordeaux where he spent 3 years as a student in order to become an embedded Linux Engineer. He is a big ardent of the world of free software and the embedded world. His knowledge background includes C/C++, Yocto, Linux, Bash, Kernel development but he is also open to trying new things and testing new technologies. First, I want to thank my patience wife for her during my writing sessions. I also give thanks my parents and my brother, who without them, this book possibly would not have happened. I would also like to thank all of the mentors that I've had over the years. Mentors such as Cyril SAGONERO, Sylvain LE HENAFF, Pierre BORDELAIS, Vincent POULAILLEAU, Fabrice BONNET, Jean-Claude PERESSINOTTO, Pierre AUBRY. Without learning from these teachers, there is not a chance I could be doing what I do today. To finish I would like to thanks Eric MOTTAY the CEO of Amplitude Systèmes, Luca TESTA the head of Electronics team at Amplitude Systèmes for his trust, Hitesham WOODHOO, Alexandre GAMONET, Kevin PINTO and Guillaume MACHINET For the various discussions about the raspberry pi during coffee breaks.
Read more about TEXIER Pierre-Jean

author image
Petter Mabäcker

Petter Mabcker is a senior software developer specializing in embedded Linux systems. For the past 8 years, he has been working with embedded Linux professionally. Currently, Petter works as a Scrum Master and senior software developer at Ericsson AB. Additionally, his knowledge includes C/C++, shell scripting, Yocto Project (including BitBake and OpenEmbedded), Scrum, and Git. In 2013, Petter started the small business Technux, which he runs as a side project in parallel with his duties at Ericsson. Some of the focus areas of the business are open source embedded Linux projects, such as the Yocto Project, together with different projects that involve the Raspberry Pi. As part of the work with Technux, Petter works as a contributer to the Yocto Project (including the Raspberry Pi BSP layer, known as meta-raspberrypi).
Read more about Petter Mabäcker