7
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Yoctoを試す(その1:はじめに)

Posted at

Yoctoを用いてRaspberryPi用Linuxを作成

3年以上前に一度だけトライしBuild自身はできたが、うまく動作できずでほっておいた。久しぶりにやる気がでたのでリトライした結果、動作したのでここに記録する。その2の予定はあるが、その次もあるか現段階では不明。

開発環境とターゲット

PC

CPU: Core i5-4460 3.2GHz
RAM: 16GB
OS: Lubuntu 18.04.3 LTS
Buildに相当な時間がかかるので、高スペックがベター。

RaspberryPi

Raspberry Pi 1 Model B+
大昔に買ったもの。

準備

ここでは、本家ページの古い(?)情報をもとに、必要なパッケージをインストールした。最新状況はこちらから確認すべきであろう。

~/proj/yocto$ 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

Build前の環境設定

検索すると非常に多くの情報が見つかるが、ここでは同じターゲット(Raspberry Pi 1 Model B+)のこの記事をベースに進める。

Pokyや必要なレイヤなどをGet

~/proj/yocto$ git clone http://git.yoctoproject.org/git/poky
~/proj/yocto$ git clone http://git.yoctoproject.org/git/meta-raspberrypi
~/proj/yocto$ git clone git://git.openembedded.org/meta-openembedded

PATH追加

Bitbake実行のため、PATHに追加を行う。

~/proj/yocto$ PATH=~/proj/yocto/poky/bitbake/bin:$PATH

実行前の環境設定

~/proj/yocto$ source poky/oe-init-build-env build

「build」は好きな名前でよい。これを実行すると、「build」ディレクトリに移動し、次のメッセージが表示される。

You had no conf/local.conf file. This configuration file has therefore been
created for you with some default values. You may wish to edit it to, for
example, select a different MACHINE (target hardware). See conf/local.conf
for more information as common configuration options are commented.

You had no conf/bblayers.conf file. This configuration file has therefore been
created for you with some default values. To add additional metadata layers
into your configuration please add entries to conf/bblayers.conf.

The Yocto Project has extensive documentation about OE including a reference
manual which can be found at:
    http://yoctoproject.org/documentation

For more information about OpenEmbedded see their website:
    http://www.openembedded.org/


### Shell environment set up for builds. ###

You can now run 'bitbake <target>'

Common targets are:
    core-image-minimal
    core-image-full-cmdline
    core-image-sato
    core-image-weston
    meta-toolchain
    meta-ide-support

You can also run generated qemu images with a command like 'runqemu qemux86'

Other commonly useful commands are:
 - 'devtool' and 'recipetool' handle common recipe tasks
 - 'bitbake-layers' handles common layer tasks
 - 'oe-pkgdata-util' handles common target package tasks

最初はエラーかと思ったが、要するに、「conf/local.conf」と「conf/bblayers.conf」とがない(正確に言うとConfigurationされていない)ので編集、、、と「bitbake 」でBuild、、ということ。

conf/local.conf

修正部分のみ記載。所持するモデル「Raspberry Pi 1 Model B+」には、次の設定がベターらしい。

MACHINE ?= "raspberrypi"

conf/bblayers.conf(1回目)

関連部分のみ記載。まずは、「meta-openembedded」を除いてBuildする。

BBLAYERS ?= " \
  /home/undeux3/proj/yocto/poky/meta \
  /home/undeux3/proj/yocto/poky/meta-poky \
  /home/undeux3/proj/yocto/poky/meta-yocto-bsp \
  /home/undeux3/proj/yocto/meta-raspberrypi \
  "

Build

bitbake

「bitbake」でBuildを実施する。

~/proj/yocto/build$ bitbake core-image-base

「core-image-base」は作成するイメージのターゲットのひとつ。他には、上述した「oe-init-build-env」実行時に表示されるものや、本家サイトのここにターゲットが見つかる。この違いについては、理解できれば、別途調べることとする。

つまづき(Fetch Error)

