yocto-第3篇-meta layer recipe class

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

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

今天简单讲几个概念和目录:metadata、class、conf和recipes等,还有一些开源的metadata从哪里获取等。
在这里插入图片描述

metadata

元数据(metadata)是什么呢?metadata中包括共享的配置(比如说qemux86-64.conf机器配置),全局变量定义(比如内核用哪个使用什么版本,机器镜像有哪些特性功能等,比如前面的x11、screen、alsa等等),共享的class类(比如 meta/classes ),包装(比如 meta/lib/ )和 recipes 配方。metadata和layers通常可以理解成一个东西,落实到我们能看见的就比如下面这些:

poky]$ ls | grep "^meta"
meta #yocto基础的layer
meta-freescale #飞思卡尔的layer
meta-mybsp #自己的bsp layer
meta-mylayer #自己的layer
meta-poky #yocto的poky发行版本layer
meta-qcom #这个是高通的layer
meta-qt5 #Qt5的layer
meta-selftest #自我测试的layer
meta-skeleton #骨架,很多例子
meta-yocto-bsp #yocto官方提供的参考bsp layer
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

layers

这个layers层是包含相关指令和配置集合的仓库(或者说是目录),这些指令和配置用来告诉Yocto该做什么。将相关metadata元数据分开到特定功能的layers层中有助于模块化开发,降低了耦合度,以便于以后可以重复利用meta layer。比如与特定机器相关的内容放在一个A layer(通常就是bsp layer)中,有些和机器无关的一些库和软件等项目可以放在另外一个B layer中,当特定的机器发生了改变,只需修改A layer或者新增另一个C layer,而不需要改动B layer,极大的避免的重复开发问题。

A layer
B layer
C layer

classes

classes 类定义了构建具有逻辑的封装和继承,有些linux的bb文件就继承了linux相关的一些class类(例如kernel-yocto.bbclass),继承这些类的kernel recipe bb文件就不需要我们为内核的下载、config配置、编译和安装等任务做太多任务,linux的类有:

poky]$ ls meta/classes/kernel*
meta/classes/kernel-arch.bbclass          meta/classes/kernelsrc.bbclass
meta/classes/kernel.bbclass               meta/classes/kernel-uboot.bbclass
meta/classes/kernel-fitimage.bbclass      meta/classes/kernel-uimage.bbclass
meta/classes/kernel-grub.bbclass          meta/classes/kernel-yocto.bbclass
meta/classes/kernel-module-split.bbclass
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

第三方应用项目也有很多class类,比如有些项目是用cmake构建的,可以继承 meta/classes/cmake.bbclass ,你就可以省去cmake项目应该怎么构建的烦恼。

上面提及的linux类和cmake类怎么继承呢?看几个例子:

#poky/meta/recipes-kernel/linux/linux-yocto.inc
inherit kernel 
inherit kernel-yocto
...
#poky/meta/recipes-support/libical/libical_3.0.8.bb
inherit cmake pkgconfig
...
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

使用到了 inherit 关键词。

recipes

recipes 配方是要构建的软件和镜像(内核镜像、文件系统镜像等)的逻辑单元,它是构建一个项目的基本,通常对于这个若干个bb文件,包括bbappend文件。recipes通常是放在metadata layers目录中,会继承上面提及的一些class类。大致如下:

meta-xxx/recipes-abc/abc.bb
  • 1

如果想知道自己的yocto有那些recipes,可以通过下面的命令查看:

build]$ bitbake-layers show-recipes
  • 1

我们简单看下 meta/recipes.txt 中内容描述:

recipes-bsp          - Anything with links to specific hardware or hardware configuration information
recipes-connectivity - Libraries and applications related to communication with other devices 
recipes-core         - What's needed to build a basic working Linux image including commonly used dependencies
recipes-devtools     - Tools primarily used by the build system (but can also be used on targets)
recipes-extended     - Applications which whilst not essential add features compared to the alternatives in
                       core. May be needed for full tool functionality.
recipes-gnome        - All things related to the GTK+ application framework
recipes-graphics     - X and other graphically related system libraries  
recipes-kernel       - The kernel and generic applications/libraries with strong kernel dependencies
recipes-multimedia   - Codecs and support utilties for audio, images and video
recipes-rt           - Provides package and image recipes for using and testing the PREEMPT_RT kernel
recipes-sato         - The Sato demo/reference UI/UX, its associated apps and configuration 
recipes-support      - Recipes used by other recipes but that are not directly included in images
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

对应的翻译:

