2007-12-30 08:52:06 +00:00
|
|
|
/* openfw.c -- Open firmware support functions. */
|
2004-03-28 21:52:02 +00:00
|
|
|
/*
|
2004-04-04 13:46:03 +00:00
|
|
|
* GRUB -- GRand Unified Bootloader
|
2009-12-05 01:43:17 +00:00
|
|
|
* Copyright (C) 2003,2004,2005,2007,2008,2009 Free Software Foundation, Inc.
|
2004-03-28 21:52:02 +00:00
|
|
|
*
|
2007-07-21 23:32:33 +00:00
|
|
|
* GRUB is free software: you can redistribute it and/or modify
|
2004-03-28 21:52:02 +00:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2007-07-21 23:32:33 +00:00
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
2004-03-28 21:52:02 +00:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
2007-07-21 23:32:33 +00:00
|
|
|
* GRUB is distributed in the hope that it will be useful,
|
2004-03-28 21:52:02 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2007-07-21 23:32:33 +00:00
|
|
|
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
2004-03-28 21:52:02 +00:00
|
|
|
*/
|
|
|
|
|
2007-02-13 03:20:16 +00:00
|
|
|
#include <grub/types.h>
|
2004-04-04 13:46:03 +00:00
|
|
|
#include <grub/err.h>
|
|
|
|
#include <grub/misc.h>
|
|
|
|
#include <grub/mm.h>
|
2005-08-03 22:53:51 +00:00
|
|
|
#include <grub/ieee1275/ieee1275.h>
|
2010-09-15 16:23:23 +00:00
|
|
|
#include <grub/net.h>
|
2004-03-28 21:52:02 +00:00
|
|
|
|
2005-04-22 02:32:37 +00:00
|
|
|
enum grub_ieee1275_parse_type
|
|
|
|
{
|
|
|
|
GRUB_PARSE_FILENAME,
|
|
|
|
GRUB_PARSE_PARTITION,
|
2011-07-05 14:37:14 +00:00
|
|
|
GRUB_PARSE_DEVICE,
|
|
|
|
GRUB_PARSE_DEVICE_TYPE
|
2005-04-22 02:32:37 +00:00
|
|
|
};
|
|
|
|
|
2013-03-02 22:51:19 +00:00
|
|
|
static int
|
|
|
|
fill_alias (struct grub_ieee1275_devalias *alias)
|
2004-10-13 23:43:44 +00:00
|
|
|
{
|
2013-03-02 22:51:19 +00:00
|
|
|
grub_ssize_t actual;
|
2004-10-13 23:43:44 +00:00
|
|
|
|
2013-03-02 22:51:19 +00:00
|
|
|
if (grub_ieee1275_get_property (alias->phandle, "device_type", alias->type,
|
|
|
|
IEEE1275_MAX_PROP_LEN, &actual))
|
|
|
|
alias->type[0] = 0;
|
|
|
|
|
|
|
|
if (alias->parent_dev == alias->phandle)
|
2009-04-24 12:05:54 +00:00
|
|
|
return 0;
|
2004-10-13 23:43:44 +00:00
|
|
|
|
2013-03-02 22:51:19 +00:00
|
|
|
if (grub_ieee1275_package_to_path (alias->phandle, alias->path,
|
|
|
|
IEEE1275_MAX_PATH_LEN, &actual))
|
2009-04-24 12:05:54 +00:00
|
|
|
return 0;
|
2004-10-13 23:43:44 +00:00
|
|
|
|
2013-03-02 22:51:19 +00:00
|
|
|
if (grub_strcmp (alias->parent_path, alias->path) == 0)
|
2009-04-24 12:05:54 +00:00
|
|
|
return 0;
|
2013-03-02 22:51:19 +00:00
|
|
|
|
|
|
|
if (grub_ieee1275_get_property (alias->phandle, "name", alias->name,
|
|
|
|
IEEE1275_MAX_PROP_LEN, &actual))
|
|
|
|
return 0;
|
|
|
|
grub_dprintf ("devalias", "device path=%s\n", alias->path);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
grub_ieee1275_devalias_free (struct grub_ieee1275_devalias *alias)
|
|
|
|
{
|
|
|
|
grub_free (alias->name);
|
|
|
|
grub_free (alias->type);
|
|
|
|
grub_free (alias->path);
|
|
|
|
grub_free (alias->parent_path);
|
|
|
|
alias->name = 0;
|
|
|
|
alias->type = 0;
|
|
|
|
alias->path = 0;
|
|
|
|
alias->parent_path = 0;
|
|
|
|
alias->phandle = GRUB_IEEE1275_PHANDLE_INVALID;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
grub_ieee1275_children_peer (struct grub_ieee1275_devalias *alias)
|
|
|
|
{
|
|
|
|
while (grub_ieee1275_peer (alias->phandle, &alias->phandle) != -1)
|
|
|
|
if (fill_alias (alias))
|
|
|
|
return;
|
|
|
|
grub_ieee1275_devalias_free (alias);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
grub_ieee1275_children_first (const char *devpath,
|
|
|
|
struct grub_ieee1275_devalias *alias)
|
|
|
|
{
|
|
|
|
grub_ieee1275_phandle_t dev;
|
|
|
|
|
|
|
|
grub_dprintf ("devalias", "iterating children of %s\n",
|
|
|
|
devpath);
|
|
|
|
|
|
|
|
alias->name = 0;
|
|
|
|
alias->path = 0;
|
|
|
|
alias->parent_path = 0;
|
|
|
|
alias->type = 0;
|
|
|
|
|
|
|
|
if (grub_ieee1275_finddevice (devpath, &dev))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (grub_ieee1275_child (dev, &alias->phandle))
|
|
|
|
return;
|
|
|
|
|
|
|
|
alias->type = grub_malloc (IEEE1275_MAX_PROP_LEN);
|
|
|
|
if (!alias->type)
|
|
|
|
return;
|
|
|
|
alias->path = grub_malloc (IEEE1275_MAX_PATH_LEN);
|
|
|
|
if (!alias->path)
|
2009-04-22 09:46:54 +00:00
|
|
|
{
|
2013-03-02 22:51:19 +00:00
|
|
|
grub_free (alias->type);
|
|
|
|
return;
|
2009-04-22 09:46:54 +00:00
|
|
|
}
|
2013-03-02 22:51:19 +00:00
|
|
|
alias->parent_path = grub_strdup (devpath);
|
|
|
|
if (!alias->parent_path)
|
2009-04-22 09:46:54 +00:00
|
|
|
{
|
2013-03-02 22:51:19 +00:00
|
|
|
grub_free (alias->path);
|
|
|
|
grub_free (alias->type);
|
|
|
|
return;
|
2009-04-22 09:46:54 +00:00
|
|
|
}
|
|
|
|
|
2013-03-02 22:51:19 +00:00
|
|
|
alias->name = grub_malloc (IEEE1275_MAX_PROP_LEN);
|
|
|
|
if (!alias->name)
|
2004-10-13 23:43:44 +00:00
|
|
|
{
|
2013-03-02 22:51:19 +00:00
|
|
|
grub_free (alias->path);
|
|
|
|
grub_free (alias->type);
|
|
|
|
grub_free (alias->parent_path);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!fill_alias (alias))
|
|
|
|
grub_ieee1275_children_peer (alias);
|
|
|
|
}
|
2010-03-31 20:01:37 +00:00
|
|
|
|
2013-03-02 22:51:19 +00:00
|
|
|
static int
|
|
|
|
iterate_recursively (const char *path,
|
|
|
|
int (*hook) (struct grub_ieee1275_devalias *alias))
|
|
|
|
{
|
|
|
|
struct grub_ieee1275_devalias alias;
|
|
|
|
int ret = 0;
|
2004-10-13 23:43:44 +00:00
|
|
|
|
2013-03-02 22:51:19 +00:00
|
|
|
FOR_IEEE1275_DEVCHILDREN(path, alias)
|
|
|
|
{
|
2009-04-24 12:05:54 +00:00
|
|
|
ret = hook (&alias);
|
|
|
|
if (ret)
|
|
|
|
break;
|
2013-03-02 22:51:19 +00:00
|
|
|
ret = iterate_recursively (alias.path, hook);
|
|
|
|
if (ret)
|
|
|
|
break;
|
2004-10-13 23:43:44 +00:00
|
|
|
}
|
2013-03-02 22:51:19 +00:00
|
|
|
grub_ieee1275_devalias_free (&alias);
|
2009-04-24 12:05:54 +00:00
|
|
|
return ret;
|
2004-10-13 23:43:44 +00:00
|
|
|
}
|
|
|
|
|
2010-01-31 00:57:17 +00:00
|
|
|
int
|
|
|
|
grub_ieee1275_devices_iterate (int (*hook) (struct grub_ieee1275_devalias *alias))
|
|
|
|
{
|
2013-03-02 22:51:19 +00:00
|
|
|
return iterate_recursively ("/", hook);
|
2010-01-31 00:57:17 +00:00
|
|
|
}
|
|
|
|
|
2013-03-02 22:51:19 +00:00
|
|
|
void
|
|
|
|
grub_ieee1275_devalias_init_iterator (struct grub_ieee1275_devalias *alias)
|
2004-03-28 21:52:02 +00:00
|
|
|
{
|
2013-03-02 22:51:19 +00:00
|
|
|
alias->name = 0;
|
|
|
|
alias->path = 0;
|
|
|
|
alias->parent_path = 0;
|
|
|
|
alias->type = 0;
|
2004-03-28 21:52:02 +00:00
|
|
|
|
2013-03-02 22:51:19 +00:00
|
|
|
grub_dprintf ("devalias", "iterating aliases\n");
|
2004-03-28 21:52:02 +00:00
|
|
|
|
2013-03-02 22:51:19 +00:00
|
|
|
if (grub_ieee1275_finddevice ("/aliases", &alias->parent_dev))
|
|
|
|
return;
|
|
|
|
|
|
|
|
alias->name = grub_malloc (IEEE1275_MAX_PROP_LEN);
|
|
|
|
if (!alias->name)
|
|
|
|
return;
|
|
|
|
|
|
|
|
alias->type = grub_malloc (IEEE1275_MAX_PROP_LEN);
|
|
|
|
if (!alias->type)
|
2009-04-22 09:46:54 +00:00
|
|
|
{
|
2013-03-02 22:51:19 +00:00
|
|
|
grub_free (alias->name);
|
|
|
|
alias->name = 0;
|
|
|
|
return;
|
2009-04-22 09:46:54 +00:00
|
|
|
}
|
|
|
|
|
2013-03-02 22:51:19 +00:00
|
|
|
alias->name[0] = '\0';
|
|
|
|
}
|
2004-03-28 21:52:02 +00:00
|
|
|
|
2013-03-02 22:51:19 +00:00
|
|
|
int
|
|
|
|
grub_ieee1275_devalias_next (struct grub_ieee1275_devalias *alias)
|
|
|
|
{
|
|
|
|
if (!alias->name)
|
|
|
|
return 0;
|
|
|
|
while (1)
|
2004-03-28 21:52:02 +00:00
|
|
|
{
|
2006-09-26 03:49:41 +00:00
|
|
|
grub_ssize_t pathlen;
|
2013-03-02 22:51:19 +00:00
|
|
|
grub_ssize_t actual;
|
2013-04-14 22:40:19 +00:00
|
|
|
char *tmp;
|
2005-10-01 Hollis Blanchard <hollis@penguinppc.org>
* disk/ieee1275/ofdisk.c (grub_ofdisk_iterate): Cast `size' to long.
* include/grub/ieee1275/ieee1275.h (grub_ieee1275_next_property):
Remove `flags' argument. All callers changed.
* kern/ieee1275/ieee1275.c (IEEE1275_PHANDLE_ROOT): Removed.
(IEEE1275_IHANDLE_INVALID): New variable.
(IEEE1275_CELL_INVALID): New variable.
(grub_ieee1275_finddevice, grub_ieee1275_get_property,
grub_ieee1275_get_property_length, grub_ieee1275_instance_to_package,
grub_ieee1275_package_to_path, grub_ieee1275_instance_to_path,
grub_ieee1275_peer, grub_ieee1275_child, grub_ieee1275_open,
grub_ieee1275_claim, grub_ieee1275_set_property): Error-check return
codes from Open Firmware. All callers updated.
(grub_ieee1275_next_property): Directly return Open Firmware return
code.
* kern/powerpc/ieee1275/cmain.c (grub_ieee1275_find_options):
Standardize error checking from `grub_ieee1275_get_property'.
* kern/powerpc/ieee1275/openfw.c (grub_devalias_iterate): Rename
`devalias' to `aliases'. Correct comments. Consolidate error paths.
2006-10-01 08:30:09 +00:00
|
|
|
|
2013-03-02 22:51:19 +00:00
|
|
|
if (alias->path)
|
|
|
|
{
|
|
|
|
grub_free (alias->path);
|
|
|
|
alias->path = 0;
|
|
|
|
}
|
2013-04-14 22:40:19 +00:00
|
|
|
tmp = grub_strdup (alias->name);
|
|
|
|
if (grub_ieee1275_next_property (alias->parent_dev, tmp,
|
2013-03-02 22:51:19 +00:00
|
|
|
alias->name) <= 0)
|
|
|
|
{
|
2013-04-14 22:40:19 +00:00
|
|
|
grub_free (tmp);
|
2013-03-02 22:51:19 +00:00
|
|
|
grub_ieee1275_devalias_free (alias);
|
|
|
|
return 0;
|
|
|
|
}
|
2013-04-14 22:40:19 +00:00
|
|
|
grub_free (tmp);
|
2013-03-02 22:51:19 +00:00
|
|
|
|
|
|
|
grub_dprintf ("devalias", "devalias name = %s\n", alias->name);
|
2008-01-20 17:20:48 +00:00
|
|
|
|
2013-03-02 22:51:19 +00:00
|
|
|
grub_ieee1275_get_property_length (alias->parent_dev, alias->name, &pathlen);
|
2004-11-16 21:59:11 +00:00
|
|
|
|
|
|
|
/* The property `name' is a special case we should skip. */
|
2013-03-02 22:51:19 +00:00
|
|
|
if (grub_strcmp (alias->name, "name") == 0)
|
2005-10-01 Hollis Blanchard <hollis@penguinppc.org>
* disk/ieee1275/ofdisk.c (grub_ofdisk_iterate): Cast `size' to long.
* include/grub/ieee1275/ieee1275.h (grub_ieee1275_next_property):
Remove `flags' argument. All callers changed.
* kern/ieee1275/ieee1275.c (IEEE1275_PHANDLE_ROOT): Removed.
(IEEE1275_IHANDLE_INVALID): New variable.
(IEEE1275_CELL_INVALID): New variable.
(grub_ieee1275_finddevice, grub_ieee1275_get_property,
grub_ieee1275_get_property_length, grub_ieee1275_instance_to_package,
grub_ieee1275_package_to_path, grub_ieee1275_instance_to_path,
grub_ieee1275_peer, grub_ieee1275_child, grub_ieee1275_open,
grub_ieee1275_claim, grub_ieee1275_set_property): Error-check return
codes from Open Firmware. All callers updated.
(grub_ieee1275_next_property): Directly return Open Firmware return
code.
* kern/powerpc/ieee1275/cmain.c (grub_ieee1275_find_options):
Standardize error checking from `grub_ieee1275_get_property'.
* kern/powerpc/ieee1275/openfw.c (grub_devalias_iterate): Rename
`devalias' to `aliases'. Correct comments. Consolidate error paths.
2006-10-01 08:30:09 +00:00
|
|
|
continue;
|
|
|
|
|
2009-04-22 09:46:54 +00:00
|
|
|
/* Sun's OpenBoot often doesn't zero terminate the device alias
|
|
|
|
strings, so we will add a NULL byte at the end explicitly. */
|
|
|
|
pathlen += 1;
|
|
|
|
|
2013-03-02 22:51:19 +00:00
|
|
|
alias->path = grub_malloc (pathlen + 1);
|
|
|
|
if (! alias->path)
|
2009-04-22 09:46:54 +00:00
|
|
|
{
|
2013-03-02 22:51:19 +00:00
|
|
|
grub_ieee1275_devalias_free (alias);
|
2009-04-24 12:05:54 +00:00
|
|
|
return 0;
|
2009-04-22 09:46:54 +00:00
|
|
|
}
|
2004-03-28 21:52:02 +00:00
|
|
|
|
2013-03-02 22:51:19 +00:00
|
|
|
if (grub_ieee1275_get_property (alias->parent_dev, alias->name, alias->path,
|
|
|
|
pathlen, &actual) || actual < 0)
|
2008-01-20 17:20:48 +00:00
|
|
|
{
|
2013-03-02 22:51:19 +00:00
|
|
|
grub_dprintf ("devalias", "get_property (%s) failed\n", alias->name);
|
|
|
|
grub_free (alias->path);
|
|
|
|
continue;
|
2008-01-20 17:20:48 +00:00
|
|
|
}
|
2011-12-24 01:45:17 +00:00
|
|
|
if (actual > pathlen)
|
|
|
|
actual = pathlen;
|
2013-03-02 22:51:19 +00:00
|
|
|
alias->path[actual] = '\0';
|
|
|
|
alias->path[pathlen] = '\0';
|
2005-10-01 Hollis Blanchard <hollis@penguinppc.org>
* disk/ieee1275/ofdisk.c (grub_ofdisk_iterate): Cast `size' to long.
* include/grub/ieee1275/ieee1275.h (grub_ieee1275_next_property):
Remove `flags' argument. All callers changed.
* kern/ieee1275/ieee1275.c (IEEE1275_PHANDLE_ROOT): Removed.
(IEEE1275_IHANDLE_INVALID): New variable.
(IEEE1275_CELL_INVALID): New variable.
(grub_ieee1275_finddevice, grub_ieee1275_get_property,
grub_ieee1275_get_property_length, grub_ieee1275_instance_to_package,
grub_ieee1275_package_to_path, grub_ieee1275_instance_to_path,
grub_ieee1275_peer, grub_ieee1275_child, grub_ieee1275_open,
grub_ieee1275_claim, grub_ieee1275_set_property): Error-check return
codes from Open Firmware. All callers updated.
(grub_ieee1275_next_property): Directly return Open Firmware return
code.
* kern/powerpc/ieee1275/cmain.c (grub_ieee1275_find_options):
Standardize error checking from `grub_ieee1275_get_property'.
* kern/powerpc/ieee1275/openfw.c (grub_devalias_iterate): Rename
`devalias' to `aliases'. Correct comments. Consolidate error paths.
2006-10-01 08:30:09 +00:00
|
|
|
|
2013-03-02 22:51:19 +00:00
|
|
|
if (grub_ieee1275_finddevice (alias->path, &alias->phandle))
|
2008-01-20 17:20:48 +00:00
|
|
|
{
|
2013-03-02 22:51:19 +00:00
|
|
|
grub_dprintf ("devalias", "finddevice (%s) failed\n", alias->path);
|
|
|
|
grub_free (alias->path);
|
|
|
|
alias->path = 0;
|
|
|
|
continue;
|
2008-01-20 17:20:48 +00:00
|
|
|
}
|
2005-10-01 Hollis Blanchard <hollis@penguinppc.org>
* disk/ieee1275/ofdisk.c (grub_ofdisk_iterate): Cast `size' to long.
* include/grub/ieee1275/ieee1275.h (grub_ieee1275_next_property):
Remove `flags' argument. All callers changed.
* kern/ieee1275/ieee1275.c (IEEE1275_PHANDLE_ROOT): Removed.
(IEEE1275_IHANDLE_INVALID): New variable.
(IEEE1275_CELL_INVALID): New variable.
(grub_ieee1275_finddevice, grub_ieee1275_get_property,
grub_ieee1275_get_property_length, grub_ieee1275_instance_to_package,
grub_ieee1275_package_to_path, grub_ieee1275_instance_to_path,
grub_ieee1275_peer, grub_ieee1275_child, grub_ieee1275_open,
grub_ieee1275_claim, grub_ieee1275_set_property): Error-check return
codes from Open Firmware. All callers updated.
(grub_ieee1275_next_property): Directly return Open Firmware return
code.
* kern/powerpc/ieee1275/cmain.c (grub_ieee1275_find_options):
Standardize error checking from `grub_ieee1275_get_property'.
* kern/powerpc/ieee1275/openfw.c (grub_devalias_iterate): Rename
`devalias' to `aliases'. Correct comments. Consolidate error paths.
2006-10-01 08:30:09 +00:00
|
|
|
|
2013-03-02 22:51:19 +00:00
|
|
|
if (grub_ieee1275_get_property (alias->phandle, "device_type", alias->type,
|
2009-07-10 20:19:08 +00:00
|
|
|
IEEE1275_MAX_PROP_LEN, &actual))
|
2008-01-20 17:20:48 +00:00
|
|
|
{
|
2008-04-25 19:41:51 +00:00
|
|
|
/* NAND device don't have device_type property. */
|
2013-03-02 22:51:19 +00:00
|
|
|
alias->type[0] = 0;
|
2008-01-20 17:20:48 +00:00
|
|
|
}
|
2013-03-02 22:51:19 +00:00
|
|
|
return 1;
|
2004-03-28 21:52:02 +00:00
|
|
|
}
|
|
|
|
}
|
2004-10-29 02:45:14 +00:00
|
|
|
|
|
|
|
/* Call the "map" method of /chosen/mmu. */
|
2010-02-13 15:48:22 +00:00
|
|
|
int
|
|
|
|
grub_ieee1275_map (grub_addr_t phys, grub_addr_t virt, grub_size_t size,
|
|
|
|
grub_uint32_t mode)
|
2004-10-29 02:45:14 +00:00
|
|
|
{
|
|
|
|
struct map_args {
|
|
|
|
struct grub_ieee1275_common_hdr common;
|
* disk/ieee1275/nand.c (grub_nand_open): All ieee1275 call arg
slots are of type grub_ieee1275_cell_t.
(grub_nand_read): Likewise.
* kern/ieee1275/ieee1275.c (IEEE1275_PHANDLE_INVALID,
IEEE1275_IHANDLE_INVALID): Use grub_ieee1275_cell_t since these
macros are used to compare values in arg/ret block of the call.
(grub_ieee1275_finddevice, grub_ieee1275_get_property,
grub_ieee1275_next_property, grub_ieee1275_get_property_length,
grub_ieee1275_instance_to_package, grub_ieee1275_package_to_path,
grub_ieee1275_instance_to_path, grub_ieee1275_write,
grub_ieee1275_read, grub_ieee1275_seek, grub_ieee1275_peer,
grub_ieee1275_child, grub_ieee1275_parent, grub_ieee1275_open,
grub_ieee1275_close, grub_ieee1275_set_property,
grub_ieee1275_set_color): All ieee1275 call arg slots are of type
grub_ieee1275_cell_t.
* kern/ieee1275/openfw.c (grub_map): Likewise.
* include/grub/ieee1275/ieee1275.h (grub_ieee1275_ihandle_t,
grub_ieee1275_phandle_t): Define as grub_unit32_t type.
2009-04-11 03:07:58 +00:00
|
|
|
grub_ieee1275_cell_t method;
|
|
|
|
grub_ieee1275_cell_t ihandle;
|
|
|
|
grub_ieee1275_cell_t mode;
|
|
|
|
grub_ieee1275_cell_t size;
|
|
|
|
grub_ieee1275_cell_t virt;
|
2010-02-13 15:48:22 +00:00
|
|
|
#ifdef GRUB_MACHINE_SPARC64
|
|
|
|
grub_ieee1275_cell_t phys_high;
|
|
|
|
#endif
|
|
|
|
grub_ieee1275_cell_t phys_low;
|
* disk/ieee1275/nand.c (grub_nand_open): All ieee1275 call arg
slots are of type grub_ieee1275_cell_t.
(grub_nand_read): Likewise.
* kern/ieee1275/ieee1275.c (IEEE1275_PHANDLE_INVALID,
IEEE1275_IHANDLE_INVALID): Use grub_ieee1275_cell_t since these
macros are used to compare values in arg/ret block of the call.
(grub_ieee1275_finddevice, grub_ieee1275_get_property,
grub_ieee1275_next_property, grub_ieee1275_get_property_length,
grub_ieee1275_instance_to_package, grub_ieee1275_package_to_path,
grub_ieee1275_instance_to_path, grub_ieee1275_write,
grub_ieee1275_read, grub_ieee1275_seek, grub_ieee1275_peer,
grub_ieee1275_child, grub_ieee1275_parent, grub_ieee1275_open,
grub_ieee1275_close, grub_ieee1275_set_property,
grub_ieee1275_set_color): All ieee1275 call arg slots are of type
grub_ieee1275_cell_t.
* kern/ieee1275/openfw.c (grub_map): Likewise.
* include/grub/ieee1275/ieee1275.h (grub_ieee1275_ihandle_t,
grub_ieee1275_phandle_t): Define as grub_unit32_t type.
2009-04-11 03:07:58 +00:00
|
|
|
grub_ieee1275_cell_t catch_result;
|
2004-10-29 02:45:14 +00:00
|
|
|
} args;
|
|
|
|
|
2010-02-13 15:48:22 +00:00
|
|
|
INIT_IEEE1275_COMMON (&args.common, "call-method",
|
|
|
|
#ifdef GRUB_MACHINE_SPARC64
|
|
|
|
7,
|
|
|
|
#else
|
|
|
|
6,
|
|
|
|
#endif
|
|
|
|
1);
|
* disk/ieee1275/nand.c (grub_nand_open): All ieee1275 call arg
slots are of type grub_ieee1275_cell_t.
(grub_nand_read): Likewise.
* kern/ieee1275/ieee1275.c (IEEE1275_PHANDLE_INVALID,
IEEE1275_IHANDLE_INVALID): Use grub_ieee1275_cell_t since these
macros are used to compare values in arg/ret block of the call.
(grub_ieee1275_finddevice, grub_ieee1275_get_property,
grub_ieee1275_next_property, grub_ieee1275_get_property_length,
grub_ieee1275_instance_to_package, grub_ieee1275_package_to_path,
grub_ieee1275_instance_to_path, grub_ieee1275_write,
grub_ieee1275_read, grub_ieee1275_seek, grub_ieee1275_peer,
grub_ieee1275_child, grub_ieee1275_parent, grub_ieee1275_open,
grub_ieee1275_close, grub_ieee1275_set_property,
grub_ieee1275_set_color): All ieee1275 call arg slots are of type
grub_ieee1275_cell_t.
* kern/ieee1275/openfw.c (grub_map): Likewise.
* include/grub/ieee1275/ieee1275.h (grub_ieee1275_ihandle_t,
grub_ieee1275_phandle_t): Define as grub_unit32_t type.
2009-04-11 03:07:58 +00:00
|
|
|
args.method = (grub_ieee1275_cell_t) "map";
|
2008-01-20 14:08:54 +00:00
|
|
|
args.ihandle = grub_ieee1275_mmu;
|
2010-02-13 15:48:22 +00:00
|
|
|
#ifdef GRUB_MACHINE_SPARC64
|
|
|
|
args.phys_high = 0;
|
|
|
|
#endif
|
|
|
|
args.phys_low = phys;
|
2004-10-29 02:45:14 +00:00
|
|
|
args.virt = virt;
|
|
|
|
args.size = size;
|
|
|
|
args.mode = mode; /* Format is WIMG0PP. */
|
2010-02-13 15:48:22 +00:00
|
|
|
args.catch_result = (grub_ieee1275_cell_t) -1;
|
2004-10-29 02:45:14 +00:00
|
|
|
|
|
|
|
if (IEEE1275_CALL_ENTRY_FN (&args) == -1)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return args.catch_result;
|
|
|
|
}
|
|
|
|
|
2012-02-04 13:00:23 +00:00
|
|
|
grub_err_t
|
2004-10-29 02:45:14 +00:00
|
|
|
grub_claimmap (grub_addr_t addr, grub_size_t size)
|
|
|
|
{
|
|
|
|
if (grub_ieee1275_claim (addr, size, 0, 0))
|
|
|
|
return -1;
|
2005-01-03 17:44:25 +00:00
|
|
|
|
2005-05-01 03:45:36 +00:00
|
|
|
if (! grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_REAL_MODE)
|
2010-02-13 15:48:22 +00:00
|
|
|
&& grub_ieee1275_map (addr, addr, size, 0x00))
|
2004-10-29 02:45:14 +00:00
|
|
|
{
|
2012-02-04 13:00:23 +00:00
|
|
|
grub_error (GRUB_ERR_OUT_OF_MEMORY, "map failed: address 0x%llx, size 0x%llx\n",
|
|
|
|
(long long) addr, (long long) size);
|
2004-10-29 02:45:14 +00:00
|
|
|
grub_ieee1275_release (addr, size);
|
2012-02-04 13:00:23 +00:00
|
|
|
return grub_errno;
|
2004-10-29 02:45:14 +00:00
|
|
|
}
|
2005-01-03 17:44:25 +00:00
|
|
|
|
2012-02-04 13:00:23 +00:00
|
|
|
return GRUB_ERR_NONE;
|
2004-10-29 02:45:14 +00:00
|
|
|
}
|
2005-03-26 17:34:50 +00:00
|
|
|
|
2005-04-22 02:32:37 +00:00
|
|
|
/* Get the device arguments of the Open Firmware node name `path'. */
|
|
|
|
static char *
|
|
|
|
grub_ieee1275_get_devargs (const char *path)
|
|
|
|
{
|
|
|
|
char *colon = grub_strchr (path, ':');
|
|
|
|
|
|
|
|
if (! colon)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return grub_strdup (colon + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the device path of the Open Firmware node name `path'. */
|
2013-03-02 22:51:19 +00:00
|
|
|
char *
|
2005-04-22 02:32:37 +00:00
|
|
|
grub_ieee1275_get_devname (const char *path)
|
|
|
|
{
|
|
|
|
char *colon = grub_strchr (path, ':');
|
|
|
|
int pathlen = grub_strlen (path);
|
2013-03-02 22:51:19 +00:00
|
|
|
struct grub_ieee1275_devalias curalias;
|
2005-04-22 02:32:37 +00:00
|
|
|
if (colon)
|
|
|
|
pathlen = (int)(colon - path);
|
|
|
|
|
|
|
|
/* Try to find an alias for this device. */
|
2013-03-02 22:51:19 +00:00
|
|
|
FOR_IEEE1275_DEVALIASES (curalias)
|
|
|
|
/* briQ firmware can change capitalization in /chosen/bootpath. */
|
|
|
|
if (grub_strncasecmp (curalias.path, path, pathlen) == 0
|
|
|
|
&& curalias.path[pathlen] == 0)
|
|
|
|
{
|
|
|
|
char *newpath;
|
|
|
|
newpath = grub_strdup (curalias.name);
|
|
|
|
grub_ieee1275_devalias_free (&curalias);
|
|
|
|
return newpath;
|
|
|
|
}
|
|
|
|
|
|
|
|
return grub_strndup (path, pathlen);
|
2005-04-22 02:32:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
|
|
|
grub_ieee1275_parse_args (const char *path, enum grub_ieee1275_parse_type ptype)
|
|
|
|
{
|
|
|
|
char type[64]; /* XXX check size. */
|
|
|
|
char *device = grub_ieee1275_get_devname (path);
|
|
|
|
char *ret = 0;
|
|
|
|
grub_ieee1275_phandle_t dev;
|
|
|
|
|
|
|
|
/* We need to know what type of device it is in order to parse the full
|
|
|
|
file path properly. */
|
|
|
|
if (grub_ieee1275_finddevice (device, &dev))
|
|
|
|
{
|
2009-12-24 22:53:05 +00:00
|
|
|
grub_error (GRUB_ERR_UNKNOWN_DEVICE, "device %s not found", device);
|
2005-04-22 02:32:37 +00:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
if (grub_ieee1275_get_property (dev, "device_type", &type, sizeof type, 0))
|
|
|
|
{
|
|
|
|
grub_error (GRUB_ERR_UNKNOWN_DEVICE,
|
2009-12-24 22:53:05 +00:00
|
|
|
"device %s lacks a device_type property", device);
|
2005-04-22 02:32:37 +00:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2011-07-05 14:37:14 +00:00
|
|
|
switch (ptype)
|
2005-04-22 02:32:37 +00:00
|
|
|
{
|
2011-07-05 14:37:14 +00:00
|
|
|
case GRUB_PARSE_DEVICE:
|
|
|
|
ret = grub_strdup (device);
|
|
|
|
break;
|
|
|
|
case GRUB_PARSE_DEVICE_TYPE:
|
|
|
|
ret = grub_strdup (type);
|
|
|
|
break;
|
|
|
|
case GRUB_PARSE_FILENAME:
|
|
|
|
{
|
|
|
|
char *comma;
|
|
|
|
char *args;
|
|
|
|
|
|
|
|
args = grub_ieee1275_get_devargs (path);
|
|
|
|
if (!args)
|
|
|
|
/* Shouldn't happen. */
|
|
|
|
return 0;
|
2005-04-22 02:32:37 +00:00
|
|
|
|
2011-07-05 14:37:14 +00:00
|
|
|
/* The syntax of the device arguments is defined in the CHRP and PReP
|
|
|
|
IEEE1275 bindings: "[partition][,[filename]]". */
|
|
|
|
comma = grub_strchr (args, ',');
|
|
|
|
|
|
|
|
if (comma)
|
|
|
|
{
|
|
|
|
char *filepath = comma + 1;
|
|
|
|
|
|
|
|
/* Make sure filepath has leading backslash. */
|
|
|
|
if (filepath[0] != '\\')
|
|
|
|
ret = grub_xasprintf ("\\%s", filepath);
|
|
|
|
else
|
|
|
|
ret = grub_strdup (filepath);
|
2005-04-22 02:32:37 +00:00
|
|
|
}
|
2011-07-05 14:37:14 +00:00
|
|
|
grub_free (args);
|
2005-04-22 02:32:37 +00:00
|
|
|
}
|
2011-07-05 14:37:14 +00:00
|
|
|
break;
|
|
|
|
case GRUB_PARSE_PARTITION:
|
|
|
|
{
|
|
|
|
char *comma;
|
|
|
|
char *args;
|
|
|
|
|
|
|
|
if (grub_strcmp ("block", type) != 0)
|
|
|
|
goto unknown;
|
|
|
|
|
|
|
|
args = grub_ieee1275_get_devargs (path);
|
|
|
|
if (!args)
|
|
|
|
/* Shouldn't happen. */
|
|
|
|
return 0;
|
2010-06-21 22:20:55 +00:00
|
|
|
|
2011-07-05 14:37:14 +00:00
|
|
|
comma = grub_strchr (args, ',');
|
|
|
|
if (!comma)
|
|
|
|
ret = grub_strdup (args);
|
|
|
|
else
|
|
|
|
ret = grub_strndup (args, (grub_size_t)(comma - args));
|
|
|
|
/* Consistently provide numbered partitions to GRUB.
|
|
|
|
OpenBOOT traditionally uses alphabetical partition
|
|
|
|
specifiers. */
|
|
|
|
if (ret[0] >= 'a' && ret[0] <= 'z')
|
|
|
|
ret[0] = '1' + (ret[0] - 'a');
|
|
|
|
grub_free (args);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
unknown:
|
2011-11-11 16:44:47 +00:00
|
|
|
grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
|
|
|
|
"unsupported type %s for device %s", type, device);
|
2005-04-22 02:32:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fail:
|
|
|
|
grub_free (device);
|
|
|
|
return ret;
|
2011-07-05 14:37:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
|
|
|
grub_ieee1275_get_device_type (const char *path)
|
|
|
|
{
|
|
|
|
return grub_ieee1275_parse_args (path, GRUB_PARSE_DEVICE_TYPE);
|
2005-04-22 02:32:37 +00:00
|
|
|
}
|
|
|
|
|
2010-06-21 22:20:55 +00:00
|
|
|
char *
|
|
|
|
grub_ieee1275_get_aliasdevname (const char *path)
|
|
|
|
{
|
|
|
|
return grub_ieee1275_parse_args (path, GRUB_PARSE_DEVICE);
|
|
|
|
}
|
|
|
|
|
2005-04-22 02:32:37 +00:00
|
|
|
char *
|
|
|
|
grub_ieee1275_get_filename (const char *path)
|
|
|
|
{
|
|
|
|
return grub_ieee1275_parse_args (path, GRUB_PARSE_FILENAME);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Convert a device name from IEEE1275 syntax to GRUB syntax. */
|
|
|
|
char *
|
|
|
|
grub_ieee1275_encode_devname (const char *path)
|
|
|
|
{
|
|
|
|
char *device = grub_ieee1275_get_devname (path);
|
2012-06-20 21:31:59 +00:00
|
|
|
char *partition;
|
2005-04-22 02:32:37 +00:00
|
|
|
char *encoding;
|
2012-06-20 21:31:59 +00:00
|
|
|
char *optr;
|
|
|
|
const char *iptr;
|
2005-04-22 02:32:37 +00:00
|
|
|
|
2012-06-20 21:31:59 +00:00
|
|
|
encoding = grub_malloc (sizeof ("ieee1275/") + 2 * grub_strlen (device)
|
|
|
|
+ sizeof (",XXXXXXXXXXXX"));
|
|
|
|
if (!encoding)
|
|
|
|
{
|
|
|
|
grub_free (device);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
partition = grub_ieee1275_parse_args (path, GRUB_PARSE_PARTITION);
|
|
|
|
|
|
|
|
optr = grub_stpcpy (encoding, "ieee1275/");
|
|
|
|
for (iptr = device; *iptr; )
|
|
|
|
{
|
|
|
|
if (*iptr == ',')
|
|
|
|
*optr++ ='\\';
|
|
|
|
*optr++ = *iptr++;
|
|
|
|
}
|
2010-02-05 23:32:07 +00:00
|
|
|
if (partition && partition[0])
|
2005-04-22 02:32:37 +00:00
|
|
|
{
|
|
|
|
unsigned int partno = grub_strtoul (partition, 0, 0);
|
2005-05-01 03:45:36 +00:00
|
|
|
|
2012-06-20 21:31:59 +00:00
|
|
|
*optr++ = ',';
|
|
|
|
|
2006-10-26 23:11:22 +00:00
|
|
|
if (grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_0_BASED_PARTITIONS))
|
|
|
|
/* GRUB partition 1 is OF partition 0. */
|
2007-07-22 09:05:11 +00:00
|
|
|
partno++;
|
2005-04-22 02:32:37 +00:00
|
|
|
|
2012-06-20 21:31:59 +00:00
|
|
|
grub_snprintf (optr, sizeof ("XXXXXXXXXXXX"), "%d", partno);
|
2005-04-22 02:32:37 +00:00
|
|
|
}
|
|
|
|
else
|
2012-06-20 21:31:59 +00:00
|
|
|
*optr = '\0';
|
2005-04-22 02:32:37 +00:00
|
|
|
|
|
|
|
grub_free (partition);
|
|
|
|
grub_free (device);
|
|
|
|
|
|
|
|
return encoding;
|
|
|
|
}
|
|
|
|
|
2010-09-13 17:17:29 +00:00
|
|
|
/* Resolve aliases. */
|
|
|
|
char *
|
|
|
|
grub_ieee1275_canonicalise_devname (const char *path)
|
|
|
|
{
|
|
|
|
struct canon_args
|
|
|
|
{
|
|
|
|
struct grub_ieee1275_common_hdr common;
|
|
|
|
grub_ieee1275_cell_t path;
|
|
|
|
grub_ieee1275_cell_t buf;
|
|
|
|
grub_ieee1275_cell_t inlen;
|
|
|
|
grub_ieee1275_cell_t outlen;
|
|
|
|
}
|
|
|
|
args;
|
|
|
|
char *buf = NULL;
|
|
|
|
grub_size_t bufsize = 64;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < 2; i++)
|
|
|
|
{
|
|
|
|
grub_free (buf);
|
|
|
|
|
|
|
|
buf = grub_malloc (bufsize);
|
|
|
|
if (!buf)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
INIT_IEEE1275_COMMON (&args.common, "canon", 3, 1);
|
|
|
|
args.path = (grub_ieee1275_cell_t) path;
|
|
|
|
args.buf = (grub_ieee1275_cell_t) buf;
|
|
|
|
args.inlen = (grub_ieee1275_cell_t) (bufsize - 1);
|
|
|
|
|
|
|
|
if (IEEE1275_CALL_ENTRY_FN (&args) == -1)
|
|
|
|
return 0;
|
|
|
|
if (args.outlen > bufsize - 1)
|
|
|
|
{
|
|
|
|
bufsize = args.outlen + 2;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
/* Shouldn't reach here. */
|
|
|
|
grub_free (buf);
|
|
|
|
return NULL;
|
|
|
|
}
|
2010-09-22 18:13:00 +00:00
|
|
|
|