1
/* init.c - generic EFI initialization and finalization */
3
* GRUB -- GRand Unified Bootloader
4
* Copyright (C) 2006,2007 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/efi/efi.h>
21
#include <grub/efi/console.h>
22
#include <grub/efi/disk.h>
23
#include <grub/term.h>
24
#include <grub/misc.h>
27
#include <grub/kernel.h>
32
/* First of all, initialize the console so that GRUB can display
36
/* Initialize the memory management system. */
39
efi_call_4 (grub_efi_system_table->boot_services->set_watchdog_timer,
46
grub_efi_set_prefix (void)
48
grub_efi_loaded_image_t *image = NULL;
54
if (grub_prefix[0] == '(')
56
pptr = grub_strrchr (grub_prefix, ')');
59
device = grub_strndup (grub_prefix + 1, pptr - grub_prefix - 1);
66
path = grub_strdup (pptr);
69
if ((!device || device[0] == ',' || !device[0]) || !path)
70
image = grub_efi_get_loaded_image (grub_efi_image_handle);
74
device = grub_efidisk_get_device_name (image->device_handle);
75
else if (device[0] == ',' || !device[0])
77
/* We have a partition, but still need to fill in the drive. */
78
char *image_device, *comma, *new_device;
80
image_device = grub_efidisk_get_device_name (image->device_handle);
81
comma = grub_strchr (image_device, ',');
84
char *drive = grub_strndup (image_device, comma - image_device);
85
new_device = grub_xasprintf ("%s%s", drive, device);
89
new_device = grub_xasprintf ("%s%s", image_device, device);
91
grub_free (image_device);
101
path = grub_efi_get_filename (image->file_path);
103
/* Get the directory. */
104
p = grub_strrchr (path, '/');
113
prefix = grub_xasprintf ("(%s)%s", device, path);
116
grub_env_set ("prefix", prefix);
128
grub_efidisk_fini ();
129
grub_console_fini ();