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

« back to all changes in this revision

Viewing changes to grub-core/commands/efi/loadbios.c

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson, Colin Watson, Robert Millan, Updated translations
  • Date: 2010-11-22 12:24:56 UTC
  • mfrom: (1.26.4 upstream) (17.3.36 sid)
  • mto: (17.3.43 sid)
  • mto: This revision was merged to the branch mainline in revision 89.
  • Revision ID: james.westby@ubuntu.com-20101122122456-y82z3sfb7k4zfdcc
Tags: 1.99~20101122-1
[ Colin Watson ]
* New Bazaar snapshot.  Too many changes to list in full, but some of the
  more user-visible ones are as follows:
  - GRUB script:
    + Function parameters, "break", "continue", "shift", "setparams",
      "return", and "!".
    + "export" command supports multiple variable names.
    + Multi-line quoted strings support.
    + Wildcard expansion.
  - sendkey support.
  - USB hotunplugging and USB serial support.
  - Rename CD-ROM to cd on BIOS.
  - Add new --boot-directory option to grub-install, grub-reboot, and
    grub-set-default; the old --root-directory option is still accepted
    but was often confusing.
  - Basic btrfs detection/UUID support (but no file reading yet).
  - bash-completion for utilities.
  - If a device is listed in device.map, always assume that it is
    BIOS-visible rather than using extra layers such as LVM or RAID.
  - Add grub-mknetdir script (closes: #550658).
  - Remove deprecated "root" command.
  - Handle RAID devices containing virtio components.
  - GRUB Legacy configuration file support (via grub-menulst2cfg).
  - Keyboard layout support (via grub-mklayout and grub-kbdcomp).
  - Check generated grub.cfg for syntax errors before saving.
  - Pause execution for at most ten seconds if any errors are displayed,
    so that the user has a chance to see them.
  - Support submenus.
  - Write embedding zone using Reed-Solomon, so that it's robust against
    being partially overwritten (closes: #550702, #591416, #593347).
  - GRUB_DISABLE_LINUX_RECOVERY and GRUB_DISABLE_NETBSD_RECOVERY merged
    into a single GRUB_DISABLE_RECOVERY variable.
  - Fix loader memory allocation failure (closes: #551627).
  - Don't call savedefault on recovery entries (closes: #589325).
  - Support triple-indirect blocks on ext2 (closes: #543924).
  - Recognise DDF1 fake RAID (closes: #603354).

[ Robert Millan ]
* Use dpkg architecture wildcards.

[ Updated translations ]
* Slovenian (Vanja Cvelbar).  Closes: #604003
* Dzongkha (dawa pemo via Tenzin Dendup).  Closes: #604102

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
}