All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 00/15] Add missing SPARC support
@ 2016-06-29 21:43 Eric Snowberg
  2016-06-29 21:43 ` [PATCH 01/15] sparc64: fix OF path names for sun4v systems Eric Snowberg
                   ` (15 more replies)
  0 siblings, 16 replies; 23+ messages in thread
From: Eric Snowberg @ 2016-06-29 21:43 UTC (permalink / raw)
  To: grub-devel; +Cc: 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.

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(-)



^ permalink raw reply	[flat|nested] 23+ messages in thread

* [PATCH 01/15] sparc64: fix OF path names for sun4v systems
  2016-06-29 21:43 [PATCH 00/15] Add missing SPARC support Eric Snowberg
@ 2016-06-29 21:43 ` Eric Snowberg
  2016-06-29 21:43 ` [PATCH 02/15] sparc64: Add blocklist GPT support for SPARC Eric Snowberg
                   ` (14 subsequent siblings)
  15 siblings, 0 replies; 23+ messages in thread
From: Eric Snowberg @ 2016-06-29 21:43 UTC (permalink / raw)
  To: grub-devel; +Cc: Eric Snowberg

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.

Signed-off-by: Eric Snowberg <eric.snowberg@oracle.com>
---
 grub-core/osdep/linux/ofpath.c |  162 +++++++++++++++++++++++++++++++++++++++-
 1 files changed, 160 insertions(+), 2 deletions(-)

diff --git a/grub-core/osdep/linux/ofpath.c b/grub-core/osdep/linux/ofpath.c
index a79682a..0994e08 100644
--- a/grub-core/osdep/linux/ofpath.c
+++ b/grub-core/osdep/linux/ofpath.c
@@ -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;
 }
-- 
1.7.1



^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH 02/15] sparc64: Add blocklist GPT support for SPARC
  2016-06-29 21:43 [PATCH 00/15] Add missing SPARC support Eric Snowberg
  2016-06-29 21:43 ` [PATCH 01/15] sparc64: fix OF path names for sun4v systems Eric Snowberg
@ 2016-06-29 21:43 ` Eric Snowberg
  2017-05-10 22:42   ` Vladimir 'phcoder' Serbinenko
  2016-06-29 21:43 ` [PATCH 03/15] grub-install: fix memory leak Eric Snowberg
                   ` (13 subsequent siblings)
  15 siblings, 1 reply; 23+ messages in thread
From: Eric Snowberg @ 2016-06-29 21:43 UTC (permalink / raw)
  To: grub-devel; +Cc: 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.

Signed-off-by: Eric Snowberg <eric.snowberg@oracle.com>
---
 grub-core/osdep/linux/blocklist.c |    5 +++++
 util/setup.c                      |   12 +++++++++---
 2 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/grub-core/osdep/linux/blocklist.c b/grub-core/osdep/linux/blocklist.c
index c77d608..caf8d4e 100644
--- a/grub-core/osdep/linux/blocklist.c
+++ b/grub-core/osdep/linux/blocklist.c
@@ -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);
diff --git a/util/setup.c b/util/setup.c
index 8aa5a39..5908498 100644
--- a/util/setup.c
+++ b/util/setup.c
@@ -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



^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH 03/15] grub-install: fix memory leak
  2016-06-29 21:43 [PATCH 00/15] Add missing SPARC support Eric Snowberg
  2016-06-29 21:43 ` [PATCH 01/15] sparc64: fix OF path names for sun4v systems Eric Snowberg
  2016-06-29 21:43 ` [PATCH 02/15] sparc64: Add blocklist GPT support for SPARC Eric Snowberg
@ 2016-06-29 21:43 ` Eric Snowberg
  2016-06-29 21:43 ` [PATCH 04/15] sparc64: Use the correct disk name in core.img Eric Snowberg
                   ` (12 subsequent siblings)
  15 siblings, 0 replies; 23+ messages in thread
From: Eric Snowberg @ 2016-06-29 21:43 UTC (permalink / raw)
  To: grub-devel; +Cc: Eric Snowberg

Fix memory leak

Signed-off-by: Eric Snowberg <eric.snowberg@oracle.com>
---
 util/grub-install.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/util/grub-install.c b/util/grub-install.c
index 6c89c2b..7394739 100644
--- a/util/grub-install.c
+++ b/util/grub-install.c
@@ -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);
-- 
1.7.1



^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH 04/15] sparc64: Use the correct disk name in core.img
  2016-06-29 21:43 [PATCH 00/15] Add missing SPARC support Eric Snowberg
                   ` (2 preceding siblings ...)
  2016-06-29 21:43 ` [PATCH 03/15] grub-install: fix memory leak Eric Snowberg
@ 2016-06-29 21:43 ` Eric Snowberg
  2016-06-29 21:43 ` [PATCH 05/15] ieee1275: fix segfault in grub-ofpathname Eric Snowberg
                   ` (11 subsequent siblings)
  15 siblings, 0 replies; 23+ messages in thread
From: Eric Snowberg @ 2016-06-29 21:43 UTC (permalink / raw)
  To: grub-devel; +Cc: 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.

Signed-off-by: Eric Snowberg <eric.snowberg@oracle.com>
---
 include/grub/emu/getroot.h |    2 ++
 util/grub-install.c        |   13 +++++++++++++
 util/probe.c               |    2 +-
 3 files changed, 16 insertions(+), 1 deletions(-)

