Received: from list by lists.gnu.org with archive (Exim 4.71) id 1fujlX-0002ZD-9L for mharc-grub-devel@gnu.org; Tue, 28 Aug 2018 15:35:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45015) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fujlR-0002Wp-OB for grub-devel@gnu.org; Tue, 28 Aug 2018 15:34:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fujlO-0001fH-MB for grub-devel@gnu.org; Tue, 28 Aug 2018 15:34:57 -0400 Received: from complete.lackof.org ([198.49.126.79]:56364) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fujlO-0001eJ-Bx for grub-devel@gnu.org; Tue, 28 Aug 2018 15:34:54 -0400 Received: from localhost (c-107-2-141-103.hsd1.co.comcast.net [107.2.141.103]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by complete.lackof.org (Postfix) with ESMTPSA id 6B69133E0184; Tue, 28 Aug 2018 13:34:53 -0600 (MDT) From: dann frazier To: grub-devel@gnu.org, Leif Lindholm Subject: [RFC][PATCH 2/2] arm: grub-install: Default to arm-efi target in EFI-based QEMU virt models Date: Tue, 28 Aug 2018 13:33:48 -0600 Message-Id: <20180828193348.31676-3-dann.frazier@canonical.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180828193348.31676-1-dann.frazier@canonical.com> References: <20180828193348.31676-1-dann.frazier@canonical.com> X-Virus-Scanned: clamav-milter 0.100.1 at complete.lackof.org X-Virus-Status: Clean X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 198.49.126.79 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 28 Aug 2018 19:34:59 -0000 From: dann frazier We currently default to the arm-uboot target in grub-install, but arm-efi should be used for some systems with UEFI firmware, such as Tianocore/EDK2-based QEMU models. We could change the default to arm-efi anytime we successfully probe for an EFI runtime. However, that would apparently do the wrong thing on U-Boot implementations that implement the UEFI spec, such as those compliant with the upcoming Embedded Base Boot Requirements specification, as they are not required to support SetVariable() in runtime services. For now, whitelist QEMU linux/virt models with runtime EFI support, but otherwise continue to default to the arm-uboot target. Signed-off-by: dann frazier --- grub-core/osdep/basic/platform.c | 6 +++++ grub-core/osdep/linux/platform.c | 37 ++++++++++++++++++++++++++++++ grub-core/osdep/windows/platform.c | 6 +++++ include/grub/util/install.h | 3 +++ util/grub-install.c | 2 +- 5 files changed, 53 insertions(+), 1 deletion(-) diff --git a/grub-core/osdep/basic/platform.c b/grub-core/osdep/basic/platform.c index 4b5502aeb..a7dafd85a 100644 --- a/grub-core/osdep/basic/platform.c +++ b/grub-core/osdep/basic/platform.c @@ -18,6 +18,12 @@ #include +const char * +grub_install_get_default_arm_platform (void) +{ + return "arm-uboot"; +} + const char * grub_install_get_default_x86_platform (void) { diff --git a/grub-core/osdep/linux/platform.c b/grub-core/osdep/linux/platform.c index d278c299b..835aa4856 100644 --- a/grub-core/osdep/linux/platform.c +++ b/grub-core/osdep/linux/platform.c @@ -121,6 +121,43 @@ is_efi (void) return 0; } +static int +is_virt (void) +{ + FILE *fp; + char *buf = NULL; + int ret = 0; + size_t len = 0; + const char qemu_virt[] = "linux,dummy-virt"; + + fp = grub_util_fopen ("/sys/firmware/devicetree/base/compatible", "r"); + if (fp == NULL) + return 0; + + if (getline (&buf, &len, fp) == -1) + { + fclose (fp); + return 0; + } + + if (strncmp (buf, qemu_virt, len) == 0) + ret = 1; + + free (buf); + fclose (fp); + + return ret; +} + +const char * +grub_install_get_default_arm_platform (void) +{ + if (is_efi() && is_virt()) + return "arm-efi"; + + return "arm-uboot"; +} + const char * grub_install_get_default_x86_platform (void) { diff --git a/grub-core/osdep/windows/platform.c b/grub-core/osdep/windows/platform.c index 58b322887..2dabd1758 100644 --- a/grub-core/osdep/windows/platform.c +++ b/grub-core/osdep/windows/platform.c @@ -116,6 +116,12 @@ is_efi (void) return platform == PLAT_EFI; } +const char * +grub_install_get_default_arm_platform (void) +{ + return "arm-uboot"; +} + const char * grub_install_get_default_x86_platform (void) { diff --git a/include/grub/util/install.h b/include/grub/util/install.h index 0dba8b67f..212ada422 100644 --- a/include/grub/util/install.h +++ b/include/grub/util/install.h @@ -207,6 +207,9 @@ grub_util_get_target_dirname (const struct grub_install_image_target_desc *t); void grub_install_create_envblk_file (const char *name); +const char * +grub_install_get_default_arm_platform (void); + const char * grub_install_get_default_x86_platform (void); diff --git a/util/grub-install.c b/util/grub-install.c index 78d0138cb..81bbec778 100644 --- a/util/grub-install.c +++ b/util/grub-install.c @@ -319,7 +319,7 @@ get_default_platform (void) #elif defined (__ia64__) return "ia64-efi"; #elif defined (__arm__) - return "arm-uboot"; + return grub_install_get_default_arm_platform (); #elif defined (__aarch64__) return "arm64-efi"; #elif defined (__amd64__) || defined (__x86_64__) || defined (__i386__) -- 2.18.0