~hamo/ubuntu/precise/grub2/grub2.hi_res

« back to all changes in this revision

Viewing changes to kern/i386/pc/init.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) 2002,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 <grub/kernel.h>
20
 
#include <grub/mm.h>
21
 
#include <grub/machine/boot.h>
22
 
#include <grub/machine/init.h>
23
 
#include <grub/machine/memory.h>
24
 
#include <grub/machine/console.h>
25
 
#include <grub/machine/kernel.h>
26
 
#include <grub/types.h>
27
 
#include <grub/err.h>
28
 
#include <grub/dl.h>
29
 
#include <grub/misc.h>
30
 
#include <grub/loader.h>
31
 
#include <grub/env.h>
32
 
#include <grub/cache.h>
33
 
#include <grub/time.h>
34
 
#include <grub/cpu/tsc.h>
35
 
 
36
 
struct mem_region
37
 
{
38
 
  grub_addr_t addr;
39
 
  grub_size_t size;
40
 
};
41
 
 
42
 
#define MAX_REGIONS     32
43
 
 
44
 
static struct mem_region mem_regions[MAX_REGIONS];
45
 
static int num_regions;
46
 
 
47
 
grub_addr_t grub_os_area_addr;
48
 
grub_size_t grub_os_area_size;
49
 
 
50
 
static char *
51
 
make_install_device (void)
52
 
{
53
 
  /* XXX: This should be enough.  */
54
 
  char dev[100], *ptr = dev;
55
 
 
56
 
  if (grub_prefix[0] != '(')
57
 
    {
58
 
      /* No hardcoded root partition - make it from the boot drive and the
59
 
         partition number encoded at the install time.  */
60
 
      if (grub_boot_drive == GRUB_BOOT_MACHINE_PXE_DL)
61
 
        {
62
 
          grub_strcpy (dev, "(pxe");
63
 
          ptr += sizeof ("(pxe") - 1;
64
 
        }
65
 
      else
66
 
        {
67
 
          grub_snprintf (dev, sizeof (dev),
68
 
                         "(%cd%u", (grub_boot_drive & 0x80) ? 'h' : 'f',
69
 
                         grub_boot_drive & 0x7f);
70
 
          ptr += grub_strlen (ptr);
71
 
 
72
 
          if (grub_install_dos_part >= 0)
73
 
            grub_snprintf (ptr, sizeof (dev) - (ptr - dev),
74
 
                           ",%u", grub_install_dos_part + 1);
75
 
          ptr += grub_strlen (ptr);
76
 
 
77
 
          if (grub_install_bsd_part >= 0)
78
 
            grub_snprintf (ptr, sizeof (dev) - (ptr - dev), ",%u",
79
 
                           grub_install_bsd_part + 1);
80
 
          ptr += grub_strlen (ptr);
81
 
        }
82
 
 
83
 
      grub_snprintf (ptr, sizeof (dev) - (ptr - dev), ")%s", grub_prefix);
84
 
      grub_strcpy (grub_prefix, dev);
85
 
    }
86
 
  else if (grub_prefix[1] == ',' || grub_prefix[1] == ')')
87
 
    {
88
 
      /* We have a prefix, but still need to fill in the boot drive.  */
89
 
      grub_snprintf (dev, sizeof (dev),
90
 
                     "(%cd%u%s", (grub_boot_drive & 0x80) ? 'h' : 'f',
91
 
                     grub_boot_drive & 0x7f, grub_prefix + 1);
92
 
      grub_strcpy (grub_prefix, dev);
93
 
    }
94
 
 
95
 
  return grub_prefix;
96
 
}
97
 
 
98
 
/* Add a memory region.  */
99
 
static void
100
 
add_mem_region (grub_addr_t addr, grub_size_t size)
101
 
{
102
 
  if (num_regions == MAX_REGIONS)
103
 
    /* Ignore.  */
104
 
    return;
105
 
 
106
 
  mem_regions[num_regions].addr = addr;
107
 
  mem_regions[num_regions].size = size;
108
 
  num_regions++;
109
 
}
110
 
 
111
 
/* Compact memory regions.  */
112
 
static void
113
 
compact_mem_regions (void)
114
 
{
115
 
  int i, j;
116
 
 
117
 
  /* Sort them.  */
118
 
  for (i = 0; i < num_regions - 1; i++)
119
 
    for (j = i + 1; j < num_regions; j++)
120
 
      if (mem_regions[i].addr > mem_regions[j].addr)
121
 
        {
122
 
          struct mem_region tmp = mem_regions[i];
123
 
          mem_regions[i] = mem_regions[j];
124
 
          mem_regions[j] = tmp;
125
 
        }
126
 
 
127
 
  /* Merge overlaps.  */
128
 
  for (i = 0; i < num_regions - 1; i++)
129
 
    if (mem_regions[i].addr + mem_regions[i].size >= mem_regions[i + 1].addr)
130
 
      {
131
 
        j = i + 1;
132
 
 
133
 
        if (mem_regions[i].addr + mem_regions[i].size
134
 
            < mem_regions[j].addr + mem_regions[j].size)
135
 
          mem_regions[i].size = (mem_regions[j].addr + mem_regions[j].size
136
 
                                 - mem_regions[i].addr);
137
 
 
138
 
        grub_memmove (mem_regions + j, mem_regions + j + 1,
139
 
                      (num_regions - j - 1) * sizeof (struct mem_region));
140
 
        i--;
141
 
        num_regions--;
142
 
      }
143
 
}
144
 
 
145
 
