All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Support Openfirmware disks with non-512B sectors
@ 2013-01-22 17:44 Paulo Flabiano Smorigo/Brazil/IBM
  2013-01-22 19:04 ` Seth Goldberg
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Paulo Flabiano Smorigo/Brazil/IBM @ 2013-01-22 17:44 UTC (permalink / raw)
  To: grub-devel

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

Hi all,

This patch adds non-512B sectors disks support for Openfirmware (ieee1275).

-- 
Paulo Flabiano Smorigo
Software Engineer
Linux Technology Center - IBM Systems & Technology Group

[-- Attachment #2: grub_ieee1275_get_block_size.patch --]
[-- Type: text/x-patch, Size: 4230 bytes --]

=== modified file 'ChangeLog'
--- ChangeLog	2013-01-22 14:28:32 +0000
+++ ChangeLog	2013-01-22 17:35:51 +0000
@@ -1,3 +1,15 @@
+2013-01-22  Paulo Flabiano Smorigo <pfsmorigo@br.ibm.com>
+
+	Support Openfirmware disks with non-512B sectors.
+
+	* grub-core/disk/ieee1275/ofdisk.c (grub_ofdisk_open): Get the block
+	size of the disk.
+	* (grub_ofdisk_get_block_size): New function.
+	* (grub_ofdisk_prepare): Use the correct block size.
+	* (grub_ofdisk_read): Likewise.
+	* (grub_ofdisk_write): Likewise.
+	* include/grub/ieee1275/ofdisk.h (grub_ofdisk_get_block_size): New proto.
+
 2013-01-22  Colin Watson  <cjwatson@ubuntu.com>
 
 	* util/grub-reboot.in (usage): Document the need for

=== modified file 'grub-core/disk/ieee1275/ofdisk.c'
--- grub-core/disk/ieee1275/ofdisk.c	2013-01-20 15:52:15 +0000
+++ grub-core/disk/ieee1275/ofdisk.c	2013-01-22 16:45:28 +0000
@@ -354,6 +354,13 @@
      is possible to use seek for this.  */
   disk->total_sectors = GRUB_DISK_SIZE_UNKNOWN;
 
+  grub_uint32_t block_size = 0;
+  block_size = grub_ofdisk_get_block_size (devpath);
+
+  for (disk->log_sector_size = 0;
+       (1U << disk->log_sector_size) < block_size;
+       disk->log_sector_size++);
+
   {
     struct ofdisk_hash_ent *op;
     op = ofdisk_hash_find (devpath);
@@ -415,7 +422,7 @@
       last_devpath = disk->data;      
     }
 
-  pos = sector << GRUB_DISK_SECTOR_BITS;
+  pos = sector << disk->log_sector_size;
 
   grub_ieee1275_seek (last_ihandle, pos, &status);
   if (status < 0)
@@ -434,9 +441,9 @@
   err = grub_ofdisk_prepare (disk, sector);
   if (err)
     return err;
-  grub_ieee1275_read (last_ihandle, buf, size  << GRUB_DISK_SECTOR_BITS,
+  grub_ieee1275_read (last_ihandle, buf, size  << disk->log_sector_size,
 		      &actual);
-  if (actual != (grub_ssize_t) (size  << GRUB_DISK_SECTOR_BITS))
+  if (actual != (grub_ssize_t) (size  << disk->log_sector_size))
     return grub_error (GRUB_ERR_READ_ERROR, N_("failure reading sector 0x%llx "
 					       "from `%s'"),
 		       (unsigned long long) sector,
@@ -454,9 +461,9 @@
   err = grub_ofdisk_prepare (disk, sector);
   if (err)
     return err;
