Fix GPT build failure on big-endian architectures
PATCH 1/1 Fix GPT build failure on big-endian architectures
Big-endian (powerpc or sparc) builds of current trunk fail as follows:
gcc-4.4 -DHAVE_CONFIG_H -I. -I../.. -Wall -W -I./include -DGRUB_UTIL=1 -DGRUB_LIBDIR=\"/usr/lib/grub\" -DLOCALEDIR=\"/usr/share/locale\" -DGRUB_MACHINE_IEEE1275=1 -DGRUB_MACHINE_SPARC64=1 -DGRUB_MACHINE=SPARC64_IEEE1275 -DGRUB_FILE=\"grub-core/partmap/gpt.c\" -I. -I../.. -I. -I../.. -I../../include -I./include -I../../grub-core/lib/libgcrypt_wrap -I../../contrib/zfs/include -g -Wall -O2 -Wno-error -Wno-missing-field-initializers -c -o grub-core/partmap/libgrubmods_a-gpt.o test -f 'grub-core/partmap/gpt.c' || echo '../../'grub-core/partmap/gpt.c
../../grub-core/partmap/gpt.c:36: error: initializer element is not constant ../../grub-core/partmap/gpt.c:36: error: (near initialization for 'grub_gpt_partition_type_bios_boot.data1') ../../grub-core/partmap/gpt.c:36: error: braced-group within expression allowed only inside a function ../../grub-core/partmap/gpt.c:36: error: braced-group within expression allowed only inside a function make[4]: *** [grub-core/partmap/libgrubmods_a-gpt.o] Error 1
I think a reasonable approach would be to do the byte-swapping at module initialisation time. Does this patch look OK?
2010-11-22 Colin Watson <[email protected]>
* include/grub/gpt_partition.h (GRUB_GPT_PARTITION_TYPE_BIOS_BOOT):
Remove byte-swapping function calls, which are not valid in structure initialisers.
* grub-core/partmap/gpt.c (grub_gpt_partition_type_bios_boot): Make non-const.
(GRUB_MOD_INIT): Byte-swap data1, data2, and data3 fields of grub_gpt_partition_type_bios_boot.
=== modified file 'grub-core/partmap/gpt.c'
partmap/gpt.c +9 -1
@@ -33,7 +33,7 @@ static grub_uint8_t grub_gpt_magic[8] =static const grub_gpt_part_type_t grub_gpt_partition_type_empty =GRUB_GPT_PARTITION_TYPE_EMPTY ;#ifdef GRUB_UTIL -static const grub_gpt_part_type_t grub_gpt_partition_type_bios_boot =GRUB_GPT_PARTITION_TYPE_BIOS_BOOT ; +static grub_gpt_part_type_t grub_gpt_partition_type_bios_boot =GRUB_GPT_PARTITION_TYPE_BIOS_BOOT ;#endif /* 512 << 7 = 65536 byte sectors. */
@@ -198,6 +198,14 @@ static struct grub_partition_map grub_gpGRUB_MOD_INIT (part_gpt) {grub_partition_map_register (&grub_gpt_partition_map); +#ifdef GRUB_UTIL + grub_gpt_partition_type_bios_boot.data1 = +grub_cpu_to_le32 (grub_gpt_partition_type_bios_boot.data1); + grub_gpt_partition_type_bios_boot.data2 = +grub_cpu_to_le32 (grub_gpt_partition_type_bios_boot.data2); + grub_gpt_partition_type_bios_boot.data3 = +grub_cpu_to_le32 (grub_gpt_partition_type_bios_boot.data3); +#endif }GRUB_MOD_FINI (part_gpt)
=== modified file 'include/grub/gpt_partition.h'
grub/gpt_partition.h +1 -1
@@ -36,7 +36,7 @@ typedef struct grub_gpt_part_type grub_g }#define GRUB_GPT_PARTITION_TYPE_BIOS_BOOT \ - { grub_cpu_to_le32 (0x21686148), grub_cpu_to_le16 (0x6449), grub_cpu_to_le16 (0x6e6f), \ + { 0x21686148, 0x6449, 0x6e6f, \ { 0x74, 0x4e, 0x65, 0x65, 0x64, 0x45, 0x46, 0x49 } \ }
Signature · 1 line
Colin Watson [[email protected]]
Quoted 6 lines · Colin Watson
partmap/gpt.c +1
-0@@ -198,6 +198,14 @@ static struct grub_partition_map grub_gpGRUB_MOD_INIT (part_gpt) {grub_partition_map_register (&grub_gpt_partition_map); +#ifdef GRUB_UTIL
partmap/gpt.c static struct grub_partition_map grub_gp · line 211
Quoted 10 lines
partmap/gpt.c +7
-0+ grub_gpt_partition_type_bios_boot.data1 = +grub_cpu_to_le32 (grub_gpt_partition_type_bios_boot.data1); + grub_gpt_partition_type_bios_boot.data2 = +grub_cpu_to_le32 (grub_gpt_partition_type_bios_boot.data2); + grub_gpt_partition_type_bios_boot.data3 = +grub_cpu_to_le32 (grub_gpt_partition_type_bios_boot.data3); +#endif }GRUB_MOD_FINI (part_gpt)
Of course the second and third of these should have been grub_cpu_to_le16.
I've gone ahead and applied this, with that correction; please do correct me if you notice anything else wrong with it.
Signature · 1 line
Colin Watson [[email protected]]