void
146
 
grub_machine_init (void)
147
 
{
148
 
  int i;
149
 
  int grub_lower_mem;
150
 
 
151
 
  /* Initialize the console as early as possible.  */
152
 
  grub_console_init ();
153
 
 
154
 
  grub_lower_mem = grub_get_memsize (0) << 10;
155
 
 
156
 
  /* Sanity check.  */
157
 
  if (grub_lower_mem < GRUB_MEMORY_MACHINE_RESERVED_END)
158
 
    grub_fatal ("too small memory");
159
 
 
160
 
#if 0
161
 
  /* Turn on Gate A20 to access >1MB.  */
162
 
  grub_gate_a20 (1);
163
 
#endif
164
 
 
165
 
/* FIXME: This prevents loader/i386/linux.c from using low memory.  When our
166
 
   heap implements support for requesting a chunk in low memory, this should
167
 
   no longer be a problem.  */
168
 
#if 0
169
 
  /* Add the lower memory into free memory.  */
170
 
  if (grub_lower_mem >= GRUB_MEMORY_MACHINE_RESERVED_END)
171
 
    add_mem_region (GRUB_MEMORY_MACHINE_RESERVED_END,
172
 
                    grub_lower_mem - GRUB_MEMORY_MACHINE_RESERVED_END);
173
 
#endif
174
 
 
175
 
  auto int NESTED_FUNC_ATTR hook (grub_uint64_t, grub_uint64_t, grub_uint32_t);
176
 
  int NESTED_FUNC_ATTR hook (grub_uint64_t addr, grub_uint64_t size, grub_uint32_t type)
177
 
    {
178
 
      /* Avoid the lower memory.  */
179
 
      if (addr < 0x100000)
180
 
        {
181
 
          if (size <= 0x100000 - addr)
182
 
            return 0;
183
 
 
184
 
          size -= 0x100000 - addr;
185
 
          addr = 0x100000;
186
 
        }
187
 
 
188
 
      /* Ignore >4GB.  */
189
 
      if (addr <= 0xFFFFFFFF && type == GRUB_MACHINE_MEMORY_AVAILABLE)
190
 
        {
191
 
          grub_size_t len;
192
 
 
193
 
          len = (grub_size_t) ((addr + size > 0xFFFFFFFF)
194
 
                 ? 0xFFFFFFFF - addr
195
 
                 : size);
196
 
          add_mem_region (addr, len);
197
 
        }
198
 
 
199
 
      return 0;
200
 
    }
201
 
 
202
 
  grub_machine_mmap_iterate (hook);
203
 
 
204
 
  compact_mem_regions ();
205
 
 
206
 
  /* Add the memory regions to free memory, except for the region starting
207
 
     from 1MB. This region is partially used for loading OS images.
208
 
     For now, 1/4 of this is added to free memory.  */
209
 
  for (i = 0; i < num_regions; i++)
210
 
    if (mem_regions[i].addr == 0x100000)
211
 
      {
212
 
        grub_size_t quarter = mem_regions[i].size >> 2;
213
 
 
214
 
        grub_os_area_addr = mem_regions[i].addr;
215
 
        grub_os_area_size = mem_regions[i].size - quarter;
216
 
        grub_mm_init_region ((void *) (grub_os_area_addr + grub_os_area_size),
217
 
                             quarter);
218
 
      }
219
 
    else
220
 
      grub_mm_init_region ((void *) mem_regions[i].addr, mem_regions[i].size);
221
 
 
222
 
  if (! grub_os_area_addr)
223
 
    grub_fatal ("no upper memory");
224
 
 
225
 
  grub_tsc_init ();
226
 
}
227
 
 
228
 
void
229
 
grub_machine_set_prefix (void)
230
 
{
231
 
  /* Initialize the prefix.  */
232
 
  grub_env_set ("prefix", make_install_device ());
233
 
}
234
 
 
235
 
void
236
 
grub_machine_fini (void)
237
 
{
238
 
  grub_console_fini ();
239
 
  grub_stop_floppy ();
240
 
}
241
 
 
242
 
/* Return the end of the core image.  */
243
 
grub_addr_t
244
 
grub_arch_modules_addr (void)
245
 
{
246
 
  return GRUB_MEMORY_MACHINE_DECOMPRESSION_ADDR
247
 
    + (grub_kernel_image_size - GRUB_KERNEL_MACHINE_RAW_SIZE);
248
 
}