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

« back to all changes in this revision

Viewing changes to grub-core/loader/efi/appleloader.c

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson, Colin Watson, Evan Broder, Mario Limonciello
  • Date: 2010-11-24 13:59:55 UTC
  • mfrom: (1.17.6 upstream) (17.6.15 experimental)
  • Revision ID: james.westby@ubuntu.com-20101124135955-r6ii5sepayr7jt53
Tags: 1.99~20101124-1ubuntu1
[ Colin Watson ]
* Resynchronise with Debian experimental.  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 for Ubuntu.
  - Apply Ubuntu GRUB Legacy changes to legacy update-grub script: title,
    recovery mode, quiet option, tweak how memtest86+ is displayed, and
    use UUIDs where appropriate.
  - Fix backslash-escaping in merge_debconf_into_conf.
  - Remove "GNU/Linux" from default distributor string.
  - Add crashkernel= options if kdump and makedumpfile are available.
  - If other operating systems are installed, then automatically unhide
    the menu.  Otherwise, if GRUB_HIDDEN_TIMEOUT is 0, then use keystatus
    if available to check whether Shift is pressed.  If it is, show the
    menu, otherwise boot immediately.  If keystatus is not available, then
    fall back to a short delay interruptible with Escape.
  - Allow Shift to interrupt 'sleep --interruptible'.
  - Don't display introductory message about line editing unless we're
    actually offering a shell prompt.  Don't clear the screen just before
    booting if we never drew the menu in the first place.
  - Remove some verbose messages printed before reading the configuration
    file.
  - Suppress progress messages as the kernel and initrd load for
    non-recovery kernel menu entries.
  - Change prepare_grub_to_access_device to handle filesystems
    loop-mounted on file images.
  - Ignore devices loop-mounted from files in 10_linux.
  - Show the boot menu if the previous boot failed, that is if it failed
    to get to the end of one of the normal runlevels.
  - Don't generate /boot/grub/device.map during grub-install or
    grub-mkconfig by default.
  - Adjust upgrade version checks for Ubuntu.
  - Don't display "GRUB loading" unless Shift is held down.
  - Adjust versions of grub-doc and grub-legacy-doc conflicts to tolerate
    our backport of the grub-doc split.
  - Fix LVM/RAID probing in the absence of /boot/grub/device.map.
  - Look for .mo files in /usr/share/locale-langpack as well, in
    preference.
  - Make sure GRUB_TIMEOUT isn't quoted unnecessarily.
  - Probe all devices in 'grub-probe --target=drive' if
    /boot/grub/device.map is missing.
  - Build-depend on qemu-kvm rather than qemu-system for grub-pc tests.
  - Use qemu rather than qemu-system-i386.
  - Program vesafb on BIOS systems rather than efifb.
  - Add a grub-rescue-efi-amd64 package containing a rescue CD-ROM image
    for EFI-AMD64.
  - On Wubi, don't ask for an install device, but just update wubildr
    using the diverted grub-install.
  - When embedding the core image in a post-MBR gap, check for and avoid
    sectors matching any of a list of known signatures.
  - Disable video_bochs and video_cirrus on PC BIOS systems, as probing
    PCI space seems to break on some systems.
* Downgrade "ACPI shutdown failed" error to a debug message, since it can
  cause spurious test failures.

[ Evan Broder ]
* Enable lua from grub-extras.
* Incorporate the bitop library into lua.
* Add enum_pci function to grub module in lua.
* Switch back to gfxpayload=keep by default, unless the video hardware
  is known to not support it.

