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 GRUB_MOD_LICENSE ("GPLv3+");
32 static grub_dl_t my_mod
;
34 static grub_efi_handle_t image_handle
;
35 static grub_efi_char16_t
*cmdline
;
38 grub_appleloader_unload (void)
40 grub_efi_boot_services_t
*b
;
42 b
= grub_efi_system_table
->boot_services
;
43 efi_call_1 (b
->unload_image
, image_handle
);
48 grub_dl_unref (my_mod
);
53 grub_appleloader_boot (void)
55 grub_efi_boot_services_t
*b
;
57 b
= grub_efi_system_table
->boot_services
;
58 efi_call_3 (b
->start_image
, image_handle
, 0, 0);
60 grub_appleloader_unload ();
65 struct piwg_full_device_path
67 struct grub_efi_memory_mapped_device_path comp1
;
68 struct grub_efi_piwg_device_path comp2
;
69 struct grub_efi_device_path end
;
72 /* early 2006 Core Duo / Core Solo models */
73 static struct piwg_full_device_path devpath_1
=
78 .type
= GRUB_EFI_HARDWARE_DEVICE_PATH_TYPE
,
79 .subtype
= GRUB_EFI_MEMORY_MAPPED_DEVICE_PATH_SUBTYPE
,
80 .length
= {sizeof (struct grub_efi_memory_mapped_device_path
), 0}
82 .memory_type
= GRUB_EFI_MEMORY_MAPPED_IO
,
83 .start_address
= 0xffe00000,
84 .end_address
= 0xfff9ffff
89 .type
= GRUB_EFI_MEDIA_DEVICE_PATH_TYPE
,
90 .subtype
= GRUB_EFI_PIWG_DEVICE_PATH_SUBTYPE
,
91 .length
= {sizeof (struct grub_efi_piwg_device_path
), 0}
93 .guid
= {0x2B0585EB, 0xD8B8, 0x49A9, {0x8B, 0x8C, 0xE2, 0x1B,
94 0x01, 0xAE, 0xF2, 0xB7}}
98 .type
= GRUB_EFI_END_DEVICE_PATH_TYPE
,
99 .subtype
= GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE
,
100 .length
= {sizeof (struct grub_efi_device_path
), 0}
104 /* mid-2006 Mac Pro (and probably other Core 2 models) */
105 static struct piwg_full_device_path devpath_2
=
110 .type
= GRUB_EFI_HARDWARE_DEVICE_PATH_TYPE
,
111 .subtype
= GRUB_EFI_MEMORY_MAPPED_DEVICE_PATH_SUBTYPE
,
112 .length
= {sizeof (struct grub_efi_memory_mapped_device_path
), 0}
114 .memory_type
= GRUB_EFI_MEMORY_MAPPED_IO
,
115 .start_address
= 0xffe00000,
116 .end_address
= 0xfff7ffff
121 .type
= GRUB_EFI_MEDIA_DEVICE_PATH_TYPE
,
122 .subtype
= GRUB_EFI_PIWG_DEVICE_PATH_SUBTYPE
,
123 .length
= {sizeof (struct grub_efi_piwg_device_path
), 0}
125 .guid
= {0x2B0585EB, 0xD8B8, 0x49A9, {0x8B, 0x8C, 0xE2, 0x1B,
126 0x01, 0xAE, 0xF2, 0xB7}}
130 .type
= GRUB_EFI_END_DEVICE_PATH_TYPE
,
131 .subtype
= GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE
,
132 .length
= {sizeof (struct grub_efi_device_path
), 0}
136 /* mid-2007 MBP ("Santa Rosa" based models) */
137 static struct piwg_full_device_path devpath_3
=
142 .type
= GRUB_EFI_HARDWARE_DEVICE_PATH_TYPE
,
143 .subtype
= GRUB_EFI_MEMORY_MAPPED_DEVICE_PATH_SUBTYPE
,
144 .length
= {sizeof (struct grub_efi_memory_mapped_device_path
), 0}
146 .memory_type
= GRUB_EFI_MEMORY_MAPPED_IO
,
147 .start_address
= 0xffe00000,
148 .end_address
= 0xfff8ffff
153 .type
= GRUB_EFI_MEDIA_DEVICE_PATH_TYPE
,
154 .subtype
= GRUB_EFI_PIWG_DEVICE_PATH_SUBTYPE
,
155 .length
= {sizeof (struct grub_efi_piwg_device_path
), 0}
157 .guid
= {0x2B0585EB, 0xD8B8, 0x49A9, {0x8B, 0x8C, 0xE2, 0x1B,
158 0x01, 0xAE, 0xF2, 0xB7}}
162 .type
= GRUB_EFI_END_DEVICE_PATH_TYPE
,
163 .subtype
= GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE
,
164 .length
= {sizeof (struct grub_efi_device_path
), 0}
169 static struct piwg_full_device_path devpath_4
=
174 .type
= GRUB_EFI_HARDWARE_DEVICE_PATH_TYPE
,
175 .subtype
= GRUB_EFI_MEMORY_MAPPED_DEVICE_PATH_SUBTYPE
,
176 .length
= {sizeof (struct grub_efi_memory_mapped_device_path
), 0}
178 .memory_type
= GRUB_EFI_MEMORY_MAPPED_IO
,
179 .start_address
= 0xffc00000,
180 .end_address
= 0xfff8ffff
185 .type
= GRUB_EFI_MEDIA_DEVICE_PATH_TYPE
,
186 .subtype
= GRUB_EFI_PIWG_DEVICE_PATH_SUBTYPE
,
187 .length
= {sizeof (struct grub_efi_piwg_device_path
), 0}
189 .guid
= {0x2B0585EB, 0xD8B8, 0x49A9, {0x8B, 0x8C, 0xE2, 0x1B,
190 0x01, 0xAE, 0xF2, 0xB7}}
194 .type
= GRUB_EFI_END_DEVICE_PATH_TYPE
,
195 .subtype
= GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE
,
196 .length
= {sizeof (struct grub_efi_device_path
), 0}
200 /* late-2008 MB/MBP (NVidia chipset) */
201 static struct piwg_full_device_path devpath_5
=
206 .type
= GRUB_EFI_HARDWARE_DEVICE_PATH_TYPE
,
207 .subtype
= GRUB_EFI_MEMORY_MAPPED_DEVICE_PATH_SUBTYPE
,
208 .length
= {sizeof (struct grub_efi_memory_mapped_device_path
), 0}
210 .memory_type
= GRUB_EFI_MEMORY_MAPPED_IO
,
211 .start_address
= 0xffcb4000,
212 .end_address
= 0xffffbfff
217 .type
= GRUB_EFI_MEDIA_DEVICE_PATH_TYPE
,
218 .subtype
= GRUB_EFI_PIWG_DEVICE_PATH_SUBTYPE
,
219 .length
= {sizeof (struct grub_efi_piwg_device_path
), 0}
221 .guid
= {0x2B0585EB, 0xD8B8, 0x49A9, {0x8B, 0x8C, 0xE2, 0x1B,
222 0x01, 0xAE, 0xF2, 0xB7}}
226 .type
= GRUB_EFI_END_DEVICE_PATH_TYPE
,
227 .subtype
= GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE
,
228 .length
= {sizeof (struct grub_efi_device_path
), 0}
232 /* mid-2010 MB/MBP (NVidia chipset) */
233 static struct piwg_full_device_path devpath_6
=
238 .type
= GRUB_EFI_HARDWARE_DEVICE_PATH_TYPE
,
239 .subtype
= GRUB_EFI_MEMORY_MAPPED_DEVICE_PATH_SUBTYPE
,
240 .length
= {sizeof (struct grub_efi_memory_mapped_device_path
), 0}
242 .memory_type
= GRUB_EFI_MEMORY_MAPPED_IO
,
243 .start_address
= 0xffcc4000,
244 .end_address
= 0xffffbfff
249 .type
= GRUB_EFI_MEDIA_DEVICE_PATH_TYPE
,
250 .subtype
= GRUB_EFI_PIWG_DEVICE_PATH_SUBTYPE
,
251 .length
= {sizeof (struct grub_efi_piwg_device_path
), 0}
253 .guid
= {0x2B0585EB, 0xD8B8, 0x49A9, {0x8B, 0x8C, 0xE2, 0x1B,
254 0x01, 0xAE, 0xF2, 0xB7}}
258 .type
= GRUB_EFI_END_DEVICE_PATH_TYPE
,
259 .subtype
= GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE
,
260 .length
= {sizeof (struct grub_efi_device_path
), 0}
267 grub_efi_device_path_t
*devpath
;
270 struct devdata devs
[] =
272 {"Core Duo/Solo", (grub_efi_device_path_t
*) &devpath_1
},
273 {"Mac Pro", (grub_efi_device_path_t
*) &devpath_2
},
274 {"MBP", (grub_efi_device_path_t
*) &devpath_3
},
275 {"MBA", (grub_efi_device_path_t
*) &devpath_4
},
276 {"MB NV", (grub_efi_device_path_t
*) &devpath_5
},
277 {"MB NV2", (grub_efi_device_path_t
*) &devpath_6
},
282 grub_cmd_appleloader (grub_command_t cmd
__attribute__ ((unused
)),
283 int argc
, char *argv
[])
285 grub_efi_boot_services_t
*b
;
286 grub_efi_loaded_image_t
*loaded_image
;
287 struct devdata
*pdev
;
289 grub_dl_ref (my_mod
);
291 /* Initialize some global variables. */
294 b
= grub_efi_system_table
->boot_services
;
296 for (pdev
= devs
; pdev
->devpath
; pdev
++)
297 if (efi_call_6 (b
->load_image
, 0, grub_efi_image_handle
, pdev
->devpath
,
298 NULL
, 0, &image_handle
) == GRUB_EFI_SUCCESS
)
303 grub_error (GRUB_ERR_BAD_OS
, "can't find model");
307 grub_printf ("Model : %s\n", pdev
->model
);
309 loaded_image
= grub_efi_get_loaded_image (image_handle
);
312 grub_error (GRUB_ERR_BAD_OS
, "no loaded image available");
319 grub_efi_char16_t
*p16
;
321 for (i
= 0, len
= 0; i
< argc
; i
++)
322 len
+= grub_strlen (argv
[i
]) + 1;
324 len
*= sizeof (grub_efi_char16_t
);
325 cmdline
= p16
= grub_malloc (len
);
329 for (i
= 0; i
< argc
; i
++)
341 loaded_image
->load_options
= cmdline
;
342 loaded_image
->load_options_size
= len
;
345 grub_loader_set (grub_appleloader_boot
, grub_appleloader_unload
, 0);
351 grub_dl_unref (my_mod
);
355 static grub_command_t cmd
;
357 GRUB_MOD_INIT(appleloader
)
359 cmd
= grub_register_command ("appleloader", grub_cmd_appleloader
,
360 "[OPTS]", N_("Boot legacy system."));
364 GRUB_MOD_FINI(appleloader
)
366 grub_unregister_command (cmd
);