Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1nIHO8-0004L2-58 for mharc-grub-devel@gnu.org; Thu, 10 Feb 2022 16:54:04 -0500 Received: from eggs.gnu.org ([209.51.188.92]:50282) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nIHO1-0004HF-EN for grub-devel@gnu.org; Thu, 10 Feb 2022 16:53:58 -0500 Received: from [2607:f8b0:4864:20::f31] (port=38810 helo=mail-qv1-xf31.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nIHNw-0008M8-Hp for grub-devel@gnu.org; Thu, 10 Feb 2022 16:53:55 -0500 Received: by mail-qv1-xf31.google.com with SMTP id d3so6497940qvb.5 for ; Thu, 10 Feb 2022 13:53:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficientek-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=SzzLTmv4XQBb9aZvuSxH66Rjilx7hVAO43zBVFuJ7Cs=; b=dBagCtCdMk2SHInQ7+CqLiKpw6CVOTrV4BF/9U2YVQTp3mV1eImUXmwuq8qjjzf3eL EfmW85CA4fPiMzxYdCpMZrYbDMsenUDfiEBHfSrF5NvmmEPZL3pSR5MlpNyB9xDA5uUd NBTA5PH8F/u+xFyiXZ/Bk5Vo3sI2oW14Flgc4kC0doebFXgd0fkEF/OOPdbk+zKWj7Dv GSTADSHMyMDQuZG89MzRRHlvYQ/vTQLId0Yzq9VGgT0Od0VN3BzzOoh4fx1hfHrhFKKH qhxDsrIDi1cKnxm5fmQJxLvf+NjRu5aCNxhy0E+opk1Juy1DbSt3GymdkifNXpYXVOH5 TQaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=SzzLTmv4XQBb9aZvuSxH66Rjilx7hVAO43zBVFuJ7Cs=; b=dbsBEqm2y2Te6NEaGG6QiXRY0owMVYAi9CIiRBpfNGdKmyInQfOfnF+YhfCfo0ufml 5NAwNTyv01EIhALDEmBTExwZuHCPtxQQssdlXGQ6QvSo3cSdZEgWh5gEQXljNM4UhYC6 duRqGZyoV0wydxC7V9Msib4DL2YC7gCbYj/OnENfp3XnUlUXHKwqdCKw60qg4MLXDlgL QzglPYjxH5DbmhNjdSKB9oR5H7ojwaD7uOLJsZv6f7elaEWjM1569XrMl7d6J0W04uvB ZNZPGLkvu/juGFjGLAmaTQoq0d/BQ36HZuFga0MdLmJT8zN8aSbxy1NKuyXdpOUwm1yN 6/kg== X-Gm-Message-State: AOAM531wdg+7dzH2ie9ebFYivpyj24gqA/Bjr1x/6zzrs6gwWeU1O4N7 yRAjK8Uhu4Y+qRYWk+3gSpw2KZCLi63Kcg== X-Google-Smtp-Source: ABdhPJwXMy2A2nH2ZjBGvC5/rZtB8OZXEmarPiWaxqfW5Ty7CPW69aDDj9lYw91f70Xg0TkYvqvU9Q== X-Received: by 2002:a05:6214:27ce:: with SMTP id ge14mr6052782qvb.19.1644530029760; Thu, 10 Feb 2022 13:53:49 -0800 (PST) Received: from localhost.localdomain (garza.riseup.net. [198.252.153.109]) by smtp.gmail.com with ESMTPSA id j15sm11740363qta.83.2022.02.10.13.53.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 13:53:49 -0800 (PST) From: Glenn Washburn To: Daniel Kiper , grub-devel@gnu.org Cc: Glenn Washburn Subject: [PATCH v3 15/15] grub-shell: Add flexibility in QEMU firmware handling Date: Thu, 10 Feb 2022 15:51:32 -0600 Message-Id: <80171fcab51b13570a21a10bf061ea80297c7c54.1644528774.git.development@efficientek.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::f31 (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::f31; envelope-from=development@efficientek.com; helo=mail-qv1-xf31.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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: Thu, 10 Feb 2022 21:53:59 -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 3df74cbe2..46f847ab7 100644 --- a/tests/util/grub-shell.in +++ b/tests/util/grub-shell.in @@ -180,21 +180,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= ;; @@ -203,7 +274,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.27.0