Package: src:grub Version: 2.02+dfsg1-11 Severity: normal Tags: upstream patch
Hi Colin, I've already submitted the core of this upstream - see http://lists.gnu.org/archive/html/grub-devel/2019-02/msg00018.html 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. Heavily inspired by the existing code for x86. I'd push this as an MR, but my head is just not in the right place for handling git-dpm right now :-( Here's a patch instead, ready to drop into debian/patches. I've extended the code here in similar fashion to what's already been added in our version of grub_install_get_default_x86_platform() to check in the pkglibdir. Otherwise this new code is just the same as I've sent upstream yesterday. -- System Information: Debian Release: 9.7 APT prefers stable-updates APT policy: (500, 'stable-updates'), (500, 'stable-debug'), (500, 'stable') Architecture: amd64 (x86_64) Foreign Architectures: i386 Kernel: Linux 4.9.0-8-amd64 (SMP w/4 CPU cores) Locale: LANG=en_GB.UTF-8, LC_CTYPE=en_GB.UTF-8 (charmap=UTF-8), LANGUAGE=en_GB.UTF-8 (charmap=UTF-8) Shell: /bin/sh linked to /bin/dash Init: systemd (via /run/systemd/system)
From: Steve McIntyre <93...@debian.org> Date: Tue, 12 Feb 2019 02:23:14 +0000 Subject: grub-install: check for arm-efi as a default target 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. Heavily inspired by the existing code for x86. Signed-off-by: Steve McIntyre <93...@debian.org> Bug-Debian: https://bugs.debian.org/XXXXXX Forwarded: http://lists.gnu.org/archive/html/grub-devel/2019-02/msg00018.html Patch-Name: grub-install-check-arm-efi.patch grub-core/osdep/basic/platform.c | 6 ++++++ grub-core/osdep/linux/platform.c | 37 +++++++++++++++++++++++++++++++++++++ include/grub/util/install.h | 3 +++ util/grub-install.c | 2 +- 5 files changed, 48 insertions(+), 1 deletion(-) diff --git a/grub-core/osdep/basic/platform.c b/grub-core/osdep/basic/platform.c index 2ab907976..ac41452e0 100644 --- a/grub-core/osdep/basic/platform.c +++ b/grub-core/osdep/basic/platform.c @@ -19,6 +19,12 @@ #include <grub/util/install.h> 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 9805c36d4..0110ac655 100644 --- a/grub-core/osdep/linux/platform.c +++ b/grub-core/osdep/linux/platform.c @@ -101,6 +101,43 @@ read_platform_size (void) } const char * +grub_install_get_default_arm_platform (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. + */ + grub_util_exec_redirect_all ((const char * []){ "modprobe", "efivars", NULL }, + NULL, NULL, "/dev/null"); + + grub_util_info ("Looking for /sys/firmware/efi .."); + if (is_not_empty_directory ("/sys/firmware/efi")) + { + const char *pkglibdir = grub_util_get_pkglibdir (); + const char *platform; + char *pd; + int found; + + grub_util_info ("...found"); + platform = "arm-efi"; + + pd = grub_util_path_concat (2, pkglibdir, platform); + found = grub_util_is_directory (pd); + free (pd); + if (found) + return platform; + else + grub_util_info ("... but %s platform not available", platform); + } + + grub_util_info ("... not found"); + 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 3fd46ec30..5783cc4bc 100644 --- a/include/grub/util/install.h +++ b/include/grub/util/install.h @@ -205,6 +205,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); const char * diff --git a/util/grub-install.c b/util/grub-install.c index 6bc96fc8f..fcd6680f1 100644 --- a/util/grub-install.c +++ b/util/grub-install.c @@ -348,7 +348,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__)