All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] chainloader: patch in BPB's sectors_per_track and num_heads
@ 2018-02-01 14:51 C. Masloch
  2018-03-03 11:22 ` C. Masloch
  2018-03-05 16:54 ` Daniel Kiper
  0 siblings, 2 replies; 4+ messages in thread
From: C. Masloch @ 2018-02-01 14:51 UTC (permalink / raw)
  To: grub-devel


These fields must reflect the ROM-BIOS's geometry for CHS-based
loaders to correctly load their next stage. Most loaders do not
query the ROM-BIOS (Int13.08), relying on the BPB fields to hold
the correct values already.

Tested with lDebug booted in qemu via grub2's
FreeDOS direct loading support, refer to
https://bitbucket.org/ecm/ldosboot + https://bitbucket.org/ecm/ldebug
(For this test, lDebug's iniload.asm must be assembled with
-D_QUERY_GEOMETRY=0 to leave the BPB values provided by grub.)

Signed-off-by: C. Masloch <pushbx@38.de>
---
 grub-core/loader/i386/pc/chainloader.c | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/grub-core/loader/i386/pc/chainloader.c
b/grub-core/loader/i386/pc/chainloader.c
index 18220b7aa..ef3a322b7 100644
--- a/grub-core/loader/i386/pc/chainloader.c
+++ b/grub-core/loader/i386/pc/chainloader.c
@@ -19,6 +19,7 @@

 #include <grub/loader.h>
 #include <grub/machine/chainloader.h>
+#include <grub/machine/biosdisk.h>
 #include <grub/machine/memory.h>
 #include <grub/file.h>
 #include <grub/err.h>
