【Yocto学习入门】02 - 构建一个简单的Poky参考嵌入式操作系统
接下开来开始进入实操,光学习理论知识是没用的,文档中记录了我整个操作过程及遇到的问题。
好了,我们开始学习吧 ^_^
一、开发环境准备
50G
以上可用碰盘空间。- 运行受支持的
Linux
发行版(即Fedora
、openSUSE
、CentOS
、Debian
或Ubuntu
的最新版本) Linux
软件需求:
Git 1.8.3.1 or greater
tar 1.28 or greater
Python 3.6.0 or greater
gcc 5.0 or greater
因为居家办公,我这边目前使用的是Ubuntu20.04虚拟机,配置如下:
ciellee@ciellee-ubuntu:~$ uname -v
#47~20.04.2-Ubuntu SMP Mon Dec 13 11:06:56 UTC 2021
ciellee@ciellee-ubuntu:~$ uname -a
Linux ciellee-ubuntu 5.11.0-43-generic #47~20.04.2-Ubuntu SMP Mon Dec 13 11:06:56 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
ciellee@ciellee-ubuntu:~$ git --version
git version 2.25.1
ciellee@ciellee-ubuntu:~$ tar --version
tar (GNU tar) 1.30
ciellee@ciellee-ubuntu:~$ python --version
Python 3.8.10
ciellee@ciellee-ubuntu:~$ gcc --version
gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
如果是新安装的电脑环境,可以直接运行这条命令一键安装好
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 pylint3 xterm python3-subunit mesa-common-dev zstd liblz4-tool
如果下载速度慢,可以通过更新源来实现加速下载:
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
sudo gedit /etc/apt/sources.list
sudo apt-get update
将文件内容修改为如下:
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security multiverse
二、下载 Poky 代码
官网git 仓库:
$ git clone git://git.yoctoproject.org/poky
$ cd poky
$ git fetch --tags
如要官方下载慢,可以下载如下github上的资源:
$ git clone https://github.com/YoeDistro/poky.git
$ cd poky
$ git remote set-url origin git://git.yoctoproject.org/poky #把源修改成了官方的,也可以不用哈
$ git fetch --tags
我这边执行过程如下:
ciellee@ciellee-ubuntu:~/work/Poky$ git clone https://github.com/YoeDistro/poky.git
Cloning into 'poky'...
remote: Enumerating objects: 631815, done.
remote: Counting objects: 100% (1978/1978), done.
remote: Compressing objects: 100% (786/786), done.
remote: Total 631815 (delta 1225), reused 1847 (delta 1179), pack-reused 629837
Receiving objects: 100% (631815/631815), 200.42 MiB | 10.69 MiB/s, done.
Resolving deltas: 100% (468053/468053), done.
ciellee@ciellee-ubuntu:~/work/Poky$ ls
poky
ciellee@ciellee-ubuntu:~/work/Poky$ cd poky/
ciellee@ciellee-ubuntu:~/work/Poky/poky$ git remote set-url origin git://git.yoctoproject.org/poky
ciellee@ciellee-ubuntu:~/work/Poky/poky$ git fetch --tags
remote: Enumerating objects: 1, done.
remote: Total 1 (delta 0), reused 0 (delta 0), pack-reused 1
Unpacking objects: 100% (1/1), 534 bytes | 534.00 KiB/s, done.
From git://git.yoctoproject.org/poky
! [rejected] uninative-3.5 -> uninative-3.5 (would clobber existing tag)
ciellee@ciellee-ubuntu:~/work/Poky/poky$
我们进入 Releases wiki 页面选择一个长期稳定支持的版本来开发,
如最新的Kirkstone 4.0:
查看 当前 poky
的所有分支,并切换到 remotes/origin/kirkstone
分支
ciellee@ciellee-ubuntu:~/work/Poky/poky$ git branch -a
* master
...... 省略......
remotes/origin/HEAD -> origin/master
remotes/origin/kirkstone
remotes/origin/kirkstone-next
...... 省略......
ciellee@ciellee-ubuntu:~/work/Poky/poky$
ciellee@ciellee-ubuntu:~/work/Poky/poky$ git checkout -t origin/kirkstone -b my-kirkstone
Branch 'my-kirkstone' set up to track remote branch 'kirkstone' from 'origin'.
Switched to a new branch 'my-kirkstone'
ciellee@ciellee-ubuntu:~/work/Poky/poky$ git branch
master
* my-kirkstone
三、配置编译环境
- 初始化构建环境
source oe-init-build-env
ciellee@ciellee-ubuntu:~/work/Poky/poky$ ls
bitbake LICENSE MAINTAINERS.md meta meta-skeleton README.hardware.md README.poky.md
contrib LICENSE.GPL-2.0-only Makefile meta-poky meta-yocto-bsp README.md README.qemu.md
documentation LICENSE.MIT MEMORIAM meta-selftest oe-init-build-env README.OE-Core.md scripts
ciellee@ciellee-ubuntu:~/work/Poky/poky$ source oe-init-build-env
### 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'
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
ciellee@ciellee-ubuntu:~/work/Poky/poky/build$ ls
bitbake-cookerdaemon.log cache conf sstate-cache tmp
运行完成后自动进入创建并进入build
目录
- 开始编译:
bitbake core-image-sato
ciellee@ciellee-ubuntu:~/work/Poky/poky/build$ bitbake core-image-sato
Loading cache: 100% | | ETA: --:--:--
Loaded 0 entries from dependency cache.
开始编译 ,截图如下:
参考:
- 《yocto 教程》
- 《Yocto系列讲解[入门篇] 1 - 快速入门熟悉Yocto的构建》