~darkmuggle-deactivatedaccount/ubuntu/quantal/grub2/fix-872244

« back to all changes in this revision

Viewing changes to kern/emu/main.c

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson, Colin Watson, Evan Broder, Mario Limonciello
  • Date: 2010-11-24 13:59:55 UTC
  • mfrom: (1.17.6 upstream) (17.6.15 experimental)
  • Revision ID: james.westby@ubuntu.com-20101124135955-r6ii5sepayr7jt53
Tags: 1.99~20101124-1ubuntu1
[ Colin Watson ]
* Resynchronise with Debian experimental.  Remaining changes:
  - Adjust for default Ubuntu boot options ("quiet splash").
  - Default to hiding the menu; holding down Shift at boot will show it.
  - Set a monochromatic theme for Ubuntu.
  - Apply Ubuntu GRUB Legacy changes to legacy update-grub script: title,
    recovery mode, quiet option, tweak how memtest86+ is displayed, and
    use UUIDs where appropriate.
  - Fix backslash-escaping in merge_debconf_into_conf.
  - Remove "GNU/Linux" from default distributor string.
  - Add crashkernel= options if kdump and makedumpfile are available.
  - If other operating systems are installed, then automatically unhide
    the menu.  Otherwise, if GRUB_HIDDEN_TIMEOUT is 0, then use keystatus
    if available to check whether Shift is pressed.  If it is, show the
    menu, otherwise boot immediately.  If keystatus is not available, then
    fall back to a short delay interruptible with Escape.
  - Allow Shift to interrupt 'sleep --interruptible'.
  - Don't display introductory message about line editing unless we're
    actually offering a shell prompt.  Don't clear the screen just before
    booting if we never drew the menu in the first place.
  - Remove some verbose messages printed before reading the configuration
    file.
  - Suppress progress messages as the kernel and initrd load for
    non-recovery kernel menu entries.
  - Change prepare_grub_to_access_device to handle filesystems
    loop-mounted on file images.
  - Ignore devices loop-mounted from files in 10_linux.
  - Show the boot menu if the previous boot failed, that is if it failed
    to get to the end of one of the normal runlevels.
  - Don't generate /boot/grub/device.map during grub-install or
    grub-mkconfig by default.
  - Adjust upgrade version checks for Ubuntu.
  - Don't display "GRUB loading" unless Shift is held down.
  - Adjust versions of grub-doc and grub-legacy-doc conflicts to tolerate
    our backport of the grub-doc split.
  - Fix LVM/RAID probing in the absence of /boot/grub/device.map.
  - Look for .mo files in /usr/share/locale-langpack as well, in
    preference.
  - Make sure GRUB_TIMEOUT isn't quoted unnecessarily.
  - Probe all devices in 'grub-probe --target=drive' if
    /boot/grub/device.map is missing.
  - Build-depend on qemu-kvm rather than qemu-system for grub-pc tests.
  - Use qemu rather than qemu-system-i386.
  - Program vesafb on BIOS systems rather than efifb.
  - Add a grub-rescue-efi-amd64 package containing a rescue CD-ROM image
    for EFI-AMD64.
  - On Wubi, don't ask for an install device, but just update wubildr
    using the diverted grub-install.
  - When embedding the core image in a post-MBR gap, check for and avoid
    sectors matching any of a list of known signatures.
  - Disable video_bochs and video_cirrus on PC BIOS systems, as probing
    PCI space seems to break on some systems.
* Downgrade "ACPI shutdown failed" error to a debug message, since it can
  cause spurious test failures.

[ Evan Broder ]
* Enable lua from grub-extras.
* Incorporate the bitop library into lua.
* Add enum_pci function to grub module in lua.
* Switch back to gfxpayload=keep by default, unless the video hardware
  is known to not support it.

