nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

Blame SOURCES/0154-Support-Openfirmware-disks-with-non-512B-sectors.patch

f96e0b
From 2274f0f3de80c1f36668815ce3f79f73716eda73 Mon Sep 17 00:00:00 2001
f96e0b
From: Vladimir 'phcoder' Serbinenko <phcoder@gmail.com>
f96e0b
Date: Tue, 19 Feb 2013 09:10:26 +0100
f96e0b
Subject: [PATCH 154/482] 	Support Openfirmware disks with non-512B
f96e0b
 sectors.
f96e0b
f96e0b
	* grub-core/disk/ieee1275/ofdisk.c (grub_ofdisk_open): Get the block
f96e0b
	size of the disk.
f96e0b
	* (grub_ofdisk_get_block_size): New function.
f96e0b
	* (grub_ofdisk_prepare): Use the correct block size.
f96e0b
	* (grub_ofdisk_read): Likewise.
f96e0b
	* (grub_ofdisk_write): Likewise.
f96e0b
	* include/grub/ieee1275/ofdisk.h (grub_ofdisk_get_block_size):
f96e0b
	New proto.
f96e0b
---
f96e0b
 ChangeLog                        | 13 +++++++++
f96e0b
 grub-core/disk/ieee1275/ofdisk.c | 59 ++++++++++++++++++++++++++++++++++++----
f96e0b
 include/grub/ieee1275/ofdisk.h   |  3 ++
f96e0b
 3 files changed, 70 insertions(+), 5 deletions(-)
f96e0b
f96e0b
diff --git a/ChangeLog b/ChangeLog
f96e0b
index 3731229..654ebcb 100644
f96e0b
--- a/ChangeLog
f96e0b
+++ b/ChangeLog
f96e0b
@@ -1,3 +1,16 @@
f96e0b
+2013-02-19  Paulo Flabiano Smorigo <pfsmorigo@br.ibm.com>
f96e0b
+
f96e0b
+	Support Openfirmware disks with non-512B sectors.
f96e0b
+
f96e0b
+	* grub-core/disk/ieee1275/ofdisk.c (grub_ofdisk_open): Get the block
f96e0b
+	size of the disk.
f96e0b
+	* (grub_ofdisk_get_block_size): New function.
f96e0b
+	* (grub_ofdisk_prepare): Use the correct block size.
f96e0b
+	* (grub_ofdisk_read): Likewise.
f96e0b
+	* (grub_ofdisk_write): Likewise.
f96e0b
+	* include/grub/ieee1275/ofdisk.h (grub_ofdisk_get_block_size):
f96e0b
+	New proto.
f96e0b
+
f96e0b
 2013-02-06  Vladimir Serbinenko  <phcoder@gmail.com>
f96e0b
 
f96e0b
 	* grub-core/commands/lsacpi.c: Fix types on 64-bit platform.
f96e0b
diff --git a/grub-core/disk/ieee1275/ofdisk.c b/grub-core/disk/ieee1275/ofdisk.c
f96e0b
index 644bbd2..2130cb1 100644
f96e0b
--- a/grub-core/disk/ieee1275/ofdisk.c
f96e0b
+++ b/grub-core/disk/ieee1275/ofdisk.c
f96e0b
@@ -349,6 +349,14 @@ grub_ofdisk_open (const char *name, grub_disk_t disk)
f96e0b
       return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "not a block device");
f96e0b
     }
f96e0b
 
f96e0b
+  grub_uint32_t block_size = 0;
f96e0b
+  if (grub_ofdisk_get_block_size (devpath, &block_size) == 0)
f96e0b
+    {
f96e0b
+      for (disk->log_sector_size = 0;
f96e0b
+           (1U << disk->log_sector_size) < block_size;
f96e0b
+           disk->log_sector_size++);
f96e0b
+    }
f96e0b
+
f96e0b
   /* XXX: There is no property to read the number of blocks.  There
f96e0b
      should be a property `#blocks', but it is not there.  Perhaps it
f96e0b
      is possible to use seek for this.  */
f96e0b
@@ -415,7 +423,7 @@ grub_ofdisk_prepare (grub_disk_t disk, grub_disk_addr_t sector)
f96e0b
       last_devpath = disk->data;      
f96e0b
     }
f96e0b
 
f96e0b
-  pos = sector << GRUB_DISK_SECTOR_BITS;
f96e0b
+  pos = sector << disk->log_sector_size;
f96e0b
 
f96e0b
   grub_ieee1275_seek (last_ihandle, pos, &status);
f96e0b
   if (status < 0)
