* [PATCH 0/2] Fix installation issues on ppc64le
@ 2022-08-24 16:03 Ismael Luceno
2022-08-24 16:03 ` [PATCH 1/2] Add helper to load linux kmods Ismael Luceno
2022-08-24 16:03 ` [PATCH 2/2] Ensure nvram is available and functional on IEEE1275 Ismael Luceno
0 siblings, 2 replies; 5+ messages in thread
From: Ismael Luceno @ 2022-08-24 16:03 UTC (permalink / raw)
To: grub-devel; +Cc: Ismael Luceno
When the /dev/nvram device is unavailable, the installation fails and
leaves the system in an unbootable state.
The patches in this series introduce a handler for the boilerplate code
and make sure nvram is available.
Ismael Luceno (2):
Add helper to load linux kmods
Ensure nvram is available and functional on IEEE1275
grub-core/osdep/unix/platform.c | 42 +++++++++++++++++++++++++++++----
1 file changed, 38 insertions(+), 4 deletions(-)
--
2.37.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/2] Add helper to load linux kmods
2022-08-24 16:03 [PATCH 0/2] Fix installation issues on ppc64le Ismael Luceno
@ 2022-08-24 16:03 ` Ismael Luceno
2022-08-24 16:03 ` [PATCH 2/2] Ensure nvram is available and functional on IEEE1275 Ismael Luceno
1 sibling, 0 replies; 5+ messages in thread
From: Ismael Luceno @ 2022-08-24 16:03 UTC (permalink / raw)
To: grub-devel; +Cc: Ismael Luceno
The function checks for already loaded (incl. built-in) modules first at
/sys/module/, then tries to load it.
Abort when unable to load efivarfs/efivars.
Signed-off-by: Ismael Luceno <iluceno@suse.de>
---
grub-core/osdep/unix/platform.c | 24 ++++++++++++++++++++----
1 file changed, 20 insertions(+), 4 deletions(-)
diff --git a/grub-core/osdep/unix/platform.c b/grub-core/osdep/unix/platform.c
index de712211cf09..a5bf064b7cf5 100644
--- a/grub-core/osdep/unix/platform.c
+++ b/grub-core/osdep/unix/platform.c
@@ -26,8 +26,25 @@
#include <grub/emu/exec.h>
#include <sys/types.h>
#include <dirent.h>
+#include <stdio.h>
#include <string.h>
#include <errno.h>
+#include <unistd.h>
+
+static int
+linux_kmod_load (const char *name)
+{
+#ifdef __linux__
+ char path[64];
+ if (snprintf (path, sizeof(path), "/sys/module/%s", name) >= sizeof(path))
+ grub_util_error (_("module name `%s' too long"), name);
+ if (!access (path, F_OK))
+ return 0;
+ return grub_util_exec ((const char * []){ "modprobe", "-q", name, NULL });
+#else
+ return 0;
+#endif
+}
static char *
get_ofpathname (const char *dev)
@@ -149,10 +166,9 @@ grub_install_register_efi (grub_device_t efidir_grub_dev,
grub_util_error (_("%s: not found"), "efibootmgr");
}
- /* On Linux, we need the efivars kernel modules. */
-#ifdef __linux__
- grub_util_exec ((const char * []){ "modprobe", "-q", "efivars", NULL });
-#endif
+ /* On Linux, we need efivarfs (or the legacy efivars). */
+ linux_kmod_load ("efivars");
+
/* Delete old entries from the same distributor. */
ret = grub_install_remove_efi_entries_by_distributor (efi_distributor);
if (ret)
--
2.37.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/2] Ensure nvram is available and functional on IEEE1275
2022-08-24 16:03 [PATCH 0/2] Fix installation issues on ppc64le Ismael Luceno
2022-08-24 16:03 ` [PATCH 1/2] Add helper to load linux kmods Ismael Luceno
@ 2022-08-24 16:03 ` Ismael Luceno
2022-08-25 4:24 ` Michael Chang
1 sibling, 1 reply; 5+ messages in thread
From: Ismael Luceno @ 2022-08-24 16:03 UTC (permalink / raw)
To: grub-devel; +Cc: Ismael Luceno
Otherwise the installation will fail, and the system will be left in an
unbootable state.
On ppc64le, the boot process shows:
Welcome to GRUB!
error: ../../grub-core/kern/dl.c:380:symbol `grub_disk_get_size' not found.
Entering rescue mode...
grub rescue>
Signed-off-by: Ismael Luceno <iluceno@suse.de>
---
grub-core/osdep/unix/platform.c | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/grub-core/osdep/unix/platform.c b/grub-core/osdep/unix/platform.c
index a5bf064b7cf5..fd23176e58a0 100644
--- a/grub-core/osdep/unix/platform.c
+++ b/grub-core/osdep/unix/platform.c
@@ -192,12 +192,30 @@ grub_install_register_efi (grub_device_t efidir_grub_dev,
return ret;
}
+static void
+linux_ensure_nvram (void)
+{
+ int fd;
+#ifndef __linux__
+ return 0;
+#endif
+ if (linux_kmod_load("nvram"))
+ grub_util_error (_("%s: kernel module not found"), "nvram");
+ fd = open ("/dev/nvram", O_RDWR);
+ if (fd == -1)
+ grub_util_error ("/dev/nvram: %s", strerror(errno));
+ close (fd);
+}
+
void
grub_install_register_ieee1275 (int is_prep, const char *install_device,
int partno, const char *relpath)
{
char *boot_device;
+ /* On Linux, ensure nvram is available and functional. */
+ linux_ensure_nvram ();
+
if (grub_util_exec_redirect_null ((const char * []){ "ofpathname", "--version", NULL }))
{
/* TRANSLATORS: This message is shown when required executable `%s'
--
2.37.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] Ensure nvram is available and functional on IEEE1275
2022-08-24 16:03 ` [PATCH 2/2] Ensure nvram is available and functional on IEEE1275 Ismael Luceno
@ 2022-08-25 4:24 ` Michael Chang
2022-08-29 14:40 ` Ismael Luceno
0 siblings, 1 reply; 5+ messages in thread
From: Michael Chang @ 2022-08-25 4:24 UTC (permalink / raw)
To: The development of GNU GRUB; +Cc: Ismael Luceno
On Wed, Aug 24, 2022 at 06:03:11PM +0200, Ismael Luceno wrote:
> Otherwise the installation will fail, and the system will be left in an
> unbootable state.
>
> On ppc64le, the boot process shows:
>
> Welcome to GRUB!
>
> error: ../../grub-core/kern/dl.c:380:symbol `grub_disk_get_size' not found.
> Entering rescue mode...
> grub rescue>
The symbol looking up failure due to failed grub-install attempt should
not happen in the first place given this commit should bail it out.
8ddbdc3bc2 grub-install: Add backup and restore
Apparently there's missing grub_set_install_backup_ponr between
successful image embedding and grub_install_register_ieee1275 and we
should fix that as well.
>
> Signed-off-by: Ismael Luceno <iluceno@suse.de>
> ---
> grub-core/osdep/unix/platform.c | 18 ++++++++++++++++++
> 1 file changed, 18 insertions(+)
>
> diff --git a/grub-core/osdep/unix/platform.c b/grub-core/osdep/unix/platform.c
> index a5bf064b7cf5..fd23176e58a0 100644
> --- a/grub-core/osdep/unix/platform.c
> +++ b/grub-core/osdep/unix/platform.c
> @@ -192,12 +192,30 @@ grub_install_register_efi (grub_device_t efidir_grub_dev,
> return ret;
> }
>
> +static void
> +linux_ensure_nvram (void)
> +{
> + int fd;
> +#ifndef __linux__
> + return 0;
> +#endif
> + if (linux_kmod_load("nvram"))
> + grub_util_error (_("%s: kernel module not found"), "nvram");
> + fd = open ("/dev/nvram", O_RDWR);
> + if (fd == -1)
> + grub_util_error ("/dev/nvram: %s", strerror(errno));
> + close (fd);
> +}
> +
I'm wondering why it is needed. The nvram module should be loaded
on-demand via linux kernel's request_module() and modalias trick whever
/dev/nvram is accessed.
Thanks,
Michael
> void
> grub_install_register_ieee1275 (int is_prep, const char *install_device,
> int partno, const char *relpath)
> {
> char *boot_device;
>
> + /* On Linux, ensure nvram is available and functional. */
> + linux_ensure_nvram ();
> +
> if (grub_util_exec_redirect_null ((const char * []){ "ofpathname", "--version", NULL }))
> {
> /* TRANSLATORS: This message is shown when required executable `%s'
> --
> 2.37.1
>
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] Ensure nvram is available and functional on IEEE1275
2022-08-25 4:24 ` Michael Chang
@ 2022-08-29 14:40 ` Ismael Luceno
0 siblings, 0 replies; 5+ messages in thread
From: Ismael Luceno @ 2022-08-29 14:40 UTC (permalink / raw)
To: Michael Chang; +Cc: The development of GNU GRUB
On Thu, 25 Aug 2022 12:24:17 +0800
Michael Chang <mchang@suse.com> wrote:
<...>
> Apparently there's missing grub_set_install_backup_ponr between
> successful image embedding and grub_install_register_ieee1275 and we
> should fix that as well.
Thanks for the feedback; I've sent v2.
<...>
> > + if (linux_kmod_load("nvram"))
> > + grub_util_error (_("%s: kernel module not found"), "nvram");
> > + fd = open ("/dev/nvram", O_RDWR);
> > + if (fd == -1)
> > + grub_util_error ("/dev/nvram: %s", strerror(errno));
<...>
> I'm wondering why it is needed. The nvram module should be loaded
> on-demand via linux kernel's request_module() and modalias trick
> whever /dev/nvram is accessed.
It was based on another patch that did so but without the extra
checking, I guess both are wrong.
It's enough checking /dev/nvram is operational; it's necessary
to fail early because other commands down the line may get ENODEV if
the module fails to load (e.g. the file may have been removed). I moved
this to an earlier point in grub-install.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-08-29 14:40 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-08-24 16:03 [PATCH 0/2] Fix installation issues on ppc64le Ismael Luceno
2022-08-24 16:03 ` [PATCH 1/2] Add helper to load linux kmods Ismael Luceno
2022-08-24 16:03 ` [PATCH 2/2] Ensure nvram is available and functional on IEEE1275 Ismael Luceno
2022-08-25 4:24 ` Michael Chang
2022-08-29 14:40 ` Ismael Luceno
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.