Yocto 快速编译以及使用QEMU启动其镜像文件

Yocto Project Quick Build — The Yocto Project ? 4.3.999 documentation

前言:

开头附上官方文档的地址,里面有详细的步骤以及相关知识的介绍。本节参考此文档。

我使用的是一台window11操作系统的机器,并且使用工具VirtualBox 安装了一个Ubuntu20.04的操作系统的虚拟机,本文将使用这样的一个虚拟机环境来编译Yocto,产生镜像文件,并使用QEMU来启动这个镜像。

1. 基本配置要求

  1. 90G的硬盘剩余空间
  2. 8G的内存
  3. 支持的操作系统 Fedora, openSUSE, CentOS, Debian, or Ubuntu,本文使用的是Ubuntu20.04
  4. Git 1.8.3.1
  5. tar 1.28
  6. Python 3.8.0
  7. gcc 8.0
  8. GNU make 4.0

输入 git --version  或 tar --version 等等,可以查看系统中工具版本。

更高的配置会节约编译时间,作者给虚拟机配置了 16G RAM 和 8核。

2. 安装必要的文件包

$ sudo apt install gawk wget git diffstat unzip texinfo gcc build-essential chrpath socat cpio python3 python3-pip python3-pexpect xz-utils debianutils iputils-ping python3-git python3-jinja2 libegl1-mesa libsdl1.2-dev python3-subunit mesa-common-dev zstd liblz4-tool file locales libacl1
$ sudo locale-gen en_US.UTF-8

3. 下载Yocto的代码

$ 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.

切换到一个指定的分支,示例为Nanbield.

$ git checkout -t origin/nanbield -b my-nanbield
Branch 'my-nanbield' set up to track remote branch 'nanbield' from 'origin'.
Switched to a new branch 'my-nanbield'

拉取最新代码

$ git pull

4.开始编译

4.1 初始化编译环境

$ cd 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:
    https://docs.yoctoproject.org

For more information about OpenEmbedded see their website:
    https://www.openembedded.org/

### Shell environment set up for builds. ###

You can now run 'bitbake <target>'

Common targets are:
    core-image-minimal
    core-image-full-cmdline
    core-image-sato
    core-image-weston
    meta-toolchain
    meta-ide-support

You can also run generated QEMU images with a command like 'runqemu qemux86-64'

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

4.2 查看你的config

前面的步骤会配置编译环境,并且产生一个build 文件夹,其下面会有conf/local.conf

文件中默认配置会产生一个适用于QEMU的镜像。

MACHINE ??= "qemux86-64"

tips:  为了加速编译时间,可以把conf/local.conf 中的以下内容的注释去掉。

BB_HASHSERVE_UPSTREAM = "hashserv.yocto.io:8687"
SSTATE_MIRRORS ?= "file://.* http://cdn.jsdelivr.net/yocto/sstate/all/PATH;downloadfilename=PATH"
BB_HASHSERVE = "auto"
BB_SIGNATURE_HANDLER = "OEEquivHash"

4.3 开始编译

$ bitbake core-image-minimal

4.4 使用QEMU启动镜像

$ runqemu qemux86-64

使用root, 即可登录。

退出QEMU,使用Ctrl-C