~psusi/ubuntu/saucy/grub2/fix-dmraid

« back to all changes in this revision

Viewing changes to .pc/ubuntu_no_insmod_on_sb.patch/grub-core/kern/efi/efi.c

  • Committer: Package Import Robot
  • Author(s): Colin Watson
  • Date: 2013-01-03 11:40:44 UTC
  • mfrom: (17.6.31 experimental)
  • Revision ID: package-import@ubuntu.com-20130103114044-et8gar9lol415wc9
Tags: 2.00-10ubuntu1
* Resynchronise with Debian.  Remaining changes:
  - Adjust for default Ubuntu boot options ("quiet splash").
  - Default to hiding the menu; holding down Shift at boot will show it.
  - Set a monochromatic theme and an appropriate background for Ubuntu.
  - Apply Ubuntu GRUB Legacy changes to legacy update-grub script.
  - Fix backslash-escaping in merge_debconf_into_conf.
  - Remove "GNU/Linux" from default distributor string.
  - Add crashkernel option.
  - Bypass menu unless other OSes are installed or Shift is pressed.
  - Allow Shift to interrupt 'sleep --interruptible'.
  - Reduce visual clutter in normal mode.
  - Remove verbose messages printed before reading configuration.
  - Suppress kernel/initrd progress messages, except in recovery mode.
  - Show the boot menu if the previous boot failed.
  - Adjust upgrade version checks for Ubuntu.
  - Suppress "GRUB loading" message unless Shift is held down.
  - Adjust versions of grub-doc and grub-legacy-doc conflicts.
  - Build-depend on qemu-kvm rather than qemu-system for grub-pc tests.
  - Check hardware support before using gfxpayload=keep.
  - Set vt.handoff=7 for smooth handoff to kernel graphical mode.
  - In recovery mode, add nomodeset to the Linux kernel arguments, and
    remove the 'set gfxpayload=keep' command.
  - Skip Windows os-prober entries on Wubi systems, and suppress the menu
    by default if those are the only other-OS entries.
  - Handle probing striped DM-RAID devices.
  - Replace 'single' by 'recovery' when friendly-recovery is installed.
  - Disable cursor as early as possible in grub_main.
  - Apply patch from Fedora to add a "linuxefi" loader.
  - Automatically call linuxefi from linux when necessary.
  - On amd64, add raw-uefi custom upload tarballs for signing.
  - Generate configuration for signed UEFI kernels if available.
  - Install signed images if UEFI Secure Boot is enabled.
  - Output a menu entry for firmware setup on UEFI FastBoot systems.
  - Stop using the /usr/share/images/desktop-base/desktop-grub.png
    alternative as the fallback background.
  - If the postinst is running in a container, skip grub-install and all
    its associated questions.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* efi.c - generic EFI support */
2
 
/*
3
 
 *  GRUB  --  GRand Unified Bootloader
4
 
 *  Copyright (C) 2006,2007,2008,2009,2010  Free Software Foundation, Inc.
5
 
 *
6
 
 *  GRUB is free software: you can redistribute it and/or modify
7
 
 *  it under the terms of the GNU General Public License as published by
8
 
 *  the Free Software Foundation, either version 3 of the License, or
9
 
 *  (at your option) any later version.
10
 
 *
11
 
 *  GRUB is distributed in the hope that it will be useful,
12
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
 *  GNU General Public License for more details.
15
 
 *
16
 
 *  You should have received a copy of the GNU General Public License
17
 
 *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
18
 
 */
19
 
 
20
 
#include <grub/misc.h>
21
 
#include <grub/charset.h>
22
 
#include <grub/efi/api.h>
23
 
#include <grub/efi/efi.h>
24
 
#include <grub/efi/console_control.h>
25
 
#include <grub/efi/pe32.h>
26
 
#include <grub/time.h>
27
 
#include <grub/term.h>
28
 
#include <grub/kernel.h>
29
 
#include <grub/mm.h>
30
 
 
31
 
/* The handle of GRUB itself. Filled in by the startup code.  */
32
 
grub_efi_handle_t grub_efi_image_handle;
33
 
 
34
 
/* The pointer to a system table. Filled in by the startup code.  */
35
 
grub_efi_system_table_t *grub_efi_system_table;
36
 
 
37
 
static grub_efi_guid_t console_control_guid = GRUB_EFI_CONSOLE_CONTROL_GUID;
38
 
static grub_efi_guid_t loaded_image_guid = GRUB_EFI_LOADED_IMAGE_GUID;
39
 
static grub_efi_guid_t device_path_guid = GRUB_EFI_DEVICE_PATH_GUID;
40
 
 
41
 
void *
42
 
grub_efi_locate_protocol (grub_efi_guid_t *protocol, void *registration)
43
 
{
44
 
  void *interface;
45
 
  grub_efi_status_t status;
46
 
 
47
 
  status = efi_call_3 (grub_efi_system_table->boot_services->locate_protocol,
48
 
                       protocol, registration, &interface);
49
 
  if (status != GRUB_EFI_SUCCESS)
50
 
    return 0;
51
 
 
52
 
  return interface;
53
 
}
54
 
 
55
 
/* Return the array of handles which meet the requirement. If successful,
56
 
   the number of handles is stored in NUM_HANDLES. The array is allocated
57
 
   from the heap.  */
58
 
grub_efi_handle_t *
59
 
