2
* GRUB -- GRand Unified Bootloader
3
* Copyright (C) 2003,2004,2005,2006,2007,2008,2009,2010 Free Software Foundation, Inc.
5
* GRUB is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation, either version 3 of the License, or
8
* (at your option) any later version.
10
* GRUB is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
24
#include <sys/types.h>
28
#include <grub/setjmp.h>
30
#include <grub/util/hostdisk.h>
32
#include <grub/util/console.h>
33
#include <grub/util/misc.h>
34
#include <grub/kernel.h>
35
#include <grub/normal.h>
36
#include <grub/util/getroot.h>
38
#include <grub/partition.h>
39
#include <grub/i18n.h>
41
#include <grub_emu_init.h>
45
/* Used for going back to the main function. */
46
static jmp_buf main_env;
48
/* Store the prefix specified by an argument. */
49
static char *prefix = NULL;
52
grub_arch_modules_addr (void)
58
grub_arch_dl_check_header (void *ehdr)
62
return GRUB_ERR_BAD_MODULE;
66
grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr)
71
return GRUB_ERR_BAD_MODULE;
77
longjmp (main_env, 1);
82
#ifdef GRUB_MACHINE_PCBIOS
83
int no_apm __attribute__ ((unused))
91
grub_machine_init (void)
96
grub_machine_set_prefix (void)
98
grub_env_set ("prefix", prefix);
104
grub_machine_fini (void)
106
grub_console_fini ();
110
read_command_list (void)
115
static struct option options[] =
117
{"root-device", required_argument, 0, 'r'},
118
{"device-map", required_argument, 0, 'm'},
119
{"directory", required_argument, 0, 'd'},
120
{"hold", optional_argument, 0, 'H'},
121
{"help", no_argument, 0, 'h'},
122
{"version", no_argument, 0, 'V'},
123
{"verbose", no_argument, 0, 'v'},
132
"Try `%s --help' for more information.\n", program_name);
135
"Usage: %s [OPTION]...\n"
139
" -r, --root-device=DEV use DEV as the root device [default=guessed]\n"
140
" -m, --device-map=FILE use FILE as the device map [default=%s]\n"
141
" -d, --directory=DIR use GRUB files in the directory DIR [default=%s]\n"
142
" -v, --verbose print verbose messages\n"
143
" -H, --hold[=SECONDS] wait until a debugger will attach\n"
144
" -h, --help display this message and exit\n"
145
" -V, --version print version information and exit\n"
147
"Report bugs to <%s>.\n", program_name, DEFAULT_DEVICE_MAP, DEFAULT_DIRECTORY, PACKAGE_BUGREPORT);
153
main (int argc, char *argv[])
156
char *dir = DEFAULT_DIRECTORY;
157
char *dev_map = DEFAULT_DEVICE_MAP;
158
volatile int hold = 0;
161
set_program_name (argv[0]);
163
grub_util_init_nls ();
165
while ((opt = getopt_long (argc, argv, "r:d:m:vH:hV", options, 0)) != -1)
181
hold = (optarg ? atoi (optarg) : -1);
186
printf ("%s (%s) %s\n", program_name, PACKAGE_NAME, PACKAGE_VERSION);
194
fprintf (stderr, "Unknown extra argument `%s'.\n", argv[optind]);
198
/* Wait until the ARGS.HOLD variable is cleared by an attached debugger. */
199
if (hold && verbosity > 0)
200
printf ("Run \"gdb %s %d\", and set ARGS.HOLD to zero.\n",
201
program_name, (int) getpid ());
210
signal (SIGINT, SIG_IGN);
211
grub_console_init ();
213
/* XXX: This is a bit unportable. */
214
grub_util_biosdisk_init (dev_map);
218
/* Make sure that there is a root device. */
221
char *device_name = grub_guess_root_device (dir);
223
grub_util_error ("cannot find a device for %s", dir);
225
root_dev = grub_util_get_grub_dev (device_name);
228
grub_util_info ("guessing the root device failed, because of `%s'",
230
grub_util_error ("cannot guess the root device. Specify the option `--root-device'");
234
dir = grub_get_prefix (dir);
235
prefix = xmalloc (strlen (root_dev) + 2 + strlen (dir) + 1);
236
sprintf (prefix, "(%s)%s", root_dev, dir);
240
if (setjmp (main_env) == 0)
245
grub_machine_fini ();