[yocto]使用devtool工具创建配方文件

1. devtool创建新的工作环境

在使用devtool之前需要先搭建poky环境,并且需要引用poky的构建环境;见之前的文章
基于poky项目创建自己的层并且在层中增加自己的配方文件

创建工作环境

  • 使用devtool创建workspace需要指定路径,否则默认在当前目录下创建新层
devtool create-workspace meta-devtool
~/test/poky$ bitbake-layers show-layers
NOTE: Starting bitbake server...
layer                 path                                                                    priority
========================================================================================================
core                 /xxx/test/poky/meta                                   5
yocto                /xxx/test/poky/meta-poky                              5
yoctobsp             /xxx/test/poky/meta-yocto-bsp                         5
meta-test            /xxx/test/poky/meta-test                              6
workspacelayer       /xxx/test/poky/meta-devtool                           99
  • 新增的层名字为workspacelayer,路径为/xxx/test/poky/meta-devtool

2. 生成配方文件

  • a.源保存在网络外部镜像中

    devtool add recipe fetchuri
    
    • 本例源来自网络外部;源被下载到工作目录下的sources目录,生成一个bbappend配方文件继承externalsrc类来指向源;

    • command

      devtool add hello https://ftp.gnu.org/gnu/hello/hello-2.12.tar.gz
      
      ~/test/poky/meta-devtool$ tree -L 1
      .
      ├── appends
      ├── conf
      ├── README
      ├── recipes
      └── sources
      
    • hello_2.12.1-6fe9.bbappend

      inherit externalsrc
      EXTERNALSRC = "/xxx/test/poky/meta-devtool/sources/hello"
      
      # initial_rev: 645b54bc75f055185b26d766a7d713871eec4152
      
  • b.源保存在本地,但不保存当前工作区中

    devtool add recipe srctree
    
    • 本例源来自于本地的meta-test/recipes-test/hello/hello-1.0,所以生成的配方文件SRC_URI为空,且在append文件中追加了源的本地路径

    • command

      devtool add hello meta-test/recipes-test/hello/hello-1.0/
      
      .
      ├── appends
      │   └── hello.bbappend
      ├── conf
      │   └── layer.conf
      ├── README
      └── recipes
          └── hello
              └── hello.bb
      
      4 directories, 4 files
      
    • hello.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.)
      
      # Unable to find any files that looked like license statements. Check the accompanying
      # documentation and source headers and set LICENSE and LIC_FILES_CHKSUM accordingly.
      #
      # NOTE: LICENSE is being set to "CLOSED" to allow you to at least start building - if
      # this is not accurate with respect to the licensing of the software being built (it
      # will not be in most cases) you must specify the correct value before using this
      # recipe for anything other than initial testing/development!
      LICENSE = "CLOSED"
      LIC_FILES_CHKSUM = ""
      
      # No information for SRC_URI yet (only an external source tree was specified)
      SRC_URI = ""
      
      # NOTE: no Makefile found, unable to determine what needs to be done
      
      do_configure () {
      	# Specify any needed configure commands here
      	:
      }
      
      do_compile () {
      	# Specify compilation commands here
      	:
      }
      
      do_install () {
      	# Specify install commands here
      	:
      }
      
    • hello.bbappend

      inherit externalsrc
      EXTERNALSRC = "/xxx/test/poky/meta-test/recipes-test/hello/hello-1.0"
      EXTERNALSRC_BUILD = "/xxx/test/poky/meta-test/recipes-test/hello/hello-1.0"
      
  • c. 源保存在网络外部镜像中,但fetch获取保存在工作区外

    devtool add recipe srctree fetchuri
    
    • 本例中源被网络下载并且保存到 ../meta-test/recipes-test/mysource
    • command
      devtool add hello ../meta-test/recipes-test/mysource https://ftp.gnu.org/gnu/hello/hello-2.12.tar.gz
      
      .
      ├── appends
      │   └── hello_2.12.1-6fe9.bbappend
      ├── conf
      │   └── layer.conf
      ├── README
      └── recipes
          └── hello
              └── hello_2.12.1-6fe9.bb
      
    • hello.bbappend
      inherit externalsrc
      EXTERNALSRC = "/home/wjzhang/poky/test/111/poky/meta-test/recipes-test/mysource"
      
      # initial_rev: 7b0ae8a9f30fd8f0c2b1f5e9de66317cd78964e5
      

3 编辑修改配方文件

devtool edit-recipe recipe
  • 以修改hello的配方文件为例
    devtool edit-recipe hello
    

4 编译目标

devtool build recipe

构建包含所有来自workspace层的菜谱的镜像

devtool build-image <image-name>

5 部署包到目标系统

可以将构建完成的包部署到目标系统上,目标系统可以是实际硬件或者QEMU;唯一要求是目标系统必须是运行着SSH的服务器

devtool deploy-target recipe target

从目标系统移除包

devtool undeploy-target recipe target

6 完成配方上的工作

devtool finish recipe layer

命令创建和本地git仓库中的提交相对应的补丁,将新配方移到更永久的层,然后重置配方,使配方正常构建而不是从工作区构建