All of lore.kernel.org
 help / color / mirror / Atom feed
From: Leo Sandoval <lsandova@redhat.com>
To: grub-devel@gnu.org
Subject: [PATCH v3 08/16] normal: Add fw_path variable (revised)
Date: Thu, 10 Oct 2024 15:43:26 -0600	[thread overview]
Message-ID: <20241010214334.1749167-9-lsandova@redhat.com> (raw)
In-Reply-To: <20241010214334.1749167-1-lsandova@redhat.com>

From: Paulo Flabiano Smorigo <pfsmorigo@br.ibm.com>

This patch makes grub look for its config file on efi where the app was
found. It was originally written by Matthew Garrett, and adapted to fix the
"No modules are loaded on grub2 network boot" issue:

https://bugzilla.redhat.com/show_bug.cgi?id=857936

Signed-off-by: Paulo Flabiano Smorigo <pfsmorigo@br.ibm.com>
Signed-off-by: Robbie Harwood <rharwood@redhat.com>
---
 grub-core/kern/main.c   | 13 ++++++-------
 grub-core/normal/main.c | 25 ++++++++++++++++++++++++-
 2 files changed, 30 insertions(+), 8 deletions(-)

diff --git a/grub-core/kern/main.c b/grub-core/kern/main.c
index 731c07c29..463dafdba 100644
--- a/grub-core/kern/main.c
+++ b/grub-core/kern/main.c
@@ -128,16 +128,15 @@ grub_set_prefix_and_root (void)
 
   grub_machine_get_bootlocation (&fwdevice, &fwpath);
 
-  if (fwdevice)
+  if (fwdevice && fwpath)
     {
-      char *cmdpath;
+      char *fw_path;
 
-      cmdpath = grub_xasprintf ("(%s)%s", fwdevice, fwpath ? : "");
-      if (cmdpath)
+      fw_path = grub_xasprintf ("(%s)/%s", fwdevice, fwpath);
+      if (fw_path)
 	{
-	  grub_env_set ("cmdpath", cmdpath);
-	  grub_env_export ("cmdpath");
-	  grub_free (cmdpath);
+	  grub_env_set ("fw_path", fw_path);
+	  grub_free (fw_path);
 	}
     }
 
diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c
index d3f53d93d..08f48c71d 100644
--- a/grub-core/normal/main.c
+++ b/grub-core/normal/main.c
@@ -339,7 +339,30 @@ grub_cmd_normal (struct grub_command *cmd __attribute__ ((unused)),
       /* Guess the config filename. It is necessary to make CONFIG static,
 	 so that it won't get broken by longjmp.  */
       char *config;
-      const char *prefix;
+      const char *prefix, *fw_path;
+
+      fw_path = grub_env_get ("fw_path");
+      if (fw_path)
+	{
+	  config = grub_xasprintf ("%s/grub.cfg", fw_path);
+	  if (config)
+	    {
+	      grub_file_t file;
+
+	      file = grub_file_open (config, GRUB_FILE_TYPE_CONFIG);
+	      if (file)
+		{
+		  grub_file_close (file);
+		  grub_enter_normal_mode (config);
+		}
+              else
+                {
+                  /*  Ignore all errors.  */
+                  grub_errno = 0;
+                }
+	      grub_free (config);
+	    }
+	}
 
       prefix = grub_env_get ("prefix");
       if (prefix)
-- 
2.46.2


_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel

  parent reply	other threads:[~2024-10-10 21:46 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-10 21:43 [PATCH v3 00/16] First Distro-agnostic series taken from Fedora Rawhide Leo Sandoval
2024-10-10 21:43 ` [PATCH v3 01/16] ieee1275/openfw: IBM client architecture (CAS) reboot support Leo Sandoval
2024-10-10 21:43 ` [PATCH v3 02/16] term/terminfo: for ppc, reset console display attr when clear screen Leo Sandoval
2024-10-10 21:43 ` [PATCH v3 03/16] ieee1275: Disable GRUB video support for IBM power machines Leo Sandoval
2024-10-10 21:43 ` [PATCH v3 04/16] configure.ac: Move bash completion script Leo Sandoval
2024-10-10 21:43 ` [PATCH v3 05/16] misc: Make "exit" take a return code Leo Sandoval
2024-10-10 21:43 ` [PATCH v3 06/16] efi/init: Make efi machines load an env block from a variable Leo Sandoval
2024-10-10 21:43 ` [PATCH v3 07/16] 20_ppc_terminfo.in: Migrate ieee1275/PPC from Yaboot to Grub2 Leo Sandoval
2024-10-10 21:43 ` Leo Sandoval [this message]
2024-10-15  5:23   ` [PATCH v3 08/16] normal: Add fw_path variable (revised) Michael Chang via Grub-devel
2024-10-15  9:01     ` Vladimir 'phcoder' Serbinenko
2024-10-10 21:43 ` [PATCH v3 09/16] commands: Pass "\x[[:hex:]][[:hex:]]" straight through unmolested Leo Sandoval
2024-10-10 21:43 ` [PATCH v3 10/16] 10_linux.in: Add devicetree loading Leo Sandoval
2024-10-10 21:43 ` [PATCH v3 11/16] Makefile.common: Add .eh_frame to list of relocations stripped Leo Sandoval
2024-10-10 21:43 ` [PATCH v3 12/16] 10_linux.in: Don't require a password to boot entries generated by grub-mkconfig Leo Sandoval
2024-10-10 21:43 ` [PATCH v3 13/16] normal/main: fw_path prefix when fallback searching for grub config Leo Sandoval
2024-10-10 21:43 ` [PATCH v3 14/16] normal/main: Try mac/guid/etc before grub.cfg on tftp config files Leo Sandoval
2024-10-10 21:43 ` [PATCH v3 15/16] 10_linux.in: Generate OS and CLASS in 10_linux from /etc/os-release Leo Sandoval
2024-10-10 21:43 ` [PATCH v3 16/16] normal/main: Try $prefix if $fw_path doesn't work Leo Sandoval
2024-10-30 16:39 ` [PATCH v3 00/16] First Distro-agnostic series taken from Fedora Rawhide Daniel Kiper
2024-10-30 17:03   ` Leo Sandoval

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241010214334.1749167-9-lsandova@redhat.com \
    --to=lsandova@redhat.com \
    --cc=grub-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.