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

« back to all changes in this revision

Viewing changes to kern/ieee1275/openfw.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
 
/*  openfw.c -- Open firmware support functions.  */
2
 
/*
3
 
 *  GRUB  --  GRand Unified Bootloader
4
 
 *  Copyright (C) 2003,2004,2005,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/types.h>
21
 
#include <grub/err.h>
22
 
#include <grub/misc.h>
23
 
#include <grub/mm.h>
24
 
#include <grub/ieee1275/ieee1275.h>
25
 
 
26
 
enum grub_ieee1275_parse_type
27
 
{
28
 
  GRUB_PARSE_FILENAME,
29
 
  GRUB_PARSE_PARTITION,
30
 
};
31
 
 
32
 
/* Walk children of 'devpath', calling hook for each.  */
33
 
int
34
 
grub_children_iterate (char *devpath,
35
 
                       int (*hook) (struct grub_ieee1275_devalias *alias))
36
 
{
37
 
  grub_ieee1275_phandle_t dev;
38
 
  grub_ieee1275_phandle_t child;
39
 
  char *childtype, *childpath;
40
 
  char *childname;
41
 
  int ret = 0;
42
 
 
43
 
  if (grub_ieee1275_finddevice (devpath, &dev))
44
 
    return 0;
45
 
 
46
 
  if (grub_ieee1275_child (dev, &child))
47
 
    return 0;
48
 
 
49
 
  childtype = grub_malloc (IEEE1275_MAX_PROP_LEN);
50
 
  if (!childtype)
51
 
    return 0;
52
 
  childpath = grub_malloc (IEEE1275_MAX_PATH_LEN);
53
 
  if (!childpath)
54
 
    {
55
 
      grub_free (childtype);
56
 
      return 0;
57
 
    }
58
 
  childname = grub_malloc (IEEE1275_MAX_PROP_LEN);
59
 
  if (!childname)
60
 
    {
61
 
      grub_free (childpath);
62
 
      grub_free (childtype);
63
 
      return 0;
64
 
    }
65
 
 
66
 
  do
67
 
    {
68
 
      struct grub_ieee1275_devalias alias;
69
 
      grub_ssize_t actual;
70
 
 
71
 
      if (grub_ieee1275_get_property (child, "device_type", childtype,
72
 
                                      IEEE1275_MAX_PROP_LEN, &actual))
73
 
        childtype[0] = 0;
74
 
 
75
 
      if (dev == child)
76
 
        continue;
77
 
 
78
 
      if (grub_ieee1275_package_to_path (child, childpath,
79
 
                                         IEEE1275_MAX_PATH_LEN, &actual))
80
 
        continue;
81
 
 
82
 
      if (grub_strcmp (devpath, childpath) == 0)
83
 
        continue;
84
 
 
85
 
      if (grub_ieee1275_get_property (child, "name", childname,
86
 
                                      IEEE1275_MAX_PROP_LEN, &actual))
87
 
        continue;
88
 
 
89
 
      alias.type = childtype;
90
 
      alias.path = childpath;
91
 
      alias.name = childname;
92
 
      ret = hook (&alias);
93
 
      if (ret)
94
 
        break;
95
 
    }
96
 
  while (grub_ieee1275_peer (child, &child) != -1);
97
 
 
98
 
  grub_free (childname);
99
 
  grub_free (childpath);
100
 
  grub_free (childtype);
101
 
 
102
 
  return ret;
103
 
}
104
 
 
105
 
int
106
 
grub_ieee1275_devices_iterate (int (*hook) (struct grub_ieee1275_devalias *alias))
107
 
{
108
 
  auto int it_through (struct grub_ieee1275_devalias *alias);
109
 
  int it_through (struct grub_ieee1275_devalias *alias)
110
 
  {
111
 
    if (hook (alias))
112
 
      return 1;
113
 
    return grub_children_iterate (alias->path, it_through);
114
 
  }
115
 
 
116
 
  return grub_children_iterate ("/", it_through);
117
 
}
118
 
 
119
 
/* Iterate through all device aliases.  This function can be used to
120
 
   find a device of a specific type.  */
121
 
int
122
 
