我经常使用Yocto Project为一个

各种产品。使用此工具时可能遇到的主要困难之一是管理多个

git 存储库以生成成功的构建。一个名为kas的新工具尝试

简化这个过程;让我们通过为 Pine64 板构建分发来看看如何。

安装

首先,我们必须安装 python3 和 pip,以及其他一些依赖项:

$ sudo apt install python3 python3-pip
$ pip3 install distro jsonschema PyYAML

进入全屏模式 退出全屏模式

然后安装kas;我遇到了依赖问题,所以我不得不手动安装另一个包

$ pip3 install testresources
$ pip3 install kas

进入全屏模式 退出全屏模式

运行简单构建

例如,我们可以尝试为已经包含在 poky 中的 qemu 机器构建一个简单的镜像

存储库。我们需要创建一个特殊的文件,kas-project.yml,它将描述我们的发行版必须如何构建

以及必须包括哪些层;我们将使用 kas 文档提供的文件,并进行一些小调整。

为项目创建一个文件夹:

$ mkdir kas-pine64
$ touch kas-project.yml

进入全屏模式 退出全屏模式

将以下代码段添加到项目配置文件中:

header:
   version: 11
machine: qemux86-64
distro: poky
target: core-image-minimal
repos:
   kas-pine64:
   poky:
   url: "https://git.yoctoproject.org/git/poky"
   refspec: hardknott
   layers:
   meta:
   meta-poky:
   meta-yocto-bsp:
local_conf_header:
   kas-pine64: |
   EXTRA_IMAGE_FEATURES += "debug-tweaks"

进入全屏模式 退出全屏模式

kas-project.yml 文件是用YAML编写的,通常是一种最小标记语言

用于配置文件。它使我们能够以非常清晰的方式描述我们的分布;在这个例子中,我们将

基于 qemux86-64 机器的 poky 分布构建 core-image-minimal 图像。使用的层是

poky 层中包含的那些,在配置文件中列出。local_conf_header部分允许

我们将任何行添加到构建文件夹中的 local.conf 文件中。

我们现在可以使用可用的 kas 命令之一,build:

$ kas build kas-project.yml

进入全屏模式 退出全屏模式

kas 将克隆 out 项目文件中指示的存储库(在这种情况下只是 poky)并开始构建过程

对我们设置的_distro_和_machine_使用bitbake;在构建过程结束时,我们将有一个_build_

具有与任何 Yocto 项目构建相同的结构的文件夹。

其他kas命令

另一个有用的 kas 命令是shell。我们可以像这样运行它

$ kas shell kas-project.yml

进入全屏模式 退出全屏模式

它的作用是打开一个加载了构建环境的新 shell 实例。我们还可以提供定制

在新外壳中执行的命令;例如要复制之前的构建命令,我们可以运行:

$ kas shell kas-project.yml -c "bitbake core-image-minimal"

进入全屏模式 退出全屏模式

由于我们正在运行基本的 Yocto 演示,我们现在可以尝试加载虚拟 QEMU 映像:

$ kas shell kas-project.yml
$ runqemu qemux86-64 core-image-minimal nographic

进入全屏模式 退出全屏模式

它将提示输入管理员密码以创建 Tap 接口,然后,在启动序列之后,我们可以使用登录

“root”(因为我们在项目文件中启用了debug-tweaks)。我也尝试过图形模式,但由于某种原因

GUI 永远不会出现,也许是因为来自 kas 环境的一些限制。

与更多层集成

[松树A64板](https://res.cloudinary.com/practicaldev/image/fetch/s--OH9ZIw2c--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev- to-uploads.s3.amazonaws.com/uploads/articles/ybl9jaluiugrcep6mld3.jpg)

现在让我们添加更多的层来为真实的棋盘构建图像,

松木 A64。在“repos”部分下

配置文件,添加以下行:

   meta-openembedded:
     url: "https://github.com/openembedded/meta-openembedded.git"
     refspec: hardknott
     layers:
       meta-oe:
   meta-sunxi:
     url: "https://github.com/linux-sunxi/meta-sunxi.git"
     refspec: hardknott

进入全屏模式 退出全屏模式

我们还可以添加一个自定义层;它可以从私有 git 存储库中获取,但它可以是一个简单的文件夹

项目结构:

$ mkdir meta-custom-pine64

进入全屏模式 退出全屏模式

还为我们的自定义层创建一个 meta-custom-pine64/conf/layer.conf 文件:

# 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-custom-pine64"
BBFILE_PATTERN_meta-custom-pine64 = "^${LAYERDIR}/"
BBFILE_PRIORITY_meta-custom-pine64 = "10"

LAYERDEPENDS_meta-custom-pine64 = ""
LAYERSERIES_COMPAT_meta-custom-pine64 = "hardknott"

进入全屏模式 退出全屏模式

然后,我们可以添加一个新的自定义图像,创建 meta-custom-pine64/recipes-images/images/kas-custom-image.bb 配方:

SUMMARY = "kas custom image"
LICENSE = "MIT"

inherit core-image

IMAGE_FEATURES += "ssh-server-openssh"

进入全屏模式 退出全屏模式

通过在项目配置文件中更改图像将图像设置为构建目标,并添加新图层;这

机器可以设置为pine64-plus:

...
machine: pine64-plus
distro: poky
target: kas-custom-image
...
# Add the new layer in our project section
repos:
  kas-pine64:
    layers:
      meta-custom-pine64:

进入全屏模式 退出全屏模式

构建过程可以再次运行:

   $ kas build kas-project.yml
   # Once the build process ends, we can flash the image
   $ cd build/tmp/deploy/images/pine64-plus/
   $ sudo dd if=kas-custom-image-pine64-plus.sunxi-sdimg of=/dev/sd<X> bs=1024 status=progress

进入全屏模式 退出全屏模式

如果我们使用闪存的 SD 映像启动开发板,我们将拥有一个带有基本映像和 ssh 服务器的系统;这个可以

作为更多结构化项目的画布。

一个小提示:在撰写本文时,U-Boot 存在问题

meta-sunxi为pine64-plus机器;我开了一个

拉取请求修复该问题;如果您想尝试应用该补丁

构建项目。

点击阅读全文
Logo

更多推荐