yocto-第15篇-devtool update-recipe命令

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

devtool update-recipe命令

devtool update-recipe命令可以使用对recipe源码的修改生成的patch来对recipe进行更新。打个比方,你要对你的源码进行修改,你可以先使用devtool modify命令提取不在workspace目录下的recipe源码,之后你需要修改、编译和测试等操作。当你对你的修改工作满意后,需要进行git提交,然后,你可以运行devtool update-recipe生成patches并更新recipe. 这个是不是和我们之前的文章描述的内容有点类似?

如果recipe的源码没有做git提交,该命令将忽略,不做任何事情。

帮助信息

~]$ cd poky/
poky]$ source oe-init-build-env
build]$ devtool update-recipe -h
NOTE: Starting bitbake server...
usage: devtool update-recipe [-h] [--mode MODE] [--initial-rev INITIAL_REV]
                             [--append LAYERDIR] [--wildcard-version]
                             [--no-remove] [--no-overrides] [--dry-run]
                             [--force-patch-refresh]
                             recipename

Applies changes from external source tree to a recipe
(updating/adding/removing patches as necessary, or by updating SRCREV). Note
that these changes need to have been committed to the git repository in order
to be recognised.

arguments:
  recipename            Name of recipe to update

options:
  -h, --help            show this help message and exit
  --mode MODE, -m MODE  Update mode (where MODE is patch, srcrev, auto;
                        default is auto)
  --initial-rev INITIAL_REV
                        Override starting revision for patches
  --append LAYERDIR, -a LAYERDIR
                        Write changes to a bbappend in the specified layer
                        instead of the recipe
  --wildcard-version, -w
                        In conjunction with -a/--append, use a wildcard to
                        make the bbappend apply to any recipe version
  --no-remove, -n       Don't remove patches, only add or update
  --no-overrides, -O    Do not handle other override branches (if they exist)
  --dry-run, -N         Dry-run (just report changes instead of writing them)
  --force-patch-refresh
                        Update patches in the layer even if they have not been
                        modified (useful for refreshing patch context)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36

通常,你可能希望在自己的layer(比如我们前面创建的meta-mylayer)中对软件进行的自定义,而不是直接将其应用于原始recipe。如果你想在自己的layer中完成,可以在devtool update-recipe命令中使用-a或–append选项,可以使append文件放到自己指定的layer中。
生成的*.bbappend文件是在指定layer目录内处创建,不一定在bblayers.conf文件中有描述。如果append文件已经存在,该命令将对其进行适当的更新。

使用举例

我们这里还是使用alsamixer程序修改举例。
首先复习下,我们已知alsamixer程序,如何知道其对应的recipe呢?