grub_devalias_iterate (int (*hook) (struct grub_ieee1275_devalias *alias))
123
 
{
124
 
  grub_ieee1275_phandle_t aliases;
125
 
  char *aliasname, *devtype;
126
 
  grub_ssize_t actual;
127
 
  struct grub_ieee1275_devalias alias;
128
 
  int ret = 0;
129
 
 
130
 
  if (grub_ieee1275_finddevice ("/aliases", &aliases))
131
 
    return 0;
132
 
 
133
 
  aliasname = grub_malloc (IEEE1275_MAX_PROP_LEN);
134
 
  if (!aliasname)
135
 
    return 0;
136
 
  devtype = grub_malloc (IEEE1275_MAX_PROP_LEN);
137
 
  if (!devtype)
138
 
    {
139
 
      grub_free (aliasname);
140
 
      return 0;
141
 
    }
142
 
 
143
 
  /* Find the first property.  */
144
 
  aliasname[0] = '\0';
145
 
 
146
 
  while (grub_ieee1275_next_property (aliases, aliasname, aliasname) > 0)
147
 
    {
148
 
      grub_ieee1275_phandle_t dev;
149
 
      grub_ssize_t pathlen;
150
 
      char *devpath;
151
 
 
152
 
      grub_dprintf ("devalias", "devalias name = %s\n", aliasname);
153
 
 
154
 
      grub_ieee1275_get_property_length (aliases, aliasname, &pathlen);
155
 
 
156
 
      /* The property `name' is a special case we should skip.  */
157
 
      if (!grub_strcmp (aliasname, "name"))
158
 
        continue;
159
 
 
160
 
      /* Sun's OpenBoot often doesn't zero terminate the device alias
161
 
         strings, so we will add a NULL byte at the end explicitly.  */
162
 
      pathlen += 1;
163
 
 
164
 
      devpath = grub_malloc (pathlen);
165
 
      if (! devpath)
166
 
        {
167
 
          grub_free (devtype);
168
 
          grub_free (aliasname);
169
 
          return 0;
170
 
        }
171
 
 
172
 
      if (grub_ieee1275_get_property (aliases, aliasname, devpath, pathlen,
173
 
                                      &actual))
174
 
        {
175
 
          grub_dprintf ("devalias", "get_property (%s) failed\n", aliasname);
176
 
          goto nextprop;
177
 
        }
178
 
      devpath [actual] = '\0';
179
 
 
180
 
      if (grub_ieee1275_finddevice (devpath, &dev))
181
 
        {
182
 
          grub_dprintf ("devalias", "finddevice (%s) failed\n", devpath);
183
 
          goto nextprop;
184
 
        }
185
 
 
186
 
      if (grub_ieee1275_get_property (dev, "device_type", devtype,
187
 
                                      IEEE1275_MAX_PROP_LEN, &actual))
188
 
        {
189
 
          /* NAND device don't have device_type property.  */
190
 
          devtype[0] = 0;
191
 
        }
192
 
 
193
 
      alias.name = aliasname;
194
 
      alias.path = devpath;
195
 
      alias.type = devtype;
196
 
      ret = hook (&alias);
197
 
 
198
 
nextprop:
199
 
      grub_free (devpath);
200
 
      if (ret)
201
 
        break;
202
 
    }
203
 
 
204
 
  grub_free (devtype);
205
 
  grub_free (aliasname);
206
 
  return ret;
207
 
}
208
 
 
209
 
/* Call the "map" method of /chosen/mmu.  */
210
 
int
211
 
grub_ieee1275_map (grub_addr_t phys, grub_addr_t virt, grub_size_t size,
212
 
                   grub_uint32_t mode)
213
 
