Yocto - 使用Yocto开发嵌入式Linux系统_13 创建定制层

Creating Custom Layers
除了使用社区或供应商提供的现有图层外,我们还将在本章中学习如何为我们的产品创建图层。此外,我们还将了解如何创建机器定义和分布,并从中获益,从而更好地组织我们的源代码。
In addition to using existing layers from the community or vendors, we will learn how to create layers for our products in this chapter. Additionally, we will discover how to create a machine definition and distribution and profit from them to organize our source code better.
1,Making a new layer
在创建我们的图层之前,最好先在以下网站查看是否已经有类似的图层: http://layers.openembedded.org
Before creating our layer, it’s always a good idea to check whether a similar one is already available at the following website: http://layers.openembedded.org .
如果我们仍在寻找适合我们需要的图层,下一步就是创建目录。通常,图层名称以 meta- 开头,但这并不是技术要求。
If we are still looking for a layer suitable for our needs, the next step is to create the directory. Usually, the layer name starts with meta-, but this is not a technical restriction.
<layer>/conf/layer.conf 文件是每个层都需要的层配置文件。可以使用 Poky 中提供的 BitBake 中名为 bitbake-layers 的工具创建新层,如以下命令所示:
The <layer>/conf/layer.conf file is the layer configuration file required for every layer. The new layer can be created with a tool called bitbake-layers from BitBake, provided in Poky, as shown in the following command:
[ Figure 12.1 – Creating a new layer using bitbake-layers ]
创建图层后,我们需要使用以下命令将其包含在 build/conf/bblayers.conf 文件中:
After creating the layer, we need to include it in the build/conf/bblayers.conf file using the following command:
[ Figure 12.2 – Adding meta-newlayer to build/conf/bblayers.conf ]
Tip
默认情况下,bitbake-layers 工具生成的图层优先级为 6。我们仍然可以使用参数自定义优先级。
The bitbake-layers tool, by default, generates the layer with layer priority 6. We can still customize the priority using parameters.
最后一条命令生成图层,如下图所示:
The last command generates the layer, as shown in the following figure:
[ Figure 12.3 – The meta-newlayer layout when created ]
meta-newlayer 的默认图层配置文件是使图层正常工作的最低配置。不过,也可以对其进行定制,以包含未来所需的配置。
The default layer configuration file for meta-newlayer is the minimal configuration to get the layer working. However, it can be customized to include configurations required in the future.
下图显示了我们刚刚创建的meta-newlayer层的默认 conf/layer.conf 内容:
The following figure shows the content of default conf/layer.conf for the meta-newlayer layer we just created:
[ Figure 12.4 – The meta-newlayer/conf/layer.conf minimal configuration ]
一些可能需要添加或更改的常用变量是 LAYERVERSION 和 LAYERDEPENDS。如果我们的图层需要其他图层才能工作,这两个变量就非常有用。这两个变量的名称必须以图层名称为后缀,如下所示:
Some commonly used variables that may need to be added or changed are LAYERVERSION and LAYERDEPENDS. Those are useful if our layer requires other layers to work. Both variables’ names must be suffixed with the layer’s name, as follows:
* LAYERVERSION:这是一个可选变量,用一个数字指定图层的版本。该变量在 LAYERDEPENDS 变量中使用,以取决于特定的层版本--例如,LAYERVERSION_meta-newlayer = “1”。
* LAYERVERSION: This is an optional variable that specifies the version of the layer in a single number. This variable is used within the LAYERDEPENDS variable to depend on a specific layer version – for example, LAYERVERSION_meta-newlayer = "1".
* LAYERDEPENDS: 列出配方所依赖的层,用空格分隔,例如,我们用 LAYERDEPENDS_meta-newlayer += “meta-otherlayer:2” 来添加对 meta-otherlayer 第 2 版的依赖。
* LAYERDEPENDS: This lists the layers that the recipes depend upon, separated by spaces – for example, we add the dependency for version 2 of meta-otherlayer with LAYERDEPENDS_meta-newlayer += "meta-otherlayer:2".
如果依赖关系无法满足或版本号不匹配,则会发生错误。现在,层结构的基础已经创建。在接下来的章节中,我们将学习如何对其进行扩展。
An error is incurred if a dependency cannot be satisfied or the version numbers do not match. The base of the layer structure is now created. In the following sections, we will learn how to extend it.
2,Adding metadata to the layer
图层元数据可实现两个目标--添加新软件,或特征化和修改现有元数据。
Layer metadata can serve two goals – add new software, or feature and modify existing metadata.
我们可以在一个新层中包含多个元数据文件,如配方、映像和 bbappend 文件。在 meta-yocto-bsp 和 meta-yocto 上有几个 bbappend 文件的示例。我们将在第 13 章 “自定义现有配方 ”中探讨它们的一些常用用法。
We can include several metadata files on a new layer, such as recipes, images, and bbappend files. There are several examples of bbappend files on meta-yocto-bsp and meta-yocto. We will explore some of their common uses in Chapter 13, Customizing Existing Recipes.
在接下来的章节中,我们将对图层元数据进行一些常见的修改。
In the next sections, we will go through some common modifications to layer metadata.
Creating an image
从本质上讲,映像文件是一组按目的分组并以受控方式配置的软件包。我们可以从头开始创建镜像文件,也可以通过重复使用现有镜像文件并添加必要的额外软件包来创建镜像文件。
Image files are, in essence, a set of packages grouped for a purpose and configured in a controlled way. We can create an image from scratch or create one by reusing an existing one and adding the extra necessary packages.
在可能的情况下,我们应该重复使用现有的图像,这样可以使代码维护更易于管理,并突出功能差异。例如,我们可能想在 core-image-full-cmdline 图像文件中加入一个应用程序并移除图像功能。在这种情况下,我们可以在 recipes-mine/images/my-image-full-cmdline.bb 文件中创建一个映像,使用下面几行代码:
We should reuse an existing image when possible, making code maintenance more manageable and highlighting the functional differences. For example, we may want to include an application and remove an image feature from the core-image-full-cmdline image file. In that case, we can create an image in the recipes-mine/images/my-image-full-cmdline.bb file with the following lines of code:
[ Figure 12.5 – The content of my-image-full-cmdline.bb ]
core-image 类提供的映像功能为常用功能提供了有用的构建模块,从头开始创建图像时应使用该类。例如,我们可以在 recipes-mine/images/my-image-strace.bb 文件中创建一个映像,该文件由以下几行代码组成:
The core-image class provides image features that offer helpful building blocks of commonly used functionality and should be used when creating an image from scratch. For example, we can create an image in the recipes-mine/images/my-image-strace.bb file consisting of the following lines of code:
[ Figure 12.6 – The content of my-image-strace.bb ]
Tip
列表
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

夜流冰

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值