LoginSignup
11
2

More than 3 years have passed since last update.

TOPPERS向けQEMUをmacOSでビルドして動かす

Last updated at Posted at 2020-09-28

本記事は2020/09/29に公開した記事を 「TOPPERS Advent Calendar 2020」 向けに再試・編集したものです.


はじめに

QEMUをmacOSでソースビルドしたよっ!というお話しです.ちょっとした事情に特化してますが,macOSでソースビルドを頑張りたい方は,たぶん全般で参考になるかと思います.
ただし筆者の環境で実施した結果なので,他の方だとライブラリなど追加で必要になるかもしれません.もし追試された方がいましたら,コメント欄などで情報をお知らせください.

きっかけ

TOPPERS開発者会議2020に参加しました.例年は湯河原温泉が楽しみなのですが,オンライン開催で残念な感じでした.

2日目セッションの @exshonda 先生の企画された議論7「3. QEMUを用いたTOPPERS第3世代RTOSの実行ハンズオン」が面白かったです.仮想環境でTOPPERS第3世代カーネルが実行できるということで,実機無しでさくっとTOPPERSカーネルを楽しめます.なおこのQEMUは本家v2.12.0をTOPPERS向けにカスタマイズしたものになっているそうです.

Releaseで配布されているバイナリおよび動作確認環境は「Ubuntu 18.04 LTS(WSL含む)」になっていました.

$ wget https://github.com/toppers/qemu_zynq/releases/download/v2.12.0-toppers/qemu-system-arm.zip
$ unzip qemu-system-arm.zip 
$ file qemu-system-arm
qemu-system-arm: ELF 64-bit LSB pie executable, x86-64, version 1 (GNU/Linux), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=8b54e713de29f12c039669b6e3ad02a7c6410319, stripped

mac使いとしてはそりゃツラいよということで,ソースビルドを試みて使えるようにしてみました.

[宣伝] 箱庭もあります!! [PR]

ちなみに TOPPERSプロジェクト 箱庭WG では,athrillという命令レベルの仮想シミュレータの開発・公開を行っています!
この記事で取り上げているQEMUと実は競合するってウワサもあるんですが,,, TOPPERS純正でお気軽にカーネルを動かしてみたい!という方は,ぜひ使ってみてください^^;

ビルド環境・動作確認環境

  • macOS Catalina (10.15.6)
  • xcode-select version 2373
  • brew 2.6.1

ビルド作業

追加で必要だったもの

ひとまずGitHubからcloneしてビルドしようとしてみたところ,以下のエラーが出力されました.

$ git clone -b stable-2.12_toppers https://github.com/toppers/qemu_zynq.git
$ cd qemu_zynq
$ mkdir build
$ cd build
# 最初に試行したときのエラー
$ ../configure 

ERROR: glib-2.22 gthread-2.0 is required to compile QEMU

# glibをインストールしてから試行したときのエラー
$ ../configure 

ERROR: pixman >= 0.21.8 not present.
       Please install the pixman devel package.

それぞれに対応して,glibをソースビルド,pixmanをbrewでインストールしました.

$ wget http://ftp.gnome.org/pub/gnome/sources/glib/2.47/glib-2.47.4.tar.xz
$ tar xzf glib-2.47.4.tar.xz 
$ cd glib-2.47.4
$ ./configure --prefix=/usr/local
$ make 
$ make install

$ brew install pixman

なお,参考にした下記ページによると,glibのソースビルドにはgettextやlibxml2などいろいろ必要そうです.brewでインストールできる気がします(たぶん筆者はROSのために入れてあった気がする)

QEMUのビルド

必要なパッケージ・ライブラリが揃ったはずなので,make を掛けていきます.

$ cd qemu_zynq/build
$ cd build
$ ../configure --target-list=arm-softmmu
$ make

ビルドされたQEMUは arm-softmmu/qemu-system-arm です.
/usr/local/binなどPATHの通るところに置いておきましょう.

$ file arm-softmmu/qemu-system-arm 
arm-softmmu/qemu-system-arm: Mach-O 64-bit executable x86_64

$ cd arm-softmmu/qemu-system-arm /usr/local/bin/

その他に必要なもの

クロスコンパイラ

組込みなのでTOPPERSカーネル+アプリのビルドにarm-none-eabiが必要です.brewでインストールします.

$ brew tap ArmMbed/homebrew-formulae
$ brew install arm-none-eabi-gcc

$ which arm-none-eabi-gcc 
/usr/local/bin/arm-none-eabi-gcc

$ arm-none-eabi-gcc --version
arm-none-eabi-gcc (GNU Tools for Arm Embedded Processors 9-2019-q4-major) 9.2.1 20191025 (release) [ARM/arm-9-branch revision 277599]
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

gdbデバッガ

もともとの動作確認環境「Ubuntu 18.04 LTS(WSL含む)」ではgdb-multiarchを使用します.
macOSではbrewでインストールできるgdbで問題ありませんでした.

$ brew install gdb

$ which gdb 
/usr/local/bin/gdb

$ gdb --version 
GNU gdb (GDB) 9.2
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Makefileの編集

gdbの使用に合わせて,もともとの編集内容からちょっとだけ修正する必要があります.
2つめの gdb: のコマンドを gdb-multiarch から gdb に変更してください.

/asp3_3.5/target/zybo_z7_gcc/Makefile.target
runqd:$(OBJFILE)
        $(QEMU)  -M xilinx-zynq-a9 -m 16 -serial null -serial mon:stdio -S -gdb tcp::1234 -nographic
gdb:$(OBJFILE)
        gdb -ex="target remote :1234" -ex="monitor system_reset" -ex="load" $(OBJFILE)

おわりに

もう他の操作は,もともとの動作確認環境「Ubuntu 18.04 LTS(WSL含む)」と同じです.
ぜひQEMUでTOPPERSを試してみてください!!

11
2
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
11
2