-  grub_ieee1275_write (last_ihandle, buf, size  << GRUB_DISK_SECTOR_BITS,
+  grub_ieee1275_write (last_ihandle, buf, size  << disk->log_sector_size,
 		       &actual);
-  if (actual != (grub_ssize_t) (size << GRUB_DISK_SECTOR_BITS))
+  if (actual != (grub_ssize_t) (size << disk->log_sector_size))
     return grub_error (GRUB_ERR_WRITE_ERROR, N_("failure writing sector 0x%llx "
 						"to `%s'"),
 		       (unsigned long long) sector,
@@ -493,3 +500,46 @@
 
   grub_disk_dev_unregister (&grub_ofdisk_dev);
 }
+
+
+grub_uint32_t grub_ofdisk_get_block_size (const char *device)
+{
+  grub_uint32_t block_size = 0;
+  grub_ieee1275_ihandle_t dev_ihandle = 0;
+
+  struct size_args_ieee1275
+    {
+      struct grub_ieee1275_common_hdr common;
+      grub_ieee1275_cell_t method;
+      grub_ieee1275_cell_t ihandle;
+      grub_ieee1275_cell_t result;
+      grub_ieee1275_cell_t size1;
+      grub_ieee1275_cell_t size2;
+    } args_ieee1275;
+
+  grub_ieee1275_open (device, &dev_ihandle);
+  if (! dev_ihandle)
+    {
+      grub_error (GRUB_ERR_UNKNOWN_DEVICE, "can't open device");
+      return 0;
+    }
+
+  INIT_IEEE1275_COMMON (&args_ieee1275.common, "call-method", 2, 2);
+  args_ieee1275.method = (grub_ieee1275_cell_t) "block-size";
+  args_ieee1275.ihandle = dev_ihandle;
+  args_ieee1275.result = 1;
+
+  if ((IEEE1275_CALL_ENTRY_FN (&args_ieee1275) == -1) || (args_ieee1275.result))
+    {
+      /* If the method isn't available use the common size */
+      grub_dprintf ("disk", "can't get block size\n");
+      grub_ieee1275_close (dev_ihandle);
+      return GRUB_DISK_SECTOR_SIZE;
+    }
+
+  grub_ieee1275_close (dev_ihandle);
+  block_size = args_ieee1275.size1;
+
+  return block_size;
+}
+

=== modified file 'include/grub/ieee1275/ofdisk.h'
--- include/grub/ieee1275/ofdisk.h	2007-07-21 23:32:33 +0000
+++ include/grub/ieee1275/ofdisk.h	2013-01-22 16:45:28 +0000
@@ -21,5 +21,6 @@
 
 extern void grub_ofdisk_init (void);
 extern void grub_ofdisk_fini (void);
+extern grub_uint32_t grub_ofdisk_get_block_size (const char *device);
 
 #endif /* ! GRUB_INIT_HEADER */


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

* Re: [PATCH] Support Openfirmware disks with non-512B sectors
  2013-01-22 17:44 [PATCH] Support Openfirmware disks with non-512B sectors Paulo Flabiano Smorigo/Brazil/IBM
@ 2013-01-22 19:04 ` Seth Goldberg
  2013-01-22 19:34   ` Paulo Flabiano Smorigo/Brazil/IBM
  2013-01-22 19:35   ` Andrey Borzenkov
  2013-01-23  7:17 ` Vladimir 'φ-coder/phcoder' Serbinenko
  2013-02-19  2:04 ` Seth Goldberg
  2 siblings, 2 replies; 12+ messages in thread
From: Seth Goldberg @ 2013-01-22 19:04 UTC (permalink / raw)
  To: The development of GNU GRUB

Hi,

   Why is this limited to OpenFirmware only?  Can you generate a patch that 
supports 4KN disks on ALL platforms?

  Thanks,
  --S

Quoting Paulo Flabiano Smorigo/Brazil/IBM, who wrote the following on Tue,...:

> Hi all,
>
> This patch adds non-512B sectors disks support for Openfirmware (ieee1275).
>
> -- 
> Paulo Flabiano Smorigo
> Software Engineer
> Linux Technology Center - IBM Systems & Technology Group


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

* Re: [PATCH] Support Openfirmware disks with non-512B sectors
  2013-01-22 19:04 ` Seth Goldberg
@ 2013-01-22 19:34   ` Paulo Flabiano Smorigo/Brazil/IBM
  2013-01-22 19:35   ` Andrey Borzenkov
  1 sibling, 0 replies; 12+ messages in thread
From: Paulo Flabiano Smorigo/Brazil/IBM @ 2013-01-22 19:34 UTC (permalink / raw)
  To: The development of GNU GRUB

Hi,

You need a different approach for each platform. Afaik, grub already  
have support
for some platforms:

http://bzr.savannah.gnu.org/lh/grub/trunk/grub/revision/3325?start_revid=4682

Regards,

-- 
Paulo Flabiano Smorigo
Software Engineer
Linux Technology Center - IBM Systems & Technology Group



Quoting Seth Goldberg <seth.goldberg@oracle.com>:

> Hi,
>
>   Why is this limited to OpenFirmware only?  Can you generate a  
> patch that supports 4KN disks on ALL platforms?
>
>  Thanks,
>  --S
>
> Quoting Paulo Flabiano Smorigo/Brazil/IBM, who wrote the following  
> on Tue,...:
>
>> Hi all,
>>
>> This patch adds non-512B sectors disks support for Openfirmware (ieee1275).
>>
>> -- 
>> Paulo Flabiano Smorigo
>> Software Engineer
>> Linux Technology Center - IBM Systems & Technology Group
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel



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

* Re: [PATCH] Support Openfirmware disks with non-512B sectors
  2013-01-22 19:04 ` Seth Goldberg
  2013-01-22 19:34   ` Paulo Flabiano Smorigo/Brazil/IBM
@ 2013-01-22 19:35   ` Andrey Borzenkov
  2013-01-22 19:39     ` Seth Goldberg
  1 sibling, 1 reply; 12+ messages in thread
From: Andrey Borzenkov @ 2013-01-22 19:35 UTC (permalink / raw)
  To: The development of GNU GRUB; +Cc: seth.goldberg

В Tue, 22 Jan 2013 11:04:19 -0800 (PST)
Seth Goldberg <seth.goldberg@oracle.com> пишет:

> Hi,
> 
>    Why is this limited to OpenFirmware only?  Can you generate a patch that 
> supports 4KN disks on ALL platforms?
> 

It already supports 4K sector internally and queries disk sector size
for SCSI, ATA and EFI (at least). BIOS is always emulating 512 sector.

>   Thanks,
>   --S
> 
> Quoting Paulo Flabiano Smorigo/Brazil/IBM, who wrote the following on Tue,...:
> 
> > Hi all,
> >
> > This patch adds non-512B sectors disks support for Openfirmware (ieee1275).
> >
> > -- 
> > Paulo Flabiano Smorigo
> > Software Engineer
> > Linux Technology Center - IBM Systems & Technology Group
> 
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel



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

* Re: [PATCH] Support Openfirmware disks with non-512B sectors
  2013-01-22 19:35   ` Andrey Borzenkov
@ 2013-01-22 19:39     ` Seth Goldberg
  2013-01-23  6:53       ` Vladimir 'φ-coder/phcoder' Serbinenko
  0 siblings, 1 reply; 12+ messages in thread
From: Seth Goldberg @ 2013-01-22 19:39 UTC (permalink / raw)
  To: Andrey Borzenkov; +Cc: The development of GNU GRUB, seth.goldberg

[-- Attachment #1: Type: TEXT/PLAIN, Size: 639 bytes --]



Quoting Andrey Borzenkov, who wrote the following on Tue, 22 Jan 2013:

> В Tue, 22 Jan 2013 11:04:19 -0800 (PST)
> Seth Goldberg <seth.goldberg@oracle.com> пишет:
>
>> Hi,
>>
>>    Why is this limited to OpenFirmware only?  Can you generate a patch that
>> supports 4KN disks on ALL platforms?
>>
>
> It already supports 4K sector internally and queries disk sector size
> for SCSI, ATA and EFI (at least). BIOS is always emulating 512 sector.

   That is not true.  True 4k native drives (on i386-pc) will not boot with 
GRUB 2 due to issues in grub-setup (I have a proposal I'll send in a bit to 
fix that).

  --S

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

* Re: [PATCH] Support Openfirmware disks with non-512B sectors
  2013-01-22 19:39     ` Seth Goldberg
@ 2013-01-23  6:53       ` Vladimir 'φ-coder/phcoder' Serbinenko
  0 siblings, 0 replies; 12+ messages in thread
From: Vladimir 'φ-coder/phcoder' Serbinenko @ 2013-01-23  6:53 UTC (permalink / raw)
  To: grub-devel

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

On 22.01.2013 20:39, Seth Goldberg wrote:

> 
> 
> Quoting Andrey Borzenkov, who wrote the following on Tue, 22 Jan 2013:
> 
>> В Tue, 22 Jan 2013 11:04:19 -0800 (PST)
>> Seth Goldberg <seth.goldberg@oracle.com> пишет:
>>
>>> Hi,
>>>
>>>    Why is this limited to OpenFirmware only?  Can you generate a
>>> patch that
>>> supports 4KN disks on ALL platforms?
>>>
>>
>> It already supports 4K sector internally and queries disk sector size
>> for SCSI, ATA and EFI (at least). BIOS is always emulating 512 sector.
> 
>   That is not true.  True 4k native drives (on i386-pc) will not boot
> with GRUB 2 due to issues in grub-setup (I have a proposal I'll send in
> a bit to fix that).
> 

The parts to query sector size on BIOS are also in. But none of my
BIOSes were able to even show a 4K-sector drive in its boot menu.

>  --S
> 
> 
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel



-- 
Regards
Vladimir 'φ-coder/phcoder' Serbinenko


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 294 bytes --]

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

* Re: [PATCH] Support Openfirmware disks with non-512B sectors
  2013-01-22 17:44 [PATCH] Support Openfirmware disks with non-512B sectors Paulo Flabiano Smorigo/Brazil/IBM
  2013-01-22 19:04 ` Seth Goldberg
@ 2013-01-23  7:17 ` Vladimir 'φ-coder/phcoder' Serbinenko
  2013-01-28 17:18   ` Paulo Flabiano Smorigo/Brazil/IBM
  2013-02-19  2:04 ` Seth Goldberg
  2 siblings, 1 reply; 12+ messages in thread
From: Vladimir 'φ-coder/phcoder' Serbinenko @ 2013-01-23  7:17 UTC (permalink / raw)
  To: grub-devel

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

On 22.01.2013 18:44, Paulo Flabiano Smorigo/Brazil/IBM wrote:

> +  grub_ieee1275_open (device, &dev_ihandle);

Please don't open another handle. This can cause lockdown on some
platforms. Use the already available framework.

-- 
Regards
Vladimir 'φ-coder/phcoder' Serbinenko


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 294 bytes --]

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

* Re: [PATCH] Support Openfirmware disks with non-512B sectors
  2013-01-23  7:17 ` Vladimir 'φ-coder/phcoder' Serbinenko
@ 2013-01-28 17:18   ` Paulo Flabiano Smorigo/Brazil/IBM
  2013-01-30  8:37     ` Vladimir 'φ-coder/phcoder' Serbinenko
  0 siblings, 1 reply; 12+ messages in thread
From: Paulo Flabiano Smorigo/Brazil/IBM @ 2013-01-28 17:18 UTC (permalink / raw)
  To: The development of GNU GRUB

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


Quoting Vladimir 'φ-coder/phcoder' Serbinenko <phcoder@gmail.com>:

> On 22.01.2013 18:44, Paulo Flabiano Smorigo/Brazil/IBM wrote:
>
>> +  grub_ieee1275_open (device, &dev_ihandle);
>
> Please don't open another handle. This can cause lockdown on some
> platforms. Use the already available framework.
>
> --
> Regards
> Vladimir 'φ-coder/phcoder' Serbinenko

Hi phcoder,

Here is a new version of my patch using last_ihandle. Is it ok now?

Thanks in advance
--
Paulo Flabiano Smorigo
Software Engineer
Linux Technology Center - IBM Systems & Technology Group
Phone: +55 (19) 2132-1647 T/L: 839-1647
Mobile: +55 (12) 9122-2734
freenode/bluenet: pfsmorigo or smow


[-- Attachment #2: grub_ieee1275_get_block_size_v2.patch --]
[-- Type: text/x-patch, Size: 4393 bytes --]

=== modified file 'ChangeLog'
--- ChangeLog	2013-01-27 15:17:21 +0000
+++ ChangeLog	2013-01-28 16:39:41 +0000
@@ -1,3 +1,15 @@
+2013-01-28  Paulo Flabiano Smorigo <pfsmorigo@br.ibm.com>
+
+	Support Openfirmware disks with non-512B sectors.
+
+	* grub-core/disk/ieee1275/ofdisk.c (grub_ofdisk_open): Get the block
+	size of the disk.
+	* (grub_ofdisk_get_block_size): New function.
+	* (grub_ofdisk_prepare): Use the correct block size.
+	* (grub_ofdisk_read): Likewise.
+	* (grub_ofdisk_write): Likewise.
+	* include/grub/ieee1275/ofdisk.h (grub_ofdisk_get_block_size): New proto.
+
 2013-01-27  Andrey Borzenkov <arvidjaar@gmail.com>
 
 	* util/grub-install.in: change misleading comment about

=== modified file 'grub-core/disk/ieee1275/ofdisk.c'
--- grub-core/disk/ieee1275/ofdisk.c	2013-01-20 15:52:15 +0000
+++ grub-core/disk/ieee1275/ofdisk.c	2013-01-28 16:39:24 +0000
@@ -349,6 +349,14 @@
       return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "not a block device");
     }
 