recipes-bsp—任何带有特定硬件或硬件配置信息链接的内容
recip- connectivity -与其他设备通信相关的库和应用程序
recipes-core—构建包括常用依赖项在内的基本工作Linux映像所需要的内容
recipes-devtools——主要用于构建系统的工具(但也可以用于目标)
recipes-extended -与内核中的替代方案相比,这些应用程序虽然不是必不可少的,但却可以添加一些特性。可能需要完整的工具功能。
所有与GTK+应用程序框架相关的内容
recipes-graphics ---X和其他图形相关的系统库
recipes-kernel—具与内核有强依赖性的通用应用程序或者库
recipes-multimedia --音频、图像和视频的编解码器和支持应用程序
recipes-rt——提供用于使用和测试PREEMPT_RT内核的包和映像食谱
recipes-sato  参考UI/UX,相关的应用程序和配置
recipes-support——其他食谱使用的食谱,但没有直接包含在图片中
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

添加开源的meta layer:

meta layer有很多开源的项目,各大厂家也会有自己的meta layer(比如高通的meta-qcom、飞思卡尔的meta-freescale,还有linphone、qt的项目等都有自己的meta layer),感兴趣的可以在
http://git.yoctoproject.org/
http://layers.openembedded.org/layerindex/branch/master
里面找找,比如添加meta-altera层。

手动下载和添加meta layer

  1. 下载一个layer到poky目录:
$ cd ~/poky
$ git clone https://github.com/kraj/meta-altera.git
  • 1
  • 2

现在,硬件layer与其他layer一起存在于上面poky实例项目中了,meta-altera包含支持altera硬件所需的所有metadata。

  1. 修改上面提及的 poky/build/conf/local.conf 文件中的MACHINE变量为" cyclone5 ",编译的时候就会根据这个变量找到 meta-altera/blob/master/conf/machine/cyclone5.conf 配置文件,并按照这个文件中的规则构建。

  2. 添加你的layer到layer配置文件中,就是在使用前将其添加到build/conf/bblayers.conf文件中。不过不用你编辑文件,可以使用下面的命令实现

$ cd ~/poky/build
$ source oe-init-build-env
$ bitbake-layers add-layer ../meta-altera
NOTE: Starting bitbake server...
Parsing recipes: 100% |##################################################################| Time: 0:00:32
Parsing of 918 .bb files complete (0 cached, 918 parsed). 1401 targets, 123 skipped, 0 masked, 0 errors.
build]$ cat conf/bblayers.conf    
# POKY_BBLAYERS_CONF_VERSION is increased each time build/conf/bblayers.conf
# changes incompatibly
POKY_BBLAYERS_CONF_VERSION = "2"

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

BBLAYERS ?= " \
  /home/peeta/poky/meta \
  /home/peeta/poky/meta-poky \
  /home/peeta/poky/meta-yocto-bsp \
  /home/peeta/poky/meta-altera \ #在这里
  "
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20

注意:上面操作只是演示如何添加第三方meta layer,熟悉后请恢复到初始状态,避免后面混淆

自动化添加meta layer

yocto提供了一个 bitbake-layer 工具可以自行在 http://layers.openembedded.org/layerindex/branch/master 中查找想要的meta layer,比如我想添加TI公司的的layer,对于的名字是 meta-ti ,下面简单演示如何自动化添加:

poky]$ source oe-init-build-env
build]$ bitbake-layers layerindex-fetch -b master meta-ti
Loading https://layers.openembedded.org/layerindex/api/;branch=master...
Layer                                              Git repository (branch)                                 Subdirectory
=============================================================================================================================
local:HEAD:openembedded-core                       git://git.yoctoproject.org/poky (my-yocto-3.2.2)        meta
  required by: meta-ti meta-arm-toolchain meta-arm meta-python meta-oe
layers.openembedded.org:master:meta-arm-toolchain  git://git.yoctoproject.org/meta-arm (master)            meta-arm-toolchain
  required by: meta-arm
layers.openembedded.org:master:meta-oe             git://git.openembedded.org/meta-openembedded (master)   meta-oe
  required by: meta-python
layers.openembedded.org:master:meta-python         git://git.openembedded.org/meta-openembedded (master)   meta-python
  required by: meta-arm
layers.openembedded.org:master:meta-arm            git://git.yoctoproject.org/meta-arm (master)            meta-arm
  required by: meta-ti
