From 1690d7936dec9a3820b20cc3c6219b2d98200eb4 Mon Sep 17 00:00:00 2001
From: Steve McIntyre <93sam@debian.org>
Date: Tue, 26 Feb 2019 14:14:17 +0000
Subject: Fall back to arm-uboot if booted using EFI but -efi is missing

It may be possible, particularly in recovery situations, to be booted
using EFI on ARM when only the arm-uboot target is installed.  There's
nothing actually stopping us installing arm-uboot from an EFI
environment, and it's better than returning a confusing error.

(When convenient, this patch should be merged with
install_efi_fallback.patch.)

Forwarded: no
Last-Update: 2019-02-26

Patch-Name: install_efi_fallback_arm.patch
---
 grub-core/osdep/linux/platform.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/grub-core/osdep/linux/platform.c b/grub-core/osdep/linux/platform.c
index 54a9b9ecc..fae85430c 100644
--- a/grub-core/osdep/linux/platform.c
+++ b/grub-core/osdep/linux/platform.c
@@ -114,8 +114,21 @@ grub_install_get_default_arm_platform (void)
   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");
-      return "arm-efi";
+      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");
