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

« back to all changes in this revision

Viewing changes to disk/ieee1275/ofdisk.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
 
/* ofdisk.c - Open Firmware disk access.  */
2
 
/*
3
 
 *  GRUB  --  GRand Unified Bootloader
4
 
 *  Copyright (C) 2004,2006,2007,2008,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/misc.h>
21
 
#include <grub/disk.h>
22
 
#include <grub/mm.h>
23
 
#include <grub/ieee1275/ieee1275.h>
24
 
#include <grub/ieee1275/ofdisk.h>
25
 
 
26
 
struct ofdisk_hash_ent
27
 
{
28
 
  char *devpath;
29
 
  struct ofdisk_hash_ent *next;
30
 
};
31
 
 
32
 
#define OFDISK_HASH_SZ  8
33
 
static struct ofdisk_hash_ent *ofdisk_hash[OFDISK_HASH_SZ];
34
 
 
35
 
static int
36
 
ofdisk_hash_fn (const char *devpath)
37
 
{
38
 
  int hash = 0;
39
 
  while (*devpath)
40
 
    hash ^= *devpath++;
41
 
  return (hash & (OFDISK_HASH_SZ - 1));
42
 
}
43
 
 
44
 
static struct ofdisk_hash_ent *
45
 
ofdisk_hash_find (const char *devpath)
46
 
{
47
 
  struct ofdisk_hash_ent *p = ofdisk_hash[ofdisk_hash_fn(devpath)];
48
 
 
49
 
  while (p)
50
 
    {
51
 
      if (!grub_strcmp (p->devpath, devpath))
52
 
        break;
53
 
      p = p->next;
54
 
    }
55
 
  return p;
56
 
}
57
 
 
58
 
static struct ofdisk_hash_ent *
59
 
ofdisk_hash_add (char *devpath)
60
 
{
61
 
  struct ofdisk_hash_ent **head = &ofdisk_hash[ofdisk_hash_fn(devpath)];
62
 
  struct ofdisk_hash_ent *p = grub_malloc(sizeof (*p));
63
 
 
64
 
  if (p)
65
 
    {
66
 
      p->devpath = devpath;
67
 
      p->next = *head;
68
 
      *head = p;
69
 
    }
70
 
  return p;
71
 
}
72
 
 
73
 
static int
74
 
grub_ofdisk_iterate (int (*hook) (const char *name))
75
 
{
76
 
  auto int dev_iterate (struct grub_ieee1275_devalias *alias);
77
 
 
78
 
  int dev_iterate (struct grub_ieee1275_devalias *alias)
79
 
    {
80
 
      int ret = 0;
81
 
 
82
 
      grub_dprintf ("disk", "disk name = %s\n", alias->name);
83
 
 
84
 
      if (grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_OFDISK_SDCARD_ONLY))
85
 
        {
86
 
          grub_ieee1275_phandle_t dev;
87
 
          char tmp[8];
88
 
 
89
 
          if (grub_ieee1275_finddevice (alias->path, &dev))
90
 
            {
91
 
              grub_dprintf ("disk", "finddevice (%s) failed\n", alias->path);
92
 
              return 0;
93
 
            }
94
 
 
95
 
          if (grub_ieee1275_get_property (dev, "iconname", tmp,
96
 
                                          sizeof tmp, 0))
97
 
            {
98
 
              grub_dprintf ("disk", "get iconname failed\n");
99
 
              return 0;
100
 
            }
101
 
 
102
 
          if (grub_strcmp (tmp, "sdmmc"))
103
 
            {
104
 
              grub_dprintf ("disk", "device is not an SD card\n");
105
 
              return 0;
106
 
            }
107
 
        }
108
 
 
109
 
      if (! grub_strcmp (alias->type, "block") &&
110
 
          grub_strncmp (alias->name, "cdrom", 5))
111
 
        ret = hook (alias->name);
112
 
      return ret;
113
 
    }
114
 
 
115
 
  return grub_devalias_iterate (dev_iterate);
116
 
}
117
 
 
118
 
static char *
119
 
compute_dev_path (const char *name)
120
 
{
121
 
  char *devpath = grub_malloc (grub_strlen (name) + 3);
122
 
  char *p, c;
123
 
 
124
 
  if (!devpath)
125
 
    return NULL;
126
 
 
127
 
  /* Un-escape commas. */
128
 
  p = devpath;
129
 
  while ((c = *name++) != '\0')
130
 
    {
131
 
      if (c == '\\' && *name == ',')
132
 
        {
133
 
          *p++ = ',';
134
 
          name++;
135
 
        }
136
 
      else
137
 
        *p++ = c;
138
 
    }
139
 
 
140
 
  if (! grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_NO_PARTITION_0))
141
 
    {
142
 
      *p++ = ':';
143
 
      *p++ = '0';
144
 
    }
145
 
  *p++ = '\0';
146
 
 
147
 
  return devpath;
148
 
}
149
 
 
150
 
static grub_err_t
151
 
grub_ofdisk_open (const char *name, grub_disk_t disk)
152
 
