fd0330
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
fd0330
From: Robbie Harwood <rharwood@redhat.com>
fd0330
Date: Wed, 25 Jan 2023 16:10:58 -0500
fd0330
Subject: [PATCH] ppc64le: signed boot media changes
fd0330
fd0330
Skip mdraid < 1.1 on isos since mdraid* can't even
fd0330
fd0330
Prior to this change, on ppc64le with part_msdos and the mdraid* modules
fd0330
enabled, we see:
fd0330
fd0330
    disk/diskfilter.c:191: scanning ieee1275/cdrom
fd0330
    kern/disk.c:196: Opening `ieee1275/cdrom'...
fd0330
    disk/ieee1275/ofdisk.c:477: Opening `cdrom'.
fd0330
    disk/ieee1275/ofdisk.c:502: MAX_RETRIES set to 20
fd0330
    kern/disk.c:288: Opening `ieee1275/cdrom' succeeded.
fd0330
    disk/diskfilter.c:136: Scanning for DISKFILTER devices on disk ieee1275/cdrom
fd0330
    partmap/msdos.c:184: partition 0: flag 0x80, type 0x96, start 0x0, len
fd0330
    0x6a5d70
fd0330
    disk/diskfilter.c:136: Scanning for DISKFILTER devices on disk ieee1275/cdrom
fd0330
    SCSI-DISK: Access beyond end of device !
fd0330
    SCSI-DISK: Access beyond end of device !
fd0330
    SCSI-DISK: Access beyond end of device !
fd0330
    SCSI-DISK: Access beyond end of device !
fd0330
    SCSI-DISK: Access beyond end of device !
fd0330
    disk/ieee1275/ofdisk.c:578: MAX_RETRIES set to 20
fd0330
fd0330
These latter two lines repeat many times, eventually ending in:
fd0330
fd0330
    kern/disk.c:388: ieee1275/cdrom read failed
fd0330
    error: ../../grub-core/disk/ieee1275/ofdisk.c:608:failure reading sector
fd0330
    0x1a9720 from `ieee1275/cdrom'.
fd0330
fd0330
and the system drops to a "grub>" prompt.
fd0330
fd0330
Prior to 1.1, mdraid stored the superblock offset from the end of the
fd0330
disk, and the firmware really doesn't like reads there.  Best guess was
fd0330
that the firmware and the iso image appear to diagree on the blocksize
fd0330
(512 vs. 2048), and the diskfilter RAID probing is too much for it.
fd0330
It's tempting to just skip probing for cdroms, but unfortunately isos
fd0330
can be virtualized elsewhere - such as regular disks.
fd0330
fd0330
Also fix detection of root, and try the chrp path as a fallback if the
fd0330
built prefix doesn't work.
fd0330
fd0330
Signed-off-by: Robbie Harwood <rharwood@redhat.com>
fd0330
fd0330
wip
fd0330
---
fd0330
 grub-core/disk/mdraid1x_linux.c  | 8 +++++++-
fd0330
 grub-core/disk/mdraid_linux.c    | 5 +++++
fd0330
 grub-core/kern/ieee1275/openfw.c | 2 +-
fd0330
 grub-core/normal/main.c          | 5 +++++
fd0330
 4 files changed, 18 insertions(+), 2 deletions(-)
fd0330
fd0330
diff --git a/grub-core/disk/mdraid1x_linux.c b/grub-core/disk/mdraid1x_linux.c
fd0330
index 38444b02c7..08c57ae16e 100644
fd0330
--- a/grub-core/disk/mdraid1x_linux.c
fd0330
+++ b/grub-core/disk/mdraid1x_linux.c
fd0330
@@ -129,7 +129,13 @@ grub_mdraid_detect (grub_disk_t disk,
fd0330
       grub_uint32_t level;
fd0330
       struct grub_diskfilter_vg *array;
fd0330
       char *uuid;
fd0330
-	
fd0330
+
fd0330
+#ifdef __powerpc__
fd0330
+      /* Firmware will yell at us for reading too far. */
fd0330
+      if (minor_version == 0)
fd0330
+        continue;
fd0330
+#endif
fd0330
+
fd0330
       if (size == GRUB_DISK_SIZE_UNKNOWN && minor_version == 0)
fd0330
 	continue;
fd0330
 	
fd0330
diff --git a/grub-core/disk/mdraid_linux.c b/grub-core/disk/mdraid_linux.c
fd0330
index e40216f511..98fcfb1be6 100644
fd0330
--- a/grub-core/disk/mdraid_linux.c
fd0330
+++ b/grub-core/disk/mdraid_linux.c
fd0330
@@ -189,6 +189,11 @@ grub_mdraid_detect (grub_disk_t disk,
fd0330
   grub_uint32_t level;
fd0330
   struct grub_diskfilter_vg *ret;
fd0330
 
fd0330
+#ifdef __powerpc__
fd0330
+  /* Firmware will yell at us for reading too far. */
fd0330
+  return NULL;
fd0330
+#endif
fd0330
+
fd0330
   /* The sector where the mdraid 0.90 superblock is stored, if available.  */
fd0330
   size = grub_disk_native_sectors (disk);
fd0330
   if (size == GRUB_DISK_SIZE_UNKNOWN)
fd0330
diff --git a/grub-core/kern/ieee1275/openfw.c b/grub-core/kern/ieee1275/openfw.c
fd0330
index 3a6689abb1..0278054c61 100644
fd0330
--- a/grub-core/kern/ieee1275/openfw.c
fd0330
+++ b/grub-core/kern/ieee1275/openfw.c
fd0330
@@ -499,7 +499,7 @@ grub_ieee1275_encode_devname (const char *path)
fd0330
 	*optr++ ='\\';
fd0330
       *optr++ = *iptr++;
fd0330
     }
fd0330
-  if (partition && partition[0])
fd0330
+  if (partition && partition[0] >= '0' && partition[0] <= '9')
fd0330
     {
fd0330
       unsigned int partno = grub_strtoul (partition, 0, 0);
fd0330
 
fd0330
diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c
fd0330
index 8f5fd81003..d59145f861 100644
fd0330
--- a/grub-core/normal/main.c
fd0330
+++ b/grub-core/normal/main.c
fd0330
@@ -372,6 +372,7 @@ grub_try_normal_prefix (const char *prefix)
fd0330
            file = grub_file_open (config, GRUB_FILE_TYPE_CONFIG);
fd0330
            if (file)
fd0330
              {
fd0330
+               grub_env_set ("prefix", prefix);
fd0330
                grub_file_close (file);
fd0330
                err = GRUB_ERR_NONE;
fd0330
              }
fd0330
@@ -447,6 +448,10 @@ grub_cmd_normal (struct grub_command *cmd __attribute__ ((unused)),
fd0330
       err = grub_try_normal ("fw_path");
fd0330
       if (err == GRUB_ERR_FILE_NOT_FOUND)
fd0330
         err = grub_try_normal ("prefix");
fd0330
+#ifdef __powerpc__
fd0330
+      if (err == GRUB_ERR_FILE_NOT_FOUND)
fd0330
+        err = grub_try_normal_prefix ("/boot/grub");
fd0330
+#endif
fd0330
       if (err == GRUB_ERR_FILE_NOT_FOUND)
fd0330
         err = grub_try_normal_discover ();
fd0330
       if (err == GRUB_ERR_FILE_NOT_FOUND)