diff --git a/include/grub/emu/getroot.h b/include/grub/emu/getroot.h
index 73fa2d3..4f04c7d 100644
--- a/include/grub/emu/getroot.h
+++ b/include/grub/emu/getroot.h
@@ -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 */
diff --git a/util/grub-install.c b/util/grub-install.c
index 7394739..f1ddf1c 100644
--- a/util/grub-install.c
+++ b/util/grub-install.c
@@ -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:
 		    {
diff --git a/util/probe.c b/util/probe.c
index fa7ca34..880cb5c 100644
--- a/util/probe.c
+++ b/util/probe.c
@@ -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;
-- 
1.7.1



^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH 05/15] ieee1275: fix segfault in grub-ofpathname
  2016-06-29 21:43 [PATCH 00/15] Add missing SPARC support Eric Snowberg
                   ` (3 preceding siblings ...)
  2016-06-29 21:43 ` [PATCH 04/15] sparc64: Use the correct disk name in core.img Eric Snowberg
@ 2016-06-29 21:43 ` Eric Snowberg
  2016-06-29 21:43 ` [PATCH 06/15] ieee1275: add nvme support within ofpath Eric Snowberg
                   ` (10 subsequent siblings)
  15 siblings, 0 replies; 23+ messages in thread
From: Eric Snowberg @ 2016-06-29 21:43 UTC (permalink / raw)
  To: grub-devel; +Cc: Eric Snowberg

fix segfault in grub-ofpathname

Signed-off-by: Eric Snowberg <eric.snowberg@oracle.com>
---
 util/ieee1275/grub-ofpathname.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/util/ieee1275/grub-ofpathname.c b/util/ieee1275/grub-ofpathname.c
index 8e5d766..300fbdd 100644
--- a/util/ieee1275/grub-ofpathname.c
+++ b/util/ieee1275/grub-ofpathname.c
@@ -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);
 
-- 
1.7.1



^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH 06/15] ieee1275: add nvme support within ofpath
  2016-06-29 21:43 [PATCH 00/15] Add missing SPARC support Eric Snowberg
                   ` (4 preceding siblings ...)
  2016-06-29 21:43 ` [PATCH 05/15] ieee1275: fix segfault in grub-ofpathname Eric Snowberg
@ 2016-06-29 21:43 ` Eric Snowberg
  2016-06-29 21:43 ` [PATCH 07/15] ofdisk: memory corruption fix Eric Snowberg
                   ` (9 subsequent siblings)
  15 siblings, 0 replies; 23+ messages in thread
From: Eric Snowberg @ 2016-06-29 21:43 UTC (permalink / raw)
  To: grub-devel; +Cc: Eric Snowberg

Add nvme support within ofpath

Signed-off-by: Eric Snowberg <eric.snowberg@oracle.com>
---
 grub-core/osdep/linux/ofpath.c |   46 ++++++++++++++++++++++++++++++++++++++++
 1 files changed, 46 insertions(+), 0 deletions(-)

diff --git a/grub-core/osdep/linux/ofpath.c b/grub-core/osdep/linux/ofpath.c
index 0994e08..4c1c95b 100644
--- a/grub-core/osdep/linux/ofpath.c
+++ b/grub-core/osdep/linux/ofpath.c
@@ -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);
-- 
1.7.1



^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH 07/15] ofdisk: memory corruption fix
  2016-06-29 21:43 [PATCH 00/15] Add missing SPARC support Eric Snowberg
                   ` (5 preceding siblings ...)
  2016-06-29 21:43 ` [PATCH 06/15] ieee1275: add nvme support within ofpath Eric Snowberg
@ 2016-06-29 21:43 ` Eric Snowberg
  2016-06-29 21:43 ` [PATCH 08/15] ofdisk: move open logic Eric Snowberg
                   ` (8 subsequent siblings)
  15 siblings, 0 replies; 23+ messages in thread
From: Eric Snowberg @ 2016-06-29 21:43 UTC (permalink / raw)
  To: grub-devel; +Cc: 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.

Signed-off-by: Eric Snowberg <eric.snowberg@oracle.com>
---
 grub-core/disk/ieee1275/ofdisk.c |   30 +++++++++++++-----------------
 1 files changed, 13 insertions(+), 17 deletions(-)

diff --git a/grub-core/disk/ieee1275/ofdisk.c b/grub-core/disk/ieee1275/ofdisk.c
index 235c0fe..18d2e95 100644
--- a/grub-core/disk/ieee1275/ofdisk.c
+++ b/grub-core/disk/ieee1275/ofdisk.c
@@ -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);
-- 
1.7.1



^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH 08/15] ofdisk: move open logic
  2016-06-29 21:43 [PATCH 00/15] Add missing SPARC support Eric Snowberg
                   ` (6 preceding siblings ...)
  2016-06-29 21:43 ` [PATCH 07/15] ofdisk: memory corruption fix Eric Snowberg
@ 2016-06-29 21:43 ` Eric Snowberg
  2016-06-29 21:43 ` [PATCH 09/15] ieee1275: ofdisk - don't continue to query block-size after we have it Eric Snowberg
                   ` (7 subsequent siblings)
  15 siblings, 0 replies; 23+ messages in thread
From: Eric Snowberg @ 2016-06-29 21:43 UTC (permalink / raw)
  To: grub-devel; +Cc: 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.

Signed-off-by: Eric Snowberg <eric.snowberg@oracle.com>
---
 grub-core/disk/ieee1275/ofdisk.c |   29 ++++++++++++++---------------
 1 files changed, 14 insertions(+), 15 deletions(-)

diff --git a/grub-core/disk/ieee1275/ofdisk.c b/grub-core/disk/ieee1275/ofdisk.c
index 18d2e95..956f675 100644
--- a/grub-core/disk/ieee1275/ofdisk.c
+++ b/grub-core/disk/ieee1275/ofdisk.c
@@ -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)
-- 
1.7.1



^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH 09/15] ieee1275: ofdisk - don't continue to query block-size after we have it
  2016-06-29 21:43 [PATCH 00/15] Add missing SPARC support Eric Snowberg
                   ` (7 preceding siblings ...)
  2016-06-29 21:43 ` [PATCH 08/15] ofdisk: move open logic Eric Snowberg
