LoginSignup
0
0

More than 1 year has passed since last update.

qemu-system-riscv64でubuntuをbootさせられなかった(失敗編)

Last updated at Posted at 2023-02-02

はじめに

タイトル通りの失敗談です。Ubuntu22.04で試したりdtbとかFDTとかいうのをなんとかかんとかほにゃららできれば動くかもしれません。 Ubuntu22.04で試したら動きました。

公式ドキュメントによる手法

これに従って入れた、が、そもそも手元にあるマシンはWSL上のUbuntu20.04で、ヴァージョンが古い。ブート途中で失敗した。ログは取り逃した。Ubuntu22.04だとちゃんと動くかもしれない。ら動いた。すいませんでした。

どこまで起動オプションを削れるか

公式ドキュメントにあるように、-biosとネット関連は削れます。メモリは1Gまでは削れます。それ以下はブートしないっぽい?

% qemu-system-riscv64 -machine virt -m 1024 -nographic -kernel /usr/lib/u-boot/qemu-riscv64_smode/uboot.elf -drive file=ubuntu-22.10-preinstalled-server-riscv64+unmatched.img,format=raw,if=virtio

ちなみに、QEMUのヴァージョンは6.2.0でした。ただ、7.2.0でも動いたので、QEMU自体の問題ではないようです。

u-bootを独自にビルドしたものを利用したらブートしませんでした。ここのビルドの問題っぽい。

nixを使ってQEMUを導入した手法

nix-shell -p qemuして、QEMU7.2.0を導入した。u-bootはv2023.01を手動でビルドした。

u-boot
% git clone git@github.com:u-boot/u-boot.git
% cd u-boot
% git checkout v2023.01
% make ARCH=riscv CROSS_COMPILE=riscv64-unknown-linux-gnu- qemu-riscv64_smode_defconfig
% make ARCH=riscv CROSS_COMPILE=riscv64-unknown-linux-gnu- all

ubuntuのディスクイメージはubuntu-22.10-preinstalled-server-riscv64+unmatched.img.xzを利用した。

qemu起動コマンド
% cd ..
% qemu-system-riscv64 --machine virt -nographic -m 512 -kernel u-boot/u-boot -drive file=ubuntu-22.10-preinstalled-server-riscv64+unmatched.img,format=raw,if=virtio
起動ログ

OpenSBI v1.1
   ____                    _____ ____ _____
  / __ \                  / ____|  _ \_   _|
 | |  | |_ __   ___ _ __ | (___ | |_) || |
 | |  | | '_ \ / _ \ '_ \ \___ \|  _ < | |
 | |__| | |_) |  __/ | | |____) | |_) || |_
  \____/| .__/ \___|_| |_|_____/|____/_____|
        | |
        |_|

Platform Name             : riscv-virtio,qemu
Platform Features         : medeleg
Platform HART Count       : 1
Platform IPI Device       : aclint-mswi
Platform Timer Device     : aclint-mtimer @ 10000000Hz
Platform Console Device   : uart8250
Platform HSM Device       : ---
Platform Reboot Device    : sifive_test
Platform Shutdown Device  : sifive_test
Firmware Base             : 0x80000000
Firmware Size             : 288 KB
Runtime SBI Version       : 1.0

Domain0 Name              : root
Domain0 Boot HART         : 0
Domain0 HARTs             : 0*
Domain0 Region00          : 0x0000000002000000-0x000000000200ffff (I)
Domain0 Region01          : 0x0000000080000000-0x000000008007ffff ()
Domain0 Region02          : 0x0000000000000000-0xffffffffffffffff (R,W,X)
Domain0 Next Address      : 0x0000000080200000
Domain0 Next Arg1         : 0x000000009fe00000
Domain0 Next Mode         : S-mode
Domain0 SysReset          : yes

Boot HART ID              : 0
Boot HART Domain          : root
Boot HART Priv Version    : v1.12
Boot HART Base ISA        : rv64imafdch
Boot HART ISA Extensions  : time,sstc
Boot HART PMP Count       : 16
Boot HART PMP Granularity : 4
Boot HART PMP Address Bits: 54
Boot HART MHPM Count      : 16
Boot HART MIDELEG         : 0x0000000000001666
Boot HART MEDELEG         : 0x0000000000f0b509


U-Boot 2023.01 (Jan 01 1980 - 00:00:00 +0000)

CPU:   rv64imafdch_zicsr_zifencei_zihintpause_zba_zbb_zbc_zbs_sstc
Model: riscv-virtio,qemu
DRAM:  512 MiB
Core:  25 devices, 12 uclasses, devicetree: board
Flash: 32 MiB
Loading Environment from nowhere... OK
In:    serial@10000000
Out:   serial@10000000
Err:   serial@10000000
Net:   No ethernet found.
Working FDT set to 9f735950
Hit any key to stop autoboot:  0

Device 0: 1af4 VirtIO Block Device
            Type: Hard Disk
            Capacity: 4608.0 MB = 4.5 GB (9437184 x 512)
... is now current device
Scanning virtio 0:1...
Found /boot/extlinux/extlinux.conf
Retrieving file: /boot/extlinux/extlinux.conf
U-Boot menu
1:      Ubuntu 22.10 5.19.0-1004-generic
2:      Ubuntu 22.10 5.19.0-1004-generic (rescue target)
Enter choice: 1
1:      Ubuntu 22.10 5.19.0-1004-generic
Retrieving file: /boot/initrd.img-5.19.0-1004-generic
Retrieving file: /boot/vmlinuz-5.19.0-1004-generic
append: root=LABEL=cloudimg-rootfs ro earlycon
Retrieving file: /lib/firmware/5.19.0-1004-generic/device-tree/qemu-riscv.dtb
** File not found /lib/firmware/5.19.0-1004-generic/device-tree/qemu-riscv.dtb **
Moving Image from 0x84000000 to 0x80200000, end=82133000
## Flattened Device Tree blob at 9f735950
   Booting using the fdt blob at 0x9f735950
Working FDT set to 9f735950
   Using Device Tree in place at 000000009f735950, end 000000009f739ded
Working FDT set to 9f735950
ERROR: fdt fixup event failed: -22
 - must RESET the board to recover.

FDT creation failed! hanging...### ERROR ### Please RESET the board ###
QEMU: Terminated

カーネルイメージのロードまではいってるっぽい。無理やりu-boot付属のdtbをコピーして使ってみたりもしたが正しく動かなかった。

おまけ

QEMUの終了はCtrl-a xよ。

opensbiのビルド
% make PLATFORM=generic ARCH=riscv CROSS_COMPILE=riscv64-unknown-linux-gnu-
ディスクイメージmount
% mkdir mnt
% sudo mount -o loop,offset=$((235520*512)) ubuntu-22.10-preinstalled-server-riscv64+unmatched.img mnt
起動編
% qemu-system-riscv64 --machine virt -nographic -m 512 -bios opensbi/build/platform/generic/firmware/fw_jump.elf -kernel u-boot/u-boot -drive file=ubuntu-22.10-preinstalled-server-riscv64+unmatched.img,format=raw,if=virtio -device virtio-net-device,netdev=eth0 -netdev user,id=eth0

#参考にしたサイト

0
0
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
0
0