Ports/riscv64/QEMU: Difference between revisions
IvanMelnikov (talk | contribs) No edit summary |
IvanMelnikov (talk | contribs) No edit summary |
||
Line 1: | Line 1: | ||
{{Stub}} | |||
QEMU, starting with version 6.0, include OpenSBI firmware. If you have an older QEMU version, follow the instructions to obtain and use the firmware below. | |||
Some older ALT images for QEMU include a VNC server that is used for system setup and graphics (see [[Regular/riscv64#VNC]] for more details). To access that server, it's convenient to forward port 5900. The necessary parameters for that are included into QEMU command lines below. | |||
== QEMU 6.0+ == | |||
QEMU 6.0 virtual machines with kernel 5.14+ have graphis (virtuo-gpu) and input (virtio-keyboard and virtio-mouse) working. | |||
Here are the steps to start a riscv64 virtual machine: | |||
'''Step 0''': Install QEMU with riscv64 support. If your host system is running ALT, you need [http://sisyphus.ru/en/srpm/Sisyphus/qemu qemu-system-riscv-core package]: | |||
apt-get install qemu-system-riscv-core | |||
On Ubuntu, riscv64 emulation is part of <tt>qemu-system-misc</tt>. | |||
'''Step 1''': Download the recent version of [https://packages.altlinux.org/ru/sisyphus/srpms/u-boot-qemu u-boot-qemu for riscv64]. You can use the riscv64 link from https://packages.altlinux.org/ru/sisyphus/srpms/u-boot-qemu/rpms. | |||
From the downloaded package, extract <tt>/usr/share/u-boot/qemu-riscv64_smode/u-boot.bin</tt>. For example: | |||
rpm2cpio u-boot-qemu-*riscv64.rpm | cpio -vi --to-stdout './usr/share/u-boot/qemu-riscv64_smode/u-boot.bin' > u-boot.bin | |||
'''Step 2''': Now you can start a virtual machine via the following commands: | |||
== | <source lang="shell"> | ||
$ IMAGE=<path to riscv64 image in img or qcow2 format> | |||
$ UBOOT=<path to u-boot.bin from step 1> | |||
$ qemu-system-riscv64 \ | |||
-nographic -m 2G -machine virt -kernel "$UBOOT" \ | |||
-smp cpus=4 \ | |||
-drive file=$IMAGE,id=hd0 -device virtio-blk-device,drive=hd0 \ | |||
-netdev user,id=eth0,hostfwd=tcp::5900-:5900 -device virtio-net-device,netdev=eth0 \ | |||
-device virtio-gpu,xres=1280,yres=800 -device virtio-keyboard -device virtio-tablet -sdl | |||
</source> | |||
== Older QEMU (pre-6.0) == | |||
For older QEMU, you need OpenSB (firmware) binary. | |||
''' | '''Option #1''' There is an OpenSBI firmware binary inside the qcow2/qcow2c image. You can copy it out of the image: | ||
<source lang=shell> | <source lang=shell> | ||
Line 18: | Line 52: | ||
</source> | </source> | ||
''' | '''Option #2''' [http://ftp.altlinux.org/pub/distributions/ALTLinux/ports/riscv64/Sisyphus/noarch/RPMS.classic/ Download] and install the latest version of OpenSBI for QEMU. | ||
and install the | |||
The OpenSBI firmware for QEMU virt will be at /usr/share/opensbi/qemu/virt/firmware/fw_payload.elf | The OpenSBI firmware for QEMU virt will be at <tt>/usr/share/opensbi/qemu/virt/firmware/fw_payload.elf</tt>. | ||
For example: | For example: | ||
Line 29: | Line 63: | ||
user$ FIRM=/usr/share/opensbi/qemu/virt/firmware/fw_payload.elf | user$ FIRM=/usr/share/opensbi/qemu/virt/firmware/fw_payload.elf | ||
</source> | </source> | ||
<source lang="shell"> | <source lang="shell"> | ||
Line 40: | Line 72: | ||
-netdev user,id=eth0,hostfwd=tcp::5900-:5900 -device virtio-net-device,netdev=eth0 | -netdev user,id=eth0,hostfwd=tcp::5900-:5900 -device virtio-net-device,netdev=eth0 | ||
</source> | </source> | ||
Revision as of 09:51, 22 November 2021
QEMU, starting with version 6.0, include OpenSBI firmware. If you have an older QEMU version, follow the instructions to obtain and use the firmware below.
Some older ALT images for QEMU include a VNC server that is used for system setup and graphics (see Regular/riscv64#VNC for more details). To access that server, it's convenient to forward port 5900. The necessary parameters for that are included into QEMU command lines below.
QEMU 6.0+
QEMU 6.0 virtual machines with kernel 5.14+ have graphis (virtuo-gpu) and input (virtio-keyboard and virtio-mouse) working.
Here are the steps to start a riscv64 virtual machine:
Step 0: Install QEMU with riscv64 support. If your host system is running ALT, you need qemu-system-riscv-core package:
apt-get install qemu-system-riscv-core
On Ubuntu, riscv64 emulation is part of qemu-system-misc.
Step 1: Download the recent version of u-boot-qemu for riscv64. You can use the riscv64 link from https://packages.altlinux.org/ru/sisyphus/srpms/u-boot-qemu/rpms.
From the downloaded package, extract /usr/share/u-boot/qemu-riscv64_smode/u-boot.bin. For example:
rpm2cpio u-boot-qemu-*riscv64.rpm | cpio -vi --to-stdout './usr/share/u-boot/qemu-riscv64_smode/u-boot.bin' > u-boot.bin
Step 2: Now you can start a virtual machine via the following commands:
$ IMAGE=<path to riscv64 image in img or qcow2 format>
$ UBOOT=<path to u-boot.bin from step 1>
$ qemu-system-riscv64 \
-nographic -m 2G -machine virt -kernel "$UBOOT" \
-smp cpus=4 \
-drive file=$IMAGE,id=hd0 -device virtio-blk-device,drive=hd0 \
-netdev user,id=eth0,hostfwd=tcp::5900-:5900 -device virtio-net-device,netdev=eth0 \
-device virtio-gpu,xres=1280,yres=800 -device virtio-keyboard -device virtio-tablet -sdl
Older QEMU (pre-6.0)
For older QEMU, you need OpenSB (firmware) binary.
Option #1 There is an OpenSBI firmware binary inside the qcow2/qcow2c image. You can copy it out of the image:
root$ qemu-nbd -c /dev/nbd0 qemu-riscv64.qcow2c
root$ mount /dev/nbd0p1 /mnt
root$ cp -v /mnt/usr/share/opensbi/qemu/virt/firmware/fw_payload.elf .
user$ FIRM=./fw_payload.elf
Option #2 Download and install the latest version of OpenSBI for QEMU.
The OpenSBI firmware for QEMU virt will be at /usr/share/opensbi/qemu/virt/firmware/fw_payload.elf.
For example:
user$ curl -O http://ftp.altlinux.org/pub/distributions/ALTLinux/ports/riscv64/Sisyphus/noarch/RPMS.classic/opensbi-firmware-qemu-0.6-alt1.noarch.rpm
root$ rpm -i opensbi-firmware-qemu-0.6-alt1.noarch.rpm
user$ FIRM=/usr/share/opensbi/qemu/virt/firmware/fw_payload.elf
$ QCOW=qemu-riscv64.qcow2c
$ qemu-system-riscv64 \
-nographic -machine virt -kernel "$FIRM" \
-m 2G -smp cpus=4 \
-drive file="$QCOW",id=hd0 -device virtio-blk-device,drive=hd0 \
-netdev user,id=eth0,hostfwd=tcp::5900-:5900 -device virtio-net-device,netdev=eth0