{
153
 
  grub_ieee1275_phandle_t dev;
154
 
  grub_ieee1275_ihandle_t dev_ihandle = 0;
155
 
  struct ofdisk_hash_ent *op;
156
 
  char *devpath;
157
 
  /* XXX: This should be large enough for any possible case.  */
158
 
  char prop[64];
159
 
  grub_ssize_t actual;
160
 
 
161
 
  devpath = compute_dev_path (name);
162
 
  if (! devpath)
163
 
    return grub_errno;
164
 
 
165
 
  op = ofdisk_hash_find (devpath);
166
 
  if (!op)
167
 
    op = ofdisk_hash_add (devpath);
168
 
 
169
 
  grub_free (devpath);
170
 
  if (!op)
171
 
    return grub_errno;
172
 
 
173
 
  grub_dprintf ("disk", "Opening `%s'.\n", op->devpath);
174
 
 
175
 
  if (grub_ieee1275_finddevice (op->devpath, &dev))
176
 
    {
177
 
      grub_error (GRUB_ERR_UNKNOWN_DEVICE, "can't read device properties");
178
 
      goto fail;
179
 
    }
180
 
 
181
 
  if (grub_ieee1275_get_property (dev, "device_type", prop, sizeof (prop),
182
 
                                  &actual))
183
 
    {
184
 
      grub_error (GRUB_ERR_UNKNOWN_DEVICE, "can't read the device type");
185
 
      goto fail;
186
 
    }
187
 
 
188
 
  if (grub_strcmp (prop, "block"))
189
 
    {
190
 
      grub_error (GRUB_ERR_BAD_DEVICE, "not a block device");
191
 
      goto fail;
192
 
    }
193
 
 
194
 
  grub_ieee1275_open (op->devpath, &dev_ihandle);
195
 
  if (! dev_ihandle)
196
 
    {
197
 
      grub_error (GRUB_ERR_UNKNOWN_DEVICE, "can't open device");
198
 
      goto fail;
199
 
    }
200
 
 
201
 
  grub_dprintf ("disk", "Opened `%s' as handle %p.\n", op->devpath,
202
 
                (void *) (unsigned long) dev_ihandle);
203
 
 
204
 
  /* XXX: There is no property to read the number of blocks.  There
205
 
     should be a property `#blocks', but it is not there.  Perhaps it
206
 
     is possible to use seek for this.  */
207
 
  disk->total_sectors = GRUB_DISK_SIZE_UNKNOWN;
208
 
 
209
 
  disk->id = (unsigned long) op;
210
 
 
211
 
  /* XXX: Read this, somehow.  */
212
 
  disk->has_partitions = 1;
213
 
  disk->data = (void *) (unsigned long) dev_ihandle;
214
 
  return 0;
215
 
 
216
 
 fail:
217
 
  if (dev_ihandle)
218
 
    grub_ieee1275_close (dev_ihandle);
219
 
  return grub_errno;
220
 
}
221
 
 
222
 
static void
223
 
grub_ofdisk_close (grub_disk_t disk)
224
 
{
225
 
  grub_dprintf ("disk", "Closing handle %p.\n",
226
 
                (void *) disk->data);
227
 
  grub_ieee1275_close ((grub_ieee1275_ihandle_t) (unsigned long) disk->data);
228
 
}
229
 
 
230
 
static grub_err_t
231
 
grub_ofdisk_read (grub_disk_t disk, grub_disk_addr_t sector,
232
 
                  grub_size_t size, char *buf)
233
 
{
234
 
  grub_ssize_t status, actual;
235
 
  unsigned long long pos;
236
 
 
237
 
  pos = sector * 512UL;
238
 
 
239
 
  grub_ieee1275_seek ((grub_ieee1275_ihandle_t) (unsigned long) disk->data,
240
 
                      pos, &status);
241
 
  if (status < 0)
242
 
    return grub_error (GRUB_ERR_READ_ERROR,
243
 
                       "seek error, can't seek block %llu",
244
 
                       (long long) sector);
245
 
  grub_ieee1275_read ((grub_ieee1275_ihandle_t) (unsigned long) disk->data,
246
 
                      buf, size * 512UL, &actual);
247
 
  if (actual != (grub_ssize_t) (size * 512UL))
248
 
    return grub_error (GRUB_ERR_READ_ERROR, "read error on block: %llu",
249
 
                       (long long) sector);
250
 
 
251
 
  return 0;
252
 
}
253
 
 
254
 
static grub_err_t
255
 
grub_ofdisk_write (grub_disk_t disk __attribute ((unused)),
256
 
                   grub_disk_addr_t sector __attribute ((unused)),
257
 
                   grub_size_t size __attribute ((unused)),
258
 
                   const char *buf __attribute ((unused)))
259
 
{
260
 
  return GRUB_ERR_NOT_IMPLEMENTED_YET;
261
 
}
262
 
 
263
 
static struct grub_disk_dev grub_ofdisk_dev =
264
 
  {
265
 
    .name = "ofdisk",
266
 
    .id = GRUB_DISK_DEVICE_OFDISK_ID,
267
 
    .iterate = grub_ofdisk_iterate,
268
 
    .open = grub_ofdisk_open,
269
 
    .close = grub_ofdisk_close,
270
 
    .read = grub_ofdisk_read,
271
 
    .write = grub_ofdisk_write,
272
 
    .next = 0
273
 
  };
274
 
 
275
 
void
276
 
grub_ofdisk_init (void)
277
 
{
278
 
  grub_disk_dev_register (&grub_ofdisk_dev);
279
 
}
280
 
 
281
 
void
282
 
grub_ofdisk_fini (void)
283
 
{
284
 
  grub_disk_dev_unregister (&grub_ofdisk_dev);
285
 
}