🍭

qemuarm64環境でLua5.4.0を動かしてみる

2020/10/01に公開

qemu環境の作成

pokyのclone

$ git clone -b dunfell git://git.yoctoproject.org/poky.git
$ cd poky
$ source oe-init-build-env build001 

conf/local.confを以下のように修正

MACHINE ?= "qemuarm64" # デフォルトだとqemux86-64となっている
IMAGE_INSTALL_append = " openssh" # devtool deploy-targetで使用するため sshを追加
QB_SERIAL_OPT_append = " -serial mon:stdio" # qemuの起動オプション

meta/conf/machine/qemuarm64.confを以下のように修正
(-nographic を指定しないと -serial mon:stdio が有効にならないっぽい)

diff --git a/meta/conf/machine/qemuarm64.conf b/meta/conf/machine/qemuarm64.conf
index 2cf1a0206c..63e54bcea0 100644
--- a/meta/conf/machine/qemuarm64.conf
+++ b/meta/conf/machine/qemuarm64.conf
@@ -18,7 +18,8 @@ QB_CPU_KVM = "-cpu host -machine gic-version=3"
 # Standard Serial console
 QB_KERNEL_CMDLINE_APPEND = "console=ttyAMA0"
 # For graphics to work we need to define the VGA device as well as the necessary USB devices
-QB_OPT_APPEND = "-show-cursor -device VGA,edid=on"
+QB_OPT_APPEND = "-nographic "
 QB_OPT_APPEND += "-device qemu-xhci -device usb-tablet -device usb-kbd"
 # Add the 'virtio-rng-pci' device otherwise the guest may run out of entropy
 QB_OPT_APPEND += "-object rng-random,filename=/dev/urandom,id=rng0 -device virtio-rng-pci,rng=rng0"

イメージの作成

$ bitbake core-image-minimal 

Lua5.4.0の追加

devtoolを使用します。まずはレシピファイルの追加。

$ devtool add lua https://www.lua.org/ftp/lua-5.4.0.tar.gz
NOTE: Starting bitbake server...
NOTE: Starting bitbake server...
INFO: Fetching https://www.lua.org/ftp/lua-5.4.0.tar.gz...
Loading cache: 100% |###################################################################################################################| Time: 0:00:01
Loaded 1312 entries from dependency cache.
Parsing recipes: 100% |#################################################################################################################| Time: 0:00:00
Parsing of 773 .bb files complete (771 cached, 2 parsed). 1314 targets, 56 skipped, 0 masked, 0 errors.
NOTE: Resolving any missing task queue dependencies

Build Configuration:
BB_VERSION           = "1.46.0"
BUILD_SYS            = "x86_64-linux"
NATIVELSBSTRING      = "universal"
TARGET_SYS           = "aarch64-poky-linux"
MACHINE              = "qemuarm64"
DISTRO               = "poky"
DISTRO_VERSION       = "3.1.2"
TUNE_FEATURES        = "aarch64 armv8a crc"
TARGET_FPU           = ""
meta                 
meta-poky            
meta-yocto-bsp       
workspace            = "dunfell:f2ae38a055f54640a968c4a8d5074f044202380e"