f96e0b
@@ -434,9 +442,9 @@ grub_ofdisk_read (grub_disk_t disk, grub_disk_addr_t sector,
f96e0b
   err = grub_ofdisk_prepare (disk, sector);
f96e0b
   if (err)
f96e0b
     return err;
f96e0b
-  grub_ieee1275_read (last_ihandle, buf, size  << GRUB_DISK_SECTOR_BITS,
f96e0b
+  grub_ieee1275_read (last_ihandle, buf, size  << disk->log_sector_size,
f96e0b
 		      &actual);
f96e0b
-  if (actual != (grub_ssize_t) (size  << GRUB_DISK_SECTOR_BITS))
f96e0b
+  if (actual != (grub_ssize_t) (size  << disk->log_sector_size))
f96e0b
     return grub_error (GRUB_ERR_READ_ERROR, N_("failure reading sector 0x%llx "
f96e0b
 					       "from `%s'"),
f96e0b
 		       (unsigned long long) sector,
f96e0b
@@ -454,9 +462,9 @@ grub_ofdisk_write (grub_disk_t disk, grub_disk_addr_t sector,
f96e0b
   err = grub_ofdisk_prepare (disk, sector);
f96e0b
   if (err)
f96e0b
     return err;
f96e0b
-  grub_ieee1275_write (last_ihandle, buf, size  << GRUB_DISK_SECTOR_BITS,
f96e0b
+  grub_ieee1275_write (last_ihandle, buf, size  << disk->log_sector_size,
f96e0b
 		       &actual);
f96e0b
-  if (actual != (grub_ssize_t) (size << GRUB_DISK_SECTOR_BITS))
f96e0b
+  if (actual != (grub_ssize_t) (size << disk->log_sector_size))
f96e0b
     return grub_error (GRUB_ERR_WRITE_ERROR, N_("failure writing sector 0x%llx "
f96e0b
 						"to `%s'"),
f96e0b
 		       (unsigned long long) sector,
f96e0b
@@ -493,3 +501,44 @@ grub_ofdisk_fini (void)
f96e0b
 
f96e0b
   grub_disk_dev_unregister (&grub_ofdisk_dev);
f96e0b
 }
f96e0b
+
f96e0b
+grub_err_t
f96e0b
+grub_ofdisk_get_block_size (const char *device, grub_uint32_t *block_size)
f96e0b
+{
f96e0b
+  struct size_args_ieee1275
f96e0b
+    {
f96e0b
+      struct grub_ieee1275_common_hdr common;
f96e0b
+      grub_ieee1275_cell_t method;
f96e0b
+      grub_ieee1275_cell_t ihandle;
f96e0b
+      grub_ieee1275_cell_t result;
f96e0b
+      grub_ieee1275_cell_t size1;
f96e0b
+      grub_ieee1275_cell_t size2;
f96e0b
+    } args_ieee1275;
f96e0b
+
f96e0b
+  if (last_ihandle)
f96e0b
+    grub_ieee1275_close (last_ihandle);
f96e0b
+
f96e0b
+  last_ihandle = 0;
f96e0b
+  last_devpath = NULL;
f96e0b
+
f96e0b
+  grub_ieee1275_open (device, &last_ihandle);
f96e0b
+  if (! last_ihandle)
f96e0b
+    return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "can't open device");
f96e0b
+
f96e0b
+  INIT_IEEE1275_COMMON (&args_ieee1275.common, "call-method", 2, 2);
f96e0b
+  args_ieee1275.method = (grub_ieee1275_cell_t) "block-size";
f96e0b
+  args_ieee1275.ihandle = last_ihandle;
f96e0b
+  args_ieee1275.result = 1;
f96e0b
+
f96e0b
+  *block_size = GRUB_DISK_SECTOR_SIZE;
f96e0b
+
f96e0b
+  if ((IEEE1275_CALL_ENTRY_FN (&args_ieee1275) == -1) || (args_ieee1275.result))
f96e0b
+    grub_dprintf ("disk", "can't get block size\n");
f96e0b
+  else
f96e0b
+    if (args_ieee1275.size1
f96e0b
+        && !(args_ieee1275.size1 & (args_ieee1275.size1 - 1))
f96e0b
+        && args_ieee1275.size1 >= 512 && args_ieee1275.size1 <= 16384)
f96e0b
+      *block_size = args_ieee1275.size1;
f96e0b
+
f96e0b
+  return 0;
f96e0b
+}
f96e0b
diff --git a/include/grub/ieee1275/ofdisk.h b/include/grub/ieee1275/ofdisk.h
f96e0b
index 2f69e3f..3f58317 100644
f96e0b
--- a/include/grub/ieee1275/ofdisk.h
f96e0b
+++ b/include/grub/ieee1275/ofdisk.h
f96e0b
@@ -22,4 +22,7 @@
f96e0b
 extern void grub_ofdisk_init (void);
f96e0b
 extern void grub_ofdisk_fini (void);
f96e0b
 
f96e0b
+extern grub_err_t grub_ofdisk_get_block_size (const char *device,
f96e0b
+                                              grub_uint32_t *block_size);
f96e0b
+
f96e0b
 #endif /* ! GRUB_INIT_HEADER */
f96e0b
-- 
f96e0b
1.8.2.1
f96e0b