grub_efi_locate_handle (grub_efi_locate_search_type_t search_type,
60
 
                        grub_efi_guid_t *protocol,
61
 
                        void *search_key,
62
 
                        grub_efi_uintn_t *num_handles)
63
 
{
64
 
  grub_efi_boot_services_t *b;
65
 
  grub_efi_status_t status;
66
 
  grub_efi_handle_t *buffer;
67
 
  grub_efi_uintn_t buffer_size = 8 * sizeof (grub_efi_handle_t);
68
 
 
69
 
  buffer = grub_malloc (buffer_size);
70
 
  if (! buffer)
71
 
    return 0;
72
 
 
73
 
  b = grub_efi_system_table->boot_services;
74
 
  status = efi_call_5 (b->locate_handle, search_type, protocol, search_key,
75
 
                             &buffer_size, buffer);
76
 
  if (status == GRUB_EFI_BUFFER_TOO_SMALL)
77
 
    {
78
 
      grub_free (buffer);
79
 
      buffer = grub_malloc (buffer_size);
80
 
      if (! buffer)
81
 
        return 0;
82
 
 
83
 
      status = efi_call_5 (b->locate_handle, search_type, protocol, search_key,
84
 
                                 &buffer_size, buffer);
85
 
    }
86
 
 
87
 
  if (status != GRUB_EFI_SUCCESS)
88
 
    {
89
 
      grub_free (buffer);
90
 
      return 0;
91
 
    }
92
 
 
93
 
  *num_handles = buffer_size / sizeof (grub_efi_handle_t);
94
 
  return buffer;
95
 
}
96
 
 
97
 
void *
98
 
grub_efi_open_protocol (grub_efi_handle_t handle,
99
 
                        grub_efi_guid_t *protocol,
100
 
                        grub_efi_uint32_t attributes)
101
 
{
102
 
  grub_efi_boot_services_t *b;
103
 
  grub_efi_status_t status;
104
 
  void *interface;
105
 
 
106
 
  b = grub_efi_system_table->boot_services;
107
 
  status = efi_call_6 (b->open_protocol, handle,
108
 
                       protocol,
109
 
                       &interface,
110
 
                       grub_efi_image_handle,
111
 
                       0,
112
 
                       attributes);
113
 
  if (status != GRUB_EFI_SUCCESS)
114
 
    return 0;
115
 
 
116
 
  return interface;
117
 
}
118
 
 
119
 
int
120
 
grub_efi_set_text_mode (int on)
121
 
{
122
 
  grub_efi_console_control_protocol_t *c;
123
 
  grub_efi_screen_mode_t mode, new_mode;
124
 
 
125
 
  c = grub_efi_locate_protocol (&console_control_guid, 0);
126
 
  if (! c)
127
 
    /* No console control protocol instance available, assume it is
128
 
       already in text mode. */
129
 
    return 1;
130
 
 
131
 
  if (efi_call_4 (c->get_mode, c, &mode, 0, 0) != GRUB_EFI_SUCCESS)
132
 
    return 0;
133
 
 
134
 
  new_mode = on ? GRUB_EFI_SCREEN_TEXT : GRUB_EFI_SCREEN_GRAPHICS;
135
 
  if (mode != new_mode)
136
 
    if (efi_call_2 (c->set_mode, c, new_mode) != GRUB_EFI_SUCCESS)
137
 
      return 0;
138
 
 
139
 
  return 1;
140
 
}
141
 
 
142
 
void
143
 
grub_efi_stall (grub_efi_uintn_t microseconds)
144
 
{
145
 
  efi_call_1 (grub_efi_system_table->boot_services->stall, microseconds);
146
 
}
147
 
 
148
 
grub_efi_loaded_image_t *
149
 
grub_efi_get_loaded_image (grub_efi_handle_t image_handle)
150
 
{
151
 
  return grub_efi_open_protocol (image_handle,
152
 
                                 &loaded_image_guid,
153
 
                                 GRUB_EFI_OPEN_PROTOCOL_GET_PROTOCOL);
154
 
}
155
 
 
156
 
void
157
 
grub_exit (void)
158
 
{
159
 
  grub_efi_fini ();
160
 
  efi_call_4 (grub_efi_system_table->boot_services->exit,
161
 
              grub_efi_image_handle, GRUB_EFI_SUCCESS, 0, 0);
162
 
  for (;;) ;
163
 
}
164
 
 
165
 
grub_err_t
166
 
grub_efi_set_virtual_address_map (grub_efi_uintn_t memory_map_size,
167
 
                                  grub_efi_uintn_t descriptor_size,
168
 
                                  grub_efi_uint32_t descriptor_version,
169
 
                                  grub_efi_memory_descriptor_t *virtual_map)
170
 
{
171
 
  grub_efi_runtime_services_t *r;
172
 
  grub_efi_status_t status;
173
 
 
174
 
  r = grub_efi_system_table->runtime_services;
175
 
  status = efi_call_4 (r->set_virtual_address_map, memory_map_size,
176
 
                       descriptor_size, descriptor_version, virtual_map);
177
 
 
178
 
  if (status == GRUB_EFI_SUCCESS)
179
 
    return GRUB_ERR_NONE;
180
 
 
181
 
  return grub_error (GRUB_ERR_IO, "set_virtual_address_map failed");
182
 
}
183
 
 
184
 
grub_err_t
185
 
grub_efi_set_variable(const char *var, const grub_efi_guid_t *guid,
186
 
                      void *data, grub_size_t datasize)
187
 
