【OpenBMC 系列】3.bitbake介绍

BitBake 最初是 OpenEmbedded 项目的一部分。它的灵感来自 Gentoo Linux 发行版使用的 Portage 包管理系统。2004 年,OpenEmbedded 项目被拆分为两个不同的部分:

BitBake,一个通用的任务执行器
OpenEmbedded,BitBake 使用的元数据集

今天,BitBake 是基于 OpenEmbedded 的项目(例如 Yocto 项目)的主要构建工具。
用户手册:https://docs.yoctoproject.org/bitbake/index.html

1.bitbake简介

BitBake 是一种软件组建自动化工具程式。功能类似于GNU Make,是针对于嵌入式Linux交叉编译器环境所设计研发。它源自于Gentoo Linux的软件包管理系统,是用 Python 写的一个程序。它是 OpenEmbedded 构建系统时使用的生产工具,比如Yocto 、WindRiver Linux 等嵌入式系统都是在使用它进行编译。它是一个多任务引擎,可以并行执行 shell 和 Python 任务,每个任务单元根据预定义的元数据来管理源码、配置、编译、打包,并最终将每个任务生成的文件集合成为系统镜像。

2. bitbake配置文件简介

Recipe ——Recipe 文件是最基本的元数据文件,每个任务单元对应一个 Recipe 文件,后缀是 .bb ,这种文件为 BitBake 提供的信息包括软件包的基本信息(作者、版本、License等)、依赖关系、源码的位置和获取方法、补丁、配置和编译方法、如何打包和安装。
ifupdown.bb


SRC_URI = "git://salsa.debian.org/debian/ifupdown.git;protocol=https \
           file://defn2-c-man-don-t-rely-on-dpkg-architecture-to-set-a.patch \
           file://99_network \
           file://0001-Define-FNM_EXTMATCH-for-musl.patch \
           file://0001-Makefile-do-not-use-dpkg-for-determining-OS-type.patch \
           file://run-ptest \
           file://0001-ifupdown-skip-wrong-test-case.patch \
           ${@bb.utils.contains('DISTRO_FEATURES', 'ptest', 'file://tweak-ptest-script.patch', '', d)} \
           "
SRCREV = "c73226073e2b13970ca613b20a13b9c0253bf9da"

S = "${WORKDIR}/git"


inherit ptest update-alternatives

do_compile () {
	chmod a+rx *.pl *.sh
	oe_runmake 'CC=${CC}' "CFLAGS=${CFLAGS} -Wall -W -D'IFUPDOWN_VERSION=\"${PV}\"'"
}

do_install () {
	install -d ${D}${mandir}/man8 \
		  ${D}${mandir}/man5 \
		  ${D}${base_sbindir}

	# If volatiles are used, then we'll also need /run/network there too.
	install -d ${D}/etc/default/volatiles
	install -m 0644 ${WORKDIR}/99_network ${D}/etc/default/volatiles

	install -m 0755 ifup ${D}${base_sbindir}/
	ln ${D}${base_sbindir}/ifup ${D}${base_sbindir}/ifdown
	install -m 0644 ifup.8 ${D}${mandir}/man8
	install -m 0644 interfaces.5 ${D}${mandir}/man5
	cd ${D}${mandir}/man8 && ln -s ifup.8 ifdown.8
}

do_install_ptest () {
    install -d ${D}${PTEST_PATH}/tests
    cp -r ${S}/tests/testbuild-linux ${D}${PTEST_PATH}/tests/
    cp -r ${S}/tests/linux ${D}${PTEST_PATH}/tests/
}

从上面可以看到bb后缀的文件,描述了软件包的信息,编译和安装方法。
Configuration ——Configuration 文件的后缀是 .conf ,它会在很多地方出现,定义了多种变量,包括硬件架构选项、编译器选项、通用配置选项、用户配置选项。主 Configuration 文件是 bitbake.conf ,以 Yocto 为例,位于 ./poky/meta/conf/bitbake.conf ,其他都在源码树的 conf 目录下。
layer.conf

# We have a conf and classes directory, add to BBPATH
BBPATH .= ":${LAYERDIR}"
# We have recipes-* directories, add to BBFILES
BBFILES += "${LAYERDIR}/recipes-*/*/*.bb"

BBFILE_COLLECTIONS += "core"
BBFILE_PATTERN_core = "^${LAYERDIR}/"
BBFILE_PRIORITY_core = "5"

LAYERSERIES_CORENAMES = "honister"

# This should only be incremented on significant changes that will
# cause compatibility issues with other layers
LAYERVERSION_core = "12"
LAYERSERIES_COMPAT_core = "honister"

BBLAYERS_LAYERINDEX_NAME_core = "openembedded-core"

# Set a variable to get to the top of the metadata location
COREBASE = '${@os.path.normpath("${LAYERDIR}/../")}'

# opkg-utils is for update-alternatives :(
SIGGEN_EXCLUDERECIPES_ABISAFE += " \
  sysvinit-inittab \

可以看出conf后缀的文件是由配置和变量组织起来的配置文件。

Classes ——Class 文件的后缀是 .bbclass ,它的内容是元数据文件之间的共享信息。BitBake 源码树都源自一个叫做 base.bbclass 的文件,在 Yocto 中位于 ./poky/meta/classes/base.bbclass ,它会被所有的 recipe 和 class 文件自动包含。它包含了标准任务的基本定义,例如获取、解压、配置、编译、安装、打包,有些定义只是框架,内容是空的。

devshell.bbclass

# devshell and fakeroot/pseudo need careful handling since only the final
# command should run under fakeroot emulation, any X connection should
# be done as the normal user. We therfore carefully construct the envionment
# manually
python () {
    if d.getVarFlag("do_devshell", "fakeroot"):
       # We need to signal our code that we want fakeroot however we
       # can't manipulate the environment and variables here yet (see YOCTO #4795)
       d.setVarFlag("do_devshell", "manualfakeroot", "1")
       d.delVarFlag("do_devshell", "fakeroot")
} 

def devpyshell(d):

    import code
    import select
    import signal
    import termios

    m, s = os.openpty()
    sname = os.ttyname(s)

    def noechoicanon(fd):
        old = termios.tcgetattr(fd)

从上面可以看出bbclass后缀的文件实际是python脚本组织起来的对数据进行操作的部分。
Layers ——Layer 被用来分类不同的任务单元。某些任务单元有共同的特性,可以放在一个 Layer 下,方便模块化组织元数据,也方便日后修改。例如要定制一套支持特定硬件的系统,可以把与低层相关的单元放在一个 layer 中,这叫做 Board Support Package(BSP) Layer 。

Append ——Append 文件的后缀是 .bbappend ,用于扩展或者覆盖 recipe 文件的信息。BitBake 希望每一个 append 文件都有一个相对应的 recipe 文件,两个文件使用同样的文件名,只是后缀不同,例如 formfactor_0.0.bb 和 formfactor_0.0.bbappend 。命名 append 文件时,可以用百分号(%)来通配 recipe 文件名。例如,一个名为 busybox_1.21.%.bbappend 的 apend 文件可以对应任何名为 busybox_1.21.x.bb 的 recipe 文件进行扩展和覆盖,文件名中的 x 可以为任何字符串,比如 busybox_1.21.1.bb、busybox_1.21.2.bb … 通常用百分号来通配版本号

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

AiFool

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

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

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

打赏作者

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

抵扣说明:

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

余额充值