@ 2016-06-29 21:43 ` Eric Snowberg
  2016-06-29 21:43 ` [PATCH 10/15] ofdisk: refactor open logic Eric Snowberg
                   ` (6 subsequent siblings)
  15 siblings, 0 replies; 23+ messages in thread
From: Eric Snowberg @ 2016-06-29 21:43 UTC (permalink / raw)
  To: grub-devel; +Cc: 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.

Signed-off-by: Eric Snowberg <eric.snowberg@oracle.com>
---
 grub-core/disk/ieee1275/ofdisk.c |   26 +++++++++++++-------------
 1 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/grub-core/disk/ieee1275/ofdisk.c b/grub-core/disk/ieee1275/ofdisk.c
index 956f675..6eaa044 100644
--- a/grub-core/disk/ieee1275/ofdisk.c
+++ b/grub-core/disk/ieee1275/ofdisk.c
@@ -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;
     }
 
-- 
1.7.1



^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH 10/15] ofdisk: refactor open logic
  2016-06-29 21:43 [PATCH 00/15] Add missing SPARC support Eric Snowberg
                   ` (8 preceding siblings ...)
  2016-06-29 21:43 ` [PATCH 09/15] ieee1275: ofdisk - don't continue to query block-size after we have it Eric Snowberg
@ 2016-06-29 21:43 ` Eric Snowberg
  2016-06-29 21:43 ` [PATCH 11/15] sparc64: boot performance improvements Eric Snowberg
                   ` (5 subsequent siblings)
  15 siblings, 0 replies; 23+ messages in thread
From: Eric Snowberg @ 2016-06-29 21:43 UTC (permalink / raw)
  To: grub-devel; +Cc: 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.

Signed-off-by: Eric Snowberg <eric.snowberg@oracle.com>
---
 grub-core/disk/ieee1275/ofdisk.c |   47 +++++++++++++++++++++++--------------
 1 files changed, 29 insertions(+), 18 deletions(-)

diff --git a/grub-core/disk/ieee1275/ofdisk.c b/grub-core/disk/ieee1275/ofdisk.c
index 6eaa044..6789072 100644
--- a/grub-core/disk/ieee1275/ofdisk.c
+++ b/grub-core/disk/ieee1275/ofdisk.c
@@ -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;
+}
-- 
1.7.1



^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH 11/15] sparc64: boot performance improvements
  2016-06-29 21:43 [PATCH 00/15] Add missing SPARC support Eric Snowberg
                   ` (9 preceding siblings ...)
  2016-06-29 21:43 ` [PATCH 10/15] ofdisk: refactor open logic Eric Snowberg
@ 2016-06-29 21:43 ` Eric Snowberg
  2016-06-29 21:43 ` [PATCH 12/15] ofdisk: only add aliases that exist Eric Snowberg
                   ` (4 subsequent siblings)
  15 siblings, 0 replies; 23+ messages in thread
From: Eric Snowberg @ 2016-06-29 21:43 UTC (permalink / raw)
  To: grub-devel; +Cc: 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.

Signed-off-by: Eric Snowberg <eric.snowberg@oracle.com>
---
 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(-)

diff --git a/grub-core/disk/ieee1275/ofdisk.c b/grub-core/disk/ieee1275/ofdisk.c
index 6789072..9c6b8b0 100644
--- a/grub-core/disk/ieee1275/ofdisk.c
+++ b/grub-core/disk/ieee1275/ofdisk.c
@@ -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;
 }
diff --git a/grub-core/kern/ieee1275/cmain.c b/grub-core/kern/ieee1275/cmain.c
index 3e12e6b..b016598 100644
--- a/grub-core/kern/ieee1275/cmain.c
+++ b/grub-core/kern/ieee1275/cmain.c
@@ -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
diff --git a/include/grub/ieee1275/ieee1275.h b/include/grub/ieee1275/ieee1275.h
index 8e42513..b79e97b 100644
--- a/include/grub/ieee1275/ieee1275.h
+++ b/include/grub/ieee1275/ieee1275.h
@@ -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);
-- 
1.7.1



^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH 12/15] ofdisk: only add aliases that exist
  2016-06-29 21:43 [PATCH 00/15] Add missing SPARC support Eric Snowberg
                   ` (10 preceding siblings ...)
  2016-06-29 21:43 ` [PATCH 11/15] sparc64: boot performance improvements Eric Snowberg
@ 2016-06-29 21:43 ` Eric Snowberg
  2016-06-29 21:43 ` [PATCH 13/15] sparc64: add disks that don't have a devalias to the device list Eric Snowberg
                   ` (3 subsequent siblings)
  15 siblings, 0 replies; 23+ messages in thread
From: Eric Snowberg @ 2016-06-29 21:43 UTC (permalink / raw)
  To: grub-devel; +Cc: 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.

Signed-off-by: Eric Snowberg <eric.snowberg@oracle.com>
---
 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(-)

diff --git a/grub-core/disk/ieee1275/ofdisk.c b/grub-core/disk/ieee1275/ofdisk.c
index 9c6b8b0..42d038c 100644
--- a/grub-core/disk/ieee1275/ofdisk.c
+++ b/grub-core/disk/ieee1275/ofdisk.c
@@ -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;
+}
diff --git a/grub-core/kern/ieee1275/cmain.c b/grub-core/kern/ieee1275/cmain.c
index b016598..59271ae 100644
--- a/grub-core/kern/ieee1275/cmain.c
+++ b/grub-core/kern/ieee1275/cmain.c
@@ -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)
 	{
diff --git a/grub-core/kern/ieee1275/ieee1275.c b/grub-core/kern/ieee1275/ieee1275.c
index 9821702..88999e0 100644
--- a/grub-core/kern/ieee1275/ieee1275.c
+++ b/grub-core/kern/ieee1275/ieee1275.c
@@ -607,3 +607,91 @@ grub_ieee1275_milliseconds (grub_uint32_t *msecs)
   *msecs = args.msecs;
   return 0;
 }
