From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1pJ7AJ-0002iS-Gb for mharc-grub-devel@gnu.org; Sat, 21 Jan 2023 01:15:47 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pJ7AH-0002iI-K5 for grub-devel@gnu.org; Sat, 21 Jan 2023 01:15:45 -0500 Received: from mail-pj1-x1036.google.com ([2607:f8b0:4864:20::1036]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pJ7AF-0000E6-Jd for grub-devel@gnu.org; Sat, 21 Jan 2023 01:15:45 -0500 Received: by mail-pj1-x1036.google.com with SMTP id k10-20020a17090a590a00b0022ba875a1a4so3990650pji.3 for ; Fri, 20 Jan 2023 22:15:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficientek-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=i0QAn5qDu/3+O5jC9TDY902DTHxaVGM4eUQFa5oQR6k=; b=cEqlytrnHSdHD2aUkT0L4nrTRTUay7d+cfqwsfLdiO7sfb5pR7bjzz1uIyZkN6eWGY 3JBKNNotBUms00WdMotxIaGH2tEriTxoWjdPwAyiEwTFm3EMMG3Hs+g9SSb/Hn5QhvlT pJSdZaQ2tRaRLpF4SRhe98iHA9JSU1aedAHqYn3+fdtrrEeVthz6dRyl0C/fn82jheho iR3KCDwOWloQN/50knVxwXSlTi3vyH3ZogJ81/a3Hy+OWkZj5nIMC740WWIkdC6dSZg8 iv4bpihQLD8EoIo8sSOX+AiNL+tgg0XXpBNgeKXthhTlbNdvHp4LBaa0ylK+jbT0ZB9J gtaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=i0QAn5qDu/3+O5jC9TDY902DTHxaVGM4eUQFa5oQR6k=; b=D1phv31vchAK0oMUT0Ym1HNe4Un4RrTW9InwcEeR6m/11aJbAbi4bK+ZG0TR36FF6+ rJyTk52qCr53OzppH4lwdtWw654VbT64JK8/JSPDIycXyQLxM3wIXB+3ytIrG9NK1FyG jdHH06nctg11tVswiVFUPIz/RB0CQ31/a9m+y8G8PyYVMVsB2UlCNp8gqknj33JHs1lZ Ody0V5KX5jJo/QxDxL9ZhSC8Zo6IeJ7Z+Y9myDYceqPpy7lcHneUCwosX2eaHnjHmdJl Q65DKGDpJo28c7cBmPwIiZGRI5I6OcUMC0YrOKN2ezYTne4uVKCzY8j4hARvV7jWHYP5 l9cg== X-Gm-Message-State: AFqh2kpmxncAJnOnW1c+O0yKspfDOsz87kQfGmHYaTBOyF4xg38Gvan3 2mZ5jjCtxzgDqFxnSzCN2vroeX/1BnPnf6Vl X-Google-Smtp-Source: AMrXdXt+prEmVvBGCYwXqIkgzM7e5lBJAffu8sXbY3uOC4It1Q3oA2QDvtOhTyFR8cLH/GGZNMA89g== X-Received: by 2002:a05:6a20:428b:b0:a5:7700:2a4a with SMTP id o11-20020a056a20428b00b000a577002a4amr22232292pzj.51.1674281741500; Fri, 20 Jan 2023 22:15:41 -0800 (PST) Received: from localhost.localdomain ([37.218.244.251]) by smtp.gmail.com with ESMTPSA id p13-20020a65490d000000b0048f8efc53a6sm23498977pgs.80.2023.01.20.22.15.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Jan 2023 22:15:40 -0800 (PST) From: Glenn Washburn To: grub-devel@gnu.org, Daniel Kiper Cc: Glenn Washburn Subject: [PATCH] grub-shell: Add flexibility in QEMU firmware handling Date: Sat, 21 Jan 2023 00:15:20 -0600 Message-Id: <20230121061520.1619840-1-development@efficientek.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::1036; envelope-from=development@efficientek.com; helo=mail-pj1-x1036.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 21 Jan 2023 06:15:45 -0000 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 --- 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