Received: from list by lists.gnu.org with archive (Exim 4.71) id 1ehGDe-0000Nf-Qi for mharc-grub-devel@gnu.org; Thu, 01 Feb 2018 09:52:06 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54346) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ehGDb-0000Kw-SD for grub-devel@gnu.org; Thu, 01 Feb 2018 09:52:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ehGDY-0008KQ-PK for grub-devel@gnu.org; Thu, 01 Feb 2018 09:52:03 -0500 Received: from mail.38.de ([81.209.249.38]:50974) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ehGDY-0008JK-Ag for grub-devel@gnu.org; Thu, 01 Feb 2018 09:52:00 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=38.de; s=mail; h=Content-Transfer-Encoding:Content-Type:MIME-Version:Date:Message-ID:Subject:From:To; bh=GXxIPQaGKByKbEsZX2vgiBahtv4xYB+MzZZv0TAlJzk=; b=MN8K4/wAcv4L10yeOA3tsE1zzznRo4hvUUyE6/qNn4/E0HCiSjEtQfGDGGrI31G67puh5ZPZlBHLvCVpTKTHWmoVvW+dciU5TwWutFOSvmTVVsoKIozLUBQVylRTXsBQR71wvaBRUXDcuh0nAUgD6e1qnL7LCeJpkxsX2Iv+N7g=; Received: from x59cc9908.dyn.telefonica.de ([89.204.153.8] helo=[192.168.1.2]) by mail.38.de with esmtpsa (TLSv1:DHE-RSA-AES128-SHA:128) (Exim 4.80.1) (envelope-from ) id 1ehGDV-0002J6-9G for grub-devel@gnu.org; Thu, 01 Feb 2018 15:51:57 +0100 To: grub-devel@gnu.org From: "C. Masloch" Subject: [PATCH] chainloader: patch in BPB's sectors_per_track and num_heads Message-ID: <6708981a-8de3-8b88-d3e9-e75f75f5849e@38.de> Date: Thu, 1 Feb 2018 15:51:55 +0100 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Language: en-GB Content-Transfer-Encoding: 7bit X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x [fuzzy] X-Received-From: 81.209.249.38 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 01 Feb 2018 14:52:05 -0000 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 --- 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 #include +#include #include #include #include @@ -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