+
+int
+grub_ieee1275_set_address (grub_ieee1275_ihandle_t ihandle,
+                           grub_uint32_t target, grub_uint32_t lun)
+{
+  struct set_address
+  {
+    struct grub_ieee1275_common_hdr common;
+    grub_ieee1275_cell_t method;
+    grub_ieee1275_cell_t ihandle;
+    grub_ieee1275_cell_t tgt;
+    grub_ieee1275_cell_t lun;
+    grub_ieee1275_cell_t catch_result;
+  }
+  args;
+
+  INIT_IEEE1275_COMMON (&args.common, "call-method", 4, 2);
+
+  /* IEEE Standard for Boot (Initialization Configuration)
+     Firmware: Core Requirements and Practices
+     E.3.2.2 Bus-specific methods for bus nodes
+
+     A package implementing the scsi-2 device type shall implement the
+     following bus-specific method:
+
+     set-address ( unit# target# -- )
+     Sets the SCSI target number (0x0..0xf) and unit number (0..7) to which
+     subsequent commands apply.
+  */
+  args.method = (grub_ieee1275_cell_t) "set-address";
+  args.ihandle = ihandle;
+  args.tgt = target;
+  args.lun = lun;
+
+  if (IEEE1275_CALL_ENTRY_FN (&args) == -1)
+    return -1;
+
+  return args.catch_result;
+}
+
+int
+grub_ieee1275_no_data_command (grub_ieee1275_ihandle_t ihandle,
+                               const void *cmd_addr, grub_ssize_t *result)
+{
+  struct set_address
+  {
+    struct grub_ieee1275_common_hdr common;
+    grub_ieee1275_cell_t method;
+    grub_ieee1275_cell_t ihandle;
+    grub_ieee1275_cell_t cmd_addr;
+    grub_ieee1275_cell_t error;
+    grub_ieee1275_cell_t catch_result;
+  }
+  args;
+
+  INIT_IEEE1275_COMMON (&args.common, "call-method", 3, 2);
+  /* IEEE 1275-1994 Standard for Boot (Initialization Configuration)
+     Firmware: Core Requirements and Practices
+
+     E.3.2.2 Bus-specific methods for bus nodes
+
+     A package implementing the scsi-2 device type shall implement the
+     following bus-specific method:
+
+     no-data-command ( cmd-addr -- error? )
+     Executes a simple SCSI command, automatically retrying under
+     certain conditions.  cmd-addr is the address of a 6-byte command buffer
+     containing an SCSI command that does not have a data transfer phase.
+     Executes the command, retrying indefinitely with the same retry criteria
+     as retry-command.
+
+     error? is nonzero if an error occurred, zero otherwise.
+     NOTE no-data-command is a convenience function. It provides
+     no capabilities that are not present in retry-command, but for
+     those commands that meet its restrictions, it is easier to use.
+   */
+  args.method = (grub_ieee1275_cell_t) "no-data-command";
+  args.ihandle = ihandle;
+  args.cmd_addr = (grub_ieee1275_cell_t) cmd_addr;
+
+  if (IEEE1275_CALL_ENTRY_FN (&args) == -1)
+    return -1;
+
+  if (result)
+    *result = args.error;
+
+  return args.catch_result;
+}
diff --git a/grub-core/kern/sparc64/ieee1275/ieee1275.c b/grub-core/kern/sparc64/ieee1275/ieee1275.c
index 53be692..16801f8 100644
--- a/grub-core/kern/sparc64/ieee1275/ieee1275.c
+++ b/grub-core/kern/sparc64/ieee1275/ieee1275.c
@@ -18,6 +18,7 @@
 
 #include <grub/ieee1275/ieee1275.h>
 #include <grub/types.h>
+#include <grub/misc.h>
 
 /* Sun specific ieee1275 interfaces used by GRUB.  */
 
@@ -89,3 +90,113 @@ grub_ieee1275_alloc_physmem (grub_addr_t *paddr, grub_size_t size,
 
   return args.catch_result;
 }
