Ports/riscv64/QEMU: Difference between revisions

From ALT Linux Wiki
< Ports‎ | riscv64
No edit summary
(Change in according to russian article)
Line 6: Line 6:
QEMU, starting with version 6.0, includes OpenSBI firmware. For older QEMU versions, there are instructions how to obtain and use the firmware in [[#OpenSBI]] section below.
QEMU, starting with version 6.0, includes OpenSBI firmware. For older QEMU versions, there are instructions how to obtain and use the firmware in [[#OpenSBI]] section below.


Some older ALT images for QEMU include a VNC server that provides access to graphical system setup and graphical desktop (see [[Regular/riscv64#VNC]] for more details). To access that server, it's convenient to forward port 5900 from the virtual machine to the host machine. The parameters necessary for that are included into QEMU command lines below.
Some older ALT images for QEMU include a VNC server that provides access to initial setup and graphical desktop (see [[Regular/riscv64#VNC]] for more details). To access that server, it's convenient to forward port 5900 from the virtual machine to the host machine. The parameters necessary for that are included into QEMU command lines below.


== ALT Images ==
== QEMU 6.0+ ==


Currently, we recommend [[Regular/riscv64|Regular builds]] (see also: [[Regular]]).
QEMU 6.0 virtual machines with kernel 5.14+ have graphics (virtuo-gpu) and input (virtio-keyboard and virtio-tablet) working using U-boot boot loader.


== Quickstart for QEMU 6.0+ ==
Here are the steps run images in QEMU:


QEMU 6.0 virtual machines with kernel 5.14+ have graphics (virtuo-gpu) and input (virtio-keyboard and virtio-mouse) working.
'''Step 0''': Install QEMU with riscv64 support to run the ALT port on RISC-V. If your host system is running ALT x86_64, you need [http://sisyphus.ru/en/srpm/Sisyphus/qemu qemu-system-riscv-core package]:


Here are the steps to start a riscv64 virtual machine:
  apt-get install qemu-system-riscv-core qemu-device-display-virtio-gpu-gl qemu-ui-sdl seavgabios


'''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]:
'''Step 1''': Download the recent version of <code>u-boot-qemu</code> for riscv64. You can use [https://packages.altlinux.org/en/sisyphus_riscv64/srpms/u-boot-sifive/rpms/ the link to the package on the official website of the Sisyphus repository]. Or find the package directly in the [http://ftp.altlinux.org/pub/distributions/ALTLinux/ports/riscv64/Sisyphus/noarch/RPMS.classic/ repository].


  apt-get install qemu-system-riscv-core
Extract '''/usr/share/u-boot/qemu-riscv64_smode/u-boot.bin''' file from the downloaded package. For example:


On Ubuntu, riscv64 emulation is part of <tt>qemu-system-misc</tt>.
rpm2cpio u-boot-qemu-*.rpm | cpio -vi --to-stdout './usr/share/u-boot/qemu-riscv64_smode/u-boot.bin' > u-boot.bin


'''Step 1''':  Download the recent version of u-boot-qemu for riscv64. You can use the link from https://packages.altlinux.org/en/sisyphus_riscv64/srpms/u-boot-sifive/rpms/.
'''Step 2''':  Now you can start a virtual machine on QEMU via the following commands. Give directions in IMAGE to image and in UBOOT to u-boot that you got in step 1:
 
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">
<source lang="shell">
$ IMAGE=<path to riscv64 image in img or qcow2 format>
$ IMAGE=<путь до образа>
$ UBOOT=<path to u-boot.bin from step 1>
$ UBOOT=<путь до u-boot.bin>
$ qemu-system-riscv64 \
$ qemu-system-riscv64 \
           -nographic -m 2G  -machine virt -kernel "$UBOOT" \
           -nographic -m 2G  -machine virt -kernel "$UBOOT" \
Line 40: Line 34:
           -drive file=$IMAGE,id=hd0 -device virtio-blk-device,drive=hd0  \
           -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 \
           -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  
           -device virtio-vga-gl,xres=1280,yres=800 -device virtio-keyboard -device virtio-tablet -display sdl,gl=on
</source>
 
If you need access via vnc, then you need to specify "-vnc: 1" instead of "-sdl" and connect to 5901 port (5900 port is taken for network forwarding):
 
<source lang="shell">
$ vncviewer localhost:5901
</source>
</source>


Line 47: Line 47:
To run riscv64 virtual machine on older (pre-6.0) QEMU, you need OpenSBI (firmware) binary.
To run riscv64 virtual machine on older (pre-6.0) QEMU, you need OpenSBI (firmware) binary.


'''Option #1''' There is an OpenSBI firmware binary inside the qcow2/qcow2c image. You can copy it out of the image:
Download the recent version of <code>opensbi</code>.
You can use [https://packages.altlinux.org/en/sisyphus_riscv64/srpms/opensbi/rpms/ the link to the package on the official website of the Sisyphus repository]. Or find the package directly in the [http://ftp.altlinux.org/pub/distributions/ALTLinux/ports/riscv64/Sisyphus/noarch/RPMS.classic/ repository].


<source lang=shell>
Extract '''/usr/share/opensbi/generic/firmware/fw_jump.elf''' file from the downloaded package. For example:
root# modprobe nbd
root# qemu-nbd -c /dev/nbd0 qemu-riscv64.qcow2c
root# mount /dev/nbd0p1 /mnt
root# cp -v /mnt/usr/share/opensbi/generic/firmware/fw_payload.elf .
user$ FIRM=./fw_payload.elf
</source>


'''Option #2''' [http://ftp.altlinux.org/pub/distributions/ALTLinux/ports/riscv64/Sisyphus/noarch/RPMS.classic/ Download] and install the latest version of OpenSBI package <code>opensbi-firmware-generic</code>.
rpm2cpio opensbi-*.rpm | cpio -vi --to-stdout './usr/share/opensbi/generic/firmware/fw_jump.elf' > fw_jump.elf


The OpenSBI firmware will be at <tt>/usr/share/opensbi/generic/firmware/fw_payload.elf</tt>.
Now you can start a virtual machine on QEMU via the following commands. Give directions in IMAGE to image, in UBOOT to u-boot, that you got in step 1, and in FIRM to fw_jump.elf.
 
For example:
 
<source lang=shell>
user$ curl -O http://ftp.altlinux.org/pub/distributions/ALTLinux/ports/riscv64/Sisyphus/noarch/RPMS.classic/opensbi-firmware-generic-0.9-alt1.noarch.rpm
root# rpm -i opensbi-firmware-generic-0.9-alt1.noarch.rpm
user$ FIRM=/usr/share/opensbi/generic/firmware/fw_payload.elf
</source>


<source lang="shell">
<source lang="shell">
$ QCOW=qemu-riscv64.qcow2c
$ IMAGE=<путь до образа>
$ UBOOT=<путь до u-boot.bin>
$ FIRM=<путь до fw_jump.elf>
$ qemu-system-riscv64 \
$ qemu-system-riscv64 \
          -nographic -machine virt -kernel "$FIRM" \
                      -nographic -machine virt \
          -m 2G -smp cpus=4 \
                      -bios "$FIRM" \
          -drive file="$QCOW",id=hd0 -device virtio-blk-device,drive=hd0 \
                      -kernel "$UBOOT" \
          -netdev user,id=eth0,hostfwd=tcp::5900-:5900 -device virtio-net-device,netdev=eth0
                      -m 2G -smp cpus=4 \
                      -drive file=$IMAGE,id=hd0,format=raw -device virtio-blk-device,drive=hd0 \
                      -netdev user,id=eth0,hostfwd=tcp::5900-:5900 -device virtio-net-device,netdev=eth0
</source>
</source>


If you need a graphical interface, run the VNC server in the image, for example, as described in [[Regular/riscv64#VNC]].
Connect to VNC, for example:
vncviewer localhost
[[Category:RISC-V]]
[[ru:Ports/riscv64/QEMU]]
[[ru:Ports/riscv64/QEMU]]
[[Category:RISC-V]]

Revision as of 18:51, 21 January 2022

Stub.png
Under construction.
This page is not finished yet and may lack substantial information.


This page describes how to start riscv64 virtual machine via QEMU.

QEMU, starting with version 6.0, includes OpenSBI firmware. For older QEMU versions, there are instructions how to obtain and use the firmware in #OpenSBI section below.

Some older ALT images for QEMU include a VNC server that provides access to initial setup and graphical desktop (see Regular/riscv64#VNC for more details). To access that server, it's convenient to forward port 5900 from the virtual machine to the host machine. The parameters necessary for that are included into QEMU command lines below.

QEMU 6.0+

QEMU 6.0 virtual machines with kernel 5.14+ have graphics (virtuo-gpu) and input (virtio-keyboard and virtio-tablet) working using U-boot boot loader.

Here are the steps run images in QEMU:

Step 0: Install QEMU with riscv64 support to run the ALT port on RISC-V. If your host system is running ALT x86_64, you need qemu-system-riscv-core package:

 apt-get install qemu-system-riscv-core qemu-device-display-virtio-gpu-gl qemu-ui-sdl seavgabios

Step 1: Download the recent version of u-boot-qemu for riscv64. You can use the link to the package on the official website of the Sisyphus repository. Or find the package directly in the repository.

Extract /usr/share/u-boot/qemu-riscv64_smode/u-boot.bin file from the downloaded package. For example:

rpm2cpio u-boot-qemu-*.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 on QEMU via the following commands. Give directions in IMAGE to image and in UBOOT to u-boot that you got in step 1:

$ IMAGE=<путь до образа>
$ UBOOT=<путь до u-boot.bin>
$ 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-vga-gl,xres=1280,yres=800 -device virtio-keyboard -device virtio-tablet -display sdl,gl=on

If you need access via vnc, then you need to specify "-vnc: 1" instead of "-sdl" and connect to 5901 port (5900 port is taken for network forwarding):

$ vncviewer localhost:5901

OpenSBI

To run riscv64 virtual machine on older (pre-6.0) QEMU, you need OpenSBI (firmware) binary.

Download the recent version of opensbi. You can use the link to the package on the official website of the Sisyphus repository. Or find the package directly in the repository.

Extract /usr/share/opensbi/generic/firmware/fw_jump.elf file from the downloaded package. For example:

rpm2cpio opensbi-*.rpm | cpio -vi --to-stdout './usr/share/opensbi/generic/firmware/fw_jump.elf' > fw_jump.elf

Now you can start a virtual machine on QEMU via the following commands. Give directions in IMAGE to image, in UBOOT to u-boot, that you got in step 1, and in FIRM to fw_jump.elf.

$ IMAGE=<путь до образа>
$ UBOOT=<путь до u-boot.bin>
$ FIRM=<путь до fw_jump.elf>
$ qemu-system-riscv64 \
                      -nographic -machine virt \
                      -bios "$FIRM" \
                      -kernel "$UBOOT" \
                      -m 2G -smp cpus=4 \
                      -drive file=$IMAGE,id=hd0,format=raw -device virtio-blk-device,drive=hd0 \
                      -netdev user,id=eth0,hostfwd=tcp::5900-:5900 -device virtio-net-device,netdev=eth0

If you need a graphical interface, run the VNC server in the image, for example, as described in Regular/riscv64#VNC.

Connect to VNC, for example:

vncviewer localhost