yocto-第9篇-devtool验证learnyocto并集成到meta-mylayer

By: fulinux
E-mail: fulinux@sina.com
Blog: https://blog.csdn.net/fulinus
喜欢的盆友欢迎订阅!
你的喜欢就是我写作的动力!

返回总目录 Yocto开发讲解系列 - 总目录

查看workspace中有哪些项目

可以罗列出当前的工作区中有哪些 recipes 及其各自源码的路径,参考如下:

poky]$ source oe-init-build-env
build]$ devtool status -h
NOTE: Starting bitbake server...
usage: devtool status [-h]

Lists recipes currently in your workspace and the paths to their respective
external source trees

options:
  -h, --help  show this help message and exit
build]$ devtool status
NOTE: Starting bitbake server...
helloyocto: /home/peeta/code/helloyocto (/home/peeta/poky/build/workspace/recipes/helloyocto/helloyocto.bb) #这个也可以没有
learnyocto: /home/peeta/poky/build/workspace/sources/learnyocto (/home/peeta/poky/build/workspace/recipes/learnyocto/learnyocto_git.bb) #这个
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

可见我当前的 workspace 有两个 recipe ,即 helloyocto learnyocto

复制软件到虚拟机中运行

前面我们编译了 learnyocto , 而且也看到如下路径中有执行程序如下:

build/workspace/sources/learnyocto/oe-workdir/image/usr/bin/learnyocto
  • 1

该程序不能在我们的(我的是 Ubuntu )电脑上面直接执行,因为编译出来的体系架构不同指令码也不一样。我们需要将其放到目标 qemux86-64 虚拟机系统中才可以执行。
我们在另一个shell终端中启动我们的 QEMU 虚拟机

build]$ runqemu qemux86-64
  • 1

然后在另一个shell终端中,通过下面的方式登路qemux86-64系统:

$ ssh-keygen -f "/home/peeta/.ssh/known_hosts" -R 192.168.7.2
$ ssh root@192.168.7.2
root@qemux86-64:~# 
  • 1
  • 2
  • 3

我们先不研究如何将learnyocto项目整合到系统镜像中,先将上面提及的learnyocto测试程序复制到qemux86-64系统中,如下:

build]$ scp workspace/sources/learnyocto/oe-workdir/image/usr/bin/learnyocto root@192.168.7.2:~/
learnyocto         100%   23KB  22.7KB/s   00:00  #发送成功
  • 1
  • 2

然后,再qemux86-64机器中执行如下:

root@qemux86-64:~# ./learnyocto 
[develop branch]Hello Yocto! #程序打印的结果
  • 1
  • 2

关闭qemux86-64系统:

root@qemux86-64:~# shutdown -h now
  • 1

项目开发和修改阶段验证

现在有一个场景是这样的:我们的learnyocto项目还在workspace,我还在开发,但是我又想集成到文件系统当中随系统一起启动并验证,怎么处理呢,手动拷贝对于那些比较大的文件较多的项目而言费时费力?有没有什么好方法呢?
使用 devtool build-image 命令来构建 image ,并将 workspace 中的 recipes 包含到的 qemux86-64 文件系统中。使用 devtool build-image 命令时,必须提供 image 的名称。还记得 qemux86-64 的编译时候的镜像名吗?参考如下:

build]$ devtool build-image core-image-sato
  • 1

编译完成后,确认下文件系统中是否有 learnyocto 程序:

build/tmp-qemux86-64/work/qemux86_64-poky-linux/core-image-sato/1.0-r0/rootfs/usr/bin/learnyocto 
  • 1

运行系统,并运行learnyocto程序:

build]$ runqemu qemux86-64
  • 1

并在另一个shell中执行:

$ ssh-keygen -f "/home/peeta/.ssh/known_hosts" -R 192.168.7.2
$ ssh root@192.168.7.2
root@qemux86-64:~# learnyocto 
[develop branch]Hello Yocto! #执行成功
  • 1
  • 2
  • 3
  • 4