+
+int
+grub_ieee1275_set_sas_address (grub_ieee1275_ihandle_t ihandle,
+                               const char *disk_name,
+                               grub_uint64_t lun)
+{
+  struct dev_set_address
+  {
+    struct grub_ieee1275_common_hdr common;
+    grub_ieee1275_cell_t method;
+    grub_ieee1275_cell_t ihandle;
+    grub_ieee1275_cell_t tgt_h;
+    grub_ieee1275_cell_t tgt_l;
+    grub_ieee1275_cell_t lun_h;
+    grub_ieee1275_cell_t lun_l;
+    grub_ieee1275_cell_t catch_result;
+  }
+  args;
+
+  grub_uint32_t sas_phy = 0, tgt = 0;
+  grub_uint64_t wwn = 0;
+
+  if (disk_name == 0)
+    return -1;
+
+  INIT_IEEE1275_COMMON (&args.common, "call-method", 6, 1);
+  args.method = (grub_ieee1275_cell_t) "set-address";
+  args.ihandle = ihandle;
+  args.lun_l = lun & 0xffffffff;
+  args.lun_h = lun >> 32;
+
+  /* PHY addressing */
+  if (*disk_name == 'p')
+    {
+      /*         Bit #   33222222 22221111 11111100 00000000
+                         10987654 32109876 54321098 76543210
+
+         sas.hi cell:    00000000 00000000 00000000 00000000
+         sas.lo cell:    00000000 00000001 jjjjjjjj iiiiiiii
+         lun.hi cell:    uuuuuuuu uuuuuuuu uuuuuuuu uuuuuuuu
+         lun.lo cell:    uuuuuuuu uuuuuuuu uuuuuuuu uuuuuuuu
+
+         00..00          Bits with the value zero
+         ii..ii          8-bit unsigned number phy identifier in the range
+                         of 0..FE .
+         jj..jj          Expander identifier. Either zero (indicating the PHY number
+                         iiiiiiii is on the SAS adapter itself) or identifies the PHY
+                         connecting to the expander, in which case iiiiiiii identifies
+                         a PHY on a SAS expander. In the non-zero case, jjjjjjjj is an
+                         8-bit unsigned number of the PHY plus one, in the range 1..FF
+         uu..uu          64-bit unsigned number logical unit number
+      */
+      sas_phy = grub_strtoul (disk_name + 1, 0, 16);
+      args.tgt_l = 0x10000 | sas_phy;
+      args.tgt_h = 0;
+    }
+  /* WWN addressing */
+  else if ((*disk_name =='w') && (*(disk_name + 1) == '5'))
+    {
+      /*          Bit #   33222222 22221111 11111100 00000000
+                          10987654 32109876 54321098 76543210
+
+          sas.hi cell:    0101vvvv vvvvvvvv vvvvvvvv vvvvssss
+          sas.lo cell:    ssssssss ssssssss ssssssss ssssssss
+          lun.hi cell:    uuuuuuuu uuuuuuuu uuuuuuuu uuuuuuuu
+          lun.lo cell:    uuuuuuuu uuuuuuuu uuuuuuuu uuuuuuuu
+
+          0101            The value "5" in the high-order NAA nibble
+          vv..vv          24-bit IEEE Organization ID
+          ss..ss          36-bit unsigned device serial number
+          uu..uu          64-bit unsigned number logical unit number
+      */
+      wwn = grub_strtoull (disk_name + 1, 0, 16);
+      args.tgt_l = wwn & 0xffffffff;
+      args.tgt_h = wwn >> 32;
+    }
+   /* Target LUN addressing */
+   else if (grub_isxdigit (*disk_name))
+    {
+      /* Deprecated
+                  Bit #   33222222 22221111 11111100 00000000
+                          10987654 32109876 54321098 76543210
+
+          sas.hi cell:    00000000 00000000 00000000 00000000
+          sas.lo cell:    00000000 00000000 00000000 tttttttt
+          lun.hi cell:    uuuuuuuu uuuuuuuu uuuuuuuu uuuuuuuu
+          lun.lo cell:    uuuuuuuu uuuuuuuu uuuuuuuu uuuuuuuu
+
+          00..00          Bits with the value zero
+          tt..tt          8-bit unsigned number target identifier in the range
+                          of 0..FF
+          uu..uu          64-bit unsigned number logical unit number
+      */
+      tgt = grub_strtol (disk_name, 0, 16);
+      if (tgt <= 0xff)
+        {
+          args.tgt_l = tgt;
+          args.tgt_h = 0;
+        }
+      else
+        return -1;
+    }
+  else
+    return -1;
+
+  if (IEEE1275_CALL_ENTRY_FN (&args) == -1)
+    return -1;
+
+  return args.catch_result;
+}
diff --git a/include/grub/ieee1275/ieee1275.h b/include/grub/ieee1275/ieee1275.h
index b79e97b..7644956 100644
--- a/include/grub/ieee1275/ieee1275.h
+++ b/include/grub/ieee1275/ieee1275.h
@@ -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);
 
diff --git a/include/grub/sparc64/ieee1275/ieee1275.h b/include/grub/sparc64/ieee1275/ieee1275.h
index 32c77f8..632eb87 100644
--- a/include/grub/sparc64/ieee1275/ieee1275.h
+++ b/include/grub/sparc64/ieee1275/ieee1275.h
@@ -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);
 
-- 
1.7.1



^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH 13/15] sparc64: add disks that don't have a devalias to the device list
  2016-06-29 21:43 [PATCH 00/15] Add missing SPARC support Eric Snowberg
                   ` (11 preceding siblings ...)
  2016-06-29 21:43 ` [PATCH 12/15] ofdisk: only add aliases that exist Eric Snowberg
@ 2016-06-29 21:43 ` Eric Snowberg
  2016-06-29 21:43 ` [PATCH 14/15] parser: Remove escape from the state transitions Eric Snowberg
                   ` (2 subsequent siblings)
  15 siblings, 0 replies; 23+ messages in thread
From: Eric Snowberg @ 2016-06-29 21:43 UTC (permalink / raw)
  To: grub-devel; +Cc: 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.

Signed-off-by: Eric Snowberg <eric.snowberg@oracle.com>
---
 grub-core/disk/ieee1275/ofdisk.c |  144 ++++++++++++++++++++++++++++++++++++++
 1 files changed, 144 insertions(+), 0 deletions(-)

diff --git a/grub-core/disk/ieee1275/ofdisk.c b/grub-core/disk/ieee1275/ofdisk.c
index 42d038c..17d082b 100644
--- a/grub-core/disk/ieee1275/ofdisk.c
+++ b/grub-core/disk/ieee1275/ofdisk.c
@@ -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)
-- 
1.7.1



^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH 14/15] parser: Remove escape from the state transitions
  2016-06-29 21:43 [PATCH 00/15] Add missing SPARC support Eric Snowberg
                   ` (12 preceding siblings ...)
  2016-06-29 21:43 ` [PATCH 13/15] sparc64: add disks that don't have a devalias to the device list Eric Snowberg
@ 2016-06-29 21:43 ` Eric Snowberg
  2016-06-29 21:43 ` [PATCH 15/15] sparc64: ignore hypervisor reboot memory block device Eric Snowberg
  2016-07-01  6:52 ` [PATCH 00/15] Add missing SPARC support Daniel Kiper
  15 siblings, 0 replies; 23+ messages in thread
From: Eric Snowberg @ 2016-06-29 21:43 UTC (permalink / raw)
  To: grub-devel; +Cc: 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.

Signed-off-by: Eric Snowberg <eric.snowberg@oracle.com>
---
 grub-core/kern/parser.c |    1 -
 1 files changed, 0 insertions(+), 1 deletions(-)

diff --git a/grub-core/kern/parser.c b/grub-core/kern/parser.c
index 78175aa..be88baa 100644
--- a/grub-core/kern/parser.c
+++ b/grub-core/kern/parser.c
@@ -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},
 
-- 
1.7.1



^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH 15/15] sparc64: ignore hypervisor reboot memory block device
  2016-06-29 21:43 [PATCH 00/15] Add missing SPARC support Eric Snowberg
                   ` (13 preceding siblings ...)
  2016-06-29 21:43 ` [PATCH 14/15] parser: Remove escape from the state transitions Eric Snowberg
@ 2016-06-29 21:43 ` Eric Snowberg
  2016-07-01  6:52 ` [PATCH 00/15] Add missing SPARC support Daniel Kiper
  15 siblings, 0 replies; 23+ messages in thread
From: Eric Snowberg @ 2016-06-29 21:43 UTC (permalink / raw)
  To: grub-devel; +Cc: 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.

Signed-off-by: Eric Snowberg <eric.snowberg@oracle.com>
---
 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(-)

diff --git a/grub-core/disk/ieee1275/ofdisk.c b/grub-core/disk/ieee1275/ofdisk.c
index 17d082b..5405be8 100644
--- a/grub-core/disk/ieee1275/ofdisk.c
+++ b/grub-core/disk/ieee1275/ofdisk.c
@@ -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;
     }
diff --git a/grub-core/kern/ieee1275/cmain.c b/grub-core/kern/ieee1275/cmain.c
index 59271ae..844862f 100644
--- a/grub-core/kern/ieee1275/cmain.c
+++ b/grub-core/kern/ieee1275/cmain.c
@@ -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)
diff --git a/include/grub/ieee1275/ieee1275.h b/include/grub/ieee1275/ieee1275.h
index 7644956..fdd123d 100644
--- a/include/grub/ieee1275/ieee1275.h
+++ b/include/grub/ieee1275/ieee1275.h
@@ -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);
-- 
1.7.1



^ permalink raw reply related	[flat|nested] 23+ messages in thread

* Re: [PATCH 00/15] Add missing SPARC support
  2016-06-29 21:43 [PATCH 00/15] Add missing SPARC support Eric Snowberg
                   ` (14 preceding siblings ...)
  2016-06-29 21:43 ` [PATCH 15/15] sparc64: ignore hypervisor reboot memory block device Eric Snowberg
@ 2016-07-01  6:52 ` Daniel Kiper
  2016-07-26 10:24   ` Daniel Kiper
  15 siblings, 1 reply; 23+ messages in thread
From: Daniel Kiper @ 2016-07-01  6:52 UTC (permalink / raw)
  To: The development of GNU GRUB; +Cc: Eric Snowberg, daniel.kiper

On Wed, Jun 29, 2016 at 02:43:13PM -0700, Eric Snowberg wrote:
> 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.

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

Next time please CC me directly too.

Daniel


^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH 00/15] Add missing SPARC support
  2016-07-01  6:52 ` [PATCH 00/15] Add missing SPARC support Daniel Kiper
@ 2016-07-26 10:24   ` Daniel Kiper
  0 siblings, 0 replies; 23+ messages in thread
From: Daniel Kiper @ 2016-07-26 10:24 UTC (permalink / raw)
  To: Daniel Kiper; +Cc: The development of GNU GRUB, Eric Snowberg

On Fri, Jul 01, 2016 at 08:52:11AM +0200, Daniel Kiper wrote:
> On Wed, Jun 29, 2016 at 02:43:13PM -0700, Eric Snowberg wrote:
> > 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.
>
> 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


^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH 02/15] sparc64: Add blocklist GPT support for SPARC
  2016-06-29 21:43 ` [PATCH 02/15] sparc64: Add blocklist GPT support for SPARC Eric Snowberg
@ 2017-05-10 22:42   ` Vladimir 'phcoder' Serbinenko
  2017-05-10 23:20     ` Eric Snowberg
  0 siblings, 1 reply; 23+ messages in thread
From: Vladimir 'phcoder' Serbinenko @ 2017-05-10 22:42 UTC (permalink / raw)
  To: The development of GNU GRUB; +Cc: Eric Snowberg

[-- Attachment #1: Type: text/plain, Size: 3264 bytes --]

On Wed, Jun 29, 2016, 23:47 Eric Snowberg <eric.snowberg@oracle.com> 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.
>
> Signed-off-by: Eric Snowberg <eric.snowberg@oracle.com>
> ---
>  grub-core/osdep/linux/blocklist.c |    5 +++++
>  util/setup.c                      |   12 +++++++++---
>  2 files changed, 14 insertions(+), 3 deletions(-)
>
> diff --git a/grub-core/osdep/linux/blocklist.c
> b/grub-core/osdep/linux/blocklist.c
> index c77d608..caf8d4e 100644
> --- a/grub-core/osdep/linux/blocklist.c
> +++ b/grub-core/osdep/linux/blocklist.c
> @@ -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)

>    /* 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);
> diff --git a/util/setup.c b/util/setup.c
> index 8aa5a39..5908498 100644
> --- a/util/setup.c
> +++ b/util/setup.c
> @@ -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
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel
>

[-- Attachment #2: Type: text/html, Size: 4368 bytes --]

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH 02/15] sparc64: Add blocklist GPT support for SPARC
  2017-05-10 22:42   ` Vladimir 'phcoder' Serbinenko
@ 2017-05-10 23:20     ` Eric Snowberg
  2017-05-11  0:37       ` Vladimir 'phcoder' Serbinenko
  0 siblings, 1 reply; 23+ messages in thread
From: Eric Snowberg @ 2017-05-10 23:20 UTC (permalink / raw)
  To: The development of GNU GRUB


> On May 10, 2017, at 4:42 PM, Vladimir 'phcoder' Serbinenko <phcoder@gmail.com> wrote:
> 
> 
> 
> On Wed, Jun 29, 2016, 23:47 Eric Snowberg <eric.snowberg@oracle.com> 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.
> 
> Signed-off-by: Eric Snowberg <eric.snowberg@oracle.com>
> ---
>  grub-core/osdep/linux/blocklist.c |    5 +++++
>  util/setup.c                      |   12 +++++++++---
>  2 files changed, 14 insertions(+), 3 deletions(-)
> 
> diff --git a/grub-core/osdep/linux/blocklist.c b/grub-core/osdep/linux/blocklist.c
> index c77d608..caf8d4e 100644
> --- a/grub-core/osdep/linux/blocklist.c
> +++ b/grub-core/osdep/linux/blocklist.c
> @@ -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.

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

> 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?

>    /* 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);
> diff --git a/util/setup.c b/util/setup.c
> index 8aa5a39..5908498 100644
> --- a/util/setup.c
> +++ b/util/setup.c
> @@ -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
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel



^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH 02/15] sparc64: Add blocklist GPT support for SPARC
  2017-05-10 23:20     ` Eric Snowberg
@ 2017-05-11  0:37       ` Vladimir 'phcoder' Serbinenko
  2017-05-11  0:40         ` Vladimir 'phcoder' Serbinenko
  0 siblings, 1 reply; 23+ messages in thread
From: Vladimir 'phcoder' Serbinenko @ 2017-05-11  0:37 UTC (permalink / raw)
  To: The development of GNU GRUB

[-- Attachment #1: Type: text/plain, Size: 4444 bytes --]

On Thu, May 11, 2017, 01:21 Eric Snowberg <eric.snowberg@oracle.com> wrote:

>
> > On May 10, 2017, at 4:42 PM, Vladimir 'phcoder' Serbinenko <
> phcoder@gmail.com> wrote:
> >
> >
> >
> > On Wed, Jun 29, 2016, 23:47 Eric Snowberg <eric.snowberg@oracle.com>
> 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.
> >
> > Signed-off-by: Eric Snowberg <eric.snowberg@oracle.com>
> > ---
> >  grub-core/osdep/linux/blocklist.c |    5 +++++
> >  util/setup.c                      |   12 +++++++++---
> >  2 files changed, 14 insertions(+), 3 deletions(-)
> >
> > diff --git a/grub-core/osdep/linux/blocklist.c
> b/grub-core/osdep/linux/blocklist.c
> > index c77d608..caf8d4e 100644
> > --- a/grub-core/osdep/linux/blocklist.c
> > +++ b/grub-core/osdep/linux/blocklist.c
> > @@ -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.
>
> 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.

>
> > 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

>
>
> >    /* 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);
> > diff --git a/util/setup.c b/util/setup.c
> > index 8aa5a39..5908498 100644
> > --- a/util/setup.c
> > +++ b/util/setup.c
> > @@ -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
> > Grub-devel@gnu.org
> > https://lists.gnu.org/mailman/listinfo/grub-devel
> > _______________________________________________
> > Grub-devel mailing list
> > Grub-devel@gnu.org
> > https://lists.gnu.org/mailman/listinfo/grub-devel
>
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel
>

[-- Attachment #2: Type: text/html, Size: 6471 bytes --]

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH 02/15] sparc64: Add blocklist GPT support for SPARC
  2017-05-11  0:37       ` Vladimir 'phcoder' Serbinenko
@ 2017-05-11  0:40         ` Vladimir 'phcoder' Serbinenko
  2017-05-11  2:05           ` Eric Snowberg
  0 siblings, 1 reply; 23+ messages in thread
From: Vladimir 'phcoder' Serbinenko @ 2017-05-11  0:40 UTC (permalink / raw)
  To: The development of GRUB 2

[-- Attachment #1: Type: text/plain, Size: 4708 bytes --]

On Thu, May 11, 2017, 02:37 Vladimir 'phcoder' Serbinenko <phcoder@gmail.com>
wrote:

>
>
> On Thu, May 11, 2017, 01:21 Eric Snowberg <eric.snowberg@oracle.com>
> wrote:
>
>>
>> > On May 10, 2017, at 4:42 PM, Vladimir 'phcoder' Serbinenko <
>> phcoder@gmail.com> wrote:
>> >
>> >
>> >
>> > On Wed, Jun 29, 2016, 23:47 Eric Snowberg <eric.snowberg@oracle.com>
>> 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.
>> >
>> > Signed-off-by: Eric Snowberg <eric.snowberg@oracle.com>
>> > ---
>> >  grub-core/osdep/linux/blocklist.c |    5 +++++
>> >  util/setup.c                      |   12 +++++++++---
>> >  2 files changed, 14 insertions(+), 3 deletions(-)
>> >
>> > diff --git a/grub-core/osdep/linux/blocklist.c
>> b/grub-core/osdep/linux/blocklist.c
>> > index c77d608..caf8d4e 100644
>> > --- a/grub-core/osdep/linux/blocklist.c
>> > +++ b/grub-core/osdep/linux/blocklist.c
>> > @@ -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.
>>
>> 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.
>
>>
>> > 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

>
>>
>> >    /* 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);
>> > diff --git a/util/setup.c b/util/setup.c
>> > index 8aa5a39..5908498 100644
>> > --- a/util/setup.c
>> > +++ b/util/setup.c
>> > @@ -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
>> > Grub-devel@gnu.org
>> > https://lists.gnu.org/mailman/listinfo/grub-devel
>> > _______________________________________________
>> > Grub-devel mailing list
>> > Grub-devel@gnu.org
>> > https://lists.gnu.org/mailman/listinfo/grub-devel
>>
>>
>> _______________________________________________
>> Grub-devel mailing list
>> Grub-devel@gnu.org
>> https://lists.gnu.org/mailman/listinfo/grub-devel
>>
>

[-- Attachment #2: Type: text/html, Size: 6991 bytes --]

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH 02/15] sparc64: Add blocklist GPT support for SPARC
  2017-05-11  0:40         ` Vladimir 'phcoder' Serbinenko
@ 2017-05-11  2:05           ` Eric Snowberg
  0 siblings, 0 replies; 23+ messages in thread
From: Eric Snowberg @ 2017-05-11  2:05 UTC (permalink / raw)
  To: The development of GNU GRUB


> On May 10, 2017, at 6:40 PM, Vladimir 'phcoder' Serbinenko <phcoder@gmail.com> wrote:
> 
> 
> 
> On Thu, May 11, 2017, 02:37 Vladimir 'phcoder' Serbinenko <phcoder@gmail.com> wrote:
> 
> 
> On Thu, May 11, 2017, 01:21 Eric Snowberg <eric.snowberg@oracle.com> wrote:
> 
> > On May 10, 2017, at 4:42 PM, Vladimir 'phcoder' Serbinenko <phcoder@gmail.com> wrote:
> >
> >
> >
> > On Wed, Jun 29, 2016, 23:47 Eric Snowberg <eric.snowberg@oracle.com> 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.
> >
> > Signed-off-by: Eric Snowberg <eric.snowberg@oracle.com>
> > ---
> >  grub-core/osdep/linux/blocklist.c |    5 +++++
> >  util/setup.c                      |   12 +++++++++---
> >  2 files changed, 14 insertions(+), 3 deletions(-)
> >
> > diff --git a/grub-core/osdep/linux/blocklist.c b/grub-core/osdep/linux/blocklist.c
> > index c77d608..caf8d4e 100644
> > --- a/grub-core/osdep/linux/blocklist.c
> > +++ b/grub-core/osdep/linux/blocklist.c
> > @@ -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.
> 
> 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.
> 
> > 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.

> 
> 
> >    /* 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);
> > diff --git a/util/setup.c b/util/setup.c
> > index 8aa5a39..5908498 100644
> > --- a/util/setup.c
> > +++ b/util/setup.c
> > @@ -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
> > Grub-devel@gnu.org
> > https://lists.gnu.org/mailman/listinfo/grub-devel
> > _______________________________________________
> > Grub-devel mailing list
> > Grub-devel@gnu.org
> > https://lists.gnu.org/mailman/listinfo/grub-devel
> 
> 
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel



^ permalink raw reply	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2017-05-11  2:05 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-29 21:43 [PATCH 00/15] Add missing SPARC support Eric Snowberg
2016-06-29 21:43 ` [PATCH 01/15] sparc64: fix OF path names for sun4v systems Eric Snowberg
2016-06-29 21:43 ` [PATCH 02/15] sparc64: Add blocklist GPT support for SPARC Eric Snowberg
2017-05-10 22:42   ` Vladimir 'phcoder' Serbinenko
2017-05-10 23:20     ` Eric Snowberg
2017-05-11  0:37       ` Vladimir 'phcoder' Serbinenko
2017-05-11  0:40         ` Vladimir 'phcoder' Serbinenko
2017-05-11  2:05           ` Eric Snowberg
2016-06-29 21:43 ` [PATCH 03/15] grub-install: fix memory leak Eric Snowberg
2016-06-29 21:43 ` [PATCH 04/15] sparc64: Use the correct disk name in core.img Eric Snowberg
2016-06-29 21:43 ` [PATCH 05/15] ieee1275: fix segfault in grub-ofpathname Eric Snowberg
2016-06-29 21:43 ` [PATCH 06/15] ieee1275: add nvme support within ofpath Eric Snowberg
2016-06-29 21:43 ` [PATCH 07/15] ofdisk: memory corruption fix Eric Snowberg
2016-06-29 21:43 ` [PATCH 08/15] ofdisk: move open logic Eric Snowberg
2016-06-29 21:43 ` [PATCH 09/15] ieee1275: ofdisk - don't continue to query block-size after we have it Eric Snowberg
2016-06-29 21:43 ` [PATCH 10/15] ofdisk: refactor open logic Eric Snowberg
2016-06-29 21:43 ` [PATCH 11/15] sparc64: boot performance improvements Eric Snowberg
2016-06-29 21:43 ` [PATCH 12/15] ofdisk: only add aliases that exist Eric Snowberg
2016-06-29 21:43 ` [PATCH 13/15] sparc64: add disks that don't have a devalias to the device list Eric Snowberg
2016-06-29 21:43 ` [PATCH 14/15] parser: Remove escape from the state transitions Eric Snowberg
2016-06-29 21:43 ` [PATCH 15/15] sparc64: ignore hypervisor reboot memory block device Eric Snowberg
2016-07-01  6:52 ` [PATCH 00/15] Add missing SPARC support Daniel Kiper
2016-07-26 10:24   ` Daniel Kiper

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.