[ Mario Limonciello ]
* Built part_msdos and vfat into bootx64.efi (LP: #677758)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *  GRUB  --  GRand Unified Bootloader
3
 
 *  Copyright (C) 2003,2004,2005,2006,2007,2008,2009,2010  Free Software Foundation, Inc.
4
 
 *
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.
9
 
 *
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.
14
 
 *
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/>.
17
 
 */
18
 
 
19
 
#include <time.h>
20
 
#include <stdio.h>
21
 
#include <stdlib.h>
22
 
#include <setjmp.h>
23
 
#include <sys/stat.h>
24
 
#include <getopt.h>
25
 
#include <string.h>
26
 
#include <signal.h>
27
 
#include <sys/types.h>
28
 
#include <unistd.h>
29
 
 
30
 
#include <grub/dl.h>
31
 
#include <grub/mm.h>
32
 
#include <grub/setjmp.h>
33
 
#include <grub/fs.h>
34
 
#include <grub/emu/hostdisk.h>
35
 
#include <grub/time.h>
36
 
#include <grub/emu/console.h>
37
 
#include <grub/emu/misc.h>
38
 
#include <grub/kernel.h>
39
 
#include <grub/normal.h>
40
 
#include <grub/emu/getroot.h>
41
 
#include <grub/env.h>
42
 
#include <grub/partition.h>
43
 
#include <grub/i18n.h>
44
 
 
45
 
#define ENABLE_RELOCATABLE 0
46
 
#include "progname.h"
47
 
 
48
 
/* Used for going back to the main function.  */
49
 
static jmp_buf main_env;
50
 
 
51
 
/* Store the prefix specified by an argument.  */
52
 
static char *prefix = NULL;
53
 
 
54
 
grub_addr_t
55
 
grub_arch_modules_addr (void)
56
 
{
57
 
  return 0;
58
 
}
59
 
 
60
 
#if GRUB_NO_MODULES
61
 
grub_err_t
62
 
grub_arch_dl_check_header (void *ehdr)
63
 
{
64
 
  (void) ehdr;
65
 
 
66
 
  return GRUB_ERR_BAD_MODULE;
67
 
}
68
 
 
69
 
grub_err_t
70
 
grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr)
71
 
{
72
 
  (void) mod;
73
 
  (void) ehdr;
74
 
 
75
 
  return GRUB_ERR_BAD_MODULE;
76
 
}
77
 
#endif
78
 
 
79
 
void
80
 
grub_reboot (void)
81
 
{
82
 
  longjmp (main_env, 1);
83
 
}
84
 
 
85
 
void
86
 
grub_halt (
87
 
#ifdef GRUB_MACHINE_PCBIOS
88
 
           int no_apm __attribute__ ((unused))
89
 
#endif
90
 
           )
91
 
{
92
 
  grub_reboot ();
93
 
}
94
 
 
95
 
void
96
 
grub_machine_init (void)
97
 
{
98
 
}
99
 
 
100
 
void
101
 
grub_machine_set_prefix (void)
102
 
{
103
 
  grub_env_set ("prefix", prefix);
104
 
  free (prefix);
105
 
  prefix = 0;
106
 
}
107
 
 
108
 
void
109
 
grub_machine_fini (void)
110
 
{
111
 
  grub_console_fini ();
112
 
}
113
 
 
114
 
 
115
 
 
116
 
static struct option options[] =
117
 
  {
118
 
    {"root-device", required_argument, 0, 'r'},
119
 
    {"device-map", required_argument, 0, 'm'},
120
 
    {"directory", required_argument, 0, 'd'},
121
 
    {"hold", optional_argument, 0, 'H'},
122
 
    {"help", no_argument, 0, 'h'},
123
 
    {"version", no_argument, 0, 'V'},
124
 
    {"verbose", no_argument, 0, 'v'},
125
 
    { 0, 0, 0, 0 }
126
 
  };
127
 
 
128
 
static int
129
 
usage (int status)
130
 
{
131
 
  if (status)
132
 
    fprintf (stderr,
133
 
             "Try `%s --help' for more information.\n", program_name);
134
 
  else
135
 
    printf (
136
 
      "Usage: %s [OPTION]...\n"
137
 
      "\n"
138
 
      "GRUB emulator.\n"
139
 
      "\n"
140
 
      "  -r, --root-device=DEV     use DEV as the root device [default=guessed]\n"
141
 
      "  -m, --device-map=FILE     use FILE as the device map [default=%s]\n"
142
 
      "  -d, --directory=DIR       use GRUB files in the directory DIR [default=%s]\n"
143
 
      "  -v, --verbose             print verbose messages\n"
144
 
      "  -H, --hold[=SECONDS]      wait until a debugger will attach\n"
145
 
      "  -h, --help                display this message and exit\n"
146
 
      "  -V, --version             print version information and exit\n"
147
 
      "\n"
148
 
      "Report bugs to <%s>.\n", program_name, DEFAULT_DEVICE_MAP, DEFAULT_DIRECTORY, PACKAGE_BUGREPORT);
149
 
  return status;
150
 
}
151
 
 
152
 
 
153
 
void grub_hostfs_init (void);
154
 
void grub_hostfs_fini (void);
155
 
void grub_host_init (void);
156
 
void grub_host_fini (void);
157
 
#if GRUB_NO_MODULES
158
 
void grub_init_all (void);
159
 
void grub_fini_all (void);
160
 
#endif
161
 
 
162
 
int
163
 
main (int argc, char *argv[])
164
 
