Skip to contentSkip to conversation

Add missing SPARC support

PATCH In review Eric Snowberg 4 participants 23 messages Jun 29, 2016 – May 11, 2017

lore
Share & tools
lore
#0 lore raw

cover Add missing SPARC support

First set of patches to add sun4v SPARC support to grub.

Major additions include:

* Properly scan for both SAS and SCSI disks
* Increasing boot performance
* GPT support
* NVMe support
* Various bug fixes

Before this patch, there isn’t a single SAS HBA that was enumerated correctly on SPARC. I went back 10 years and believe I have added every HBA with OF support.

Without these patches, on larger systems, it took 15+ minutes to get to the grub menu. Now it takes about a second.

This code has been tested on T1, T2, T4, T5, and T7 hardware.

Eric Snowberg (15):
sparc64: fix OF path names for sun4v systems
sparc64: Add blocklist GPT support for SPARC
grub-install: fix memory leak
sparc64: Use the correct disk name in core.img
ieee1275: fix segfault in grub-ofpathname
ieee1275: add nvme support within ofpath
ofdisk: memory corruption fix
ofdisk: move open logic
ieee1275: ofdisk - don't continue to query block-size after we have
it
ofdisk: refactor open logic
sparc64: boot performance improvements
ofdisk: only add aliases that exist
sparc64: add disks that don't have a devalias to the device list
parser: Remove escape from the state transitions
sparc64: ignore hypervisor reboot memory block device

 grub-core/disk/ieee1275/ofdisk.c           |  499 +++++++++++++++++++++++++---
 grub-core/kern/ieee1275/cmain.c            |    8 +
 grub-core/kern/ieee1275/ieee1275.c         |   88 +++++
 grub-core/kern/parser.c                    |    1 -
 grub-core/kern/sparc64/ieee1275/ieee1275.c |  111 ++++++
 grub-core/osdep/linux/blocklist.c          |    5 +
 grub-core/osdep/linux/ofpath.c             |  208 ++++++++++++-
 include/grub/emu/getroot.h                 |    2 +
 include/grub/ieee1275/ieee1275.h           |   13 +
 include/grub/sparc64/ieee1275/ieee1275.h   |    4 +
 util/grub-install.c                        |   14 +
 util/ieee1275/grub-ofpathname.c            |    4 +-
 util/probe.c                               |    2 +-
 util/setup.c                               |   12 +-
 14 files changed, 910 insertions(+), 61 deletions(-)
#1 lore raw

PATCH 1/15 sparc64: fix OF path names for sun4v systems

Fix the Open Firmware (OF) path property for sun4v SPARC systems. These platforms do not have a /sas/ within their path. Over time different OF addressing schemes have been supported. There is no generic addressing scheme that works across every HBA.

---
 grub-core/osdep/linux/ofpath.c |  162 +++++++++++++++++++++++++++++++++++++++-
 1 files changed, 160 insertions(+), 2 deletions(-)
grub-core/osdep/linux/ofpath.c +160 -2
index a79682a..0994e08 100644
@@ -38,6 +38,42 @@
 #include <errno.h>
 #include <ctype.h>
 
+typedef enum
+  {
+    GRUB_OFPATH_SPARC_PHY_ADDR = 1,
+    GRUB_OFPATH_SPARC_TGT_LUN,
+  } ofpath_sparc_addressing;
+
+struct ofpath_sparc_hba
+{
+  grub_uint32_t device_id;
+  ofpath_sparc_addressing addressing;
+};
+
+static struct ofpath_sparc_hba sparc_lsi_hba[] = {
+  /* Rhea, Jasper 320, LSI53C1020/1030 */
+  {0x30, GRUB_OFPATH_SPARC_TGT_LUN},
+  /* SAS-1068E */
+  {0x50, GRUB_OFPATH_SPARC_TGT_LUN},
+  /* SAS-1064E */
+  {0x56, GRUB_OFPATH_SPARC_TGT_LUN},
+  /* Pandora SAS-1068E */
+  {0x58, GRUB_OFPATH_SPARC_TGT_LUN},
+  /* Aspen, Invader, LSI SAS-3108 */
+  {0x5d, GRUB_OFPATH_SPARC_TGT_LUN},
+  /* Niwot, SAS 2108 */
+  {0x79, GRUB_OFPATH_SPARC_TGT_LUN},
+  /* Erie, Falcon, LSI SAS 2008 */
+  {0x72, GRUB_OFPATH_SPARC_PHY_ADDR},
+  /* LSI WarpDrive 6203 */
+  {0x7e, GRUB_OFPATH_SPARC_PHY_ADDR},
+  /* LSI SAS 2308 */
+  {0x87, GRUB_OFPATH_SPARC_PHY_ADDR},
+  /* LSI SAS 3008 */
+  {0x97, GRUB_OFPATH_SPARC_PHY_ADDR},
+  {0, 0}
+};
+
 #ifdef OFPATH_STANDALONE
 #define xmalloc malloc
 void
@@ -336,6 +372,85 @@ vendor_is_ATA(const char *path)
 }
 
 static void
+check_hba_identifiers(const char *sysfs_path, int *vendor, int *device_id)
+{
+  char *ed = strstr (sysfs_path, "host");
+  size_t path_size;
+  char *p = NULL, *path = NULL;
+  char buf[8];
+  int fd;
+
+  if (!ed)
+    return;
+
+  p = xstrdup (sysfs_path);
+  ed = strstr (p, "host");
+
+  if (!ed)
+    {
+      free (p);
+      return;
+    }
+  *ed = '\0';
+
+  path_size = (strlen (p) + sizeof("vendor"));
+  path = xmalloc (path_size);
+
+  if (!path)
+    {
+      free (p);
+      return;
+    }
+
+  snprintf (path, path_size, "%svendor", p);
+  fd = open (path, O_RDONLY);
+
+  if (fd < 0)
+    {
+      free (p);
+      free (path);
+      return;
+    }
+
+  memset (buf, 0, sizeof (buf));
+
+  if (read (fd, buf, sizeof (buf) - 1) < 0)
+    {
+      close (fd);
+      free (p);
+      free (path);
+      return;
+    }
+
+  close (fd);
+  sscanf (buf, "%x", vendor);
+  snprintf (path, path_size, "%sdevice", p);
+  fd = open (path, O_RDONLY);
+
+  if (fd < 0)
+    {
+      free (p);
+      free (path);
+      return;
+    }
+
+  memset (buf, 0, sizeof (buf));
+
+  if (read (fd, buf, sizeof (buf) - 1) < 0)
+    {
+      close (fd);
+      free (p);
+      free (path);
+      return;
+    }
+
+  close (fd);
+  sscanf (buf, "%x", device_id);
+  free (path);
+  free (p);
+}
+
+static void
 check_sas (const char *sysfs_path, int *tgt, unsigned long int *sas_address)
 {
   char *ed = strstr (sysfs_path, "end_device");
@@ -413,9 +528,11 @@ of_path_of_scsi(const char *sys_devname __attribute__((unused)), const char *dev
     }
 
   of_path = find_obppath(sysfs_path);
-  free (sysfs_path);
   if (!of_path)
-    return NULL;
+    {
+      free (sysfs_path);
+      return NULL;
+    }
 
   if (strstr (of_path, "qlc"))
     strcat (of_path, "/fp@0,0");
@@ -444,6 +561,45 @@ of_path_of_scsi(const char *sys_devname __attribute__((unused)), const char *dev
     }
   else
     {
+#ifdef __sparc__
+      ofpath_sparc_addressing addressing = GRUB_OFPATH_SPARC_TGT_LUN;
+      int vendor = 0, device_id = 0;
+      char *optr = disk;
+
+      check_hba_identifiers (sysfs_path, &vendor, &device_id);
+
+      /* Over time different OF addressing schemes have been supported */
+      /* There is no generic addressing scheme that works across */
+      /* every HBA */
+      if (vendor == 0x1000) /* LSI Logic Vendor ID */
+        {
+          struct ofpath_sparc_hba *lsi_hba;
+
+          for (lsi_hba = sparc_lsi_hba; lsi_hba->device_id; lsi_hba++)
+            if (lsi_hba->device_id == device_id)
+              {
+                addressing = lsi_hba->addressing;
+                break;
+              }
+        }
+
+      if (addressing == GRUB_OFPATH_SPARC_PHY_ADDR)
+        optr += snprintf (disk, sizeof (disk), "/%s@p%x", disk_name, tgt);
+      else
+        optr += snprintf (disk, sizeof (disk), "/%s@%x", disk_name, tgt);
+
+      if (lun)
+        optr += snprintf (optr, sizeof (disk) - (optr - disk - 1), ",%x", lun);
+
+      if (*digit_string != '\0')
+        {
+          int part;
+
+          sscanf (digit_string, "%d", &part);
+          snprintf (optr, sizeof (disk) - (optr - disk - 1), ":%c", 'a'
+                    + (part - 1));
+        }
+#else
       if (lun == 0)
         {
           int sas_id = 0;
@@ -491,7 +647,9 @@ of_path_of_scsi(const char *sys_devname __attribute__((unused)), const char *dev
             }
 	  free (lunstr);
         }
+#endif
     }
+  free (sysfs_path);
   strcat(of_path, disk);
   return of_path;
 }
Signature · 1 line
1.7.1
#2 lore raw

PATCH 2/15 sparc64: Add blocklist GPT support for SPARC

In reply to Eric Snowberg

Add block-list GPT support for SPARC. The OBP "load" and "boot" methods are partition aware and neither command can see the partition table. Also neither command can address the entire physical disk. When the install happens, grub generates the block-list entries based on the beginning of the physical disk, not the beginning of the parition. This patch fixes the block-list entries so they match what OBP expects during boot for a GPT disk.

T5 and above now supports GPT as well as VTOC.

This patch has been tested on T5-2 and newer SPARC systems.

---
 grub-core/osdep/linux/blocklist.c |    5 +++++
 util/setup.c                      |   12 +++++++++---
 2 files changed, 14 insertions(+), 3 deletions(-)
