devtoolの使い方 (3):QEMUによる動作確認(deploy-target)と作成完了(finish)

この投稿は連載:「devtoolの使い方」(全4回)の第3回です。

前回はdevtool addを使ってslコマンドをビルドできるようになりました。今回はビルドしたslコマンドをQEMU上で動作確認します。その中で少しのレシピ修正をします。そのあとレシピをレイヤに登録して、レシピ作成を完了します。

事前準備

動作確認用のイメージcore-image-full-cmdlineのビルド

まずは動作確認に使用するイメージをビルドします。あとでsshを使ってファイルを転送するのでsshサーバが起動するcore-image-full-cmdlineをビルド・起動します。

bitbake core-image-full-cmdline
runqemu qemux86 core-image-full-cmdline

イメージのビルドは時間がかかります。runqemuコマンドでQEMU側のIPアドレスはデフォルトの192.168.7.2で起動します。

 slコマンドの転送 deploy-target

今まで使用していたターミナルは一旦QEMU用としておいておいて、新しくターミナルを開いて作業を続行します。それではslコマンドを転送してみましょう。転送はdeploy-targetコマンドです。

# source oe-init-build-env で環境変数を設定しなおしてください
devtool deploy-target sl [email protected]

「deployするファイルがない。slレシピをビルド済みならinstallで何もインストールしてないよ。」とエラーが出ました。ビルドはできているのでインストール対象がないことが問題のようです。

sakate@walle:~/git/poky/build$ devtool deploy-target sl [email protected]
Parsing recipes..done.
ERROR: No files to deploy - have you built the sl recipe? If so, the install step has not installed any files.

レシピの修正

レシピの内容確認

レシピの修正をする前に、前回addコマンドで生成したレシピの内容を確認します。

# Recipe created by recipetool
# This is the basis of a recipe and may need further editing in order to be fully functional.
# (Feel free to remove these comments when editing.)

# WARNING: the following LICENSE and LIC_FILES_CHKSUM values are best guesses - it is
# your responsibility to verify that the values are complete and correct.
#
# The following license files were not able to be identified and are
# represented as "Unknown" below, you will need to check them yourself:
#   LICENSE
#
LICENSE = "Unknown"
LIC_FILES_CHKSUM = "file://LICENSE;md5=74e9dd589a0ab212a9002b15ef2b82f0"

SRC_URI = "git://github.com/mtoyoda/sl;protocol=https"

# Modify these as desired
PV = "1.0+git${SRCPV}"
SRCREV = "923e7d7ebc5c1f009755bdeb789ac25658ccce03"

S = "${WORKDIR}/git"

# NOTE: this is a Makefile-only piece of software, so we cannot generate much of the
# recipe automatically - you will need to examine the Makefile yourself and ensure
# that the appropriate arguments are passed in.

do_configure () {
    # Specify any needed configure commands here
    :
}

do_compile () {
    # You will almost certainly need to add additional arguments here
    oe_runmake
}

do_install () {
    # NOTE: unable to determine what to put here - there is a Makefile but no
    # target named "install", so you will need to define this yourself
    :
}

LICENSE周りやSRC_URI, PV, SRCREVなどの設定がされていて、do_configure, do_compile, do_installが生成されています。

LICENSEについてはUnknownでWARNINGが出ていますがどうすべきかよくわからないので放置します。GPL, MIT等のOSSライセンスの場合は自動で認識してくれるはずです。

本題はdo_installですね。NOTEがついていてMakefileのターゲットにinstallがなかったので自分で定義してくれと書いてあります。逆に言うとmake installが使えるのであれば自動でdo_installを生成してくれるということですね。devtoolなかなかすごいです。

レシピの修正 do_install

diff --git a/sl_git.bb b/sl_git.bb
index 8c362cb..aff6497 100644
--- a/sl_git.bb
+++ b/sl_git.bb
@@ -19,6 +19,7 @@ PV = "1.0+git${SRCPV}"
 SRCREV = "923e7d7ebc5c1f009755bdeb789ac25658ccce03"
 
 S = "${WORKDIR}/git"
+DEPENDS = "ncurses"
 
 # NOTE: this is a Makefile-only piece of software, so we cannot generate much of the
 # recipe automatically - you will need to examine the Makefile yourself and ensure
@@ -35,8 +36,7 @@ do_compile () {
 }
 
 do_install () {
- # NOTE: unable to determine what to put here - there is a Makefile but no
- # target named "install", so you will need to define this yourself
- :
+ install -d ${D}${bindir}
+ install -m 0755 ${S}/sl ${D}${bindir}
 }
 

2個目のハンクがdo_installに対する修正です。インストール先のディレクトリを作り(お約束)、その後ソースディレクトリ内にビルドされたslコマンドを先のインストールディレクトリにインストールしています。

