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

« back to all changes in this revision

Viewing changes to grub-core/efiemu/loadcore_common.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
/* Load runtime image of EFIemu. Functions common to 32/64-bit mode */
 
2
/*
 
3
 *  GRUB  --  GRand Unified Bootloader
 
4
 *  Copyright (C) 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/file.h>
 
21
#include <grub/err.h>
 
22
#include <grub/mm.h>
 
23
#include <grub/misc.h>
 
24
#include <grub/efiemu/efiemu.h>
 
25
#include <grub/cpu/efiemu.h>
 
26
 
 
27
/* Are we in 32 or 64-bit mode?*/
 
28
static grub_efiemu_mode_t grub_efiemu_mode = GRUB_EFIEMU_NOTLOADED;
 
29
/* Runtime ELF file */
 
30
static grub_ssize_t efiemu_core_size;
 
31
static void *efiemu_core = 0;
 
32
/* Linked list of segments */
 
33
static grub_efiemu_segment_t efiemu_segments = 0;
 
34
 
 
35
/* equivalent to sizeof (grub_efi_uintn_t) but taking the mode into account*/
 
36
int
 
37
grub_efiemu_sizeof_uintn_t (void)
 
38
{
 
39
  if (grub_efiemu_mode == GRUB_EFIEMU32)
 
40
    return 4;
 
41
  if (grub_efiemu_mode == GRUB_EFIEMU64)
 
42
    return 8;
 
43
  return 0;
 
44
}
 
45
 
 
46
/* Check the header and set mode */
 
47
static grub_err_t
 
48
grub_efiemu_check_header (void *ehdr, grub_size_t size,
 
49
                          grub_efiemu_mode_t *mode)
 
50
{
 
51
  /* Check the magic numbers.  */
 
52
  if ((*mode == GRUB_EFIEMU_NOTLOADED || *mode == GRUB_EFIEMU32)
 
53
      && grub_efiemu_check_header32 (ehdr,size))
 
54
    {
 
55
      *mode = GRUB_EFIEMU32;
 
56
      return GRUB_ERR_NONE;
 
57
    }
 
58
  if ((*mode == GRUB_EFIEMU_NOTLOADED || *mode == GRUB_EFIEMU64)
 
59
      && grub_efiemu_check_header64 (ehdr,size))
 
60
    {
 
61
      *mode = GRUB_EFIEMU64;
 
62
      return GRUB_ERR_NONE;
 
63
    }
 
64
  return grub_error (GRUB_ERR_BAD_OS, "invalid ELF magic");
 
65
}
 
66
 
 
67
/* Unload segments */
 
68
static int
 
69
grub_efiemu_unload_segs (grub_efiemu_segment_t seg)
 
70
{
 
71
  grub_efiemu_segment_t segn;
 
72
  for (; seg; seg = segn)
 
73
    {
 
74
      segn = seg->next;
 
75
      grub_efiemu_mm_return_request (seg->handle);
 
76
      grub_free (seg);
 
77
    }
 
78
  return 1;
 
79
}
 
80
 
 
81
 
 
82
grub_err_t
 
83
grub_efiemu_loadcore_unload(void)
 
84
{
 
85
  switch (grub_efiemu_mode)
 
86
    {
 
87
    case GRUB_EFIEMU32:
 
88
      grub_efiemu_loadcore_unload32 ();
 
89
      break;
 
90
 
 
91
    case GRUB_EFIEMU64:
 
92
      grub_efiemu_loadcore_unload64 ();
 
93
      break;
 
94
 
 
95
    default:
 
96
      break;
 
97
    }
 
98
 
 
99
  grub_efiemu_mode = GRUB_EFIEMU_NOTLOADED;
 
100
 
 
101
  grub_free (efiemu_core);
 
102
  efiemu_core = 0;
 
103
 
 
104
  grub_efiemu_unload_segs (efiemu_segments);
 
105
  efiemu_segments = 0;
 
106
 
 
107
  grub_efiemu_free_syms ();
 
108
 
 
109
  return GRUB_ERR_NONE;
 
110
}
 
111
 
 
112
/* Load runtime file and do some initial preparations */
 
113
grub_err_t
 
114
grub_efiemu_loadcore_init (grub_file_t file)
 
115
{
 
116
  grub_err_t err;
 
117
 
 
118
  efiemu_core_size = grub_file_size (file);
 
119
  efiemu_core = 0;
 
120
  efiemu_core = grub_malloc (efiemu_core_size);
 
121
  if (! efiemu_core)
 
122
    return grub_errno;
 
123
 
 
124
  if (grub_file_read (file, efiemu_core, efiemu_core_size)
 
125
      != (int) efiemu_core_size)
 
126
    {
 
127
      grub_free (efiemu_core);
 
128
      efiemu_core = 0;
 
129
      return grub_errno;
 
130
    }
 
131
 
 
132
  if (grub_efiemu_check_header (efiemu_core, efiemu_core_size,
 
133
                                &grub_efiemu_mode))
 
134
    {
 
135
      grub_free (efiemu_core);
 
136
      efiemu_core = 0;
 
137
      return GRUB_ERR_BAD_MODULE;
 
138
    }
 
139
 
 
140
  switch (grub_efiemu_mode)
 
141
    {
 
142
    case GRUB_EFIEMU32:
 
143
      if ((err = grub_efiemu_loadcore_init32 (efiemu_core, efiemu_core_size,
 
144
                                              &efiemu_segments)))
 
145
        {
 
146
          grub_free (efiemu_core);
 
147
          efiemu_core = 0;
 
148
          grub_efiemu_mode = GRUB_EFIEMU_NOTLOADED;
 
149
          return err;
 
150
        }
 
151
      break;
 
152
 
 
153
    case GRUB_EFIEMU64:
 
154
      if ((err = grub_efiemu_loadcore_init64 (efiemu_core, efiemu_core_size,
 
155
                                              &efiemu_segments)))
 
156
        {
 
157
          grub_free (efiemu_core);
 
158
          efiemu_core = 0;
 
159
          grub_efiemu_mode = GRUB_EFIEMU_NOTLOADED;
 
160
          return err;
 
161
        }
 
162
      break;
 
163
 
 
164
    default:
 
165
      return grub_error (GRUB_ERR_BAD_OS, "unknown EFI runtime");
 
166
    }
 
167
  return GRUB_ERR_NONE;
 
168
}
 
169
 
 
170
grub_err_t
 
171
grub_efiemu_loadcore_load (void)
 
172
{
 
173
  grub_err_t err;
 
174
  switch (grub_efiemu_mode)
 
175
    {
 
176
    case GRUB_EFIEMU32:
 
177
      if ((err = grub_efiemu_loadcore_load32 (efiemu_core, efiemu_core_size,
 
178
                                              efiemu_segments)))
 
179
          grub_efiemu_loadcore_unload ();
 
180
      return err;
 
181
    case GRUB_EFIEMU64:
 
182
      if ((err = grub_efiemu_loadcore_load64 (efiemu_core, efiemu_core_size,
 
183
                                              efiemu_segments)))
 
184
          grub_efiemu_loadcore_unload ();
 
185
      return err;
 
186
    default:
 
187
      return grub_error (GRUB_ERR_BAD_OS, "unknown EFI runtime");
 
188
    }
 
189
}