Gentoo Archives: gentoo-commits

From: "Robin H. Johnson (robbat2)" <robbat2@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] gentoo-x86 commit in sys-boot/grub/files: grub-0.97-gpt.patch
Date: Mon, 25 Feb 2008 01:44:42
Message-Id: E1JTSOV-0001Zu-5K@stork.gentoo.org
1 robbat2 08/02/25 01:44:39
2
3 Added: grub-0.97-gpt.patch
4 Log:
5 Bug #178586, include support for booting from a GPT-style disk.
6 (Portage version: 2.1.4.4)
7
8 Revision Changes Path
9 1.1 sys-boot/grub/files/grub-0.97-gpt.patch
10
11 file : http://sources.gentoo.org/viewcvs.py/gentoo-x86/sys-boot/grub/files/grub-0.97-gpt.patch?rev=1.1&view=markup
12 plain: http://sources.gentoo.org/viewcvs.py/gentoo-x86/sys-boot/grub/files/grub-0.97-gpt.patch?rev=1.1&content-type=text/plain
13
14 Index: grub-0.97-gpt.patch
15 ===================================================================
16 diff -ruBbd --unidirectional-new-file grub-0.96/stage2/builtins.c grub-0.96-patched/stage2/builtins.c
17 --- grub-0.96/stage2/builtins.c 2004-06-20 09:33:04.000000000 -0400
18 +++ grub-0.96-patched/stage2/builtins.c 2007-01-04 13:56:06.000000000 -0500
19 @@ -1229,14 +1229,15 @@
20 for (drive = 0x80; drive < 0x88; drive++)
21 {
22 unsigned long part = 0xFFFFFF;
23 - unsigned long start, len, offset, ext_offset;
24 - int type, entry;
25 + unsigned long start, len, offset, ext_offset, gpt_offset;
26 + int type, entry, gpt_count, gpt_size;
27 char buf[SECTOR_SIZE];
28
29 current_drive = drive;
30 while (next_partition (drive, 0xFFFFFF, &part, &type,
31 &start, &len, &offset, &entry,
32 - &ext_offset, buf))
33 + &ext_offset, &gpt_offset,
34 + &gpt_count, &gpt_size, buf))
35 {
36 if (type != PC_SLICE_TYPE_NONE
37 && ! IS_PC_SLICE_TYPE_BSD (type)
38 @@ -2806,8 +2807,8 @@
39 {
40 int new_type;
41 unsigned long part = 0xFFFFFF;
42 - unsigned long start, len, offset, ext_offset;
43 - int entry, type;
44 + unsigned long start, len, offset, ext_offset, gpt_offset;
45 + int entry, type, gpt_count, gpt_size;
46 char mbr[512];
47
48 /* Get the drive and the partition. */
49 @@ -2844,7 +2845,14 @@
50 /* Look for the partition. */
51 while (next_partition (current_drive, 0xFFFFFF, &part, &type,
52 &start, &len, &offset, &entry,
53 - &ext_offset, mbr))
54 + &ext_offset, &gpt_offset, &gpt_count, &gpt_size, mbr))
55 + /* The partition may not be a GPT partition. */
56 + if (gpt_offset != 0)
57 + {
58 + errnum = ERR_BAD_ARGUMENT;
59 + return 1;
60 + }
61 +
62 {
63 if (part == current_partition)
64 {
65 diff -ruBbd --unidirectional-new-file grub-0.96/stage2/disk_io.c grub-0.96-patched/stage2/disk_io.c
66 --- grub-0.96/stage2/disk_io.c 2004-05-23 12:35:24.000000000 -0400
67 +++ grub-0.96-patched/stage2/disk_io.c 2007-01-04 14:01:08.000000000 -0500
68 @@ -21,6 +21,7 @@
69
70 #include <shared.h>
71 #include <filesys.h>
72 +#include <gpt.h>
73
74 #ifdef SUPPORT_NETBOOT
75 # define GRUB 1
76 @@ -502,8 +503,8 @@
77 set_partition_hidden_flag (int hidden)
78 {
79 unsigned long part = 0xFFFFFF;
80 - unsigned long start, len, offset, ext_offset;
81 - int entry, type;
82 + unsigned long start, len, offset, ext_offset, gpt_offset;
83 + int entry, type, gpt_count, gpt_size;
84 char mbr[512];
85
86 /* The drive must be a hard disk. */
87 @@ -524,7 +525,14 @@
88 /* Look for the partition. */
89 while (next_partition (current_drive, 0xFFFFFF, &part, &type,
90 &start, &len, &offset, &entry,
91 - &ext_offset, mbr))
92 + &ext_offset, &gpt_offset, &gpt_count, &gpt_size, mbr))
93 + /* The partition may not be a GPT partition. */
94 + if (gpt_offset != 0)
95 + {
96 + errnum = ERR_BAD_ARGUMENT;
97 + return 1;
98 + }
99 +
100 {
101 if (part == current_partition)
102 {
103 @@ -577,11 +585,14 @@
104 unsigned long *partition, int *type,
105 unsigned long *start, unsigned long *len,
106 unsigned long *offset, int *entry,
107 - unsigned long *ext_offset, char *buf)
108 + unsigned long *ext_offset,
109 + unsigned long *gpt_offset, int *gpt_count,
110 + int *gpt_size, char *buf)
111 {
112 /* Forward declarations. */
113 auto int next_bsd_partition (void);
114 auto int next_pc_slice (void);
115 + auto int next_gpt_slice(void);
116
117 /* Get next BSD partition in current PC slice. */
118 int next_bsd_partition (void)
119 @@ -666,6 +677,40 @@
120 return 0;
121 }
122
123 + /* If this is a GPT partition table, read it as such. */
124 + if (*entry == -1 && *offset == 0 && PC_SLICE_TYPE (buf, 0) == PC_SLICE_TYPE_GPT)
125 + {
126 + struct grub_gpt_header *hdr = (struct grub_gpt_header *) buf;
127 +
128 + /* Read in the GPT Partition table header. */
129 + if (! rawread (drive, 1, 0, SECTOR_SIZE, buf))
130 + return 0;
131 +
132 + if (hdr->magic == GPT_HEADER_MAGIC && hdr->version == 0x10000)
133 + {
134 + /* Let gpt_offset point to the first entry in the GPT
135 + partition table. This can also be used by callers of
136 + next_partition to determine if a entry comes from a
137 + GPT partition table or not. */
138 + *gpt_offset = hdr->partitions;
139 + *gpt_count = hdr->maxpart;
140 + *gpt_size = hdr->partentry_size;
141 +
142 + return next_gpt_slice();
143 + }
144 + else
145 + {
146 + /* This is not a valid header for a GPT partition table.
147 + Re-read the MBR or the boot sector of the extended
148 + partition. */
149 + if (! rawread (drive, *offset, 0, SECTOR_SIZE, buf))
150 + return 0;
151 + }
152 + }
153 +
154 + /* Not a GPT partition. */
155 + *gpt_offset = 0;
156 +
157 /* Increase the entry number. */
158 (*entry)++;
159
160 @@ -710,6 +755,43 @@
161 return 1;
162 }
163
164 + /* Get the next GPT slice. */
165 + int next_gpt_slice (void)
166 + {
167 + struct grub_gpt_partentry *gptentry = (struct grub_gpt_partentry *) buf;
168 + /* Make GPT partitions show up as PC slices. */
169 + int pc_slice_no = (*partition & 0xFF0000) >> 16;
170 +
171 + /* If this is the first time... */
172 + if (pc_slice_no == 0xFF)
173 + {
174 + pc_slice_no = -1;
175 + *entry = -1;
176 + }
177 +
178 + do {
179 + (*entry)++;
180 +
181 + if (*entry >= *gpt_count)
182 + {
183 + errnum = ERR_NO_PART;
184 + return 0;
185 + }
186 + /* Read in the GPT Partition table entry. */
187 + if (! rawread (drive, (*gpt_offset) + GPT_ENTRY_SECTOR (*gpt_size, *entry), GPT_ENTRY_INDEX (*gpt_size, *entry), *gpt_size, buf))
188 + return 0;
189 + } while (! (gptentry->type1 && gptentry->type2));
190 +
191 + pc_slice_no++;
192 + *start = gptentry->start;
193 + *len = gptentry->end - gptentry->start + 1;
194 + *type = PC_SLICE_TYPE_EXT2FS;
195 + *entry = pc_slice_no;
196 + *partition = (*entry << 16) | 0xFFFF;
197 +
198 + return 1;
199 + }
200 +
201 /* Start the body of this function. */
202
203 #ifndef STAGE1_5
204 @@ -717,6 +799,9 @@
205 return 0;
206 #endif
207
208 + if (*partition != 0xFFFFFF && *gpt_offset != 0)
209 + return next_gpt_slice ();
210 +
211 /* If previous partition is a BSD partition or a PC slice which
212 contains BSD partitions... */
213 if ((*partition != 0xFFFFFF && IS_PC_SLICE_TYPE_BSD (*type & 0xff))
214 @@ -755,6 +840,9 @@
215 unsigned long dest_partition = current_partition;
216 unsigned long part_offset;
217 unsigned long ext_offset;
218 + unsigned long gpt_offset;
219 + int gpt_count;
220 + int gpt_size;
221 int entry;
222 char buf[SECTOR_SIZE];
223 int bsd_part, pc_slice;
224 @@ -766,7 +854,8 @@
225 int ret = next_partition (current_drive, dest_partition,
226 &current_partition, &current_slice,
227 &part_start, &part_length,
228 - &part_offset, &entry, &ext_offset, buf);
229 + &part_offset, &entry, &ext_offset,
230 + &gpt_offset, &gpt_count, &gpt_size, buf);
231 bsd_part = (current_partition >> 8) & 0xFF;
232 pc_slice = current_partition >> 16;
233 return ret;
234 diff -ruBbd --unidirectional-new-file grub-0.96/stage2/gpt.h grub-0.96-patched/stage2/gpt.h
235 --- grub-0.96/stage2/gpt.h 1969-12-31 19:00:00.000000000 -0500
236 +++ grub-0.96-patched/stage2/gpt.h 2007-01-04 13:52:14.000000000 -0500
237 @@ -0,0 +1,68 @@
238 +/*
239 + * GRUB -- GRand Unified Bootloader
240 + * Copyright (C) 2002,2005,2006 Free Software Foundation, Inc.
241 + *
242 + * This program is free software; you can redistribute it and/or modify
243 + * it under the terms of the GNU General Public License as published by
244 + * the Free Software Foundation; either version 2 of the License, or
245 + * (at your option) any later version.
246 + *
247 + * This program is distributed in the hope that it will be useful,
248 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
249 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
250 + * GNU General Public License for more details.
251 + *
252 + * You should have received a copy of the GNU General Public License
253 + * along with this program; if not, write to the Free Software
254 + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
255 + */
256 +
257 +#ifndef _GPT_H
258 +#define _GPT_H
259 +
260 +typedef signed char grub_int8_t;
261 +typedef signed short grub_int16_t;
262 +typedef signed int grub_int32_t;
263 +typedef signed long long int grub_int64_t;
264 +typedef unsigned char grub_uint8_t;
265 +typedef unsigned short grub_uint16_t;
266 +typedef unsigned int grub_uint32_t;
267 +typedef unsigned long long int grub_uint64_t;
268 +
269 +struct grub_gpt_header
270 +{
271 + grub_uint64_t magic;
272 + grub_uint32_t version;
273 + grub_uint32_t headersize;
274 + grub_uint32_t crc32;
275 + grub_uint32_t unused1;
276 + grub_uint64_t primary;
277 + grub_uint64_t backup;
278 + grub_uint64_t start;
279 + grub_uint64_t end;
280 + grub_uint8_t guid[16];
281 + grub_uint64_t partitions;
282 + grub_uint32_t maxpart;
283 + grub_uint32_t partentry_size;
284 + grub_uint32_t partentry_crc32;
285 +} __attribute__ ((packed));
286 +
287 +struct grub_gpt_partentry
288 +{
289 + grub_uint64_t type1;
290 + grub_uint64_t type2;
291 + grub_uint8_t guid[16];
292 + grub_uint64_t start;
293 + grub_uint64_t end;
294 + grub_uint8_t attrib;
295 + char name[72];
296 +} __attribute__ ((packed));
297 +
298 +#define GPT_HEADER_MAGIC 0x5452415020494645UL
299 +
300 +#define GPT_ENTRY_SECTOR(size,entry) \
301 + ((((entry) * (size) + 1) & ~(SECTOR_SIZE - 1)) >> SECTOR_BITS)
302 +#define GPT_ENTRY_INDEX(size,entry) \
303 + ((((entry) * (size) + 1) & (SECTOR_SIZE - 1)) - 1)
304 +
305 +#endif /* _GPT_H */
306 diff -ruBbd --unidirectional-new-file grub-0.96/stage2/pc_slice.h grub-0.96-patched/stage2/pc_slice.h
307 --- grub-0.96/stage2/pc_slice.h 2003-07-09 07:45:53.000000000 -0400
308 +++ grub-0.96-patched/stage2/pc_slice.h 2007-01-04 13:52:14.000000000 -0500
309 @@ -115,6 +115,7 @@
310 #define PC_SLICE_TYPE_LINUX_EXTENDED 0x85
311 #define PC_SLICE_TYPE_VSTAFS 0x9e
312 #define PC_SLICE_TYPE_DELL_UTIL 0xde
313 +#define PC_SLICE_TYPE_GPT 0xee
314 #define PC_SLICE_TYPE_LINUX_RAID 0xfd
315
316
317 diff -ruBbd --unidirectional-new-file grub-0.96/stage2/shared.h grub-0.96-patched/stage2/shared.h
318 --- grub-0.96/stage2/shared.h 2004-06-19 12:40:09.000000000 -0400
319 +++ grub-0.96-patched/stage2/shared.h 2007-01-04 13:52:15.000000000 -0500
320 @@ -934,7 +934,9 @@
321 unsigned long *partition, int *type,
322 unsigned long *start, unsigned long *len,
323 unsigned long *offset, int *entry,
324 - unsigned long *ext_offset, char *buf);
325 + unsigned long *ext_offset,
326 + unsigned long *gpt_offset, int *gpt_count,
327 + int *gpt_size, char *buf);
328
329 /* Sets device to the one represented by the SAVED_* parameters. */
330 int make_saved_active (void);
331
332
333
334 --
335 gentoo-commits@l.g.o mailing list