因为工作中很多时候需要基于Yocto来改代码、编译SDK,很久之前就想彻底搞明白Yocto的理念、整个构建的细节。
现在开坑,基于Yocto官方文档,以实践记录+网络资料整理的方式,希望加深对Yocto的理解。
操作基于2020年4月份发行的3.1版本(Dunfell)。 Yocto的版本release记录:https://wiki.yoctoproject.org/wiki/Releases
系统要求:参考Yocto官方的参考文档https://www.yoctoproject.org/docs/current/brief-yoctoprojectqs/brief-yoctoprojectqs.html PC最好是Linux发行版,要求如下:
硬盘:至少50GB
发行版:最近的Fedora, openSUSE, CentOS, Debian, or Ubuntu
常用工具:
-
Git 1.8.3.1 or greater
-
tar 1.28 or greater
-
Python 3.5.0 or greater.
-
gcc 5.0 or greater.
需要安装如下软件包(我用的是Ubuntu 18.04, 以Ubuntu18.04为例。其他发行版请参考上面的链接):
$ sudo apt-get install gawk wget git-core diffstat unzip texinfo gcc-multilib \
build-essential chrpath socat cpio python python3 python3-pip python3-pexpect \
xz-utils debianutils iputils-ping libsdl1.2-dev xterm
获取Poky:
$ git clone git://git.yoctoproject.org/poky
Cloning into 'poky'...
remote: Counting objects: 432160, done.
remote: Compressing objects: 100% (102056/102056), done.
remote: Total 432160 (delta 323116), reused 432037 (delta 323000)
Receiving objects: 100% (432160/432160), 153.81 MiB | 8.54 MiB/s, done.
Resolving deltas: 100% (323116/323116), done.
Checking connectivity... done.
下载完成后会得到一个Poky文件夹。从这个文件夹里可以看到Git commit history。你可以在默认的分支上构建你的系统,也可以新建一个分支。如下:
$ git checkout tags/yocto-3.1 -b csdn1013-yocto-3.1
Switched to a new branch 'csdn1013-yocto-3.1'
~/poky$ git branch
* csdn1013-yocto-3.1
dunfell
开始构建
1. 首先需要初始化编译环境source oe-init-build-env
~/poky$ source oe-init-build-env
You had no conf/local.conf file. This configuration file has therefore been
created for you with some default values. You may wish to edit it to, for
example, select a different MACHINE (target hardware). See conf/local.conf
for more information as common configuration options are commented.
You had no conf/bblayers.conf file. This configuration file has therefore been
created for you with some default values. To add additional metadata layers
into your configuration please add entries to conf/bblayers.conf.
The Yocto Project has extensive documentation about OE including a reference
manual which can be found at:
http://yoctoproject.org/documentation
For more information about OpenEmbedded see their website:
http://www.openembedded.org/
### Shell environment set up for builds. ###
You can now run 'bitbake <target>'
Common targets are:
core-image-minimal
core-image-sato
meta-toolchain
meta-ide-support
You can also run generated qemu images with a command like 'runqemu qemux86'
Other commonly useful commands are:
- 'devtool' and 'recipetool' handle common recipe tasks
- 'bitbake-layers' handles common layer tasks
- 'oe-pkgdata-util' handles common target package tasks
如上面提示,现在通过bitbake编译工具可以编译一些目标image了:
core-image-minimal
core-image-sato
meta-toolchain
meta-ide-support
$bitbake core-image-sato