]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
util/grub-install: Ensure a functional /dev/nvram
authorIsmael Luceno <iluceno@suse.de>
Mon, 5 Sep 2022 12:39:46 +0000 (14:39 +0200)
committerDaniel Kiper <daniel.kiper@oracle.com>
Wed, 7 Dec 2022 22:37:32 +0000 (23:37 +0100)
This enables an early failure; for i386-ieee1275 and powerpc-ieee1275 on
Linux, without /dev/nvram the system may be left in an unbootable state.

Signed-off-by: Ismael Luceno <iluceno@suse.de>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
util/grub-install.c

index 1c0ece7f19e0a4a11bee85d1b1f9f63940ad9ab6..53b46480428878cb5359894bca38ee266016a9b6 100644 (file)
@@ -827,6 +827,19 @@ fill_core_services (const char *core_services)
   free (sysv_plist);
 }
 
+#ifdef __linux__
+static void
+try_open (const char *path)
+{
+  FILE *f;
+
+  f = grub_util_fopen (path, "r+");
+  if (f == NULL)
+    grub_util_error (_("Unable to open %s: %s"), path, strerror (errno));
+  fclose (f);
+}
+#endif
+
 int
 main (int argc, char *argv[])
 {
@@ -1026,6 +1039,20 @@ main (int argc, char *argv[])
       break;
     }
 
+  switch (platform)
+    {
+    case GRUB_INSTALL_PLATFORM_I386_IEEE1275:
+    case GRUB_INSTALL_PLATFORM_POWERPC_IEEE1275:
+#ifdef __linux__
+      /* On Linux, ensure /dev/nvram is _functional_. */
+      if (update_nvram)
+        try_open ("/dev/nvram");
+#endif
+      break;
+    default:
+      break;
+    }
+
   /* Find the EFI System Partition.  */
 
   if (is_efi)