Initialising tasks: 100% |##############################################################################################################| Time: 0:00:00
Sstate summary: Wanted 0 Found 0 Missed 0 Current 0 (0% match, 0% complete)
NOTE: No setscene tasks
NOTE: Executing Tasks
NOTE: Tasks Summary: Attempted 2 tasks of which 0 didn't need to be rerun and all succeeded.
INFO: Using default source tree path /home/USERNAME/yocto/poky/build001/workspace/sources/lua
NOTE: Reconnecting to bitbake server...
NOTE: Retrying server connection (#1)...
NOTE: Reconnecting to bitbake server...
NOTE: Reconnecting to bitbake server...
NOTE: Retrying server connection (#1)...
NOTE: Retrying server connection (#1)...
NOTE: Starting bitbake server...
INFO: Using source tree as build directory since that would be the default for this recipe
INFO: Recipe /home/USERNAME/yocto/poky/build001/workspace/recipes/lua/lua_5.4.0.bb has been automatically created; further editing may be required to make it fully functional

その後、ビルドをするとエラーになります。

$ devtool build lua
NOTE: Starting bitbake server...
NOTE: Reconnecting to bitbake server...
NOTE: Retrying server connection (#1)...
NOTE: Reconnecting to bitbake server...
NOTE: Previous bitbake instance shutting down?, waiting to retry...
NOTE: Retrying server connection (#2)...
Loading cache: 100% |###################################################################################################################| Time: 0:00:00
Loaded 1312 entries from dependency cache.
Parsing recipes: 100% |#################################################################################################################| Time: 0:00:00
Parsing of 773 .bb files complete (771 cached, 2 parsed). 1314 targets, 56 skipped, 0 masked, 0 errors.
Loading cache: 100% |###################################################################################################################| Time: 0:00:01
Loaded 1312 entries from dependency cache.
Parsing recipes: 100% |#################################################################################################################| Time: 0:00:00
Parsing of 773 .bb files complete (771 cached, 2 parsed). 1314 targets, 56 skipped, 0 masked, 0 errors.
NOTE: Resolving any missing task queue dependencies

Build Configuration:
BB_VERSION           = "1.46.0"
BUILD_SYS            = "x86_64-linux"
NATIVELSBSTRING      = "universal"
TARGET_SYS           = "aarch64-poky-linux"
MACHINE              = "qemuarm64"
DISTRO               = "poky"
DISTRO_VERSION       = "3.1.2"
TUNE_FEATURES        = "aarch64 armv8a crc"
TARGET_FPU           = ""
meta                 
meta-poky            
meta-yocto-bsp       
workspace            = "dunfell:f2ae38a055f54640a968c4a8d5074f044202380e"

Initialising tasks: 100% |##############################################################################################################| Time: 0:00:00
Sstate summary: Wanted 0 Found 0 Missed 0 Current 124 (0% match, 100% complete)
NOTE: Executing Tasks
NOTE: lua: compiling from external source tree /home/USERNAME/yocto/poky/build001/workspace/sources/lua
ERROR: lua-5.4.0-r0 do_install: oe_runmake failed
ERROR: lua-5.4.0-r0 do_install: Execution of '/home/USERNAME/yocto/poky/build001/tmp/work/aarch64-poky-linux/lua/5.4.0-r0/temp/run.do_install.76390' failed with exit code 1:
cd src && mkdir -p /usr/local/bin /usr/local/include /usr/local/lib /usr/local/man/man1 /usr/local/share/lua/5.4 /usr/local/lib/lua/5.4
mkdir: cannot create directory ‘/usr/local/share/lua’: Permission denied
mkdir: cannot create directory ‘/usr/local/lib/lua’: Permission denied
make: *** [Makefile:58: install] Error 1
WARNING: exit code 1 from a shell command.

ERROR: Logfile of failure stored in: /home/USERNAME/yocto/poky/build001/tmp/work/aarch64-poky-linux/lua/5.4.0-r0/temp/log.do_install.76390
Log data follows:
| DEBUG: Executing python function extend_recipe_sysroot
| NOTE: Direct dependencies are ['virtual:native:/home/USERNAME/yocto/poky/meta/recipes-devtools/pseudo/pseudo_git.bb:do_populate_sysroot', '/home/USERNAME/yocto/poky/meta/recipes-devtools/gcc/gcc-cross_9.3.bb:do_populate_sysroot', '/home/USERNAME/yocto/poky/meta/recipes-core/glibc/glibc_2.31.bb:do_populate_sysroot', '/home/USERNAME/yocto/poky/meta/recipes-devtools/gcc/gcc-runtime_9.3.bb:do_populate_sysroot']
| NOTE: Installed into sysroot: []
| NOTE: Skipping as already exists in sysroot: ['pseudo-native', 'gcc-cross-aarch64', 'glibc', 'gcc-runtime', 'automake-native', 'patch-native', 'xz-native', 'flex-native', 'zlib-native', 'gnu-config-native', 'quilt-native', 'linux-libc-headers', 'gmp-native', 'libtool-native', 'autoconf-native', 'texinfo-dummy-native', 'mpfr-native', 'binutils-cross-aarch64', 'libmpc-native', 'libgcc', 'attr-native', 'gettext-minimal-native', 'm4-native']
| DEBUG: Python function extend_recipe_sysroot finished
| DEBUG: Executing shell function do_install
| NOTE: make -j 4 install
| cd src && mkdir -p /usr/local/bin /usr/local/include /usr/local/lib /usr/local/man/man1 /usr/local/share/lua/5.4 /usr/local/lib/lua/5.4
| mkdir: cannot create directory ‘/usr/local/share/lua’: Permission denied
| mkdir: cannot create directory ‘/usr/local/lib/lua’: Permission denied
| make: *** [Makefile:58: install] Error 1
| ERROR: oe_runmake failed
| WARNING: exit code 1 from a shell command.
| ERROR: Execution of '/home/USERNAME/yocto/poky/build001/tmp/work/aarch64-poky-linux/lua/5.4.0-r0/temp/run.do_install.76390' failed with exit code 1:
| cd src && mkdir -p /usr/local/bin /usr/local/include /usr/local/lib /usr/local/man/man1 /usr/local/share/lua/5.4 /usr/local/lib/lua/5.4
| mkdir: cannot create directory ‘/usr/local/share/lua’: Permission denied
| mkdir: cannot create directory ‘/usr/local/lib/lua’: Permission denied
| make: *** [Makefile:58: install] Error 1
| WARNING: exit code 1 from a shell command.
| 
ERROR: Task (/home/USERNAME/yocto/poky/build001/workspace/recipes/lua/lua_5.4.0.bb:do_install) failed with exit code '1'
NOTE: Tasks Summary: Attempted 528 tasks of which 523 didn't need to be rerun and 1 failed.

Summary: 1 task failed:
  /home/USERNAME/yocto/poky/build001/workspace/recipes/lua/lua_5.4.0.bb:do_install
Summary: There were 2 ERROR messages shown, returning a non-zero exit code.

長いですが、原因は以下。
/usr/local/以下にインストールしようとしてしまっています。

mkdir: cannot create directory ‘/usr/local/share/lua’: Permission denied
mkdir: cannot create directory ‘/usr/local/lib/lua’: Permission denied

Makefileを見ると以下のようにINSTALL_TOPで"/usr/local"が指定されています。

INSTALL_TOP= /usr/local # <-- ここ
INSTALL_BIN= $(INSTALL_TOP)/bin
INSTALL_INC= $(INSTALL_TOP)/include
INSTALL_LIB= $(INSTALL_TOP)/lib
INSTALL_MAN= $(INSTALL_TOP)/man/man1
INSTALL_LMOD= $(INSTALL_TOP)/share/lua/$V
INSTALL_CMOD= $(INSTALL_TOP)/lib/lua/$V

なので、ここをコメントアウトします。

# INSTALL_TOP= /usr/local # コメントアウトする

recipes/lua/lua_5.4.0.bb の do_installを以下のように修正。
${D}の説明はこちら(Yocto Project Mega-Manual)

do_install () {
	# This is a guess; additional arguments may be required
	oe_runmake install INSTALL_TOP=${D} # INSTALL_TOP=${D}を追加 
}

これでもう一度ビルドを試みます。
残念ですが、これも失敗します。

$ devtool build lua
NOTE: Starting bitbake server...
NOTE: Reconnecting to bitbake server...
NOTE: Retrying server connection (#1)...
NOTE: Reconnecting to bitbake server...
NOTE: Previous bitbake instance shutting down?, waiting to retry...
NOTE: Retrying server connection (#2)...
Loading cache: 100% |###################################################################################################################| Time: 0:00:00
Loaded 1312 entries from dependency cache.
Parsing recipes: 100% |#################################################################################################################| Time: 0:00:00
Parsing of 773 .bb files complete (771 cached, 2 parsed). 1314 targets, 56 skipped, 0 masked, 0 errors.
Loading cache: 100% |###################################################################################################################| Time: 0:00:01
Loaded 1312 entries from dependency cache.
Parsing recipes: 100% |#################################################################################################################| Time: 0:00:00
Parsing of 773 .bb files complete (771 cached, 2 parsed). 1314 targets, 56 skipped, 0 masked, 0 errors.
NOTE: Resolving any missing task queue dependencies

Build Configuration:
BB_VERSION           = "1.46.0"
BUILD_SYS            = "x86_64-linux"
NATIVELSBSTRING      = "universal"
TARGET_SYS           = "aarch64-poky-linux"
MACHINE              = "qemuarm64"
DISTRO               = "poky"
DISTRO_VERSION       = "3.1.2"
TUNE_FEATURES        = "aarch64 armv8a crc"
TARGET_FPU           = ""
meta                 
meta-poky            
meta-yocto-bsp       
workspace            = "dunfell:f2ae38a055f54640a968c4a8d5074f044202380e"

Initialising tasks: 100% |##############################################################################################################| Time: 0:00:00
Sstate summary: Wanted 0 Found 0 Missed 0 Current 124 (0% match, 100% complete)
NOTE: Executing Tasks
NOTE: lua: compiling from external source tree /home/USERNAME/yocto/poky/build001/workspace/sources/lua
ERROR: lua-5.4.0-r0 do_package: Fatal errors occurred in subprocesses:
Command '['aarch64-poky-linux-objcopy', '--only-keep-debug', '/home/USERNAME/yocto/poky/build001/tmp/work/aarch64-poky-linux/lua/5.4.0-r0/package/bin/lua', '/home/USERNAME/yocto/poky/build001/tmp/work/aarch64-poky-linux/lua/5.4.0-r0/package/bin/.debug/lua']' returned non-zero exit status 1.
Subprocess output:aarch64-poky-linux-objcopy: Unable to recognise the format of the input file `/home/USERNAME/yocto/poky/build001/tmp/work/aarch64-poky-linux/lua/5.4.0-r0/package/bin/lua'
Command '['aarch64-poky-linux-objcopy', '--only-keep-debug', '/home/USERNAME/yocto/poky/build001/tmp/work/aarch64-poky-linux/lua/5.4.0-r0/package/bin/luac', '/home/USERNAME/yocto/poky/build001/tmp/work/aarch64-poky-linux/lua/5.4.0-r0/package/bin/.debug/luac']' returned non-zero exit status 1.
Subprocess output:aarch64-poky-linux-objcopy: Unable to recognise the format of the input file `/home/USERNAME/yocto/poky/build001/tmp/work/aarch64-poky-linux/lua/5.4.0-r0/package/bin/luac'

ERROR: Logfile of failure stored in: /home/USERNAME/yocto/poky/build001/tmp/work/aarch64-poky-linux/lua/5.4.0-r0/temp/log.do_package.79056
ERROR: Task (/home/USERNAME/yocto/poky/build001/workspace/recipes/lua/lua_5.4.0.bb:do_package) failed with exit code '1'
NOTE: Tasks Summary: Attempted 530 tasks of which 526 didn't need to be rerun and 1 failed.

Summary: 1 task failed:
  /home/USERNAME/yocto/poky/build001/workspace/recipes/lua/lua_5.4.0.bb:do_package
Summary: There was 1 ERROR message shown, returning a non-zero exit code.

meta/classes/package.bbclassの以下が関係しているっぽい

    #
    # First lets process debug splitting
    #
    if (d.getVar('INHIBIT_PACKAGE_DEBUG_SPLIT') != '1'):
        results = oe.utils.multiprocess_launch(splitdebuginfo, list(elffiles), d, extraargs=(dvar, debugdir, debuglibdir, debugappend, debugsrcdir, d))

詳細は不明...
とりあえず、パッケージ(?)の作成は不要と考え、パッケージ作成関連する処理をスキップするようにする。
参考にしたドキュメントは以下

recipes/lua/lua_5.4.0.bb に以下追加。

do_package[noexec] = "1"
do_packagedata[noexec] = "1"
do_package_qa[noexec] = "1"
INHIBIT_PACKAGE_STRIP = "1"
INHIBIT_PACKAGE_DEBUG_SPLIT = "1"

あとよく見たら、コンパイラの指定が gcc固定となっていたので
sources/lua/src/Makefileを以下のように修正。

# Your platform. See PLATS for possible values.
PLAT= linux # linuxに変更

#CC= gcc -std=gnu99 # コメントアウト

sources/lua/Makefileも以下のように修正

PLAT= linux # linuxに変更

これでやっとビルドが通りました。

$ devtool build lua
NOTE: Starting bitbake server...
NOTE: Reconnecting to bitbake server...
NOTE: Retrying server connection (#1)...
Loading cache: 100% |###################################################################################################################| Time: 0:00:00
Loaded 1312 entries from dependency cache.
Parsing recipes: 100% |#################################################################################################################| Time: 0:00:00
Parsing of 773 .bb files complete (771 cached, 2 parsed). 1314 targets, 56 skipped, 0 masked, 0 errors.
Loading cache: 100% |###################################################################################################################| Time: 0:00:01
Loaded 1312 entries from dependency cache.
Parsing recipes: 100% |#################################################################################################################| Time: 0:00:00
Parsing of 773 .bb files complete (771 cached, 2 parsed). 1314 targets, 56 skipped, 0 masked, 0 errors.
NOTE: Resolving any missing task queue dependencies

Build Configuration:
BB_VERSION           = "1.46.0"
BUILD_SYS            = "x86_64-linux"
NATIVELSBSTRING      = "universal"
TARGET_SYS           = "aarch64-poky-linux"
MACHINE              = "qemuarm64"
DISTRO               = "poky"
DISTRO_VERSION       = "3.1.2"
TUNE_FEATURES        = "aarch64 armv8a crc"
TARGET_FPU           = ""
meta                 
meta-poky            
meta-yocto-bsp       
workspace            = "dunfell:f2ae38a055f54640a968c4a8d5074f044202380e"

Initialising tasks: 100% |##############################################################################################################| Time: 0:00:00
Sstate summary: Wanted 0 Found 0 Missed 0 Current 124 (0% match, 100% complete)
NOTE: Executing Tasks
NOTE: Tasks Summary: Attempted 531 tasks of which 529 didn't need to be rerun and all succeeded.

qemu環境へLuaのコピー

まず、qemuを起動します。

$ runqemu tmp/deploy/images/qemuarm64/

次に、別のウィンドウから以下のように
devtoolを実行。これでLuaが qemu環境にコピーされます。

$ devtool deploy-target -s lua root@192.168.7.2
NOTE: Starting bitbake server...
NOTE: Reconnecting to bitbake server...
NOTE: Retrying server connection (#1)...
Loading cache: 100% |###################################################################################################################| Time: 0:00:01
Loaded 1312 entries from dependency cache.
Parsing recipes: 100% |#################################################################################################################| Time: 0:00:00
Parsing of 773 .bb files complete (771 cached, 2 parsed). 1314 targets, 56 skipped, 0 masked, 0 errors.
devtool_deploy.list                                                                                                  100%  187    34.2KB/s   00:00    
devtool_deploy.sh                                                                                                    100% 1017   324.8KB/s   00:00    
./
./lib/
./lib/liblua.a
./lib/lua/
./lib/lua/5.4/
./include/
./include/lauxlib.h
./include/lua.hpp
./include/lualib.h
./include/lua.h
./include/luaconf.h
./man/
./man/man1/
./man/man1/luac.1
./man/man1/lua.1
./bin/
./bin/lua
./bin/luac
./share/
./share/lua/
./share/lua/5.4/
INFO: Successfully deployed /home/USERNAME/yocto/poky/build001/tmp/work/aarch64-poky-linux/lua/5.4.0-r0/image

先程起動したqemu側でluaを実行してみます。

root@qemuarm64:~# lua
Lua 5.4.0  Copyright (C) 1994-2020 Lua.org, PUC-Rio
> exit()
stdin:1: attempt to call a nil value (global 'exit')
stack traceback:
	stdin:1: in main chunk
	[C]: in ?
> a = 10
> b = 20
> b + a
30
> ^C
root@qemuarm64:~# 

できました。

Discussion