1
/* appleloader.c - apple legacy boot loader. */
3
* GRUB -- GRand Unified Bootloader
4
* Copyright (C) 2008,2009 Free Software Foundation, Inc.
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.
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.
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/>.
20
#include <grub/loader.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>
30
static grub_dl_t my_mod;
32
static grub_efi_handle_t image_handle;
33
static grub_efi_char16_t *cmdline;
36
grub_appleloader_unload (void)
38
grub_efi_boot_services_t *b;
40
b = grub_efi_system_table->boot_services;
41
efi_call_1 (b->unload_image, image_handle);
46
grub_dl_unref (my_mod);
51
grub_appleloader_boot (void)
53
grub_efi_boot_services_t *b;
55
b = grub_efi_system_table->boot_services;
56
efi_call_3 (b->start_image, image_handle, 0, 0);
58
grub_appleloader_unload ();
63
struct piwg_full_device_path
65
struct grub_efi_memory_mapped_device_path comp1;
66
struct grub_efi_piwg_device_path comp2;
67
struct grub_efi_device_path end;
70
/* early 2006 Core Duo / Core Solo models */
71
static struct piwg_full_device_path devpath_1 =
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}
80
.memory_type = GRUB_EFI_MEMORY_MAPPED_IO,
81
.start_address = 0xffe00000,
82
.end_address = 0xfff9ffff
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}
91
.guid = {0x2B0585EB, 0xD8B8, 0x49A9, {0x8B, 0x8C, 0xE2, 0x1B,
92
0x01, 0xAE, 0xF2, 0xB7}}
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}
102
/* mid-2006 Mac Pro (and probably other Core 2 models) */
103
static struct piwg_full_device_path devpath_2 =
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}
112
.memory_type = GRUB_EFI_MEMORY_MAPPED_IO,
113
.start_address = 0xffe00000,
114
.end_address = 0xfff7ffff
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}
123
.guid = {0x2B0585EB, 0xD8B8, 0x49A9, {0x8B, 0x8C, 0xE2, 0x1B,
124
0x01, 0xAE, 0xF2, 0xB7}}
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}
134
/* mid-2007 MBP ("Santa Rosa" based models) */
135
static struct piwg_full_device_path devpath_3 =
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}
144
.memory_type = GRUB_EFI_MEMORY_MAPPED_IO,
145
.start_address = 0xffe00000,
146
.end_address = 0xfff8ffff
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}
155
.guid = {0x2B0585EB, 0xD8B8, 0x49A9, {0x8B, 0x8C, 0xE2, 0x1B,
156
0x01, 0xAE, 0xF2, 0xB7}}
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}
167
static struct piwg_full_device_path devpath_4 =
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}
176
.memory_type = GRUB_EFI_MEMORY_MAPPED_IO,
177
.start_address = 0xffc00000,
178
.end_address = 0xfff8ffff
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}
187
.guid = {0x2B0585EB, 0xD8B8, 0x49A9, {0x8B, 0x8C, 0xE2, 0x1B,
188
0x01, 0xAE, 0xF2, 0xB7}}
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}
198
/* late-2008 MB/MBP (NVidia chipset) */
199
static struct piwg_full_device_path devpath_5 =
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}
208
.memory_type = GRUB_EFI_MEMORY_MAPPED_IO,
209
.start_address = 0xffcb4000,
210
.end_address = 0xffffbfff
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}
219
.guid = {0x2B0585EB, 0xD8B8, 0x49A9, {0x8B, 0x8C, 0xE2, 0x1B,
220
0x01, 0xAE, 0xF2, 0xB7}}
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}
233
grub_efi_device_path_t *devpath;
236
struct devdata devs[] =
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},
247
grub_cmd_appleloader (grub_command_t cmd __attribute__ ((unused)),
248
int argc, char *argv[])
250
grub_efi_boot_services_t *b;
251
grub_efi_loaded_image_t *loaded_image;
252
struct devdata *pdev;
254
grub_dl_ref (my_mod);
256
/* Initialize some global variables. */
259
b = grub_efi_system_table->boot_services;
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)
268
grub_error (GRUB_ERR_BAD_OS, "can't find model");
272
grub_printf ("Model : %s\n", pdev->model);
274
loaded_image = grub_efi_get_loaded_image (image_handle);
277
grub_error (GRUB_ERR_BAD_OS, "no loaded image available");
284
grub_efi_char16_t *p16;
286
for (i = 0, len = 0; i < argc; i++)
287
len += grub_strlen (argv[i]) + 1;
289
len *= sizeof (grub_efi_char16_t);
290
cmdline = p16 = grub_malloc (len);
294
for (i = 0; i < argc; i++)
306
loaded_image->load_options = cmdline;
307
loaded_image->load_options_size = len;
310
grub_loader_set (grub_appleloader_boot, grub_appleloader_unload, 0);
316
grub_dl_unref (my_mod);
320
static grub_command_t cmd;
322
GRUB_MOD_INIT(appleloader)
324
cmd = grub_register_command ("appleloader", grub_cmd_appleloader,
325
"[OPTS]", N_("Boot legacy system."));
329
GRUB_MOD_FINI(appleloader)
331
grub_unregister_command (cmd);