Yocto创建自己的meta-layer

1. 设置编译环境

2. 新建自己的layer

$cd poky //因为bitbake-layers create-layer会在当前所在目录创建meta-test.所以先进入poky目录

$bitbake-layers create-layer meta-test

NOTE: Starting bitbake server...
Add your new layer with 'bitbake-layers add-layer meta-test'

  默认的layer 优先级是6,如果你想改变优先级,可以通过--priority选项来设置。或者直接修改meta-test/conf/layer.conf中的BBFILE_PRIORITY的值。

#We have a conf and classes directory, add to BBPATH
BBPATH .= ":${LAYERDIR}"

#We have recipes-* directories, add to BBFILES
BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \
           "${LAYERDIR}/recipes-*/*/*.bbappend

BBFILE_COLLECTIONS += "meta-test"
BBFILE_PATTERN_meta-test = "^${LAYERDIR}/"

BBFILE_PRIORITY_meta-test = 6

LAYERDEPENDS_meta-test = "core"
LAYERSERIES_COMPAT_meta-test = "dunfell"
  • BBPATH: Adds the layer's root directory to BitBake's search path. Through the use of the BBPATH variable, BitBake locates class files (.bbclass), configuration files, and files that are included with include and require statements. For these cases, BitBake uses the first file that matches the name found in BBPATH. This is similar to the way the PATH variable is used for binaries. It is recommended, therefore, that you use unique class and configuration filenames in your custom layer. 把LAYER的目录加入Bitbake的搜索路径中。通过BBPATH,bitbake定位.bbclass,conf,include和 require的文件。bitbake使用与BBPATH名字匹配的第一个文件。建议创建属于你的唯一名字的配置文件,class文件。

  • BBFILES: Defines the location for all recipes in the layer. 定义Layer中所有的recipes的路径

  • BBFILE_COLLECTIONS: Establishes the current layer through a unique identifier that is used throughout the OpenEmbedded build system to refer to the layer. In this example, the identifier "test" is the representation for the container layer named "meta-test". 创建一个唯一标识符给OE构建系统参照。这个例子中是meta-test。

  • BBFILE_PATTERN: Expands immediately during parsing to provide the directory of the layer. 在解析期间立即展开以提供Layer的目录。

  • BBFILE_PRIORITY: Establishes a priority to use for recipes in the layer when the OpenEmbedded build finds recipes of the same name in different layers. 当meta-test下的recipes-*名字与其他layer中的recipes名字相同,那么OE构建系统会根据recipes的优先级来构建。假如meta-test中的recipes优先级更高但是版本较低(recipes-application/camera/camera.1.0.0.bb),即使其他layer中相同名字的recipes版本号较高recipes-application/camera/camera.1.0.5.bb,OE也会优先构建meta-test中的recipes。

  • LAYERVERSION: Establishes a version number for the layer. You can use this version number to specify this exact version of the layer as a dependency when using the LAYERDEPENDS variable. Layer的版本号。你可以通过LAYERDEPENDS变量指定使用特定版本号的Layer

  • LAYERDEPENDS: Lists all layers on which this layer depends (if any). 如果该Layer依赖其他layer,LAYERDEPENDS列出其依赖的所有LAYER

  • LAYERSERIES_COMPAT: Lists the Yocto Project releases for which the current version is compatible. This variable is a good way to indicate if your particular layer is current.

上面的内容只是通过bitbake-layers脚本创建的例子,实际配置你的recipes时,最直接的方式是拷贝其他recipes中的bbfile内容到你的bb文件中,然后修改。

注意事项:

a. 配置你自己的recipes时,请不要将其他layer中的recipes-*直接拷贝到你的layer中进行配置。

这样你的配置可能会覆盖其他layer中的配置。 请使用bbappend来实现你对其他layer/recipes的修改。

b. 对于使用include文件的recipe,请使用附加文件(.bbappend)。

或者,如果要引入需要include的新recipe,请使用相对于原始LAYER目录的路径来引用该文件。 例如,使用require recipes-core / package / file.inc代替require file.inc。 如果发现必须覆盖包含文件,则可能表明包含文件在其最初所属的LAYER中有不足之处。 在这种情况下,应该尝试解决该缺陷而不要覆盖include文件。 例如,您可以通过使包含文件的维护者添加一个或多个变量来解决此问题,从而轻松地覆盖需要覆盖的部分。

c. 将你layer结构化:

Proper use of overrides within append files and placement of machine-specific files within your layer can ensure that a build is not using the wrong Metadata and negatively impacting a build for a different machine.例如,

--可以修改变量值,支持构建不同的machine:

Suppose you have a layer named meta-one that adds support for building machine "one". To do so, you use an append file named base-files.bbappend and create a dependency on "foo" by altering the DEPENDS variable:

     DEPENDS = "foo"
                                

The dependency is created during any build that includes the layer meta-one. However, you might not want this dependency for all machines. For example, suppose you are building for machine "two" but your bblayers.conf file has the meta-one layer included. During the build, the base-files for machine "two" will also have the dependency on foo.

To make sure your changes apply only when building machine "one", use a machine override with the DEPENDS statement:

     DEPENDS_one = "foo"
                                

You should follow the same strategy when using _append and _prepend operations:

     DEPENDS_append_one = " foo"
     DEPENDS_prepend_one = "foo "

