nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

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

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