1個目のハンクの DEPENDS = “ncurses”は天下り的ですが、イメージに組み込む時にエラーが出て気づいたのでここで追加しておきます。slコマンドはncursesに依存しています。bitbakeで実際にビルドする際の依存関係を解決するために使用されます。

転送と動作確認

slコマンドの(再)転送 deploy-target

それではこれで再度転送を試みます。必要ならQEMU内でslコマンドが入っていないことを事前にwihch slなどで確認しておいてください。

devtool build sl
devtool deploy-target sl [email protected]

これで転送できるはずです。もし、「ERROR: Failed to copy script to [email protected] – rerun with -s to get a complete error message」と出る場合は指示通り -sオプションをつけてdeploy-targetを実施してください。私の場合はQEMU側のfingerprintが違うことが原因でしたので指示に従ってECDSAキーを削除することで解消しました。

動作確認

それではQEMU上でslコマンドがあるか試してみましょう。アスキーアートのSLが画面を走り抜けます。

which sl
sl

転送の取り消し undeploy-target

逆に転送を取り消したい場合は、undeploy-targetを使用します。引数は同じです。

devtool undeploy-target sl [email protected]

レシピの作成完了

レイヤの追加

レシピの作成を完了するためには、作成したレシピをいれるレイヤが必要です。ここで新しくレイヤを作りましょう。

レイヤの作成は下記で行います。今回はmeta-learning-devtoolという名前のレイヤを作成します。”meta-“は作成時に勝手に付加されるので不要です。対話的に聞かれますが、特に指定することはないのでデフォルト設定で作成を完了させます。
cd $BUILDDIR
yocto-layer create learning-devtool
bitbake-layers add-layer "$BUILDDIR/meta-learning-devtool"
bitbake-layers show-layers

これでadd時に追加されたworkspaceと作成したmeta-learning-devtoolが追加された状態になります。

レシピの修正完了 finish

それではレシピの作成を完了してレイヤへ登録します。完了する前にソースコードへの修正は忘れずにコミットしておきましょう。このコミットメッセージがパッチファイルのファイル名に採用されます。

cd $BUILDDIR/workspace/sources/sl/
git add Makefile
git commit -m "Change toolchain for recipe"

レイヤへの追加は下記のコマンドで行います。追加先のレイヤには先ほど作成したレイヤーを指定します。

cd $BUILDDIR
devtool finish sl meta-learning-devtool

実行結果は下記のようになります。コミットメッセージを使用したパッチファイルが生成され、レイヤmeta-learning-devtoolにレシピslが追加されました。編集していたソースコードはworkspaceに残っていますので必要に応じて消しましょう。

sakate@walle:~/git/poky/build$ devtool finish sl meta-learning-devtool
Parsing recipes..WARNING: No bb files matched BBFILE_PATTERN_learning-devtool '^/home/sakate/git/poky/build/meta-learning-devtool/'
done.
NOTE: Adding new patch 0001-Change-toolchain-for-recipe.patch
NOTE: Updating recipe sl_git.bb
NOTE: Moving recipe file to /home/sakate/git/poky/build/meta-learning-devtool/recipes-sl/sl
NOTE: Cleaning sysroot for recipe sl...
NOTE: Leaving source tree /home/sakate/git/poky/build/workspace/sources/sl as-is; if you no longer need it then please delete it manually

生成されたレシピのファイル構成は下記のようになります。パッチファイルができていますね。レシピは先程まで編集していたファイルがこちらへ移動され、workspaceからは削除されます。

meta-learning-devtool/recipes-sl/
└── sl
    ├── sl
    │   └── 0001-Change-toolchain-for-recipe.patch
    └── sl_git.bb

レシピの中を確認するとちゃんとパッチファイルも登録されていることがわかります。複数コミットある場合は複数のパッチファイルが作成されて順番に適用されるようになります。

SRC_URI = "git://github.com/mtoyoda/sl;protocol=https \
           file://0001-Change-toolchain-for-recipe.patch \
           "

まとめ

ここまででdevtoolによるレシピの作成方法を確認してきました。使用した主なコマンドは下記の通りです。結構たくさん使いましたね。

  • devtool status
  • devtool add
  • devtool build
  • devtool deploy-target
  • devtool undeploy-target
  • yocto-layer create
  • bitbake-layers add-layer
  • bitbake-layers show-layers
  • devtool finish

次回以降でmodify, upgradeについて見ていきます。

 

 

シリーズ:devtoolの使い方<< devtoolの使い方 (2):レシピの作成(add)とビルドdevtoolの使い方 (4):修正(modify)とアップグレード(upgrade) >>

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

nineteen − 3 =

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください