Yocto 环境搭建

2019-07-13 01:16发布

转载地址:https://blog.csdn.net/encourage2011/article/details/72454582

Yocto Project简介

Yocto Project™ 是一个开源的协作软件,提供模板、工具和方法帮你创建定制的 Linux 系统和嵌入+式产品,而无需关心硬件体系。适合嵌入式Linux开发人员使用。查看Yocto Project Quick Start 
Yocto Project

相关术语

Poky

Poky是Yocto Project的参考发布版本。它包括OpenEmbedded构建系统(BitBake and OpenEmbedded Core)和一系列metadata,帮助开发者构建自己的distro。你可以下载Poky和使用它去逐步搭建自己的发布版本。需要注意的是Poky不包括二进制文件,它是一个关于搭建编译你自己制定的Linux发布版本的一个源代码用例。

Bitbake

一种软件组建自动化工具程式,像所有的build工具一样(比如make,ant,jam)控制如何去构建系统并且解决构建依赖。但是又区别于功能单一的工程管理工具(比如make),bitbake不是基于把依赖写死了的makefile,而是收集和管理大量之间没有依赖关系的描述文件(这里我们称为包的配方),然后自动按照正确的顺序进行构建。oe代表OpenEmbedded,而openembedded是一些用来交叉编译,安装和打包的metadata(元数据)。会获取*.bb文件中包的依赖关系的命令格式。

OpenEmbedded-Core

是一些脚本(shell和Python脚本)和数据构成的自动构建系统。

Metadata

Recipes(配方):(.bb/.bbappend)组件的逻辑单元的构建规范,用来获取源代码、构建和打包组件; 
Class:(.bbclass)包括各个recipes之间共享的相同的功能; 
Configuration:(.conf)定义Poky如何的各种配置文件; 
Layers:一系列相同的recipes,就像meta-fsl-arm。

i.MX 基于Yocto Project 环境搭建

下记内容主要基于 i.MX_Yocto_Project_User’s_Guide.pdf进行整理。

简介

Freescale provides an additional layer called the Freescale BSP Release, named meta-fsl-bsp-release, to integrate a new Freescale release with the FSL Yocto Project Community BSP.Freescale i.MX boards are configured in the meta-fsl-bsp-release and meta-fsl-arm layers. This includes U-Boot, the Linux kernel, and reference board-specific details.L4.1.15_2.0.0_ga is a Linux kernel that Freescale has released only for the Yocto Project.Freescale L4.1.15_2.0.0_ga uses device trees. Device tree settings are found in the i.MX machine configuration files.Graphics recipes integrate the Freescale graphics package release. For the i.MX boards that have a GPU, the imxgpu-viv recipes package the graphic components for each DISTRO – X11, frame buffer (FB), Xwayland,Wayland backend, and Weston compositor (Weston).Freescales provideds a script, fsl-setup-release.sh, that simplifies the setup for i.MX machines. To use the script, the name of the specific machine to be built for needs to be specified as well as the graphical backend desired. The script sets up a directory and the configuration files for the specified machine and backend.The Yocto Project build uses the bitbake command. For example, bitbake builds the named component. Each component build has multiple tasks, such as fetching, configuration, compilation, packaging, and deploying to the target rootfs. The bitbake image build gathers all the components required by the image and build in order of the dependency per task. The first build is the toolchain along with the tools required for the components to build.If a new terminal window is opened or the machine is rebooted after a build directory is set up, the setup environment script should be used to set up the environment variables and run a build again. The full fsl-setup-release.sh is not needed.$ source setup-environmentAftera build is complete, the created image resides in /tmp/deploy/images. An image is, for the most part, specific to the machine set in the environment setup. Each image build creates a U-Boot, a kernel, and an image type based on the IMAGE_FSTYPES defined in the machine configuration file. Most machine configurations provide an SD card image (.sdcard), an ext3 and tar.bz2. The ext3 is the root file system only. The .sdcard image contains U-Boot, the kernel and the rootfs completely set up for use on an SD card.

Ubuntu下载编译Yocto所需要的工具包

