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

« back to all changes in this revision

Viewing changes to grub-core/kern/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
/* main.c - the kernel main routine */
 
2
/*
 
3
 *  GRUB  --  GRand Unified Bootloader
 
4
 *  Copyright (C) 2002,2003,2005,2006,2008,2009  Free Software Foundation, Inc.
 
5
 *
 
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.
 
10
 *
 
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.
 
15
 *
 
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/>.
 
18
 */
 
19
 
 
20
#include <grub/kernel.h>
 
21
#include <grub/misc.h>
 
22
#include <grub/symbol.h>
 
23
#include <grub/dl.h>
 
24
#include <grub/term.h>
 
25
#include <grub/file.h>
 
26
#include <grub/device.h>
 
27
#include <grub/env.h>
 
28
#include <grub/mm.h>
 
29
#include <grub/command.h>
 
30
#include <grub/reader.h>
 
31
#include <grub/parser.h>
 
32
 
 
33
void
 
34
grub_module_iterate (int (*hook) (struct grub_module_header *header))
 
35
{
 
36
  struct grub_module_info *modinfo;
 
37
  struct grub_module_header *header;
 
38
  grub_addr_t modbase;
 
39
 
 
40
  modbase = grub_arch_modules_addr ();
 
41
  modinfo = (struct grub_module_info *) modbase;
 
42
 
 
43
  /* Check if there are any modules.  */
 
44
  if ((modinfo == 0) || modinfo->magic != GRUB_MODULE_MAGIC)
 
45
    return;
 
46
 
 
47
  for (header = (struct grub_module_header *) (modbase + modinfo->offset);
 
48
       header < (struct grub_module_header *) (modbase + modinfo->size);
 
49
       header = (struct grub_module_header *) ((char *) header + header->size))
 
50
    {
 
51
      if (hook (header))
 
52
        break;
 
53
    }
 
54
}
 
55
 
 
56
/* This is actualy platform-independant but used only on yeeloong and sparc.  */
 
57
#if defined (GRUB_MACHINE_MIPS_YEELOONG) || defined (GRUB_MACHINE_SPARC64)
 
58
grub_addr_t
 
59
grub_modules_get_end (void)
 
60
{
 
61
  struct grub_module_info *modinfo;
 
62
  grub_addr_t modbase;
 
63
 
 
64
  modbase = grub_arch_modules_addr ();
 
65
  modinfo = (struct grub_module_info *) modbase;
 
66
 
 
67
  /* Check if there are any modules.  */
 
68
  if ((modinfo == 0) || modinfo->magic != GRUB_MODULE_MAGIC)
 
69
    return modbase;
 
70
 
 
71
  return modbase + modinfo->size;
 
72
}
 
73
#endif
 
74
 
 
75
/* Load all modules in core.  */
 
76
static void
 
77
grub_load_modules (void)
 
78
{
 
79
  auto int hook (struct grub_module_header *);
 
80
  int hook (struct grub_module_header *header)
 
81
    {
 
82
      /* Not an ELF module, skip.  */
 
83
      if (header->type != OBJ_TYPE_ELF)
 
84
        return 0;
 
85
 
 
86
      if (! grub_dl_load_core ((char *) header + sizeof (struct grub_module_header),
 
87
                               (header->size - sizeof (struct grub_module_header))))
 
88
        grub_fatal ("%s", grub_errmsg);
 
89
 
 
90
      if (grub_errno)
 
91
        grub_print_error ();
 
92
 
 
93
      return 0;
 
94
    }
 
95
 
 
96
  grub_module_iterate (hook);
 
97
}
 
98
 
 
99
static void
 
100
grub_load_config (void)
 
101
{
 
102
  auto int hook (struct grub_module_header *);
 
103
  int hook (struct grub_module_header *header)
 
104
    {
 
105
      /* Not an embedded config, skip.  */
 
106
      if (header->type != OBJ_TYPE_CONFIG)
 
107
        return 0;
 
108
 
 
109
      grub_parser_execute ((char *) header +
 
110
                           sizeof (struct grub_module_header));
 
111
      return 1;
 
112
    }
 
113
 
 
114
  grub_module_iterate (hook);
 
115
}
 
116
 
 
117
/* Write hook for the environment variables of root. Remove surrounding
 
118
   parentheses, if any.  */
 
119
static char *
 
120
grub_env_write_root (struct grub_env_var *var __attribute__ ((unused)),
 
121
                     const char *val)
 
122
{
 
123
  /* XXX Is it better to check the existence of the device?  */
 
124
  grub_size_t len = grub_strlen (val);
 
125
 
 
126
  if (val[0] == '(' && val[len - 1] == ')')
 
127
    return grub_strndup (val + 1, len - 2);
 
128
 
 
129
  return grub_strdup (val);
 
130
}
 
131
 
 
132
/* Set the root device according to the dl prefix.  */
 
133
static void
 
134
grub_set_root_dev (void)
 
135
{
 
136
  const char *prefix;
 
137
 
 
138
  grub_register_variable_hook ("root", 0, grub_env_write_root);
 
139
 
 
140
  prefix = grub_env_get ("prefix");
 
141
 
 
142
  if (prefix)
 
143
    {
 
144
      char *dev;
 
145
 
 
146
      dev = grub_file_get_device_name (prefix);
 
147
      if (dev)
 
148
        {
 
149
          grub_env_set ("root", dev);
 
150
          grub_free (dev);
 
151
        }
 
152
    }
 
153
}
 
154
 
 
155
/* Load the normal mode module and execute the normal mode if possible.  */
 
156
static void
 
157
grub_load_normal_mode (void)
 
158
{
 
159
  /* Load the module.  */
 
160
  grub_dl_load ("normal");
 
161
 
 
162
  /* Something went wrong.  Print errors here to let user know why we're entering rescue mode.  */
 
163
  grub_print_error ();
 
164
  grub_errno = 0;
 
165
 
 
166
  grub_command_execute ("normal", 0, 0);
 
167
}
 
168
 
 
169
/* The main routine.  */
 
170
void
 
171
grub_main (void)
 
172
{
 
173
  /* First of all, initialize the machine.  */
 
174
  grub_machine_init ();
 
175
 
 
176
  /* Hello.  */
 
177
  grub_setcolorstate (GRUB_TERM_COLOR_HIGHLIGHT);
 
178
  grub_printf ("Welcome to GRUB!\n\n");
 
179
  grub_setcolorstate (GRUB_TERM_COLOR_STANDARD);
 
180
 
 
181
  /* Load pre-loaded modules and free the space.  */
 
182
  grub_register_exported_symbols ();
 
183
#ifdef GRUB_LINKER_HAVE_INIT
 
184
  grub_arch_dl_init_linker ();
 
185
#endif  
 
186
  grub_load_modules ();
 
187
 
 
188
  /* It is better to set the root device as soon as possible,
 
189
     for convenience.  */
 
190
  grub_machine_set_prefix ();
 
191
  grub_set_root_dev ();
 
192
 
 
193
  grub_register_core_commands ();
 
194
 
 
195
  grub_load_config ();
 
196
  grub_load_normal_mode ();
 
197
  grub_rescue_run ();
 
198
}