bitbake版本hello world

本文介绍了一个简单的BitBake项目示例,展示了如何搭建编译环境、配置文件的作用及recipe的编写过程。通过一个打印“Hello, World!”的recipe,详细解析了BitBake的工作流程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

参考文章

文件列表

ethan@Vostro270:~/hello$ tree
.
├── classes
│   └── base.bbclass
├── conf
│   ├── bblayers.conf
│   └── bitbake.conf
├── mylayer
│   ├── conf
│   │   └── layer.conf
│   └── printhello.bb
└── readme.txt

4 directories, 6 files

编译环境

$ git clone git://git.openembedded.org/bitbake
$ export PATH=/home/ethan/bitbake/bin:$PATH

版本检查

ethan@Vostro270:~/bitbake$ bitbake --version
BitBake Build Tool Core version 1.37.0

编译流程

${TOPDIR}/conf

ethan@Vostro270:~/hello$ bitbake
ERROR: Unable to find conf/bblayers.conf or conf/bitbake.conf. BBAPTH is unset and/or not in a build directory?

以上输出应该注意到

  • bitbake认定工程目录为BBPATH或者当前目录
  • bitbake首先解释工程目录的conf/bblayers.conf 以及conf/bitbake.conf

conf/bblayers.conf

LAYERSERIES_CORENAMES = "rocko"

BBLAYERS ?= " \
    /home/ethan/hello/mylayer \
"

该文件是核心layer,指定顶层layer。该文件需要注意到

  • LAYERSERIES_CORENAMES指定核心层的版本昵称。其他layer指定兼容的核心layer。从而方便管控兼容性。后面mylayer层还会讲解。这里的昵称可以自定义。
  • BBLAYERS指定顶层layer。顶层layer可能会添加相应的子layer

conf/bitbake.conf

TMPDIR  = "${TOPDIR}/tmp"
CACHE   = "${TMPDIR}/cache"
STAMP   = "${TMPDIR}/stamps"
T       = "${TMPDIR}/work"
B       = "${TMPDIR}"

该文件是配置文件。目前只指定编译输出路径。

${TOPDIR}/classes/base.bbclass

bitbake使用class文件提供公共的代码和函数。base.bbclass作为基础class,它会被所有recipe隐式继承。由于本处只作示例作用。只有一个build的任务。

该文件内容如下

addtask build

${TOPDIR}/mylayer

mylayer是本示例的唯一layer。它包括一个conf和唯一一个recipe,printhello.bb。

${TOPDIR}/mylayer/conf/layer.conf

BBPATH .= ":${LAYERDIR}"

BBFILES += "${LAYERDIR}/*.bb"

BBFILE_COLLECTIONS += "mylayer"
BBFILE_PATTERN_mylayer := "^${LAYERDIR}/"
LAYERSERIES_COMPAT_mylayer = "rocko"

注意

  • 操作符.=代表不带空格附加。假设编译时指定BBPATH的值为/home/ethan/hello。则第一行的计算结果为/home/ethan/hello:/home/ethan/mylayer/conf/layer.conf
  • 操作符+=代表带空格附件。
  • LAYERSERIES_COMPAT_mylayer指定兼容的core层为”rocko”。如果不指定,最新版本的bitbake会报warning。

不指定兼容core的warning信息

WARNING: Layer mylayer should set LAYERSERIES_COMPAT_mylayer in its conf/layer.conf file to list the core layer names it is compatible with.

${TOPDIR}/mylayer/printhello.bb

本例唯一的recipe。它的目的仅仅是打印hello, world信息。

DESCRIPTION = "Prints Hello World"
PN = 'printhello'
PV = '1'

python do_build() {
    bb.plain("********************");
    bb.plain("*                  *");
    bb.plain("*  Hello, World!   *");
    bb.plain("*                  *");
    bb.plain("********************");
}
  • PN是package name的简写。
  • PV是package ersion的简写。

执行

$ export PATH=/home/ethan/bitbake/bin:$PATH
$ export BBPATH=/home/ethan/hello
$ bitbake printhello

输出信息

Parsing recipes: 100% |###################################################################################################################################################| Time: 0:00:00
Parsing of 1 .bb files complete (0 cached, 1 parsed). 1 targets, 0 skipped, 0 masked, 0 errors.
NOTE: Resolving any missing task queue dependencies
Initialising tasks: 100% |################################################################################################################################################| Time: 0:00:00
NOTE: Executing RunQueue Tasks
********************
*                  *
*  Hello, World!   *
*                  *
********************
NOTE: Tasks Summary: Attempted 1 tasks of which 0 didn't need to be rerun and all succeeded.
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值