nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

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

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