Ports/riscv64/QEMU: Difference between revisions

From ALT Linux Wiki
< Ports‎ | riscv64
(Created page with " == Old QEMU (pre-6.0) == To the QEMU virt machine with one of the images one could proceed through the following steps: '''Step 0.''' Install QEMU with riscv64 system supp...")
 
No edit summary
 
(16 intermediate revisions by 3 users not shown)
Line 1: Line 1:


{{Stub}}


== Old QEMU (pre-6.0) ==
This page describes how to start riscv64 virtual machine via [https://www.qemu.org QEMU].


To the QEMU virt machine with one of the images one could proceed through the following steps:
QEMU, starting with version 6.0, includes OpenSBI firmware. For older QEMU versions you need to obtain the firmware -- check out the instructions in the [[#OpenSBI]] section below.


'''Step 0.''' Install QEMU with riscv64 system support. For example, in the case of ALT x86_64: [http://sisyphus.ru/en/srpm/Sisyphus/qemu qemu-system-riscv-core].
Some ALT images for riscv64 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.


'''Step 1.a''' The OpenSBI firmware is placed inside the qcow2/qcow2c image. Let us copy it out of the image.
== QEMU 6.0+ ==


<source lang=shell>
QEMU 6.0 virtual machines with kernel 5.14 or newer have graphics (virtuo-gpu) and input (virtio-keyboard and virtio-tablet) working. Here are the steps run ALT images in QEMU:
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
</source>


'''Step 1.b''' Alternative option: [http://ftp.altlinux.org/pub/distributions/ALTLinux/ports/riscv64/Sisyphus/noarch/RPMS.classic/ download]
'''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 [https://packages.altlinux.org/en/sisyphus/srpms/qemu/ qemu-system-riscv-core package]:
and install the last version of the OpenSBI for QEMU virt machine.
The OpenSBI firmware for QEMU virt will be at /usr/share/opensbi/qemu/virt/firmware/fw_payload.elf


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


<source lang=shell>
'''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].
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
Extract '''/usr/share/u-boot/qemu-riscv64_smode/u-boot.bin''' file from the downloaded package. For example:
user$ FIRM=/usr/share/opensbi/qemu/virt/firmware/fw_payload.elf
 
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. Put the path to the image you want to run into the IMAGE environment variable, and path to the U-Boot binary you obtained on the step 1 to UBOOT environment variable:
 
<source lang="shell">
$ IMAGE=/path/to/<image>
$ UBOOT=/path/to/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-keyboard -device virtio-tablet \
          -device virtio-vga-gl,xres=1280,yres=800 -display sdl,gl=on
</source>
 
If you need to access the virtual machine via VNC, replace <tt>-device virtio-vga-gl</tt> and <tt>-display sdl</tt> options with "-device virtio-vga -vnc :1" and connect to 5901 port (5900 port is taken for the network forwarding):
 
<source lang="shell">
$ vncviewer localhost:5901
</source>
</source>


'''Step 2.''' Now, it is all set to run the QEMU with a qcow2/qcow2c image, just place the path to the image in QCOW variable:
== OpenSBI ==
 
To run riscv64 virtual machine on older (pre-6.0) QEMU, you need OpenSBI (firmware) binary.
 
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/riscv64/RPMS.classic/ 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. Put path to your image into IMAGE, path to the u-boot binary into UBOOT environment variable, and path to  to u-boot, and path to <tt>fw_jump.elf</tt> that you extracted from FIRM package into FIRM variable:


<source lang="shell">
<source lang="shell">
$ QCOW=qemu-riscv64.qcow2c
$ IMAGE=/path/to/<image>
$ UBOOT=/path/to/u-boot.bin
$ FIRM=/path/to/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>


'''Step 3.''' For a graphical system, the following system setup is performing through [[Regular/riscv64#VNC|VNC]]. To connect to the X11 VNC server one should enter the default
If you need a graphical interface, run the VNC server in the VM, for example, as described in [[Regular/riscv64#VNC]].
password '''<tt>alt</tt>''', it could be changed to another one at the inital setup of the system through GUI.
 
Connect to VNC, for example, like this:
 
vncviewer localhost
 
[[Category:RISC-V]]
[[ru:Ports/riscv64/QEMU]]

Latest revision as of 10:15, 16 November 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 you need to obtain the firmware -- check out the instructions in the #OpenSBI section below.

Some ALT images for riscv64 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 or newer have graphics (virtuo-gpu) and input (virtio-keyboard and virtio-tablet) working. Here are the steps run ALT 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. Put the path to the image you want to run into the IMAGE environment variable, and path to the U-Boot binary you obtained on the step 1 to UBOOT environment variable:

$ IMAGE=/path/to/<image>
$ UBOOT=/path/to/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-keyboard -device virtio-tablet \
          -device virtio-vga-gl,xres=1280,yres=800 -display sdl,gl=on

If you need to access the virtual machine via VNC, replace -device virtio-vga-gl and -display sdl options with "-device virtio-vga -vnc :1" and connect to 5901 port (5900 port is taken for the 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. Put path to your image into IMAGE, path to the u-boot binary into UBOOT environment variable, and path to to u-boot, and path to fw_jump.elf that you extracted from FIRM package into FIRM variable:

$ IMAGE=/path/to/<image>
$ UBOOT=/path/to/u-boot.bin
$ FIRM=/path/to/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 VM, for example, as described in Regular/riscv64#VNC.

Connect to VNC, for example, like this:

vncviewer localhost