Yocto - 使用Yocto开发嵌入式Linux系统_05 认识Bitbake工具

时间:2024-10-02 11:14:18
Meeting the BitBake Tool
通过本章,我们将开始学习 Yocto 项目引擎如何在幕后工作的旅程。正如每一段旅程一样,沟通是至关重要的,因此我们需要理解 Yocto 项目工具所使用的语言,并学习如何充分利用这些工具来实现我们的目标。
With this chapter, we will now begin our journey of learning how the Yocto Project’s engine works behind the scenes. As is the case with every journey, communication is critical, so we need to understand the language used by the Yocto Project’s tools and learn how to get the best out of these tools to accomplish our goals.
前面几章向我们介绍了创建和仿真镜像文件的标准 Yocto Project 工作流程。在本章中,我们将探讨元数据的概念,以及 BitBake 如何读取这些元数据来收集内部数据。
The preceding chapters introduced us to the standard Yocto Project workflow for creating and emulating images. Now, in this chapter, we will explore the concept of metadata and how BitBake reads this metadata to make its internal data collections.
1,Understanding the BitBake tool
BitBake 任务调度程序是从 Gentoo 发行版中使用的软件包管理系统 Portage 分支而来的。然而,由于使用情况不同,这两个项目出现了很大的分歧。Yocto 项目和 OpenEmbedded 项目是 BitBake 的密集用户。BitBake 仍是一个独立的项目,有自己的开发周期和邮件列表 ( bitbake-devel@lists.openembedded.org)。
The BitBake task scheduler started as a fork from Portage, the package management system used in the Gentoo distribution. However, the two projects diverged significantly due to different use cases. The Yocto Project and the OpenEmbedded Project are intensive users of BitBake. It remains a separate and independent project with its own development cycle and mailing list (bitbake-devel@lists.openembedded.org).
BitBake 是一个类似于 GNU Make 的工具。正如第 1 章 “认识 Yocto 项目 ”中所述,BitBake 是一个任务执行器和调度器,可以解析 Python 和 Shell Script 混合代码。
BitBake is a tool similar to GNU Make. As discussed in Chapter 1, Meeting the Yocto Project, BitBake is a task executor and scheduler that parses Python and Shell Script mixed code.
因此,BitBake 负责并行运行尽可能多的任务,同时确保它们在运行时尊重各自的依赖关系。
Therefore, BitBake is responsible for running as many tasks as possible in parallel while ensuring they are run respecting their dependencies.
2,BitBake metadata collections
对于 BitBake 来说,所有元数据都属于某个元数据集合。而且,元数据集合有一个唯一的名称,Yocto 项目对这些集合使用的通用术语是 “层”。
For BitBake, there is no metadata outside a metadata collection. Instead, a metadata collection has a unique name, and the common term the Yocto Project uses for those collections is Layer.
在第 1 章 “认识 Yocto 项目 ”中,我们介绍了以下几个层:
Chapter 1, Meeting the Yocto Project, explains that we have the following layers:
* OpenEmbedded Core: This is inside the meta directory
* Poky distribution: This is inside the meta-poky directory
* Yocto Project reference BSP: This is inside the meta-yocto-bsp directory
前面的列表描述了层的实际示例。每个层都包含一个名为 conf/layer.conf 的文件。该文件定义了几个层属性,如元数据集合的名称和优先级。下图显示了 meta-poky 图层的 conf/layer.conf 文件:
The preceding list describes real examples of layers. Every layer contains a file called conf/layer.conf. This file defines several layer properties, such as the collection name and priority. The following figure shows the conf/layer.conf file for the meta-poky layer:
[ Figure 4.1 – The conf/layer.conf file for the meta-poky layer ]
前面的示例相对简单,但可以作为我们说明 conf/layer.conf 文件原理的基础。
The preceding example is relatively simple but serves as a base for us to illustrate the conf/layer.conf file principles.
在第 8 行 BBFILE_COLLECTIONS 中,我们告诉 BitBake 创建一个名为 yocto 的新元数据集合。接下来,在第 9 行 BBFILE_PATTERN_yocto,我们定义了匹配所有以 LAYERDIR 变量开头的路径的规则,以识别属于 yocto 集合的元数据。最后,在第 10 行,BBFILE_PRIORITY_yocto 确定了 yocto 元数据集相对于其他元数据集的优先级(数字越大,优先级越高)。
In line 8, BBFILE_COLLECTIONS, we tell BitBake to create a new metadata collection called yocto. Next, in line 9, BBFILE_PATTERN_yocto, we define the rule to match all paths starting with the LAYERDIR variable to identify the metadata belonging to the yocto collection. Finally, in line 10, BBFILE_PRIORITY_yocto establishes the priority (the higher the number, the higher the priority) of the yocto collection against the other metadata collections.
层与层之间的依赖关系至关重要,因为它可以确保所有需要的元数据都可以使用。以第 18 行为例,在conf/layer.conf 文件中为 LAYERDEPENDS_yocto 添加了一个和 core的依赖关系,core表示OpenEmbedded Core层。
The dependency relation between the layers is vital as it ensures that all required metadata is available for use. An example is in line 18 as LAYERDEPENDS_yocto, from the conf/layer.conf file, adds a dependency to the core, provided by the OpenEmbedded Core layer.
图 4.2 显示了 Poky 使用 bitbake-layers 命令创建的图层,如下所示:
Figure 4.2 shows Poky’s layers using the bitbake-layers command, as follows:
[ Figure 4.2 – Results of bitbake-layers show-layers for Poky ]
3, Metadata types
我们可以将 BitBake 使用的元数据分为三大类。它们如下:
There are three major areas where we can classify the metadata used by BitBake. They are as follows:
* Configuration (the .conf files)
* Classes (the .bbclass files)
* Recipes (the .bb and .bbappend files)
配置文件定义全局内容,以提供信息,并配置配方的工作方式。配置文件的一个典型例子是机器文件,其中包含描述硬件的设置列表。
The configuration files define the global content to provide information and configure how the recipes work. One typical example of a configuration file is the machine file, which has a list of settings that describes the hardware.
整个系统都使用这些类,配方可以根据自己的需要继承这些类,或者 默认情况下就继承。它们定义了常用的系统行为,并提供了基本方法。例如,kernel.bbclass 抽象了与构建和打包 Linux 内核相关的任务,不受版本或供应商变更的影响。
The whole system uses the classes that recipes can inherit according to their needs or by default. They define the commonly used system’s behavior and provide the base methods. For example, kernel.bbclass abstracts tasks related to building and packaging the Linux kernel independently of version or vendor changes.
注释
配方和类混合了 Python 和 Shell 脚本代码。
Note
The recipes and classes mix Python and Shell Script code.
类和配方描述要运行的任务,并提供所需信息,以便 BitBake 生成所需的任务列表及其依赖关系。继承机制允许一个配方继承一个或多个类,以促进代码重用、提高准确性并简化维护。Linux 内核配方的一个例子是 linux-yocto_5.15.bb,它继承了一组类,包括 kernel.bbclass。
The classes and recipes describe the tasks to be run and provide the information needed to allow BitBake to generate the required task list and its dependencies. The inheritance mechanism permits a recipe to inherit one or more classes to promote code reuse, improve accuracy, and make maintenance easier. A Linux kernel recipe example is linux-yocto_5.15.bb, which inherits a set of classes, including kernel.bbclass.
第 5 章 “掌握 BitBake 工具 ”介绍了 BitBake 所有元数据类型(.conf、.bb 和 .bbclass)中最常用的方面,第 8 章 “深入了解 BitBake 元数据 ”详细介绍了元数据语法和句法。
BitBake’s most commonly used aspects across all types of metadata (.conf, .bb, and .bbclass) are covered in Chapter 5, Grasping the BitBake Tool, while the metadata grammar and syntax are detailed in Chapter 8, Diving into BitBake Metadata.
考虑到图 4.1,我们需要注意另外两个变量--BBPATH 和 BBFILES。
Taking Figure 4.1 into consideration, we need to pay attention to two other variables – BBPATH and BBFILES.
第 2 行的 BBPATH 类似于 PATH,但在元数据文件的搜索列表中添加了一个目录;第 5 行的 BBFILES 变量列出了用于索引配方文件集合的模式。
BBPATH, on line 2, is analogous to PATH but adds a directory to the search list for metadata files; the BBFILES variable, on line 5, lists the pattern used to index the collection recipe files.
4, Summary
在本章中,我们了解了元数据、元数据集合概念以及 conf/layer.conf 的重要性,这些都是理解 Yocto 项目的基础。在下一章中,我们将学习元数据知识,了解配方如何相互依赖,以及 BitBake 如何处理依赖关系。此外,我们还将更好地了解 BitBake 所管理的任务,下载所有需要的源代码,构建和生成软件包,并了解这些软件包如何与生成的映像相匹配。
In this chapter, we learned about metadata, metadata collection concepts, and the importance of conf/layer.conf, which are the base for the understanding of the Yocto Project. In the next chapter, we will examine metadata knowledge, understand how recipes depend on each other, and how BitBake deals with dependencies. Additionally, we will also get a better view of the tasks managed by BitBake, download all the required source code, build and generate packages, and see how these packages fit into generated images.