Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1OdUtb-0008HJ-Mu for mharc-grub-devel@gnu.org; Mon, 26 Jul 2010 17:07:35 -0400 Received: from [140.186.70.92] (port=56416 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OdUtX-0008CC-25 for grub-devel@gnu.org; Mon, 26 Jul 2010 17:07:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OdUtV-0007pk-OU for grub-devel@gnu.org; Mon, 26 Jul 2010 17:07:30 -0400 Received: from caffeine.csclub.uwaterloo.ca ([129.97.134.17]:45410) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OdUtV-0007pb-Ir for grub-devel@gnu.org; Mon, 26 Jul 2010 17:07:29 -0400 Received: from caffeine.csclub.uwaterloo.ca (localhost [127.0.0.1]) by caffeine.csclub.uwaterloo.ca (Postfix) with ESMTP id 12E46C228; Mon, 26 Jul 2010 17:07:29 -0400 (EDT) Received: by caffeine.csclub.uwaterloo.ca (Postfix, from userid 20367) id 00397CB50; Mon, 26 Jul 2010 17:07:28 -0400 (EDT) Date: Mon, 26 Jul 2010 17:07:28 -0400 To: The development of GNU GRUB Message-ID: <20100726210728.GW2632@caffeine.csclub.uwaterloo.ca> References: <4C4ABECA.2030008@gmail.com> <20100726172034.GV2632@caffeine.csclub.uwaterloo.ca> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="H1spWtNR+x+ondvy" Content-Disposition: inline In-Reply-To: <20100726172034.GV2632@caffeine.csclub.uwaterloo.ca> User-Agent: Mutt/1.5.18 (2008-05-17) From: lsorense@csclub.uwaterloo.ca (Lennart Sorensen) X-Virus-Scanned: ClamAV using ClamSMTP X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) Cc: Peter Henn , Felix Zielcke , Colin Watson Subject: Big Endian fix patch (was: Re: Couple more fixes for Linux raid metadata 1.x support) X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 26 Jul 2010 21:07:32 -0000 --H1spWtNR+x+ondvy Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Mon, Jul 26, 2010 at 01:20:34PM -0400, Lennart Sorensen wrote: > I just tried this patch with a fresh checkout. I still can't get grub > to read my 1.x raids (That I just created using the debian installer > daily build). > > If I use 0.9 raid, it seems to work fine. > > I keep getting errors like: > > Welcome to GRUB! > > error: read error on block: 18446744073709551360. > error: no such disk. > Entering rescue mode... > grub rescue> > > Now this is on a powerpc64 system, so it is big endian. That number by > the way is FFFFFFFFFFFFFF00. > > I wonder if some part of the 1.x raid handling code has an endianess bug. > > Got any guesses I can try before I just go convert back to 0.9 raids? > I really hate giving up on things that ought to work and loose the > debugging opportunity. Turns out it very much was endian issues. Here is a patch that fixes it for me. I am using your two recent patches as well. -- Len Sorensen --H1spWtNR+x+ondvy Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="md_raid_1x_bigendian_fix.diff" --- grub-updates/grub2-1.98+20100726/disk/mdraid_linux.c 2010-07-26 11:53:14.000000000 -0400 +++ grub2-1.98+20100726.working/disk/mdraid_linux.c 2010-07-26 17:03:31.127206219 -0400 @@ -290,7 +290,7 @@ grub_uint32_t disk_csum; grub_uint32_t csum; grub_uint64_t newcsum; - int size = 256 + sb->max_dev*2; + int size = 256 + grub_le_to_cpu32(sb->max_dev)*2; grub_uint32_t *isuper = (grub_uint32_t*)sb; int i; @@ -309,6 +309,12 @@ return csum; } +static grub_uint32_t grub_mdraid_csum_fold(grub_uint32_t csum) +{ + csum = (csum & 0xffff) + (csum >> 16); + return (csum & 0xffff) + (csum >> 16); +} + static grub_err_t grub_mdraid_detect_1x (grub_disk_t disk, grub_disk_addr_t sector, struct grub_raid_super_1x *sb, @@ -318,31 +324,31 @@ grub_uint64_t sb_size; struct grub_raid_super_1x *real_sb; - if (sb->major_version != 1) + if (grub_le_to_cpu32(sb->major_version) != 1) return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, "Unsupported RAID version: %d", - sb->major_version); + grub_le_to_cpu32(sb->major_version)); - if (sb->super_offset != sector) + if (grub_le_to_cpu64(sb->super_offset) != sector) /* We're not where we're supposed to be. Usually caused by a 1.0 superblock at the end of a disk with a single large partition. */ return grub_error (GRUB_ERR_OUT_OF_RANGE, "wrong superblock location"); - if (sb->feature_map & MD_FEATURE_RECOVERY_OFFSET) + if (grub_le_to_cpu32(sb->feature_map) & MD_FEATURE_RECOVERY_OFFSET) /* Disk is currently being recovered. Silently ignore it. */ return grub_error (GRUB_ERR_OUT_OF_RANGE, "recovery in progress"); - if (sb->feature_map & MD_FEATURE_RESHAPE_ACTIVE) + if (grub_le_to_cpu32(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, "reshape active"); /* Multipath. */ - if ((int) sb->level == -4) + if ((int) grub_le_to_cpu32(sb->level) == -4) sb->level = 1; - if (sb->level != 0 && sb->level != 1 && sb->level != 4 && - sb->level != 5 && sb->level != 6 && sb->level != 10) + if (grub_le_to_cpu32(sb->level) != 0 && grub_le_to_cpu32(sb->level) != 1 && grub_le_to_cpu32(sb->level) != 4 && + grub_le_to_cpu32(sb->level) != 5 && grub_le_to_cpu32(sb->level) != 6 && grub_le_to_cpu32(sb->level) != 10) return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, - "Unsupported RAID level: %d", sb->level); + "Unsupported RAID level: %d", grub_le_to_cpu32(sb->level)); /* 1.x superblocks don't have a fixed size on disk. So we have to read it again now that we now the max device count. */ @@ -357,7 +363,7 @@ return grub_errno; } - if (grub_mdraid_calc_csum(real_sb) != real_sb->sb_csum) + if (grub_mdraid_csum_fold(grub_mdraid_calc_csum(real_sb)) != grub_mdraid_csum_fold(real_sb->sb_csum)) { grub_free (real_sb); return grub_error (GRUB_ERR_OUT_OF_RANGE, "csum invalid"); @@ -403,7 +409,7 @@ grub_memcpy (array->uuid, real_sb->set_uuid, 16); - *start_sector = real_sb->data_offset; + *start_sector = grub_le_to_cpu64(real_sb->data_offset); grub_free (real_sb); return 0; @@ -457,9 +463,10 @@ &sb_1x)) return grub_errno; - if (sb_1x.magic == SB_MAGIC) + if (grub_le_to_cpu32(sb_1x.magic) == SB_MAGIC) { return grub_mdraid_detect_1x (disk, sector, &sb_1x, array, start_sector); + } } /* Neither 0.90 nor 1.x. */ --H1spWtNR+x+ondvy--