你可能会问:为什么要这个 devtool build-image core-image-sato 命令?不是有前面的 bitbake core-image-sato ,你的疑惑是有点道理的。但是你要这么想,当前是 learnyocto 项目通过devtool工具来做开发或修改,是在workspace目录中有自己的一套recipe,其他的metadata中也可能又有一套,而workspace中的recipe并没有实际将修改中的项目和我们的目标镜像(即core-image-sato)关联起来,bitbake要么找不到对应的recipe,要么使用了其他metadata目录中的recipe,总之,bitbake没有去编译workspace目录中的recipe。因此,我们就需要使用 devtool build-image core-image-sato 命令来帮我们解决这个问题,它可以在开发和修改的中途就来验证你的成果,如果成功了就集成到某个metadata layer目录中,如果没有成功就继续开发和修改~

集成到meta-mylayer中去

比如说此时我们通过 devtoolo 工具已经完成了 learnyocto 项目的开发,但是它当前只是在 workspace 目录中,一个用于开发的临时目录中,我们需要固化我们的成果,需要将其添加到一个 metadata 中去,比如我们之前创建的 meta-mylayer 中去,我们应该怎么做呢?此时, devtool finish 命令就派上用场了,参考如下:

build]$ devtool finish learnyocto meta-mylayer
...
Parsing of 877 .bb files complete (875 cached, 2 parsed). 1461 targets, 49 skipped, 0 masked, 0 errors.

Summary: There was 1 WARNING message shown.
INFO: Updating SRCREV in recipe learnyocto_git.bb
INFO: Moving recipe file to /home/peeta/poky/meta-mylayer/recipes-learnyocto/learnyocto
INFO: Leaving source tree /home/peeta/poky/build/workspace/sources/learnyocto as-is; if you no longer need it then please delete it manually
build]$ rm workspace/sources/learnyocto/ -rf #确认不需要就可以删除,以免下次调用devtool命令时冲突
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

在上面的 INFO 提示中也可以看出我们的 learnyocto 项目已经添加到 meta-mylayer 目录中去了,如下所示:

poky]$ tree meta-mylayer/recipes-learnyocto/
meta-mylayer/recipes-learnyocto/
└── learnyocto
    └── learnyocto_git.bb
  • 1
  • 2
  • 3
  • 4

看下这个bb文件:

poky]$ cat meta-mylayer/recipes-learnyocto/learnyocto/learnyocto_git.bb
# Recipe created by recipetool
# This is the basis of a recipe and may need further editing in order to be fully functional.
# (Feel free to remove these comments when editing.)

# WARNING: the following LICENSE and LIC_FILES_CHKSUM values are best guesses - it is
# your responsibility to verify that the values are complete and correct.
LICENSE = "LGPLv3"
LIC_FILES_CHKSUM = "file://LICENSE;md5=e6a600fd5e1d9cbde2d983680233ad02"

SRC_URI = "git://gitee.com/fulinux/learnyocto.git;protocol=https;branch=develop"

# Modify these as desired
PV = "1.0+git${SRCPV}"
SRCREV = "351e99f4d4f6045771a920a33ab178b55a8ff829"

S = "${WORKDIR}/git"

inherit cmake

# Specify any options you want to pass to cmake using EXTRA_OECMAKE:
EXTRA_OECMAKE = ""
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22

这个bb文件我没有做任何改动,一步到位,指定了 SRC_URI 、版本信息、cmake编译方式等。是不是超级方便~

tips: 通常我们可以将meta-mylayer做成一个独立的项目放到git服务器上面,避免意外删除

这条命令后面的 yocto-第16篇-devtool upgrade命令 也有讲,就是将learnyocto项目从workspace开发目录中添加到了自己的meta-mylayer层中了。

如何安装到文件系统中

我们先清空我们的 core-image-sato 目标镜像,然后用bitbake命令来编译:

build]$ bitbake core-image-sato -c cleanall
build]$ bitbake core-image-sato
  • 1
  • 2

此时,在 build/tmp-qemux86-64/work/qemux86_64-poky-linux/core-image-sato/1.0-r0/rootfs/usr/bin/ 目录下就没有 learnyocto 程序了
说明正常编译目标镜像的时候是没有将 learnyocto 中集成到文件系统的,为什么?因为没有添加这个:

IMAGE_INSTALL += "learnyocto"
  • 1

那么在哪里可以添加这个 IMAGE_INSTALL 变量呢?有两个地方,下面先讲第一个。

在local.conf文件中添加

添加 IMAGE_INSTALL 变量,第一个方法是在 build/conf/local.conf 文件结尾添加如下一行:

build]$ cat conf/local.conf
...
IMAGE_INSTALL_append = " learnyocto"  #在learnyocto前面有个空格哦
  • 1
  • 2
  • 3

添加完后重新source环境,并编译:

poky]$ source oe-init-build-env
build]$ bitbake core-image-sato
  • 1
  • 2

确认下文件系统中是否有 learnyocto 程序:

build/tmp-qemux86-64/work/qemux86_64-poky-linux/core-image-sato/1.0-r0/rootfs/usr/bin/learnyocto 
  • 1

如果想进一步确认可以将 qemux86-64 虚拟机跑起来运行程序看看。我这里就不运行它了~

在目标recipe文件中添加

build/conf/local.conf 文件中添加这个毕竟是一个临时的方案,最终的方案是应该将其添加到我们的 meta-mylayer 目录中去,既不会修改原poky目录下的内容,又让文件系统永久性的集成了我们的软件项目。

首先,有看过 yocto-第5篇-在meta-mylayer中添加helloworld recipe 的盆友应该记得我们创建的这个文件:

poky/meta-mylayer/recipes-sato/images/core-image-sato.bbappend 
  • 1

我们也可以在这个文件中添加:

...
IMAGE_INSTALL += "learnyocto"
  • 1
  • 2

添加完后重新source环境,并编译:

poky]$ source oe-init-build-env
build]$ bitbake core-image-sato
  • 1
  • 2

确认下文件系统中是否有 learnyocto 程序:

build/tmp-qemux86-64/work/qemux86_64-poky-linux/core-image-sato/1.0-r0/rootfs/usr/bin/learnyocto 
  • 1

当然,最后运行 qemux86-64 虚拟机后,就可以运行跑我们的程序了:

root@qemux86-64:~# learnyocto 
[develop branch]Hello Yocto!
  • 1
  • 2

查看安装的软件清单

yocto编译的内容那么多我怎么知道有哪些项目目标输出呢,
小技巧:

build]$ cat tmp/deploy/images/qemux86-64/core-image-sato-qemux86-64.manifest
...
alsa-utils-alsamixer core2_64 1.2.1
busybox core2_64 1.31.1
kernel-5.4.50-yocto-standard qemux86_64 5.4.50+git999
update-rc.d noarch 0.8
...
helloworld-a core2-64 1.0-r0 #这个是我们自己添加的
helloworld-c core2-64 1.0-r0 #这个是我们自己添加的
helloworld-m core2-64 1.0-r0 #这个是我们自己添加的
learnyocto core2-64 1.0+git0+351e99f4d4-r0 #这个是我们自己添加的
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

上面有列举几个目标文件,有kernel、和应用程序。每一行的第二个参数,比如举例中有两类:core2_64 和 noarch。
其中core2_64表示该项目于目标的体系架构有关,可以理解成有相应二进制的执行程序。而noarch为与体系结构无关的项目,一般就是一些配置文件、脚本什么的,可以在任意平台上使用,比如上面的update-rc.d,还有一些字体库、time zoen什么的。

谢谢阅读!希望帮我点个赞加关注,你的喜欢就是我持续更新的动力!