grub-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 2/2] tests/util/grub-shell: Add flexibility in QEMU firmware hand


From: Glenn Washburn
Subject: [PATCH 2/2] tests/util/grub-shell: Add flexibility in QEMU firmware handling
Date: Sat, 8 Jun 2024 21:42:35 -0500

First look for firmware files in the source directory and then, if not
found, look for them in locations where Debian installs them. Prefer to
use the unified firmware file and, if not found, use the pflash firmware
files split in to code and variables. By looking for files in the source
directory first, system firmware files can be overridden and it can be
ensured that the tests can be run regardless of the distro or where the
system firmware files are stored. If no firmware files are found, print
an error message and exit with error.

If a firmware VARS file is found, use it with snapshot mode enabled, which
makes the VARS writable to the virtual machine, but does not write back
the changes to the file. This allows using the readonly system VARS file
without copying it or using it in readonly mode, which causes the arm
machine to fail. This also gives tests effectively their own ephemeral VARS
file that can be written to without causing side-effects for other tests.

Signed-off-by: Glenn Washburn <development@efficientek.com>
---
 tests/util/grub-shell.in | 104 ++++++++++++++++++++++++++++++++++++---
 1 file changed, 96 insertions(+), 8 deletions(-)

diff --git a/tests/util/grub-shell.in b/tests/util/grub-shell.in
index b0fbc6969637..c0671cc46999 100644
--- a/tests/util/grub-shell.in
+++ b/tests/util/grub-shell.in
@@ -181,8 +181,30 @@ case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" 
in
        boot=cd
        console=console
        trim=1
-       pflash=/usr/share/qemu/OVMF32.fd
-       qemuopts="-drive if=pflash,format=raw,unit=0,snapshot=on,file=$pflash 
$qemuopts"
+       pflash=${srcdir}/OVMF32.fd
+       pflash_code=${srcdir}/OVMF32_CODE.fd
+       pflash_vars=${srcdir}/OVMF32_VARS.fd
+       if [ -f "$pflash" ]; then
+           qemuopts="-drive 
if=pflash,format=raw,unit=0,snapshot=on,file=$pflash $qemuopts"
+       elif [ -f "$pflash_code" ]; then
+           qemuopts="-drive 
if=pflash,format=raw,unit=0,readonly=on,file=$pflash_code $qemuopts"
+           if [ -f "$pflash_vars" ]; then
+               qemuopts="-drive 
if=pflash,format=raw,unit=1,snapshot=on,file=$pflash_vars $qemuopts"
+           fi
+       else
+           pflash=/usr/share/qemu/OVMF32.fd
+           pflash_code=/usr/share/OVMF/OVMF32_CODE_4M.secboot.fd
+           pflash_vars=/usr/share/OVMF/OVMF32_VARS_4M.fd
+           if [ -f "$pflash" ]; then
+               qemuopts="-drive 
if=pflash,format=raw,unit=0,snapshot=on,file=$pflash $qemuopts"
+           elif [ -f "$pflash_code" ]; then
+               qemuopts="-drive 
if=pflash,format=raw,unit=0,readonly=on,file=$pflash_code $qemuopts"
+               qemuopts="-drive 
if=pflash,format=raw,unit=1,snapshot=on,file=$pflash_vars $qemuopts"
+           else
+               echo "Firmware not found, please install either the appropriate 
Debian package or an appropriately named copy in the source directory." >&2
+               exit 1
+           fi
+       fi
        qemuopts="-machine q35 $qemuopts"
        ;;
     x86_64-efi)
@@ -190,16 +212,60 @@ case 
"${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in
        boot=cd
        console=console
        trim=1
-       pflash=/usr/share/qemu/OVMF.fd
-       qemuopts="-drive if=pflash,format=raw,unit=0,snapshot=on,file=$pflash 
$qemuopts"
+       pflash=${srcdir}/OVMF.fd
+       pflash_code=${srcdir}/OVMF_CODE.fd
+       pflash_vars=${srcdir}/OVMF_VARS.fd
+       if [ -f "$pflash" ]; then
+           qemuopts="-drive 
if=pflash,format=raw,unit=0,snapshot=on,file=$pflash $qemuopts"
+       elif [ -f "$pflash_code" ]; then
+           qemuopts="-drive 
if=pflash,format=raw,unit=0,readonly=on,file=$pflash_code $qemuopts"
+           if [ -f "$pflash_vars" ]; then
+               qemuopts="-drive 
if=pflash,format=raw,unit=1,snapshot=on,file=$pflash_vars $qemuopts"
+           fi
+       else
+           pflash=/usr/share/qemu/OVMF.fd
+           pflash_code=/usr/share/OVMF/OVMF_CODE.fd
+           pflash_vars=/usr/share/OVMF/OVMF_VARS.fd
+           if [ -f "$pflash" ]; then
+               qemuopts="-drive 
if=pflash,format=raw,unit=0,snapshot=on,file=$pflash $qemuopts"
+           elif [ -f "$pflash_code" ]; then
+               qemuopts="-drive 
if=pflash,format=raw,unit=0,readonly=on,file=$pflash_code $qemuopts"
+               qemuopts="-drive 
if=pflash,format=raw,unit=1,snapshot=on,file=$pflash_vars $qemuopts"
+           else
+               echo "Firmware not found, please install either the appropriate 
Debian package or an appropriately named copy in the source directory." >&2
+               exit 1
+           fi
+       fi
        ;;
     arm64-efi)
        qemu=qemu-system-aarch64
        boot=hd
        console=console
        trim=1