grub-core/osdep/linux/blocklist.c +5 -0
index c77d608..caf8d4e 100644
@@ -58,6 +58,11 @@ grub_install_get_blocklist (grub_device_t root_dev,
   struct fiemap fie1;
   int fd;
 
+#ifdef __sparc__
+  if (grub_strstr (container->partmap->name, "gpt"))
+    container_start = 0;
+#endif
+
   /* Write the first two sectors of the core image onto the disk.  */
   grub_util_info ("opening the core image `%s'", core_path);
   fd = open (core_path, O_RDONLY);
util/setup.c +9 -3
index 8aa5a39..5908498 100644
@@ -721,15 +721,21 @@ unable_to_embed:
   {
     char *buf, *ptr = core_img;
     size_t len = core_size;
-    grub_uint64_t blk;
+    grub_uint64_t blk, offset = 0;
     grub_partition_t container = core_dev->disk->partition;
     grub_err_t err;
 
     core_dev->disk->partition = 0;
+#ifdef GRUB_SETUP_SPARC64
+    {
+      if (grub_strstr (container->partmap->name, "gpt"))
+        offset = grub_partition_get_start (container);
+    }
+#endif
 
     buf = xmalloc (core_size);
     blk = bl.first_sector;
-    err = grub_disk_read (core_dev->disk, blk, 0, GRUB_DISK_SECTOR_SIZE, buf);
+    err = grub_disk_read (core_dev->disk, blk + offset, 0, GRUB_DISK_SECTOR_SIZE, buf);
     if (err)
       grub_util_error (_("cannot read `%s': %s"), core_dev->disk->name,
 		       grub_errmsg);
@@ -748,7 +754,7 @@ unable_to_embed:
 	if (cur > len)
 	  cur = len;
 
-	err = grub_disk_read (core_dev->disk, blk, 0, cur, buf);
+	err = grub_disk_read (core_dev->disk, blk + offset, 0, cur, buf);
 	if (err)
 	  grub_util_error (_("cannot read `%s': %s"), core_dev->disk->name,
 			   grub_errmsg);
Signature · 1 line
1.7.1
#3 lore raw

Re: [PATCH 02/15] sparc64: Add blocklist GPT support for SPARC

Quoted 25 lines · On Wed, Jun 29, 2016, 23:47 Eric Snowberg <[email protected]> wrote:

Add block-list GPT support for SPARC. The OBP "load" and "boot" methods are partition aware and neither command can see the partition table. Also neither command can address the entire physical disk. When the install happens,
grub generates the block-list entries based on the beginning of the physical
disk, not the beginning of the parition. This patch fixes the block-list entries so they match what OBP expects during boot for a GPT disk.

T5 and above now supports GPT as well as VTOC.

This patch has been tested on T5-2 and newer SPARC systems.

---
 grub-core/osdep/linux/blocklist.c |    5 +++++
 util/setup.c                      |   12 +++++++++---
 2 files changed, 14 insertions(+), 3 deletions(-)
grub-core/osdep/linux/blocklist.c +0 -0
index c77d608..caf8d4e 100644

grub-core/osdep/linux/blocklist.c grub_install_get_blocklist (grub_device_t root_dev, · line 66

Quoted 9 lines
grub-core/osdep/linux/blocklist.c +5 -0
@@ -58,6 +58,11 @@ grub_install_get_blocklist (grub_device_t root_dev,
   struct fiemap fie1;
   int fd;
 
+#ifdef __sparc__
+  if (grub_strstr (container->partmap->name, "gpt"))
+    container_start = 0;
+#endif
+
 

This makes ifdef conditional on platform of the tool, not of the binaries and they can be different. Also there are several implementations of blocklist retrieving for different platform. This condition needs to be detected and adjusted for in the caller (setup)

Quoted 51 lines
grub-core/osdep/linux/blocklist.c +0 -0
   /* Write the first two sectors of the core image onto the disk.  */
   grub_util_info ("opening the core image `%s'", core_path);
   fd = open (core_path, O_RDONLY);
util/setup.c +8 -2
index 8aa5a39..5908498 100644
@@ -721,15 +721,21 @@ unable_to_embed:
   {
     char *buf, *ptr = core_img;
     size_t len = core_size;
-    grub_uint64_t blk;
+    grub_uint64_t blk, offset = 0;
     grub_partition_t container = core_dev->disk->partition;
     grub_err_t err;
 
     core_dev->disk->partition = 0;
+#ifdef GRUB_SETUP_SPARC64
+    {
+      if (grub_strstr (container->partmap->name, "gpt"))
+        offset = grub_partition_get_start (container);
+    }
+#endif
 
     buf = xmalloc (core_size);
     blk = bl.first_sector;
-    err = grub_disk_read (core_dev->disk, blk, 0, GRUB_DISK_SECTOR_SIZE,
 buf);
+    err = grub_disk_read (core_dev->disk, blk + offset, 0,
 GRUB_DISK_SECTOR_SIZE, buf);
     if (err)
       grub_util_error (_("cannot read `%s': %s"), core_dev->disk->name,
                       grub_errmsg);
util/setup.c +1 -2
@@ -748,7 +754,7 @@ unable_to_embed:
        if (cur > len)
          cur = len;
 
-       err = grub_disk_read (core_dev->disk, blk, 0, cur, buf);
+       err = grub_disk_read (core_dev->disk, blk + offset, 0, cur, buf);
        if (err)
          grub_util_error (_("cannot read `%s': %s"), core_dev->disk->name,
                           grub_errmsg);
--

1.7.1

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#4 lore raw

Re: [PATCH 02/15] sparc64: Add blocklist GPT support for SPARC

Quoted 36 lines · Vladimir 'phcoder' Serbinenko

On Wed, Jun 29, 2016, 23:47 Eric Snowberg <[email protected]> wrote:
Add block-list GPT support for SPARC. The OBP "load" and "boot" methods are partition aware and neither command can see the partition table. Also neither command can address the entire physical disk. When the install happens, grub generates the block-list entries based on the beginning of the physical disk, not the beginning of the parition. This patch fixes the block-list entries so they match what OBP expects during boot for a GPT disk.

T5 and above now supports GPT as well as VTOC.

This patch has been tested on T5-2 and newer SPARC systems.

---
 grub-core/osdep/linux/blocklist.c |    5 +++++
 util/setup.c                      |   12 +++++++++---
 2 files changed, 14 insertions(+), 3 deletions(-)
grub-core/osdep/linux/blocklist.c +5 -0
index c77d608..caf8d4e 100644
@@ -58,6 +58,11 @@ grub_install_get_blocklist (grub_device_t root_dev,
   struct fiemap fie1;
   int fd;
 
+#ifdef __sparc__
+  if (grub_strstr (container->partmap->name, "gpt"))
+    container_start = 0;
+#endif
+
Quoted 1 line

This makes ifdef conditional on platform of the tool, not of the binaries and they can be different.

Exactly, they are different, that is why the ifdef was added for SPARC. The tool was putting the wrong value into the binary.

Quoted 1 line

Also there are several implementations of blocklist retrieving for different platform. This condition needs to be detected and adjusted for in the caller (setup)

How do you recommend I adjusted it in the setup when container_start is obtained from grub_partition_get_start?

Quoted 52 lines
   /* Write the first two sectors of the core image onto the disk.  */
   grub_util_info ("opening the core image `%s'", core_path);
   fd = open (core_path, O_RDONLY);
util/setup.c +9 -4
index 8aa5a39..5908498 100644
@@ -721,15 +721,21 @@ unable_to_embed:
   {
     char *buf, *ptr = core_img;
     size_t len = core_size;
-    grub_uint64_t blk;
+    grub_uint64_t blk, offset = 0;
     grub_partition_t container = core_dev->disk->partition;
     grub_err_t err;
 
     core_dev->disk->partition = 0;
+#ifdef GRUB_SETUP_SPARC64
+    {
+      if (grub_strstr (container->partmap->name, "gpt"))
+        offset = grub_partition_get_start (container);
+    }
+#endif
 
     buf = xmalloc (core_size);
     blk = bl.first_sector;
-    err = grub_disk_read (core_dev->disk, blk, 0, GRUB_DISK_SECTOR_SIZE, buf);
+    err = grub_disk_read (core_dev->disk, blk + offset, 0, GRUB_DISK_SECTOR_SIZE, buf);
     if (err)
       grub_util_error (_("cannot read `%s': %s"), core_dev->disk->name,
                       grub_errmsg);
@@ -748,7 +754,7 @@ unable_to_embed:
        if (cur > len)
          cur = len;
 
-       err = grub_disk_read (core_dev->disk, blk, 0, cur, buf);
+       err = grub_disk_read (core_dev->disk, blk + offset, 0, cur, buf);
        if (err)
          grub_util_error (_("cannot read `%s': %s"), core_dev->disk->name,
                           grub_errmsg);
--

1.7.1

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#5 lore raw

Re: [PATCH 02/15] sparc64: Add blocklist GPT support for SPARC

Quoted 44 lines · On Thu, May 11, 2017, 01:21 Eric Snowberg <[email protected]> wrote:
Quoted 2 lines

On May 10, 2017, at 4:42 PM, Vladimir 'phcoder' Serbinenko <

Quoted 4 lines · [email protected]> wrote:

On Wed, Jun 29, 2016, 23:47 Eric Snowberg <[email protected]>

Quoted 3 lines · wrote:

Add block-list GPT support for SPARC. The OBP "load" and "boot" methods are partition aware and neither command can see the partition table. Also neither command can address the entire physical disk. When the install

happens,

Quoted 1 line

grub generates the block-list entries based on the beginning of the

physical

Quoted 7 lines

disk, not the beginning of the parition. This patch fixes the block-list entries so they match what OBP expects during boot for a GPT disk.

T5 and above now supports GPT as well as VTOC.

This patch has been tested on T5-2 and newer SPARC systems.

Review

Quoted 7 lines
---
 grub-core/osdep/linux/blocklist.c |    5 +++++
 util/setup.c                      |   12 +++++++++---
 2 files changed, 14 insertions(+), 3 deletions(-)
(quoted diff) +0 -0

b/grub-core/osdep/linux/blocklist.c

Quoted 12 lines

index c77d608..caf8d4e 100644

grub-core/osdep/linux/blocklist.c +5 -0
@@ -58,6 +58,11 @@ grub_install_get_blocklist (grub_device_t root_dev,
   struct fiemap fie1;
   int fd;
 
+#ifdef __sparc__
+  if (grub_strstr (container->partmap->name, "gpt"))
+    container_start = 0;
+#endif
+
Quoted 1 line

This makes ifdef conditional on platform of the tool, not of the

binaries and they can be different.

Quoted 3 lines

Exactly, they are different, that is why the ifdef was added for SPARC. The tool was putting the wrong value into the binary.

No. What I mean is that someone with x86 cpu fan prepare a disk for sparc64. He would compile tools for x86 and binaries for sparc64. With your code tool will end up with wrong offsets.

Quoted 8 lines
Quoted 2 lines

Also there are several implementations of blocklist retrieving for

different platform. This condition needs to be detected and adjusted for in the caller (setup)

How do you recommend I adjusted it in the setup when container_start is obtained from grub_partition_get_start?

Just subtract partition offset in save_blocklists or its caller

Quoted 64 lines
Quoted 19 lines

   /* Write the first two sectors of the core image onto the disk.  */
   grub_util_info ("opening the core image `%s'", core_path);
   fd = open (core_path, O_RDONLY);
util/setup.c +1 -1
index 8aa5a39..5908498 100644
@@ -721,15 +721,21 @@ unable_to_embed:
   {
     char *buf, *ptr = core_img;
     size_t len = core_size;
-    grub_uint64_t blk;
+    grub_uint64_t blk, offset = 0;
     grub_partition_t container = core_dev->disk->partition;
     grub_err_t err;
 
     core_dev->disk->partition = 0;

util/setup.c unable_to_embed: · line 732

Quoted 10 lines
util/setup.c +6 -1
+#ifdef GRUB_SETUP_SPARC64
+    {
+      if (grub_strstr (container->partmap->name, "gpt"))
+        offset = grub_partition_get_start (container);
+    }
+#endif
 
     buf = xmalloc (core_size);
     blk = bl.first_sector;
-    err = grub_disk_read (core_dev->disk, blk, 0,

GRUB_DISK_SECTOR_SIZE, buf);

util/setup.c unable_to_embed: · line 738

Quoted 1 line
util/setup.c +1 -0
+    err = grub_disk_read (core_dev->disk, blk + offset, 0,

GRUB_DISK_SECTOR_SIZE, buf);

util/setup.c unable_to_embed: · line 759

Quoted 11 lines
util/setup.c +1 -1
     if (err)
       grub_util_error (_("cannot read `%s': %s"), core_dev->disk->name,
                       grub_errmsg);
@@ -748,7 +754,7 @@ unable_to_embed:
        if (cur > len)
          cur = len;
 
-       err = grub_disk_read (core_dev->disk, blk, 0, cur, buf);
+       err = grub_disk_read (core_dev->disk, blk + offset, 0, cur, buf);
        if (err)
          grub_util_error (_("cannot read `%s': %s"),

core_dev->disk->name,

Quoted 5 lines
util/setup.c +0 -1
                           grub_errmsg);
--

1.7.1

Quoted 8 lines

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#6 lore raw

Re: [PATCH 02/15] sparc64: Add blocklist GPT support for SPARC

Quoted 58 lines · On Thu, May 11, 2017, 02:37 Vladimir 'phcoder' Serbinenko <[email protected]>…
Quoted 45 lines · On Thu, May 11, 2017, 01:21 Eric Snowberg <[email protected]> wrote:
Quoted 2 lines

On May 10, 2017, at 4:42 PM, Vladimir 'phcoder' Serbinenko <

Quoted 4 lines · [email protected]> wrote:

On Wed, Jun 29, 2016, 23:47 Eric Snowberg <[email protected]>

Quoted 2 lines · wrote:

Add block-list GPT support for SPARC. The OBP "load" and "boot" methods are partition aware and neither command can see the partition table.

Also

Quoted 1 line

neither command can address the entire physical disk. When the install

happens,

Quoted 1 line

grub generates the block-list entries based on the beginning of the

physical

Quoted 7 lines

disk, not the beginning of the parition. This patch fixes the block-list entries so they match what OBP expects during boot for a GPT disk.

T5 and above now supports GPT as well as VTOC.

This patch has been tested on T5-2 and newer SPARC systems.

Review

Quoted 7 lines
---
 grub-core/osdep/linux/blocklist.c |    5 +++++
 util/setup.c                      |   12 +++++++++---
 2 files changed, 14 insertions(+), 3 deletions(-)
(quoted diff) +0 -0

b/grub-core/osdep/linux/blocklist.c

Quoted 12 lines

index c77d608..caf8d4e 100644

grub-core/osdep/linux/blocklist.c +5 -0
@@ -58,6 +58,11 @@ grub_install_get_blocklist (grub_device_t root_dev,
   struct fiemap fie1;
   int fd;
 
+#ifdef __sparc__
+  if (grub_strstr (container->partmap->name, "gpt"))
+    container_start = 0;
+#endif
+
Quoted 1 line

This makes ifdef conditional on platform of the tool, not of the

binaries and they can be different.

Quoted 3 lines

Exactly, they are different, that is why the ifdef was added for SPARC. The tool was putting the wrong value into the binary.

No. What I mean is that someone with x86 cpu fan prepare a disk for sparc64. He would compile tools for x86 and binaries for sparc64. With your code tool will end up with wrong offsets.

Quoted 1 line
Quoted 9 lines
Quoted 7 lines
Quoted 1 line

Also there are several implementations of blocklist retrieving for

different platform. This condition needs to be detected and adjusted for in the caller (setup)

How do you recommend I adjusted it in the setup when container_start is obtained from grub_partition_get_start?

Just subtract partition offset in save_blocklists or its caller

Sorry, I meant *not* its caller

Quoted 66 lines
Quoted 65 lines
Quoted 19 lines

   /* Write the first two sectors of the core image onto the disk.  */
   grub_util_info ("opening the core image `%s'", core_path);
   fd = open (core_path, O_RDONLY);
util/setup.c +1 -1
index 8aa5a39..5908498 100644
@@ -721,15 +721,21 @@ unable_to_embed:
   {
     char *buf, *ptr = core_img;
     size_t len = core_size;
-    grub_uint64_t blk;
+    grub_uint64_t blk, offset = 0;
     grub_partition_t container = core_dev->disk->partition;
     grub_err_t err;
 
     core_dev->disk->partition = 0;

util/setup.c unable_to_embed: · line 732

Quoted 10 lines
util/setup.c +6 -1
+#ifdef GRUB_SETUP_SPARC64
+    {
+      if (grub_strstr (container->partmap->name, "gpt"))
+        offset = grub_partition_get_start (container);
+    }
+#endif
 
     buf = xmalloc (core_size);
     blk = bl.first_sector;
-    err = grub_disk_read (core_dev->disk, blk, 0,

GRUB_DISK_SECTOR_SIZE, buf);

util/setup.c unable_to_embed: · line 738

Quoted 1 line
util/setup.c +1 -0
+    err = grub_disk_read (core_dev->disk, blk + offset, 0,

GRUB_DISK_SECTOR_SIZE, buf);

util/setup.c unable_to_embed: · line 757

Quoted 9 lines
util/setup.c +1 -1
     if (err)
       grub_util_error (_("cannot read `%s': %s"), core_dev->disk->name,
                       grub_errmsg);
@@ -748,7 +754,7 @@ unable_to_embed:
        if (cur > len)
          cur = len;
 
-       err = grub_disk_read (core_dev->disk, blk, 0, cur, buf);
+       err = grub_disk_read (core_dev->disk, blk + offset, 0, cur,

buf);

util/setup.c unable_to_embed: · line 759

Quoted 2 lines
util/setup.c +0 -0
        if (err)
          grub_util_error (_("cannot read `%s': %s"),

core_dev->disk->name,

Quoted 5 lines
util/setup.c +0 -1
                           grub_errmsg);
--

1.7.1

Quoted 8 lines

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#7 lore raw

Re: [PATCH 02/15] sparc64: Add blocklist GPT support for SPARC

Quoted 50 lines · Vladimir 'phcoder' Serbinenko

On Thu, May 11, 2017, 02:37 Vladimir 'phcoder' Serbinenko <[email protected]> wrote:

Quoted 35 lines · On Thu, May 11, 2017, 01:21 Eric Snowberg <[email protected]> wrote:

On May 10, 2017, at 4:42 PM, Vladimir 'phcoder' Serbinenko <[email protected]> wrote:

On Wed, Jun 29, 2016, 23:47 Eric Snowberg <[email protected]> wrote:
Add block-list GPT support for SPARC. The OBP "load" and "boot" methods are partition aware and neither command can see the partition table. Also neither command can address the entire physical disk. When the install happens, grub generates the block-list entries based on the beginning of the physical disk, not the beginning of the parition. This patch fixes the block-list entries so they match what OBP expects during boot for a GPT disk.

T5 and above now supports GPT as well as VTOC.

This patch has been tested on T5-2 and newer SPARC systems.

---
 grub-core/osdep/linux/blocklist.c |    5 +++++
 util/setup.c                      |   12 +++++++++---
 2 files changed, 14 insertions(+), 3 deletions(-)
grub-core/osdep/linux/blocklist.c +5 -0
index c77d608..caf8d4e 100644
@@ -58,6 +58,11 @@ grub_install_get_blocklist (grub_device_t root_dev,
   struct fiemap fie1;
   int fd;
 
+#ifdef __sparc__
+  if (grub_strstr (container->partmap->name, "gpt"))
+    container_start = 0;
+#endif
+
Quoted 1 line

This makes ifdef conditional on platform of the tool, not of the binaries and they can be different.

Exactly, they are different, that is why the ifdef was added for SPARC. The tool was putting the wrong value into the binary.
No. What I mean is that someone with x86 cpu fan prepare a disk for sparc64. He would compile tools for x86 and binaries for sparc64. With your code tool will end up with wrong offsets.

Quoted 5 lines
Quoted 1 line

Also there are several implementations of blocklist retrieving for different platform. This condition needs to be detected and adjusted for in the caller (setup)

How do you recommend I adjusted it in the setup when container_start is obtained from grub_partition_get_start? Just subtract partition offset in save_blocklists or its caller
Sorry, I meant *not* its caller

Ok, I’ll make that change and send an updated patch.

Quoted 64 lines
Quoted 46 lines

   /* Write the first two sectors of the core image onto the disk.  */
   grub_util_info ("opening the core image `%s'", core_path);
   fd = open (core_path, O_RDONLY);
util/setup.c +9 -4
index 8aa5a39..5908498 100644
@@ -721,15 +721,21 @@ unable_to_embed:
   {
     char *buf, *ptr = core_img;
     size_t len = core_size;
-    grub_uint64_t blk;
+    grub_uint64_t blk, offset = 0;
     grub_partition_t container = core_dev->disk->partition;
     grub_err_t err;
 
     core_dev->disk->partition = 0;
+#ifdef GRUB_SETUP_SPARC64
+    {
+      if (grub_strstr (container->partmap->name, "gpt"))
+        offset = grub_partition_get_start (container);
+    }
+#endif
 
     buf = xmalloc (core_size);
     blk = bl.first_sector;
-    err = grub_disk_read (core_dev->disk, blk, 0, GRUB_DISK_SECTOR_SIZE, buf);
+    err = grub_disk_read (core_dev->disk, blk + offset, 0, GRUB_DISK_SECTOR_SIZE, buf);
     if (err)
       grub_util_error (_("cannot read `%s': %s"), core_dev->disk->name,
                       grub_errmsg);
@@ -748,7 +754,7 @@ unable_to_embed:
        if (cur > len)
          cur = len;
 
-       err = grub_disk_read (core_dev->disk, blk, 0, cur, buf);
+       err = grub_disk_read (core_dev->disk, blk + offset, 0, cur, buf);
        if (err)
          grub_util_error (_("cannot read `%s': %s"), core_dev->disk->name,
                           grub_errmsg);
--

1.7.1

Quoted 8 lines

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#8 lore raw

PATCH 3/15 grub-install: fix memory leak

In reply to Eric Snowberg

Fix memory leak

---
 util/grub-install.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
util/grub-install.c +1 -0
index 6c89c2b..7394739 100644
@@ -1468,6 +1468,7 @@ main (int argc, char *argv[])
 		{
 		  grub_util_fprint_full_disk_name (load_cfg_f, g, dev);
 		  fprintf (load_cfg_f, " ");
+		  free (g);
 		}
 	      if (dev != grub_dev)
 		grub_device_close (dev);
Signature · 1 line
1.7.1
#9 lore raw

PATCH 4/15 sparc64: Use the correct disk name in core.img

In reply to Eric Snowberg

Use the correct disk name and escape it properly in core.img for SPARC. Prior to this patch, search.fs_uuid was missing from the core.img. On SPARC, the core.img is very small and doesn't contain everything needed to boot. Therefore many modules contained within:
/boot/grub/sparc64-ieee1275 are needed.

This patch will prevent walking the entire device tree every time and possibly using the wrong disk.

This has been tested on T1 thru T7 hardware

I didn't change the behavior for other IEEE1275 platforms, but they may benefit from this patch if they were added within the switch statement.

---
 include/grub/emu/getroot.h |    2 ++
 util/grub-install.c        |   13 +++++++++++++
 util/probe.c               |    2 +-
 3 files changed, 16 insertions(+), 1 deletions(-)
include/grub/emu/getroot.h +2 -0
index 73fa2d3..4f04c7d 100644
@@ -100,5 +100,7 @@ grub_util_guess_baremetal_drive (const char *orig_path);
 void
 grub_util_fprint_full_disk_name (FILE *f,
 				 const char *drive, grub_device_t dev);
+char *
+escape_of_path (const char *orig_path);
 
 #endif /* ! GRUB_UTIL_GETROOT_HEADER */
util/grub-install.c +13 -0
index 7394739..f1ddf1c 100644
@@ -1347,6 +1347,7 @@ main (int argc, char *argv[])
 	  || grub_drives[1]
 	  || (!install_drive
 	      && platform != GRUB_INSTALL_PLATFORM_POWERPC_IEEE1275)
+	  || (platform == GRUB_INSTALL_PLATFORM_SPARC64_IEEE1275)
 	  || (install_drive && !is_same_disk (grub_drives[0], install_drive))
 	  || !have_bootdev (platform))
 	{
@@ -1438,6 +1439,18 @@ main (int argc, char *argv[])
 		    g = grub_util_guess_efi_drive (*curdev);
 		    break;
 		  case GRUB_INSTALL_PLATFORM_SPARC64_IEEE1275:
+		    {
+		      char *dname;
+		      const char *ofpath = grub_util_devname_to_ofpath (*curdev);
+		      g = xasprintf ("ieee1275/%s", ofpath);
+		      dname = escape_of_path (g);
+		      fprintf (load_cfg_f, "%s ", dname);
+		      free (dname);
+		      free (g);
+		      g = NULL;
+		      break;
+		    }
+
 		  case GRUB_INSTALL_PLATFORM_POWERPC_IEEE1275:
 		  case GRUB_INSTALL_PLATFORM_I386_IEEE1275:
 		    {
util/probe.c +1 -1
index fa7ca34..880cb5c 100644
@@ -44,7 +44,7 @@
 /* Since OF path names can have "," characters in them, and GRUB
    internally uses "," to indicate partitions (unlike OF which uses
    ":" for this purpose) we escape such commas.  */
-static char *
+char *
 escape_of_path (const char *orig_path)
 {
   char *new_path, *d, c;
Signature · 1 line
1.7.1
#10 lore raw

PATCH 5/15 ieee1275: fix segfault in grub-ofpathname

In reply to Eric Snowberg

fix segfault in grub-ofpathname

---
 util/ieee1275/grub-ofpathname.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
util/ieee1275/grub-ofpathname.c +3 -1
index 8e5d766..300fbdd 100644
@@ -46,7 +46,9 @@ int main(int argc, char **argv)
     }
 
   of_path = grub_util_devname_to_ofpath (argv[1]);
-  printf("%s\n", of_path);
+
+  if (of_path)
+    printf ("%s\n", of_path);
 
   free (of_path);
 
Signature · 1 line
1.7.1
#11 lore raw

PATCH 6/15 ieee1275: add nvme support within ofpath

In reply to Eric Snowberg

Add nvme support within ofpath

---
 grub-core/osdep/linux/ofpath.c |   46 ++++++++++++++++++++++++++++++++++++++++
 1 files changed, 46 insertions(+), 0 deletions(-)
grub-core/osdep/linux/ofpath.c +46 -0
index 0994e08..4c1c95b 100644
@@ -343,6 +343,49 @@ of_path_of_ide(const char *sys_devname __attribute__((unused)), const char *devi
   return ret;
 }
 
+static char *
+of_path_of_nvme(const char *sys_devname __attribute__((unused)),
+	        const char *device,
+	        const char *devnode __attribute__((unused)),
+	        const char *devicenode)
+{
+  char *sysfs_path, *of_path, disk[MAX_DISK_CAT];
+  const char *digit_string, *part_end;
+
+  digit_string = trailing_digits (device);
+  part_end = devicenode + strlen (devicenode) - 1;
+
+  if ((digit_string != '\0') && (*part_end == 'p'))
+    {
+      /* We have a partition number, strip it off */
+      int part;
+      char *nvmedev, *end;
+
+      nvmedev = strdup (devicenode);
+
+      if (nvmedev == NULL)
+        return NULL;
+
+      end = nvmedev + strlen (nvmedev) - 1;
+      *end = '\0'; /* remove the p */
+      sscanf (digit_string, "%d", &part);
+      snprintf (disk, sizeof (disk), "/disk@1:%c", 'a' + (part - 1));
+      sysfs_path = block_device_get_sysfs_path_and_link (nvmedev);
+      free (nvmedev);
+    }
+  else
+    {
+      /* We do not have the parition */
+      snprintf (disk, sizeof (disk), "/disk@1");
+      sysfs_path = block_device_get_sysfs_path_and_link (device);
+    }
+
+  of_path = find_obppath (sysfs_path);
+  free (sysfs_path);
+  strcat (of_path, disk);
+  return of_path;
+}
+
 static int
 vendor_is_ATA(const char *path)
 {
@@ -695,6 +738,9 @@ grub_util_devname_to_ofpath (const char *sys_devname)
     /* All the models I've seen have a devalias "floppy".
        New models have no floppy at all. */
     ofpath = xstrdup ("floppy");
+  else if (device[0] == 'n' && device[1] == 'v' && device[2] == 'm'
+           && device[3] == 'e')
+    ofpath = of_path_of_nvme (name_buf, device, devnode, devicenode);
   else
     {
       grub_util_warn (_("unknown device type %s"), device);
Signature · 1 line
1.7.1
#12 lore raw

PATCH 7/15 ofdisk: memory corruption fix

In reply to Eric Snowberg

The goal of this patch is to clean up memory corruption by having memory allocation take place in a single location, while not causing any new memory leaks. In various parts of the code the same path is called different things, for example it is called curcan, device,
name_dup, can, and devpath, These are all the same thing.

Within ofdisk_hash_add_real p->devpath it stores a pointer that later can get freed, causing memory corruption problems.

The following code path is an example of the memory corruption this patch will fix:

devpath created in grub_ofdisk_open
it then calls ofdisk_hash_add with devpath
it then calls ofdisk_hash_add_real with devpath
ofdisk_hash_add_real saves pointer of devpath
return
return
free devpath

dangling pointer/memory corruption with what is stored in ofdisk_hash_add_real

The patch fixes this problem and prevents a memory leak by cleaning up the new copy when it is no longer needed.

---
 grub-core/disk/ieee1275/ofdisk.c |   30 +++++++++++++-----------------
 1 files changed, 13 insertions(+), 17 deletions(-)
grub-core/disk/ieee1275/ofdisk.c +13 -17
index 235c0fe..18d2e95 100644
@@ -74,7 +74,7 @@ ofdisk_hash_find (const char *devpath)
 }
 
 static struct ofdisk_hash_ent *
-ofdisk_hash_add_real (char *devpath)
+ofdisk_hash_add_real (const char *devpath)
 {
   struct ofdisk_hash_ent *p;
   struct ofdisk_hash_ent **head = &ofdisk_hash[ofdisk_hash_fn(devpath)];
@@ -85,13 +85,20 @@ ofdisk_hash_add_real (char *devpath)
   if (!p)
     return NULL;
 
-  p->devpath = devpath;
+  p->devpath = grub_strdup (devpath);
+
+  if (!p->devpath)
+    {
+      grub_free (p);
+      return NULL;
+    }
 
   p->grub_devpath = grub_malloc (sizeof ("ieee1275/")
 				 + 2 * grub_strlen (p->devpath));
 
   if (!p->grub_devpath)
     {
+      grub_free (p->devpath);
       grub_free (p);
       return NULL;
     }
@@ -101,6 +108,7 @@ ofdisk_hash_add_real (char *devpath)
       p->open_path = grub_malloc (grub_strlen (p->devpath) + 3);
       if (!p->open_path)
 	{
+          grub_free (p->devpath);
 	  grub_free (p->grub_devpath);
 	  grub_free (p);
 	  return NULL;
@@ -140,7 +148,7 @@ check_string_removable (const char *str)
 }
 
 static struct ofdisk_hash_ent *
-ofdisk_hash_add (char *devpath, char *curcan)
+ofdisk_hash_add (const char *devpath, const char *curcan)
 {
   struct ofdisk_hash_ent *p, *pcan;
 
@@ -160,8 +168,6 @@ ofdisk_hash_add (char *devpath, char *curcan)
   pcan = ofdisk_hash_find (curcan);
   if (!pcan)
     pcan = ofdisk_hash_add_real (curcan);
-  else
-    grub_free (curcan);
 
   if (check_string_removable (devpath) || check_string_removable (curcan))
     pcan->is_removable = 1;
@@ -191,18 +197,7 @@ dev_iterate_real (const char *name, const char *path)
 
   op = ofdisk_hash_find (path);
   if (!op)
-    {
-      char *name_dup = grub_strdup (name);
-      char *can = grub_strdup (path);
-      if (!name_dup || !can)
-	{
-	  grub_errno = GRUB_ERR_NONE;
-	  grub_free (name_dup);
-	  grub_free (can);
-	  return;
-	}
-      op = ofdisk_hash_add (name_dup, can);
-    }
+    op = ofdisk_hash_add (name, path);
   return;
 }
 
@@ -658,6 +653,7 @@ insert_bootpath (void)
       char *device = grub_ieee1275_get_devname (bootpath);
       op = ofdisk_hash_add (device, NULL);
       op->is_boot = 1;
+      grub_free (device);
     }
   grub_free (type);
   grub_free (bootpath);
Signature · 1 line
1.7.1
#13 lore raw

PATCH 8/15 ofdisk: move open logic

In reply to Eric Snowberg

Move open logic from grub_ofdisk_get_block_size into grub_ofdisk_open. This will simplify reviewing future performance improvement patches in this area. In preparation for last_ihandle changes.

---
 grub-core/disk/ieee1275/ofdisk.c |   29 ++++++++++++++---------------
 1 files changed, 14 insertions(+), 15 deletions(-)
grub-core/disk/ieee1275/ofdisk.c +14 -15
index 18d2e95..956f675 100644
@@ -44,8 +44,8 @@ struct ofdisk_hash_ent
 };
 
 static grub_err_t
-grub_ofdisk_get_block_size (const char *device, grub_uint32_t *block_size,
-			    struct ofdisk_hash_ent *op);
+grub_ofdisk_get_block_size (grub_uint32_t *block_size,
+                            struct ofdisk_hash_ent *op);
 
 #define OFDISK_HASH_SZ	8
 static struct ofdisk_hash_ent *ofdisk_hash[OFDISK_HASH_SZ];
@@ -504,7 +504,17 @@ grub_ofdisk_open (const char *name, grub_disk_t disk)
     disk->id = (unsigned long) op;
     disk->data = op->open_path;
 
-    err = grub_ofdisk_get_block_size (devpath, &block_size, op);
+    if (last_ihandle)
+      grub_ieee1275_close (last_ihandle);
+
+    last_ihandle = 0;
+    last_devpath = NULL;
+
+    grub_ieee1275_open (devpath, &last_ihandle);
+    if (! last_ihandle)
+      return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "can't open device");
+
+    err = grub_ofdisk_get_block_size (&block_size, op);
     if (err)
       {
         grub_free (devpath);
@@ -681,8 +691,7 @@ grub_ofdisk_init (void)
 }
 
 static grub_err_t
-grub_ofdisk_get_block_size (const char *device, grub_uint32_t *block_size,
-			    struct ofdisk_hash_ent *op)
+grub_ofdisk_get_block_size (grub_uint32_t *block_size, struct ofdisk_hash_ent *op)
 {
   struct size_args_ieee1275
     {
@@ -694,16 +703,6 @@ grub_ofdisk_get_block_size (const char *device, grub_uint32_t *block_size,
       grub_ieee1275_cell_t size2;
     } args_ieee1275;
 
-  if (last_ihandle)
-    grub_ieee1275_close (last_ihandle);
-
-  last_ihandle = 0;
-  last_devpath = NULL;
-
-  grub_ieee1275_open (device, &last_ihandle);
-  if (! last_ihandle)
-    return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "can't open device");
-
   *block_size = 0;
 
   if (op->block_size_fails >= 2)
Signature · 1 line
1.7.1
#14 lore raw

PATCH 9/15 ieee1275: ofdisk - don't continue to query block-size after we have it

In reply to Eric Snowberg

Within commit: 87ec3b7fa9061f470616ed927fc140e995831c00 - "Don't continue to query block-size if disk doesn't have it.” Disks that returned 0 to the block-size query, still get queried every time.

OpenBoot PROM (OBP) does not have hotplug support until the OS is running. Therefore, fix logic in grub_ofdisk_get_block_size so the block size is not requested upon each open since it will not change.

---
 grub-core/disk/ieee1275/ofdisk.c |   26 +++++++++++++-------------
 1 files changed, 13 insertions(+), 13 deletions(-)
grub-core/disk/ieee1275/ofdisk.c +13 -13
index 956f675..6eaa044 100644
@@ -35,7 +35,8 @@ struct ofdisk_hash_ent
   char *grub_devpath;
   int is_boot;
   int is_removable;
-  int block_size_fails;
+  int block_size_retries;
+  grub_uint32_t block_size;
   /* Pointer to shortest available name on nodes representing canonical names,
      otherwise NULL.  */
   const char *shortest;
@@ -703,10 +704,15 @@ grub_ofdisk_get_block_size (grub_uint32_t *block_size, struct ofdisk_hash_ent *o
       grub_ieee1275_cell_t size2;
     } args_ieee1275;
 
+  if ((op->block_size_retries >= 2) || (op->block_size > 0))
+    {
+      *block_size = op->block_size;
+      return GRUB_ERR_NONE;
+    }
+
   *block_size = 0;
 
-  if (op->block_size_fails >= 2)
-    return GRUB_ERR_NONE;
+  op->block_size_retries++;
 
   INIT_IEEE1275_COMMON (&args_ieee1275.common, "call-method", 2, 2);
   args_ieee1275.method = (grub_ieee1275_cell_t) "block-size";
@@ -714,21 +720,15 @@ grub_ofdisk_get_block_size (grub_uint32_t *block_size, struct ofdisk_hash_ent *o
   args_ieee1275.result = 1;
 
   if (IEEE1275_CALL_ENTRY_FN (&args_ieee1275) == -1)
-    {
-      grub_dprintf ("disk", "can't get block size: failed call-method\n");
-      op->block_size_fails++;
-    }
+    grub_dprintf ("disk", "can't get block size: failed call-method\n");
   else if (args_ieee1275.result)
-    {
-      grub_dprintf ("disk", "can't get block size: %lld\n",
-		    (long long) args_ieee1275.result);
-      op->block_size_fails++;
-    }
+    grub_dprintf ("disk", "can't get block size: %lld\n",
+		 (long long) args_ieee1275.result);
   else if (args_ieee1275.size1
 	   && !(args_ieee1275.size1 & (args_ieee1275.size1 - 1))
 	   && args_ieee1275.size1 >= 512 && args_ieee1275.size1 <= 16384)
     {
-      op->block_size_fails = 0;
+      op->block_size = args_ieee1275.size1;
       *block_size = args_ieee1275.size1;
     }
 
Signature · 1 line
1.7.1
#15 lore raw

PATCH 10/15 ofdisk: refactor open logic

In reply to Eric Snowberg

Consolidate duplicate code into grub_ofdisk_new_open. This is in preperation for further last_ihandle changes for disk open caching on SPARC.

---
 grub-core/disk/ieee1275/ofdisk.c |   47 +++++++++++++++++++++++--------------
 1 files changed, 29 insertions(+), 18 deletions(-)
grub-core/disk/ieee1275/ofdisk.c +29 -18
index 6eaa044..6789072 100644
@@ -48,6 +48,9 @@ static grub_err_t
 grub_ofdisk_get_block_size (grub_uint32_t *block_size,
                             struct ofdisk_hash_ent *op);
 
+static grub_err_t
+grub_ofdisk_open_real (grub_disk_t disk);
+
 #define OFDISK_HASH_SZ	8
 static struct ofdisk_hash_ent *ofdisk_hash[OFDISK_HASH_SZ];
 
@@ -504,16 +507,12 @@ grub_ofdisk_open (const char *name, grub_disk_t disk)
       }
     disk->id = (unsigned long) op;
     disk->data = op->open_path;
-
-    if (last_ihandle)
-      grub_ieee1275_close (last_ihandle);
-
-    last_ihandle = 0;
-    last_devpath = NULL;
-
-    grub_ieee1275_open (devpath, &last_ihandle);
-    if (! last_ihandle)
-      return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "can't open device");
+    err = grub_ofdisk_open_real (disk);
+    if (err)
+      {
+        grub_free (devpath);
+        return err;
+      }
 
     err = grub_ofdisk_get_block_size (&block_size, op);
     if (err)
@@ -553,17 +552,13 @@ grub_ofdisk_prepare (grub_disk_t disk, grub_disk_addr_t sector)
 {
   grub_ssize_t status;
   unsigned long long pos;
+  grub_err_t err;
 
   if (disk->data != last_devpath)
     {
-      if (last_ihandle)
-	grub_ieee1275_close (last_ihandle);
-      last_ihandle = 0;
-      last_devpath = NULL;
-
-      grub_ieee1275_open (disk->data, &last_ihandle);
-      if (! last_ihandle)
-	return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "can't open device");
+      err = grub_ofdisk_open_real (disk);
+      if (err)
+        return err;
       last_devpath = disk->data;      
     }
 
@@ -734,3 +729,19 @@ grub_ofdisk_get_block_size (grub_uint32_t *block_size, struct ofdisk_hash_ent *o
 
   return 0;
 }
+
+static grub_err_t
+grub_ofdisk_open_real (grub_disk_t disk)
+{
+  if (last_ihandle)
+    grub_ieee1275_close (last_ihandle);
+
+  last_ihandle = 0;
+  last_devpath = NULL;
+
+  grub_ieee1275_open (disk->data, &last_ihandle);
+  if (! last_ihandle)
+    return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "can't open device");
+
+  return 0;
+}
Signature · 1 line
1.7.1
#16 lore raw

PATCH 11/15 sparc64: boot performance improvements

In reply to Eric Snowberg

Keep sun4v OF devices open. This can save 6 - 7 seconds per open call and can decrease boot times from over 10 minutes to a few seconds on larger SPARC systems. The open/close calls with some vendors' SAS controllers cause the entire card to be reinitialized after each close.

---
 grub-core/disk/ieee1275/ofdisk.c |   17 ++++++++++++++++-
 grub-core/kern/ieee1275/cmain.c  |    4 ++++
 include/grub/ieee1275/ieee1275.h |    2 ++
 3 files changed, 22 insertions(+), 1 deletions(-)
grub-core/disk/ieee1275/ofdisk.c +16 -1
index 6789072..9c6b8b0 100644
@@ -37,6 +37,7 @@ struct ofdisk_hash_ent
   int is_removable;
   int block_size_retries;
   grub_uint32_t block_size;
+  grub_ieee1275_ihandle_t ihandle;
   /* Pointer to shortest available name on nodes representing canonical names,
      otherwise NULL.  */
   const char *shortest;
@@ -539,7 +540,7 @@ grub_ofdisk_close (grub_disk_t disk)
 {
   if (disk->data == last_devpath)
     {
-      if (last_ihandle)
+      if (! (grub_ieee1275_test_flag(GRUB_IEEE1275_FLAG_CACHE_OPEN)) && last_ihandle)
 	grub_ieee1275_close (last_ihandle);
       last_ihandle = 0;
       last_devpath = NULL;
@@ -733,6 +734,18 @@ grub_ofdisk_get_block_size (grub_uint32_t *block_size, struct ofdisk_hash_ent *o
 static grub_err_t
 grub_ofdisk_open_real (grub_disk_t disk)
 {
+  struct ofdisk_hash_ent *op = (struct ofdisk_hash_ent *)disk->id;
+
+  if (!op)
+    return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "BUG: can't open device ");
+
+  if (grub_ieee1275_test_flag(GRUB_IEEE1275_FLAG_CACHE_OPEN) && op->ihandle)
+    {
+      last_ihandle = op->ihandle;
+      last_devpath = disk->data;
+      return 0;
+    }
+
   if (last_ihandle)
     grub_ieee1275_close (last_ihandle);
 
@@ -743,5 +756,7 @@ grub_ofdisk_open_real (grub_disk_t disk)
   if (! last_ihandle)
     return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "can't open device");
 
+  op->ihandle = last_ihandle;
+  last_devpath = disk->data;
   return 0;
 }
grub-core/kern/ieee1275/cmain.c +4 -0
index 3e12e6b..b016598 100644
@@ -108,6 +108,10 @@ grub_ieee1275_find_options (void)
   if (rc >= 0)
     {
       char *ptr;
+
+      if (grub_strncmp (tmp, "sun4v", 5) == 0)
+	  grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_CACHE_OPEN);
+
       for (ptr = tmp; ptr - tmp < actual; ptr += grub_strlen (ptr) + 1)
 	{
 	  if (grub_memcmp (ptr, "MacRISC", sizeof ("MacRISC") - 1) == 0
include/grub/ieee1275/ieee1275.h +2 -0
index 8e42513..b79e97b 100644
@@ -146,6 +146,8 @@ enum grub_ieee1275_flag
   GRUB_IEEE1275_FLAG_BROKEN_REPEAT,
 
   GRUB_IEEE1275_FLAG_CURSORONOFF_ANSI_BROKEN,
+
+  GRUB_IEEE1275_FLAG_CACHE_OPEN,
 };
 
 extern int EXPORT_FUNC(grub_ieee1275_test_flag) (enum grub_ieee1275_flag flag);
Signature · 1 line
1.7.1
#17 lore raw

PATCH 12/15 ofdisk: only add aliases that exist

In reply to Eric Snowberg

Only add device aliases that really exist for SPARC.

SPARC hardware ships with devaliases the could exist in the future. For example a T7 might contain the following predefined devalias list:

{20} ok devalias

disk0                    /pci@301/pci@1/scsi@0/disk@p0
disk1                    /pci@301/pci@1/scsi@0/disk@p1
disk2                    /pci@301/pci@1/scsi@0/disk@p2
disk3                    /pci@301/pci@1/scsi@0/disk@p3
disk4                    /pci@303/pci@1/scsi@0/disk@p0
disk5                    /pci@303/pci@1/scsi@0/disk@p1
disk                     /pci@301/pci@1/scsi@0/disk@p0

However there could be just a single disk installed in disk0.

Now grub will no longer try to use these disks that don't exist. This was causing long delays on boot and showed nonexistent drives in the shell.

---
 grub-core/disk/ieee1275/ofdisk.c           |  225 ++++++++++++++++++++++++++++
 grub-core/kern/ieee1275/cmain.c            |    3 +
 grub-core/kern/ieee1275/ieee1275.c         |   88 +++++++++++
 grub-core/kern/sparc64/ieee1275/ieee1275.c |  111 ++++++++++++++
 include/grub/ieee1275/ieee1275.h           |    9 +
 include/grub/sparc64/ieee1275/ieee1275.h   |    4 +
 6 files changed, 440 insertions(+), 0 deletions(-)
grub-core/disk/ieee1275/ofdisk.c +225 -0
index 9c6b8b0..42d038c 100644
@@ -22,8 +22,10 @@
 #include <grub/mm.h>
 #include <grub/ieee1275/ieee1275.h>
 #include <grub/ieee1275/ofdisk.h>
+#include <grub/scsicmd.h>
 #include <grub/i18n.h>
 #include <grub/time.h>
+#include <grub/list.h>
 
 static char *last_devpath;
 static grub_ieee1275_ihandle_t last_ihandle;
@@ -45,6 +47,14 @@ struct ofdisk_hash_ent
   struct ofdisk_hash_ent *next;
 };
 
+struct ofdisk_hba_ent
+{
+  struct ofdisk_hba_ent *next;
+  struct ofdisk_hba_ent **prev;
+  grub_ieee1275_ihandle_t ihandle;
+  char *path;
+};
+
 static grub_err_t
 grub_ofdisk_get_block_size (grub_uint32_t *block_size,
                             struct ofdisk_hash_ent *op);
@@ -52,9 +62,36 @@ grub_ofdisk_get_block_size (grub_uint32_t *block_size,
 static grub_err_t
 grub_ofdisk_open_real (grub_disk_t disk);
 
+static grub_err_t
+sparc_disk_present (const char *path);
+
+static char *
+get_hbaname_from_path (const char *path);
+
+static char *
+get_diskname_from_path (const char *path);
+
+static struct ofdisk_hba_ent *
+ofdisk_hba_find (const char *devpath);
+
+static grub_ieee1275_ihandle_t
+ofdisk_hba_open (const char *hba_name);
+
 #define OFDISK_HASH_SZ	8
 static struct ofdisk_hash_ent *ofdisk_hash[OFDISK_HASH_SZ];
 
+static struct ofdisk_hba_ent *ofdisk_hba_ents = NULL;
+
+static struct grub_scsi_test_unit_ready ofdisk_tur =
+{
+  .opcode = grub_scsi_cmd_test_unit_ready,
+  .lun = 0,
+  .reserved1 = 0,
+  .reserved2 = 0,
+  .reserved3 = 0,
+  .control = 0,
+};
+
 static int
 ofdisk_hash_fn (const char *devpath)
 {
@@ -363,6 +400,9 @@ scan (void)
     {
       if (grub_strcmp (alias.type, "block") != 0)
 	continue;
+      if (grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_VALIDATE_DEV_ALIASES) &&
+          sparc_disk_present (alias.path) == 0)
+        continue;
       dev_iterate_real (alias.name, alias.path);
     }
 
@@ -451,6 +491,46 @@ compute_dev_path (const char *name)
   return devpath;
 }
 
+static char *
+get_hbaname_from_path (const char *path)
+{
+  char *sptr, *hba_name;
+
+  hba_name = grub_strdup (path);
+
+  if (!hba_name)
+    return NULL;
+
+  sptr = grub_strstr (hba_name, "/disk@");
+
+  if (!sptr)
+    return NULL;
+
+  *sptr = '\0';
+
+  return hba_name;
+}
+
+static char *
+get_diskname_from_path (const char *path)
+{
+  const char *disk_dev = "/disk@";
+  char *sptr, *disk_name;
+
+  sptr = grub_strstr (path, disk_dev);
+
+  if (!sptr)
+    return NULL;
+
+  disk_name = grub_strdup (sptr + grub_strlen (disk_dev));
+  sptr = grub_strstr (disk_name, ":");
+
+  if (sptr)
+    *sptr = '\0';
+
+  return disk_name;
+}
+
 static grub_err_t
 grub_ofdisk_open (const char *name, grub_disk_t disk)
 {
@@ -760,3 +840,148 @@ grub_ofdisk_open_real (grub_disk_t disk)
   last_devpath = disk->data;
   return 0;
 }
+
+static struct ofdisk_hba_ent *
+ofdisk_hba_find (const char *devpath)
+{
+  struct ofdisk_hba_ent *dev = NULL;
+
+  FOR_LIST_ELEMENTS (dev, ofdisk_hba_ents)
+    if (grub_strcmp (dev->path, devpath) == 0)
+      break;
+
+  return dev;
+}
+
+static struct ofdisk_hba_ent *
+ofdisk_hba_add (const char *devpath, grub_ieee1275_ihandle_t ihandle)
+{
+  struct ofdisk_hba_ent *dev;
+
+  dev = grub_zalloc (sizeof (struct ofdisk_hba_ent));
+
+  if (!dev)
+    return NULL;
+
+  dev->path = grub_strdup (devpath);
+
+  if (!dev->path)
+    {
+      grub_free (dev);
+      return NULL;
+    }
+
+  dev->ihandle = ihandle;
+  grub_list_push (GRUB_AS_LIST_P (&ofdisk_hba_ents), GRUB_AS_LIST (dev));
+
+  return dev;
+}
+
+static grub_ieee1275_ihandle_t
+ofdisk_hba_open (const char *hba_name)
+{
+  grub_ieee1275_ihandle_t ihandle;
+  struct ofdisk_hba_ent *dev;
+
+  dev = ofdisk_hba_find (hba_name);
+
+  if (dev)
+    ihandle = dev->ihandle;
+  else if (grub_ieee1275_open (hba_name, &ihandle))
+    ihandle = 0;
+  else
+    {
+      dev = ofdisk_hba_add (hba_name, ihandle);
+
+      if (!dev)
+        ihandle = 0;
+    }
+
+  return ihandle;
+}
+
+static grub_err_t
+sparc_disk_present (const char *full_path)
+{
+  char *disk_name = get_diskname_from_path (full_path);
+  char *hba_name = get_hbaname_from_path (full_path);
+  char *lun_name = NULL, *sptr = NULL, *device_type = 0;
+  grub_ieee1275_ihandle_t ihandle;
+  /* Per SPARC SCSI binding spec, default to 2 for legacy devices that may
+     not have this property */
+  grub_uint32_t address_cells = 2;
+  grub_ieee1275_phandle_t root;
+  grub_uint64_t lun = 0;
+  grub_ssize_t result;
+  grub_err_t rval = GRUB_ERR_NONE;
+
+  if ((!hba_name) || (!disk_name))
+    {
+      grub_free (hba_name);
+      grub_free (disk_name);
+      return GRUB_ERR_NONE;
+    }
+
+  ihandle = ofdisk_hba_open (hba_name);
+
+  if (ihandle == 0)
+    {
+      grub_free (hba_name);
+      grub_free (disk_name);
+      return GRUB_ERR_NONE;
+    }
+
+  sptr = grub_strstr (disk_name, ",");
+
+  if (sptr)
+    {
+      lun_name = grub_strdup (sptr + 1);
+      *sptr = '\0';
+      lun = grub_strtoull (lun_name, 0, 16);
+    }
+
+  grub_ieee1275_finddevice (hba_name, &root);
+  grub_ieee1275_get_integer_property (root, "#address-cells", &address_cells,
+                                      sizeof address_cells, 0);
+  device_type = grub_ieee1275_get_device_type (hba_name);
+
+  if ((grub_strcmp (device_type, "scsi-2") == 0) ||
+      (grub_strcmp (device_type, "scsi-sas") == 0))
+    {
+      if (address_cells == 4)
+        {
+          if (grub_ieee1275_set_sas_address (ihandle, disk_name, lun) == 0)
+            if (grub_ieee1275_no_data_command (ihandle, &ofdisk_tur,
+                                               &result) == 0)
+              if (result == 0)
+                rval = GRUB_ERR_BAD_DEVICE;
+        }
+      else if ((address_cells == 2) && (grub_isxdigit (*disk_name)))
+        {
+          grub_uint32_t tgt;
+          tgt = grub_strtol (disk_name, 0, 16);
+          if (tgt <= 0xff)
+            if (grub_ieee1275_set_address (ihandle, tgt, lun) == 0)
+              if (grub_ieee1275_no_data_command (ihandle, &ofdisk_tur,
+                                                 &result) == 0)
+                if (result == 0)
+                  rval = GRUB_ERR_BAD_DEVICE;
+        }
+    }
+  else if (grub_strcmp (device_type, "scsi-usb") == 0)
+    {
+      if (grub_ieee1275_set_address (ihandle, 0, 0) == 0)
+        if (grub_ieee1275_no_data_command (ihandle, &ofdisk_tur, &result) == 0)
+          if (result == 0)
+            rval = GRUB_ERR_BAD_DEVICE;
+    }
+  else
+    {
+      /* ieee1275_finddevice would validate these already */
+      rval = GRUB_ERR_BAD_DEVICE;
+    }
+
+  grub_free (hba_name);
+  grub_free (disk_name);
+  return rval;
+}
grub-core/kern/ieee1275/cmain.c +3 -0
index b016598..59271ae 100644
@@ -110,7 +110,10 @@ grub_ieee1275_find_options (void)
       char *ptr;
 
       if (grub_strncmp (tmp, "sun4v", 5) == 0)
+	{
 	  grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_CACHE_OPEN);
+	  grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_VALIDATE_DEV_ALIASES);
+	}
 
       for (ptr = tmp; ptr - tmp < actual; ptr += grub_strlen (ptr) + 1)
 	{
grub-core/kern/ieee1275/ieee1275.c +88 -0

91 lines not on this page · raw message

grub-core/kern/sparc64/ieee1275/ieee1275.c +111 -0

120 lines not on this page · raw message

include/grub/ieee1275/ieee1275.h +9 -0
index b79e97b..7644956 100644
@@ -148,6 +148,8 @@ enum grub_ieee1275_flag
   GRUB_IEEE1275_FLAG_CURSORONOFF_ANSI_BROKEN,
 
   GRUB_IEEE1275_FLAG_CACHE_OPEN,
+
+  GRUB_IEEE1275_FLAG_VALIDATE_DEV_ALIASES,
 };
 
 extern int EXPORT_FUNC(grub_ieee1275_test_flag) (enum grub_ieee1275_flag flag);
@@ -213,6 +215,13 @@ int EXPORT_FUNC(grub_ieee1275_set_color) (grub_ieee1275_ihandle_t ihandle,
 					  int index, int r, int g, int b);
 int EXPORT_FUNC(grub_ieee1275_milliseconds) (grub_uint32_t *msecs);
 
+int EXPORT_FUNC(grub_ieee1275_set_address) (grub_ieee1275_ihandle_t ihandle,
+                                            grub_uint32_t target,
+                                            grub_uint32_t lun);
+
+int EXPORT_FUNC(grub_ieee1275_no_data_command) (grub_ieee1275_ihandle_t ihandle,
+                                                const void *cmd_addr,
+                                                grub_ssize_t *result);
 
 grub_err_t EXPORT_FUNC(grub_claimmap) (grub_addr_t addr, grub_size_t size);
 
include/grub/sparc64/ieee1275/ieee1275.h +4 -0
index 32c77f8..632eb87 100644
@@ -21,6 +21,7 @@
 #define GRUB_IEEE1275_MACHINE_HEADER	1
 
 #include <grub/types.h>
+#include <grub/ieee1275/ieee1275.h>
 
 #define GRUB_IEEE1275_CELL_SIZEOF 8
 typedef grub_uint64_t grub_ieee1275_cell_t;
@@ -42,6 +43,9 @@ extern int EXPORT_FUNC(grub_ieee1275_claim_vaddr) (grub_addr_t vaddr,
 extern int EXPORT_FUNC(grub_ieee1275_alloc_physmem) (grub_addr_t *paddr,
 						     grub_size_t size,
 						     grub_uint32_t align);
+extern int EXPORT_FUNC(grub_ieee1275_set_sas_address) (grub_uint32_t ihandle,
+                                                       const char *disk_name,
+                                                       grub_uint64_t lun);
 
 extern grub_addr_t EXPORT_VAR (grub_ieee1275_original_stack);
 
Signature · 1 line
1.7.1
#18 lore raw

PATCH 13/15 sparc64: add disks that don't have a devalias to the device list

In reply to Eric Snowberg

Add ability for grub2 to be capable of booting from a disk that does not have a device alias. This patch will find all disks in the system and add them to the device list.

---
 grub-core/disk/ieee1275/ofdisk.c |  144 ++++++++++++++++++++++++++++++++++++++
 1 files changed, 144 insertions(+), 0 deletions(-)
grub-core/disk/ieee1275/ofdisk.c +144 -0
index 42d038c..17d082b 100644
@@ -376,6 +376,150 @@ dev_iterate (const struct grub_ieee1275_devalias *alias)
       grub_free (table);
       grub_free (buf);
     }
+  else if (grub_strcmp (alias->type, "scsi-2") == 0)
+    {
+      grub_ieee1275_ihandle_t ihandle;
+      grub_ssize_t result;
+      char *buf, *bufptr;
+      grub_uint8_t tgt;
+
+      buf = grub_malloc (grub_strlen (alias->path) +
+                         sizeof ("/disk@00"));
+      if (!buf)
+        return;
+
+      bufptr = grub_stpcpy (buf, alias->path);
+      ihandle = ofdisk_hba_open (alias->path);
+
+      if (ihandle == 0)
+        {
+          grub_free (buf);
+          return;
+        }
+
+      for (tgt = 0; tgt <= 0xf; tgt++)
+        {
+          if (grub_ieee1275_set_address(ihandle, tgt, 0) == 0)
+            if (grub_ieee1275_no_data_command (ihandle, &ofdisk_tur,
+                                               &result) == 0)
+              if (result == 0)
+                {
+                  grub_snprintf (bufptr, sizeof ("/disk@00"),
+                                 "/disk@%" PRIxGRUB_UINT32_T, tgt);
+                  dev_iterate_real (buf, buf);
+                }
+        }
+
+      grub_free (buf);
+      return;
+    }
+  else if (grub_strcmp (alias->type, "scsi-sas") == 0)
+    {
+      grub_ieee1275_ihandle_t ihandle;
+      grub_uint32_t address_cells = 2;
+      grub_ieee1275_phandle_t root;
+      grub_ssize_t result;
+      char *buf, *bufptr;
+
+      buf = grub_malloc (grub_strlen (alias->path) +
+                         sizeof ("/disk@p1100"));
+
+      if (!buf)
+        return;
+
+      bufptr = grub_stpcpy (buf, alias->path);
+      bufptr = grub_stpcpy (bufptr, "/disk@");
+      ihandle = ofdisk_hba_open (alias->path);
+
+      if (ihandle == 0)
+        {
+          grub_free (buf);
+          return;
+        }
+
+      grub_ieee1275_finddevice (alias->path, &root);
+      grub_ieee1275_get_integer_property (root, "#address-cells", &address_cells,
+                                          sizeof address_cells, 0);
+      if (address_cells == 2)
+        {
+          grub_uint8_t tgt;
+
+          for (tgt = 0; tgt < 0xf; tgt++)
+            {
+              if (grub_ieee1275_set_address(ihandle, tgt, 0) == 0)
+                if (grub_ieee1275_no_data_command (ihandle, &ofdisk_tur,
+                                                   &result) == 0)
+                  if (result == 0)
+                    {
+                      grub_snprintf (bufptr, sizeof ("p1100"),
+                                     "%" PRIxGRUB_UINT32_T, tgt);
+                      dev_iterate_real (buf, buf);
+                    }
+            }
+        }
+      else if (address_cells == 4)
+        {
+          grub_uint16_t exp;
+          grub_uint8_t phy;
+
+          for (exp = 0; exp <= 0x100; exp+=0x100)
+            for (phy = 0; phy < 0xff; phy++)
+              {
+                grub_snprintf (bufptr, sizeof ("p1100"),
+                               "p%" PRIxGRUB_UINT32_T, exp | phy);
+                if (grub_ieee1275_set_sas_address (ihandle, bufptr, 0) == 0)
+                  if (grub_ieee1275_no_data_command (ihandle, &ofdisk_tur,
+                                                     &result) == 0)
+                    if (result == 0)
+                      dev_iterate_real (buf, buf);
+              }
+        }
+      grub_free (buf);
+      return;
+    }
+  else if (grub_strcmp (alias->type, "nvme") == 0)
+    {
+      char *buf;
+
+      buf = grub_malloc (IEEE1275_MAX_PATH_LEN);
+
+      if (!buf)
+        return;
+
+      grub_snprintf (buf, IEEE1275_MAX_PATH_LEN, "%s/disk@1", alias->path);
+      dev_iterate_real (buf, buf);
+      grub_free (buf);
+      return;
+    }
+  else if (grub_strcmp (alias->type, "scsi-usb") == 0)
+    {
+      grub_ieee1275_ihandle_t ihandle;
+      grub_ssize_t result;
+
+      ihandle = ofdisk_hba_open (alias->path);
+
+      if (ihandle == 0)
+        return;
+
+      if (grub_ieee1275_set_address (ihandle, 0, 0) == 0)
+        if (grub_ieee1275_no_data_command (ihandle, &ofdisk_tur, &result) == 0)
+          if (result == 0)
+            {
+              char *buf, *bufptr;
+
+              buf = grub_malloc (grub_strlen (alias->path) +
+                                 sizeof ("/disk@0"));
+
+              if (!buf)
+                return;
+
+              bufptr = grub_stpcpy (buf, alias->path);
+              grub_snprintf (bufptr, sizeof ("/disk@0"), "/disk@0");
+              dev_iterate_real (buf, buf);
+              grub_free (buf);
+            }
+      return;
+    }
 
   if (!grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_NO_TREE_SCANNING_FOR_DISKS)
       && grub_strcmp (alias->type, "block") == 0)
Signature · 1 line
1.7.1
#19 lore raw

PATCH 14/15 parser: Remove escape from the state transitions

In reply to Eric Snowberg

Remove GRUB_PARSER_STATE_ESC with state GRUB_PARSER_STATE_TEXT from the list of not allowed characters

This fixes a problem where a properly escaped comma is in the disk path.

For example: /pci@306/pci@1/LSI,mrsas@0/disk@0:a

During grub install, the search.fs_uuid is correctly stored in the core.img.

As seen here:

 001e380: 7365 6172 6368 2e66 735f 7575 6964 2039  search.fs_uuid 9
 001e390: 6462 6137 6333 362d 6431 6432 2d34 6163  dba7c36-d1d2-4ac
 001e3a0: 642d 6135 3037 2d30 3634 6132 3462 3538  d-a507-064a24b58
 001e3b0: 3666 3420 726f 6f74 2069 6565 6531 3237  6f4 root ieee127
 001e3c0: 352f 2f70 6369 4033 3036 2f70 6369 4031  5//pci@306/pci@1
 001e3d0: 2f4c 5349 5c2c 6d72 7361 7340 302f 6469  /LSI\,mrsas@0/di
 001e3e0: 736b 4030 3a61 200a 7365 7420 7072 6566  sk@0:a .set pref
 001e3f0: 6978 3d28 2472 6f6f 7429 272f 6772 7562  ix=($root)'/grub
 001e400: 3227 0a00 0000 0000 0000 0003 0000 0010  2'..............
 001e410: 2f67 7275 6232 0000                      /grub2..

Before this change the following args would be sent to grub_cmd_do_search:

key: 9dba7c36-d1d2-4acd-a507-064a24b586f4
var: root
hint: ieee1275//pci@306/pci@1/LSI,mrsas@0/disk@0:a

The hint above is not correct. It should be:

hint: ieee1275//pci@306/pci@1/LSI\,mrsas@0/disk@0:a

Later on, when it tries to use this disk, it incorrectly truncates the device name since the comma isn’t escaped and tries to do the grub_disk_open with ieee1275//pci@306/pci@1/LSI.

---
 grub-core/kern/parser.c |    1 -
 1 files changed, 0 insertions(+), 1 deletions(-)
grub-core/kern/parser.c +0 -1
index 78175aa..be88baa 100644
@@ -30,7 +30,6 @@ static struct grub_parser_state_transition state_transitions[] = {
   {GRUB_PARSER_STATE_TEXT, GRUB_PARSER_STATE_QUOTE, '\'', 0},
   {GRUB_PARSER_STATE_TEXT, GRUB_PARSER_STATE_DQUOTE, '\"', 0},
   {GRUB_PARSER_STATE_TEXT, GRUB_PARSER_STATE_VAR, '$', 0},
-  {GRUB_PARSER_STATE_TEXT, GRUB_PARSER_STATE_ESC, '\\', 0},
 
   {GRUB_PARSER_STATE_ESC, GRUB_PARSER_STATE_TEXT, 0, 1},
 
Signature · 1 line
1.7.1
#20 lore raw

PATCH 15/15 sparc64: ignore hypervisor reboot memory block device

In reply to Eric Snowberg

Ignore the hypervisor's reboot memory block device. Newer sun4v hardware contain a block device for the hypervisor. This block device should not be used by anyone else.

---
 grub-core/disk/ieee1275/ofdisk.c |    3 +++
 grub-core/kern/ieee1275/cmain.c  |    1 +
 include/grub/ieee1275/ieee1275.h |    2 ++
 3 files changed, 6 insertions(+), 0 deletions(-)
grub-core/disk/ieee1275/ofdisk.c +3 -0
index 17d082b..5405be8 100644
@@ -524,6 +524,9 @@ dev_iterate (const struct grub_ieee1275_devalias *alias)
   if (!grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_NO_TREE_SCANNING_FOR_DISKS)
       && grub_strcmp (alias->type, "block") == 0)
     {
+      if (grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_IGNORE_REBOOT_DEV)
+          && grub_strstr (alias->path, "reboot-memory"))
+        return;
       dev_iterate_real (alias->path, alias->path);
       return;
     }
grub-core/kern/ieee1275/cmain.c +1 -0
index 59271ae..844862f 100644
@@ -113,6 +113,7 @@ grub_ieee1275_find_options (void)
 	{
 	  grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_CACHE_OPEN);
 	  grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_VALIDATE_DEV_ALIASES);
+	  grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_IGNORE_REBOOT_DEV);
 	}
 
       for (ptr = tmp; ptr - tmp < actual; ptr += grub_strlen (ptr) + 1)
include/grub/ieee1275/ieee1275.h +2 -0
index 7644956..fdd123d 100644
@@ -150,6 +150,8 @@ enum grub_ieee1275_flag
   GRUB_IEEE1275_FLAG_CACHE_OPEN,
 
   GRUB_IEEE1275_FLAG_VALIDATE_DEV_ALIASES,
+
+  GRUB_IEEE1275_FLAG_IGNORE_REBOOT_DEV,
 };
 
 extern int EXPORT_FUNC(grub_ieee1275_test_flag) (enum grub_ieee1275_flag flag);
Signature · 1 line
1.7.1
#21 lore raw
In reply to Eric Snowberg
Quoted 10 lines · Eric Snowberg

First set of patches to add sun4v SPARC support to grub.

Major additions include:

* Properly scan for both SAS and SCSI disks
* Increasing boot performance
* GPT support
* NVMe support
* Various bug fixes

Quoted 8 lines

Before this patch, there isn???t a single SAS HBA that was enumerated correctly on SPARC. I went back 10 years and believe I have added every HBA with OF support.

Without these patches, on larger systems, it took 15+ minutes to get to the grub menu. Now it takes about a second.

This code has been tested on T1, T2, T4, T5, and T7 hardware.

I will take a look at it in week or two.

Next time please CC me directly too.

Daniel

#22 lore raw
Quoted 15 lines · Daniel Kiper
Quoted 14 lines · Eric Snowberg

First set of patches to add sun4v SPARC support to grub.

Major additions include:

* Properly scan for both SAS and SCSI disks
* Increasing boot performance
* GPT support
* NVMe support
* Various bug fixes

Before this patch, there isn???t a single SAS HBA that was enumerated correctly on SPARC. I went back 10 years and believe I have added every HBA with OF support.

Quoted 6 lines
Quoted 4 lines

Without these patches, on larger systems, it took 15+ minutes to get to the grub menu. Now it takes about a second.

This code has been tested on T1, T2, T4, T5, and T7 hardware.

I will take a look at it in week or two.

It looks that I will do that in August. Currently I am working on other important stuff and I wish to release it before my vacation. Sorry for delay.

Daniel