900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > 【Yocto学习入门】02 - 构建一个简单的Poky参考嵌入式操作系统

【Yocto学习入门】02 - 构建一个简单的Poky参考嵌入式操作系统

时间:2024-01-16 17:40:52

相关推荐

【Yocto学习入门】02 - 构建一个简单的Poky参考嵌入式操作系统

【Yocto学习入门】02 - 构建一个简单的Poky参考嵌入式操作系统

一、开发环境准备二、下载 Poky 代码三、配置编译环境3.1 下载失败情况处理 Failed to fetch URL http://downloads.xxxxxxxxx四、使用 QEMU 运行构建的镜像

接下开来开始进入实操,光学习理论知识是没用的,文档中记录了我整个操作过程及遇到的问题。

好了,我们开始学习吧 ^_^

官网文档:《欢迎来到 Yocto 项目文档》

一、开发环境准备

50G以上可用碰盘空间。运行受支持的Linux发行版(即FedoraopenSUSECentOSDebianUbuntu的最新版本)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 ciellee@ciellee-ubuntu:~$ uname -aLinux ciellee-ubuntu 5.11.0-43-generic #47~20.04.2-Ubuntu SMP Mon Dec 13 11:06:56 UTC x86_64 x86_64 x86_64 GNU/Linuxciellee@ciellee-ubuntu:~$ git --versiongit version 2.25.1ciellee@ciellee-ubuntu:~$ tar --versiontar (GNU tar) 1.30ciellee@ciellee-ubuntu:~$ python --versionPython 3.8.10ciellee@ciellee-ubuntu:~$ gcc --versiongcc (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 /ubuntu/ focal main restricted universe multiversedeb-src /ubuntu/ focal main restricted universe multiversedeb /ubuntu/ focal-security main restricted universe multiversedeb-src /ubuntu/ focal-security main restricted universe multiversedeb /ubuntu/ focal-updates main restricted universe multiversedeb-src /ubuntu/ focal-updates main restricted universe multiversedeb /ubuntu/ focal-proposed main restricted universe multiversedeb-src /ubuntu/ focal-proposed main restricted universe multiversedeb /ubuntu/ focal-backports main restricted universe multiversedeb-src /ubuntu/ focal-backports main restricted universe multiversedeb http://mirrors.tuna./ubuntu/ focal main restricteddeb http://mirrors.tuna./ubuntu/ focal-updates main restricteddeb http://mirrors.tuna./ubuntu/ focal universedeb http://mirrors.tuna./ubuntu/ focal-updates universedeb http://mirrors.tuna./ubuntu/ focal multiversedeb http://mirrors.tuna./ubuntu/ focal-updates multiversedeb http://mirrors.tuna./ubuntu/ focal-backports main restricted universe multiversedeb http://mirrors.tuna./ubuntu/ focal-security main restricteddeb http://mirrors.tuna./ubuntu/ focal-security universedeb http://mirrors.tuna./ubuntu/ focal-security multiverse

二、下载 Poky 代码

官网git 仓库:

$ git clone git:///poky$ cd poky$ git fetch --tags

如要官方下载慢,可以下载如下github上的资源:

$ git clone /YoeDistro/poky.git$ cd poky$ git remote set-url origin git:///poky #把源修改成了官方的,也可以不用哈$ git fetch --tags

我这边执行过程如下:

ciellee@ciellee-ubuntu:~/work/Poky$ git clone /YoeDistro/poky.gitCloning 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 629837Receiving objects: 100% (631815/631815), 200.42 MiB | 10.69 MiB/s, done.Resolving deltas: 100% (468053/468053), done.ciellee@ciellee-ubuntu:~/work/Poky$ lspokyciellee@ciellee-ubuntu:~/work/Poky$ cd poky/ciellee@ciellee-ubuntu:~/work/Poky/poky$ git remote set-url origin git:///pokyciellee@ciellee-ubuntu:~/work/Poky/poky$ git fetch --tagsremote: Enumerating objects: 1, done.remote: Total 1 (delta 0), reused 0 (delta 0), pack-reused 1Unpacking objects: 100% (1/1), 534 bytes | 534.00 KiB/s, done.From git:///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/masterremotes/origin/kirkstoneremotes/origin/kirkstone-next...... 省略......ciellee@ciellee-ubuntu:~/work/Poky/poky$ ciellee@ciellee-ubuntu:~/work/Poky/poky$ git checkout -t origin/kirkstone -b my-kirkstoneBranch '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$ lsbitbake LICENSEMAINTAINERS.md meta meta-skeletonREADME.hardware.md README.poky.mdcontrib LICENSE.GPL-2.0-only Makefile meta-pokymeta-yocto-bspREADME.md README.qemu.mddocumentation LICENSE.MIT MEMORIAM meta-selftest oe-init-build-env README.OE-Core.md scriptsciellee@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-minimalcore-image-full-cmdlinecore-image-satocore-image-westonmeta-toolchainmeta-ide-supportYou 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 tasksciellee@ciellee-ubuntu:~/work/Poky/poky/build$ lsbitbake-cookerdaemon.log cache conf sstate-cache tmp

