LoginSignup
5
3

More than 5 years have passed since last update.

QEMUでARMのU-bootを動かす

Posted at

QEMUを使って、その上でU-Bootを動かしてみました。

本当はRaspberry Pi 3のモデルを使いたかったのですが、うまく動かなかったのでvexpressのモデルを使いましました。

準備

環境としては、Vagrant上のUbutu 18.04 LTSを使いました。
コンパイルに必要なパッケージをインストールします。
(最初 Ubuntu 16.04LTSを使ったら、必要なライブラリのバージョンが古くて失敗でした。)

% sudo apt build-dep qemu
% sudo apt install gcc-arm-linux-gnueabihf

QEMU

QEMUは、その時点での最新リリースの 2.12を使いました。
 (最初 tar.xzのソースを持ってきてコンパイルしたら失敗したので、gitで取得したらOKでした。サブモジュールが不一致だったみたいです。)

$ git clone git://git.qemu.org/qemu.git
$ cd qemu
$ git checkout -b v2.12.0-release refs/tags/v2.12.0
$ git submodule update --init

$ ./configure --prefix=`pwd`/build --target-list=arm-softmmu,aarch64-softmmu --audio-drv-list=alsa
$ make
$ make install

U-Boot

gitでソースコードを取得。
コンフィグを生成して、コンパイル。

$ git clone git://git.denx.de/u-boot.git
$ cd u-boot
$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- vexpress_ca9x4_defconfig
$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf-

動作例

vexpress-a9のモデルを使って32bitのARMエミュレータで起動する。

$ cd ..
$ qemu/build/bin/qemu-system-arm  -M vexpress-a9 -nographic -kernel u-boot/u-boot

u-boot/configs/vexpress_ca9x4_defconfigによると、0x60800000にプログラムが配置されているので、U-bootとQEMUでメモリダンプしてみました。 同じ内容が表示されることを確認してみた。

QEMUのモニタに接続には、コマンドラインでCtrl-A cを入力します。

QEMUを終了するときは、Ctrl-A xを入力する、Ctrl-A hを入力で簡単なヘルプが表示されます。

U-Boot 2018.05-00167-g57a72d0560-dirty (May 12 2018 - 08:00:26 +0000)

DRAM:  128 MiB
WARNING: Caches not enabled
Flash: 128 MiB
MMC:   MMC: 0
*** Warning - bad CRC, using default environment

