All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thomas Frauendorfer | Miray Software <t.frauendorfer@miray.de>
To: grub-devel@gnu.org
Subject: [PATCH] Workaround for usb boot failure on some mainboards
Date: Wed, 22 Sep 2010 17:45:34 +0200	[thread overview]
Message-ID: <4C9A249E.2060100@miray.de> (raw)

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

Hi,

On some boards, like the AsRock K7S41GX, Grub fails to boot from 
superfloppy fat32 formated usb sticks.

The reason for the boot failure is that  the bios of the  mentioned 
board  replaces byte 0x24 of the bpb with the value 0x00 when it's read 
through the bios function.
In fat16 this byte contains the Disc unit number, so this causes no real 
harm there.
In fat32 this byte is part of the sectors per FAT information, so by 
modifying this value the bios makes Grub unable to read the fat system.

The attached workaround reads the backup bpb information on fat32 
filesystems and uses the sectors per fat information stored there.

PS: I'm sorry if this mail is a duplicate, but I sent it before but I 
wasn't subscribed so it might have been blocked/dropped before



[-- Attachment #2: fat.patch --]
[-- Type: text/plain, Size: 1508 bytes --]

--- ../grub2-upstream/grub2-upstream/grub-core/fs/fat.c	2010-09-21 12:13:17.154835710 +0200
+++ grub2-merge/grub-core/fs/fat.c	2010-09-22 10:23:27.935482451 +0200
@@ -214,6 +214,29 @@ grub_fat_mount (grub_disk_t disk)
 			    ? grub_le_to_cpu16 (bpb.sectors_per_fat_16)
 			    : grub_le_to_cpu32 (bpb.version_specific.fat32.sectors_per_fat_32))
 			   << data->logical_sector_bits);
+  if (bpb.sectors_per_fat_16)
+    data->sectors_per_fat = grub_le_to_cpu16 (bpb.sectors_per_fat_16) << data->logical_sector_bits;
+  else
+    {
+      /* Workaround for buggy BIOSes which replace offset 0x24 in the bpb 
+         with the drive number. This offset is part of sectors_per_fat_32 in
+         the fat32 structure. 
+         We read the backup bpb (if available) and use the value there */
+      struct grub_fat_bpb backup_bpb;
+      grub_uint32_t backup_bpb_address = grub_le_to_cpu16 (bpb.version_specific.fat32.backup_boot_sector) << data->logical_sector_bits;
+      if (bpb.version_specific.fat32.backup_boot_sector && 
+	  (! grub_disk_read (disk,
+			     backup_bpb_address,
+			     0,
+			     sizeof (backup_bpb),
+			     &backup_bpb)))
+	data->sectors_per_fat = grub_le_to_cpu32 (backup_bpb.version_specific.fat32.sectors_per_fat_32) << data->logical_sector_bits;
+
+      if (data->sectors_per_fat == 0)
+	data->sectors_per_fat = grub_le_to_cpu32 (bpb.version_specific.fat32.sectors_per_fat_32) << data->logical_sector_bits;
+    }
+
+
   if (data->sectors_per_fat == 0)
     goto fail;
 


             reply	other threads:[~2010-09-22 15:45 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-22 15:45 Thomas Frauendorfer | Miray Software [this message]
2010-09-22 16:14 ` [PATCH] Workaround for usb boot failure on some mainboards Lennart Sorensen
2010-09-22 16:52   ` Thomas Frauendorfer
2010-09-22 17:45     ` Lennart Sorensen
2010-09-22 19:54       ` Thomas Frauendorfer
2010-09-22 23:08 ` Vladimir 'φ-coder/phcoder' Serbinenko
  -- strict thread matches above, loose matches on Subject: below --
2010-09-22  9:07 Thomas Frauendorfer | Miray Software

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4C9A249E.2060100@miray.de \
    --to=t.frauendorfer@miray.de \
    --cc=grub-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.