{
165
 
  char *root_dev = 0;
166
 
  char *dir = DEFAULT_DIRECTORY;
167
 
  char *dev_map = DEFAULT_DEVICE_MAP;
168
 
  volatile int hold = 0;
169
 
  int opt;
170
 
 
171
 
  set_program_name (argv[0]);
172
 
 
173
 
  while ((opt = getopt_long (argc, argv, "r:d:m:vH:hV", options, 0)) != -1)
174
 
    switch (opt)
175
 
      {
176
 
      case 'r':
177
 
        root_dev = optarg;
178
 
        break;
179
 
      case 'd':
180
 
        dir = optarg;
181
 
        break;
182
 
      case 'm':
183
 
        dev_map = optarg;
184
 
        break;
185
 
      case 'v':
186
 
        verbosity++;
187
 
        break;
188
 
      case 'H':
189
 
        hold = (optarg ? atoi (optarg) : -1);
190
 
        break;
191
 
      case 'h':
192
 
        return usage (0);
193
 
      case 'V':
194
 
        printf ("%s (%s) %s\n", program_name, PACKAGE_NAME, PACKAGE_VERSION);
195
 
        return 0;
196
 
      default:
197
 
        return usage (1);
198
 
      }
199
 
 
200
 
  if (optind < argc)
201
 
    {
202
 
      fprintf (stderr, "Unknown extra argument `%s'.\n", argv[optind]);
203
 
      return usage (1);
204
 
    }
205
 
 
206
 
  /* Wait until the ARGS.HOLD variable is cleared by an attached debugger. */
207
 
  if (hold && verbosity > 0)
208
 
    printf ("Run \"gdb %s %d\", and set ARGS.HOLD to zero.\n",
209
 
            program_name, (int) getpid ());
210
 
  while (hold)
211
 
    {
212
 
      if (hold > 0)
213
 
        hold--;
214
 
 
215
 
      sleep (1);
216
 
    }
217
 
 
218
 
  signal (SIGINT, SIG_IGN);
219
 
  grub_console_init ();
220
 
  grub_host_init ();
221
 
  grub_hostfs_init ();
222
 
 
223
 
  /* XXX: This is a bit unportable.  */
224
 
  grub_util_biosdisk_init (dev_map);
225
 
 
226
 
#if GRUB_NO_MODULES
227
 
  grub_init_all ();
228
 
#endif
229
 
 
230
 
  /* Make sure that there is a root device.  */
231
 
  if (! root_dev)
232
 
    {
233
 
      char *device_name = grub_guess_root_device (dir);
234
 
      if (! device_name)
235
 
        grub_util_error ("cannot find a device for %s", dir);
236
 
 
237
 
      root_dev = grub_util_get_grub_dev (device_name);
238
 
      if (! root_dev)
239
 
        {
240
 
          grub_util_info ("guessing the root device failed, because of `%s'",
241
 
                          grub_errmsg);
242
 
          grub_util_error ("cannot guess the root device. Specify the option `--root-device'");
243
 
        }
244
 
    }
245
 
 
246
 
  if (strcmp (root_dev, "host") == 0)
247
 
    dir = xstrdup (dir);
248
 
  else
249
 
    dir = grub_make_system_path_relative_to_its_root (dir);
250
 
  prefix = xmalloc (strlen (root_dev) + 2 + strlen (dir) + 1);
251
 
  sprintf (prefix, "(%s)%s", root_dev, dir);
252
 
  free (dir);
253
 
 
254
 
  /* Start GRUB!  */
255
 
  if (setjmp (main_env) == 0)
256
 
    grub_main ();
257
 
 
258
 
#if GRUB_NO_MODULES
259
 
  grub_fini_all ();
260
 
#endif
261
 
  grub_hostfs_fini ();
262
 
  grub_host_fini ();
263
 
 
264
 
  grub_machine_fini ();
265
 
 
266
 
  return 0;
267
 
}
268
 
 
269
 
#ifdef __MINGW32__
270
 
 
271
 
void
272
 
grub_millisleep (grub_uint32_t ms)
273
 
{
274
 
  Sleep (ms);
275
 
}
276
 
 
277
 
#else
278
 
 
279
 
void
280
 
grub_millisleep (grub_uint32_t ms)
281
 
{
282
 
  struct timespec ts;
283
 
 
284
 
  ts.tv_sec = ms / 1000;
285
 
  ts.tv_nsec = (ms % 1000) * 1000000;
286
 
  nanosleep (&ts, NULL);
287
 
}
288
 
 
289
 
#endif
290
 
 
291
 
#if GRUB_NO_MODULES
292
 
void
293
 
grub_register_exported_symbols (void)
294
 
{
295
 
}
296
 
#endif