Yocto Project Quick Build

Yocto Project Quick Build

  1. 使用Yocto Project构建典型的image镜像
  2. 配置特定硬件的build

Compatible Linux Distribution

肯定编译机器配置知足以下要求:html

  • 50G的空闲硬盘
  • 运行有一个支持的Linux 发行版(Fedora, openSUSE, CentOS, Debian, or Ubuntu)。
  • 软件版本要求
    • Git 1.8.3.1 or greater
    • tar 1.27 or greater
    • Python 3.4.0 or greater.

Build Host Packages

在编译机器上安装必要的编译软件,Ubuntu系统可以使用以下的命令进行安装:python

$ sudo apt-get install gawk wget git-core diffstat unzip texinfo gcc-multilib \
     build-essential chrpath socat cpio python python3 python3-pip python3-pexpect \
     xz-utils debianutils iputils-ping libsdl1.2-dev xterm

Use Git to Clone Poky

编译机器配置完成之后,使用git 命令从Poky上下载代码,当前以yocto-2.5为例:git

$ git clone git://git.yoctoproject.org/poky
     Cloning into 'poky'...
     remote: Counting objects: 361782, done.
     remote: Compressing objects: 100% (87100/87100), done.
     remote: Total 361782 (delta 268619), reused 361439 (delta 268277)
     Receiving objects: 100% (361782/361782), 131.94 MiB | 6.88 MiB/s, done.
     Resolving deltas: 100% (268619/268619), done.
     Checking connectivity... done.
     $ git checkout tags/yocto-2.5 -b my-yocto-2.5

Building Your Image

使用以下命令来构建一个image。这个生成过程是从源代码构建一个包含工具链的完整的Linux发行版。github

Note:
编译过程当中会下载一些东西,若是编译机器没有配置代理,那么在编译过程当中会报 Git 或 Fetch的问题。

初始化编译环境:Initialize the Build Environment

运行oe-init-build-env脚本在编译机器上构建Yocto项目的编译环境。bash

$source oe-init-build-env

执行这个脚本的时候,远在源代码路径(the Source Directory)下建立构建目录(the Build Directory)。脚本执行完,当前的工做目录就被设置成了构建目录。而后,在以后的编译过程当中,构建目录保存和编译过程当中生成的全部文件。模块化

测试本地配置文件:Examine Your Local Configuration File

在设置完编编译环境以后,会在构建目录的conf文件夹下生成一个local.conf文件。默认,是去编译一个qemux86的target,这个target适用于当前的模拟器。这里面所使用的包管理器是RPM包管理器。工具

Tip学习

经过使用镜像,能够显著加快编译时间病防止fetch问题。在构建目录的local.conf中加上以下几行,就能够使用镜像。测试

SSTATE_MIRRORS = "\
     file://.* http://sstate.yoctoproject.org/dev/PATH;downloadfilename=PATH \n \
     file://.* http://sstate.yoctoproject.org/2.4/PATH;downloadfilename=PATH \n \
     file://.* http://sstate.yoctoproject.org/2.5/PATH;downloadfilename=PATH \n \
     "

这个事例只展现了如何在Yocto项目2.4,2.5和development area中添加sstate path,更详细的介绍参考:http://sstate.yoctoproject.org/fetch

开始编译:Start the Build

继续执行以下的命令,为咱们制定的target编译一个OS镜像,这个例子中,咱们编译的是:core-iamge-sato

$bitbake core-image-sato

使用QEMU模拟镜像:Simulate Your Image Using QEMU

一旦镜像编译完成,就能够启动QEMU。(QEMU是可一个和Yocto 项目一块儿的快速模拟器)

$runqemu qemux86

若是像学习更多的QEMU,能够查看( the Yocto Project Development Tasks Manual)以下内容: "Using the Quick EMUlator (QEMU)".

退出QEMU:Exit QEMU

点击QEMU窗口的关闭按钮或 Ctrl-C就能够退出QEMU。

为特定硬件定制编译:Customizing Your Build for Specific Hardware

通常来讲,layers是包含相关指令集和配置的库,他告诉Yocto Project要作什么。将相关的元数据隔离在功能特定的层中有助于模块化开发,并更容易重用层中的元数据。

Note 方便起见,layers一般以“meta-”命名。

按照以下步骤能够新增一个硬件层。

找一个Layer:Find a Layer

Yocto Project的源码库中有不少硬件层.当前以meta-altera为例。

复制这个Layer:Clone the Layer

经过git命令,将这个git库clone到本地。放在以前poky库的顶层。

$ cd ~/poky
     $ git clone https://github.com/kraj/meta-altera.git
     Cloning into 'meta-altera'...
     remote: Counting objects: 25170, done.
     remote: Compressing objects: 100% (350/350), done.
     remote: Total 25170 (delta 645), reused 719 (delta 538), pack-reused 24219
     Receiving objects: 100% (25170/25170), 41.02 MiB | 1.64 MiB/s, done.
     Resolving deltas: 100% (13385/13385), done.
     Checking connectivity... done.

这时,这个硬件层,就和其余层同样存在编译机器的Poky库下面了,而且包含了altera硬件所须要的所有元数据。Altera是归Intel全部的。

为特定机器配置编译:Change the Configuration to Build for a Specific Machine

local.conf文件中的“MACHINE”变量,指定了编译生成的机器。这个例子中,“MACHINE”是"cyclones“。如今这个配置在:conf/machine/cyclone5.conf.

将你的层添加到层配置文件中:Add Your Layer to the Layer Configuration File

在编译过程你使用一个层以前,必须将这个层添加到构建路径的bblayers.conf文件中。

使用bitbake-layers add-layer命令将这个layer添加到配置文件中。

$ cd ~/poky/build
     $ 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.

添加layer的详细信息在以下位置:Adding a Layer Using the bitbake-layers Script

按照这些步骤完成以后,你当前的Yocto Project开发环境中就添加了meta-altera层,并能够执行cyclone5的编译。

查看Altera的README能够帮助你编译一个cyclone5的image。

建立本身的Layer:Creating Your Own General Layer

也许你有一个应用程序或者你须要隔离一组特定的行为,你能够使用bitbake-layers create-layer来建立本身的通用层。这个工具自动建立一个包含layer.conf配置文件的目录,这个recipes-example子目录里面包含example.bb recipes文件,licensing文件和README。

命令以下:

$cd ~/poky
     $bitbake-layers create-layer meta-mylayer
     NOTE: Starting bitbake server...
     Add your new layer with 'bitbake-layers add-layer meta-mylayer'

更多详细信息能够参考Creating a General Layer Using the bitbake-layers Script

相关文章
相关标签/搜索