From patchwork Thu Feb 21 14:46:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve McIntyre <93sam@debian.org> X-Patchwork-Id: 158910 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp573971jaa; Thu, 21 Feb 2019 06:49:20 -0800 (PST) X-Google-Smtp-Source: AHgI3Iaz+0F0Fai834vgp3fP0F/A0jLQzkeecEpGwFt7UfgF7Bn0Tnj0i6U0l5RwwPl/5L0SXySr X-Received: by 2002:a25:ca83:: with SMTP id a125mr32222507ybg.45.1550760560846; Thu, 21 Feb 2019 06:49:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550760560; cv=none; d=google.com; s=arc-20160816; b=LuLxSJcIVgmhWKxwAq44ZrLrC11/z537xLnZ7TZul+9WSnU4r4IH9Pm583ibuYjAXL qKgZDYI6qly5R6WM+7AIXhjEouUj8gvpMN+6FWhUIi7uQZoTxV+6KAWsT0idKeh/bkr5 r7mudu+AZmxSk/br8t26V1gFeob/Jhc+GrH6NRSA80ZdptVuYDH38v3Imhkfm5U6vk+2 qMcOtOsqYBx9VB8eD+Dvf1iktatX+7G1BkTWLrYEkR949XvNATABYe1UeNF+cWBPD0Vf pqpVWi2aQoRzpynvwGd1p/tt1m0gMbJk0biS8mBPehLOH8dmdyrJVjhlmHrBMMGgxbir YzXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:references:in-reply-to:message-id:date:subject :to:from; bh=jQknKs5XW38O1IAozsA0s8Y02lf5EpLjya8mxqbUnbI=; b=dWUw9x3j0R+YdEcUGf0G2dKP1vWlSz3UZokVRLdthn0qhavCmVKJQ0AEQQwHtzc7hW IPutezimzk2cG/s7BnQD4b+C+sg7okpe+WlvB1if3u/1Zvak43kw3wL4PuavBsjp4+sw ILSj0hX4KU+WT+IUEg1IWN4ndWd1V5vMuMqOsEk8VOfbbpf76/1hASf95pdeR7hSHeki qrY5krdp+/FaItWws2KSze3ZOOWHTPxNedbE6MzlzkvGUfvbVLOI/yOdi4mWR8XQo0EU RdcqeoG5r3z87JJD5dUuOmpoiFHNjJp7lfu7QQ8a7os4CcK+bn6N3VINeo6bW33a48X8 DIaA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="grub-devel-bounces+patch=linaro.org@gnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id n197si721102yba.179.2019.02.21.06.49.20 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 21 Feb 2019 06:49:20 -0800 (PST) Received-SPF: pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="grub-devel-bounces+patch=linaro.org@gnu.org" Received: from localhost ([127.0.0.1]:33281 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwpf6-00085L-Dl for patch@linaro.org; Thu, 21 Feb 2019 09:49:20 -0500 Received: from eggs.gnu.org ([209.51.188.92]:51135) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwpdG-0006TF-5z for grub-devel@gnu.org; Thu, 21 Feb 2019 09:47:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gwpd6-0008Mj-Ew for grub-devel@gnu.org; Thu, 21 Feb 2019 09:47:22 -0500 Received: from cheddar.halon.org.uk ([93.93.131.118]:40042) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gwpd6-0008Fe-6X for grub-devel@gnu.org; Thu, 21 Feb 2019 09:47:16 -0500 Received: from bsmtp by cheddar.halon.org.uk with local-bsmtp (Exim 4.89) (envelope-from ) id 1gwpd1-0003Oo-WE; Thu, 21 Feb 2019 14:47:12 +0000 Received: from steve by tack.einval.org with local (Exim 4.89) (envelope-from ) id 1gwpc9-0007A7-7s; Thu, 21 Feb 2019 14:46:17 +0000 From: Steve McIntyre <93sam@debian.org> To: grub-devel@gnu.org Subject: [PATCH] grub-install: check for arm-efi as a default target Date: Thu, 21 Feb 2019 14:46:11 +0000 Message-Id: <20190221144611.27440-1-93sam@debian.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190221114110.z5nm5zhoyr3q5ngh@bivouac.eciton.net> References: <20190221114110.z5nm5zhoyr3q5ngh@bivouac.eciton.net> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 93.93.131.118 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: , Reply-To: The development of GNU GRUB Cc: Steve McIntyre <93sam@debian.org> MIME-Version: 1.0 Errors-To: grub-devel-bounces+patch=linaro.org@gnu.org Sender: "Grub-devel" Much like on x86, we can work out if the system is running on top of EFI firmware. If so, return "arm-efi". If not, fall back to "arm-uboot" as previously. Split out the code to (maybe) load the efivar module and check for /sys/firmware/efi into a common helper routine is_efi_system() Signed-off-by: Steve McIntyre <93sam@debian.org> --- grub-core/osdep/basic/platform.c | 6 ++++++ grub-core/osdep/linux/platform.c | 46 +++++++++++++++++++++++++++++++--------- include/grub/util/install.h | 3 +++ util/grub-install.c | 2 +- 4 files changed, 46 insertions(+), 11 deletions(-) -- 2.11.0 _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel Reviewed-by: Leif Lindholm Reviewed-by: Daniel Kiper 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 @@ -19,6 +19,12 @@ #include const char * +grub_install_get_default_arm_platform (void) +{ + return "arm-uboot"; +} + +const char * grub_install_get_default_x86_platform (void) { return "i386-pc"; diff --git a/grub-core/osdep/linux/platform.c b/grub-core/osdep/linux/platform.c index 775b6c031..5cb7bf923 100644 --- a/grub-core/osdep/linux/platform.c +++ b/grub-core/osdep/linux/platform.c @@ -97,16 +97,19 @@ read_platform_size (void) return ret; } -const char * -grub_install_get_default_x86_platform (void) -{ +/* Are we running on an EFI-based system? */ +static int +is_efi_system (void) +{ /* - On Linux, we need the efivars kernel modules. - If no EFI is available this module just does nothing - besides a small hello and if we detect efi we'll load it - anyway later. So it should be safe to - try to load it here. - */ + Linux uses efivarfs (mounted on /sys/firmware/efi/efivars) + to access the EFI variable store. + Some legacy systems may still use the deprecated efivars + interface (accessed through /sys/firmware/efi/vars). + Where both are present, libefivar will use the former in + preference, so attempting to load efivars will not interfere + with later operations. + */ grub_util_exec_redirect_all ((const char * []){ "modprobe", "efivars", NULL }, NULL, NULL, "/dev/null"); @@ -114,13 +117,36 @@ grub_install_get_default_x86_platform (void) if (is_not_empty_directory ("/sys/firmware/efi")) { grub_util_info ("...found"); + return 1; + } + else + { + grub_util_info ("... not found"); + return 0; + } +} + +const char * +grub_install_get_default_arm_platform (void) +{ + if (is_efi_system()) + return "arm-efi"; + else + return "arm-uboot"; +} + +const char * +grub_install_get_default_x86_platform (void) +{ + if (is_efi_system()) + { if (read_platform_size() == 64) return "x86_64-efi"; else return "i386-efi"; } - grub_util_info ("... not found. Looking for /proc/device-tree .."); + grub_util_info ("Looking for /proc/device-tree .."); if (is_not_empty_directory ("/proc/device-tree")) { grub_util_info ("...found"); diff --git a/include/grub/util/install.h b/include/grub/util/install.h index af2bf65d7..80a51fcb1 100644 --- a/include/grub/util/install.h +++ b/include/grub/util/install.h @@ -209,6 +209,9 @@ 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); int diff --git a/util/grub-install.c b/util/grub-install.c index 4a0a66168..1d68cc5bb 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__)