~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, 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
/* 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
}