pmb.qemu: use consistent hardware for all architectures (!1886)

To ensure consistent behavior for QEMU on all architectures,
it is helpful to try to use the same hardware elements where possible.

A few examples of current inconsistent behavior:
  - x86_64 uses a SCSI disk, while aarch64 uses virtio-blk
  - x86_64 uses e1000 network, while aarch64 uses virtio-net-device
  - x86_64 uses PS/2 mouse, while aarch64 uses usb-mouse
  - only x86_64 prints serial output to console

At least the virtio components are usually independent of the selected
architecture, so we can use them for both architectures.

This commit makes most of the hardware configuration shared:
  - Redirect serial output to stdio
  - virtio-blk for the disk image
  - virtio-gpu-pci (this was already implicit for both architectures)
  - virtio-net-pci for the network interface
  - virtio-mouse-pci/virtio-keyboard-pci as input devices
  - intel-hda for audio

We also set -nodefaults to avoid setting up unneeded devices
especially for x86_64.
This commit is contained in:
Minecrell 2020-03-05 23:35:50 +01:00 committed by Oliver Smith
parent 81b3aade07
commit 240e10816d
No known key found for this signature in database
GPG Key ID: 5AE7F5513E0885CB
1 changed files with 9 additions and 15 deletions

View File

@ -109,36 +109,29 @@ def command_qemu(args, arch, img_path):
command += [rootfs_native + "/usr/bin/qemu-system-" + arch]
command += ["-L", rootfs_native + "/usr/share/qemu/"]
command += ["-nodefaults"]
command += ["-kernel", rootfs + "/boot/vmlinuz-" + flavor]
command += ["-initrd", rootfs + "/boot/initramfs-" + flavor]
command += ["-append", shlex.quote(cmdline)]
command += ["-smp", str(os.cpu_count())]
command += ["-m", str(args.memory)]
command += ["-netdev",
"user,id=net0,"
command += ["-serial", "stdio"]
command += ["-drive", "file=" + img_path + ",format=raw,if=virtio"]
command += ["-device", "virtio-mouse-pci"]
command += ["-device", "virtio-keyboard-pci"]
command += ["-nic",
"user,model=virtio-net-pci,"
"hostfwd=tcp::" + port_ssh + "-:22,"
]
command += ["-show-cursor"]
if arch == "x86_64":
command += ["-vga", "virtio"]
command += ["-serial", "stdio"]
command += ["-drive", "file=" + img_path + ",format=raw"]
command += ["-device", "e1000,netdev=net0"]
elif arch == "aarch64":
command += ["-M", "virt"]
command += ["-cpu", "cortex-a57"]
command += ["-device", "virtio-gpu-pci"]
command += ["-device", "virtio-net-device,netdev=net0"]
command += ["-usb", "-device", "usb-ehci",
"-device", "usb-kbd", "-device", "usb-mouse"]
# Add storage
command += ["-device", "virtio-blk-device,drive=system"]
command += ["-drive", "if=none,id=system,file={},id=hd0".format(img_path)]
else:
raise RuntimeError("Architecture {} not supported by this command yet.".format(arch))
@ -154,6 +147,7 @@ def command_qemu(args, arch, img_path):
display += ",gl=" + ("on" if args.qemu_gl else "off")
command += ["-display", display]
command += ["-show-cursor"]
# Audio support
if args.qemu_audio: