Skip to contentSkip to conversation

improve GPT support on PC/BIOS

PATCH New Robert Millan 1 participant 1 message Feb 17, 2008

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 improve GPT support on PC/BIOS

This patch improves GPT support on PC/BIOS systems by allowing grub-setup to locate usable regions for embedding our core.img (akin to sector 0x1 on PC partmap), and use them accordingly.

Comments?

Signature · 5 lines
Robert Millan

<GPLv2> I know my rights; I want my phone call!
<DRM> What use is a phone call… if you are unable to speak?
(as seen on /.)

2008-02-17 Robert Millan <[email protected]>

* partmap/gpt.c: Include <grub/gpt_partition.h>'. (grub_gpt_partition_type_empty): Redefine with macro from <grub/gpt_partition.h>'. (gpt_partition_map_iterate): Adjust partition type comparison.

Export entry' as partmap-specific part.data' struct. (grub_gpt_header, grub_gpt_partentry): Move from here ...

* include/grub/gpt_partition.h (grub_gpt_header) (grub_gpt_partentry): ... to here (new file).

* util/i386/pc/grub-setup.c: Include `<grub/gpt_partition.h>'.

(grub_gpt_partition_type_bios_boot): New const variable, defined with macro from `<grub/gpt_partition.h>'.

(setup): Replace first_start' with embed_region', which keeps track of the embed region (and is partmap-agnostic).

Replace find_first_partition_start() with find_usable_region(), which finds a usable region for embedding using partmap-specific knowledge (supports PC/MSDOS and GPT).

Fix all assumptions that the embed region start at sector 1, using embed_region.start' from now on. Similarly, use embed_region.end' rather than `first_start' to calculate available size.

In grub_util_info() message, replace "into after the MBR" with an indication of the specific sector our embed region starts at.

partmap/gpt.c renamed from grub2/partmap/gpt.c +5 -31
diff -x '*~' -Nurp ../grub2/partmap/gpt.c ./partmap/gpt.c
@@ -1,7 +1,7 @@
 /* gpt.c - Read GUID Partition Tables (GPT).  */
 /*
  *  GRUB  --  GRand Unified Bootloader
- *  Copyright (C) 2002,2005,2006,2007  Free Software Foundation, Inc.
+ *  Copyright (C) 2002,2005,2006,2007,2008  Free Software Foundation, Inc.
  *
  *  GRUB is free software: you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -23,41 +23,14 @@
 #include <grub/partition.h>
 #include <grub/dl.h>
 #include <grub/pc_partition.h>
-
-struct grub_gpt_header
-{
-  grub_uint8_t magic[8];
-  grub_uint32_t version;
-  grub_uint32_t headersize;
-  grub_uint32_t crc32;
-  grub_uint32_t unused1;
-  grub_uint64_t primary;
-  grub_uint64_t backup;
-  grub_uint64_t start;
-  grub_uint64_t end;
-  grub_uint8_t guid[16];
-  grub_uint64_t partitions;
-  grub_uint32_t maxpart;
-  grub_uint32_t partentry_size;
-  grub_uint32_t partentry_crc32;
-} __attribute__ ((packed));
-
-struct grub_gpt_partentry
-{
-  grub_uint8_t type[16];
-  grub_uint8_t guid[16];
-  grub_uint64_t start;
-  grub_uint64_t end;
-  grub_uint8_t attrib;
-  char name[72];
-} __attribute__ ((packed));
+#include <grub/gpt_partition.h>
 
 static grub_uint8_t grub_gpt_magic[8] =
   {
     45, 46, 49, 20, 50, 41, 52, 54
   };
 
-static grub_uint8_t grub_gpt_partition_type_empty[16] = { 0 };
+static const grub_gpt_part_type_t grub_gpt_partition_type_empty = GRUB_GPT_PARTITION_TYPE_EMPTY;
 
 static struct grub_partition_map grub_gpt_partition_map;
 
@@ -114,7 +87,7 @@ gpt_partition_map_iterate (grub_disk_t d
 			  sizeof (entry), (char *) &entry))
 	return grub_errno;
 
-      if (grub_memcmp (grub_gpt_partition_type_empty, entry.type,
+      if (grub_memcmp (&grub_gpt_partition_type_empty, &entry.type,
 		       sizeof (grub_gpt_partition_type_empty)))
 	{
 	  /* Calculate the first block and the size of the partition.  */
@@ -124,6 +97,7 @@ gpt_partition_map_iterate (grub_disk_t d
 	  part.offset = entries;
 	  part.index = partno;
 	  part.partmap = &grub_gpt_partition_map;
+	  part.data = &entry;
 
 	  grub_dprintf ("gpt", "GPT entry %d: start=%lld, length=%lld\n",
 			partno, part.start, part.len);
include/grub/gpt_partition.h renamed from grub2/include/grub/gpt_partition.h +71 -0

71 lines not on this page · raw message

util/i386/pc/grub-setup.c renamed from grub2/util/i386/pc/grub-setup.c +35 -19

114 lines not on this page · raw message