All of lore.kernel.org
 help / color / mirror / Atom feed
From: Glenn Washburn <development@efficientek.com>
To: grub-devel@gnu.org, Daniel Kiper <dkiper@net-space.pl>
Cc: Glenn Washburn <development@efficientek.com>
Subject: [PATCH] grub-shell: Add flexibility in QEMU firmware handling
Date: Sat, 21 Jan 2023 00:15:20 -0600	[thread overview]
Message-ID: <20230121061520.1619840-1-development@efficientek.com> (raw)

The current qemu firmware paths for arm-efi and arm64-efi are not available
on Ubuntu/Debian but are hardcoded. Switch to first looking for firmware
files in the source directory and if not found, look for them in locations
where Debian installs them. Prefer to use the firmware file usable with the
QEMU '-bios' option and if not found use the newer pflash firmware files.
This allows supporting older systems more easily. 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 and where
it stores firmware files. If no firmware files are found, print an error
message telling the user that those files must exist and exit with error.

Do not load the system 32-bit ARM firmware VARS file because it must be
writable to prevent a data exception and boot failure. So in order to use
the VARS file, it must be copied to a writable location, but its quite large
at 64M and is not needed to boot successfully.

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

diff --git a/tests/util/grub-shell.in b/tests/util/grub-shell.in
index 75f71dc1a2..7e13960284 100644
--- a/tests/util/grub-shell.in
+++ b/tests/util/grub-shell.in
@@ -181,21 +181,92 @@ case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in
 	boot=cd
 	console=console
 	trim=1
-	qemuopts="-bios OVMF-ia32.fd $qemuopts"
+	bios=${srcdir}/OVMF32.fd
+	pflash_code=${srcdir}/OVMF32_CODE.fd
+	pflash_vars=${srcdir}/OVMF32_VARS.fd
+	if [ -f "$bios" ]; then
+	    qemuopts="-bios $bios $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,readonly=on,file=$pflash_vars $qemuopts"
+	    fi
+	else
+	    bios=/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 "$bios" ]; then
+		qemuopts="-bios $bios $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,readonly=on,file=$pflash_vars $qemuopts"
+	    else
+		echo "Firmware not found, please make sure $bios or both $pflash_code and $pflash_vars exist." >&2
+		exit 1
+	    fi
+	fi
+	qemuopts="-machine q35,accel=tcg $qemuopts"
 	;;
     x86_64-efi)
 	qemu=qemu-system-x86_64
 	boot=cd
 	console=console
 	trim=1
-	qemuopts="-bios OVMF.fd $qemuopts"
+	bios=${srcdir}/OVMF.fd
+	pflash_code=${srcdir}/OVMF_CODE.fd
+	pflash_vars=${srcdir}/OVMF_VARS.fd
+	if [ -f "$bios" ]; then
+	    qemuopts="-bios $bios $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,readonly=on,file=$pflash_vars $qemuopts"
+	    fi
+	else
+	    bios=/usr/share/qemu/OVMF.fd
+	    pflash_code=/usr/share/OVMF/OVMF_CODE.fd
+	    pflash_vars=/usr/share/OVMF/OVMF_VARS.fd
+	    if [ -f "$bios" ]; then
+		qemuopts="-bios $bios $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,readonly=on,file=$pflash_vars $qemuopts"
+	    else
+		echo "Firmware not found, please make sure $bios or both $pflash_code and $pflash_vars exist." >&2
+		exit 1
+	    fi
+	fi
 	;;
     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"
+	bios=${srcdir}/AAVMF.fd
+	pflash_code=${srcdir}/AAVMF_CODE.fd
+	pflash_vars=${srcdir}/AAVMF_VARS.fd
+	if [ -f "$bios" ]; then
+	    qemuopts="-bios $bios $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,readonly=on,file=$pflash_vars $qemuopts"
+	    fi
+	else
+	    bios=/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 "$bios" ]; then
+		qemuopts="-bios $bios $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,readonly=on,file=$pflash_vars $qemuopts"
+	    else
+		echo "Firmware not found, please make sure $bios or both $pflash_code and $pflash_vars exist." >&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=
 	;;
@@ -204,7 +275,33 @@ 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"
+	bios=${srcdir}/AAVMF32.fd
+	pflash_code=${srcdir}/AAVMF32_CODE.fd
+	pflash_vars=${srcdir}/AAVMF32_VARS.fd
+	if [ -f "$bios" ]; then
+	    qemuopts="-bios $bios $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,file=$pflash_vars $qemuopts"
+	    fi
+	else
+	    bios=/usr/share/AAVMF/AAVMF32.fd
+	    pflash_code=/usr/share/AAVMF/AAVMF32_CODE.fd
+	    pflash_vars=/usr/share/AAVMF/AAVMF32_VARS.fd
+	    if [ -f "$bios" ]; then
+		qemuopts="-bios $bios $qemuopts"
+	    elif [ -f "$pflash_code" ]; then
+		# NOTE: Do not use the pflash VARS file because it cannot be
+		# used in readonly. So it would need to be copied to a writable
+		# path, but its large at 64M and not needed for running tests.
+		qemuopts="-drive if=pflash,format=raw,unit=0,readonly=on,file=$pflash_code $qemuopts"
+	    else
+		echo "Firmware not found, please make sure $bios or both $pflash_code and $pflash_vars exist." >&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	other threads:[~2023-01-21  6:15 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-21  6:15 Glenn Washburn [this message]
2023-01-23  9:28 ` [PATCH] grub-shell: Add flexibility in QEMU firmware handling Gerd Hoffmann
2023-01-23 20:09   ` Glenn Washburn
2023-01-24  8:16     ` Gerd Hoffmann
2023-01-26  5:23       ` Glenn Washburn
2023-01-24 21:21     ` Robbie Harwood
2023-01-26  4:53       ` Glenn Washburn

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230121061520.1619840-1-development@efficientek.com \
    --to=development@efficientek.com \
    --cc=dkiper@net-space.pl \
    --cc=grub-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.