]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
tests/util/grub-shell: Add flexibility in QEMU firmware handling
authorGlenn Washburn <development@efficientek.com>
Sun, 9 Jun 2024 02:42:35 +0000 (21:42 -0500)
committerDaniel Kiper <daniel.kiper@oracle.com>
Thu, 20 Jun 2024 13:11:32 +0000 (15:11 +0200)
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>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
tests/util/grub-shell.in

index 89b9d42056760c33bf3eb3502d9db2523ed092fb..ae5f711fe26c7aee5f66a3b4fab1cfedf9f7ce4c 100644 (file)
@@ -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