{
188
 
  grub_efi_status_t status;
189
 
  grub_efi_runtime_services_t *r;
190
 
  grub_efi_char16_t *var16;
191
 
  grub_size_t len, len16;
192
 
 
193
 
  len = grub_strlen (var);
194
 
  len16 = len * GRUB_MAX_UTF16_PER_UTF8;
195
 
  var16 = grub_malloc ((len16 + 1) * sizeof (var16[0]));
196
 
  if (!var16)
197
 
    return grub_errno;
198
 
  len16 = grub_utf8_to_utf16 (var16, len16, (grub_uint8_t *) var, len, NULL);
199
 
  var16[len16] = 0;
200
 
 
201
 
  r = grub_efi_system_table->runtime_services;
202
 
 
203
 
  status = efi_call_5 (r->set_variable, var16, guid, 
204
 
                       (GRUB_EFI_VARIABLE_NON_VOLATILE
205
 
                        | GRUB_EFI_VARIABLE_BOOTSERVICE_ACCESS
206
 
                        | GRUB_EFI_VARIABLE_RUNTIME_ACCESS),
207
 
                       datasize, data);
208
 
  if (status == GRUB_EFI_SUCCESS)
209
 
    return GRUB_ERR_NONE;
210
 
 
211
 
  return grub_error (GRUB_ERR_IO, "could not set EFI variable `%s'", var);
212
 
}
213
 
 
214
 
void *
215
 
grub_efi_get_variable (const char *var, const grub_efi_guid_t *guid,
216
 
                       grub_size_t *datasize_out)
217
 
{
218
 
  grub_efi_status_t status;
219
 
  grub_efi_uintn_t datasize = 0;
220
 
  grub_efi_runtime_services_t *r;
221
 
  grub_efi_char16_t *var16;
222
 
  void *data;
223
 
  grub_size_t len, len16;
224
 
 
225
 
  *datasize_out = 0;
226
 
 
227
 
  len = grub_strlen (var);
228
 
  len16 = len * GRUB_MAX_UTF16_PER_UTF8;
229
 
  var16 = grub_malloc ((len16 + 1) * sizeof (var16[0]));
230
 
  if (!var16)
231
 
    return NULL;
232
 
  len16 = grub_utf8_to_utf16 (var16, len16, (grub_uint8_t *) var, len, NULL);
233
 
  var16[len16] = 0;
234
 
 
235
 
  r = grub_efi_system_table->runtime_services;
236
 
 
237
 
  status = efi_call_5 (r->get_variable, var16, guid, NULL, &datasize, NULL);
238
 
 
239
 
  if (!datasize)
240
 
    return NULL;
241
 
 
242
 
  data = grub_malloc (datasize);
243
 
  if (!data)
244
 
    {
245
 
      grub_free (var16);
246
 
      return NULL;
247
 
    }
248
 
 
249
 
  status = efi_call_5 (r->get_variable, var16, guid, NULL, &datasize, data);
250
 
  grub_free (var16);
251
 
 
252
 
  if (status == GRUB_EFI_SUCCESS)
253
 
    {
254
 
      *datasize_out = datasize;
255
 
      return data;
256
 
    }
257
 
 
258
 
  grub_free (data);
259
 
  return NULL;
260
 
}
261
 
 
262
 
#pragma GCC diagnostic ignored "-Wcast-align"
263
 
 
264
 
/* Search the mods section from the PE32/PE32+ image. This code uses
265
 
   a PE32 header, but should work with PE32+ as well.  */
266
 
grub_addr_t
267
 
grub_efi_modules_addr (void)
268
 
{
269
 
  grub_efi_loaded_image_t *image;
270
 
  struct grub_pe32_header *header;
271
 
  struct grub_pe32_coff_header *coff_header;
272
 
  struct grub_pe32_section_table *sections;
273
 
  struct grub_pe32_section_table *section;
274
 
  struct grub_module_info *info;
275
 
  grub_uint16_t i;
276
 
 
277
 
  image = grub_efi_get_loaded_image (grub_efi_image_handle);
278
 
  if (! image)
279
 
    return 0;
280
 
 
281
 
  header = image->image_base;
282
 
  coff_header = &(header->coff_header);
283
 
  sections
284
 
    = (struct grub_pe32_section_table *) ((char *) coff_header
285
 
                                          + sizeof (*coff_header)
286
 
                                          + coff_header->optional_header_size);
287
 
 
288
 
  for (i = 0, section = sections;
289
 
       i < coff_header->num_sections;
290
 
       i++, section++)
291
 
    {
292
 
      if (grub_strcmp (section->name, "mods") == 0)
293
 
        break;
294
 
    }
295
 
 
296
 
  if (i == coff_header->num_sections)
297
 
    return 0;
298
 
 
299
 
  info = (struct grub_module_info *) ((char *) image->image_base
300
 
                                      + section->virtual_address);
301
 
  if (info->magic != GRUB_MODULE_MAGIC)
302
 
    return 0;
303
 
 
304
 
  return (grub_addr_t) info;
305
 
}
306
 
 
307
 
#pragma GCC diagnostic error "-Wcast-align"
308
 
 
309
 
char *
310
 
grub_efi_get_filename (grub_efi_device_path_t *dp)
311
 
{
312
 
  char *name = 0;
313
 
 
314
 
  while (1)
315
 
    {
316
 
      grub_efi_uint8_t type = GRUB_EFI_DEVICE_PATH_TYPE (dp);
317
 
      grub_efi_uint8_t subtype = GRUB_EFI_DEVICE_PATH_SUBTYPE (dp);
318
 
 
319
 
      if (type == GRUB_EFI_END_DEVICE_PATH_TYPE)
320
 
        break;
321
 
      else if (type == GRUB_EFI_MEDIA_DEVICE_PATH_TYPE
322
 
               && subtype == GRUB_EFI_FILE_PATH_DEVICE_PATH_SUBTYPE)
323
 
        {
324
 
          grub_efi_file_path_device_path_t *fp;
325
 
          grub_efi_uint16_t len;
326
 
          char *p;
327
 
          grub_size_t size;
328
 
 
329
 
          if (name)
330
 
            {
331
 
              size = grub_strlen (name);
332
 
              name[size] = '/';
333
 
              size++;
334
 
            }
335
 
          else
336
 
            size = 0;
337
 
 
338
 
          len = ((GRUB_EFI_DEVICE_PATH_LENGTH (dp) - 4)
339
 
                 / sizeof (grub_efi_char16_t));
340
 
          p = grub_realloc (name, size + len * 4 + 1);
341
 
          if (! p)
342
 
            {
343
 
              grub_free (name);
344
 
              return 0;
345
 
            }
346
 
 
347
 
          name = p;
348
 
          fp = (grub_efi_file_path_device_path_t *) dp;
349
 
          *grub_utf16_to_utf8 ((grub_uint8_t *) name + size,
350
 
                               fp->path_name, len) = '\0';
351
 
        }
352
 
 
353
 
      dp = GRUB_EFI_NEXT_DEVICE_PATH (dp);
354
 
    }
355
 
 
356
 
  if (name)
357
 
    {
358
 
      /* EFI breaks paths with backslashes.  */
359
 
      char *p;
360
 
 
361
 
      for (p = name; *p; p++)
362
 
        if (*p == '\\')
363
 
          *p = '/';
364
 
    }
365
 
 
366
 
  return name;
367
 
}
368
 
 
369
 
grub_efi_device_path_t *
370
 
grub_efi_get_device_path (grub_efi_handle_t handle)
371
 
{
372
 
  return grub_efi_open_protocol (handle, &device_path_guid,
373
 
                                 GRUB_EFI_OPEN_PROTOCOL_GET_PROTOCOL);
374
 
}
375
 
 
376
 
/* Print the chain of Device Path nodes. This is mainly for debugging. */
377
 
void
378
 
grub_efi_print_device_path (grub_efi_device_path_t *dp)
379
 
