yocto-第16篇-devtool upgrade命令

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

问题出发点

现在考虑这么个情况:已知某个recipe最近更新了一个版本,然后修复了一个重要的bug,但是此时我们的这个recipe还是上一个版本,该如何升级recipe呢?

devtool upgrade命令

devtool upgrade命令能将现有recipe升级到上游已知的最新版本。在软件的整个生命周期中,recipe均由其上游发行商或开发者不断进行版本的升级,可以使用devtool update命令来确保构建的recipe与上游的recipe是最新的。devtool upgrade命令很灵活,可以指定源代码修订和版本。也会将对应的recipe源码提取到workspace目录中,每个recipe可以支持多种形式的源码和不同的URL参数。
在这里插入图片描述

该命令的帮助信息

看帮助信息可知该命令功能复杂,很强大!

build]$ devtool upgrade --help
NOTE: Starting bitbake server...
usage: devtool upgrade [-h] [--version VERSION] [--srcrev SRCREV]
                       [--srcbranch SRCBRANCH] [--branch BRANCH] [--no-patch]
                       [--no-overrides] [--same-dir | --no-same-dir]
                       [--keep-temp] [--keep-failure]
                       recipename [srctree]

Upgrades an existing recipe to a new upstream version. Puts the upgraded
recipe file into the workspace along with any associated files, and extracts
the source tree to a specified location (in case patches need rebasing or
adding to as a result of the upgrade).

arguments:
  recipename            Name of recipe to upgrade (just name - no version,
                        path or extension)
  srctree               Path to where to extract the source tree. If not
                        specified, a subdirectory of
                        /home/peeta/poky/build/workspace/sources will be used.

options:
  -h, --help            show this help message and exit
  --version VERSION, -V VERSION
                        Version to upgrade to (PV). If omitted, latest
                        upstream version will be determined and used, if
                        possible.
  --srcrev SRCREV, -S SRCREV
                        Source revision to upgrade to (useful when fetching
                        from an SCM such as git)
  --srcbranch SRCBRANCH, -B SRCBRANCH
                        Branch in source repository containing the revision to
                        use (if fetching from an SCM such as git)
  --branch BRANCH, -b BRANCH
                        Name for new development branch to checkout (default
                        "devtool")
  --no-patch            Do not apply patches from the recipe to the new source
                        code
  --no-overrides, -O    Do not create branches for other override
                        configurations
  --same-dir, -s        Build in same directory as source
  --no-same-dir         Force build in a separate build directory
  --keep-temp           Keep temporary directory (for debugging)
  --keep-failure        Keep failed upgrade recipe and associated files (for
                        debugging)
  • 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

使用举例learnyocto

这里我们继续使用前面章节中创建的一个recipe: learnyocto项目。我们在git仓库中master分支修改源码,并打上tag, 升级我们的版本到v1.1,让后提交,此时我们yoco里面的recipe并不清楚我们的版本有升级,还是使用了先前的develop分支上最新的提交。

更新learnyocto代码

如果没有源码,通过下面的方式拉取代码:

$ cd ~/
~$ git clone https://gitee.com/fulinux/learnyocto #换成自己的链接哦
  • 1
  • 2

开始切换到master分支:

$ cd learnyocto/
[learnyocto]$ git checkout master
切换到分支 'master'
您的分支领先 'origin/master' 共 1 个提交。
  (使用 "git push" 来发布您的本地提交)
[learnyocto]$ git tag
v1.0
[learnyocto]$ git log
ed0cbaa 修改readme文件 (Peeta Chen, 12 天前)
e046070 修改main.c (Peeta Chen, 2 周前)
351e99f 第一次代码 (Peeta Chen, 2 周前)
83f1936 Initial commit (fulinux, 2 周前)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

修改learnyocto

修改源码,加个打印:

[learnyocto]$ vim main.c
  • 1
#include <stdio.h>

