Reader small image

You're reading from  Embedded Linux Development Using Yocto Project - Third Edition

Product typeBook
Published inApr 2023
PublisherPackt
ISBN-139781804615065
Edition3rd Edition
Right arrow
Authors (2):
Otavio Salvador
Otavio Salvador
author image
Otavio Salvador

Otavio Salvador loves technology and started his free software activities in 1999. In 2002, he founded O.S. Systems, a company focused on embedded system development services and consultancy worldwide, creating and maintaining customized BSPs, and helping companies with their product developments challenges. This resulted in his joining the OpenEmbedded community in 2008, when he became an active contributor to the OpenEmbedded project.
Read more about Otavio Salvador

Daiane Angolini
Daiane Angolini
author image
Daiane Angolini

Daiane Angolini has been working with embedded Linux since 2008. She has been working as an application engineer at NXP, acting on internal development, porting custom applications from Android, and on-site customer support for i.MX architectures in areas such as the Linux kernel, u-boot, Android, Yocto Project, and user-space applications. However, it was on the Yocto Project that she found her place.
Read more about Daiane Angolini

View More author details
Right arrow

Customizing Existing Recipes

In the course of our work with Yocto Project’s tools, it is expected that we will need to customize existing recipes. In this chapter, we will explore some examples, such as changing compilation options, enabling or disabling features of a recipe, applying an extra patch, and using configuration fragments to customize some recipes.

Understanding common use cases

Nowadays, projects usually have a set of layers to provide the required features. We certainly need to make changes on top of them to adapt them to our specific needs. They may be cosmetic or substantive changes, but the way to make them is the same.

We must create a .bbappend file to change a preexisting recipe in our project layer. For example, suppose the original recipe was named <original-layer>/recipes-core/app/app_1.2.3.bb. When you create a .bbappend file, you can use the % wildcard character to allow for matching recipe names. So, the .bbappend file could have the following different forms:

  • App_1.2.3.bbappend: This applies the change only for the 1.2.3 version
  • app_1.2.%.bbappend: This applies the change only for the 1.2.y version
  • app_1.%.bbappend: This applies the change only for the 1.x and 1.x.y versions
  • app_%.bbappend: This applies the change for any version

We can have multiple .bbappend files, depending...

Adding extra options to recipes based on Autotools

Let’s assume we have Autotools-based application, along with a preexisting recipe for it, and we want to do the following:

  • Enable my-feature
  • Disable another-feature

The content of the .bbappend file to make the changes will be the following:

Figure 13.2 – Adding extra configuration to the Autoconf flags

Figure 13.2 – Adding extra configuration to the Autoconf flags

The same strategy can be used if we need to enable it conditionally based on the hardware we are building for, as follows:

Figure 13.3 – Conditionally adding extra configuration to the Autoconf flags

Figure 13.3 – Conditionally adding extra configuration to the Autoconf flags

The Yocto Project supports many different build systems, and the variables to configure them are shown in the following table:

Applying a patch

For cases where we need to apply a patch to an existing package, we should use FILESEXTRAPATHS, which includes new directories in the searching algorithm, making the additional file visible to BitBake, as shown here:

Figure 13.4 – The content of .bbappend is used only to apply mypatch.patch

Figure 13.4 – The content of .bbappend is used only to apply mypatch.patch

In the preceding example, THISDIR expands to the current directory, and PN and PV expand to the package name and version, respectively. This new path is then included in the directories list used for file searching. The prepend operator is crucial as it guarantees that the file is picked from this directory, even if a file with the same name is added in the lower priority layers in the future.

BitBake assumes that every file with a .patch or .diff extension is a patch and applies them accordingly.

Adding extra files to the existing packages

If we need to include an additional configuration file, we should use FILESEXTRAPATHS, as explained in the previous example and shown in the following lines of code:

Figure 13.5 – The content of the .bbappend file to install a new configuration file

Figure 13.5 – The content of the .bbappend file to install a new configuration file

The do_install:append function appends the provided block below the metadata already available in the original do_install function. It includes the command to copy our new configuration file into the package’s filesystem. The file is copied from ${WORKDIR} to ${D} as these are the directories used by Poky to build the package and the destination directory used by Poky to create the package.

There are many variables to define paths in our recipes, such as bindir, datadir, and sysconfdir. The poky/meta/conf/bitbake.conf file defines all those commonly used variables. The variables exist, so the installation paths of binaries can be customized depending...

Configuration fragments for Kconfig-based projects

The Kconfig configuration infrastructure has become popular due to its flexibility and expressiveness. Although it started with Linux kernel, some other projects use the same infrastructure, such as U-Boot and BusyBox.

The configuration is based on select-based features where you can enable or disable a feature and save the result of this choice in a file for later use. So please consider the following figure:

Figure 13.9 – Enable or disable TFTPD on BusyBox KConfig

Figure 13.9 – Enable or disable TFTPD on BusyBox KConfig

We have control whether the TFTPD support in BusyBox is enabled (a) or not (b).

The Yocto Project provides a specialized class to handle the configuration of the Kconfig-based project, allowing minor modifications called configuration fragments. We can use this to enable or disable features for your machine, for example, when configuring linux-yocto, we can use <layer>/recipes-kernel/linux/linux-yocto_%.bbappend as in the...

Summary

In this chapter, we learned how to customize existing recipes using the .bbappend files and benefited from this by avoiding the duplication of source code. We saw how to enable or disable a feature, how to apply a patch, and how to use the configuration fragment support.

In the next chapter, we will discuss how the Yocto Project can help us with some legal aspects of producing a Linux-based system using packages under different licenses. We will understand which artifacts we need and how Poky can be configured to generate the artifacts that should be shared as part of the copyleft compliance accomplishment process.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Embedded Linux Development Using Yocto Project - Third Edition
Published in: Apr 2023Publisher: PacktISBN-13: 9781804615065
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
Otavio Salvador

Otavio Salvador loves technology and started his free software activities in 1999. In 2002, he founded O.S. Systems, a company focused on embedded system development services and consultancy worldwide, creating and maintaining customized BSPs, and helping companies with their product developments challenges. This resulted in his joining the OpenEmbedded community in 2008, when he became an active contributor to the OpenEmbedded project.
Read more about Otavio Salvador

author image
Daiane Angolini

Daiane Angolini has been working with embedded Linux since 2008. She has been working as an application engineer at NXP, acting on internal development, porting custom applications from Android, and on-site customer support for i.MX architectures in areas such as the Linux kernel, u-boot, Android, Yocto Project, and user-space applications. However, it was on the Yocto Project that she found her place.
Read more about Daiane Angolini

Build System

Variable

Autotools

EXTRA_OECONF

Cargo

...