~hamo/ubuntu/precise/grub2/grub2.hi_res

« back to all changes in this revision

Viewing changes to kern/efi/efi.c

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson, Colin Watson, Robert Millan, Updated translations
  • Date: 2010-11-22 12:24:56 UTC
  • mfrom: (1.26.4 upstream) (17.3.36 sid)
  • mto: (17.3.43 sid)
  • mto: This revision was merged to the branch mainline in revision 89.
  • Revision ID: james.westby@ubuntu.com-20101122122456-y82z3sfb7k4zfdcc
Tags: 1.99~20101122-1
[ Colin Watson ]
* New Bazaar snapshot.  Too many changes to list in full, but some of the
  more user-visible ones are as follows:
  - GRUB script:
    + Function parameters, "break", "continue", "shift", "setparams",
      "return", and "!".
    + "export" command supports multiple variable names.
    + Multi-line quoted strings support.
    + Wildcard expansion.
  - sendkey support.
  - USB hotunplugging and USB serial support.
  - Rename CD-ROM to cd on BIOS.
  - Add new --boot-directory option to grub-install, grub-reboot, and
    grub-set-default; the old --root-directory option is still accepted
    but was often confusing.
  - Basic btrfs detection/UUID support (but no file reading yet).
  - bash-completion for utilities.
  - If a device is listed in device.map, always assume that it is
    BIOS-visible rather than using extra layers such as LVM or RAID.
  - Add grub-mknetdir script (closes: #550658).
  - Remove deprecated "root" command.
  - Handle RAID devices containing virtio components.
  - GRUB Legacy configuration file support (via grub-menulst2cfg).
  - Keyboard layout support (via grub-mklayout and grub-kbdcomp).
  - Check generated grub.cfg for syntax errors before saving.
  - Pause execution for at most ten seconds if any errors are displayed,
    so that the user has a chance to see them.
  - Support submenus.
  - Write embedding zone using Reed-Solomon, so that it's robust against
    being partially overwritten (closes: #550702, #591416, #593347).
  - GRUB_DISABLE_LINUX_RECOVERY and GRUB_DISABLE_NETBSD_RECOVERY merged
    into a single GRUB_DISABLE_RECOVERY variable.
  - Fix loader memory allocation failure (closes: #551627).
  - Don't call savedefault on recovery entries (closes: #589325).
  - Support triple-indirect blocks on ext2 (closes: #543924).
  - Recognise DDF1 fake RAID (closes: #603354).

[ Robert Millan ]
* Use dpkg architecture wildcards.

[ Updated translations ]
* Slovenian (Vanja Cvelbar).  Closes: #604003
* Dzongkha (dawa pemo via Tenzin Dendup).  Closes: #604102

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  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/machine/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
 
void
166
 
grub_reboot (void)
167
 
{
168
 
  grub_efi_fini ();
169
 
  efi_call_4 (grub_efi_system_table->runtime_services->reset_system,
170
 
              GRUB_EFI_RESET_COLD, GRUB_EFI_SUCCESS, 0, NULL);
171
 
}
172
 
 
173
 
void
174
 
grub_halt (void)
175
 
{
176
 
  grub_efi_fini ();
177
 
  efi_call_4 (grub_efi_system_table->runtime_services->reset_system,
178
 
              GRUB_EFI_RESET_SHUTDOWN, GRUB_EFI_SUCCESS, 0, NULL);
179
 
}
180
 
 
181
 
int
182
 
grub_efi_exit_boot_services (grub_efi_uintn_t map_key)
183
 
{
184
 
  grub_efi_boot_services_t *b;
185
 
  grub_efi_status_t status;
186
 
 
187
 
  b = grub_efi_system_table->boot_services;
188
 
  status = efi_call_2 (b->exit_boot_services, grub_efi_image_handle, map_key);
189
 
  return status == GRUB_EFI_SUCCESS;
190
 
}
191
 
 
192
 
grub_err_t
193
 
grub_efi_set_virtual_address_map (grub_efi_uintn_t memory_map_size,
194
 
                                  grub_efi_uintn_t descriptor_size,
195
 
                                  grub_efi_uint32_t descriptor_version,
196
 
                                  grub_efi_memory_descriptor_t *virtual_map)
197
 
{
198
 
  grub_efi_runtime_services_t *r;
199
 
  grub_efi_status_t status;
200
 
 
201
 
  r = grub_efi_system_table->runtime_services;
202
 
  status = efi_call_4 (r->set_virtual_address_map, memory_map_size,
203
 
                       descriptor_size, descriptor_version, virtual_map);
204
 
 
205
 
  if (status == GRUB_EFI_SUCCESS)
206
 
    return GRUB_ERR_NONE;
207
 
 
208
 
  return grub_error (GRUB_ERR_IO, "set_virtual_address_map failed");
209
 
}
210
 
 
211
 
grub_uint32_t
212
 
grub_get_rtc (void)
213
 
{
214
 
  grub_efi_time_t time;
215
 
  grub_efi_runtime_services_t *r;
216
 
 
217
 
  r = grub_efi_system_table->runtime_services;
218
 
  if (efi_call_2 (r->get_time, &time, 0) != GRUB_EFI_SUCCESS)
219
 
    /* What is possible in this case?  */
220
 
    return 0;
221
 
 
222
 
  return (((time.minute * 60 + time.second) * 1000
223
 
           + time.nanosecond / 1000000)
224
 
          * GRUB_TICKS_PER_SECOND / 1000);
225
 
}
226
 
 
227
 
/* Search the mods section from the PE32/PE32+ image. This code uses
228
 
   a PE32 header, but should work with PE32+ as well.  */
229
 
grub_addr_t
230
 
grub_arch_modules_addr (void)
231
 
{
232
 
  grub_efi_loaded_image_t *image;
233
 
  struct grub_pe32_header *header;
234
 
  struct grub_pe32_coff_header *coff_header;
235
 
  struct grub_pe32_section_table *sections;
236
 
  struct grub_pe32_section_table *section;
237
 
  struct grub_module_info *info;
238
 
  grub_uint16_t i;
239
 
 
240
 
  image = grub_efi_get_loaded_image (grub_efi_image_handle);
241
 
  if (! image)
242
 
    return 0;
243
 
 
244
 
  header = image->image_base;
245
 
  coff_header = &(header->coff_header);
246
 
  sections
247
 
    = (struct grub_pe32_section_table *) ((char *) coff_header
248
 
                                          + sizeof (*coff_header)
249
 
                                          + coff_header->optional_header_size);
250
 
 
251
 
  for (i = 0, section = sections;
252
 
       i < coff_header->num_sections;
253
 
       i++, section++)
254
 
    {
255
 
      if (grub_strcmp (section->name, "mods") == 0)
256
 
        break;
257
 
    }
258
 
 
259
 
  if (i == coff_header->num_sections)
260
 
    return 0;
261
 
 
262
 
  info = (struct grub_module_info *) ((char *) image->image_base
263
 
                                      + section->virtual_address);
264
 
  if (info->magic != GRUB_MODULE_MAGIC)
265
 
    return 0;
266
 
 
267
 
  return (grub_addr_t) info;
268
 
}
269
 
 
270
 
char *
271
 
grub_efi_get_filename (grub_efi_device_path_t *dp)
272
 
{
273
 
  char *name = 0;
274
 
 
275
 
  while (1)
276
 
    {
277
 
      grub_efi_uint8_t type = GRUB_EFI_DEVICE_PATH_TYPE (dp);
278
 
      grub_efi_uint8_t subtype = GRUB_EFI_DEVICE_PATH_SUBTYPE (dp);
279
 
 
280
 
      if (type == GRUB_EFI_END_DEVICE_PATH_TYPE)
281
 
        break;
282
 
      else if (type == GRUB_EFI_MEDIA_DEVICE_PATH_TYPE
283
 
               && subtype == GRUB_EFI_FILE_PATH_DEVICE_PATH_SUBTYPE)
284
 
        {
285
 
          grub_efi_file_path_device_path_t *fp;
286
 
          grub_efi_uint16_t len;
287
 
          char *p;
288
 
          grub_size_t size;
289
 
 
290
 
          if (name)
291
 
            {
292
 
              size = grub_strlen (name);
293
 
              name[size] = '/';
294
 
              size++;
295
 
            }
296
 
          else
297
 
            size = 0;
298
 
 
299
 
          len = ((GRUB_EFI_DEVICE_PATH_LENGTH (dp) - 4)
300
 
                 / sizeof (grub_efi_char16_t));
301
 
          p = grub_realloc (name, size + len * 4 + 1);
302
 
          if (! p)
303
 
            {
304
 
              grub_free (name);
305
 
              return 0;
306
 
            }
307
 
 
308
 
          name = p;
309
 
          fp = (grub_efi_file_path_device_path_t *) dp;
310
 
          *grub_utf16_to_utf8 ((grub_uint8_t *) name + size,
311
 
                               fp->path_name, len) = '\0';
312
 
        }
313
 
 
314
 
      dp = GRUB_EFI_NEXT_DEVICE_PATH (dp);
315
 
    }
316
 
 
317
 
  if (name)
318
 
    {
319
 
      /* EFI breaks paths with backslashes.  */
320
 
      char *p;
321
 
 
322
 
      for (p = name; *p; p++)
323
 
        if (*p == '\\')
324
 
          *p = '/';
325
 
    }
326
 
 
327
 
  return name;
328
 
}
329
 
 
330
 
grub_efi_device_path_t *
331
 
grub_efi_get_device_path (grub_efi_handle_t handle)
332
 
{
333
 
  return grub_efi_open_protocol (handle, &device_path_guid,
334
 
                                 GRUB_EFI_OPEN_PROTOCOL_GET_PROTOCOL);
335
 
}
336
 
 
337
 
/* Print the chain of Device Path nodes. This is mainly for debugging. */
338
 
void
339
 
grub_efi_print_device_path (grub_efi_device_path_t *dp)
340
 
{
341
 
  while (1)
342
 
    {
343
 
      grub_efi_uint8_t type = GRUB_EFI_DEVICE_PATH_TYPE (dp);
344
 
      grub_efi_uint8_t subtype = GRUB_EFI_DEVICE_PATH_SUBTYPE (dp);
345
 
      grub_efi_uint16_t len = GRUB_EFI_DEVICE_PATH_LENGTH (dp);
346
 
 
347
 
      switch (type)
348
 
        {
349
 
        case GRUB_EFI_END_DEVICE_PATH_TYPE:
350
 
          switch (subtype)
351
 
            {
352
 
            case GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE:
353
 
              grub_printf ("/EndEntire\n");
354
 
              //grub_putchar ('\n');
355
 
              break;
356
 
            case GRUB_EFI_END_THIS_DEVICE_PATH_SUBTYPE:
357
 
              grub_printf ("/EndThis\n");
358
 
              //grub_putchar ('\n');
359
 
              break;
360
 
            default:
361
 
              grub_printf ("/EndUnknown(%x)\n", (unsigned) subtype);
362
 
              break;
363
 
            }
364
 
          break;
365
 
 
366
 
        case GRUB_EFI_HARDWARE_DEVICE_PATH_TYPE:
367
 
          switch (subtype)
368
 
            {
369
 
            case GRUB_EFI_PCI_DEVICE_PATH_SUBTYPE:
370
 
              {
371
 
                grub_efi_pci_device_path_t pci;
372
 
                grub_memcpy (&pci, dp, len);
373
 
                grub_printf ("/PCI(%x,%x)",
374
 
                             (unsigned) pci.function, (unsigned) pci.device);
375
 
              }
376
 
              break;
377
 
            case GRUB_EFI_PCCARD_DEVICE_PATH_SUBTYPE:
378
 
              {
379
 
                grub_efi_pccard_device_path_t pccard;
380
 
                grub_memcpy (&pccard, dp, len);
381
 
                grub_printf ("/PCCARD(%x)",
382
 
                             (unsigned) pccard.function);
383
 
              }
384
 
              break;
385
 
            case GRUB_EFI_MEMORY_MAPPED_DEVICE_PATH_SUBTYPE:
386
 
              {
387
 
                grub_efi_memory_mapped_device_path_t mmapped;
388
 
                grub_memcpy (&mmapped, dp, len);
389
 
                grub_printf ("/MMap(%x,%llx,%llx)",
390
 
                             (unsigned) mmapped.memory_type,
391
 
                             (unsigned long long) mmapped.start_address,
392
 
                             (unsigned long long) mmapped.end_address);
393
 
              }
394
 
              break;
395
 
            case GRUB_EFI_VENDOR_DEVICE_PATH_SUBTYPE:
396
 
              {
397
 
                grub_efi_vendor_device_path_t vendor;
398
 
                grub_memcpy (&vendor, dp, sizeof (vendor));
399
 
                grub_printf ("/Vendor(%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x)",
400
 
                             (unsigned) vendor.vendor_guid.data1,
401
 
                             (unsigned) vendor.vendor_guid.data2,
402
 
                             (unsigned) vendor.vendor_guid.data3,
403
 
                             (unsigned) vendor.vendor_guid.data4[0],
404
 
                             (unsigned) vendor.vendor_guid.data4[1],
405
 
                             (unsigned) vendor.vendor_guid.data4[2],
406
 
                             (unsigned) vendor.vendor_guid.data4[3],
407
 
                             (unsigned) vendor.vendor_guid.data4[4],
408
 
                             (unsigned) vendor.vendor_guid.data4[5],
409
 
                             (unsigned) vendor.vendor_guid.data4[6],
410
 
                             (unsigned) vendor.vendor_guid.data4[7]);
411
 
              }
412
 
              break;
413
 
            case GRUB_EFI_CONTROLLER_DEVICE_PATH_SUBTYPE:
414
 
              {
415
 
                grub_efi_controller_device_path_t controller;
416
 
                grub_memcpy (&controller, dp, len);
417
 
                grub_printf ("/Ctrl(%x)",
418
 
                             (unsigned) controller.controller_number);
419
 
              }
420
 
              break;
421
 
            default:
422
 
              grub_printf ("/UnknownHW(%x)", (unsigned) subtype);
423
 
              break;
424
 
            }
425
 
          break;
426
 
 
427
 
        case GRUB_EFI_ACPI_DEVICE_PATH_TYPE:
428
 
          switch (subtype)
429
 
            {
430
 
            case GRUB_EFI_ACPI_DEVICE_PATH_SUBTYPE:
431
 
              {
432
 
                grub_efi_acpi_device_path_t acpi;
433
 
                grub_memcpy (&acpi, dp, len);
434
 
                grub_printf ("/ACPI(%x,%x)",
435
 
                             (unsigned) acpi.hid,
436
 
                             (unsigned) acpi.uid);
437
 
              }
438
 
              break;
439
 
            case GRUB_EFI_EXPANDED_ACPI_DEVICE_PATH_SUBTYPE:
440
 
              {
441
 
                grub_efi_expanded_acpi_device_path_t eacpi;
442
 
                grub_memcpy (&eacpi, dp, sizeof (eacpi));
443
 
                grub_printf ("/ACPI(");
444
 
 
445
 
                if (GRUB_EFI_EXPANDED_ACPI_HIDSTR (dp)[0] == '\0')
446
 
                  grub_printf ("%x,", (unsigned) eacpi.hid);
447
 
                else
448
 
                  grub_printf ("%s,", GRUB_EFI_EXPANDED_ACPI_HIDSTR (dp));
449
 
 
450
 
                if (GRUB_EFI_EXPANDED_ACPI_UIDSTR (dp)[0] == '\0')
451
 
                  grub_printf ("%x,", (unsigned) eacpi.uid);
452
 
                else
453
 
                  grub_printf ("%s,", GRUB_EFI_EXPANDED_ACPI_UIDSTR (dp));
454
 
 
455
 
                if (GRUB_EFI_EXPANDED_ACPI_CIDSTR (dp)[0] == '\0')
456
 
                  grub_printf ("%x)", (unsigned) eacpi.cid);
457
 
                else
458
 
                  grub_printf ("%s)", GRUB_EFI_EXPANDED_ACPI_CIDSTR (dp));
459
 
              }
460
 
              break;
461
 
            default:
462
 
              grub_printf ("/UnknownACPI(%x)", (unsigned) subtype);
463
 
              break;
464
 
            }
465
 
          break;
466
 
 
467
 
        case GRUB_EFI_MESSAGING_DEVICE_PATH_TYPE:
468
 
          switch (subtype)
469
 
            {
470
 
            case GRUB_EFI_ATAPI_DEVICE_PATH_SUBTYPE:
471
 
              {
472
 
                grub_efi_atapi_device_path_t atapi;
473
 
                grub_memcpy (&atapi, dp, len);
474
 
                grub_printf ("/ATAPI(%x,%x,%x)",
475
 
                             (unsigned) atapi.primary_secondary,
476
 
                             (unsigned) atapi.slave_master,
477
 
                             (unsigned) atapi.lun);
478
 
              }
479
 
              break;
480
 
            case GRUB_EFI_SCSI_DEVICE_PATH_SUBTYPE:
481
 
              {
482
 
                grub_efi_scsi_device_path_t scsi;
483
 
                grub_memcpy (&scsi, dp, len);
484
 
                grub_printf ("/SCSI(%x,%x)",
485
 
                             (unsigned) scsi.pun,
486
 
                             (unsigned) scsi.lun);
487
 
              }
488
 
              break;
489
 
            case GRUB_EFI_FIBRE_CHANNEL_DEVICE_PATH_SUBTYPE:
490
 
              {
491
 
                grub_efi_fibre_channel_device_path_t fc;
492
 
                grub_memcpy (&fc, dp, len);
493
 
                grub_printf ("/FibreChannel(%llx,%llx)",
494
 
                             (unsigned long long) fc.wwn,
495
 
                             (unsigned long long) fc.lun);
496
 
              }
497
 
              break;
498
 
            case GRUB_EFI_1394_DEVICE_PATH_SUBTYPE:
499
 
              {
500
 
                grub_efi_1394_device_path_t firewire;
501
 
                grub_memcpy (&firewire, dp, len);
502
 
                grub_printf ("/1394(%llx)", (unsigned long long) firewire.guid);
503
 
              }
504
 
              break;
505
 
            case GRUB_EFI_USB_DEVICE_PATH_SUBTYPE:
506
 
              {
507
 
                grub_efi_usb_device_path_t usb;
508
 
                grub_memcpy (&usb, dp, len);
509
 
                grub_printf ("/USB(%x,%x)",
510
 
                             (unsigned) usb.parent_port_number,
511
 
                             (unsigned) usb.interface);
512
 
              }
513
 
              break;
514
 
            case GRUB_EFI_USB_CLASS_DEVICE_PATH_SUBTYPE:
515
 
              {
516
 
                grub_efi_usb_class_device_path_t usb_class;
517
 
                grub_memcpy (&usb_class, dp, len);
518
 
                grub_printf ("/USBClass(%x,%x,%x,%x,%x)",
519
 
                             (unsigned) usb_class.vendor_id,
520
 
                             (unsigned) usb_class.product_id,
521
 
                             (unsigned) usb_class.device_class,
522
 
                             (unsigned) usb_class.device_subclass,
523
 
                             (unsigned) usb_class.device_protocol);
524
 
              }
525
 
              break;
526
 
            case GRUB_EFI_I2O_DEVICE_PATH_SUBTYPE:
527
 
              {
528
 
                grub_efi_i2o_device_path_t i2o;
529
 
                grub_memcpy (&i2o, dp, len);
530
 
                grub_printf ("/I2O(%x)", (unsigned) i2o.tid);
531
 
              }
532
 
              break;
533
 
            case GRUB_EFI_MAC_ADDRESS_DEVICE_PATH_SUBTYPE:
534
 
              {
535
 
                grub_efi_mac_address_device_path_t mac;
536
 
                grub_memcpy (&mac, dp, len);
537
 
                grub_printf ("/MacAddr(%02x:%02x:%02x:%02x:%02x:%02x,%x)",
538
 
                             (unsigned) mac.mac_address[0],
539
 
                             (unsigned) mac.mac_address[1],
540
 
                             (unsigned) mac.mac_address[2],
541
 
                             (unsigned) mac.mac_address[3],
542
 
                             (unsigned) mac.mac_address[4],
543
 
                             (unsigned) mac.mac_address[5],
544
 
                             (unsigned) mac.if_type);
545
 
              }
546
 
              break;
547
 
            case GRUB_EFI_IPV4_DEVICE_PATH_SUBTYPE:
548
 
              {
549
 
                grub_efi_ipv4_device_path_t ipv4;
550
 
                grub_memcpy (&ipv4, dp, len);
551
 
                grub_printf ("/IPv4(%u.%u.%u.%u,%u.%u.%u.%u,%u,%u,%x,%x)",
552
 
                             (unsigned) ipv4.local_ip_address[0],
553
 
                             (unsigned) ipv4.local_ip_address[1],
554
 
                             (unsigned) ipv4.local_ip_address[2],
555
 
                             (unsigned) ipv4.local_ip_address[3],
556
 
                             (unsigned) ipv4.remote_ip_address[0],
557
 
                             (unsigned) ipv4.remote_ip_address[1],
558
 
                             (unsigned) ipv4.remote_ip_address[2],
559
 
                             (unsigned) ipv4.remote_ip_address[3],
560
 
                             (unsigned) ipv4.local_port,
561
 
                             (unsigned) ipv4.remote_port,
562
 
                             (unsigned) ipv4.protocol,
563
 
                             (unsigned) ipv4.static_ip_address);
564
 
              }
565
 
              break;
566
 
            case GRUB_EFI_IPV6_DEVICE_PATH_SUBTYPE:
567
 
              {
568
 
                grub_efi_ipv6_device_path_t ipv6;
569
 
                grub_memcpy (&ipv6, dp, len);
570
 
                grub_printf ("/IPv6(%x:%x:%x:%x:%x:%x:%x:%x,%x:%x:%x:%x:%x:%x:%x:%x,%u,%u,%x,%x)",
571
 
                             (unsigned) ipv6.local_ip_address[0],
572
 
                             (unsigned) ipv6.local_ip_address[1],
573
 
                             (unsigned) ipv6.local_ip_address[2],
574
 
                             (unsigned) ipv6.local_ip_address[3],
575
 
                             (unsigned) ipv6.local_ip_address[4],
576
 
                             (unsigned) ipv6.local_ip_address[5],
577
 
                             (unsigned) ipv6.local_ip_address[6],
578
 
                             (unsigned) ipv6.local_ip_address[7],
579
 
                             (unsigned) ipv6.remote_ip_address[0],
580
 
                             (unsigned) ipv6.remote_ip_address[1],
581
 
                             (unsigned) ipv6.remote_ip_address[2],
582
 
                             (unsigned) ipv6.remote_ip_address[3],
583
 
                             (unsigned) ipv6.remote_ip_address[4],
584
 
                             (unsigned) ipv6.remote_ip_address[5],
585
 
                             (unsigned) ipv6.remote_ip_address[6],
586
 
                             (unsigned) ipv6.remote_ip_address[7],
587
 
                             (unsigned) ipv6.local_port,
588
 
                             (unsigned) ipv6.remote_port,
589
 
                             (unsigned) ipv6.protocol,
590
 
                             (unsigned) ipv6.static_ip_address);
591
 
              }
592
 
              break;
593
 
            case GRUB_EFI_INFINIBAND_DEVICE_PATH_SUBTYPE:
594
 
              {
595
 
                grub_efi_infiniband_device_path_t ib;
596
 
                grub_memcpy (&ib, dp, len);
597
 
                grub_printf ("/InfiniBand(%x,%llx,%llx,%llx)",
598
 
                             (unsigned) ib.port_gid[0], /* XXX */
599
 
                             (unsigned long long) ib.remote_id,
600
 
                             (unsigned long long) ib.target_port_id,
601
 
                             (unsigned long long) ib.device_id);
602
 
              }
603
 
              break;
604
 
            case GRUB_EFI_UART_DEVICE_PATH_SUBTYPE:
605
 
              {
606
 
                grub_efi_uart_device_path_t uart;
607
 
                grub_memcpy (&uart, dp, len);
608
 
                grub_printf ("/UART(%llu,%u,%x,%x)",
609
 
                             (unsigned long long) uart.baud_rate,
610
 
                             uart.data_bits,
611
 
                             uart.parity,
612
 
                             uart.stop_bits);
613
 
              }
614
 
              break;
615
 
            case GRUB_EFI_VENDOR_MESSAGING_DEVICE_PATH_SUBTYPE:
616
 
              {
617
 
                grub_efi_vendor_messaging_device_path_t vendor;
618
 
                grub_memcpy (&vendor, dp, sizeof (vendor));
619
 
                grub_printf ("/Vendor(%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x)",
620
 
                             (unsigned) vendor.vendor_guid.data1,
621
 
                             (unsigned) vendor.vendor_guid.data2,
622
 
                             (unsigned) vendor.vendor_guid.data3,
623
 
                             (unsigned) vendor.vendor_guid.data4[0],
624
 
                             (unsigned) vendor.vendor_guid.data4[1],
625
 
                             (unsigned) vendor.vendor_guid.data4[2],
626
 
                             (unsigned) vendor.vendor_guid.data4[3],
627
 
                             (unsigned) vendor.vendor_guid.data4[4],
628
 
                             (unsigned) vendor.vendor_guid.data4[5],
629
 
                             (unsigned) vendor.vendor_guid.data4[6],
630
 
                             (unsigned) vendor.vendor_guid.data4[7]);
631
 
              }
632
 
              break;
633
 
            default:
634
 
              grub_printf ("/UnknownMessaging(%x)", (unsigned) subtype);
635
 
              break;
636
 
            }
637
 
          break;
638
 
 
639
 
        case GRUB_EFI_MEDIA_DEVICE_PATH_TYPE:
640
 
          switch (subtype)
641
 
            {
642
 
            case GRUB_EFI_HARD_DRIVE_DEVICE_PATH_SUBTYPE:
643
 
              {
644
 
                grub_efi_hard_drive_device_path_t hd;
645
 
                grub_memcpy (&hd, dp, len);
646
 
                grub_printf ("/HD(%u,%llx,%llx,%02x%02x%02x%02x%02x%02x%02x%02x,%x,%x)",
647
 
                             hd.partition_number,
648
 
                             (unsigned long long) hd.partition_start,
649
 
                             (unsigned long long) hd.partition_size,
650
 
                             (unsigned) hd.partition_signature[0],
651
 
                             (unsigned) hd.partition_signature[1],
652
 
                             (unsigned) hd.partition_signature[2],
653
 
                             (unsigned) hd.partition_signature[3],
654
 
                             (unsigned) hd.partition_signature[4],
655
 
                             (unsigned) hd.partition_signature[5],
656
 
                             (unsigned) hd.partition_signature[6],
657
 
                             (unsigned) hd.partition_signature[7],
658
 
                             (unsigned) hd.mbr_type,
659
 
                             (unsigned) hd.signature_type);
660
 
              }
661
 
              break;
662
 
            case GRUB_EFI_CDROM_DEVICE_PATH_SUBTYPE:
663
 
              {
664
 
                grub_efi_cdrom_device_path_t cd;
665
 
                grub_memcpy (&cd, dp, len);
666
 
                grub_printf ("/CD(%u,%llx,%llx)",
667
 
                             cd.boot_entry,
668
 
                             (unsigned long long) cd.partition_start,
669
 
                             (unsigned long long) cd.partition_size);
670
 
              }
671
 
              break;
672
 
            case GRUB_EFI_VENDOR_MEDIA_DEVICE_PATH_SUBTYPE:
673
 
              {
674
 
                grub_efi_vendor_media_device_path_t vendor;
675
 
                grub_memcpy (&vendor, dp, sizeof (vendor));
676
 
                grub_printf ("/Vendor(%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x)",
677
 
                             (unsigned) vendor.vendor_guid.data1,
678
 
                             (unsigned) vendor.vendor_guid.data2,
679
 
                             (unsigned) vendor.vendor_guid.data3,
680
 
                             (unsigned) vendor.vendor_guid.data4[0],
681
 
                             (unsigned) vendor.vendor_guid.data4[1],
682
 
                             (unsigned) vendor.vendor_guid.data4[2],
683
 
                             (unsigned) vendor.vendor_guid.data4[3],
684
 
                             (unsigned) vendor.vendor_guid.data4[4],
685
 
                             (unsigned) vendor.vendor_guid.data4[5],
686
 
                             (unsigned) vendor.vendor_guid.data4[6],
687
 
                             (unsigned) vendor.vendor_guid.data4[7]);
688
 
              }
689
 
              break;
690
 
            case GRUB_EFI_FILE_PATH_DEVICE_PATH_SUBTYPE:
691
 
              {
692
 
                grub_efi_file_path_device_path_t *fp;
693
 
                grub_uint8_t buf[(len - 4) * 2 + 1];
694
 
                fp = (grub_efi_file_path_device_path_t *) dp;
695
 
                *grub_utf16_to_utf8 (buf, fp->path_name,
696
 
                                     (len - 4) / sizeof (grub_efi_char16_t))
697
 
                  = '\0';
698
 
                grub_printf ("/File(%s)", buf);
699
 
              }
700
 
              break;
701
 
            case GRUB_EFI_PROTOCOL_DEVICE_PATH_SUBTYPE:
702
 
              {
703
 
                grub_efi_protocol_device_path_t proto;
704
 
                grub_memcpy (&proto, dp, sizeof (proto));
705
 
                grub_printf ("/Protocol(%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x)",
706
 
                             (unsigned) proto.guid.data1,
707
 
                             (unsigned) proto.guid.data2,
708
 
                             (unsigned) proto.guid.data3,
709
 
                             (unsigned) proto.guid.data4[0],
710
 
                             (unsigned) proto.guid.data4[1],
711
 
                             (unsigned) proto.guid.data4[2],
712
 
                             (unsigned) proto.guid.data4[3],
713
 
                             (unsigned) proto.guid.data4[4],
714
 
                             (unsigned) proto.guid.data4[5],
715
 
                             (unsigned) proto.guid.data4[6],
716
 
                             (unsigned) proto.guid.data4[7]);
717
 
              }
718
 
              break;
719
 
            default:
720
 
              grub_printf ("/UnknownMedia(%x)", (unsigned) subtype);
721
 
              break;
722
 
            }
723
 
          break;
724
 
 
725
 
        case GRUB_EFI_BIOS_DEVICE_PATH_TYPE:
726
 
          switch (subtype)
727
 
            {
728
 
            case GRUB_EFI_BIOS_DEVICE_PATH_SUBTYPE:
729
 
              {
730
 
                grub_efi_bios_device_path_t bios;
731
 
                grub_memcpy (&bios, dp, sizeof (bios));
732
 
                grub_printf ("/BIOS(%x,%x,%s)",
733
 
                             (unsigned) bios.device_type,
734
 
                             (unsigned) bios.status_flags,
735
 
                             (char *) (dp + 1));
736
 
              }
737
 
              break;
738
 
            default:
739
 
              grub_printf ("/UnknownBIOS(%x)", (unsigned) subtype);
740
 
              break;
741
 
            }
742
 
          break;
743
 
 
744
 
        default:
745
 
          grub_printf ("/UnknownType(%x,%x)\n",
746
 
                       (unsigned) type,
747
 
                       (unsigned) subtype);
748
 
          return;
749
 
          break;
750
 
        }
751
 
 
752
 
      if (GRUB_EFI_END_ENTIRE_DEVICE_PATH (dp))
753
 
        break;
754
 
 
755
 
      dp = (grub_efi_device_path_t *) ((char *) dp + len);
756
 
    }
757
 
}
758
 
 
759
 
int
760
 
grub_efi_finish_boot_services (void)
761
 
{
762
 
  grub_efi_uintn_t mmap_size = 0;
763
 
  grub_efi_uintn_t map_key;
764
 
  grub_efi_uintn_t desc_size;
765
 
  grub_efi_uint32_t desc_version;
766
 
  void *mmap_buf = 0;
767
 
 
768
 
  if (grub_efi_get_memory_map (&mmap_size, mmap_buf, &map_key,
769
 
                               &desc_size, &desc_version) < 0)
770
 
    return 0;
771
 
 
772
 
  mmap_buf = grub_malloc (mmap_size);
773
 
 
774
 
  if (grub_efi_get_memory_map (&mmap_size, mmap_buf, &map_key,
775
 
                               &desc_size, &desc_version) <= 0)
776
 
    return 0;
777
 
 
778
 
  return grub_efi_exit_boot_services (map_key);
779
 
}
780