Yocto & Bitbake 速查

如果我有空的话,我会更新这个文档,我是说如果。

完整文档可以在Yocto 文档网站找到。 参考自yoctoproject-cheatsheet

Cli 命令

需要先通过source setup-environment设置Bitbake环境

命令描述
bitbake 编译指定的 image
bitbake -c 执行指定的 task。 可选的 task 有: fetch, unpack, patch, configure, compile, install, package, clean, cleansstate, rebuild, reconfigure, reinstall等。
bitbake -c cleanall 清理指定的 recipe. 包括工作目录和 sstate cache
bitbake -c devshell 进入指定 recipe 的 shell 环境
bitbake -c listtasks 列出指定 recipe 的所有 task
bitbake -c showappends 显示指定 recipe 的所有 append 文件
bitbake -e 显示指定 recipe 的所有变量
bitbake -s列出所有可用的 recipe
bitbake -S 显示指定 recipe 的依赖关系
bitbake –graphviz –ui=depexp生成的包依赖关系图
bitbake-layers show-layers显示所有的 layer
bitbake-layers show-appends显示所有的 append 文件
bitbake-layers show-recipes显示所有的 recipe
bitbake-layers show-recipes “gdb*”搜索 recipe
bitbake-layers show-depends显示所有的依赖关系

变量语法和操作

参考自Bitbake User Manual

可以随时使用 bitbake -e 查看编译时的变量。

语法描述
VARIABLE = "value"设置变量
VARIABLE = " value "如果变量值中有空格,那么空格会被保留
VARIABLE = ""设置变量为空
VARIABLE = " "设置变量为一个空格
VARIABLE = '"'通过单引号设置含有双引号的变量
VARIABLE = "${OTHER_VARIABLE}"引用其他变量, 变量在真正使用时才会被展开
VARIABLE := "${OTHER_VARIABLE}"设置变量,立即展开
VARIABLE ?= "value"设置默认值,如果变量已经设置,那么不会覆盖
VARIABLE ??= "value"设置默认值,见弱默认值
VARIABLE += "value"追加变量值(带空格)
VARIABLE =+ "value"在变量值前面追加(带空格)
VARIABLE .= "value"追加变量值(无空格)
VARIABLE =. "value"在变量值后面追加(无空格)

TODO

local.conf 配置

这些配置可以加入到 local.conf 或者bblayers.conf文件中,也根据需求加入其他 Machine 配置中。

配置作用
RM_WORK_EXCLUDE += "recipe_name"编译后不删除指定的 recipe 的工作目录,用于调试
INHERIT += "rm_work"编译后删除工作目录

FAQ

NOTE: Reconnecting to bitbake server

删除 bitbake.lock

1
rm -rf <build-dir>/bitbake.lock

ERROR: nothing provides A needed by B

  • 情况一: recipe A 不存在,没有被添加到 packagegroup 或者 dependcy 中
  • 情况二: recipe A 编出来是空包,没有生成任何文件。需要在 A 的 recipe 中添加 ALLOW_EMPTY_${PN} = "1" 来解决

经常在编译动态库时会遇到这个问题,因为动态库的 recipe 生成的是一个空包。

Yocto / OE : recipe with CMake install a shared library .so - Stack Overflow do_rootfs missing package (ipk) or not found in base feeds (rpm) (yoctoproject.org)

只有 *.so.*(包含版本号的动态库)会被打包进 FILES_${PN},而软链接 *.so 会被打包进 -devpackage

如何使用 devtool 新增patch

bitbake - What is best practice to do small changes in source code in Yocto - Stack Overflow

1
2
3
4
5
6
7
8
9
devtool modify -x <recipe> <path-to-unpack>
devtool build <recipe>

# 修改位于<path-to-unpack>的源码
git add
git commit

devtool update-recipe <recipe>
devtool reset <recipe>
使用 Hugo 构建
主题 StackJimmy 设计