QEMUからRISC-Vイメージを立ち上げる
作成したイメージをQEMUから立ち上げましょう。必要なのはRISC-V用のエミュレーターとファームウェア,
$ sudo apt install --no-install-recommends \ qemu-system-misc opensbi
amd64などのアーキテクチャーと異なり,
RISC-V向けのU-Boot本体は残念ながらUbuntuのリポジトリに存在しません。U-Boot 2019.
$ wget http://ftp.jp.debian.org/debian/pool/main/u/u-boot/u-boot-qemu_2020.01+dfsg-1_all.deb $ sudo apt install ./u-boot-qemu_2020.01+dfsg-1_all.deb
本パッケージはQEMU上で動かすバイナリの集合体のようなものであり,
さて,
$ qemu-system-riscv64 -nographic -machine virt -m 2G \ -kernel /usr/lib/riscv64-linux-gnu/opensbi/qemu/virt/fw_jump.elf \ -device loader,file=/usr/lib/u-boot/qemu-riscv64_smode/u-boot.bin,addr=0x80200000 \ -object rng-random,filename=/dev/urandom,id=rng0 -device virtio-rng-device,rng=rng0 \ -append "console=ttyS0 rw root=/dev/vda1" \ -device virtio-blk-device,drive=hd0 -drive file=rootfs-riscv64.img,format=raw,id=hd0 \ -device virtio-net-device,netdev=usernet -netdev user,id=usernet,hostfwd=tcp::22222-:22
まずはU-Bootが立ち上がります。
OpenSBI v0.5 (Oct 12 2019 06:02:51) ____ _____ ____ _____ / __ \ / ____| _ \_ _| | | | |_ __ ___ _ __ | (___ | |_) || | | | | | '_ \ / _ \ '_ \ \___ \| _ < | | | |__| | |_) | __/ | | |____) | |_) || |_ \____/| .__/ \___|_| |_|_____/|____/_____| | | |_| Platform Name : QEMU Virt Machine Platform HART Features : RV64ACDFIMSU Platform Max HARTs : 8 Current Hart : 0 Firmware Base : 0x80000000 Firmware Size : 116 KB Runtime SBI Version : 0.2 PMP0: 0x0000000080000000-0x000000008001ffff (A) PMP1: 0x0000000000000000-0xffffffffffffffff (A,R,W,X) U-Boot 2020.01+dfsg-1 (Jan 08 2020 - 08:19:44 +0000) CPU: rv64imafdcsu Model: riscv-virtio,qemu DRAM: 2 GiB In: uart@10000000 Out: uart@10000000 Err: uart@10000000 Net: Warning: virtio-net#2 using MAC address from ROM eth0: virtio-net#2 Hit any key to stop autoboot: 0 Device 0: QEMU VirtIO Block Device Type: Hard Disk Capacity: 10240.0 MB = 10.0 GB (20971520 x 512) ... is now current device Scanning virtio 0:1... Found /boot/extlinux/extlinux.conf Retrieving file: /boot/extlinux/extlinux.conf 611 bytes read in 1 ms (596.7 KiB/s) U-Boot menu 1: Debian GNU/Linux kernel 5.4.0-2-riscv64 2: Debian GNU/Linux kernel 5.4.0-2-riscv64 (rescue target) Enter choice: 1
「U-Boot menu」
1: Debian GNU/Linux kernel 5.4.0-2-riscv64 Retrieving file: /boot/initrd.img-5.4.0-2-riscv64 49472068 bytes read in 47 ms (1003.8 MiB/s) Retrieving file: /boot/vmlinux-5.4.0-2-riscv64 9381656 bytes read in 13 ms (688.2 MiB/s) append: rw noquiet root=/dev/vda1 ## Flattened Device Tree blob at ff7410c0 Booting using the fdt blob at 0xff7410c0 Using Device Tree in place at 00000000ff7410c0, end 00000000ff744d99 Starting kernel ... [ 0.000000] OF: fdt: Ignoring memory range 0x80000000 - 0x80200000 [ 0.000000] Linux version 5.4.0-2-riscv64 (debian-kernel@lists.debian.org) (gcc version 9.2.1 20200104 (Debian 9.2.1-22)) #1 SMP Debian 5.4 .8-1 (2020-01-05) [ 0.000000] Initial ramdisk at: 0x(____ptrval____) (49472068 bytes) [ 0.000000] Zone ranges: [ 0.000000] DMA32 [mem 0x0000000080200000-0x00000000ffffffff] [ 0.000000] Normal empty [ 0.000000] Movable zone start for each node [ 0.000000] Early memory node ranges [ 0.000000] node 0: [mem 0x0000000080200000-0x00000000ffffffff] [ 0.000000] Initmem setup node 0 [mem 0x0000000080200000-0x00000000ffffffff] [ 0.000000] software IO TLB: mapped [mem 0xf9741000-0xfd741000] (64MB) [ 0.000000] elf_hwcap is 0x112d [ 0.000000] percpu: Embedded 26 pages/cpu s68440 r8192 d29864 u106496 [ 0.000000] Built 1 zonelists, mobility grouping on. Total pages: 515592 [ 0.000000] Kernel command line: rw noquiet root=/dev/vda1
カーネルとinitramfsがロードされて起動を開始します。
Debian GNU/Linux bullseye/sid riscv ttyS0 riscv login: shibata Password: Linux riscv 5.4.0-2-riscv64 #1 SMP Debian 5.4.8-1 (2020-01-05) riscv64 The programs included with the Debian GNU/Linux system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright. Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. shibata@riscv:~$
systemdも起動したらログインバナーが表示されるので,
/proc/
を確認するとRISC-VのISAモードが表示されていることがわかります。
shibata@riscv:~$ cat /proc/cpuinfo processor : 0 hart : 0 isa : rv64imafdcu mmu : sv48
もちろん,
shibata@riscv:~$ file /usr/bin/busybox /usr/bin/busybox: ELF 64-bit LSB shared object, UCB RISC-V, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-riscv64-lp64d.so.1, for GNU/Linux 4.15.0, BuildID[sha1]=5cbc897e13ba8b5015132999916418f8423d5728, stripped
あとは
ちなみに動いているのはQEMUの上なので,
QEMU 4.0.0 monitor - type 'help' for more information (qemu) info registers pc ffffffe000085596 mhartid 0000000000000000 mstatus 0000000000000000 mip 0000000000000000 mie 00000000000002aa mideleg 0000000000000222 medeleg 000000000000b109 mtvec 0000000080000488 mepc ffffffe00046d810 mcause 0000000000000009 zero 0000000000000000 ra ffffffe0000bdf94 sp ffffffe0007d3f30 gp ffffffe00087f080 tp ffffffe0007da300 t0 0000000000000000 t1 0000000000006000 t2 0000000000003933 s0 ffffffe0007d3f40 s1 ffffffe00087f7a0 a0 ffffffe0000bdf94 a1 0000000000000001 a2 0000000000000000 a3 ffffffe0008b6b58 a4 000000000000083e a5 0000000000000000 a6 000000005bd58b6b a7 0000000000000000 s2 0000000000000000 s3 ffffffe00087f96c s4 0000000000000001 s5 ffffffe00087f618 s6 ffffffe000036008 s7 0000000000000000 s8 00000000fff63cc6 s9 0000000000000003 s10 0000000000000000 s11 00000000ff770b10 t3 0000000000000000 t4 0000000000000001 t5 ffffffe000705838 t6 0000000000000000 ft0 0000000000000000 ft1 0000000000000000 ft2 0000000000000000 ft3 0000000000000000 ft4 0000000000000000 ft5 0000000000000000 ft6 0000000000000000 ft7 0000000000000000 fs0 0000000000000000 fs1 0000000000000000 fa0 0000000000000000 fa1 0000000000000000 fa2 0000000000000000 fa3 0000000000000000 fa4 0000000000000000 fa5 0000000000000000 fa6 0000000000000000 fa7 0000000000000000 fs2 0000000000000000 fs3 0000000000000000 fs4 0000000000000000 fs5 0000000000000000 fs6 0000000000000000 fs7 0000000000000000 fs8 0000000000000000 fs9 0000000000000000 fs10 0000000000000000 fs11 0000000000000000 ft8 0000000000000000 ft9 0000000000000000 ft10 0000000000000000 ft11 0000000000000000