[ Mario Limonciello ]
* Built part_msdos and vfat into bootx64.efi (LP: #677758)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* appleloader.c - apple legacy boot loader.  */
 
2
/*
 
3
 *  GRUB  --  GRand Unified Bootloader
 
4
 *  Copyright (C) 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/loader.h>
 
21
#include <grub/err.h>
 
22
#include <grub/mm.h>
 
23
#include <grub/dl.h>
 
24
#include <grub/misc.h>
 
25
#include <grub/efi/api.h>
 
26
#include <grub/efi/efi.h>
 
27
#include <grub/command.h>
 
28
#include <grub/i18n.h>
 
29
 
 
30
static grub_dl_t my_mod;
 
31
 
 
32
static grub_efi_handle_t image_handle;
 
33
static grub_efi_char16_t *cmdline;
 
34
 
 
35
static grub_err_t
 
36
grub_appleloader_unload (void)
 
37
{
 
38
  grub_efi_boot_services_t *b;
 
39
 
 
40
  b = grub_efi_system_table->boot_services;
 
41
  efi_call_1 (b->unload_image, image_handle);
 
42
 
 
43
  grub_free (cmdline);
 
44
  cmdline = 0;
 
45
 
 
46
  grub_dl_unref (my_mod);
 
47
  return GRUB_ERR_NONE;
 
48
}
 
49
 
 
50
static grub_err_t
 
51
grub_appleloader_boot (void)
 
52
{
 
53
  grub_efi_boot_services_t *b;
 
54
 
 
55
  b = grub_efi_system_table->boot_services;
 
56
  efi_call_3 (b->start_image, image_handle, 0, 0);
 
57
 
 
58
  grub_appleloader_unload ();
 
59
 
 
60
  return grub_errno;
 
61
}
 
62
 
 
63
struct piwg_full_device_path
 
64
{
 
65
  struct grub_efi_memory_mapped_device_path comp1;
 
66
  struct grub_efi_piwg_device_path comp2;
 
67
  struct grub_efi_device_path end;
 
68
};
 
69
 
 
70
/* early 2006 Core Duo / Core Solo models  */
 
71
static struct piwg_full_device_path devpath_1 =
 
72
{
 
73
  .comp1 =
 
74
  {
 
75
    .header = {
 
76
      .type = GRUB_EFI_HARDWARE_DEVICE_PATH_TYPE,
 
77
      .subtype = GRUB_EFI_MEMORY_MAPPED_DEVICE_PATH_SUBTYPE,
 
78
      .length = {sizeof (struct grub_efi_memory_mapped_device_path), 0}
 
79
    },
 
80
    .memory_type = GRUB_EFI_MEMORY_MAPPED_IO,
 
81
    .start_address = 0xffe00000,
 
82
    .end_address = 0xfff9ffff
 
83
  },
 
84
  .comp2 =
 
85
  {
 
86
    .header = {
 
87
      .type = GRUB_EFI_MEDIA_DEVICE_PATH_TYPE,
 
88
      .subtype = GRUB_EFI_PIWG_DEVICE_PATH_SUBTYPE,
 
89
      .length = {sizeof (struct grub_efi_piwg_device_path), 0}
 
90
    },
 
91
    .guid = {0x2B0585EB, 0xD8B8, 0x49A9, {0x8B, 0x8C, 0xE2, 0x1B,
 
92
                                          0x01, 0xAE, 0xF2, 0xB7}}
 
93
  },
 
94
  .end =
 
95
  {
 
96
    .type = GRUB_EFI_END_DEVICE_PATH_TYPE,
 
97
    .subtype = GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE,
 
98
    .length = {sizeof (struct grub_efi_device_path), 0}
 
99
  }
 
100
};
 
101
 
 
102
/* mid-2006 Mac Pro (and probably other Core 2 models)  */
 
103
static struct piwg_full_device_path devpath_2 =
 
104
{
 
105
  .comp1 =
 
106
  {
 
107
    .header = {
 
108
      .type = GRUB_EFI_HARDWARE_DEVICE_PATH_TYPE,
 
109
      .subtype = GRUB_EFI_MEMORY_MAPPED_DEVICE_PATH_SUBTYPE,
 
110
      .length = {sizeof (struct grub_efi_memory_mapped_device_path), 0}
 
111
    },
 
112
    .memory_type = GRUB_EFI_MEMORY_MAPPED_IO,
 
113
    .start_address = 0xffe00000,
 
114
    .end_address = 0xfff7ffff
 
115
  },
 
116
  .comp2 =
 
117
  {
 
118
    .header = {
 
119
      .type = GRUB_EFI_MEDIA_DEVICE_PATH_TYPE,
 
120
      .subtype = GRUB_EFI_PIWG_DEVICE_PATH_SUBTYPE,
 
121
      .length = {sizeof (struct grub_efi_piwg_device_path), 0}
 
122
    },
 
123
    .guid = {0x2B0585EB, 0xD8B8, 0x49A9, {0x8B, 0x8C, 0xE2, 0x1B,
 
124
                                          0x01, 0xAE, 0xF2, 0xB7}}
 
125
  },
 
126
  .end =
 
127
  {
 
128
    .type = GRUB_EFI_END_DEVICE_PATH_TYPE,
 
129
    .subtype = GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE,
 
130
    .length = {sizeof (struct grub_efi_device_path), 0}
 
131
  }
 
132
};
 
133
 
 
134
/* mid-2007 MBP ("Santa Rosa" based models)  */
 
135
static struct piwg_full_device_path devpath_3 =
 
136
{
 
137
  .comp1 =
 
138
  {
 
139
    .header = {
 
140
      .type = GRUB_EFI_HARDWARE_DEVICE_PATH_TYPE,
 
141
      .subtype = GRUB_EFI_MEMORY_MAPPED_DEVICE_PATH_SUBTYPE,
 
142
      .length = {sizeof (struct grub_efi_memory_mapped_device_path), 0}
 
143
    },
 
144
    .memory_type = GRUB_EFI_MEMORY_MAPPED_IO,
 
145
    .start_address = 0xffe00000,
 
146
    .end_address = 0xfff8ffff
 
147
  },
 
148
  .comp2 =
 
149
  {
 
150
    .header = {
 
151
      .type = GRUB_EFI_MEDIA_DEVICE_PATH_TYPE,
 
152
      .subtype = GRUB_EFI_PIWG_DEVICE_PATH_SUBTYPE,
 
153
      .length = {sizeof (struct grub_efi_piwg_device_path), 0}
 
154
    },
 
155
    .guid = {0x2B0585EB, 0xD8B8, 0x49A9, {0x8B, 0x8C, 0xE2, 0x1B,
 
156
                                          0x01, 0xAE, 0xF2, 0xB7}}
 
157
  },
 
158
  .end =
 
159
  {
 
160
    .type = GRUB_EFI_END_DEVICE_PATH_TYPE,
 
161
    .subtype = GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE,
 
162
    .length = {sizeof (struct grub_efi_device_path), 0}
 
163
  }
 
164
};
 
165
 
 
166
/* early-2008 MBA  */
 
167
static struct piwg_full_device_path devpath_4 =
 
168
{
 
169
  .comp1 =
 
170
  {
 
171
    .header = {
 
172
      .type = GRUB_EFI_HARDWARE_DEVICE_PATH_TYPE,
 
173
      .subtype = GRUB_EFI_MEMORY_MAPPED_DEVICE_PATH_SUBTYPE,
 
174
      .length = {sizeof (struct grub_efi_memory_mapped_device_path), 0}
 
175
    },
 
176
    .memory_type = GRUB_EFI_MEMORY_MAPPED_IO,
 
177
    .start_address = 0xffc00000,
 
178
    .end_address = 0xfff8ffff
 
179
  },
 
180
  .comp2 =
 
181
  {
 
182
    .header = {
 
183
      .type = GRUB_EFI_MEDIA_DEVICE_PATH_TYPE,
 
184
      .subtype = GRUB_EFI_PIWG_DEVICE_PATH_SUBTYPE,
 
185
      .length = {sizeof (struct grub_efi_piwg_device_path), 0}
 
186
    },
 
187
    .guid = {0x2B0585EB, 0xD8B8, 0x49A9, {0x8B, 0x8C, 0xE2, 0x1B,
 
188
                                          0x01, 0xAE, 0xF2, 0xB7}}
 
189
  },
 
190
  .end =
 
191
  {
 
192
    .type = GRUB_EFI_END_DEVICE_PATH_TYPE,
 
193
    .subtype = GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE,
 
194
    .length = {sizeof (struct grub_efi_device_path), 0}
 
195
  }
 
196
};
 
197
 
 
198
/* late-2008 MB/MBP (NVidia chipset)  */
 
199
static struct piwg_full_device_path devpath_5 =
 
200
{
 
201
  .comp1 =
 
202
  {
 
203
    .header = {
 
204
      .type = GRUB_EFI_HARDWARE_DEVICE_PATH_TYPE,
 
205
      .subtype = GRUB_EFI_MEMORY_MAPPED_DEVICE_PATH_SUBTYPE,
 
206
      .length = {sizeof (struct grub_efi_memory_mapped_device_path), 0}
 
207
    },
 
208
    .memory_type = GRUB_EFI_MEMORY_MAPPED_IO,
 
209
    .start_address = 0xffcb4000,
 
210
    .end_address = 0xffffbfff
 
211
  },
 
212
  .comp2 =
 
213
  {
 
214
    .header = {
 
215
      .type = GRUB_EFI_MEDIA_DEVICE_PATH_TYPE,
 
216
      .subtype = GRUB_EFI_PIWG_DEVICE_PATH_SUBTYPE,
 
217
      .length = {sizeof (struct grub_efi_piwg_device_path), 0}
 
218
    },
 
219
    .guid = {0x2B0585EB, 0xD8B8, 0x49A9, {0x8B, 0x8C, 0xE2, 0x1B,
 
220
                                          0x01, 0xAE, 0xF2, 0xB7}}
 
221
  },
 
222
  .end =
 
223
  {
 
224
    .type = GRUB_EFI_END_DEVICE_PATH_TYPE,
 
225
    .subtype = GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE,
 
226
    .length = {sizeof (struct grub_efi_device_path), 0}
 
227
  }
 
228
};
 
229
 
 
230
struct devdata
 
231
{
 
232
  char *model;
 
233
  grub_efi_device_path_t *devpath;
 
234
};
 
235
 
 
236
struct devdata devs[] =
 
237
{
 
238
  {"Core Duo/Solo", (grub_efi_device_path_t *) &devpath_1},
 
239
  {"Mac Pro", (grub_efi_device_path_t *) &devpath_2},
 
240
  {"MBP", (grub_efi_device_path_t *) &devpath_3},
 
241
  {"MBA", (grub_efi_device_path_t *) &devpath_4},
 
242
  {"MB NV", (grub_efi_device_path_t *) &devpath_5},
 
243
  {NULL, NULL},
 
244
};
 
245
 
 
246
static grub_err_t
 
247
grub_cmd_appleloader (grub_command_t cmd __attribute__ ((unused)),
 
248
                      int argc, char *argv[])
 
249
{
 
250
  grub_efi_boot_services_t *b;
 
251
  grub_efi_loaded_image_t *loaded_image;
 
252
  struct devdata *pdev;
 
253
 
 
254
  grub_dl_ref (my_mod);
 
255
 
 
256
  /* Initialize some global variables.  */
 
257
  image_handle = 0;
 
258
 
 
259
  b = grub_efi_system_table->boot_services;
 
260
 
 
261
  for (pdev = devs ; pdev->devpath ; pdev++)
 
262
    if (efi_call_6 (b->load_image, 0, grub_efi_image_handle, pdev->devpath,
 
263
                    NULL, 0, &image_handle) == GRUB_EFI_SUCCESS)
 
264
      break;
 
265
 
 
266
  if (! pdev->devpath)
 
267
    {
 
268
      grub_error (GRUB_ERR_BAD_OS, "can't find model");
 
269
      goto fail;
 
270
    }
 
271
 
 
272
  grub_printf ("Model : %s\n", pdev->model);
 
273
 
 
274
  loaded_image = grub_efi_get_loaded_image (image_handle);
 
275
  if (! loaded_image)
 
276
    {
 
277
      grub_error (GRUB_ERR_BAD_OS, "no loaded image available");
 
278
      goto fail;
 
279
    }
 
280
 
 
281
  if (argc > 0)
 
282
    {
 
283
      int i, len;
 
284
      grub_efi_char16_t *p16;
 
285
 
 
286
      for (i = 0, len = 0; i < argc; i++)
 
287
        len += grub_strlen (argv[i]) + 1;
 
288
 
 
289
      len *= sizeof (grub_efi_char16_t);
 
290
      cmdline = p16 = grub_malloc (len);
 
291
      if (! cmdline)
 
292
        goto fail;
 
293
 
 
294
      for (i = 0; i < argc; i++)
 
295
        {
 
296
          char *p8;
 
297
 
 
298
          p8 = argv[i];
 
299
          while (*p8)
 
300
            *(p16++) = *(p8++);
 
301
 
 
302
          *(p16++) = ' ';
 
303
        }
 
304
      *(--p16) = 0;
 
305
 
 
306
      loaded_image->load_options = cmdline;
 
307
      loaded_image->load_options_size = len;
 
308
    }
 
309
 
 
310
  grub_loader_set (grub_appleloader_boot, grub_appleloader_unload, 0);
 
311
 
 
312
  return 0;
 
313
 
 
314
 fail:
 
315
 
 
316
  grub_dl_unref (my_mod);
 
317
  return grub_errno;
 
318
}
 
319
 
 
320
static grub_command_t cmd;
 
321
 
 
322
GRUB_MOD_INIT(appleloader)
 
323
{
 
324
  cmd = grub_register_command ("appleloader", grub_cmd_appleloader,
 
325
                               "[OPTS]", N_("Boot legacy system."));
 
326
  my_mod = mod;
 
327
}
 
328
 
 
329
GRUB_MOD_FINI(appleloader)
 
330
{
 
331
  grub_unregister_command (cmd);
 
332
}