Blame SOURCES/0218-powerpc-adjust-setting-of-prefix-for-signed-binary-c.patch

8e15ce
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
8e15ce
From: Daniel Axtens <dja@axtens.net>
8e15ce
Date: Mon, 19 Jul 2021 14:35:55 +1000
8e15ce
Subject: [PATCH] powerpc: adjust setting of prefix for signed binary case
8e15ce
8e15ce
On RHEL-signed powerpc grub, we sign a grub with -p /grub2 and expect
8e15ce
that there's a boot partition.
8e15ce
8e15ce
Unfortunately grub_set_prefix_and_root tries to convert this to
8e15ce
($fwdevice)/grub2. This ends up being (ieee1275/disk)/grub2 and that
8e15ce
falls apart pretty quickly - there's no file-system on ieee1275/disk,
8e15ce
and it makes the search routine try things like
8e15ce
(ieee1275/disk,msdos2)(ieee1275/disk)/grub2 which also doesn't work.
8e15ce
8e15ce
Detect if we would be about to create (ieee1275/disk)/path and don't:
8e15ce
preserve a prefix of /path instead and hope the search later finds us.
8e15ce
8e15ce
Related: rhbz#1899864
8e15ce
8e15ce
Signed-off-by: Daniel Axtens <dja@axtens.net>
8e15ce
---
8e15ce
 grub-core/kern/main.c | 38 +++++++++++++++++++++++++++++++++-----
8e15ce
 1 file changed, 33 insertions(+), 5 deletions(-)
8e15ce
8e15ce
diff --git a/grub-core/kern/main.c b/grub-core/kern/main.c
8e15ce
index 0285e95a2bb..e809a5edec1 100644
8e15ce
--- a/grub-core/kern/main.c
8e15ce
+++ b/grub-core/kern/main.c
8e15ce
@@ -216,13 +216,41 @@ grub_set_prefix_and_root (void)
8e15ce
   if (device)
8e15ce
     {
8e15ce
       char *prefix_set;
8e15ce
-    
8e15ce
-      prefix_set = grub_xasprintf ("(%s)%s", device, path ? : "");
8e15ce
-      if (prefix_set)
8e15ce
+
8e15ce
+#ifdef __powerpc__
8e15ce
+      /* We have to be careful here on powerpc-ieee1275 + signed grub. We
8e15ce
+	 will have signed something with a prefix that doesn't have a device
8e15ce
+	 because we cannot know in advance what partition we're on.
8e15ce
+
8e15ce
+	 We will have had !device earlier, so we will have set device=fwdevice
8e15ce
+	 However, we want to make sure we do not end up setting prefix to be
8e15ce
+	 ($fwdevice)/path, because we will then end up trying to boot or search
8e15ce
+	 based on a prefix of (ieee1275/disk)/path, which will not work because
8e15ce
+	 it's missing a partition.
8e15ce
+
8e15ce
+	 Also:
8e15ce
+	  - You can end up with a device with an FS directly on it, without
8e15ce
+	    a partition, e.g. ieee1275/cdrom.
8e15ce
+
8e15ce
+	  - powerpc-ieee1275 + grub-install sets e.g. prefix=(,gpt2)/path,
8e15ce
+	    which will have now been extended to device=$fwdisk,partition
8e15ce
+	    and path=/path
8e15ce
+
8e15ce
+	 So we only need to act if device = ieee1275/disk exactly.
8e15ce
+       */
8e15ce
+      if (grub_strncmp (device, "ieee1275/disk", 14) == 0)
8e15ce
+        grub_env_set ("prefix", path);
8e15ce
+      else
8e15ce
+#endif
8e15ce
 	{
8e15ce
-	  grub_env_set ("prefix", prefix_set);
8e15ce
-	  grub_free (prefix_set);
8e15ce
+	  prefix_set = grub_xasprintf ("(%s)%s", device, path ? : "");
8e15ce
+	  if (prefix_set)
8e15ce
+	  {
8e15ce
+	    grub_env_set ("prefix", prefix_set);
8e15ce
+	    grub_free (prefix_set);
8e15ce
+	  }
8e15ce
 	}
8e15ce
+
8e15ce
       grub_env_set ("root", device);
8e15ce
     }
8e15ce