{
380
 
  while (1)
381
 
    {
382
 
      grub_efi_uint8_t type = GRUB_EFI_DEVICE_PATH_TYPE (dp);
383
 
      grub_efi_uint8_t subtype = GRUB_EFI_DEVICE_PATH_SUBTYPE (dp);
384
 
      grub_efi_uint16_t len = GRUB_EFI_DEVICE_PATH_LENGTH (dp);
385
 
 
386
 
      switch (type)
387
 
        {
388
 
        case GRUB_EFI_END_DEVICE_PATH_TYPE:
389
 
          switch (subtype)
390
 
            {
391
 
            case GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE:
392
 
              grub_printf ("/EndEntire\n");
393
 
              //grub_putchar ('\n');
394
 
              break;
395
 
            case GRUB_EFI_END_THIS_DEVICE_PATH_SUBTYPE:
396
 
              grub_printf ("/EndThis\n");
397
 
              //grub_putchar ('\n');
398
 
              break;
399
 
            default:
400
 
              grub_printf ("/EndUnknown(%x)\n", (unsigned) subtype);
401
 
              break;
402
 
            }
403
 
          break;
404
 
 
405
 
        case GRUB_EFI_HARDWARE_DEVICE_PATH_TYPE:
406
 
          switch (subtype)
407
 
            {
408
 
            case GRUB_EFI_PCI_DEVICE_PATH_SUBTYPE:
409
 
              {
410
 
                grub_efi_pci_device_path_t pci;
411
 
                grub_memcpy (&pci, dp, len);
412
 
                grub_printf ("/PCI(%x,%x)",
413
 
                             (unsigned) pci.function, (unsigned) pci.device);
414
 
              }
415
 
              break;
416
 
            case GRUB_EFI_PCCARD_DEVICE_PATH_SUBTYPE:
417
 
              {
418
 
                grub_efi_pccard_device_path_t pccard;
419
 
                grub_memcpy (&pccard, dp, len);
420
 
                grub_printf ("/PCCARD(%x)",
421
 
                             (unsigned) pccard.function);
422
 
              }
423
 
              break;
424
 
            case GRUB_EFI_MEMORY_MAPPED_DEVICE_PATH_SUBTYPE:
425
 
              {
426
 
                grub_efi_memory_mapped_device_path_t mmapped;
427
 
                grub_memcpy (&mmapped, dp, len);
428
 
                grub_printf ("/MMap(%x,%llx,%llx)",
429
 
                             (unsigned) mmapped.memory_type,
430
 
                             (unsigned long long) mmapped.start_address,
431
 
                             (unsigned long long) mmapped.end_address);
432
 
              }
433
 
              break;
434
 
            case GRUB_EFI_VENDOR_DEVICE_PATH_SUBTYPE:
435
 
              {
436
 
                grub_efi_vendor_device_path_t vendor;
437
 
                grub_memcpy (&vendor, dp, sizeof (vendor));
438
 
                grub_printf ("/Vendor(%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x)",
439
 
                             (unsigned) vendor.vendor_guid.data1,
440
 
                             (unsigned) vendor.vendor_guid.data2,
441
 
                             (unsigned) vendor.vendor_guid.data3,
442
 
                             (unsigned) vendor.vendor_guid.data4[0],
443
 
                             (unsigned) vendor.vendor_guid.data4[1],
444
 
                             (unsigned) vendor.vendor_guid.data4[2],
445
 
                             (unsigned) vendor.vendor_guid.data4[3],
446
 
                             (unsigned) vendor.vendor_guid.data4[4],
447
 
                             (unsigned) vendor.vendor_guid.data4[5],
448
 
                             (unsigned) vendor.vendor_guid.data4[6],
449
 
                             (unsigned) vendor.vendor_guid.data4[7]);
450
 
              }
451
 
              break;
452
 
            case GRUB_EFI_CONTROLLER_DEVICE_PATH_SUBTYPE:
453
 
              {
454
 
                grub_efi_controller_device_path_t controller;
455
 
                grub_memcpy (&controller, dp, len);
456
 
                grub_printf ("/Ctrl(%x)",
457
 
                             (unsigned) controller.controller_number);
458
 
              }
459
 
              break;
460
 
            default:
461
 
              grub_printf ("/UnknownHW(%x)", (unsigned) subtype);
462
 
              break;
463
 
            }
464
 
          break;
465
 
 
466
 
        case GRUB_EFI_ACPI_DEVICE_PATH_TYPE:
467
 
          switch (subtype)
468
 
            {
469
 
            case GRUB_EFI_ACPI_DEVICE_PATH_SUBTYPE:
470
 
              {
471
 
                grub_efi_acpi_device_path_t acpi;
472
 
                grub_memcpy (&acpi, dp, len);
473
 
                grub_printf ("/ACPI(%x,%x)",
474
 
                             (unsigned) acpi.hid,
475
 
                             (unsigned) acpi.uid);
476
 
              }
477
 
              break;
478
 
            case GRUB_EFI_EXPANDED_ACPI_DEVICE_PATH_SUBTYPE:
479
 
              {
480
 
                grub_efi_expanded_acpi_device_path_t eacpi;
481
 
                grub_memcpy (&eacpi, dp, sizeof (eacpi));
482
 
                grub_printf ("/ACPI(");
483
 
 
484
 
                if (GRUB_EFI_EXPANDED_ACPI_HIDSTR (dp)[0] == '\0')
485
 
                  grub_printf ("%x,", (unsigned) eacpi.hid);
486
 
                else
487
 
                  grub_printf ("%s,", GRUB_EFI_EXPANDED_ACPI_HIDSTR (dp));
488
 
 
489
 
                if (GRUB_EFI_EXPANDED_ACPI_UIDSTR (dp)[0] == '\0')
490
 
                  grub_printf ("%x,", (unsigned) eacpi.uid);
491
 
                else
492
 
                  grub_printf ("%s,", GRUB_EFI_EXPANDED_ACPI_UIDSTR (dp));
493
 
 
494
 
                if (GRUB_EFI_EXPANDED_ACPI_CIDSTR (dp)[0] == '\0')
495
 
                  grub_printf ("%x)", (unsigned) eacpi.cid);
496
 
                else
497
 
                  grub_printf ("%s)", GRUB_EFI_EXPANDED_ACPI_CIDSTR (dp));
498
 
              }
499
 
              break;
500
 
            default:
501
 
              grub_printf ("/UnknownACPI(%x)", (unsigned) subtype);
502
 
              break;
503
 
            }
504
 
          break;
505
 
 
506
 
        case GRUB_EFI_MESSAGING_DEVICE_PATH_TYPE:
507
 
          switch (subtype)
508
 
            {
509
 
            case GRUB_EFI_ATAPI_DEVICE_PATH_SUBTYPE:
510
 
              {
511
 
                grub_efi_atapi_device_path_t atapi;
512
 
                grub_memcpy (&atapi, dp, len);
513
 
                grub_printf ("/ATAPI(%x,%x,%x)",
514
 
                             (unsigned) atapi.primary_secondary,
515
 
                             (unsigned) atapi.slave_master,
516
 
                             (unsigned) atapi.lun);
517
 
              }
518
 
              break;
519
 
            case GRUB_EFI_SCSI_DEVICE_PATH_SUBTYPE:
520
 
              {
521
 
                grub_efi_scsi_device_path_t scsi;
522
 
                grub_memcpy (&scsi, dp, len);
523
 
                grub_printf ("/SCSI(%x,%x)",
524
 
                             (unsigned) scsi.pun,
525
 
                             (unsigned) scsi.lun);
526
 
              }
527
 
              break;
528
 
            case GRUB_EFI_FIBRE_CHANNEL_DEVICE_PATH_SUBTYPE:
529
 
              {
530
 
                grub_efi_fibre_channel_device_path_t fc;
531
 
                grub_memcpy (&fc, dp, len);
532
 
                grub_printf ("/FibreChannel(%llx,%llx)",
533
 
                             (unsigned long long) fc.wwn,
534
 
                             (unsigned long long) fc.lun);
535
 
              }
536
 
              break;
537
 
            case GRUB_EFI_1394_DEVICE_PATH_SUBTYPE:
538
 
              {
539
 
                grub_efi_1394_device_path_t firewire;
540
 
                grub_memcpy (&firewire, dp, len);
541
 
                grub_printf ("/1394(%llx)", (unsigned long long) firewire.guid);
542
 
              }
543
 
              break;
544
 
            case GRUB_EFI_USB_DEVICE_PATH_SUBTYPE:
545
 
              {
546
 
                grub_efi_usb_device_path_t usb;
547
 
                grub_memcpy (&usb, dp, len);
548
 
                grub_printf ("/USB(%x,%x)",
549
 
                             (unsigned) usb.parent_port_number,
550
 
                             (unsigned) usb.interface);
551
 
              }
552
 
              break;
553
 
            case GRUB_EFI_USB_CLASS_DEVICE_PATH_SUBTYPE:
554
 
              {
555
 
                grub_efi_usb_class_device_path_t usb_class;
556
 
                grub_memcpy (&usb_class, dp, len);
557
 
                grub_printf ("/USBClass(%x,%x,%x,%x,%x)",
558
 
                             (unsigned) usb_class.vendor_id,
559
 
                             (unsigned) usb_class.product_id,
560
 
                             (unsigned) usb_class.device_class,
561
 
                             (unsigned) usb_class.device_subclass,
562
 
                             (unsigned) usb_class.device_protocol);
563
 
              }
564
 
              break;
565
 
            case GRUB_EFI_I2O_DEVICE_PATH_SUBTYPE:
566
 
              {
567
 
                grub_efi_i2o_device_path_t i2o;
568
 
                grub_memcpy (&i2o, dp, len);
569
 
                grub_printf ("/I2O(%x)", (unsigned) i2o.tid);
570
 
              }
571
 
              break;
572
 
            case GRUB_EFI_MAC_ADDRESS_DEVICE_PATH_SUBTYPE:
573
 
              {
574
 
                grub_efi_mac_address_device_path_t mac;
575
 
                grub_memcpy (&mac, dp, len);
576
 
                grub_printf ("/MacAddr(%02x:%02x:%02x:%02x:%02x:%02x,%x)",
577
 
                             (unsigned) mac.mac_address[0],
578
 
                             (unsigned) mac.mac_address[1],
579
 
                             (unsigned) mac.mac_address[2],
580
 
                             (unsigned) mac.mac_address[3],
581
 
                             (unsigned) mac.mac_address[4],
582
 
                             (unsigned) mac.mac_address[5],
583
 
                             (unsigned) mac.if_type);
584
 
              }
585
 
              break;
586
 
            case GRUB_EFI_IPV4_DEVICE_PATH_SUBTYPE:
587
 
              {
588
 
                grub_efi_ipv4_device_path_t ipv4;
589
 
                grub_memcpy (&ipv4, dp, len);
590
 
                grub_printf ("/IPv4(%u.%u.%u.%u,%u.%u.%u.%u,%u,%u,%x,%x)",
591
 
                             (unsigned) ipv4.local_ip_address[0],
592
 
                             (unsigned) ipv4.local_ip_address[1],
593
 
                             (unsigned) ipv4.local_ip_address[2],
594
 
                             (unsigned) ipv4.local_ip_address[3],
595
 
                             (unsigned) ipv4.remote_ip_address[0],
596
 
                             (unsigned) ipv4.remote_ip_address[1],
597
 
                             (unsigned) ipv4.remote_ip_address[2],
598
 
                             (unsigned) ipv4.remote_ip_address[3],
599
 
                             (unsigned) ipv4.local_port,
600
 
                             (unsigned) ipv4.remote_port,
601
 
                             (unsigned) ipv4.protocol,
602
 
                             (unsigned) ipv4.static_ip_address);
603
 
              }
604
 
              break;
605
 
            case GRUB_EFI_IPV6_DEVICE_PATH_SUBTYPE:
606
 
              {
607
 
                grub_efi_ipv6_device_path_t ipv6;
608
 
                grub_memcpy (&ipv6, dp, len);
609
 
                grub_printf ("/IPv6(%x:%x:%x:%x:%x:%x:%x:%x,%x:%x:%x:%x:%x:%x:%x:%x,%u,%u,%x,%x)",
610
 
                             (unsigned) ipv6.local_ip_address[0],
611
 
                             (unsigned) ipv6.local_ip_address[1],
612
 
                             (unsigned) ipv6.local_ip_address[2],
613
 
                             (unsigned) ipv6.local_ip_address[3],
614
 
                             (unsigned) ipv6.local_ip_address[4],
615
 
                             (unsigned) ipv6.local_ip_address[5],
616
 
                             (unsigned) ipv6.local_ip_address[6],
617
 
                             (unsigned) ipv6.local_ip_address[7],
618
 
                             (unsigned) ipv6.remote_ip_address[0],
619
 
                             (unsigned) ipv6.remote_ip_address[1],
620
 
                             (unsigned) ipv6.remote_ip_address[2],
621
 
                             (unsigned) ipv6.remote_ip_address[3],
622
 
                             (unsigned) ipv6.remote_ip_address[4],
623
 
                             (unsigned) ipv6.remote_ip_address[5],
624
 
                             (unsigned) ipv6.remote_ip_address[6],
625
 
                             (unsigned) ipv6.remote_ip_address[7],
626
 
                             (unsigned) ipv6.local_port,
627
 
                             (unsigned) ipv6.remote_port,
628
 
                             (unsigned) ipv6.protocol,
629
 
                             (unsigned) ipv6.static_ip_address);
630
 
              }
631
 
              break;
632
 
            case GRUB_EFI_INFINIBAND_DEVICE_PATH_SUBTYPE:
633
 
              {
634
 
                grub_efi_infiniband_device_path_t ib;
635
 
                grub_memcpy (&ib, dp, len);
636
 
                grub_printf ("/InfiniBand(%x,%llx,%llx,%llx)",
637
 
                             (unsigned) ib.port_gid[0], /* XXX */
638
 
                             (unsigned long long) ib.remote_id,
639
 
                             (unsigned long long) ib.target_port_id,
640
 
                             (unsigned long long) ib.device_id);
641
 
              }
642
 
              break;
643
 
            case GRUB_EFI_UART_DEVICE_PATH_SUBTYPE:
644
 
              {
645
 
                grub_efi_uart_device_path_t uart;
646
 
                grub_memcpy (&uart, dp, len);
647
 
                grub_printf ("/UART(%llu,%u,%x,%x)",
648
 
                             (unsigned long long) uart.baud_rate,
649
 
                             uart.data_bits,
650
 
                             uart.parity,
651
 
                             uart.stop_bits);
652
 
              }
653
 
              break;
654
 
            case GRUB_EFI_VENDOR_MESSAGING_DEVICE_PATH_SUBTYPE:
655
 
              {
656
 
                grub_efi_vendor_messaging_device_path_t vendor;
657
 
                grub_memcpy (&vendor, dp, sizeof (vendor));
658
 
                grub_printf ("/Vendor(%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x)",
659
 
                             (unsigned) vendor.vendor_guid.data1,
660
 
                             (unsigned) vendor.vendor_guid.data2,
661
 
                             (unsigned) vendor.vendor_guid.data3,
662
 
                             (unsigned) vendor.vendor_guid.data4[0],
663
 
                             (unsigned) vendor.vendor_guid.data4[1],
664
 
                             (unsigned) vendor.vendor_guid.data4[2],
665
 
                             (unsigned) vendor.vendor_guid.data4[3],
666
 
                             (unsigned) vendor.vendor_guid.data4[4],
667
 
                             (unsigned) vendor.vendor_guid.data4[5],
668
 
                             (unsigned) vendor.vendor_guid.data4[6],
669
 
                             (unsigned) vendor.vendor_guid.data4[7]);
670
 
              }
671
 
              break;
672
 
            default:
673
 
              grub_printf ("/UnknownMessaging(%x)", (unsigned) subtype);
674
 
              break;
675
 
            }
676
 
          break;
677
 
 
678
 
        case GRUB_EFI_MEDIA_DEVICE_PATH_TYPE:
679
 
          switch (subtype)
680
 
            {
681
 
            case GRUB_EFI_HARD_DRIVE_DEVICE_PATH_SUBTYPE:
682
 
              {
683
 
                grub_efi_hard_drive_device_path_t hd;
684
 
                grub_memcpy (&hd, dp, len);
685
 
                grub_printf ("/HD(%u,%llx,%llx,%02x%02x%02x%02x%02x%02x%02x%02x,%x,%x)",
686
 
                             hd.partition_number,
687
 
                             (unsigned long long) hd.partition_start,
688
 
                             (unsigned long long) hd.partition_size,
689
 
                             (unsigned) hd.partition_signature[0],
690
 
                             (unsigned) hd.partition_signature[1],
691
 
                             (unsigned) hd.partition_signature[2],
692
 
                             (unsigned) hd.partition_signature[3],
693
 
                             (unsigned) hd.partition_signature[4],
694
 
                             (unsigned) hd.partition_signature[5],
695
 
                             (unsigned) hd.partition_signature[6],
696
 
                             (unsigned) hd.partition_signature[7],
697
 
                             (unsigned) hd.mbr_type,
698
 
                             (unsigned) hd.signature_type);
699
 
              }
700
 
              break;
701
 
            case GRUB_EFI_CDROM_DEVICE_PATH_SUBTYPE:
702
 
              {
703
 
                grub_efi_cdrom_device_path_t cd;
704
 
                grub_memcpy (&cd, dp, len);
705
 
                grub_printf ("/CD(%u,%llx,%llx)",
706
 
                             cd.boot_entry,
707
 
                             (unsigned long long) cd.partition_start,
708
 
                             (unsigned long long) cd.partition_size);
709
 
              }
710
 
              break;
711
 
            case GRUB_EFI_VENDOR_MEDIA_DEVICE_PATH_SUBTYPE:
712
 
              {
713
 
                grub_efi_vendor_media_device_path_t vendor;
714
 
                grub_memcpy (&vendor, dp, sizeof (vendor));
715
 
                grub_printf ("/Vendor(%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x)",
716
 
                             (unsigned) vendor.vendor_guid.data1,
717
 
                             (unsigned) vendor.vendor_guid.data2,
718
 
                             (unsigned) vendor.vendor_guid.data3,
719
 
                             (unsigned) vendor.vendor_guid.data4[0],
720
 
                             (unsigned) vendor.vendor_guid.data4[1],
721
 
                             (unsigned) vendor.vendor_guid.data4[2],
722
 
                             (unsigned) vendor.vendor_guid.data4[3],
723
 
                             (unsigned) vendor.vendor_guid.data4[4],
724
 
                             (unsigned) vendor.vendor_guid.data4[5],
725
 
                             (unsigned) vendor.vendor_guid.data4[6],
726
 
                             (unsigned) vendor.vendor_guid.data4[7]);
727
 
              }
728
 
              break;
729
 
            case GRUB_EFI_FILE_PATH_DEVICE_PATH_SUBTYPE:
730
 
              {
731
 
                grub_efi_file_path_device_path_t *fp;
732
 
                grub_uint8_t buf[(len - 4) * 2 + 1];
733
 
                fp = (grub_efi_file_path_device_path_t *) dp;
734
 
                *grub_utf16_to_utf8 (buf, fp->path_name,
735
 
                                     (len - 4) / sizeof (grub_efi_char16_t))
736
 
                  = '\0';
737
 
                grub_printf ("/File(%s)", buf);
738
 
              }
739
 
              break;
740
 
            case GRUB_EFI_PROTOCOL_DEVICE_PATH_SUBTYPE:
741
 
              {
742
 
                grub_efi_protocol_device_path_t proto;
743
 
                grub_memcpy (&proto, dp, sizeof (proto));
744
 
                grub_printf ("/Protocol(%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x)",
745
 
                             (unsigned) proto.guid.data1,
746
 
                             (unsigned) proto.guid.data2,
747
 
                             (unsigned) proto.guid.data3,
748
 
                             (unsigned) proto.guid.data4[0],
749
 
                             (unsigned) proto.guid.data4[1],
750
 
                             (unsigned) proto.guid.data4[2],
751
 
                             (unsigned) proto.guid.data4[3],
752
 
                             (unsigned) proto.guid.data4[4],
753
 
                             (unsigned) proto.guid.data4[5],
754
 
                             (unsigned) proto.guid.data4[6],
755
 
                             (unsigned) proto.guid.data4[7]);
756
 
              }
757
 
              break;
758
 
            default:
759
 
              grub_printf ("/UnknownMedia(%x)", (unsigned) subtype);
760
 
              break;
761
 
            }
762
 
          break;
763
 
 
764
 
        case GRUB_EFI_BIOS_DEVICE_PATH_TYPE:
765
 
          switch (subtype)
766
 
            {
767
 
            case GRUB_EFI_BIOS_DEVICE_PATH_SUBTYPE:
768
 
              {
769
 
                grub_efi_bios_device_path_t bios;
770
 
                grub_memcpy (&bios, dp, sizeof (bios));
771
 
                grub_printf ("/BIOS(%x,%x,%s)",
772
 
                             (unsigned) bios.device_type,
773
 
                             (unsigned) bios.status_flags,
774
 
                             (char *) (dp + 1));
775
 
              }
776
 
              break;
777
 
            default:
778
 
              grub_printf ("/UnknownBIOS(%x)", (unsigned) subtype);
779
 
              break;
780
 
            }
781
 
          break;
782
 
 
783
 
        default:
784
 
          grub_printf ("/UnknownType(%x,%x)\n",
785
 
                       (unsigned) type,
786
 
                       (unsigned) subtype);
787
 
          return;
788
 
          break;
789
 
        }
790
 
 
791
 
      if (GRUB_EFI_END_ENTIRE_DEVICE_PATH (dp))
792
 
        break;
793
 
 
794
 
      dp = (grub_efi_device_path_t *) ((char *) dp + len);
795
 
    }
796
 
}
797
 
 
798
 
/* Compare device paths.  */
799
 
int
800
 
grub_efi_compare_device_paths (const grub_efi_device_path_t *dp1,
801
 
                               const grub_efi_device_path_t *dp2)
802
 
{
803
 
  if (! dp1 || ! dp2)
804
 
    /* Return non-zero.  */
805
 
    return 1;
806
 
 
807
 
  while (1)
808
 
    {
809
 
      grub_efi_uint8_t type1, type2;
810
 
      grub_efi_uint8_t subtype1, subtype2;
811
 
      grub_efi_uint16_t len1, len2;
812
 
      int ret;
813
 
 
814
 
      type1 = GRUB_EFI_DEVICE_PATH_TYPE (dp1);
815
 
      type2 = GRUB_EFI_DEVICE_PATH_TYPE (dp2);
816
 
 
817
 
      if (type1 != type2)
818
 
        return (int) type2 - (int) type1;
819
 
 
820
 
      subtype1 = GRUB_EFI_DEVICE_PATH_SUBTYPE (dp1);
821
 
      subtype2 = GRUB_EFI_DEVICE_PATH_SUBTYPE (dp2);
822
 
 
823
 
      if (subtype1 != subtype2)
824
 
        return (int) subtype1 - (int) subtype2;
825
 
 
826
 
      len1 = GRUB_EFI_DEVICE_PATH_LENGTH (dp1);
827
 
      len2 = GRUB_EFI_DEVICE_PATH_LENGTH (dp2);
828
 
 
829
 
      if (len1 != len2)
830
 
        return (int) len1 - (int) len2;
831
 
 
832
 
      ret = grub_memcmp (dp1, dp2, len1);
833
 
      if (ret != 0)
834
 
        return ret;
835
 
 
836
 
      if (GRUB_EFI_END_ENTIRE_DEVICE_PATH (dp1))
837
 
        break;
838
 
 
839
 
      dp1 = (grub_efi_device_path_t *) ((char *) dp1 + len1);
840
 
      dp2 = (grub_efi_device_path_t *) ((char *) dp2 + len2);
841
 
    }
842
 
 
843
 
  return 0;
844
 
}