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

« back to all changes in this revision

Viewing changes to efiemu/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) 2009  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
 
/* This is an emulation of EFI runtime services.
20
 
   This allows a more uniform boot on i386 machines.
21
 
   As it emulates only runtime service it isn't able
22
 
   to chainload EFI bootloader on non-EFI system. */
23
 
 
24
 
 
25
 
#include <grub/file.h>
26
 
#include <grub/err.h>
27
 
#include <grub/normal.h>
28
 
#include <grub/mm.h>
29
 
#include <grub/dl.h>
30
 
#include <grub/misc.h>
31
 
#include <grub/efiemu/efiemu.h>
32
 
#include <grub/machine/efiemu.h>
33
 
#include <grub/command.h>
34
 
#include <grub/i18n.h>
35
 
 
36
 
/* System table. Two version depending on mode */
37
 
grub_efi_system_table32_t *grub_efiemu_system_table32 = 0;
38
 
grub_efi_system_table64_t *grub_efiemu_system_table64 = 0;
39
 
/* Modules may need to execute some actions after memory allocation happens */
40
 
static struct grub_efiemu_prepare_hook *efiemu_prepare_hooks = 0;
41
 
/* Linked list of configuration tables */
42
 
static struct grub_efiemu_configuration_table *efiemu_config_tables = 0;
43
 
static int prepared = 0;
44
 
 
45
 
/* Free all allocated space */
46
 
grub_err_t
47
 
grub_efiemu_unload (void)
48
 
{
49
 
  struct grub_efiemu_configuration_table *cur, *d;
50
 
  struct grub_efiemu_prepare_hook *curhook, *d2;
51
 
  grub_efiemu_loadcore_unload ();
52
 
 
53
 
  grub_efiemu_mm_unload ();
54
 
 
55
 
  for (cur = efiemu_config_tables; cur;)
56
 
    {
57
 
      d = cur->next;
58
 
      if (cur->unload)
59
 
        cur->unload (cur->data);
60
 
      grub_free (cur);
61
 
      cur = d;
62
 
    }
63
 
  efiemu_config_tables = 0;
64
 
 
65
 
  for (curhook = efiemu_prepare_hooks; curhook;)
66
 
    {
67
 
      d2 = curhook->next;
68
 
      if (curhook->unload)
69
 
        curhook->unload (curhook->data);
70
 
      grub_free (curhook);
71
 
      curhook = d2;
72
 
    }
73
 
  efiemu_prepare_hooks = 0;
74
 
 
75
 
  prepared = 0;
76
 
 
77
 
  return GRUB_ERR_NONE;
78
 
}
79
 
 
80
 
/* Remove previously registered table from the list */
81
 
grub_err_t
82
 
grub_efiemu_unregister_configuration_table (grub_efi_guid_t guid)
83
 
{
84
 
  struct grub_efiemu_configuration_table *cur, *prev;
85
 
 
86
 
  /* Special treating if head is to remove */
87
 
  while (efiemu_config_tables
88
 
         && !grub_memcmp (&(efiemu_config_tables->guid), &guid, sizeof (guid)))
89
 
    {
90
 
      if (efiemu_config_tables->unload)
91
 
          efiemu_config_tables->unload (efiemu_config_tables->data);
92
 
        cur = efiemu_config_tables->next;
93
 
        grub_free (efiemu_config_tables);
94
 
        efiemu_config_tables = cur;
95
 
    }
96
 
  if (!efiemu_config_tables)
97
 
    return GRUB_ERR_NONE;
98
 
 
99
 
  /* Remove from chain */
100
 
  for (prev = efiemu_config_tables, cur = prev->next; cur;)
101
 
    if (grub_memcmp (&(cur->guid), &guid, sizeof (guid)) == 0)
102
 
      {
103
 
        if (cur->unload)
104
 
          cur->unload (cur->data);
105
 
        prev->next = cur->next;
106
 
        grub_free (cur);
107
 
        cur = prev->next;
108
 
      }
109
 
    else
110
 
      {
111
 
        prev = cur;
112
 
        cur = cur->next;
113
 
      }
114
 
  return GRUB_ERR_NONE;
115
 
}
116
 
 
117
 
grub_err_t
118
 
grub_efiemu_register_prepare_hook (grub_err_t (*hook) (void *data),
119
 
                                   void (*unload) (void *data),
120
 
                                   void *data)
121
 
{
122
 
  struct grub_efiemu_prepare_hook *nhook;
123
 
  if (! hook)
124
 
    return grub_error (GRUB_ERR_BAD_ARGUMENT, "you must supply the hook");
125
 
  nhook = (struct grub_efiemu_prepare_hook *) grub_malloc (sizeof (*nhook));
126
 
  if (! nhook)
127
 
    return grub_error (GRUB_ERR_OUT_OF_MEMORY, "couldn't prepare hook");
128
 
  nhook->hook = hook;
129
 
  nhook->unload = unload;
130
 
  nhook->data = data;
131
 
  nhook->next = efiemu_prepare_hooks;
132
 
  efiemu_prepare_hooks = nhook;
133
 
  return GRUB_ERR_NONE;
134
 
}
135
 
 
136
 
/* Register a configuration table either supplying the address directly
137
 
   or with a hook
138
 
*/
139
 
grub_err_t
140
 
grub_efiemu_register_configuration_table (grub_efi_guid_t guid,
141
 
                                          void * (*get_table) (void *data),
142
 
                                          void (*unload) (void *data),
143
 
                                          void *data)
144
 
{
145
 
  struct grub_efiemu_configuration_table *tbl;
146
 
  grub_err_t err;
147
 
 
148
 
 if (! get_table && ! data)
149
 
    return grub_error (GRUB_ERR_BAD_ARGUMENT,
150
 
                       "you must set at least get_table or data");
151
 
  if ((err = grub_efiemu_unregister_configuration_table (guid)))
152
 
    return err;
153
 
 
154
 
  tbl = (struct grub_efiemu_configuration_table *) grub_malloc (sizeof (*tbl));
155
 
  if (! tbl)
156
 
    return grub_error (GRUB_ERR_OUT_OF_MEMORY, "couldn't register table");
157
 
 
158
 
  tbl->guid = guid;
159
 
  tbl->get_table = get_table;
160
 
  tbl->unload = unload;
161
 
  tbl->data = data;
162
 
  tbl->next = efiemu_config_tables;
163
 
  efiemu_config_tables = tbl;
164
 
 
165
 
  return GRUB_ERR_NONE;
166
 
}
167
 
 
168
 
static grub_err_t
169
 
grub_cmd_efiemu_unload (grub_command_t cmd __attribute__ ((unused)),
170
 
                        int argc __attribute__ ((unused)),
171
 
                        char *args[] __attribute__ ((unused)))
172
 
{
173
 
  return grub_efiemu_unload ();
174
 
}
175
 
 
176
 
static grub_err_t
177
 
grub_cmd_efiemu_prepare (grub_command_t cmd __attribute__ ((unused)),
178
 
                         int argc __attribute__ ((unused)),
179
 
                         char *args[] __attribute__ ((unused)))
180
 
{
181
 
  return grub_efiemu_prepare ();
182
 
}
183
 
 
184
 
 
185
 
 
186
 
 
187
 
int
188
 
grub_efiemu_exit_boot_services (grub_efi_uintn_t map_key
189
 
                                __attribute__ ((unused)))
190
 
{
191
 
  /* Nothing to do here yet */
192
 
  return 1;
193
 
}
194
 
 
195
 
int
196
 
grub_efiemu_finish_boot_services (void)
197
 
{
198
 
  /* Nothing to do here yet */
199
 
  return 1;
200
 
}
201
 
 
202
 
/* Load the runtime from the file FILENAME.  */
203
 
static grub_err_t
204
 
grub_efiemu_load_file (const char *filename)
205
 
{
206
 
  grub_file_t file;
207
 
  grub_err_t err;
208
 
 
209
 
  file = grub_file_open (filename);
210
 
  if (! file)
211
 
    return 0;
212
 
 
213
 
  err = grub_efiemu_mm_init ();
214
 
  if (err)
215
 
    {
216
 
      grub_file_close (file);
217
 
      grub_efiemu_unload ();
218
 
      return grub_error (grub_errno, "couldn't init memory management");
219
 
    }
220
 
 
221
 
  grub_dprintf ("efiemu", "mm initialized\n");
222
 
 
223
 
  err = grub_efiemu_loadcore_init (file);
224
 
  if (err)
225
 
    {
226
 
      grub_file_close (file);
227
 
      grub_efiemu_unload ();
228
 
      return err;
229
 
    }
230
 
 
231
 
  grub_file_close (file);
232
 
 
233
 
  /* For configuration tables entry in system table. */
234
 
  grub_efiemu_request_symbols (1);
235
 
 
236
 
  return GRUB_ERR_NONE;
237
 
}
238
 
 
239
 