build]$ devtool search alsamixer
NOTE: Starting bitbake server...
NOTE: Reconnecting to bitbake server...
NOTE: Retrying server connection (#1)...
Loading cache: 100% |#####################################################################################################| Time: 0:00:00
Loaded 1321 entries from dependency cache.
Parsing recipes: 100% |###################################################################################################| Time: 0:00:00
Parsing of 782 .bb files complete (780 cached, 2 parsed). 1323 targets, 46 skipped, 0 masked, 0 errors.
alsa-utils            ALSA sound utilities
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

可以看到alsamixer对应的recipe就是alsa-utils,开始修改提取源码:

build]$ devtool modify alsa-utils
NOTE: Starting bitbake server...
NOTE: Reconnecting to bitbake server...
NOTE: Retrying server connection (#1)...
Loading cache: 100% |#####################################################################################################| Time: 0:00:00
Loaded 1321 entries from dependency cache.
Parsing recipes: 100% |###################################################################################################| Time: 0:00:00
Parsing of 782 .bb files complete (780 cached, 2 parsed). 1323 targets, 46 skipped, 0 masked, 0 errors.
NOTE: Resolving any missing task queue dependencies

Build Configuration:
BB_VERSION           = "1.46.0"
BUILD_SYS            = "x86_64-linux"
NATIVELSBSTRING      = "universal"
TARGET_SYS           = "x86_64-poky-linux"
MACHINE              = "qemux86-64"
DISTRO               = "poky"
DISTRO_VERSION       = "3.1.2"
TUNE_FEATURES        = "m64 core2"
TARGET_FPU           = ""
meta                 
meta-poky            
meta-yocto-bsp       = "my-yocto-3.1.2:569b1f5d67c57de957e243997c53ec2f81dc8dfe"
meta-altera          = "master:aa24dfcb39fce3619a87ee6eef6e4296e66d2099"
meta-mylayer         
workspace            = "my-yocto-3.1.2:569b1f5d67c57de957e243997c53ec2f81dc8dfe"

Initialising tasks: 100% |################################################################################################| Time: 0:00:00
Sstate summary: Wanted 0 Found 0 Missed 0 Current 20 (0% match, 100% complete)
NOTE: Executing Tasks
NOTE: Tasks Summary: Attempted 93 tasks of which 90 didn't need to be rerun and all succeeded.
INFO: Source tree extracted to /home/peeta/poky/build/workspace/sources/alsa-utils
INFO: Recipe alsa-utils now set up to build from /home/peeta/poky/build/workspace/sources/alsa-utils
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33

查看devtool modify命令生成了哪些内容:

build]$ ls workspace/
appends/      conf/         .devtool_md5  README        recipes/      sources/      
[build]$ ls workspace/appends/
alsa-utils_1.2.1.bbappend  helloyocto.bbappend  learnyocto_git.bbappend
[build]$ ls workspace/conf/
layer.conf
[build]$ ls workspace/recipes/
helloyocto  learnyocto
[build]$ ls workspace/sources/
alsa-utils  example  learnyocto
[build]$ cat workspace/appends/alsa-utils_1.2.1.bbappend 
FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
FILESPATH_prepend := "/home/peeta/poky/build/workspace/sources/alsa-utils/oe-local-files:"
# srctreebase: /home/peeta/poky/build/workspace/sources/alsa-utils

inherit externalsrc
# NOTE: We use pn- overrides here to avoid affecting multiple variants in the case where the recipe uses BBCLASSEXTEND
EXTERNALSRC_pn-alsa-utils = "/home/peeta/poky/build/workspace/sources/alsa-utils"

# initial_rev: 19b96aa06bc454d64df7a728c9a3072886901058
# commit: 9471b9fed28eab1b75631dd30c27756bb688dd8f
[build]$ cd workspace/sources/alsa-utils/
[alsa-utils]$ git branch 
* devtool
  master
[alsa-utils]$ git log
9471b9f alsamixer:test devtool modify (Peeta Chen, 5 分钟前) #可见其包含上一次我提交的内容
19b96aa Initial commit from upstream at version 1.2.1 (OpenEmbedded, 5 分钟前)
[alsa-utils]$ git log -p .
9471b9f alsamixer:test devtool modify (Peeta Chen, 5 分钟前)

