tests/util/grub-shell: Use pflash instead of -bios to load UEFI firmware

According to the OVMF whitepaper [1]:

  IMPORTANT: Never pass OVMF.fd to qemu with the -bios option. That option
  maps the firmware image as ROM into the guest's address space, and forces
  OVMF to emulate non-volatile variables with a fallback driver that is
  bound to have insufficient and confusing semantics.

Use the pflash interface instead. Currently the unified firmware file is
used, which contains both firmware code and variable sections. By enabling
snapshot on the pflash device, the firmware can be loaded in such a way
that variables can be written to without writing to the backing file.

Since pflash does no searching for firmware paths that are not absolute,
unlike the -bios option, also make firmware paths absolute. Additionally,
update the previous firmware paths or file names that did not correspond to
ones installed by Debian.

Use the q35 machine, instead of the default i440fx, for i386-efi because
the default machine type does not emulate a flash device, which is now
needed to load the firmware.

[1] http://www.linux-kvm.org/downloads/lersek/ovmf-whitepaper-c770f8c.txt

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
This commit is contained in:
Glenn Washburn 2024-06-08 21:42:34 -05:00 committed by Daniel Kiper
parent 88a7e64c2c
commit d2fc9dfcd1

View File

@ -181,21 +181,26 @@ case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in
boot=cd
console=console
trim=1
qemuopts="-bios OVMF-ia32.fd $qemuopts"
pflash=/usr/share/qemu/OVMF32.fd
qemuopts="-drive if=pflash,format=raw,unit=0,snapshot=on,file=$pflash $qemuopts"
qemuopts="-machine q35 $qemuopts"
;;
x86_64-efi)
qemu=qemu-system-x86_64
boot=cd
console=console
trim=1
qemuopts="-bios OVMF.fd $qemuopts"
pflash=/usr/share/qemu/OVMF.fd
qemuopts="-drive if=pflash,format=raw,unit=0,snapshot=on,file=$pflash $qemuopts"
;;
arm64-efi)
qemu=qemu-system-aarch64
boot=hd
console=console
trim=1
qemuopts="-machine virt -cpu cortex-a57 -bios /usr/share/qemu-efi/QEMU_EFI.fd $qemuopts"
pflash=/usr/share/qemu-efi-aarch64/QEMU_EFI.fd
qemuopts="-drive if=pflash,format=raw,unit=0,snapshot=on,file=$pflash $qemuopts"
qemuopts="-machine virt -cpu cortex-a57 $qemuopts"
disk="device virtio-blk-device,drive=hd1 -drive if=none,id=hd1,file="
serial_port=
;;
@ -204,7 +209,9 @@ case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in
boot=hd
console=console
trim=1
qemuopts="-machine virt -bios /usr/share/ovmf-arm/QEMU_EFI.fd $qemuopts"
pflash=/usr/share/AAVMF/AAVMF32.fd
qemuopts="-drive if=pflash,format=raw,unit=0,snapshot=on,file=$pflash $qemuopts"
qemuopts="-machine virt $qemuopts"
disk="device virtio-blk-device,drive=hd1 -drive if=none,id=hd1,file="
serial_port=efi0
;;