grub_err_t
240
 
grub_efiemu_autocore (void)
241
 
{
242
 
  const char *prefix;
243
 
  char *filename;
244
 
  char *suffix;
245
 
  grub_err_t err;
246
 
 
247
 
  if (grub_efiemu_sizeof_uintn_t () != 0)
248
 
    return GRUB_ERR_NONE;
249
 
 
250
 
  prefix = grub_env_get ("prefix");
251
 
 
252
 
  if (! prefix)
253
 
    return grub_error (GRUB_ERR_FILE_NOT_FOUND,
254
 
                       "couldn't find efiemu core because prefix "
255
 
                       "isn't set");
256
 
 
257
 
  suffix = grub_efiemu_get_default_core_name ();
258
 
 
259
 
  filename = grub_xasprintf ("%s/%s", prefix, suffix);
260
 
  if (! filename)
261
 
    return grub_error (GRUB_ERR_OUT_OF_MEMORY,
262
 
                       "couldn't allocate temporary space");
263
 
 
264
 
 
265
 
  err = grub_efiemu_load_file (filename);
266
 
  grub_free (filename);
267
 
  if (err)
268
 
    return err;
269
 
#ifndef GRUB_MACHINE_EMU
270
 
  err = grub_machine_efiemu_init_tables ();
271
 
  if (err)
272
 
    return err;
273
 
#endif
274
 
 
275
 
  return GRUB_ERR_NONE;
276
 
}
277
 
 
278
 
grub_err_t
279
 
grub_efiemu_prepare (void)
280
 
{
281
 
  grub_err_t err;
282
 
 
283
 
  if (prepared)
284
 
    return GRUB_ERR_NONE;
285
 
 
286
 
  grub_dprintf ("efiemu", "Preparing %d-bit efiemu\n",
287
 
                8 * grub_efiemu_sizeof_uintn_t ());
288
 
 
289
 
  err = grub_efiemu_autocore ();
290
 
 
291
 
  /* Create NVRAM. */
292
 
  grub_efiemu_pnvram ();
293
 
 
294
 
  prepared = 1;
295
 
 
296
 
  if (grub_efiemu_sizeof_uintn_t () == 4)
297
 
    return grub_efiemu_prepare32 (efiemu_prepare_hooks, efiemu_config_tables);
298
 
  else
299
 
    return grub_efiemu_prepare64 (efiemu_prepare_hooks, efiemu_config_tables);
300
 
}
301
 
 
302
 
 
303
 
static grub_err_t
304
 
grub_cmd_efiemu_load (grub_command_t cmd __attribute__ ((unused)),
305
 
                      int argc, char *args[])
306
 
{
307
 
  grub_err_t err;
308
 
 
309
 
  grub_efiemu_unload ();
310
 
 
311
 
  if (argc != 1)
312
 
    return grub_error (GRUB_ERR_BAD_ARGUMENT, "filename required");
313
 
 
314
 
  err = grub_efiemu_load_file (args[0]);
315
 
  if (err)
316
 
    return err;
317
 
#ifndef GRUB_MACHINE_EMU
318
 
  err = grub_machine_efiemu_init_tables ();
319
 
  if (err)
320
 
    return err;
321
 
#endif
322
 
  return GRUB_ERR_NONE;
323
 
}
324
 
 
325
 
static grub_command_t cmd_loadcore, cmd_prepare, cmd_unload;
326
 
 
327
 
GRUB_MOD_INIT(efiemu)
328
 
{
329
 
  cmd_loadcore = grub_register_command ("efiemu_loadcore",
330
 
                                        grub_cmd_efiemu_load,
331
 
                                        N_("FILE"),
332
 
                                        N_("Load and initialize EFI emulator."));
333
 
  cmd_prepare = grub_register_command ("efiemu_prepare",
334
 
                                       grub_cmd_efiemu_prepare,
335
 
                                       0,
336
 
                                       N_("Finalize loading of EFI emulator."));
337
 
  cmd_unload = grub_register_command ("efiemu_unload", grub_cmd_efiemu_unload,
338
 
                                      0,
339
 
                                      N_("Unload EFI emulator."));
340
 
}
341
 
 
342
 
GRUB_MOD_FINI(efiemu)
343
 
{
344
 
  grub_unregister_command (cmd_loadcore);
345
 
  grub_unregister_command (cmd_prepare);
346
 
  grub_unregister_command (cmd_unload);
347
 
}