Page
1
(This page has no text content)
Page
2
Embedded Linux Development Using Yocto Project Fourth Edition Build production-grade embedded Linux products with the Yocto Project 6.0 (Wrynose) Otavio Salvador Daiane Angolini
Page
3
Embedded Linux Development Using Yocto Project Fourth Edition Copyright © 2026 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the authors, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information. Portfolio Director: Rohit Rajkumar Relationship Lead: Kaustubh Manglurkar Project Manager: Sandip Tadge Content Engineer: Anuradha Joglekar Technical Editor: Tejas Mhasvekar Copy Editor: Anuradha Joglekar Indexer: Tejal Soni Proofreader: Anuradha Joglekar Production Designer: Vijay Kamble Marketing Owner: Chayan Majumdar First edition: July 2014 Second edition: November 2017 Third edition: April 2023 Fourth edition: September 2026 Production reference: 1180926 Published by Packt Publishing Ltd. Grosvenor House 11 St Paul's Square Birmingham B3 1RB, UK. ISBN 978-1-80669-507-2 www.packtpub.com
Page
4
To Khem Raj, Vanessa Maegima, and Sergio Prado, whose technical review made this a better book, and to the Yocto Project and OpenEmbedded Project communities, whose work is the subject of every page. Our thanks also to the team at Packt for their support throughout the process. – Otavio Salvador and Daiane Angolini
Page
5
Foreword I have been working on OpenEmbedded and the Yocto Project for longer than I like to dwell on these days, starting with Poky Linux at OpenedHand back in 2006. We were trying to solve the comparatively simple problem of production-quality embedded Linux: a core set of packages that were well tested, with reliable and reproducible builds, without every team needing to write their own build scripts. It turned out that having builds that just worked, while considering the practicalities of shipping commercial products, was something people wanted, and a few years later this evolved into the Yocto Project, released in 2011. Fast-forward 20 years and there's still work to be done, as the world continues to change and being able to build an image easily just isn't enough anymore. You need to know exactly what is in it, where it all came from, what vulnerabilities have been reported, and how to implement updates after it has been released. And, importantly, you need to be able to demonstrate all of this when your Legal team, a customer, or even a state regulator asks. That last one is a significant change from the world in which Poky Linux was started. Security scans are no longer something you do once when you're about to ship, fixing the worst issues and hoping for the best. You need to know your full software supply chain throughout the product's lifetime, so you know that you're not shipping an ancient library that was bundled into another piece of software. Fail to do this, and your product could be compromised, inadvertently become part of a botnet, and you may only find out when the state regulators come knocking. Open source licensing has also evolved, and shipping a single huge page containing all of the license texts isn't considered "best in class" anymore. There are licenses that have serious implications or "interesting" interactions when combined with other licenses. They need to be tracked in detail so that you understand what licenses are going into your image, while also watching all of the projects for licensing changes. License compliance is no longer an academic exercise, but a process with real legal ramifications. The reason I encourage anyone making Linux-based products to use the Yocto Project is that these requirements are not afterthoughts; they have always been a key consideration of the project from day one. It has been tracking license texts, generating manifests, scanning for vulnerabilities, and reporting on changes between builds for many years. Now the regulatory environment has caught up with what has long been considered just best practices, and the Yocto Project is well suited to help users comply with the new rules.
Page
6
Of course, the Yocto Project is still complex and can have what I've previously described as a "near-vertical" learning curve. Building systems with sufficient flexibility to work across the wide range of deployments that the Yocto Project supports just isn't simple, as removing complexity often removes options that may well be needed for your specific requirements. This is where having authors like Otavio and Daiane is key. They're not writing about the Yocto Project from afar, rewriting the manual just enough to be different. They've been using the Yocto Project since its inception, contributing to it, maintaining BSPs, and working with commercial customers who have faced these issues and need to make things work. That experience shows through in the book: years of experience with real problems and actual people have molded the content, so it focuses on explaining the basics efficiently and knows what the reader's next question will be. The Yocto Project documentation has a Quick Start guide that shows you how to build and boot an image. This book can help you take that image, the same image that everyone else built, and turn it into your image, your idea, your product. Happy building! Ross Burton Yocto Project TSC member and Principal Engineer, Arm Ltd.
Page
7
Contributors About the authors 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 board support packages (BSPs) and helping companies with their product development challenges. This resulted in his joining the OpenEmbedded Project community in 2008, and he has contributed to the Yocto Project since its earliest releases, becoming the maintainer of meta‑freescale, the community BSP layer for NXP hardware, in 2011. He is also active in the Zephyr Project. As Chief Executive Officer of O.S. Systems, he works across build systems, low-level and system programming, and real-time embedded development. More recently, he has adopted AI technologies deeply in his day-to-day engineering work. Beyond his technical work, he follows the financial markets closely, with a particular interest in options and cryptocurrencies. He is a co-author of all four editions of this book. To my wife, Bruna Salvador, for her support and her patience, and for making room in our life for a book that took far more of it than I promised. And to the team at O.S. Systems, whose work with customers is where most of these explanations were first worked out.
Page
8
Daiane Angolini has been working with embedded Linux since 2008. She is a senior software engineer at Foundries.io, now part of Qualcomm Technologies, Inc., where she works on platform engineering for the Foundries.io open-source projects, including the company's Yocto Project distribution and the BSPs it carries across ARM and x86 platforms. She has contributed to meta‑freescale since 2012 and takes part in the Linux kernel, U-Boot, OpenEmbedded Project, and Yocto Project communities. Before that, at NXP, she worked on internal development, ported custom applications across i.MX platforms, and supported customers on the Linux kernel, U-Boot, and user-space applications. She writes technical articles on ARM architectures and the Yocto Project, and she has co-authored every edition of this book. To my husband, Thiago Justo, for his tremendous support while this book was written. And to my managers, David Griego and Nicolas Dechesne, and my employer, for the time and backing to work on this project.
Page
9
About the reviewers Khem Raj is the Embedded Linux and Open Source Leader at Qualcomm's IoT, Automotive, and Robotics business unit. He holds a bachelor's degree (Hons) in electronics and communications engineering. He has over 25 years of experience building operating systems, compilers, and scalable build systems at start-ups and Fortune 500 companies. A prolific open- source contributor, he is the lead maintainer of OpenEmbedded and sub-system maintainer for Yocto Project, looking after the toolchain and SDK recipes. He has been on the Yocto Project advisory board, TSC, and OpenEmbedded technical steering committee. He also maintains critical layers such as meta-riscv. A frequent conference speaker, he has reviewed Mastering Embedded Linux Programming and Mastering Linux Device Driver Development for Packt. He is an avid reader and a lifelong learner. I would like to thank Packt for giving me the opportunity to review this book. Above all, I would like to thank my wife, Sweta, and our children, Himangi and Vihaan, for always being there for me and supporting me in all my endeavors. Vanessa Maegima is an embedded systems engineer with over a decade of experience in Linux BSP development and customer support. She has worked at companies ranging from major SoC vendors, such as Qualcomm and NXP, to the startup-oriented environment of Foundries.io, gaining a broad perspective on embedded software development and real-world product use cases. As a technical documentation enthusiast, she enjoys turning complex engineering concepts into clear, practical, and useful guidance. She lives in southeastern Brazil with her loving husband and their playful dog. Sergio Prado is an embedded systems engineer, consultant, and trainer with more than 30 years of experience in embedded software development. He is the founder and principal engineer at Embedded Labworks, where he helps companies develop embedded Linux systems and trains engineering teams worldwide. He is an active open source contributor and has contributed to projects including the Yocto Project, Buildroot, and the Linux kernel. Sergio is also a frequent speaker at international conferences, including the Yocto Project Summit and Embedded Linux Conference.
Page
10
Table of Contents Preface xix Free benefits with your book ............................................................................................... xxvii Part 1: Getting Started 1 Chapter 1: Meeting the Yocto Project 3 What is the Yocto Project? ......................................................................................................... 4 Why the Yocto Project? .............................................................................................................. 4 How the Yocto Project produces embedded systems ................................................................. 5 OpenEmbedded Project and the Yocto Project .......................................................................... 6 Yocto Project metadata layers ................................................................................................... 6 Release cadence and the LTS cycle ............................................................................................. 8 Yocto Project 6.0 release notes and migration guide ............................................................... 10 Summary ................................................................................................................................ 10 Chapter 2: Baking Our First Yocto Project Image 11 Technical requirements ............................................................................................................ 12 Preparing the build host system ............................................................................................... 12 Using Windows Subsystem for Linux (WSL 2) • 13 Preparing a Linux-based system • 14 Debian-based distributions • 15 Fedora • 16 openSUSE Leap • 17 AlmaLinux, Rocky Linux, and CentOS Stream • 17 Setting up with bitbake-setup ................................................................................................ 18 Installing the bitbake-setup tool • 18 Initializing your first project • 19 Understanding the bitbake-setup directory structure • 20 Activating the build environment • 21 Reviewing the configuration files • 21
Page
11
Building a target image ........................................................................................................... 22 Running images in QEMU ....................................................................................................... 25 Summary ................................................................................................................................ 27 Chapter 3: Using VS Code with the BitBake Extension 29 Technical requirements ........................................................................................................... 30 Opening the generated workspace file .................................................................................... 30 Installing the Yocto Project BitBake extension ......................................................................... 31 Working with syntax highlighting and context-based suggestions ......................................... 32 Touring the extension's other features .................................................................................... 33 Building core-image-full-cmdline from VS Code .................................................................... 34 Running runqemu from VS Code ............................................................................................. 35 Using the integrated terminal • 35 Defining a workspace task • 35 Summary ................................................................................................................................ 37 Chapter 4: Meeting the BitBake Tool 39 Technical requirements ........................................................................................................... 39 BitBake's role in the build workflow ...................................................................................... 40 Metadata collections and layer structure ............................................................................... 40 Inspecting layers with bitbake-layers ..................................................................................... 42 Configuration, classes, and recipes ......................................................................................... 43 Summary ................................................................................................................................ 45 Part 2: Core Concepts 47 Chapter 5: Grasping the BitBake Tool 49 Technical requirements ........................................................................................................... 50 Preparing the environment ..................................................................................................... 50 Indexing metadata ................................................................................................................... 51 Initializing BitBake .................................................................................................................. 51 Parsing metadata .................................................................................................................... 52 Dependencies .......................................................................................................................... 53 Inspecting the dependency graph • 55 Fetching the source code ......................................................................................................... 56 Table of Contents x
Page
12
Remote file downloads • 57 Git repositories • 59 Optimizing source code downloads ....................................................................................... 60 Disabling network access • 62 Understanding BitBake tasks .................................................................................................. 63 Common BitBake tasks explained • 64 Hash equivalence • 65 Summary ................................................................................................................................ 65 Chapter 6: Detailing the Temporary Build Directory 67 Technical requirements ........................................................................................................... 68 Detailing the build directory ................................................................................................... 68 Constructing the build directory ............................................................................................. 69 Exploring the temporary build directory ................................................................................. 70 Understanding the work directory ........................................................................................... 71 Understanding the sysroot directories .................................................................................... 75 Summary ................................................................................................................................ 76 Chapter 7: Assimilating Packaging Support 77 Technical requirements ........................................................................................................... 77 Supported package formats .................................................................................................... 78 List of supported package formats • 78 Choosing a package format • 78 Running code during package installation .............................................................................. 79 Understanding the Shared State Cache ................................................................................... 81 Explaining package versioning ................................................................................................ 83 Specifying runtime package dependencies .............................................................................. 83 Using packages to generate a root filesystem image ................................................................ 84 Package feeds .......................................................................................................................... 85 Using package feeds • 86 Summary ............................................................................................................................... 88 Chapter 8: Understanding BitBake Metadata 89 Technical requirements .......................................................................................................... 90 Variable assignment and expansion operators ....................................................................... 90 xi Table of Contents
Page
13
Basic variable assignment • 91 Variable expansion • 92 Deferred evaluation • 92 Immediate variable expansion • 92 Assigning a value with ?= • 92 Assigning a default with ??= • 93 List and string appending, prepending, and removal .............................................................. 94 List appending and prepending • 94 String appending and prepending • 94 Using :append and :prepend • 94 Comparing :append with .= • 95 Removing list items • 95 Conditional metadata and the override mechanism ............................................................... 95 Conditional metadata sets • 95 Conditional appending • 96 Working through a combined example • 97 File inclusion with include and require ................................................................................... 97 Python and shell metadata functions ...................................................................................... 98 Python variable expansion • 98 Defining executable metadata • 98 Defining python functions in the global namespace • 99 Anonymous Python functions • 99 Combining Python and shell • 100 Class files and metadata inheritance ..................................................................................... 100 Understanding class files in BitBake • 100 Global classes • 101 Recipe-specific classes • 101 Tuning workspace cleanup classes • 101 Summary ............................................................................................................................... 101 Part 3: Advanced Concepts 103 Chapter 9: Developing with the Yocto Project 105 Technical requirements ......................................................................................................... 106 What is a Software Development Kit? ................................................................................... 106 Table of Contents xii
Page
14
Generating an image for on-device development .................................................................. 107 Understanding the types of cross-development SDKs ........................................................... 107 Using the Standard SDK ........................................................................................................ 108 Installing the Standard SDK • 108 Building applications with the Standard SDK • 109 Building the Linux kernel with the Standard SDK • 110 Using the Extensible SDK ....................................................................................................... 110 Generating the Extensible SDK • 111 Installing the Extensible SDK • 111 Structure of the Extensible SDK • 113 Building an image using devtool • 113 Running an image on QEMU • 114 Creating a recipe from an external git repository • 115 Building a recipe using devtool • 117 Modifying an existing recipe with devtool • 118 Working with the devtool source git tree • 119 Extending the eSDK • 120 Using VS Code with the Extensible SDK • 121 Summary ............................................................................................................................... 122 Chapter 10: Debugging with the Yocto Project 123 Technical requirements ......................................................................................................... 124 Differentiating metadata and application debugging ........................................................... 124 Tracking image, package, and SDK content .......................................................................... 124 Debugging packaging ........................................................................................................... 126 Inspecting packages • 126 Debugging with logging in the Yocto Project ........................................................................ 128 Debugging metadata variables .............................................................................................. 129 Using a Development Shell .................................................................................................... 130 Using the GNU Debugger for debugging ................................................................................. 132 Going deeper with profiling and tracing ................................................................................ 133 Walking through a missing file .............................................................................................. 133 Summary ............................................................................................................................... 136 xiii Table of Contents
Page
15
Chapter 11: Exploring External Layers 137 Technical requirements .......................................................................................................... 137 Powering flexibility with layers ............................................................................................. 138 Detailing a layer's source code .............................................................................................. 140 Adding meta layers ................................................................................................................. 142 The OpenEmbedded Layer Index .......................................................................................... 144 Summary ............................................................................................................................... 145 Chapter 12: Creating Custom Layers 147 Technical requirements .......................................................................................................... 147 Creating the layer .................................................................................................................. 148 Adding metadata to the layer ................................................................................................. 151 Creating an image .................................................................................................................. 152 Adding a package recipe ......................................................................................................... 156 Automatically creating a base package recipe using devtool • 158 Adding support for a new machine definition ....................................................................... 160 Wrapping an image for your machine .................................................................................... 163 Using a custom distribution ................................................................................................... 167 Adjusting default DISTRO_FEATURES and MACHINE_FEATURES ......................................... 171 Interaction between MACHINE_FEATURES and DISTRO_FEATURES .................................... 172 Understanding the scope of variables in BitBake .................................................................... 173 Global variables • 173 Recipe-specific variables • 174 Summary ............................................................................................................................... 174 Chapter 13: Customizing Existing Recipes 175 Technical requirements .......................................................................................................... 176 Understanding common use cases ......................................................................................... 176 Extending a task .................................................................................................................... 178 Adding extra build options to recipes ..................................................................................... 179 Applying a patch .................................................................................................................... 181 Adding extra files to existing packages ................................................................................... 181 Understanding file search paths ............................................................................................ 183 Changing recipe feature configuration .................................................................................. 185 Table of Contents xiv
Page
16
Configuration fragments for Kconfig-based projects .............................................................. 187 Summary .............................................................................................................................. 190 Chapter 14: Managing BitBake Configuration 191 Technical requirements .......................................................................................................... 192 Exploring available configurations ........................................................................................ 192 Managing build configuration with bitbake-config-build ..................................................... 193 Listing available fragments • 193 Disabling fragments • 194 Enabling fragments • 197 Inspecting a fragment • 199 Configuration precedence and conflicts • 200 Creating custom BitBake configuration fragments ............................................................... 201 Defining a standard fragment • 201 Enabling your fragment • 203 Organizing fragments with subdirectories • 203 Defining built-in fragments • 204 Managing layers with bitbake-setup ..................................................................................... 205 Keeping your setup current ................................................................................................... 207 Reproducible team workflows ............................................................................................. 208 Creating custom BitBake configuration templates • 209 Sharing the download cache • 212 Keeping several BitBake setups under one top directory • 213 Managing private BitBake registries • 213 Source overrides for development branches • 214 Synchronizing configurations across teams • 215 Configuration, sources, and reproducibility • 216 Summary .............................................................................................................................. 216 Chapter 15: License Compliance and Software Bill of Materials 219 Technical requirements ......................................................................................................... 220 Understanding copyleft ........................................................................................................ 220 The role of the Yocto Project ................................................................................................... 221 Achieving copyleft compliance with the Yocto Project ........................................................... 221 Managing software licensing with the Yocto Project ............................................................. 222 xv Table of Contents
Page
17
Understanding commercial licenses ..................................................................................... 225 Configuring your project for compliance .............................................................................. 226 Understanding license auditing • 226 Providing the source code • 227 Providing compilation scripts and source code modifications • 230 Considerations for copyleft compliance • 230 Output file formats • 230 Providing license text inside the image • 230 Generating a Software Bill of Materials • 231 Declaring a proprietary license for your own recipes • 232 SBOM-based vulnerability scanning • 235 Summary .............................................................................................................................. 237 Part 4: Bridging to Real-World Application 239 Chapter 16: Building and Booting a Custom Embedded Linux System 241 Technical requirements ......................................................................................................... 242 Discovering the right BSP layer ............................................................................................. 242 Reviewing aspects that impact hardware use ........................................................................ 243 Key considerations for board selection • 243 Overview of widely used BSP layers • 244 Using physical hardware • 244 BeagleBone Black .................................................................................................................. 247 Baking for BeagleBone Black • 247 Setting up the source structure • 247 Building the image • 248 Writing the image to an SD card • 249 Booting the board • 249 Raspberry Pi 4 or Raspberry Pi 5 ............................................................................................ 250 Baking for Raspberry Pi 4 or Raspberry Pi 5 • 250 Setting up the source structure • 250 Building the image • 252 Writing the image to an SD card • 252 Booting the board • 254 Table of Contents xvi
Page
18
VisionFive 2 ........................................................................................................................... 254 Baking for VisionFive 2 • 254 Setting up the source structure • 254 Building the image • 256 Writing the image to an SD card • 256 Booting the board • 256 Arduino UNO Q ..................................................................................................................... 257 Baking for the Arduino UNO Q • 257 Setting up the source structure • 258 Enabling the qcomflash image type • 261 Building the image • 261 Flashing with qdl • 262 Booting the board • 263 Taking the next steps ............................................................................................................ 263 Contributing to the community • 264 Embracing feedback • 264 Summary .............................................................................................................................. 264 Chapter 17: Speeding Up Product Development Through Emulation (QEMU) 267 Technical requirements ......................................................................................................... 268 What is QEMU? ..................................................................................................................... 268 What are the benefits of using QEMU over hardware? .......................................................... 269 When is choosing real hardware preferable? ......................................................................... 269 Using runqemu capabilities .................................................................................................. 270 Using runqemu to test graphical applications • 271 Using runqemu to validate memory constraints • 273 Using runqemu to select a Linux kernel image and root filesystem • 275 Using runqemu to pass custom boot arguments • 276 Using runqemu with a serial console • 276 Using runqemu to validate audio stacks • 277 Using runqemu to help with image regression tests • 277 Using runqemu to run package tests with ptest • 280 Summary .............................................................................................................................. 283 xvii Table of Contents
Page
19
Chapter 18: Best Practices 285 Guidelines to follow for the Yocto Project ............................................................................. 286 Manage layers • 286 Tidy up bitbake-setup configuration files • 287 Avoid creating too many layers • 289 Prepare the product metadata for new Yocto Project releases • 290 Create your custom distribution • 290 Avoid reusing existing images for your product • 291 Standard SDK is commonly undervalued • 291 Avoid too many patches for the Linux kernel and bootloader modifications • 292 Avoid using AUTOREV as SRCREV • 293 Maintain the Shared State Cache • 293 Enforce the guidelines with version control and continuous integration • 295 Create a software bill of materials • 295 Guidelines to follow for general projects ............................................................................... 296 Continuously monitor the project license constraints • 296 Security can harm your project • 297 Don't underestimate maintenance costs • 298 Tackle project risk points and constraints as soon as possible • 299 Summary ............................................................................................................................. 300 Chapter 19: Unlock Your Exclusive Benefits 301 Unlock this Book's Free Benefits in 3 Easy Steps .................................................................... 302 Other Books You May Enjoy 306 Index 309 Table of Contents xviii
Page
20
Preface An embedded Linux product is never only a Linux kernel and a root filesystem. It is a particular set of packages, built with a particular toolchain, for a particular piece of hardware, under license terms you have to be able to account for. Assembling that by hand works once. It does not survive a product line, and it does not survive the day a security fix lands and the whole image has to be rebuilt exactly as it was built eighteen months earlier. The Yocto Project exists to make that repeatable. It is not a Linux distribution and it does not ship images you install. It is a set of tools, metadata, and community practice that lets you describe the system you want and then build it the same way every time for the hardware you ship on. Among the open-source build systems available for embedded work, a few properties make it the one most product teams settle on: Everything is built from source, so the toolchain, the compiler flags, the package selection, and the license terms of what you ship are all yours to decide and to audit The metadata is layered, which keeps hardware support, distribution policy, and your own application recipes in separate repositories that can be versioned and upgraded independently Long-term support releases are maintained for four years, which is close enough to the service life of a typical embedded product to plan around The build output is reproducible, so a colleague, a build server, and a customer support engineer investigating a field failure can all reconstruct the same image This book follows the path an engineer actually walks when adopting the Yocto Project. It opens with what the project is, who produces it, and how its releases are organized, then prepares a build host and produces a first bootable image with bitbake‑setup. From there, it turns to BitBake itself: how it locates metadata, parses it, works out the dependency graph, fetches source code, and schedules the tasks that turn that source into a package. The middle of the book covers the artifacts a build leaves behind and the metadata you write to shape them. That means the temporary build directory with its per-recipe work and sysroot trees, the packaging support that turns build output into installable packages, root filesystem images, and package feeds, and the metadata syntax itself: assignment and expansion operators, appends and removals, the override mechanism, Python and shell functions, and class inheritance. Those chapters are followed by the tooling you use on top of a working build, • • • •