{
214
 
  struct map_args {
215
 
    struct grub_ieee1275_common_hdr common;
216
 
    grub_ieee1275_cell_t method;
217
 
    grub_ieee1275_cell_t ihandle;
218
 
    grub_ieee1275_cell_t mode;
219
 
    grub_ieee1275_cell_t size;
220
 
    grub_ieee1275_cell_t virt;
221
 
#ifdef GRUB_MACHINE_SPARC64
222
 
    grub_ieee1275_cell_t phys_high;
223
 
#endif
224
 
    grub_ieee1275_cell_t phys_low;
225
 
    grub_ieee1275_cell_t catch_result;
226
 
  } args;
227
 
 
228
 
  INIT_IEEE1275_COMMON (&args.common, "call-method",
229
 
#ifdef GRUB_MACHINE_SPARC64
230
 
                        7,
231
 
#else
232
 
                        6,
233
 
#endif
234
 
                        1);
235
 
  args.method = (grub_ieee1275_cell_t) "map";
236
 
  args.ihandle = grub_ieee1275_mmu;
237
 
#ifdef GRUB_MACHINE_SPARC64
238
 
  args.phys_high = 0;
239
 
#endif
240
 
  args.phys_low = phys;
241
 
  args.virt = virt;
242
 
  args.size = size;
243
 
  args.mode = mode; /* Format is WIMG0PP.  */
244
 
  args.catch_result = (grub_ieee1275_cell_t) -1;
245
 
 
246
 
  if (IEEE1275_CALL_ENTRY_FN (&args) == -1)
247
 
    return -1;
248
 
 
249
 
  return args.catch_result;
250
 
}
251
 
 
252
 
int
253
 
grub_claimmap (grub_addr_t addr, grub_size_t size)
254
 
{
255
 
  if (grub_ieee1275_claim (addr, size, 0, 0))
256
 
    return -1;
257
 
 
258
 
  if (! grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_REAL_MODE)
259
 
      && grub_ieee1275_map (addr, addr, size, 0x00))
260
 
    {
261
 
      grub_printf ("map failed: address 0x%llx, size 0x%llx\n",
262
 
                   (long long) addr, (long long) size);
263
 
      grub_ieee1275_release (addr, size);
264
 
      return -1;
265
 
    }
266
 
 
267
 
  return 0;
268
 
}
269
 
 
270
 
/* Get the device arguments of the Open Firmware node name `path'.  */
271
 
static char *
272
 
grub_ieee1275_get_devargs (const char *path)
273
 
{
274
 
  char *colon = grub_strchr (path, ':');
275
 
 
276
 
  if (! colon)
277
 
    return 0;
278
 
 
279
 
  return grub_strdup (colon + 1);
280
 
}
281
 
 
282
 
/* Get the device path of the Open Firmware node name `path'.  */
283
 
static char *
284
 
grub_ieee1275_get_devname (const char *path)
285
 
{
286
 
  char *colon = grub_strchr (path, ':');
287
 
  char *newpath = 0;
288
 
  int pathlen = grub_strlen (path);
289
 
  auto int match_alias (struct grub_ieee1275_devalias *alias);
290
 
 
291
 
  int match_alias (struct grub_ieee1275_devalias *curalias)
292
 
    {
293
 
      /* briQ firmware can change capitalization in /chosen/bootpath.  */
294
 
      if (! grub_strncasecmp (curalias->path, path, pathlen))
295
 
        {
296
 
          newpath = grub_strdup (curalias->name);
297
 
          return 1;
298
 
        }
299
 
 
300
 
      return 0;
301
 
    }
302
 
 
303
 
  if (colon)
304
 
    pathlen = (int)(colon - path);
305
 
 
306
 
  /* Try to find an alias for this device.  */
307
 
  grub_devalias_iterate (match_alias);
308
 
 
309
 
  if (! newpath)
310
 
    newpath = grub_strndup (path, pathlen);
311
 
 
312
 
  return newpath;
313
 
}
314
 
 
315
 
static char *
316
 
grub_ieee1275_parse_args (const char *path, enum grub_ieee1275_parse_type ptype)
317
 
