By: fulinux
E-mail: fulinux@sina.com
Blog: https://blog.csdn.net/fulinus
喜欢的盆友欢迎点赞和订阅!
你的喜欢就是我写作的动力!
返回总目录:Yocto开发讲解系列 - 总目录
学习Yocto的目标:
我的理想是通过一条命令生成对应开发板的所有镜像文件,开机后的系统跑着Qt的wayland桌面管理系统,实现一个类似手机桌面环境的系统,但是精简、高效率、不吃资源、方便应用层实现多个Qt程序来回切换使用桌面等等。这是我学习yocto和wayland/QtWayland的目的
欢迎来到Yocto的世界
下面我将手把手带大家进入Yocto宏大的世界,一起领略下Yocto伟大,以后再也不用为编译bootloader、linux kernel、busybox、第三方库或程序、以及如何制作文件系统而苦恼了!
准备编译环境:
对编译机器的要求:
我建议你使用Ubuntu 16.04以上的版本!
磁盘空闲大小最好是50G以上!
Git, tar, Python和gcc版本需要满足如下要求:
- Git 1.8.3.1 or greater
- tar 1.28 or greater
- Python 3.5.0 or greater
- gcc 5.0 or greater
我当前的ubuntu版本如下:
$ uname -a
Linux OptiPlex-7050 4.15.0-136-generic #140~16.04.1-Ubuntu SMP Wed Feb 3 18:51:03 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
sudo apt-get install gawk wget git-core diffstat unzip texinfo gcc-multilib \
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 -y
#或者Ubuntu最新版本安装下面的
$ 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 -y
下载yocto的poky项目:
环境准备好之后开始下载源代码!
提示:yocto poky下载和编译的整个环节(除了运行QEMU虚拟机外)不需要root权限,请尽可能不要在root环境下去操作哦
$ git clone git://git.yoctoproject.org/poky
$ cd poky
$ git fetch --tags
下面是如果你poky克隆下载比较慢的可以在github上面找找资源,比如:
$ git clone https://github.com/YoeDistro/poky.git
$ cd poky
$ git remote set-url origin git://git.yoctoproject.org/poky #把源修改成了官方的,也可以不用哈
$ git fetch --tags
当然,我们尽量选择一个稳定的长期支持的版本来做开发,比如Dunfell
(yocto-3.1)版本,推荐使用Dunfell
,支持到2024年,但是本系列使用的是最新的Hardknott
(yocto-3.3)。最新的Honister
(yocto-3.4)以及之后的版本语法有大的改动,如果你稍有些经验的话可以用Honister
或更高版本,如果是小白就用Hardknott
或者Dunfell
吧,它们两个没有语法上的差异,可以兼容。
切换到对应的版本:
git checkout -t origin/hardknott -b my-hardknott
或者:
git checkout -t origin/dunfell -b my-dunfell
使能编译环境:
首先是进入这个poky目录哈~
$ cd ~/poky
简单看下这里都有什么~
使能一下编译环境,最好是开发的时候起一个独立的终端(shell
)来负责编译,这样就不用反复切换终端,还要使能下面的语句了。(不执行下面语句的话,就不能使用bitbake命令哦):
$ source oe-init-build-env
有个提示:
You can also run generated qemu images with a command like ‘runqemu
qemux86-64’
首次使能的时候会创建build目录,后面包括编译和输出的所有东西都在这个build目录下,所以build目录下的改动都是零时的,都是会变化的,所以不建议在build的目录下去做代码的修改,也无法保存下来,当然也不要怕去修改build目录下的代码,为了快速和零时改动是可以接收的。而且后面的章节讲到创建workspace目录都在这个下面。
build]$ ls
bitbake-cookerdaemon.log cache conf sstate-cache tmp
开始Yocto的编译:
好了,准备好了编译环境,就可以开始编译了!如下所示:
提示:如果编译有错误看下面内容:
build]$ bitbake core-image-sato
Loading cache: 100% | | ETA: --:--:--
Loaded 0 entries from dependency cache.
Parsing recipes: 100% |###########################################################################| Time: 0:00:11
Parsing of 821 .bb files complete (0 cached, 821 parsed). 1395 targets, 42 skipped, 0 masked, 0 errors.
NOTE: Resolving any missing task queue dependencies
Build Configuration:
BB_VERSION = "1.48.0"
BUILD_SYS = "x86_64-linux"
NATIVELSBSTRING = "ubuntu-16.04"
TARGET_SYS = "x86_64-poky-linux"
MACHINE = "qemux86-64"
DISTRO = "mydistro"
DISTRO_VERSION = "3.2.2"
TUNE_FEATURES = "m64 core2"
TARGET_FPU = ""
meta
meta-poky
meta-yocto-bsp
Initialising tasks: 100% |########################################################################| Time: 0:00:07
Sstate summary: Wanted 1975 Found 328 Missed 1647 Current 0 (16% match, 0% complete)
NOTE: Executing Tasks
例如图片中这样:
要下载的东西还是特别多的,6835个任务要执行
初始构建时间可能很长,要为构建一个功能齐全的Linux系统需要编译大量的软件包,就不可避免需要较长的初始构建时间。但是,一旦完成初始构建,Yocto Project使用的共享状态(状态)缓存机制可以防止系统重新构建自上次构建以来尚未“触及”的软件包。稳定状态机制大大减少了后续构建的时间。
可能要等待一段时间。。。。我们继续看下文
有些盆友网络下载速度慢,我将我的downloads目录打包后上传到了百度云上面,连接分享如下,
链接:https://pan.baidu.com/s/1ajjdPB97VEkpJYOjJ_P5FQ 提取码:uatu
复制这段内容后打开百度网盘手机App,操作更方便哦
下载后合并解压,在将其中的文件复制到poky/build/downloads下
编译出错解决方法
如果编译出错:
build]$ bitbake core-image-sato
ERROR: OE-core's config sanity checker detected a potential misconfiguration.
Either fix the cause of this error or at your own risk disable the checker (see sanity.conf).
Following is the list of potential problems / advisories:
Your version of gcc is older than 6.0 and will break builds. Please install a newer version of gcc (you could use the project's buildtools-extended-tarball or use scripts/install-buildtools).
提示我们说系统的gcc
版本比6.0的低,我的Ubuntu
是16.04,对应的gcc
版本是5.4,此时它也提供了解决方法,即执行:
poky]$ scripts/install-buildtools
INFO: Fetching buildtools installer
*******会卡顿一段时间**********
INFO: Fetching buildtools installer checksum
INFO: Checksum success
INFO: Making installer executable
Extended Build tools installer version 3.1+snapshot
===================================================
You are about to install the SDK to "/home/fulinux/poky/buildtools". Proceed [Y/n]? Y
Extracting SDK..................done
Setting it up...done
SDK has been successfully set up and is ready to be used.
Each time you wish to use the SDK in a new shell session, you need to source the environment setup script e.g.
$ . /home/fulinux/poky/buildtools/environment-setup-x86_64-pokysdk-linux
其实本质是将相关的开发工具下载到了poky/buildtools
目录下,如:
poky]$ ls buildtools/sysroots/x86_64-pokysdk-linux/usr/bin/
2to3 ifnames mshortname subunit-notify
2to3-3.8 ld mshowfat subunit-output
aclocal ld.bfd mtools subunit-stats
aclocal-1.16 ld.gold mtoolstest subunit-tags
addr2line libtoolize mtype tap2subunit
amuFormat.sh locale mxtar tar
ar locate mzip texi2any
as lz nettle-hash texi2dvi
autoconf m4 nettle-lfib-stream texi2pdf
autoheader make nettle-pbkdf2 texindex
autom4te makedb nm tgz
automake makeinfo objcopy update-alternatives
automake-1.16 mattrib objdump update-ca-certificates
autopoint mbadblocks openssl updatedb
autoreconf mcat patch uz
autoscan mcd patch.patch wget
autoupdate mcheck pbr x86_64-pokysdk-linux-addr2line
c++ mclasserase pcprofiledump x86_64-pokysdk-linux-ar
cc mcomp pdftexi2dvi x86_64-pokysdk-linux-as
c++filt mcopy pip3 x86_64-pokysdk-linux-c++filt
chrpath mdel pip3.8 x86_64-pokysdk-linux-cpp
cpp mdeltree pkcs1-conv x86_64-pokysdk-linux-dwp
c_rehash mdir pkg-config x86_64-pokysdk-linux-elfedit
dwp mdu pldd x86_64-pokysdk-linux-g++
easy3_install mformat pod2texi x86_64-pokysdk-linux-gcc
easy_install-3.8 minfo pydoc3 x86_64-pokysdk-linux-gcc-10.2.0
elfedit mkmanifest pydoc3.8 x86_64-pokysdk-linux-gcc-ar
find mlabel python3 x86_64-pokysdk-linux-gcc-nm
find.findutils mmd python3.8 x86_64-pokysdk-linux-gcc-ranlib
g++ mmount python3.8.real x86_64-pokysdk-linux-gnu-pkg-config
gcc mmove ranlib x86_64-pokysdk-linux-gprof
gencat mpartition readelf x86_64-pokysdk-linux-ld
getconf mrd recode-sr-latin x86_64-pokysdk-linux-ld.bfd
getent mren rpcgen x86_64-pokysdk-linux-ld.gold
gettextize msgattrib sexp-conv x86_64-pokysdk-linux-libtool
git msgcat size x86_64-pokysdk-linux-lto-dump
git.real msgcmp sprof x86_64-pokysdk-linux-nm
git-receive-pack msgcomm strings x86_64-pokysdk-linux-objcopy
git-shell msgconv strip x86_64-pokysdk-linux-objdump
git-upload-archive msgen subunit-1to2 x86_64-pokysdk-linux-ranlib
git-upload-pack msgexec subunit2csv x86_64-pokysdk-linux-readelf
gnu-configize msgfilter subunit2disk x86_64-pokysdk-linux-size
gprof msgfmt subunit2gtk x86_64-pokysdk-linux-strings
gtar msggrep subunit2junitxml x86_64-pokysdk-linux-strip
iconv msginit subunit2pyunit xargs
iconvconfig msgmerge subunit-2to1 xargs.findutils
idle3 msgunfmt subunit-filter xgettext
idle3.8 msguniq subunit-ls
这个时候我们只需要在终端窗口中执行:
. /home/fulinux/poky/buildtools/environment-setup-x86_64-pokysdk-linux
使能一下gcc等工具路径的环境变量脚本即可开始重新编译了。
更新Python3.6
安装python3.6的方法:
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update
sudo apt-get install python3.6
#将Python版本切换到3.6
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 3
其他切换去的方法,比如切换3.5:
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.5 3
Yocto系列讲解 (入门篇) 2 - 演示运行qemux86-64虚拟机
最终效果展示
最终的效果:
希望帮我点个赞加关注,你的喜欢就是我持续更新的动力!