Fetch Errorが発生。例えば、次のようなもの。

ERROR: eudev-3.2.10-r0 do_fetch: Fetcher failure
ERROR: qemu-native-5.2.0-r0 do_fetch: Fetcher failure

単にうまくDownloadできないだけらしい。解決方法を探すと、これこれを参考に、downloadsディレクトリに直接パッケージをDownloadすることがベターと判断。

~/proj/yocto/build/downloads$ https://dev.gentoo.org/~blueness/eudev/eudev-3.2.10.tar.gz
~/proj/yocto/build/downloads$ touch eudev-3.2.10.tar.gz.done

~/proj/yocto/build/downloads$ https://download.qemu.org/qemu-5.2.0.tar.xz
~/proj/yocto/build/downloads$ touch qemu-5.2.0.tar.xz.done

結果

Build時間は上記エラー対応も含めて4時間くらい、50GBもの容量を要した。

マイクロSDカードへの書き込み

「build/tmp/deploy/images/raspberrypi」にイメージが作成される。bmaptoolを使って書き込む。

~/proj/yocto/build$ sudo apt install bmap-tools

~/proj/yocto/build/tmp/deploy/images/raspberrypi$ 
sudo bmaptool copy --bmap core-image-base-raspberrypi.wic.bmap core-image-base-raspberrypi.wic.bz2 /dev/sdd

「/dev/sdd」は環境により異なる。

ログイン

Raspbianなどとは異なり、パスワードなしの「root」でログインできる。

次に

上記設定における「core-image-base」にsshが入っていなかったので、種々トライ。

conf/bblayers.conf(2回目)

「meta-openembedded」も一部加えてみた。

BBLAYERS ?= " \
  /home/undeux3/proj/yocto/poky/meta \
  /home/undeux3/proj/yocto/poky/meta-poky \
  /home/undeux3/proj/yocto/poky/meta-yocto-bsp \
  /home/undeux3/proj/yocto/meta-raspberrypi \
  /home/undeux3/proj/yocto/meta-openembedded/meta-oe \
  /home/undeux3/proj/yocto/meta-openembedded/meta-networking \
  /home/undeux3/proj/yocto/meta-openembedded/meta-python \
  "

これで、「bitbake core-image-base」の結果として作成されるイメージにも、sshは含まれておらず。その時は詳細を調べる気がなかったので、別のターゲット(イメージ)を対象とした。

~/proj/yocto/build$ bitbake core-image-sato

これには、sshが含まれていた。

上記2回目のBuild(core-image-sato)はそれほど時間かからず

~/proj/yocto/build/tmp

このディレクトリ配下にダウンロード済のパッケージや「core-image-base」用にBuildした結果が残されており、10−30分(記憶は定かでない)でBuildが完了したような気がする。

その後、sshについて調べる

conf/local.confへ設定追加でOK

「IMAGE_FEATURES_append」や「IMAGE_INSTALL_append」に適切な追加を行うと、オプションで様々パッケージが追加できることが判明。本家サイトにも情報があるが、たとえば、この記事に「conf/local.conf」の設定例がわかりやすく記載されている。

IMAGE_FEATURES_append = " ssh-server-openssh"
IMAGE_INSTALL_append = " openssh openssh-sftp-server"

ダブルクオーテーション(”)の次の空白は大事らしい。上記を「conf/local.conf」に記載後、

~/proj/yocto/build$ bitbake core-image-base

で作成されたイメージに、sshが含まれていた。

「IMAGE_FEATURES_append」や「IMAGE_INSTALL_append」で検索すると、追加できるパッケージについて、有益な情報が見つかるようだ。

調査する中で有益と感じた情報

Yoctoとは

この説明がナイスだった。

レシピ一覧を確認するコマンド

~/proj/yocto/build$ bitbake-layers show-recipes

bitbakeで指定可能なターゲット(イメージ)

ここに情報あり。

おわりに

その2に続く(続きたい)。

7
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?