みつきんのメモ

組み込みエンジニアです。Interface誌で「Yocto Projectではじめる 組み込みLinux開発入門」連載中

Yocto Project 5.0リリース

はじめに

4/30にKirkstoneの次のLTSとなるScarthgap(YP-5.0)がリリースされた。

LangdaleからNanbieldまででレシピのバージョンアップだけでなく、機能の追加などが行われているのでKirkstoneと比較すると結構便利になっている。

大きい点としてはSDKでRustやGoが使用可能になっているなど。

宗教上の理由で仕様が許されない筆者は恩恵が得られないが、VSCodeとの連携も強化されている。

bitbake-layersコマンドはかなり強化されている。

環境構築

Pokyの取得

scarthgapブランチの最新を使用する場合は下記。

$  git clone git://git.yoctoproject.org/poky.git -b scarthgap

リリースされたタグのバージョンを使用する場合は下記。

$ git clone git://git.yoctoproject.org/poky.git
$ git fetch --tags
$ git checkout -b tags/scarthgap-5.0 scarthgap-5.0

ビルド

タグを変更するまでレシピが更新されることのないtagバージョンを使うのであれば、 own-mirrorを作成すると、ダウンロードデータを使いまわしできて便利。

ローカルミラー(own-mirror)作成

ミラーを作成するには下記のようにする。

$ source poky/oe-init-build-env build_mirror
$ cat << 'EOF' >> ./conf/local.conf
MACHINE ?= "qemuarm64"

DL_DIR = "${HOME}/own-mirror-5.0"
BB_GENERATE_MIRROR_TARBALLS = "1"
SOURCE_MIRROR_FETCH = "1"
EOF
$ bitbake world --runall=fetch

ビルド実行

ミラー参照設定とビルド実行を行う。

$ source poky/oe-init-build-env build
$ cat << 'EOF' >> ./conf/local.conf
MACHINE ?= "qemuarm64"

INIT_MANAGER ?= "systemd"
DL_DIR ?= "${TOPDIR}/../downloads"

INHERIT += "own-mirrors"
SOURCE_MIRROR_URL = "file://${HOME}/own-mirror-5.0"
EOF
$ bitbake core-image-base

実行

QEMUを実行する。

$ runqemu nographic

Poky (Yocto Project Reference Distro) 5.0 qemuarm64 ttyAMA0

qemuarm64 login: root

WARNING: Poky is a reference Yocto Project distribution that should be used for
testing and development purposes only. It is recommended that you create your
own distribution for production use.

root@qemuarm64:~# cat /etc/os-release
ID=poky
NAME="Poky (Yocto Project Reference Distro)"
VERSION="5.0 (scarthgap)"
VERSION_ID=5.0
VERSION_CODENAME="scarthgap"
PRETTY_NAME="Poky (Yocto Project Reference Distro) 5.0 (scarthgap)"
CPE_NAME="cpe:/o:openembedded:poky:5.0"
root@qemuarm64:~# uname -a
Linux qemuarm64 6.6.23-yocto-standard #1 SMP PREEMPT Thu Mar 28 16:04:47 UTC 2024 aarch64 GNU/Linux

bitbake-layersの新機能

create-layers-setup

詳細は今度調べるとしてcreate-layers-setupが強力なので紹介しておく。

create-layers-setupは、現在のレイヤ構成を再現するためのスクリプトjsonが出力される。 これらを使用することで、現在のレイヤ構成を再現することができるようになっている。

使用しているレイヤのリビジョンやディレクトリ構成などのも保存されるようになっているため、 reposやkasなどの外部ツールを使用せずに、他のPCなどで同じレイヤ構成を再現することが可能となっている。 ただし、このサブコマンドではbblayers.confやlocal.localは管理されないので、再現されるのはレイヤのデータとディレクトリ構成のみとなる。

使い方は下記の通り非常に簡単。

$ bitbake-layers create-layers-setup dest-dir

出力結果は下記のようになる。

$ tree ./dest-dir/
./dest-dir/
├── setup-layers
└── setup-layers.json

setup-layersスクリプトを実行すると、必要なレイヤがcloneされる。

この機能で管理対象となるレイヤはgitリポジトリである必要がある。つまり、実質的にはgithubやgitlabなどで管理されていることを想定している。

save-build-conf

create-layers-setupではbblayers.confやlocal.confを引き継げないということを言ったが、 こちらと組み合わせることで問題は解決できる。

このサブコマンドは、現在のlocal.confbblayers.confからtemplateconfを生成し、指定のレイヤに保存する。 もともとYocto Projectではoe-init-build-envをsourceする際にTEMPLATECONFという環境変数を設定しておくことで local.confやbblayers.confを生成する際に使用するテンプレートを変更することができる。

下記のようにすることで、現在のlocal.confやbblayers.confの設定をレイヤに保存することができる。

$ bitbake-layers save-build-conf meta-test test

これを実行すると下記のようにファイルが生成される。

meta-test/
├── COPYING.MIT
├── README
├── conf
│   ├── layer.conf
│   └── templates
│       └── test
│           ├── bblayers.conf.sample
│           ├── conf-notes.txt
│           ├── conf-summary.txt
│           └── local.conf.sample
└── recipes-example
    └── example
        └── example_0.1.bb

conf/templates/test以下にコンフィグのテンプレートが作成されている。

まとめ

Yocto Project 5.0(Scarthgap)がリリースされた。 このバージョンはLTSとなっている。

前のLTSであるKirkstoneと比較すると結構機能が追加されていて便利になっている。 bitbake-layersのsave-build-confとcreate-layers-setupはとても便利なので、具体的な使用方法は今度紹介する。