+  grub_uint32_t block_size = 0;
+  if (grub_ofdisk_get_block_size (devpath, &block_size) == 0)
+    {
+      for (disk->log_sector_size = 0;
+           (1U << disk->log_sector_size) < block_size;
+           disk->log_sector_size++);
+    }
+
   /* XXX: There is no property to read the number of blocks.  There
      should be a property `#blocks', but it is not there.  Perhaps it
      is possible to use seek for this.  */
@@ -415,7 +423,7 @@
       last_devpath = disk->data;      
     }
 
-  pos = sector << GRUB_DISK_SECTOR_BITS;
+  pos = sector << disk->log_sector_size;
 
   grub_ieee1275_seek (last_ihandle, pos, &status);
   if (status < 0)
@@ -434,9 +442,9 @@
   err = grub_ofdisk_prepare (disk, sector);
   if (err)
     return err;
-  grub_ieee1275_read (last_ihandle, buf, size  << GRUB_DISK_SECTOR_BITS,
+  grub_ieee1275_read (last_ihandle, buf, size  << disk->log_sector_size,
 		      &actual);
-  if (actual != (grub_ssize_t) (size  << GRUB_DISK_SECTOR_BITS))
+  if (actual != (grub_ssize_t) (size  << disk->log_sector_size))
     return grub_error (GRUB_ERR_READ_ERROR, N_("failure reading sector 0x%llx "
 					       "from `%s'"),
 		       (unsigned long long) sector,
@@ -454,9 +462,9 @@
   err = grub_ofdisk_prepare (disk, sector);
   if (err)
     return err;
-  grub_ieee1275_write (last_ihandle, buf, size  << GRUB_DISK_SECTOR_BITS,
+  grub_ieee1275_write (last_ihandle, buf, size  << disk->log_sector_size,
 		       &actual);
-  if (actual != (grub_ssize_t) (size << GRUB_DISK_SECTOR_BITS))
+  if (actual != (grub_ssize_t) (size << disk->log_sector_size))
     return grub_error (GRUB_ERR_WRITE_ERROR, N_("failure writing sector 0x%llx "
 						"to `%s'"),
 		       (unsigned long long) sector,
@@ -493,3 +501,43 @@
 
   grub_disk_dev_unregister (&grub_ofdisk_dev);
 }
+
+grub_err_t
+grub_ofdisk_get_block_size (const char *device, grub_uint32_t *block_size)
+{
+  struct size_args_ieee1275
+    {
+      struct grub_ieee1275_common_hdr common;
+      grub_ieee1275_cell_t method;
+      grub_ieee1275_cell_t ihandle;
+      grub_ieee1275_cell_t result;
+      grub_ieee1275_cell_t size1;
+      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");
+
+  INIT_IEEE1275_COMMON (&args_ieee1275.common, "call-method", 2, 2);
+  args_ieee1275.method = (grub_ieee1275_cell_t) "block-size";
+  args_ieee1275.ihandle = last_ihandle;
+  args_ieee1275.result = 1;
+
+  if ((IEEE1275_CALL_ENTRY_FN (&args_ieee1275) == -1) || (args_ieee1275.result))
+    {
+      /* If the method isn't available use the common size */
+      grub_dprintf ("disk", "can't get block size\n");
+      *block_size = GRUB_DISK_SECTOR_SIZE;
+    }
+  else
+    *block_size = args_ieee1275.size1;
+
+  return 0;
+}

=== modified file 'include/grub/ieee1275/ofdisk.h'
--- include/grub/ieee1275/ofdisk.h	2007-07-21 23:32:33 +0000
+++ include/grub/ieee1275/ofdisk.h	2013-01-28 16:14:09 +0000
@@ -22,4 +22,7 @@
 extern void grub_ofdisk_init (void);
 extern void grub_ofdisk_fini (void);
 
+extern grub_err_t grub_ofdisk_get_block_size (const char *device,
+                                              grub_uint32_t *block_size);
+
 #endif /* ! GRUB_INIT_HEADER */


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

* Re: [PATCH] Support Openfirmware disks with non-512B sectors
  2013-01-28 17:18   ` Paulo Flabiano Smorigo/Brazil/IBM
@ 2013-01-30  8:37     ` Vladimir 'φ-coder/phcoder' Serbinenko
  2013-01-30 19:21       ` Paulo Flabiano Smorigo/Brazil/IBM
  0 siblings, 1 reply; 12+ messages in thread
From: Vladimir 'φ-coder/phcoder' Serbinenko @ 2013-01-30  8:37 UTC (permalink / raw)
  To: grub-devel

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

On 28.01.2013 18:18, Paulo Flabiano Smorigo/Brazil/IBM wrote:

> 
> Quoting Vladimir 'φ-coder/phcoder' Serbinenko <phcoder@gmail.com>:
> 
>> On 22.01.2013 18:44, Paulo Flabiano Smorigo/Brazil/IBM wrote:
>>
>>> +  grub_ieee1275_open (device, &dev_ihandle);
>>
>> Please don't open another handle. This can cause lockdown on some
>> platforms. Use the already available framework.
>>
>> -- 
>> Regards
>> Vladimir 'φ-coder/phcoder' Serbinenko
> 
> Hi phcoder,
> 
> Here is a new version of my patch using last_ihandle. Is it ok now?

This patch lacks sanity checks. You need to check that sector size is
sane (never trust openfirmware or BIOS). Like this (taken from biosdisk.c):
	      if (drp->bytes_per_sector
		  && !(drp->bytes_per_sector & (drp->bytes_per_sector - 1))
		  && drp->bytes_per_sector >= 512
		  && drp->bytes_per_sector <= 16384)

> 
> Thanks in advance
> 
> 
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel



-- 
Regards
Vladimir 'φ-coder/phcoder' Serbinenko


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 294 bytes --]

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

* Re: [PATCH] Support Openfirmware disks with non-512B sectors
  2013-01-30  8:37     ` Vladimir 'φ-coder/phcoder' Serbinenko
@ 2013-01-30 19:21       ` Paulo Flabiano Smorigo/Brazil/IBM
  2013-02-19  9:03         ` Vladimir 'φ-coder/phcoder' Serbinenko
  0 siblings, 1 reply; 12+ messages in thread
From: Paulo Flabiano Smorigo/Brazil/IBM @ 2013-01-30 19:21 UTC (permalink / raw)
  To: The development of GNU GRUB

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


Quoting Vladimir 'φ-coder/phcoder' Serbinenko <phcoder@gmail.com>:

> On 28.01.2013 18:18, Paulo Flabiano Smorigo/Brazil/IBM wrote:
>
>>
>> Quoting Vladimir 'φ-coder/phcoder' Serbinenko <phcoder@gmail.com>:
>>
>>> On 22.01.2013 18:44, Paulo Flabiano Smorigo/Brazil/IBM wrote:
>>>
>>>> +  grub_ieee1275_open (device, &dev_ihandle);
>>>
>>> Please don't open another handle. This can cause lockdown on some
>>> platforms. Use the already available framework.
>>>
>>> --
>>> Regards
>>> Vladimir 'φ-coder/phcoder' Serbinenko
>>
>> Hi phcoder,
>>
>> Here is a new version of my patch using last_ihandle. Is it ok now?
>
> This patch lacks sanity checks. You need to check that sector size is
> sane (never trust openfirmware or BIOS). Like this (taken from biosdisk.c):
> 	      if (drp->bytes_per_sector
> 		  && !(drp->bytes_per_sector & (drp->bytes_per_sector - 1))
> 		  && drp->bytes_per_sector >= 512
> 		  && drp->bytes_per_sector <= 16384)
>
>>
>> Thanks in advance
>>
>>
>> _______________________________________________
>> Grub-devel mailing list
>> Grub-devel@gnu.org
>> https://lists.gnu.org/mailman/listinfo/grub-devel
>
>
>
> --
> Regards
> Vladimir 'φ-coder/phcoder' Serbinenko

Hi,

Sanity check added.

Best regards,
--
Paulo Flabiano Smorigo
Software Engineer
Linux Technology Center - IBM Systems & Technology Group


[-- Attachment #2: grub_ieee1275_get_block_size_v3.patch --]
[-- Type: text/x-patch, Size: 4478 bytes --]

=== modified file 'ChangeLog'
--- ChangeLog	2013-01-27 15:17:21 +0000
+++ ChangeLog	2013-01-28 16:39:41 +0000
@@ -1,3 +1,15 @@
+2013-01-28  Paulo Flabiano Smorigo <pfsmorigo@br.ibm.com>
+
+	Support Openfirmware disks with non-512B sectors.
+
+	* grub-core/disk/ieee1275/ofdisk.c (grub_ofdisk_open): Get the block
+	size of the disk.
+	* (grub_ofdisk_get_block_size): New function.
+	* (grub_ofdisk_prepare): Use the correct block size.
+	* (grub_ofdisk_read): Likewise.
+	* (grub_ofdisk_write): Likewise.
+	* include/grub/ieee1275/ofdisk.h (grub_ofdisk_get_block_size): New proto.
+
 2013-01-27  Andrey Borzenkov <arvidjaar@gmail.com>
 
 	* util/grub-install.in: change misleading comment about

=== modified file 'grub-core/disk/ieee1275/ofdisk.c'
--- grub-core/disk/ieee1275/ofdisk.c	2013-01-20 15:52:15 +0000
+++ grub-core/disk/ieee1275/ofdisk.c	2013-01-30 19:05:49 +0000
@@ -349,6 +349,14 @@
       return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "not a block device");
     }
 
+  grub_uint32_t block_size = 0;
+  if (grub_ofdisk_get_block_size (devpath, &block_size) == 0)
+    {
+      for (disk->log_sector_size = 0;
+           (1U << disk->log_sector_size) < block_size;
+           disk->log_sector_size++);
+    }
+
   /* XXX: There is no property to read the number of blocks.  There
      should be a property `#blocks', but it is not there.  Perhaps it
      is possible to use seek for this.  */
@@ -415,7 +423,7 @@
       last_devpath = disk->data;      
     }
 
-  pos = sector << GRUB_DISK_SECTOR_BITS;
+  pos = sector << disk->log_sector_size;
 
   grub_ieee1275_seek (last_ihandle, pos, &status);
   if (status < 0)
@@ -434,9 +442,9 @@
   err = grub_ofdisk_prepare (disk, sector);
   if (err)
     return err;
-  grub_ieee1275_read (last_ihandle, buf, size  << GRUB_DISK_SECTOR_BITS,
+  grub_ieee1275_read (last_ihandle, buf, size  << disk->log_sector_size,
 		      &actual);
-  if (actual != (grub_ssize_t) (size  << GRUB_DISK_SECTOR_BITS))
+  if (actual != (grub_ssize_t) (size  << disk->log_sector_size))
     return grub_error (GRUB_ERR_READ_ERROR, N_("failure reading sector 0x%llx "
 					       "from `%s'"),
 		       (unsigned long long) sector,
@@ -454,9 +462,9 @@
   err = grub_ofdisk_prepare (disk, sector);
   if (err)
     return err;
-  grub_ieee1275_write (last_ihandle, buf, size  << GRUB_DISK_SECTOR_BITS,
+  grub_ieee1275_write (last_ihandle, buf, size  << disk->log_sector_size,
 		       &actual);
-  if (actual != (grub_ssize_t) (size << GRUB_DISK_SECTOR_BITS))
+  if (actual != (grub_ssize_t) (size << disk->log_sector_size))
     return grub_error (GRUB_ERR_WRITE_ERROR, N_("failure writing sector 0x%llx "
 						"to `%s'"),
 		       (unsigned long long) sector,
@@ -493,3 +501,44 @@
 
   grub_disk_dev_unregister (&grub_ofdisk_dev);
 }
+
+grub_err_t
+grub_ofdisk_get_block_size (const char *device, grub_uint32_t *block_size)
+{
+  struct size_args_ieee1275
+    {
+      struct grub_ieee1275_common_hdr common;
+      grub_ieee1275_cell_t method;
+      grub_ieee1275_cell_t ihandle;
+      grub_ieee1275_cell_t result;
+      grub_ieee1275_cell_t size1;
+      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");
+
+  INIT_IEEE1275_COMMON (&args_ieee1275.common, "call-method", 2, 2);
+  args_ieee1275.method = (grub_ieee1275_cell_t) "block-size";
+  args_ieee1275.ihandle = last_ihandle;
+  args_ieee1275.result = 1;
+
+  *block_size = GRUB_DISK_SECTOR_SIZE;
+
+  if ((IEEE1275_CALL_ENTRY_FN (&args_ieee1275) == -1) || (args_ieee1275.result))
+    grub_dprintf ("disk", "can't get block size\n");
+  else
+    if (args_ieee1275.size1
+        && !(args_ieee1275.size1 & (args_ieee1275.size1 - 1))
+        && args_ieee1275.size1 >= 512 && args_ieee1275.size1 <= 16384)
+      *block_size = args_ieee1275.size1;
+
+  return 0;
+}

=== modified file 'include/grub/ieee1275/ofdisk.h'
--- include/grub/ieee1275/ofdisk.h	2007-07-21 23:32:33 +0000
+++ include/grub/ieee1275/ofdisk.h	2013-01-28 16:14:09 +0000
@@ -22,4 +22,7 @@
 extern void grub_ofdisk_init (void);
 extern void grub_ofdisk_fini (void);
 
+extern grub_err_t grub_ofdisk_get_block_size (const char *device,
+                                              grub_uint32_t *block_size);
+
 #endif /* ! GRUB_INIT_HEADER */


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

* Re: [PATCH] Support Openfirmware disks with non-512B sectors
  2013-01-22 17:44 [PATCH] Support Openfirmware disks with non-512B sectors Paulo Flabiano Smorigo/Brazil/IBM
  2013-01-22 19:04 ` Seth Goldberg
  2013-01-23  7:17 ` Vladimir 'φ-coder/phcoder' Serbinenko
@ 2013-02-19  2:04 ` Seth Goldberg
  2 siblings, 0 replies; 12+ messages in thread
From: Seth Goldberg @ 2013-02-19  2:04 UTC (permalink / raw)
  To: The development of GNU GRUB

Hi,

   Forgot to add: thanks for your work here :).

  --S

Quoting Paulo Flabiano Smorigo/Brazil/IBM, who wrote the following on Tue,...:

> Hi all,
>
> This patch adds non-512B sectors disks support for Openfirmware (ieee1275).
>
> -- 
> Paulo Flabiano Smorigo
> Software Engineer
> Linux Technology Center - IBM Systems & Technology Group


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

* Re: [PATCH] Support Openfirmware disks with non-512B sectors
  2013-01-30 19:21       ` Paulo Flabiano Smorigo/Brazil/IBM
@ 2013-02-19  9:03         ` Vladimir 'φ-coder/phcoder' Serbinenko
  0 siblings, 0 replies; 12+ messages in thread
From: Vladimir 'φ-coder/phcoder' Serbinenko @ 2013-02-19  9:03 UTC (permalink / raw)
  To: grub-devel

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

Committed, thanks. Sorry for delay.

On 30.01.2013 20:21, Paulo Flabiano Smorigo/Brazil/IBM wrote:

> === modified file 'ChangeLog'
> --- ChangeLog	2013-01-27 15:17:21 +0000
> +++ ChangeLog	2013-01-28 16:39:41 +0000
> @@ -1,3 +1,15 @@
> +2013-01-28  Paulo Flabiano Smorigo <pfsmorigo@br.ibm.com>
> +
> +	Support Openfirmware disks with non-512B sectors.
> +
> +	* grub-core/disk/ieee1275/ofdisk.c (grub_ofdisk_open): Get the block
> +	size of the disk.
> +	* (grub_ofdisk_get_block_size): New function.
> +	* (grub_ofdisk_prepare): Use the correct block size.
> +	* (grub_ofdisk_read): Likewise.
> +	* (grub_ofdisk_write): Likewise.
> +	* include/grub/ieee1275/ofdisk.h (grub_ofdisk_get_block_size): New proto.
> +
>  2013-01-27  Andrey Borzenkov <arvidjaar@gmail.com>
>  
>  	* util/grub-install.in: change misleading comment about
> 
> === modified file 'grub-core/disk/ieee1275/ofdisk.c'
> --- grub-core/disk/ieee1275/ofdisk.c	2013-01-20 15:52:15 +0000
> +++ grub-core/disk/ieee1275/ofdisk.c	2013-01-30 19:05:49 +0000
> @@ -349,6 +349,14 @@
>        return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "not a block device");
>      }
>  
> +  grub_uint32_t block_size = 0;
> +  if (grub_ofdisk_get_block_size (devpath, &block_size) == 0)
> +    {
> +      for (disk->log_sector_size = 0;
> +           (1U << disk->log_sector_size) < block_size;
> +           disk->log_sector_size++);
> +    }
> +
>    /* XXX: There is no property to read the number of blocks.  There
>       should be a property `#blocks', but it is not there.  Perhaps it
>       is possible to use seek for this.  */
> @@ -415,7 +423,7 @@
>        last_devpath = disk->data;      
>      }
>  
> -  pos = sector << GRUB_DISK_SECTOR_BITS;
> +  pos = sector << disk->log_sector_size;
>  
>    grub_ieee1275_seek (last_ihandle, pos, &status);
>    if (status < 0)
> @@ -434,9 +442,9 @@
>    err = grub_ofdisk_prepare (disk, sector);
>    if (err)
>      return err;
> -  grub_ieee1275_read (last_ihandle, buf, size  << GRUB_DISK_SECTOR_BITS,
> +  grub_ieee1275_read (last_ihandle, buf, size  << disk->log_sector_size,
>  		      &actual);
> -  if (actual != (grub_ssize_t) (size  << GRUB_DISK_SECTOR_BITS))
> +  if (actual != (grub_ssize_t) (size  << disk->log_sector_size))
>      return grub_error (GRUB_ERR_READ_ERROR, N_("failure reading sector 0x%llx "
>  					       "from `%s'"),
>  		       (unsigned long long) sector,
> @@ -454,9 +462,9 @@
>    err = grub_ofdisk_prepare (disk, sector);
>    if (err)
>      return err;
> -  grub_ieee1275_write (last_ihandle, buf, size  << GRUB_DISK_SECTOR_BITS,
> +  grub_ieee1275_write (last_ihandle, buf, size  << disk->log_sector_size,
>  		       &actual);
> -  if (actual != (grub_ssize_t) (size << GRUB_DISK_SECTOR_BITS))
> +  if (actual != (grub_ssize_t) (size << disk->log_sector_size))
>      return grub_error (GRUB_ERR_WRITE_ERROR, N_("failure writing sector 0x%llx "
>  						"to `%s'"),
>  		       (unsigned long long) sector,
> @@ -493,3 +501,44 @@
>  
>    grub_disk_dev_unregister (&grub_ofdisk_dev);
>  }
> +
> +grub_err_t
> +grub_ofdisk_get_block_size (const char *device, grub_uint32_t *block_size)
> +{
> +  struct size_args_ieee1275
> +    {
> +      struct grub_ieee1275_common_hdr common;
> +      grub_ieee1275_cell_t method;
> +      grub_ieee1275_cell_t ihandle;
> +      grub_ieee1275_cell_t result;
> +      grub_ieee1275_cell_t size1;
> +      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");
> +
> +  INIT_IEEE1275_COMMON (&args_ieee1275.common, "call-method", 2, 2);
> +  args_ieee1275.method = (grub_ieee1275_cell_t) "block-size";
> +  args_ieee1275.ihandle = last_ihandle;
> +  args_ieee1275.result = 1;
> +
> +  *block_size = GRUB_DISK_SECTOR_SIZE;
> +
> +  if ((IEEE1275_CALL_ENTRY_FN (&args_ieee1275) == -1) || (args_ieee1275.result))
> +    grub_dprintf ("disk", "can't get block size\n");
> +  else
> +    if (args_ieee1275.size1
> +        && !(args_ieee1275.size1 & (args_ieee1275.size1 - 1))
> +        && args_ieee1275.size1 >= 512 && args_ieee1275.size1 <= 16384)
> +      *block_size = args_ieee1275.size1;
> +
> +  return 0;
> +}
> 
> === modified file 'include/grub/ieee1275/ofdisk.h'
> --- include/grub/ieee1275/ofdisk.h	2007-07-21 23:32:33 +0000
> +++ include/grub/ieee1275/ofdisk.h	2013-01-28 16:14:09 +0000
> @@ -22,4 +22,7 @@
>  extern void grub_ofdisk_init (void);
>  extern void grub_ofdisk_fini (void);
>  
> +extern grub_err_t grub_ofdisk_get_block_size (const char *device,
> +                                              grub_uint32_t *block_size);
> +
>  #endif /* ! GRUB_INIT_HEADER */
> 
> 
> 




[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 294 bytes --]

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

end of thread, other threads:[~2013-02-19  9:04 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-01-22 17:44 [PATCH] Support Openfirmware disks with non-512B sectors Paulo Flabiano Smorigo/Brazil/IBM
2013-01-22 19:04 ` Seth Goldberg
2013-01-22 19:34   ` Paulo Flabiano Smorigo/Brazil/IBM
2013-01-22 19:35   ` Andrey Borzenkov
2013-01-22 19:39     ` Seth Goldberg
2013-01-23  6:53       ` Vladimir 'φ-coder/phcoder' Serbinenko
2013-01-23  7:17 ` Vladimir 'φ-coder/phcoder' Serbinenko
2013-01-28 17:18   ` Paulo Flabiano Smorigo/Brazil/IBM
2013-01-30  8:37     ` Vladimir 'φ-coder/phcoder' Serbinenko
2013-01-30 19:21       ` Paulo Flabiano Smorigo/Brazil/IBM
2013-02-19  9:03         ` Vladimir 'φ-coder/phcoder' Serbinenko
2013-02-19  2:04 ` Seth Goldberg

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.