Yocto
Yocto系列讲解[入门篇] 1 - 快速入门熟悉Yocto的构建
Yocto系列讲解[入门篇] 2 - 演示运行qemux86-64虚拟机
Yocto系列讲解[理论篇] 3 - meta layer recipe class概念介绍
Yocto系列讲解[入门篇] 4 - 创建自己的meta layer
Yocto系列讲解[入门篇] 5 - 在meta-mylayer中添加helloworld recipe
Yocto系列讲解[理论篇] 6 - yocto是什么,学习它不难
Yocto系列讲解[实战篇] 7 - 开发工具devtool实操(创建新项目helloyocto)
Yocto系列讲解[实战篇] 8 - 开发工具devtool实操(添加git项目learnyocto)
Yocto系列讲解[实战篇] 9 - devtool验证并将learnyocto添加到meta-mylayer中
Yocto系列讲解[实战篇] 10 - 在qemux86机器运行时安装程序
Yocto系列讲解[实战篇] 11 - 在qemux86机器运行时卸载删除程序
Yocto系列讲解[实战篇]12 - 修改开源项目的代码(1)
Yocto系列讲解[技巧篇]13 - devtool修改workspace目录位置
Yocto系列讲解[技巧篇]14 - devtool edit-recipe命令(编辑bb文件命令)
本文档使用 MrDoc 发布
-
+
首页
Yocto系列讲解[理论篇] 3 - meta layer recipe class概念介绍
今天简单讲几个概念和目录:metadata、class、conf和recipes等,还有一些开源的metadata从哪里获取等。  ### metadata 元数据(metadata)是什么呢?metadata中包括共享的配置(比如说qemux86-64.conf机器配置),全局变量定义(比如内核用哪个使用什么版本,机器镜像有哪些特性功能等,比如前面的x11、screen、alsa等等),共享的class类(比如meta/classes),包装(比如meta/lib/)和recipes配方。metadata和layers通常可以理解成一个东西,落实到我们能看见的就比如下面这些: ```shell 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 ``` ### layers 这个layers层是包含相关指令和配置集合的仓库(或者说是目录),这些指令和配置用来告诉Yocto该做什么。将相关metadata元数据分开到特定功能的layers层中有助于模块化开发,降低了耦合度,以便于以后可以重复利用meta layer。比如与特定机器相关的内容放在一个A layer(通常就是bsp layer)中,有些和机器无关的一些库和软件等项目可以放在另外一个B layer中,当特定的机器发生了改变,只需修改A layer或者新增另一个C layer,而不需要改动B layer,极大的避免的重复开发问题。 ```mindmap A layer B layer C layer ``` ### classes classes类定义了构建具有逻辑的封装和继承,有些linux的bb文件就继承了linux相关的一些class类(例如kernel-yocto.bbclass),继承这些类的kernel recipe bb文件就不需要我们为内核的下载、config配置、编译和安装等任务做太多任务,linux的类有: ```shell 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 ``` 第三方应用项目也有很多class类,比如有些项目是用cmake构建的,可以继承meta/classes/cmake.bbclass ,你就可以省去cmake项目应该怎么构建的烦恼。 上面提及的linux类和cmake类怎么继承呢?看几个例子: ```shell #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 ... ``` 使用到了inherit关键词。 ### recipes recipes配方是要构建的软件和镜像(内核镜像、文件系统镜像等)的逻辑单元,它是构建一个项目的基本,通常对于这个若干个bb文件,包括bbappend文件。recipes通常是放在metadata layers目录中,会继承上面提及的一些class类。大致如下: ```shell meta-xxx/recipes-abc/abc.bb ``` 如果想知道自己的yocto有那些recipes,可以通过下面的命令查看: ```shell $ bitbake-layers show-recipes ``` 我们简单看下meta/recipes.txt中内容描述: ```shell 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 ``` 对应的翻译: ```shell 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——其他食谱使用的食谱,但没有直接包含在图片中 ``` ### 添加开源的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 下载一个layer到poky目录: ```shell $ cd ~/poky $ git clone https://github.com/kraj/meta-altera.git ``` 现在,硬件layer与其他layer一起存在于上面poky实例项目中了,meta-altera包含支持altera硬件所需的所有metadata。 修改上面提及的poky/build/conf/local.conf文件中的MACHINE变量为"cyclone5",编译的时候就会根据这个变量找到meta-altera/blob/master/conf/machine/cyclone5.conf配置文件,并按照这个文件中的规则构建。 添加你的layer到layer配置文件中,就是在使用前将其添加到build/conf/bblayers.conf文件中。不过不用你编辑文件,可以使用下面的命令实现 ```shell $ 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 \ #在这里 " ``` 注意:上面操作只是演示如何添加第三方meta layer,熟悉后请恢复到初始状态,避免后面混淆 #### 自动化添加meta layer yocto提供了一个bitbake-layer工具可以自行在http://layers.openembedded.org/layerindex/branch/master中查找想要的meta layer,比如我想添加TI公司的的layer,对于的名字是meta-ti,下面简单演示如何自动化添加: ```shell 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 ``` 可以看到不光是添加了meta-ti,还添加了其他几个依赖的meta layer,在build/conf/bblayers.conf文件中也可以看到: ```shell 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 \ " ``` 这里我只是演示,演示完之后可以自行将其删除。 注释:由于我添加的这个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层、与底层硬件耦合性不强的可以放到另一个层中,可以实现层与层的分离,改动某个层不影响另外的层,方便每个层的修改和复用)
admin
2024年2月5日 08:29
转发文档
收藏文档
上一篇
下一篇
手机扫码
复制链接
手机扫一扫转发分享
复制链接
Markdown文件
分享
链接
类型
密码
更新密码