Previous Next

Yocto Project Customization for Linux (Giometti R.) (z-library.sk, 1lib.sk, z-lib.sk)

Author: Giometti R.

Linux

No Description

📄 File Format: PDF
💾 File Size: 17.0 MB
12
Views
0
Downloads
0.00
Total Donations

📄 Text Preview (First 20 pages)

ℹ️

Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

📄 Page 1
Yocto Project Customization for Linux The Essential Guide for Embedded Developers — Rodolfo Giometti
📄 Page 2
Yocto Project Customization for Linux The Essential Guide for Embedded Developers Rodolfo Giometti
📄 Page 3
Yocto Project Customization for Linux: The Essential Guide for Embedded Developers ISBN-13 (pbk): 979-8-8688-1434-1 ISBN-13 (electronic): 979-8-8688-1435-8 https://doi.org/10.1007/979-8-8688-1435-8 Copyright © 2025 by Rodolfo Giometti This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed. Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights. While the advice and information in this book are believed to be true and accurate at the date of publication, neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may be made. The publisher makes no warranty, express or implied, with respect to the material contained herein. Managing Director, Apress Media LLC: Welmoed Spahr Acquisitions Editor: James Robinson-Prior Editorial Project Manager: Jacob Shmulewitz Distributed to the book trade worldwide by Springer Science+Business Media New York, 1 New York Plaza, New York, NY 10004. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@ springer-sbm.com, or visit www.springeronline.com. Apress Media, LLC is a Delaware LLC and the sole member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation. For information on translations, please e-mail booktranslations@springernature.com; for reprint, paperback, or audio rights, please e-mail bookpermissions@springernature.com. Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook versions and licenses are also available for most titles. For more information, reference our Print and eBook Bulk Sales web page at http://www.apress.com/bulk-sales. Any source code or other supplementary material referenced by the author in this book is available to readers on GitHub. For more detailed information, please visit https://www.apress. com/gp/services/source-code. If disposing of this product, please recycle the paper Rodolfo Giometti LUCCA, Italy
📄 Page 4
To Mauro and Aleandro. You know why.
📄 Page 5
v About the Author �������������������������������������������������������������������������������xiii About the Technical Reviewer ������������������������������������������������������������xv Acknowledgments ����������������������������������������������������������������������������xvii Introduction ���������������������������������������������������������������������������������������xix Chapter 1: Setting Up the Building Environment ����������������������������������1 1.1 Embedded World Terms ..................................................................................1 1.2 Target System Overview .................................................................................5 1.3 Setting Up the Target Machine ........................................................................7 1.3.1 Serial Connection ...................................................................................7 1.3.2 Network Connection .............................................................................14 1.4 Setting Up the Host Machine ........................................................................17 1.4.1 Building on Virtual Machines ................................................................19 1.4.2 Building by Using schroot (and debootstrap) ........................................21 1.5 Installing the Building Environment ..............................................................26 1.6 Summary.......................................................................................................28 Chapter 2: Installing the Sources �������������������������������������������������������29 2.1 Downloading the Repositories ......................................................................29 2.2 Setting Up the Build Directory .......................................................................32 2.3 Understanding Basic Configuration Settings ................................................38 2.4 Doing the Build ..............................................................................................44 Table of Contents
📄 Page 6
vi 2.5 Checking the Network Connection ................................................................52 2.6 Updating (and Inspecting) the Code ..............................................................55 2.7 Summary.......................................................................................................61 Chapter 3: Yocto Project Basics ���������������������������������������������������������63 3.1 What Is the Yocto Project ..............................................................................63 3.2 The Layer Model ............................................................................................65 3.3 The Core Components ...................................................................................69 3.3.1 Recipes .................................................................................................70 3.3.2 Classes .................................................................................................74 3.3.3 Configurations ......................................................................................79 3.4 Main Configuration Files ...............................................................................81 3.4.1 The local.conf File.................................................................................81 3.4.2 The machine.conf File ...........................................................................90 3.4.3 The distro.conf File ...............................................................................98 3.4.4 The bitbake.conf File ..........................................................................102 3.4.5 The bblayers.conf ...............................................................................110 3.4.6 The layer.conf .....................................................................................112 3.5 Summary.....................................................................................................115 Chapter 4: Yocto Tools ����������������������������������������������������������������������117 4.1 bitbake ........................................................................................................117 4.1.1 Executing Tasks ..................................................................................119 4.1.2 Using More Configuration Files ..........................................................124 4.1.3 Passing Variables from the Command Line ........................................129 4.2 bitbake-layers .............................................................................................132 4.3 recipetool ....................................................................................................138 4.4 devshell (and pydevshell) ............................................................................146 Table of ConTenTs
📄 Page 7
vii 4.5 devtool ........................................................................................................153 4.5.1 Adding and Modifying Recipes in the Workspace ...............................155 4.5.2 Inspecting Recipes .............................................................................166 4.5.3 Building and Testing the Code ............................................................170 4.5.4 Finalizing the Job ...............................................................................176 4.5.5 Configuring the Code ..........................................................................181 4.5.6 Miscellaneous Commands ..................................................................185 4.6 oe-pkgdata-util ...........................................................................................188 4.7 Summary.....................................................................................................194 Chapter 5: BitBake Internals ������������������������������������������������������������195 5.1 Variable Management .................................................................................195 5.1.1 Basic Assignments and Expansion .....................................................197 5.1.2 Setting Default Values ........................................................................203 5.1.3 Appending, Prepending, and Removal ................................................205 5.1.4 Unsetting Variables and Flags ............................................................208 5.1.5 Using Inline Python Variable Expansion ..............................................210 5.1.6 Using Anonymous Python Functions ..................................................213 5.1.7 Exporting Variables .............................................................................215 5.2 Tasks ...........................................................................................................217 5.2.1 Defining New Tasks ............................................................................217 5.2.2 Understanding Task Execution ...........................................................220 5.2.3 Prepending, Appending, and Redefinition ...........................................225 5.2.4 Deleting a Task ...................................................................................227 5.3 Conditional Syntax (a.k.a. Overrides) ..........................................................228 5.3.1 Understanding the Overrides ..............................................................228 5.3.2 Machine and Distros Overriding .........................................................233 5.3.3 Overriding by Tasks ............................................................................237 5.3.4 File Overriding ....................................................................................238 Table of ConTenTs
📄 Page 8
viii 5.4 Including, Requiring, and Inheriting a File ...................................................243 5.4.1 The include and require Directives .....................................................244 5.4.2 The inherit Directive ...........................................................................244 5.4.3 The INHERIT Directive .........................................................................246 5.5 Summary.....................................................................................................247 Chapter 6: Recipes����������������������������������������������������������������������������249 6.1 Locating and Naming Conventions .............................................................249 6.2 Understanding Version Policies ...................................................................253 6.3 Recipe Structure .........................................................................................257 6.3.1 General Descriptions ..........................................................................259 6.3.2 Source Code Information ....................................................................265 6.3.3 Building Rules .....................................................................................278 6.3.4 Packaging Information .......................................................................282 6.4 The Building Tasks ......................................................................................292 6.4.1 The do_fetch Task ...............................................................................294 6.4.2 The do_unpack Task ...........................................................................296 6.4.3 The do_configure Task........................................................................297 6.4.4 The do_compile Task ..........................................................................300 6.4.5 The do_install Task .............................................................................301 6.5 Building Images ..........................................................................................308 6.5.1 The Core Image Recipe .......................................................................309 6.5.2 The Image Class .................................................................................314 6.5.3 Generating Initramfs ...........................................................................322 6.6 Best Practices .............................................................................................324 6.7 Summary.....................................................................................................326 Table of ConTenTs
📄 Page 9
ix Chapter 7: Generating and Managing Layers �����������������������������������327 7.1 A Typical Layout ..........................................................................................327 7.2 Creating a New Layer ..................................................................................330 7.3 Adding a Layer ............................................................................................336 7.4 Adding Custom Scripts ................................................................................340 7.4.1 Inspecting Variables ...........................................................................344 7.4.2 Inspecting Packages ..........................................................................348 7.4.3 Inspecting Images ..............................................................................352 7.4.4 Inspecting the Git Repositories ...........................................................356 7.5 Summary.....................................................................................................358 Chapter 8: Adding New Hardware ����������������������������������������������������359 8.1 Adding a Machine .......................................................................................359 8.1.1 By Including the Original machine.conf ..............................................360 8.1.2 By Cloning the Original machine.conf .................................................364 8.2 Customizing the Bootloader ........................................................................366 8.2.1 Understanding the U-Boot Configuration Variables ............................367 8.2.2 Customizing U-Boot by Hand ..............................................................369 8.2.3 Customizing U-Boot with devtool .......................................................385 8.3 Notes on the Prebootloaders .......................................................................396 8.4 Customizing the Kernel ...............................................................................401 8.4.1 Understanding the Linux Configuration Variables ...............................401 8.4.2 Customizing Linux by Hand ................................................................402 8.4.3 Customizing Linux with devtool ..........................................................416 8.5 Summary.....................................................................................................426 Table of ConTenTs
📄 Page 10
x Chapter 9: C Application Recipes �����������������������������������������������������427 9.1 User Space Programs .................................................................................428 9.2 Library Packages ........................................................................................444 9.3 Multi-packages ...........................................................................................455 9.4 External Dependencies ...............................................................................479 9.5 Kernel Modules ...........................................................................................495 9.6 Summary.....................................................................................................503 Chapter 10: Python Application Recipes ������������������������������������������505 10.1 Adding Python Applications (for Development) .........................................505 10.2 Using the setuptools3 Build System .........................................................507 10.3 Using the pypi Build System .....................................................................513 10.3.1 The Assisted Mode............................................................................514 10.3.2 The Manual Way ...............................................................................526 10.4 Summary...................................................................................................538 Chapter 11: Miscellaneous Recipes ��������������������������������������������������539 11.1 Adding System Services ...........................................................................539 11.1.1 Notes on Initd ...................................................................................540 11.1.2 A Systemd Simple Example ..............................................................545 11.2 Getting Newer (or Older) Releases ............................................................554 11.3 Editing (or Appending) Existing Recipes ...................................................564 11.3.1 Adding Custom Files .........................................................................564 11.3.2 Changing the Default Configuration .................................................571 11.3.3 Changing a Variable ..........................................................................574 11.4 Adding Custom Package Groups ...............................................................575 11.5 Adding Binary Packages ...........................................................................581 Table of ConTenTs
📄 Page 11
xi 11.6 Notes on Native Recipes ...........................................................................586 11.6.1 Native C Code ...................................................................................587 11.6.2 Native Python Code ..........................................................................592 11.7 Summary...................................................................................................600 Chapter 12: Image Recipes ���������������������������������������������������������������601 12.1 Custom Recipe Files .................................................................................601 12.2 Customizing by bbappend(ing) ..................................................................605 12.3 Cloning and Renaming ..............................................................................607 12.4 Customizing by Configuration Files ...........................................................610 12.5 Changing the System Configuration..........................................................613 12.5.1 Adding Users ....................................................................................613 12.5.2 Changing Root’s Settings .................................................................618 12.5.3 Setting a Custom Hostname .............................................................619 12.5.4 Setting the Default Network Configuration .......................................620 12.5.5 automount fstab ...............................................................................625 12.5.6 Getting Logs and tmp Files As Nonvolatile .......................................630 12.6 Adding an Initramfs ...................................................................................633 12.7 Summary...................................................................................................640 Chapter 13: Optimizations and Best Practices ���������������������������������641 13.1 Development and Production Releases ....................................................641 13.2 Fixing All Package Revision ......................................................................648 13.3 Downloading Everything ...........................................................................660 13.4 Creating a Custom Repo Manifest.............................................................661 13.5 Checking for Common Vulnerabilities and Exposures (CVEs) ....................677 13.6 Summary...................................................................................................687 Index �������������������������������������������������������������������������������������������������689 Table of ConTenTs
📄 Page 12
xiii About the Author Rodolfo Giometti is an engineer, IT specialist, embedded GNU/Linux expert, and Software Libre evangelist. He has over 20 years of experience with GNU/Linux Embedded on x86, ARM, MIPS, and PowerPC-based platforms, and he is the maintainer of the LinuxPPS projects (Linux’s Pulse Per Second subsystem). Rodolfo still actively contributes to the Linux source code, contributing several patches and new device drivers for industrial application devices.
📄 Page 13
xv About the Technical Reviewer Antonio Tringali a freelance electronic engineer, develops cutting-edge hardware and software solutions with a focus on cybersecurity.  
📄 Page 14
xvii Acknowledgments I would like to express my deepest gratitude to Giacomo Vianelli for his support and suggestions. Heartfelt thanks to my technical reviewer, Antonio Tringali, for his suggestions and critical reading of what is reported in this book. This book would not be the same without the intuition of James Robinson-Prior and the support of Gryffin Winkler and Shobana Srinivasan. Finally, to my family for their unwavering support throughout this journey. To my spouse Valentina and my children Romina and Raffaele, who supported me during the time of writing this book.
📄 Page 15
xix Introduction Embedded computers have become very complex in the last few years since they are called to solve plenty of complex problems that humans did by themselves before. This complexity has involved hardware and software, and embedded systems now need very complex OSes in order to work as expected. The Yocto OS is now the effective standard for the most part of the embedded systems around the world. This is due to its robustness, high configuration, high availability of software packages, and the ability to support several hardware platforms with common mechanisms so that developers may deploy their systems with minor effort even on different machines. This book shows how the Yocto build system (i.e., the Yocto Project’s machine to build binary images from sources) works and how developers may easily (and quickly) move from the demo Yocto distributions that silicon vendors relay for their development kits to their final product. It accompanies developers from the demo Yocto distribution to their final Yocto distribution by explaining how the build system works and by doing practical examples. What This Book Covers This book talks about the Yocto Project, but it is not yet another book talking about the Yocto Project. In fact, its main goal is not to explain how the Yocto Project works (even if something must be explained anyway, and this is done in the second part of this book), but it talks instead about how developers can alter an already functional Yocto distribution
📄 Page 16
xx (which has usually been developed for a development kit from a silicon vendor) to support their embedded system which is (typically) derived from those development kits! So, this book has a first part where I briefly introduce some common embedded terms and where I present the embedded kit I’m going to use in this book to effectively test my example code on real hardware (I know perfectly that I cannot cover all possible hardware configuration all my readers may work on; that’s why I have tried to write all examples in the most generic form I could, so that, even if you have a different hardware configuration, you may hopefully use these examples on your systems). In this first part, I also explain how to get Yocto sources and how to set up a possible host machine configuration to be able to recompile a Yocto image from scratch. Below is a brief introduction of each chapter related to this first part: • Chapter 1 – Setting Up the Building Environment starts by introducing some common terms of the embedded programming world, then it presents the development kit used in this book: the EDIMM 2.0 STARTER KIT by Engicam. And, after a brief introduction of the board, it sets up both serial and Ethernet communication channels in order to be able to supply commands and code on real hardware. Finally, it explains how to install a complete developing system on a GNU/Linux-based host system (on both real and emulated machines). • Chapter 2 – Installing the Sources shows how to download Yocto sources and how to set up a fully functional build environment. Then it shows how to build a Yocto image from scratch and how to install it on our embedded kit. In the end, some notes about how to fix up the network connection on the new image are provided with some notes about how to update the code. InTroduCTIon
📄 Page 17
xxi The second part follows, and it can be considered as the theoretical part of this book. In fact, in this part, I will explain some theory about how the Yocto build system works and how developers can use available tools to properly manage the sources to fit their needs. This is not a complete manual (there is already one very well-written and complete manual on the Internet at https://docs.yoctoproject.org/ref-manual/index. html, where the readers can find whatever about the theory is not covered here), but I present and explain such concepts that we are going to use in this book so that it can be used as a practical reference text. A brief introduction of each chapter of this theoretical part is as follows: • Chapter 3 – Yocto Project Basics introduces the Yocto Project’s basic information, which every Yocto developer should know in order to better understand how it works. To begin, I will explain what the Yocto Project is and its basic concepts. Next I will present the main Yocto components starting from its main configuration files and the variables they hold. • Chapter 4 – Yocto Tools introduces most used Yocto commands such as BitBake, recipetool, devtool, etc. All these commands are then used in the next chapters to create or manage recipes. • Chapter 5 – BitBake Internals shows how the Yocto Project’s main component, named BitBake, works, how it uses variables, and how it executes its tasks. BitBake has its syntax which has similarities to several other programming languages. But it also provides some unique features, and we need to understand how BitBake interprets these objects in order to be able to write effective recipes and/or manage the Yocto distribution. InTroduCTIon
📄 Page 18
xxii • Chapter 6 – Recipes shows how recipes can be written and how they work, for example, which variables and tasks we can put in them and how we can use them to create packages or root filesystem. In the end, the third part follows, and it can be considered as the practical part of this book. In fact, I’m going to show here how to effectively write or modify recipes or how to define a new layer or machine, and I’ll present some possible best practices and configurations that developers may use to improve their projects. A brief introduction of each chapter of this practical part is as follows: • Chapter 7 – Generating and Managing Layers explains how a new layer can be added to an existent Yocto build system. In this manner, developers may add their customizations and recipes within a private layer where they have a total control of the newly developed Yocto system. • Chapter 8 – Adding New Hardware shows how new machines can be derived from the already defined ones, in such a way to reduce the developing time needed to define new custom hardware. Techniques explained in this chapter will reduce the time to market of new hardware! • Chapter 9 – C Application Recipes focuses the attention on recipes for programs written in C (or C++). Several examples of user space and libraries are presented, along with a kernel space project. • Chapter 10 – Python Application Recipes explains how to generate recipes for Python-based projects by proposing two different ways to do so (via setuptools3 or via pypi). InTroduCTIon
📄 Page 19
xxiii • Chapter 11 – Miscellaneous Recipes covers various common problems in embedded computing which don’t fit into the previous two chapters, for example, how to get a newer program release, how to add a system service, or how to deploy native packages (i.e., for the host machine). • Chapter 12 – Image Recipes explains how to write recipes to generate root filesystem images, that is, how to group together several package recipes to have a running root filesystem for our embedded machines. • Chapter 13 – Optimizations and Best Practices reports some final suggestions about how to properly configure our Yocto build system to save all sources or (for example) about having the ability to build a development or production release easily, etc. What You Need for This Book The following are the prerequisites for efficient learning. Software Prerequisite Regarding the software, you should have some knowledge of a non- graphical text editor such as vi or nano. Even though the graphical interface can be used by directly connecting an LCD, a keyboard, and a mouse to embedded kits. In this book, we assume that you can do little modifications to text files by using a text editor only. The host computer, that is, the computer you will use to cross-compile the code and/or to manage your embedded systems, is assumed to run a GNU/Linux-based distribution. My host PC is running an Ubuntu 22.04, InTroduCTIon
📄 Page 20
xxiv but you can also use a newer Ubuntu Long-Term Support (LTS) or a Debian-based system too with little modifications. Alternatively, you may use another GNU/Linux distribution but with a little effort from you, mainly regarding the needed tools’ installation, library dependencies, and package management. Foreign systems such as Windows, macOS, or similar are not covered in this book. The knowledge of how a C/C++ compiler works and how to manage a Makefile is required. This book will also present some kernel programming techniques, but these must not be taken as a kernel programming course. You need a proper book for such a topic! However, each example is well documented, and you will find several suggested resources. As a final note, I suppose that you know how to connect a GNU/Linux- based board on the Internet to download a package or a generic file. Hardware Prerequisite In this book, all code is developed and tested on the EDIMM 2.0 STARTER KIT developed by Engicam, but you can use another embedded kit due to the fact that the code is portable. It should compile for different systems without any issue. However, some minor modifications may be required in order to properly move binary images on these systems and when deriving new machines from an existing one. Conventions In this book, you will find many text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning. InTroduCTIon
The above is a preview of the first 20 pages. Register to read the complete e-book.

💝 Support Author

0.00
Total Amount (¥)
0
Donation Count

Login to support the author

Login Now

Recommended for You

Loading recommended books...
Failed to load, please try again later
Back to List