Yocto - 使用Yocto开发嵌入式Linux系统_08 掌握软件包相关功能

Assimilating Packaging Support
本章介绍了解 Poky 和 BitBake 打包相关方面的关键概念。我们将了解支持的二进制包格式、共享状态缓存、包版本控制组件、如何设置和使用二进制包馈以支持我们的开发流程等。
This chapter presents the key concepts for understanding the aspects of Poky and BitBake related to packaging. We will learn about the supported binary package formats, shared state cache, package versioning components, how to set up and use binary package feeds to support our development process, and more.
1, Using supported package formats
从 Yocto 项目的角度来看,一个配方可以生成一个或多个输出包。软件包将一组文件和元数据封装起来,以便将来使用。它们可以安装到一个或多个镜像中,也可以部署以供日后使用。
From a Yocto Project perspective, a recipe may generate one or more output packages. A package wraps a set of files and metadata in a way that makes them available in the future. They can be installed into one or more images or deployed for later use.
软件包对 Poky 至关重要,因为它们能让构建系统生成不同类型的工件,如映像和工具链。
Packages are critical to Poky, as they enable the build system to produce diverse types of artifacts, such as images and toolchains.
List of supported package formats
目前,BitBake 支持四种不同的软件包格式:
* Red Hat Package Manager (RPM): 最初名为 Red Hat 软件包管理器,但自从被其他几个 Linux 发行版采用后,现在被称为 RPM 软件包格式,这是一种在 SuSE、OpenSuSE、Red Hat、Fedora 和 CentOS 等 Linux 发行版中使用的流行格式。
* Debian 软件包管理器(DEB): 这是在 Debian 和其他几个基于 Debian 的发行版中广泛使用的格式,其中 Ubuntu Linux 和 Linux Mint 最广为人知。
* Itsy 软件包管理系统(IPK): 这是一种为嵌入式设备设计的轻量级软件包管理系统,与 Debian 的软件包格式相似。支持 IPK 格式的 opkg 软件包管理器在多个发行版中使用,如 OpenEmbedded Core、OpenWRT 和 Poky。
* Tar: 源于磁带存档,是一种广泛使用的 tarball 文件类型,用于将多个文件合并为一个文件。
Currently, BitBake supports four different package formats:
* Red Hat Package Manager (RPM): Originally named Red Hat Package Manager but now known as the RPM package format since its adoption by several other Linux distributions, this is a popular format in use in Linux distributions such as SuSE, OpenSuSE, Red Hat, Fedora, and CentOS.
* Debian Package Manager (DEB): This is a widespread format used in Debian and several other Debian-based distributions – Ubuntu Linux and Linux Mint are the most widely known.
* Itsy Package Management System (IPK): This was a lightweight package management system designed for embedded devices that resembled Debian’s package format. The opkg package manager, which supports the IPK format, is used in several distributions such as OpenEmbedded Core, OpenWRT, and Poky.
* Tar: This is derived from the Tape Archive, a widely used tarball file type used to group several files into just a single file.
Choosing a package format
对格式的支持是通过一组类(即 package_rpm、package_deb 和 package_ipk)来实现的。我们可以使用 PACKAGE_CLASSES 变量选择一种或多种格式,如下例所示:
The support for formats is provided using a set of classes (i.e., package_rpm, package_deb, and package_ipk). We can select one or more formats using the PACKAGE_CLASSES variable, as shown in the following example:
[ Figure 7.1 – The variable used to configure which package format to use ] 
你可以在 build/conf/local.conf 文件中配置一种或多种软件包格式。
You can configure one or more package formats – for example, in the build/conf/local.conf file.
Tip
PACKAGE_CLASSES 中的第一种软件包格式是用于生成镜像的格式。
The first package format in PACKAGE_CLASSES is the one used for image generation.
Poky 默认使用 RPM 软件包格式,它使用 DNF 软件包管理器。不过,格式选择取决于多个因素,如特定于软件包格式的功 能、内存和资源使用情况。OpenEmbedded Core 默认使用 IPK 和 opkg 作为软件包管理器,因为它占用的内存和资源更少。
Poky defaults to the RPM package format, which uses the DNF package manager. However, the format choice depends on several factors, such as package format-specific features, memory, and resource usage. OpenEmbedded Core defaults to the IPK and opkg as the package manager, as it offers a smaller memory and resource usage footprint.
另一方面,熟悉基于 Debian 系统的用户可能更倾向于为其产品使用 APT 和 DEB 软件包格式。
On the other hand, users familiar with Debian-based systems may prefer to use the APT and DEB package formats for their products.
2, Running code during package installation
软件包可以使用脚本作为安装和删除程序的一部分。包含的脚本定义如下:
* preinst: 在解压缩软件包之前执行。如果软件包有服务,则必须在安装或升级时停止服务。
* postinst: 解压缩后,通常会完成软件包所需的配置。许多 postinst 脚本会在安装或升级后执行启动或重启服务所需的命令。
* prerm: 在删除与软件包相关的文件之前,它通常会停止与软件包相关的守护进程。
* postrm: 通常会修改软件包创建的链接或其他文件。
Packages can use scripts as part of their installation and removal process. The included scripts are defined as follows:
* preinst: This executes before unpacking the package. If the package has services, it must stop them for installation or upgrade.
* postinst: After unpacking, this typically completes any required configuration of the package. Many postinst scripts execute any command necessary to start or restart a service after installation or upgrade.
* prerm: It usually stops any daemon associated with a package before removing files associated with the package.
* postrm: This commonly modifies links or other files created by the package.
preinst 和 prerm 脚本针对复杂的用例,例如更新软件包时的数据迁移。在 Yocto 项目中,postinst 和 postrm 还负责停止和启动 systemd 或 sysvinit 服务。当我们使用 systemd 和 update-rc.d 类时,会提供一个默认脚本。可以对其进行定制,以包括任何特殊情况。
The preinst and prerm scripts target complex use cases, such as data migration when updating packages. In the Yocto Project case, postinst and postrm are also responsible for stopping and starting the systemd or sysvinit services. A default script is provided when we use the systemd and update-rc.d classes. It can be customized to include any particular case.
软件包安装后 (postinst) 脚本在创建根文件系统时运行。如果脚本返回成功值,则软件包被标记为已安装。要为软件包添加 postinst 脚本,我们可以使用下面的方法:
The post-package installation ( postinst) scripts are run during the root filesystem creation. The package is marked as installed if the script returns a success value. To add a postinst script for a package, we can use the following:
[ Figure 7.2 – An example of the pkg_postinst script  ]
有时,我们需要确保 postinst 在目标设备内部运行。这可以使用 postinst_ontarget 变体来实现,例如下面的命令:
Sometimes, we need to ensure that postinst runs inside the target device itself. This can be done using the postinst_ontarget variant, such as the following:
[ Figure 7.3 – An example of the pkg_postinst_ontarget script ]
Tip
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

夜流冰

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

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

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

打赏作者

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

抵扣说明:

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

余额充值