1 /* appleloader.c - apple legacy boot loader. */
3 * GRUB -- GRand Unified Bootloader
4 * Copyright (C) 2008 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/normal.h>
26 #include <grub/efi/api.h>
27 #include <grub/efi/efi.h>
29 static grub_dl_t my_mod
;
31 static grub_efi_handle_t image_handle
;
32 static grub_efi_char16_t
*cmdline
;
35 grub_appleloader_unload (void)
37 grub_efi_boot_services_t
*b
;
39 b
= grub_efi_system_table
->boot_services
;
40 efi_call_1 (b
->unload_image
, image_handle
);
45 grub_dl_unref (my_mod
);
50 grub_appleloader_boot (void)
52 grub_efi_boot_services_t
*b
;
54 b
= grub_efi_system_table
->boot_services
;
55 efi_call_3 (b
->start_image
, image_handle
, 0, 0);
57 grub_appleloader_unload ();
62 /* early 2006 Core Duo / Core Solo models */
63 static grub_uint8_t devpath_1
[] =
65 0x01, 0x03, 0x18, 0x00, 0x0B, 0x00, 0x00, 0x00,
66 0x00, 0x00, 0xE0, 0xFF, 0x00, 0x00, 0x00, 0x00,
67 0xFF, 0xFF, 0xF9, 0xFF, 0x00, 0x00, 0x00, 0x00,
68 0x04, 0x06, 0x14, 0x00, 0xEB, 0x85, 0x05, 0x2B,
69 0xB8, 0xD8, 0xA9, 0x49, 0x8B, 0x8C, 0xE2, 0x1B,
70 0x01, 0xAE, 0xF2, 0xB7, 0x7F, 0xFF, 0x04, 0x00,
73 /* mid-2006 Mac Pro (and probably other Core 2 models) */
74 static grub_uint8_t devpath_2
[] =
76 0x01, 0x03, 0x18, 0x00, 0x0B, 0x00, 0x00, 0x00,
77 0x00, 0x00, 0xE0, 0xFF, 0x00, 0x00, 0x00, 0x00,
78 0xFF, 0xFF, 0xF7, 0xFF, 0x00, 0x00, 0x00, 0x00,
79 0x04, 0x06, 0x14, 0x00, 0xEB, 0x85, 0x05, 0x2B,
80 0xB8, 0xD8, 0xA9, 0x49, 0x8B, 0x8C, 0xE2, 0x1B,
81 0x01, 0xAE, 0xF2, 0xB7, 0x7F, 0xFF, 0x04, 0x00,
84 /* mid-2007 MBP ("Santa Rosa" based models) */
85 static grub_uint8_t devpath_3
[] =
87 0x01, 0x03, 0x18, 0x00, 0x0B, 0x00, 0x00, 0x00,
88 0x00, 0x00, 0xE0, 0xFF, 0x00, 0x00, 0x00, 0x00,
89 0xFF, 0xFF, 0xF8, 0xFF, 0x00, 0x00, 0x00, 0x00,
90 0x04, 0x06, 0x14, 0x00, 0xEB, 0x85, 0x05, 0x2B,
91 0xB8, 0xD8, 0xA9, 0x49, 0x8B, 0x8C, 0xE2, 0x1B,
92 0x01, 0xAE, 0xF2, 0xB7, 0x7F, 0xFF, 0x04, 0x00,
96 static grub_uint8_t devpath_4
[] =
98 0x01, 0x03, 0x18, 0x00, 0x0B, 0x00, 0x00, 0x00,
99 0x00, 0x00, 0xC0, 0xFF, 0x00, 0x00, 0x00, 0x00,
100 0xFF, 0xFF, 0xF8, 0xFF, 0x00, 0x00, 0x00, 0x00,
101 0x04, 0x06, 0x14, 0x00, 0xEB, 0x85, 0x05, 0x2B,
102 0xB8, 0xD8, 0xA9, 0x49, 0x8B, 0x8C, 0xE2, 0x1B,
103 0x01, 0xAE, 0xF2, 0xB7, 0x7F, 0xFF, 0x04, 0x00,
109 grub_efi_device_path_t
*devpath
;
112 struct devdata devs
[] =
114 {"Core Duo/Solo", (grub_efi_device_path_t
*) devpath_1
},
115 {"Mac Pro", (grub_efi_device_path_t
*) devpath_2
},
116 {"MBP", (grub_efi_device_path_t
*) devpath_3
},
117 {"MBA", (grub_efi_device_path_t
*) devpath_4
},
122 grub_cmd_appleloader (struct grub_arg_list
*state
__attribute__ ((unused
)),
123 int argc
, char *argv
[])
125 grub_efi_boot_services_t
*b
;
126 grub_efi_loaded_image_t
*loaded_image
;
127 struct devdata
*pdev
;
129 grub_dl_ref (my_mod
);
131 /* Initialize some global variables. */
134 b
= grub_efi_system_table
->boot_services
;
136 for (pdev
= devs
; pdev
->devpath
; pdev
++)
137 if (efi_call_6 (b
->load_image
, 0, grub_efi_image_handle
, pdev
->devpath
,
138 NULL
, 0, &image_handle
) == GRUB_EFI_SUCCESS
)
143 grub_error (GRUB_ERR_BAD_OS
, "can't find model");
147 grub_printf ("Model : %s\n", pdev
->model
);
149 loaded_image
= grub_efi_get_loaded_image (image_handle
);
152 grub_error (GRUB_ERR_BAD_OS
, "no loaded image available");
159 grub_efi_char16_t
*p16
;
161 for (i
= 0, len
= 0; i
< argc
; i
++)
162 len
+= grub_strlen (argv
[i
]) + 1;
164 len
*= sizeof (grub_efi_char16_t
);
165 cmdline
= p16
= grub_malloc (len
);
169 for (i
= 0; i
< argc
; i
++)
181 loaded_image
->load_options
= cmdline
;
182 loaded_image
->load_options_size
= len
;
185 grub_loader_set (grub_appleloader_boot
, grub_appleloader_unload
, 0);
191 grub_dl_unref (my_mod
);
195 GRUB_MOD_INIT(appleloader
)
197 grub_register_command ("appleloader", grub_cmd_appleloader
,
198 GRUB_COMMAND_FLAG_BOTH
,
199 "appleloader [OPTS]",
200 "Boot legacy system.", 0);
205 GRUB_MOD_FINI(appleloader
)
207 grub_unregister_command ("appleloader");