{
318
 
  char type[64]; /* XXX check size.  */
319
 
  char *device = grub_ieee1275_get_devname (path);
320
 
  char *args = grub_ieee1275_get_devargs (path);
321
 
  char *ret = 0;
322
 
  grub_ieee1275_phandle_t dev;
323
 
 
324
 
  if (!args)
325
 
    /* Shouldn't happen.  */
326
 
    return 0;
327
 
 
328
 
  /* We need to know what type of device it is in order to parse the full
329
 
     file path properly.  */
330
 
  if (grub_ieee1275_finddevice (device, &dev))
331
 
    {
332
 
      grub_error (GRUB_ERR_UNKNOWN_DEVICE, "device %s not found", device);
333
 
      goto fail;
334
 
    }
335
 
  if (grub_ieee1275_get_property (dev, "device_type", &type, sizeof type, 0))
336
 
    {
337
 
      grub_error (GRUB_ERR_UNKNOWN_DEVICE,
338
 
                  "device %s lacks a device_type property", device);
339
 
      goto fail;
340
 
    }
341
 
 
342
 
  if (!grub_strcmp ("block", type))
343
 
    {
344
 
      /* The syntax of the device arguments is defined in the CHRP and PReP
345
 
         IEEE1275 bindings: "[partition][,[filename]]".  */
346
 
      char *comma = grub_strchr (args, ',');
347
 
 
348
 
      if (ptype == GRUB_PARSE_FILENAME)
349
 
        {
350
 
          if (comma)
351
 
            {
352
 
              char *filepath = comma + 1;
353
 
 
354
 
              /* Make sure filepath has leading backslash.  */
355
 
              if (filepath[0] != '\\')
356
 
                ret = grub_xasprintf ("\\%s", filepath);
357
 
              else
358
 
                ret = grub_strdup (filepath);
359
 
            }
360
 
        }
361
 
      else if (ptype == GRUB_PARSE_PARTITION)
362
 
        {
363
 
          if (!comma)
364
 
            ret = grub_strdup (args);
365
 
          else
366
 
            ret = grub_strndup (args, (grub_size_t)(comma - args));
367
 
        }
368
 
    }
369
 
  else
370
 
    {
371
 
      /* XXX Handle net devices by configuring & registering a grub_net_dev
372
 
         here, then return its name?
373
 
         Example path: "net:<server ip>,<file name>,<client ip>,<gateway
374
 
         ip>,<bootp retries>,<tftp retries>".  */
375
 
      grub_printf ("Unsupported type %s for device %s\n", type, device);
376
 
    }
377
 
 
378
 
fail:
379
 
  grub_free (device);
380
 
  grub_free (args);
381
 
  return ret;
382
 
}
383
 
 
384
 
char *
385
 
grub_ieee1275_get_filename (const char *path)
386
 
{
387
 
  return grub_ieee1275_parse_args (path, GRUB_PARSE_FILENAME);
388
 
}
389
 
 
390
 
/* Convert a device name from IEEE1275 syntax to GRUB syntax.  */
391
 
char *
392
 
grub_ieee1275_encode_devname (const char *path)
393
 
{
394
 
  char *device = grub_ieee1275_get_devname (path);
395
 
  char *partition = grub_ieee1275_parse_args (path, GRUB_PARSE_PARTITION);
396
 
  char *encoding;
397
 
 
398
 
  if (partition && partition[0])
399
 
    {
400
 
      unsigned int partno = grub_strtoul (partition, 0, 0);
401
 
 
402
 
      if (grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_0_BASED_PARTITIONS))
403
 
        /* GRUB partition 1 is OF partition 0.  */
404
 
        partno++;
405
 
 
406
 
      encoding = grub_xasprintf ("(%s,%d)", device, partno);
407
 
    }
408
 
  else
409
 
    encoding = grub_xasprintf ("(%s)", device);
410
 
 
411
 
  grub_free (partition);
412
 
  grub_free (device);
413
 
 
414
 
  return encoding;
415
 
}
416
 
 
417
 
/* On i386, a firmware-independant grub_reboot() is provided by realmode.S.  */
418
 
#ifndef __i386__
419
 
void
420
 
grub_reboot (void)
421
 
{
422
 
  grub_ieee1275_interpret ("reset-all", 0);
423
 
  for (;;) ;
424
 
}
425
 
#endif
426
 
 
427
 
void
428
 
grub_halt (void)
429
 
{
430
 
  /* Not standardized.  We try three known commands.  */
431
 
 
432
 
  grub_ieee1275_interpret ("shut-down", 0);
433
 
  grub_ieee1275_interpret ("power-off", 0);
434
 
  grub_ieee1275_interpret ("poweroff", 0);
435
 
  for (;;) ;
436
 
}