layers.openembedded.org:master:meta-ti             git://git.yoctoproject.org/meta-ti (master)             
Cloning into '/home/peeta/poky/meta-arm'...
remote: Enumerating objects: 7308, done.
remote: Counting objects: 100% (7308/7308), done.
remote: Compressing objects: 100% (6063/6063), done.
remote: Total 7308 (delta 4238), reused 1418 (delta 683)
Receiving objects: 100% (7308/7308), 1.42 MiB | 743.00 KiB/s, done.
Resolving deltas: 100% (4238/4238), done.
Checking connectivity... done.
Cloning into '/home/peeta/poky/meta-openembedded'...
remote: Counting objects: 154631, done.
remote: Compressing objects: 100% (51743/51743), done.
remote: Total 154631 (delta 96778), reused 153131 (delta 95918)
Receiving objects: 100% (154631/154631), 40.46 MiB | 3.07 MiB/s, done.
Resolving deltas: 100% (96778/96778), done.
Checking connectivity... done.
Cloning into '/home/peeta/poky/meta-ti'...
remote: Enumerating objects: 36329, done.
remote: Counting objects: 100% (36329/36329), done.
remote: Compressing objects: 100% (11690/11690), done.
remote: Total 36329 (delta 24883), reused 34120 (delta 23222)
Receiving objects: 100% (36329/36329), 9.45 MiB | 586.00 KiB/s, done.
Resolving deltas: 100% (24883/24883), done.
Checking connectivity... done.
Adding layer "meta-arm-toolchain" (/home/peeta/poky/meta-arm/meta-arm-toolchain) to conf/bblayers.conf
Adding layer "meta-oe" (/home/peeta/poky/meta-openembedded/meta-oe) to conf/bblayers.conf
Adding layer "meta-python" (/home/peeta/poky/meta-openembedded/meta-python) to conf/bblayers.conf
Adding layer "meta-arm" (/home/peeta/poky/meta-arm/meta-arm) to conf/bblayers.conf
Adding layer "meta-ti" (/home/peeta/poky/meta-ti/) to conf/bblayers.conf
  • 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

可以看到不光是添加了meta-ti,还添加了其他几个依赖的meta layer,在 build/conf/bblayers.conf 文件中也可以看到:

build]$ cat conf/bblayers.conf    
# POKY_BBLAYERS_CONF_VERSION is increased each time build/conf/bblayers.conf
# changes incompatibly
POKY_BBLAYERS_CONF_VERSION = "2"

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

BBLAYERS ?= " \
  /home/peeta/poky/meta \
  /home/peeta/poky/meta-poky \
  /home/peeta/poky/meta-yocto-bsp \
  /home/peeta/poky/meta-mybsp \
  /home/peeta/poky/meta-mylayer \
  /home/peeta/poky/meta-qt5 \
  /home/peeta/poky/meta-arm/meta-arm-toolchain \
  /home/peeta/poky/meta-openembedded/meta-oe \
  /home/peeta/poky/meta-openembedded/meta-python \
  /home/peeta/poky/meta-arm/meta-arm \
  /home/peeta/poky/meta-ti \
  "
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21

这里我只是演示,演示完之后可以自行将其删除。

注释:由于我添加的这个meta-ti和我现有的版本有点不匹配,编译时会出错,建议删除哦。还有些layer通过这种自动化方式无法实现。

另外还有一个 bitbake-layers remove-layer layerdir 命令可以删除对于的layer.

这里有个添加meta-qt5的例子可以参考: https://fulinux.blog.csdn.net/article/details/116353466

The Yocto Project Layer Model

相关阅读:
The Yocto Project’s “Layer Model” is a development model for embedded and IoT Linux creation that distinguishes the Yocto Project from other simple build systems. The Layer Model simultaneously supports collaboration and customization. Layers are repositories that contain related sets of instructions that tell the OpenEmbedded build system what to do. You can collaborate, share, and reuse layers.
Yocto项目的“Layer Model”是用于嵌入式和IoT Linux创建的开发模型,该模型将Yocto项目与其他简单构建系统区分开来。层模型同时支持协作和定制。层是包含相关指令集的仓库,这些指令集告诉 OpenEmbedded构建系统要做什么。可以协作,共享和复用layers。

Layers can contain changes to previous instructions or settings at any time. This powerful override capability is what allows you to customize previously supplied collaborative or community layers to suit your product requirements.
图层可以随时包含对先前说明或设置的更改。这种强大的覆盖功能可以自定义先前提供的协作层或社区层,以满足您的产品需求。(我的理解:类似C++里面的重载或者devices tree里面dtsi和dts中相同区块内容时会以新的定义为准)

You use different layers to logically separate information in your build. As an example, you could have BSP, GUI, distro configuration, middleware, or application layers. Putting your entire build into one layer limits and complicates future customization and reuse. Isolating information into layers, on the other hand, helps simplify future customizations and reuse. You might find it tempting to keep everything in one layer when working on a single project. However, the more modular your Metadata, the easier it is to cope with future changes.

您使用不同的层在逻辑上分离构建中的信息。例如,您可能具有BSP,GUI,发行版配置,中间件或应用程序层。如果将整个项目放到一个层次上构建,会限制将来的自定义和复用,并使其复杂化。另一方面,将信息隔离到层中有助于简化将来的自定义和复用。当您在一个项目上工作时,可能会将所有内容保持在一层中。但是,元数据越模块化,就越容易应对未来的变化。(我的理解:比如bootloader、linux内核等于硬件强相关的项目放到BSP层、与底层硬件耦合性不强的可以放到另一个层中,可以实现层与层的分离,改动某个层不影响另外的层,方便每个层的修改和复用)

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