-       pflash=/usr/share/qemu-efi-aarch64/QEMU_EFI.fd
-       qemuopts="-drive if=pflash,format=raw,unit=0,snapshot=on,file=$pflash 
$qemuopts"
+       pflash=${srcdir}/AAVMF.fd
+       pflash_code=${srcdir}/AAVMF_CODE.fd
+       pflash_vars=${srcdir}/AAVMF_VARS.fd
+       if [ -f "$pflash" ]; then
+           qemuopts="-drive 
if=pflash,format=raw,unit=0,snapshot=on,file=$pflash $qemuopts"
+       elif [ -f "$pflash_code" ]; then
+           qemuopts="-drive 
if=pflash,format=raw,unit=0,readonly=on,file=$pflash_code $qemuopts"
+           if [ -f "$pflash_vars" ]; then
+               qemuopts="-drive 
if=pflash,format=raw,unit=1,snapshot=on,file=$pflash_vars $qemuopts"
+           fi
+       else
+           pflash=/usr/share/qemu-efi-aarch64/QEMU_EFI.fd
+           pflash_code=/usr/share/AAVMF/AAVMF_CODE.fd
+           pflash_vars=/usr/share/AAVMF/AAVMF_VARS.fd
+           if [ -f "$pflash" ]; then
+               qemuopts="-drive 
if=pflash,format=raw,unit=0,snapshot=on,file=$pflash $qemuopts"
+           elif [ -f "$pflash_code" ]; then
+               qemuopts="-drive 
if=pflash,format=raw,unit=0,readonly=on,file=$pflash_code $qemuopts"
+               qemuopts="-drive 
if=pflash,format=raw,unit=1,snapshot=on,file=$pflash_vars $qemuopts"
+           else
+               echo "Firmware not found, please install either the appropriate 
Debian package or an appropriately named copy in the source directory." >&2
+               exit 1
+           fi
+       fi
        qemuopts="-machine virt -cpu cortex-a57 $qemuopts"
        disk="device virtio-blk-device,drive=hd1 -drive if=none,id=hd1,file="
        serial_port=
@@ -209,8 +275,30 @@ case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" 
in
        boot=hd
        console=console
        trim=1
-       pflash=/usr/share/AAVMF/AAVMF32.fd
-       qemuopts="-drive if=pflash,format=raw,unit=0,snapshot=on,file=$pflash 
$qemuopts"
+       pflash=${srcdir}/AAVMF32.fd
+       pflash_code=${srcdir}/AAVMF32_CODE.fd
+       pflash_vars=${srcdir}/AAVMF32_VARS.fd
+       if [ -f "$pflash" ]; then
+           qemuopts="-drive 
if=pflash,format=raw,unit=0,snapshot=on,file=$pflash $qemuopts"
+       elif [ -f "$pflash_code" ]; then
+           qemuopts="-drive 
if=pflash,format=raw,unit=0,readonly=on,file=$pflash_code $qemuopts"
+           if [ -f "$pflash_vars" ]; then
+               qemuopts="-drive 
if=pflash,format=raw,unit=1,snapshot=on,file=$pflash_vars $qemuopts"
+           fi
+       else
+           pflash=/usr/share/AAVMF/AAVMF32.fd
+           pflash_code=/usr/share/AAVMF/AAVMF32_CODE.fd
+           pflash_vars=/usr/share/AAVMF/AAVMF32_VARS.fd
+           if [ -f "$pflash" ]; then
+               qemuopts="-drive 
if=pflash,format=raw,unit=0,snapshot=on,file=$pflash $qemuopts"
+           elif [ -f "$pflash_code" ]; then
+               qemuopts="-drive 
if=pflash,format=raw,unit=0,readonly=on,file=$pflash_code $qemuopts"
+               qemuopts="-drive 
if=pflash,format=raw,unit=1,snapshot=on,file=$pflash_vars $qemuopts"
+           else
+               echo "Firmware not found, please install either the appropriate 
Debian package or an appropriately named copy in the source directory." >&2
+               exit 1
+           fi
+       fi
        qemuopts="-machine virt $qemuopts"
        disk="device virtio-blk-device,drive=hd1 -drive if=none,id=hd1,file="
        serial_port=efi0
-- 
2.34.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]