Skip to content

Commit

Permalink
x86, build: Fix portability issues when cross-building
Browse files Browse the repository at this point in the history
It would appear that we never actually generated a correct CRC when
building on a bigendian machine.  Depending on the word size, we would
either generate an all-zero CRC (64-bit machine) or a byte-swapped
CRC (32-bit machine.)  Fix the types used so we don't arbitrarily use
a 64-bit word to hold 32-bit numbers, and pass the CRC through
put_unaligned_le32() like all the other numbers.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Cc: Stephen Rothwell <sfr@canb.auug.org.au>
Cc: Matt Fleming <matt@console-pimps.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Nick Bowler <nbowler@elliptictech.com>
Link: http://lkml.kernel.org/r/20120229111322.9eb4b23ff1672e8853ad3b3b@canb.auug.org.au
  • Loading branch information
H. Peter Anvin committed Feb 29, 2012
1 parent b8d43cb commit a51f404
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions arch/x86/boot/tools/build.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

typedef unsigned char u8;
typedef unsigned short u16;
typedef unsigned long u32;
typedef unsigned int u32;

#define DEFAULT_MAJOR_ROOT 0
#define DEFAULT_MINOR_ROOT 0
Expand Down Expand Up @@ -247,8 +247,9 @@ int main(int argc, char ** argv)
}

/* Write the CRC */
fprintf(stderr, "CRC %lx\n", crc);
if (fwrite(&crc, 1, 4, stdout) != 4)
fprintf(stderr, "CRC %x\n", crc);
put_unaligned_le32(crc, buf);
if (fwrite(buf, 1, 4, stdout) != 4)
die("Writing CRC failed");

close(fd);
Expand Down

0 comments on commit a51f404

Please sign in to comment.