Blame SOURCES/0187-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>
b35c50
[rharwood@redhat.com: squash in fixup commit]
b35c50
Signed-off-by: Robbie Harwood <rharwood@redhat.com>
8e15ce
---
b35c50
 grub-core/kern/main.c | 49 ++++++++++++++++++++++++++++++++++++++++++++-----
b35c50
 1 file changed, 44 insertions(+), 5 deletions(-)
8e15ce
8e15ce
diff --git a/grub-core/kern/main.c b/grub-core/kern/main.c
b35c50
index b573be6650..3fc3401472 100644
8e15ce
--- a/grub-core/kern/main.c
8e15ce
+++ b/grub-core/kern/main.c
b35c50
@@ -216,13 +216,52 @@ 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
+
b35c50
+	  - PowerVM will give us device names like
b35c50
+	    ieee1275//vdevice/v-scsi@3000006c/disk@8100000000000000
b35c50
+	    and we don't want to try to encode some sort of truth table about
b35c50
+	    what sorts of paths represent disks with partition tables and those
b35c50
+	    without partition tables.
b35c50
+
b35c50
+	 So we act unless there is a comma in the device, which would indicate
b35c50
+	 a partition has already been specified.
b35c50
+
b35c50
+	 (If we only have a path, the code in normal to discover config files
b35c50
+	 will try both without partitions and then with any partitions so we
b35c50
+	 will cover both CDs and HDs.)
8e15ce
+       */
b35c50
+      if (grub_strchr (device, ',') == NULL)
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