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