As an actual example, here's a snippet from the generic kernel include file linux-yocto.inc, wherein the kernel compile and link options are adjusted in the case of a subset of the supported architectures:

     DEPENDS_append_aarch64 = " libgcc"
     KERNEL_CC_append_aarch64 = " ${TOOLCHAIN_OPTIONS}"
     KERNEL_LD_append_aarch64 = " ${TOOLCHAIN_OPTIONS}"

     DEPENDS_append_nios2 = " libgcc"
     KERNEL_CC_append_nios2 = " ${TOOLCHAIN_OPTIONS}"
     KERNEL_LD_append_nios2 = " ${TOOLCHAIN_OPTIONS}"

     DEPENDS_append_arc = " libgcc"
     KERNEL_CC_append_arc = " ${TOOLCHAIN_OPTIONS}"
     KERNEL_LD_append_arc = " ${TOOLCHAIN_OPTIONS}"

     KERNEL_FEATURES_append_qemuall=" features/debug/printk.scc"

d. 不同machine的文件,应该放在对应machine的目录下: 

When you have a base recipe, such as base-files.bb, that contains a SRC_URI statement to a file, you can use an append file to cause the build to use your own version of the file. For example, an append file in your layer at meta-one/recipes-core/base-files/base-files.bbappend could extend FILESPATH using FILESEXTRAPATHS as follows:

     FILESEXTRAPATHS_prepend := "${THISDIR}/${BPN}:"
                                

The build for machine "one" will pick up your machine-specific file as long as you have the file in meta-one/recipes-core/base-files/base-files/. However, if you are building for a different machine and the bblayers.conf file includes the meta-one layer and the location of your machine-specific file is the first location where that file is found according to FILESPATH, builds for all machines will also use that machine-specific file.

You can make sure that a machine-specific file is used for a particular machine by putting the file in a subdirectory specific to the machine. For example, rather than placing the file in meta-one/recipes-core/base-files/base-files/ as shown above, put it in meta-one/recipes-core/base-files/base-files/one/. Not only does this make sure the file is used only when building for machine "one", but the build process locates the file more quickly.

In summary, you need to place all files referenced from SRC_URI in a machine-specific subdirectory within the layer in order to restrict those files to machine-specific builds.

 

3. 使能你的layer

meta-test加进bblayer.conf之后,OE才会构建你的layer。

使用脚本检查你的layer是否与yocto的规则兼容:在poky目录下执行

source oe-init-build-env
yocto-check-layer meta-test/

在build目录下,将meta-test加入 bblayer.conf:

$bitbake-layers add-layer meta-test

$cat conf/local.conf

//你会看到类似下面的内容,最后一行表示meta-test已经加入OE的构建中
     # POKY_BBLAYERS_CONF_VERSION is increased each time build/conf/bblayers.conf
     # changes incompatibly
     POKY_BBLAYERS_CONF_VERSION = "2"

     BBPATH = "${TOPDIR}"
     BBFILES ?= ""

     BBLAYERS ?= " \
       /home/user/poky/meta \
       /home/user/poky/meta-poky \
       /home/user/poky/meta-yocto-bsp \
       /home/user/poky/meta-test \

4. 使用bbappend文件

A recipe that appends Metadata to another recipe is called a BitBake append file. A BitBake append file uses the .bbappend file type suffix, while the corresponding recipe to which Metadata is being appended uses the .bb file type suffix. 一个recipe附加新的设置到另一个recipe中,需要使用append文件。.bbappend是对.bb文件已有设置的重写/附加。

You can use a .bbappend file in your layer to make additions or changes to the content of another layer's recipe without having to copy the other layer's recipe into your layer. Your .bbappend file resides in your layer, while the main .bb recipe file to which you are appending Metadata resides in a different layer. 在你的recipe中修改其他layer的recipe时,你不需要将其他layer的recipe文件拷贝到你的layer目录。而应该用.bbappend文件。

Being able to append information to an existing recipe not only avoids duplication, but also automatically applies recipe changes from a different layer into your layer. If you were copying recipes, you would have to manually merge changes as they occur. 

When you create an append file, you must use the same root name as the corresponding recipe file. For example, the append file someapp_3.1.3.bbappend must apply to someapp_3.1.3.bb. This means the original recipe and append file names are version number-specific. If the corresponding recipe is renamed to update to a newer version, you must also rename and possibly update the corresponding .bbappend as well. During the build process, BitBake displays an error on starting if it detects a .bbappend file that does not have a corresponding recipe with a matching name.  bbappend的根文件名需要与.bb文件根文件名匹配一致。否则bitbake在构件时会报错。

5. 管理你的layer

$ bitbake-layers --help
     NOTE: Starting bitbake server...
     usage: bitbake-layers [-d] [-q] [-F] [--color COLOR] [-h] <subcommand> ...

     BitBake layers utility

     optional arguments:
       -d, --debug           Enable debug output
       -q, --quiet           Print only errors
       -F, --force           Force add without recipe parse verification
       --color COLOR         Colorize output (where COLOR is auto, always, never)
       -h, --help            show this help message and exit

     subcommands:
       <subcommand>
         show-layers         show current configured layers.
         show-overlayed      list overlayed recipes (where the same recipe exists
                             in another layer)
         show-recipes        list available recipes, showing the layer they are
                             provided by
         show-appends        list bbappend files and recipe files they apply to
         show-cross-depends  Show dependencies between recipes that cross layer
                             boundaries.
         add-layer           Add one or more layers to bblayers.conf.
         remove-layer        Remove one or more layers from bblayers.conf.
         flatten             flatten layer configuration into a separate output
                             directory.
         layerindex-fetch    Fetches a layer from a layer index along with its
                             dependent layers, and adds them to conf/bblayers.conf.
         layerindex-show-depends
                             Find layer dependencies from layer index.
         create-layer        Create a basic layer

     Use bitbake-layers <subcommand> --help to get help on a specific command

5. Customizing Images

 

  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值