int main (int argc, char **argv)
{
    printf ("[master branch]Hello Yocto!\n");//change develop to master
    printf ("Learn devtool upgrade command\n"); //新添加的一行

    return 0;
} /* ----- End of main() ----- */
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

git提交打tag

提交并打上tag v1.1版本,并提交到gitee服务器上去:

[learnyocto]$ git add main.c
[learnyocto]$ git commit -m "learn devtool upgrade command"
[learnyocto]$ git tag v1.1
[learnyocto]$ git push origin master
[learnyocto]$ git push origin v1.1
  • 1
  • 2
  • 3
  • 4
  • 5

OK,到目前为止我们的准备工作完成了。

使用devtool upgrade命令

我前面使用的learnyocto项目使用的是develop分支的内容,现在我们准备将其升级到v1.1版本,操作如下:

[build]$ devtool upgrade -V v1.1 learnyocto

NOTE: Starting bitbake server...
ERROR: recipe learnyocto is already in your workspace
  • 1
  • 2
  • 3
  • 4

提示说我们的项目已经在workspace中了。此时改如何办呢?难道直接删除workspace/sources/learnyocto吗,不对!我们借鉴前面的方法,将learnyocto添加到meta-mylayer中去,这样一来,就解决了该问题,操作如下:

[build]$ devtool finish learnyocto meta-mylayer
NOTE: Starting bitbake server...
ERROR: Source tree is not clean:

 M main.c

Ensure you have committed your changes or use -f/--force if you are sure there's nothing that needs to be committed
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

提示我们main.c文件有修改,我们去看看:

[learnyocto]$ git diff
diff --git a/main.c b/main.c
index 2384495..b02aa9f 100644
--- a/main.c
+++ b/main.c
@@ -3,6 +3,7 @@
 int main (int argc, char **argv)
 {
     printf ("[develop branch]Hello Yocto!\n");
+    printf ("[develop branch]learn devtool deploy-target\n");
 
     return 0;
 } /* ----- End of main() ----- */
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

由此可见我们前面执行devtool upgrade命令对其有影响,由此这里我们将该修改撤销:

[learnyocto]$ git checkout -- main.c
  • 1

再次执行devtool finish命令

执行如下:

[build]$ devtool finish learnyocto 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 (780 cached, 2 parsed). 1323 targets, 46 skipped, 0 masked, 0 errors.
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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

这样我们的learnyocto项目就添加到了自己的meta-mylayer层中了,查看:

[build]$ ls ../meta-mylayer/
conf  COPYING.MIT  README  recipes-core  recipes-example  recipes-learnyocto  recipes-multimedia
[build]$ tree ../meta-mylayer/recipes-learnyocto/
../meta-mylayer/recipes-learnyocto/
└── learnyocto
    └── learnyocto_git.bb

1 directory, 1 file
[build]$ 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
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30

OK,这个learnyocto recipe已经加入到了meta-mylayer中了,我们就可以安心的删除workspace/sources/learnyocto了,如下:

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

再用devtool upgrade命令

[build]$ devtool upgrade -V v1.1 learnyocto
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.
ERROR: Recipe specifies a SRCREV value; you must specify a new one when upgrading
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

不过提示错了,recipe需要指定一个SRCREV值,查看devtool upgrade的帮助信息:

  --srcrev SRCREV, -S SRCREV
                        Source revision to upgrade to (useful when fetching
                        from an SCM such as git)
  • 1
  • 2
  • 3

因为是git项目,需要使用参数"–srcrev"或者"-s" 然后加上源码的版本,因此命令修改如下:

