From: Ismael Luceno Date: Mon, 5 Sep 2022 12:39:46 +0000 (+0200) Subject: util/grub-install: Ensure a functional /dev/nvram X-Git-Tag: grub-2.12-rc1~209 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=67e90bf743c357ccb4aa39c10e6107087a7a0776;p=thirdparty%2Fgrub.git util/grub-install: Ensure a functional /dev/nvram 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 Reviewed-by: Daniel Kiper --- diff --git a/util/grub-install.c b/util/grub-install.c index 1c0ece7f1..53b464804 100644 --- a/util/grub-install.c +++ b/util/grub-install.c @@ -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)