参考文章
文件列表
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.