@@ -86,9 +87,16 @@ grub_chainloader_unload (void)
 void
 grub_chainloader_patch_bpb (void *bs, grub_device_t dev, grub_uint8_t dl)
 {
-  grub_uint32_t part_start = 0;
+  grub_uint32_t part_start = 0, heads = 0, sectors = 0;
   if (dev && dev->disk)
-    part_start = grub_partition_get_start (dev->disk->partition);
+    {
+      part_start = grub_partition_get_start (dev->disk->partition);
+      if (dev->disk->data)
+        {
+          heads = ((struct grub_biosdisk_data *)(dev->disk->data))->heads;
+          sectors = ((struct grub_biosdisk_data
*)(dev->disk->data))->sectors;
+        }
+    }
   if (grub_memcmp ((char *) &((struct grub_ntfs_bpb *) bs)->oem_name,
 		   "NTFS", 4) == 0)
     {
@@ -127,12 +135,20 @@ grub_chainloader_patch_bpb (void *bs,
grub_device_t dev, grub_uint8_t dl)
 	{
 	  bpb->num_hidden_sectors = grub_cpu_to_le32 (part_start);
 	  bpb->version_specific.fat12_or_fat16.num_ph_drive = dl;
+          if (sectors)
+            bpb->sectors_per_track = grub_cpu_to_le16 (sectors);
+          if (heads)
+            bpb->num_heads = grub_cpu_to_le16 (heads);
 	  return;
 	}
       if (bpb->version_specific.fat32.sectors_per_fat_32)
 	{
 	  bpb->num_hidden_sectors = grub_cpu_to_le32 (part_start);
 	  bpb->version_specific.fat32.num_ph_drive = dl;
+          if (sectors)
+            bpb->sectors_per_track = grub_cpu_to_le16 (sectors);
+          if (heads)
+            bpb->num_heads = grub_cpu_to_le16 (heads);
 	  return;
 	}
       break;
-- 
2.11.0


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

* Re: [PATCH] chainloader: patch in BPB's sectors_per_track and num_heads
  2018-02-01 14:51 [PATCH] chainloader: patch in BPB's sectors_per_track and num_heads C. Masloch
@ 2018-03-03 11:22 ` C. Masloch
  2018-03-05 16:57   ` Daniel Kiper
  2018-03-05 16:54 ` Daniel Kiper
  1 sibling, 1 reply; 4+ messages in thread
From: C. Masloch @ 2018-03-03 11:22 UTC (permalink / raw)
  To: grub-devel

Hello,

Was this overlooked?

I think I should check whether dev->disk->data actually is a (struct
grub_biosdisk_data *) but I don't know how!

Regards,
ecm


On at 2018-02-01 15:51 +01:00, C. Masloch wrote:
> 
> These fields must reflect the ROM-BIOS's geometry for CHS-based
> loaders to correctly load their next stage. Most loaders do not
> query the ROM-BIOS (Int13.08), relying on the BPB fields to hold
> the correct values already.
> 
> Tested with lDebug booted in qemu via grub2's
> FreeDOS direct loading support, refer to
> https://bitbucket.org/ecm/ldosboot + https://bitbucket.org/ecm/ldebug
> (For this test, lDebug's iniload.asm must be assembled with
> -D_QUERY_GEOMETRY=0 to leave the BPB values provided by grub.)
> 
> Signed-off-by: C. Masloch <pushbx@38.de>
> ---
>  grub-core/loader/i386/pc/chainloader.c | 20 ++++++++++++++++++--
>  1 file changed, 18 insertions(+), 2 deletions(-)
> 
> diff --git a/grub-core/loader/i386/pc/chainloader.c
> b/grub-core/loader/i386/pc/chainloader.c
> index 18220b7aa..ef3a322b7 100644
> --- a/grub-core/loader/i386/pc/chainloader.c
> +++ b/grub-core/loader/i386/pc/chainloader.c
> @@ -19,6 +19,7 @@
> 
>  #include <grub/loader.h>
>  #include <grub/machine/chainloader.h>
> +#include <grub/machine/biosdisk.h>
>  #include <grub/machine/memory.h>
>  #include <grub/file.h>
>  #include <grub/err.h>
> @@ -86,9 +87,16 @@ grub_chainloader_unload (void)
>  void
>  grub_chainloader_patch_bpb (void *bs, grub_device_t dev, grub_uint8_t dl)
>  {
> -  grub_uint32_t part_start = 0;
> +  grub_uint32_t part_start = 0, heads = 0, sectors = 0;
>    if (dev && dev->disk)
> -    part_start = grub_partition_get_start (dev->disk->partition);
> +    {
> +      part_start = grub_partition_get_start (dev->disk->partition);
> +      if (dev->disk->data)
> +        {
> +          heads = ((struct grub_biosdisk_data *)(dev->disk->data))->heads;
> +          sectors = ((struct grub_biosdisk_data
> *)(dev->disk->data))->sectors;
> +        }
> +    }
>    if (grub_memcmp ((char *) &((struct grub_ntfs_bpb *) bs)->oem_name,
>  		   "NTFS", 4) == 0)
>      {
> @@ -127,12 +135,20 @@ grub_chainloader_patch_bpb (void *bs,
> grub_device_t dev, grub_uint8_t dl)
>  	{
>  	  bpb->num_hidden_sectors = grub_cpu_to_le32 (part_start);
>  	  bpb->version_specific.fat12_or_fat16.num_ph_drive = dl;
> +          if (sectors)
> +            bpb->sectors_per_track = grub_cpu_to_le16 (sectors);
> +          if (heads)
> +            bpb->num_heads = grub_cpu_to_le16 (heads);
>  	  return;
>  	}
>        if (bpb->version_specific.fat32.sectors_per_fat_32)
>  	{
>  	  bpb->num_hidden_sectors = grub_cpu_to_le32 (part_start);
>  	  bpb->version_specific.fat32.num_ph_drive = dl;
> +          if (sectors)
> +            bpb->sectors_per_track = grub_cpu_to_le16 (sectors);
> +          if (heads)
> +            bpb->num_heads = grub_cpu_to_le16 (heads);
>  	  return;
>  	}
>        break;
> 



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

* Re: [PATCH] chainloader: patch in BPB's sectors_per_track and num_heads
  2018-02-01 14:51 [PATCH] chainloader: patch in BPB's sectors_per_track and num_heads C. Masloch
  2018-03-03 11:22 ` C. Masloch
@ 2018-03-05 16:54 ` Daniel Kiper
  1 sibling, 0 replies; 4+ messages in thread
From: Daniel Kiper @ 2018-03-05 16:54 UTC (permalink / raw)
  To: pushbx; +Cc: grub-devel

On Thu, Feb 01, 2018 at 03:51:55PM +0100, C. Masloch wrote:
>
> These fields must reflect the ROM-BIOS's geometry for CHS-based
> loaders to correctly load their next stage. Most loaders do not
> query the ROM-BIOS (Int13.08), relying on the BPB fields to hold
> the correct values already.
>
> Tested with lDebug booted in qemu via grub2's
> FreeDOS direct loading support, refer to
> https://bitbucket.org/ecm/ldosboot + https://bitbucket.org/ecm/ldebug
> (For this test, lDebug's iniload.asm must be assembled with
> -D_QUERY_GEOMETRY=0 to leave the BPB values provided by grub.)
>
> Signed-off-by: C. Masloch <pushbx@38.de>

Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>

If there are no objections I will apply this in a week or so.

Daniel

PS Please CC me next time.


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

* Re: [PATCH] chainloader: patch in BPB's sectors_per_track and num_heads
  2018-03-03 11:22 ` C. Masloch
@ 2018-03-05 16:57   ` Daniel Kiper
  0 siblings, 0 replies; 4+ messages in thread
From: Daniel Kiper @ 2018-03-05 16:57 UTC (permalink / raw)
  To: pushbx; +Cc: grub-devel

On Sat, Mar 03, 2018 at 12:22:04PM +0100, C. Masloch wrote:
> Hello,
>
> Was this overlooked?

Yep, sorry about that.

> I think I should check whether dev->disk->data actually is a (struct
> grub_biosdisk_data *) but I don't know how!

I am not sure it is possible. Anyway, LGTM.

Daniel


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

end of thread, other threads:[~2018-03-05 16:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-01 14:51 [PATCH] chainloader: patch in BPB's sectors_per_track and num_heads C. Masloch
2018-03-03 11:22 ` C. Masloch
2018-03-05 16:57   ` Daniel Kiper
2018-03-05 16:54 ` 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.