Essential Yocto Project host packages are:#sudo apt-get install gawk wget git-core diffstat unzip texinfo gcc-multilib build-essential chrpath socat libsdl1.2-devi.MX layers host packages for a Ubuntu 12.04 or 14.04 host setup are:#sudo apt-get install libsdl1.2-dev xterm sed cvs subversion coreutils texi2html docbook-utils python-pysqlite2 help2man make gcc g++ desktop-file-utils libgl1-mesa-dev libglu1-mesa-dev mercurial autoconf automake groff curl lzop asciidoci.MX layers host packages for a Ubuntu 12.04 host setup only are:#sudo apt-get install uboot-mkimagei.MX layers host packages for a Ubuntu 14.04 host setup only are:#sudo apt-get install u-boot-tools

设置repo工具

设置repo工具

下载recipe layers

4、下载recipe layers下载之后,在fsl-release-bsp/sources目录下会有meta文件如下: 
base meta-browser meta-fsl-arm meta-fsl-arm-extra meta-fsl-bsp-release meta-fsl-demos meta-openembedded meta-qt5 poky每个文件夹里面存放着各个layers所需的文件来源信息。bitbake命令就是通过解析里面的文件来获取并下载编译所需的源代码。layer

配置环境

DISTRO=fsl-imx-x11 MACHINE=imx6dlsabresd source fsl-setup-release.sh -b build-x11DISTRO指定的内容标记要生成的distribution,固定为以下内容的一个: 
DISTROfsl-setup-release.sh脚本会根据MACHINE指定的内容从sources/meta-fsl-arm/conf/machine里面的文件选择对应的.conf进行编译。-b选项指定配置和编译的内容存放的路径放在build-x11。 
当执行该脚本之后,会在build-x11/ 目录下生成配置文件。
 
build-x11build-x11/conf/local.conf会指定DL_DIR的内容,该路径用于下载并保存编译所需要的包。在bitbake在编译的时候会先去该路径查看有没有所需的包,如果没有,就从网上下载到该目录下。一般情况下这些包都是固定的,在团队开发中可由一人先下载,之后共享出来,然后每个人将DL_DIR指定到该共享文件夹就可以省去网上下载的麻烦。local.confBuild-x11/conf/bblayers.conf会指定所需要的layers。 
layersbitbake在启动时会执行bitbake.confbitbake.conf会装载用户提供的local.conf。然后根据用户在local.conf中定义的硬件平台MACHINE和发布目标DISTRO装载machine子目录和distro子目录的配置文件。machine子目录里是硬件平台相关的配置文件。distro子目录里是与发布目标相关的配置文件。配置文件负责设置bitbake内部使用的环境变量。这些变量会影响整个构建过程。每次新打开一个窗口,都要进行一次source操作。#source setup-environment <build-dir>

编译

执行编译之前,先要在/home/VictorHuang/work/downloads执行脚本./mk-empty-dir创建git关联空的目录。正常使用 DL_DIR 下载到的包都是包括 .git 的目录的,编译的时候会去检查 .git的内容。但是我们使用git管理并共享downloads/的内容,这里将 .git 相关的内容给忽略掉。所以编译之前要创建 .git 相关的空目录。 
执行
#bitbake image-name其中image-name的内容为以下的一个: 
image-name执行完毕之后会在build-x11/tmp/work-shared/imx6dlsabresd/kernel-source看到kernel的源代码和 
tmp/work/imx6dlsabresd-poky-linux-gnueabi/linux-imx/4.1.15-r0/git
build-x11/tmp/deploy/images目录下会有编译生成的所有images文件。 
在build-x11/tmp目录下常见的目录为:
http://blog.csdn.net/rocky_zhm/article/details/48266657 
tmp目录

U-Boot所在路径

通用路径为: 
/tmp/work/-poky-linuxgnueabi/u-boot-imx//git 
比如为: 
build-x11/tmp/work/imx6dlsabresd-poky-linux-gnueabi/u-boot-imx/2016.03-r0/git

单独编译某一模块

#bitbake -c compile -f module-name-f是为了强制编译 
module-name 是模块的名称,这个名称可以在 tmp/work/imx6dlsabresd-poky-linux-gnueabi/目录下看。
例如:想单独编译一下kernel,可以用以下命令。#bitbake -c compile -f linux-imx编译后重新发布:#bitbake -c deploy module-name例如:#bitbake -c deploy linux-imx查看列表#bitbake -c listtasks linux-imx

mk-empty-dir脚本

#!/bin/sh # version 0.1 REVERSION=0.1 # copy right bingge # --- History --- # v0.1 init version if [ "$1" = "--version" -o "$1" = "-V" ]; then echo -e "