nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

Blame SOURCES/0210-powerpc-prefix-detection-support-device-names-with-c.patch

e28c09
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
e28c09
From: Daniel Axtens <dja@axtens.net>
e28c09
Date: Thu, 24 Mar 2022 14:34:32 +1100
e28c09
Subject: [PATCH] powerpc: prefix detection: support device names with commas
e28c09
e28c09
Frustratingly, the device name itself can contain an embedded comma:
e28c09
e.g /pci@800000020000015/pci1014,034A@0/sas/disk@5000c50098a0ee8b
e28c09
e28c09
So my previous approach was wrong: we cannot rely upon the presence
e28c09
of a comma to say that a partition has been specified!
e28c09
e28c09
It turns out for prefixes like (,gpt2)/grub2 we really want to make
e28c09
up a full (device,partition)/patch prefix, because root discovery code
e28c09
in 10_linux will reset the root variable and use search to fill it again.
e28c09
If you have run grub-install, you probably don't have search built in,
e28c09
and if you don't have prefix containing (device,partition), grub will
e28c09
construct ($root)$prefix/powerpc-ieee1275/search.mod - but because $root
e28c09
has just been changed, this will no longer work, and the boot will fail!
e28c09
e28c09
Retain the gist of the logic, but instead of looking for a comma, look for
e28c09
a leading '('. This matches the earlier code better anyway.
e28c09
e28c09
There's certainly a better fix to be had. But any time you chose to build
e28c09
with a bare prefix like '/grub2', you're almost certainly going to build in
e28c09
search anyway, so this will do.
e28c09
e28c09
Signed-off-by: Daniel Axtens <dja@axtens.net>
e28c09
---
e28c09
 grub-core/kern/main.c | 27 +++++++++++++++++++++------
e28c09
 1 file changed, 21 insertions(+), 6 deletions(-)
e28c09
e28c09
diff --git a/grub-core/kern/main.c b/grub-core/kern/main.c
b35c50
index 993b8a8598..e94a2f78fb 100644
e28c09
--- a/grub-core/kern/main.c
e28c09
+++ b/grub-core/kern/main.c
e28c09
@@ -242,14 +242,29 @@ grub_set_prefix_and_root (void)
e28c09
 	    what sorts of paths represent disks with partition tables and those
e28c09
 	    without partition tables.
e28c09
 
e28c09
-	 So we act unless there is a comma in the device, which would indicate
e28c09
-	 a partition has already been specified.
e28c09
+          - Frustratingly, the device name itself can contain an embedded comma:
e28c09
+            /pci@800000020000015/pci1014,034A@0/sas/disk@5000c50098a0ee8b
e28c09
+            So we cannot even rely upon the presence of a comma to say that a
e28c09
+            partition has been specified!
e28c09
 
e28c09
-	 (If we only have a path, the code in normal to discover config files
e28c09
-	 will try both without partitions and then with any partitions so we
e28c09
-	 will cover both CDs and HDs.)
e28c09
+         If we only have a path in $prefix, the code in normal to discover
e28c09
+	 config files will try all disks, both without partitions and then with
e28c09
+	 any partitions so we will cover both CDs and HDs.
e28c09
+
e28c09
+         However, it doesn't then set the prefix to be something like
e28c09
+         (discovered partition)/path, and so it is fragile against runtime
e28c09
+         changes to $root. For example some of the stuff done in 10_linux to
e28c09
+         reload $root sets root differently and then uses search to find it
e28c09
+         again. If the search module is not built in, when we change root, grub
e28c09
+         will look in (new root)/path/powerpc-ieee1275, that won't work, and we
e28c09
+         will not be able to load the search module and the boot will fail.
e28c09
+
e28c09
+         This is particularly likely to hit us in the grub-install
e28c09
+         (,msdos2)/grub2 case, so we act unless the supplied prefix starts with
e28c09
+         '(', which would likely indicate a partition has already been
e28c09
+         specified.
e28c09
        */
e28c09
-      if (grub_strchr (device, ',') == NULL)
e28c09
+      if (prefix && prefix[0] != '(')
e28c09
         grub_env_set ("prefix", path);
e28c09
       else
e28c09
 #endif