diff --git a/alsamixer/cli.c b/alsamixer/cli.c
index 3f8f52f..fe00d31 100644
--- a/alsamixer/cli.c
+++ b/alsamixer/cli.c
@@ -37,7 +37,7 @@ static struct snd_mixer_selem_regopt selem_regopt = {
 
 static void show_help(void)
 {
-       puts(_("Usage: alsamixer [options]"));
+       puts(_("Usage: alsamixer [options], hello fulinux!"));
        puts(_("Useful options:\n"
               "  -h, --help              this help\n"
               "  -c, --card=NUMBER       sound card number or id\n"
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44

开始修改代码

我们还是简单的在打印里面加个字符串“hello yocto”:

[alsa-utils]$ vim alsamixer/cli.c +38  #你们也可以根据自己的喜好使用编辑器。
  • 1
static void show_help(void)
{
    puts(_("Usage: alsamixer [options], hello fulinux! hello yocto")); //我的修改在这一行
    puts(_("Useful options:\n"
           "  -h, --help              this help\n"
           "  -c, --card=NUMBER       sound card number or id\n"
           "  -D, --device=NAME       mixer device name\n"
           "  -V, --view=MODE         starting view mode: playback/capture/all"));
    puts(_("Debugging options:\n"
           "  -g, --no-color          toggle using of colors\n"
           "  -a, --abstraction=NAME  mixer abstraction level: none/basic"));
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

git提交

我们认为我们修改OK了,也不用编译和认证了。直接提交加速我们的进程~

[alsa-utils]$ git status
位于分支 devtool
尚未暂存以备提交的变更:
  (使用 "git add <文件>..." 更新要提交的内容)
  (使用 "git checkout -- <文件>..." 丢弃工作区的改动)

        修改:     alsamixer/cli.c

修改尚未加入提交(使用 "git add" 和/或 "git commit -a"[alsa-utils]$ git diff
diff --git a/alsamixer/cli.c b/alsamixer/cli.c
index fe00d31..ab25686 100644
--- a/alsamixer/cli.c
+++ b/alsamixer/cli.c
@@ -37,7 +37,7 @@ static struct snd_mixer_selem_regopt selem_regopt = {
 
 static void show_help(void)
 {
-       puts(_("Usage: alsamixer [options], hello fulinux!"));
+       puts(_("Usage: alsamixer [options], hello fulinux! hello yocto"));
        puts(_("Useful options:\n"
               "  -h, --help              this help\n"
               "  -c, --card=NUMBER       sound card number or id\n"
[alsa-utils]$ git add -u
[alsa-utils]$ git commit -m "add hello yocto in alsamixer help"
[devtool 37e4d5e] add hello yocto in alsamixer help
 1 file changed, 1 insertion(+), 1 deletion(-)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28

执行devtool update-recipe命令

我们将生成的补丁放到meta-mylayer中,执行结果如下:

[build]$ devtool update-recipe alsa-utils -a ../meta-mylayer/
NOTE: Starting bitbake server...
NOTE: Reconnecting to bitbake server...
NOTE: Retrying server connection (#1)...
Loading cache: 100% |#####################################################################################################| Time: 0:00:00
Loaded 1321 entries from dependency cache.
Parsing recipes: 100% |###################################################################################################| Time: 0:00:00
Parsing of 782 .bb files complete (779 cached, 3 parsed). 1323 targets, 46 skipped, 0 masked, 0 errors.
NOTE: Writing append file /home/peeta/poky/meta-mylayer/recipes-multimedia/alsa/alsa-utils_1.2.1.bbappend
NOTE: Copying 0001-add-hello-yocto-in-alsamixer-help.patch to /home/peeta/poky/meta-mylayer/recipes-multimedia/alsa/alsa-utils/0001-add-hello-yocto-in-alsamixer-help.patch
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

查看下更新内容

看放在meta-mylayer中的补丁:

[build]$ cat ../meta-mylayer/recipes-multimedia/alsa/alsa-utils/0001-add-hello-yocto-in-alsamixer-help.patch
From 37e4d5e23abb78e142a0815615429509b63c92d0 Mon Sep 17 00:00:00 2001
From: Peeta Chen <peeta.chen@quectel.com>
Date: Wed, 28 Oct 2020 20:07:28 +0800
Subject: [PATCH] add hello yocto in alsamixer help

---
 alsamixer/cli.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/alsamixer/cli.c b/alsamixer/cli.c
index fe00d31..ab25686 100644
--- a/alsamixer/cli.c
+++ b/alsamixer/cli.c
@@ -37,7 +37,7 @@ static struct snd_mixer_selem_regopt selem_regopt = {
 
 static void show_help(void)
 {
-       puts(_("Usage: alsamixer [options], hello fulinux!"));
+       puts(_("Usage: alsamixer [options], hello fulinux! hello yocto"));
        puts(_("Useful options:\n"
               "  -h, --help              this help\n"
               "  -c, --card=NUMBER       sound card number or id\n"
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23

看append文件

[build]$ cat ../meta-mylayer/recipes-multimedia/alsa/alsa-utils_1.2.1.bbappend #这个文件好像是这次生成的
FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"

SRC_URI += "file://0001-add-hello-yocto-in-alsamixer-help.patch"

[build]$ cat ../meta-mylayer/recipes-multimedia/alsa/alsa-utils_%.bbappend 
FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"

SRC_URI += "file://0001-alsamixer-test-devtool-modify.patch"
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

结束我们的修改

还记的如何结束我们的修改吗?参考如下:

[build]$ devtool finish alsa-utils meta-mylayer
NOTE: Starting bitbake server...
NOTE: Reconnecting to bitbake server...
NOTE: Retrying server connection (#1)...
Loading cache: 100% |#####################################################################################################| Time: 0:00:00
Loaded 1321 entries from dependency cache.
Parsing recipes: 100% |###################################################################################################| Time: 0:00:00
Parsing of 782 .bb files complete (779 cached, 3 parsed). 1323 targets, 46 skipped, 0 masked, 0 errors.
NOTE: Writing append file /home/peeta/poky/meta-mylayer/recipes-multimedia/alsa/alsa-utils_%.bbappend
NOTE: Copying 0001-add-hello-yocto-in-alsamixer-help.patch to /home/peeta/poky/meta-mylayer/recipes-multimedia/alsa/alsa-utils/0001-add-hello-yocto-in-alsamixer-help.patch
INFO: Cleaning sysroot for recipe alsa-utils...
INFO: Leaving source tree /home/peeta/poky/build/workspace/sources/alsa-utils as-is; if you no longer need it then please delete it manually
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

奇怪的一点是怎么又修改了meta-mylayer/recipes-multimedia/alsa/alsa-utils_%.bbappend文件呢?但是实际上并没有,如下所示:

[build]$ cat ../meta-mylayer/recipes-multimedia/alsa/alsa-utils_%.bbappend
FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"

SRC_URI += "file://0001-alsamixer-test-devtool-modify.patch"
  • 1
  • 2
  • 3
  • 4

最后我们删除修改的目录:

[build]$ rm -rf workspace/sources/alsa-utils
  • 1

最后验证

最后我们按照之前的方法编译到文件系统中进行验证:

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

运行qemu机器:

[build]$ runqemu qemux86-64 &  #直接在后台运行
  • 1

登录执行程序

[build]$ ssh root@192.168.7.2              
ssh: connect to host 192.168.7.2 port 22: Connection refused #系统还没有起来
[build]$ ssh root@192.168.7.2
ssh: connect to host 192.168.7.2 port 22: Connection refused
[build]$ ssh root@192.168.7.2
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
SHA256:1pmXwoYGs6dYx0fQDhlK20FB5Pj39HBCb00Gq3xv1Go.
Please contact your system administrator.
Add correct host key in /home/peeta/.ssh/known_hosts to get rid of this message.
Offending RSA key in /home/peeta/.ssh/known_hosts:13
  remove with:
  ssh-keygen -f "/home/peeta/.ssh/known_hosts" -R 192.168.7.2
RSA host key for 192.168.7.2 has changed and you have requested strict checking.
Host key verification failed.
[build]$ ssh-keygen -f "/home/peeta/.ssh/known_hosts" -R 192.168.7.2
# Host 192.168.7.2 found: line 13
/home/peeta/.ssh/known_hosts updated.
Original contents retained as /home/peeta/.ssh/known_hosts.old
[build]$ ssh root@192.168.7.2
The authenticity of host '192.168.7.2 (192.168.7.2)' can't be established.
RSA key fingerprint is SHA256:1pmXwoYGs6dYx0fQDhlK20FB5Pj39HBCb00Gq3xv1Go.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.7.2' (RSA) to the list of known hosts.
root@qemux86-64:~# alsamixer --help
Usage: alsamixer [options], hello fulinux! hello yocto
Useful options:
  -h, --help              this help
  -c, --card=NUMBER       sound card number or id
  -D, --device=NAME       mixer device name
  -V, --view=MODE         starting view mode: playback/capture/all
Debugging options:
  -g, --no-color          toggle using of colors
  -a, --abstraction=NAME  mixer abstraction level: none/basic
root@qemux86-64:~# 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40

可以看到alsamixer --help打印的第一行多了“hello yocto”字符串。
OK我们的工作完成了!