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

« back to all changes in this revision

Viewing changes to commands/efi/loadbios.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
 
/* loadbios.c - command to load a bios dump  */
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/dl.h>
21
 
#include <grub/misc.h>
22
 
#include <grub/file.h>
23
 
#include <grub/efi/efi.h>
24
 
#include <grub/pci.h>
25
 
#include <grub/command.h>
26
 
#include <grub/i18n.h>
27
 
 
28
 
static grub_efi_guid_t acpi_guid = GRUB_EFI_ACPI_TABLE_GUID;
29
 
static grub_efi_guid_t acpi2_guid = GRUB_EFI_ACPI_20_TABLE_GUID;
30
 
static grub_efi_guid_t smbios_guid = GRUB_EFI_SMBIOS_TABLE_GUID;
31
 
 
32
 
#define EBDA_SEG_ADDR   0x40e
33
 
#define LOW_MEM_ADDR    0x413
34
 
#define FAKE_EBDA_SEG   0x9fc0
35
 
 
36
 
#define BLANK_MEM       0xffffffff
37
 
#define VBIOS_ADDR      0xc0000
38
 
#define SBIOS_ADDR      0xf0000
39
 
 
40
 
static int
41
 
enable_rom_area (void)
42
 
{
43
 
  grub_pci_address_t addr;
44
 
  grub_uint32_t *rom_ptr;
45
 
  grub_pci_device_t dev = { .bus = 0, .device = 0, .function = 0};
46
 
 
47
 
  rom_ptr = (grub_uint32_t *) VBIOS_ADDR;
48
 
  if (*rom_ptr != BLANK_MEM)
49
 
    {
50
 
      grub_printf ("ROM image is present.\n");
51
 
      return 0;
52
 
    }
53
 
 
54
 
  /* FIXME: should be macroified.  */
55
 
  addr = grub_pci_make_address (dev, 144);
56
 
  grub_pci_write_byte (addr++, 0x30);
57
 
  grub_pci_write_byte (addr++, 0x33);
58
 
  grub_pci_write_byte (addr++, 0x33);
59
 
  grub_pci_write_byte (addr++, 0x33);
60
 
  grub_pci_write_byte (addr++, 0x33);
61
 
  grub_pci_write_byte (addr++, 0x33);
62
 
  grub_pci_write_byte (addr++, 0x33);
63
 
  grub_pci_write_byte (addr, 0);
64
 
 
65
 
  *rom_ptr = 0;
66
 
  if (*rom_ptr != 0)
67
 
    {
68
 
      grub_printf ("Can\'t enable ROM area.\n");
69
 
      return 0;
70
 
    }
71
 
 
72
 
  return 1;
73
 
}
74
 
 
75
 
static void
76
 
lock_rom_area (void)
77
 
{
78
 
  grub_pci_address_t addr;
79
 
  grub_pci_device_t dev = { .bus = 0, .device = 0, .function = 0};
80
 
 
81
 
  /* FIXME: should be macroified.  */
82
 
  addr = grub_pci_make_address (dev, 144);
83
 
  grub_pci_write_byte (addr++, 0x10);
84
 
  grub_pci_write_byte (addr++, 0x11);
85
 
  grub_pci_write_byte (addr++, 0x11);
86
 
  grub_pci_write_byte (addr++, 0x11);
87
 
  grub_pci_write_byte (addr, 0x11);
88
 
}
89
 
 
90
 
static void
91
 
fake_bios_data (int use_rom)
92
 