In:    serial
Out:   serial
Err:   serial
Net:   smc911x-0
Hit any key to stop autoboot:  0 
MMC Device 1 not found
no mmc device at slot 1
Card did not respond to voltage select!
smc911x: MAC 52:54:00:12:34:56
smc911x: detected LAN9118 controller
smc911x: phy initialized
smc911x: MAC 52:54:00:12:34:56
BOOTP broadcast 1
DHCP client bound to address 10.0.2.15 (17 ms)
*** Warning: no boot file name; using '0A00020F.img'
Using smc911x-0 device
TFTP from server 10.0.2.2; our IP address is 10.0.2.15
Filename '0A00020F.img'.
Load address: 0x80008000
Loading: *
TFTP error: 'Access violation' (2)
...(TFTPのエラーが続くが省略)
...
Not retrying...
smc911x: MAC 52:54:00:12:34:56
smc911x: MAC 52:54:00:12:34:56
Wrong Image Format for bootm command
ERROR: can't get kernel image!
=> md 60800000
60800000: ea0000b8 e59ff014 e59ff014 e59ff014    ................
60800010: e59ff014 e59ff014 e59ff014 e59ff014    ................
60800020: 60800060 608000c0 60800120 60800180    `..`...` ..`...`
60800030: 608001e0 60800240 608002a0 deadbeef    ...`@..`...`....
60800040: 0badc0de e320f000 e320f000 e320f000    ...... ... ... .
60800050: e320f000 e320f000 e320f000 e320f000    .. ... ... ... .
60800060: e51fd028 e58de000 e14fe000 e58de004    (.........O.....
60800070: e3a0d013 e169f00d e1a0e00f e1b0f00e    ......i.........
60800080: e24dd048 e88d1fff e51f2050 e892000c    H.M.....P ......
60800090: e28d0048 e28d5034 e1a0100e e885000f    H...4P..........
608000a0: e1a0000d eb000464 e320f000 e320f000    ....d..... ... .
608000b0: e320f000 e320f000 e320f000 e320f000    .. ... ... ... .
608000c0: e51fd088 e58de000 e14fe000 e58de004    ..........O.....
608000d0: e3a0d013 e169f00d e1a0e00f e1b0f00e    ......i.........
608000e0: e24dd048 e88d1fff e51f20b0 e892000c    H.M...... ......
608000f0: e28d0048 e28d5034 e1a0100e e885000f    H...4P..........
=>
(qemu) xp/40xw 0x60800000
0000000060800000: 0xea0000b8 0xe59ff014 0xe59ff014 0xe59ff014
0000000060800010: 0xe59ff014 0xe59ff014 0xe59ff014 0xe59ff014
0000000060800020: 0x60800060 0x608000c0 0x60800120 0x60800180
0000000060800030: 0x608001e0 0x60800240 0x608002a0 0xdeadbeef
0000000060800040: 0x0badc0de 0xe320f000 0xe320f000 0xe320f000
0000000060800050: 0xe320f000 0xe320f000 0xe320f000 0xe320f000
0000000060800060: 0xe51fd028 0xe58de000 0xe14fe000 0xe58de004
0000000060800070: 0xe3a0d013 0xe169f00d 0xe1a0e00f 0xe1b0f00e
0000000060800080: 0xe24dd048 0xe88d1fff 0xe51f2050 0xe892000c
0000000060800090: 0xe28d0048 0xe28d5034 0xe1a0100e 0xe885000f
(qemu) xp/40i 0x60800000
0x60800000:  ea0000b8  b        #0x608002e8
0x60800004:  e59ff014  ldr      pc, [pc, #0x14]
0x60800008:  e59ff014  ldr      pc, [pc, #0x14]
0x6080000c:  e59ff014  ldr      pc, [pc, #0x14]
0x60800010:  e59ff014  ldr      pc, [pc, #0x14]
0x60800014:  e59ff014  ldr      pc, [pc, #0x14]
0x60800018:  e59ff014  ldr      pc, [pc, #0x14]
0x6080001c:  e59ff014  ldr      pc, [pc, #0x14]
0x60800020:  e59ff014  ldr      pc, [pc, #0x14]
0x60800024:  e59ff014  ldr      pc, [pc, #0x14]
0x60800028:  e59ff014  ldr      pc, [pc, #0x14]
0x6080002c:  e59ff014  ldr      pc, [pc, #0x14]
0x60800030:  e59ff014  ldr      pc, [pc, #0x14]
0x60800034:  e59ff014  ldr      pc, [pc, #0x14]
0x60800038:  e59ff014  ldr      pc, [pc, #0x14]
0x6080003c:  60800060  addvs    r0, r0, r0, rrx
0x60800040:  608000c0  addvs    r0, r0, r0, asr #1
0x60800044:  60800120  addvs    r0, r0, r0, lsr #2
0x60800048:  60800180  addvs    r0, r0, r0, lsl #3
0x6080004c:  608001e0  addvs    r0, r0, r0, ror #3
0x60800050:  60800240  addvs    r0, r0, r0, asr #4
0x60800054:  608002a0  addvs    r0, r0, r0, lsr #5
0x60800058:  deadbeef  cdple    p14, #0xa, c11, c13, c15, #7
0x6080005c:  0badc0de  bleq     #0x5f3703dc
0x60800060:  e320f000  nop      
0x60800064:  e320f000  nop      
0x60800068:  e320f000  nop      
0x6080006c:  e320f000  nop      
0x60800070:  e320f000  nop      
0x60800074:  e320f000  nop      
0x60800078:  e320f000  nop      
0x6080007c:  e51fd028  ldr      sp, [pc, #-0x28]
0x60800080:  e58de000  str      lr, [sp]
0x60800084:  e14fe000  mrs      lr, spsr
0x60800088:  e58de004  str      lr, [sp, #4]
0x6080008c:  e3a0d013  mov      sp, #0x13
0x60800090:  e169f00d  msr      spsr_fc, sp
0x60800094:  e1a0e00f  mov      lr, pc
0x60800098:  e1b0f00e  movs     pc, lr
0x6080009c:  e24dd048  sub      sp, sp, #0x48
(qemu)
(qemu) QEMU: Terminated

参考にしたページ

5
3
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
5
3