Yocto
Created: 2023/10/22
概要
Yoctoは組み込み向けLinuxの一種です。
Raspberry Pi3で試す
次の手順でイメージをビルドしSDカードに書き込んで起動を確かめます。
- 開発用コンテナを作成
- meta-raspberrypiレイヤの取得
- ビルド
- 書き込み
ビルド環境
- Windows 11 + WSL + Docker
ターゲット
- Raspberry Pi3
- Yocto 4.2 (mickledore)
Poky環境のセットアップ
$ mkdir rpi-mickledore
$ cd rpi-mickledore/
$ git clone -b mickledore git://git.yoctoproject.org/poky.git
$ docker run --rm -it -v $(pwd):/workdir crops/poky --workdir=/workdir
コンテナ内のシェルで作業する。関連コマンドを有効にするためにスクリプトを実行する。
pokyuser@4c5ad0c1bea7:/workdir$ source poky/oe-init-build-env
ここまでやるとbuildにconfなどが生成される
rpi-mickledore/
┣ build/
┃ ┗ conf/
┃ ┣ bblayers.conf
┃ ┣ conf-notes.txt
┃ ┣ local.conf
┃ ┗ templateconf.cfg
┗ poky/
参考
- https://github.com/crops/docker-win-mac-docs/wiki
- YoctoProject 4.2(mickledore)をラズベリーパイで試す - みつきんのメモ
meta-raspberrypiの取得
bitbake-layers layerindex-fetch
を利用してmeta-raspberrypiをPoky内に配置する。
pokyuser@8f2fb8eb82ec:/workdir/build$ bitbake-layers layerindex-fetch meta-raspberrypi
pokyuser@8f2fb8eb82ec:/workdir/build$ bitbake-layers show-layers
NOTE: Starting bitbake server...
layer path priority
========================================================================================================
core /workdir/poky/meta 5
yocto /workdir/poky/meta-poky 5
yoctobsp /workdir/poky/meta-yocto-bsp 5
raspberrypi /workdir/poky/meta-raspberrypi 9
local.confを編集
conf/local.conf
をVSCodeで編集
# (中略) ...
MACHINE = "raspberrypi3-64"
DL_DIR = "${TOPDIR}/../downloads"
# enable uart
ENABLE_UART = "1"
# systemd
DISTRO_FEATURES:append = " systemd"
VIRTUAL-RUNTIME_init_manager = "systemd"
DISTRO_FEATURES_BACKFILL_CONSIDERED = "sysvinit"
VIRTUAL-RUNTIME_initscripts = ""
# Accept for the synaptics license
LICENSE_FLAGS_ACCEPTED = "synaptics-killswitch"
ビルド
pokyuser@8f2fb8eb82ec:/workdir/build$ bitbake core-image-base
エラー: linux-raspberrypi-...do_fetch: Failed to fetch
内部で実行されるGit cloneでエラーが発生してしまった。
pokyuser@8f2fb8eb82ec:/workdir/build$ bitbake core-image-base
Loading cache: 100% | | ETA: --:--:--
Loaded 0 entries from dependency cache.
Parsing recipes: 100% |##################################################################################| Time: 0:00:21
Parsing of 938 .bb files complete (0 cached, 938 parsed). 1839 targets, 75 skipped, 0 masked, 0 errors.
NOTE: Resolving any missing task queue dependencies
Build Configuration:
BB_VERSION = "2.4.0"
BUILD_SYS = "x86_64-linux"
NATIVELSBSTRING = "universal"
TARGET_SYS = "aarch64-poky-linux"
MACHINE = "raspberrypi3-64"
DISTRO = "poky"
DISTRO_VERSION = "4.2.3"
TUNE_FEATURES = "aarch64 armv8a crc cortexa53"
TARGET_FPU = ""
meta
meta-poky
meta-yocto-bsp = "mickledore:87dc91ac724997ae4494a5247e94b9aad10cce1a"
meta-raspberrypi = "mickledore:aa0aed9a08d6578a18c4eeb3b44ed8354a57ebee"
Initialising tasks: 100% |###############################################################################| Time: 0:00:03
Sstate summary: Wanted 1378 Local 0 Mirrors 0 Missed 1378 Current 298 (0% match, 17% complete)
NOTE: Executing Tasks
WARNING: linux-raspberrypi-1_6.1.20+gitAUTOINC+1a97a82e62_a1cd5351f4-r0 do_fetch: Failed to fetch URL git://github.com/raspberrypi/linux.git;name=machine;branch=rpi-6.1.y;protocol=https, attempting MIRRORS if available
ERROR: linux-raspberrypi-1_6.1.20+gitAUTOINC+1a97a82e62_a1cd5351f4-r0 do_fetch: Fetcher failure: Fetch command export PSEUDO_DISABLED=1; export SSL_CERT_FILE="/opt/poky/4.1/sysroots/x86_64-pokysdk-linux/etc/ssl/certs/ca-certificates.crt"; export GIT_SSL_CAINFO="/opt/poky/4.1/sysroots/x86_64-pokysdk-linux/etc/ssl/certs/ca-certificates.crt"; export PATH="/workdir/build/tmp/sysroots-uninative/x86_64-linux/usr/bin:/workdir/poky/scripts:/workdir/build/tmp/work/raspberrypi3_64-poky-linux/linux-raspberrypi/1_6.1.20+gitAUTOINC+1a97a82e62_a1cd5351f4-r0/recipe-sysroot-native/usr/bin/aarch64-poky-linux:/workdir/build/tmp/work/raspberrypi3_64-poky-linux/linux-raspberrypi/1_6.1.20+gitAUTOINC+1a97a82e62_a1cd5351f4-r0/recipe-sysroot/usr/bin/crossscripts:/workdir/build/tmp/work/raspberrypi3_64-poky-linux/linux-raspberrypi/1_6.1.20+gitAUTOINC+1a97a82e62_a1cd5351f4-r0/recipe-sysroot-native/usr/sbin:/workdir/build/tmp/work/raspberrypi3_64-poky-linux/linux-raspberrypi/1_6.1.20+gitAUTOINC+1a97a82e62_a1cd5351f4-r0/recipe-sysroot-native/usr/bin:/workdir/build/tmp/work/raspberrypi3_64-poky-linux/linux-raspberrypi/1_6.1.20+gitAUTOINC+1a97a82e62_a1cd5351f4-r0/recipe-sysroot-native/sbin:/workdir/build/tmp/work/raspberrypi3_64-poky-linux/linux-raspberrypi/1_6.1.20+gitAUTOINC+1a97a82e62_a1cd5351f4-r0/recipe-sysroot-native/bin:/workdir/poky/bitbake/bin:/workdir/build/tmp/hosttools"; export HOME="/home/pokyuser"; LANG=C git -c gc.autoDetach=false -c core.pager=cat clone --bare --mirror https://github.com/raspberrypi/linux.git /workdir/build/../downloads/git2/github.com.raspberrypi.linux.git --progress failed with exit code 128, no output
ERROR: linux-raspberrypi-1_6.1.20+gitAUTOINC+1a97a82e62_a1cd5351f4-r0 do_fetch: Bitbake Fetcher Error: FetchError('Unable to fetch URL from any source.', 'git://github.com/raspberrypi/linux.git;name=machine;branch=rpi-6.1.y;protocol=https')
ERROR: Logfile of failure stored in: /workdir/build/tmp/work/raspberrypi3_64-poky-linux/linux-raspberrypi/1_6.1.20+gitAUTOINC+1a97a82e62_a1cd5351f4-r0/temp/log.do_fetch.9429
ERROR: Task (/workdir/poky/meta-raspberrypi/recipes-kernel/linux/linux-raspberrypi_6.1.bb:do_fetch) failed with exit code '1'
NOTE: Tasks Summary: Attempted 957 tasks of which 541 didn't need to be rerun and 1 failed.
Summary: 1 task failed:
/workdir/poky/meta-raspberrypi/recipes-kernel/linux/linux-raspberrypi_6.1.bb:do_fetch
Summary: There was 1 WARNING message.
Summary: There were 2 ERROR messages, returning a non-zero exit code.
gitのcloneで失敗しているようだったので該当コマンドだけ手動で実行した。
pokyuser@8f2fb8eb82ec:/workdir/build$ git -c gc.autoDetach=false -c core.pager=cat clone --bare --mirror https://github.com/raspberrypi/linux.git /workdir/build/../downloads/git2/github.com.raspberrypi.linux.git
pokyuser@8f2fb8eb82ec:/workdir/build$ bitbake core-image-base
Loading cache: 100% |####################################################################################| Time: 0:00:00Loaded 1839 entries from dependency cache.
NOTE: Resolving any missing task queue dependencies
Build Configuration:
BB_VERSION = "2.4.0"
BUILD_SYS = "x86_64-linux"
NATIVELSBSTRING = "universal"
TARGET_SYS = "aarch64-poky-linux"
MACHINE = "raspberrypi3-64"
DISTRO = "poky"
DISTRO_VERSION = "4.2.3"
TUNE_FEATURES = "aarch64 armv8a crc cortexa53"
TARGET_FPU = ""
meta
meta-poky
meta-yocto-bsp = "mickledore:87dc91ac724997ae4494a5247e94b9aad10cce1a"
meta-raspberrypi = "mickledore:aa0aed9a08d6578a18c4eeb3b44ed8354a57ebee"
Initialising tasks: 100% |###############################################################################| Time: 0:00:02Sstate summary: Wanted 1283 Local 0 Mirrors 0 Missed 1283 Current 393 (0% match, 23% complete)
NOTE: Executing Tasks
NOTE: Tasks Summary: Attempted 4190 tasks of which 1378 didn't need to be rerun and all succeeded.
書き込み
bmaptoolsで書き込むのが良いが、Windows環境だと不自由なので解凍してRaspberry pi Imagerを利用して書き込む。
pokyuser@8f2fb8eb82ec:/workdir/build$ cd tmp/deploy/images/raspberrypi3-64/
pokyuser@8f2fb8eb82ec:/workdir/build/tmp/deploy/images/raspberrypi3-64$ cp core-image-base-raspberrypi3-64.wic.bz2 /workdir/
pokyuser@8f2fb8eb82ec:/workdir/build/tmp/deploy/images/raspberrypi3-64$ cd /workdir/
pokyuser@8f2fb8eb82ec:/workdir$ bunzip2 core-image-base-raspberrypi3-64.wic.bz2
Windows側にcore-image-base-raspberrypi3-64.wic
を移動させ、カスタムイメージとして書き込む。
結果
root@raspberrypi3-64:~# cat /etc/os-release
ID=poky
NAME="Poky (Yocto Project Reference Distro)"
VERSION="4.2.3 (mickledore)"
VERSION_ID=4.2.3
VERSION_CODENAME="mickledore"
PRETTY_NAME="Poky (Yocto Project Reference Distro) 4.2.3 (mickledore)"
root@raspberrypi3-64:~#
アプリケーションを追加する
IMAGE_INSTALL
変数にパッケージを追加する(重要)。なので、なにかアプリケーションをインストールするときは次の手順になる。
- レイヤーを追加
- アプリケーションを追加
試しにdockerを追加
meta-virtualization
に含まれているらしい。
pokyuser@f58fb7064379:/workdir/build$ bitbake-layers layerindex-fetch meta-virtualization
local.conf
に下記を追加。
IMAGE_INSTALL:append = " packagegroup-docker"
で、こう。