{
93
 
  unsigned i;
94
 
  void *acpi, *smbios;
95
 
  grub_uint16_t *ebda_seg_ptr, *low_mem_ptr;
96
 
 
97
 
  ebda_seg_ptr = (grub_uint16_t *) EBDA_SEG_ADDR;
98
 
  low_mem_ptr = (grub_uint16_t *) LOW_MEM_ADDR;
99
 
  if ((*ebda_seg_ptr) || (*low_mem_ptr))
100
 
    return;
101
 
 
102
 
  acpi = 0;
103
 
  smbios = 0;
104
 
  for (i = 0; i < grub_efi_system_table->num_table_entries; i++)
105
 
    {
106
 
      grub_efi_guid_t *guid =
107
 
        &grub_efi_system_table->configuration_table[i].vendor_guid;
108
 
 
109
 
      if (! grub_memcmp (guid, &acpi2_guid, sizeof (grub_efi_guid_t)))
110
 
        {
111
 
          acpi = grub_efi_system_table->configuration_table[i].vendor_table;
112
 
          grub_dprintf ("efi", "ACPI2: %p\n", acpi);
113
 
        }
114
 
      else if (! grub_memcmp (guid, &acpi_guid, sizeof (grub_efi_guid_t)))
115
 
        {
116
 
          void *t;
117
 
 
118
 
          t = grub_efi_system_table->configuration_table[i].vendor_table;
119
 
          if (! acpi)
120
 
            acpi = t;
121
 
          grub_dprintf ("efi", "ACPI: %p\n", t);
122
 
        }
123
 
      else if (! grub_memcmp (guid, &smbios_guid, sizeof (grub_efi_guid_t)))
124
 
        {
125
 
          smbios = grub_efi_system_table->configuration_table[i].vendor_table;
126
 
          grub_dprintf ("efi", "SMBIOS: %p\n", smbios);
127
 
        }
128
 
    }
129
 
 
130
 
  *ebda_seg_ptr = FAKE_EBDA_SEG;
131
 
  *low_mem_ptr = (FAKE_EBDA_SEG >> 6);
132
 
 
133
 
  *((grub_uint16_t *) (FAKE_EBDA_SEG << 4)) = 640 - *low_mem_ptr;
134
 
 
135
 
  if (acpi)
136
 
    grub_memcpy ((char *) ((FAKE_EBDA_SEG << 4) + 16), acpi, 1024 - 16);
137
 
 
138
 
  if ((use_rom) && (smbios))
139
 
    grub_memcpy ((char *) SBIOS_ADDR, (char *) smbios + 16, 16);
140
 
}
141
 
 
142
 
static grub_err_t
143
 
grub_cmd_fakebios (struct grub_command *cmd __attribute__ ((unused)),
144
 
                   int argc __attribute__ ((unused)),
145
 
                   char *argv[] __attribute__ ((unused)))
146
 
{
147
 
  if (enable_rom_area ())
148
 
    {
149
 
      fake_bios_data (1);
150
 
      lock_rom_area ();
151
 
    }
152
 
  else
153
 
    fake_bios_data (0);
154
 
 
155
 
  return 0;
156
 
}
157
 
 
158
 
static grub_err_t
159
 
grub_cmd_loadbios (grub_command_t cmd __attribute__ ((unused)),
160
 
                   int argc, char *argv[])
161
 
{
162
 
  grub_file_t file;
163
 
  int size;
164
 
 
165
 
  if (argc == 0)
166
 
    return grub_error (GRUB_ERR_BAD_ARGUMENT, "no ROM image specified");
167
 
 
168
 
  if (argc > 1)
169
 
    {
170
 
      file = grub_file_open (argv[1]);
171
 
      if (! file)
172
 
        return grub_errno;
173
 
 
174
 
      if (file->size != 4)
175
 
        grub_error (GRUB_ERR_BAD_ARGUMENT, "invalid int10 dump size");
176
 
      else
177
 
        grub_file_read (file, (void *) 0x40, 4);
178
 
 
179
 
      grub_file_close (file);
180
 
      if (grub_errno)
181
 
        return grub_errno;
182
 
    }
183
 
 
184
 
  file = grub_file_open (argv[0]);
185
 
  if (! file)
186
 
    return grub_errno;
187
 
 
188
 
  size = file->size;
189
 
  if ((size < 0x10000) || (size > 0x40000))
190
 
    grub_error (GRUB_ERR_BAD_ARGUMENT, "invalid bios dump size");
191
 
  else if (enable_rom_area ())
192
 
    {
193
 
      grub_file_read (file, (void *) VBIOS_ADDR, size);
194
 
      fake_bios_data (size <= 0x40000);
195
 
      lock_rom_area ();
196
 
    }
197
 
 
198
 
  grub_file_close (file);
199
 
  return grub_errno;
200
 
}
201
 
 
202
 
static grub_command_t cmd_fakebios, cmd_loadbios;
203
 
 
204
 
GRUB_MOD_INIT(loadbios)
205
 
{
206
 
  cmd_fakebios = grub_register_command ("fakebios", grub_cmd_fakebios,
207
 
                                        0, N_("Fake BIOS."));
208
 
 
209
 
  cmd_loadbios = grub_register_command ("loadbios", grub_cmd_loadbios,
210
 
                                        "BIOS_DUMP [INT10_DUMP]",
211
 
                                        N_("Load BIOS dump."));
212
 
}
213
 
 
214
 
GRUB_MOD_FINI(loadbios)
215
 
{
216
 
  grub_unregister_command (cmd_fakebios);
217
 
  grub_unregister_command (cmd_loadbios);
218
 
}