运行完成后自动进入创建并进入build目录

开始编译:bitbake core-image-sato

ciellee@ciellee-ubuntu:~/work/Poky/poky/build$ bitbake core-image-satoLoading cache: 100% || ETA: --:--:--Loaded 0 entries from dependency cache.

开始编译 ,截图如下:

接下来是漫长的等待,因为有些package的网站访问速度实在太慢了,等待中。。。。。。。。

看这网速,9k/s, 要哭了,我等,继续等,T_T

现在是5月1日17:44,从昨天到今天已经整整拉了一天了,才走到一半。

从进度条看,总共有6556个任务,一天时间做到了3142,还有一半,明天应该问题不大。

3.1 下载失败情况处理 Failed to fetch URL http://downloads.xxxxxxxxx

当出现如下载失败的情况,

ciellee@ciellee-ubuntu:~/work/Poky/poky/build$ bitbake core-image-satoLoading cache: 100% || ETA: --:--:--Loaded 0 entries from dependency cache.Parsing recipes: 100% |#########################################################################################| Time: 0:01:18Parsing of 882 .bb files complete (0 cached, 882 parsed). 1640 targets, 44 skipped, 0 masked, 0 errors.NOTE: Resolving any missing task queue dependenciesBuild Configuration:BB_VERSION = "2.0.0"BUILD_SYS = "x86_64-linux"NATIVELSBSTRING= "ubuntu-20.04"TARGET_SYS = "x86_64-poky-linux"MACHINE = "qemux86-64"DISTRO= "poky"DISTRO_VERSION = "4.0"TUNE_FEATURES = "m64 core2"TARGET_FPU = ""meta meta-poky meta-yocto-bsp = "my-kirkstone:27de52e402ae000dfa502d52908cd6e6aef923ec"NOTE: Fetching uninative binary shim /releases/uninative/3.6/x86_64-nativesdk-libc-3.6.tar.xz;sha256sum=9bfc4c970495b3716b2f9e52c4df9f968c02463a9a95000f6657fbc3fde1f098 (will check PREMIRRORS first)WARNING: Failed to fetch URL /releases/uninative/3.6/x86_64-nativesdk-libc-3.6.tar.xz;sha256sum=9bfc4c970495b3716b2f9e52c4df9f968c02463a9a95000f6657fbc3fde1f098, attempting MIRRORS if availableInitialising tasks: 100% |######################################################################################| Time: 0:00:03Sstate summary: Wanted 2730 Local 0 Mirrors 0 Missed 2730 Current 0 (0% match, 0% complete)NOTE: Executing TasksWARNING: xz-native-5.2.5-r0 do_fetch: Failed to fetch URL /xz/xz-5.2.5.tar.gz, attempting MIRRORS if availableWARNING: zlib-native-1.2.11-r0 do_fetch: Failed to fetch URL /libpng/zlib/1.2.11/zlib-1.2.11.tar.xz, attempting MIRRORS if available

可以直接用迅雷下载好,然后复制进Pokey/build/downloads目录

通过搜索,可以看出,这些需要下载的包 ,都是提前定义在meta元数据的.bb文件中的

ciellee@ciellee-ubuntu:~/work/Poky/poky$ grep -rsn "/xz/xz" ../meta/recipes-extended/xz/xz_5.2.5.bb:27:SRC_URI = "/xz/xz-${PV}.tar.gz \./meta/recipes-extended/xz/xz/CVE--1271.patch:50:Upstream-Status: Backport [/xz/xzgrep-ZDI-CAN-16587.patch]

下载的时候,耐心点,网速也没办法

一些大文件,如果下载网速慢,可以通过这里加一句log,打印出下载地址,然后 直接迅雷 加速下载后再放进去。

文件路径:bitbake/lib/bb/fetch2/__init__.py

NOTE: Executing TasksWARNING: binutils-cross-x86_64-2.38-r0 do_fetch: [ciellee-debug]start to fetch URL git:///git/binutils-gdb.git;branch=binutils-2_38-branch;protocol=gitSetscene tasks: 2730 of 2730Currently 1 running tasks (114 of 6556) 1% |# |0: binutils-cross-x86_64-2.38-r0 do_fetch - 3m52s (pid 57866) 17% |######## | 20.9K/s

四、使用 QEMU 运行构建的镜像

一方面网速慢,尤其是访问git仓库时,

别一方面,我用的是虚拟机,所以编译也很慢,我这边从下载代码,到编译成功,总共使用了两天两夜的时间,

编译成功后,再执行一遍,截图如下:

Build 目录下各目录大小情况:

使用 QEMU 运行构建的镜像

source oe-init-build-env

runqemu qemux86-64

由于需要用到UI显示,注意这个只能在ubuntu 下执行,不能在ssh终端中运行。

运行过程中截图如下:

点击进入 Terminal,可以看到当前系统的文件系统。

好了,本文就写到这里吧,下篇文章开始,我们深入代码去看看

参考:

《yocto 教程》《Yocto系列讲解[入门篇] 1 - 快速入门熟悉Yocto的构建》《The Yocto Project ® 4.0.999 documentation》

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。