[build]$ devtool upgrade -S v1.1 learnyocto 
NOTE: Starting bitbake server...
NOTE: Reconnecting to bitbake server...
NOTE: Retrying server connection (#1)...
Loading cache: 100% |################################################################################| Time: 0:00:00
Loaded 1322 entries from dependency cache.
Parsing recipes: 100% |##############################################################################| Time: 0:00:00
Parsing of 782 .bb files complete (781 cached, 1 parsed). 1323 targets, 46 skipped, 0 masked, 0 errors.
INFO: Extracting current version source...
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: Extracting upgraded version source...
INFO: Upgraded source extracted to /home/peeta/poky/build/workspace/sources/learnyocto
INFO: New recipe is /home/peeta/poky/build/workspace/recipes/learnyocto/learnyocto_git.bb
  • 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

此时我的项目就成功更新了,验证如下:

[build]$ cd workspace/sources/learnyocto/
[learnyocto]$ git log #每个人的log格式可能不一样,这里我的配置不同
* cac0e57 - (HEAD -> devtool, tag: v1.1, tag: devtool-patched-new, tag: devtool-base-new, origin/master, origin/HEAD) learn devtool upgrade command (7 天前) <Peeta Chen>
* ed0cbaa - 修改readme文件 (3 周前) <Peeta Chen>
* e046070 - (tag: v1.0, master) 修改main.c (3 周前) <Peeta Chen>
* 351e99f - (tag: devtool-patched, tag: devtool-base, origin/develop, devtool-orig, develop) 第一次代码 (3 周前) <Peeta Chen>
* 83f1936 - Initial commit (3 周前) <fulinux>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

log的第一条信息就可以知道当前的提交就是tag v1.1

查看代码

[learnyocto]$ cat main.c 
#include <stdio.h>

int main (int argc, char **argv)
{
    printf ("[master branch]Hello Yocto!\n");//change develop to master
    printf ("Learn devtool upgrade command\n");

    return 0;
} /* ----- End of main() ----- */
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

如你所见已经添加了最新的一行。

编译新版本

[learnyocto]$ cd -
/home/peeta/poky/build
[build]$ devtool build learnyocto
  • 1
  • 2
  • 3

在线部署验证

最好是在另外两个终端中操作:

[build]$ runqemu qemux86-64
  • 1

ssh登录系统
确认系统已启动,并为了后续验证使用:

[~]$ ssh root@192.168.7.2
ssh: connect to host 192.168.7.2 port 22: Connection refused
[~]$ ssh root@192.168.7.2
ssh: connect to host 192.168.7.2 port 22: Connection refused
[ ~]$ ssh root@192.168.7.2
ssh: connect to host 192.168.7.2 port 22: Connection refused
[~]$ ssh root@192.168.7.2
root@qemux86-64:~#   
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

这样能登录说明已启动
将其部署到用户根目录下,便于直观的知道部署了哪些文件:

[build]$ devtool deploy-target learnyocto root@192.168.7.2:~/
  • 1

验证结果如下:

root@qemux86-64:~# ls
usr
root@qemux86-64:~# ./usr/bin/learnyocto 
[master branch]Hello Yocto!
Learn devtool upgrade command   #可见这是我们新加入的一行
root@qemux86-64:~# 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

收尾工作

到了这里你以为我们的工作完了吗?错误,还有重要的工作,就是讲recipe添加到layer中,devtool只是为了方便开发,而实际真正将项目整合到yocto项目中还没有完成,操作如下:

[build]$ devtool finish learnyocto ../meta-mylayer
NOTE: Starting bitbake server...
NOTE: Reconnecting to bitbake server...
NOTE: Retrying server connection (#1)...
Loading cache: 100% |################################################################################| Time: 0:00:00
Loaded 1322 entries from dependency cache.
Parsing recipes: 100% |##############################################################################| Time: 0:00:00
Parsing of 783 .bb files complete (780 cached, 3 parsed). 1324 targets, 46 skipped, 0 masked, 0 errors.
INFO: No patches or files need updating
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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

查看下bb文件

[build]$ tree ../meta-mylayer/recipes-learnyocto/
../meta-mylayer/recipes-learnyocto/
└── learnyocto
    └── learnyocto_git.bb

1 directory, 1 file
[build]$ 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 = "v1.1"

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
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28

对比一下之前的内容就是更改了SRCREV消息

综上我们的任务完成~