0bf74728de
Fix detection of "real mode" when /options/real-mode? doesn't exist. * include/grub/ieee1275/ieee1275.h (grub_ieee1275_mmu): New variable declaration. * kern/powerpc/ieee1275/cmain.c (grub_ieee1275_mmu): New variable. (grub_ieee1275_find_options): If `grub_ieee1275_mmu' is 0, set `GRUB_IEEE1275_FLAG_REAL_MODE'. (cmain): Intialize `grub_ieee1275_mmu' (using /chosen/mmu integer property). * kern/powerpc/ieee1275/openfw.c (grub_map): Rely on pre-initialized `grub_ieee1275_mmu' rather than obtaining a handler on every call.
122 lines
3.6 KiB
C
122 lines
3.6 KiB
C
/* cmain.c - Startup code for the PowerPC. */
|
||
/*
|
||
* GRUB -- GRand Unified Bootloader
|
||
* Copyright (C) 2003,2004,2005,2006,2007,2008 Free Software Foundation, Inc.
|
||
*
|
||
* GRUB is free software: you can redistribute it and/or modify
|
||
* it under the terms of the GNU General Public License as published by
|
||
* the Free Software Foundation, either version 3 of the License, or
|
||
* (at your option) any later version.
|
||
*
|
||
* GRUB is distributed in the hope that it will be useful,
|
||
* 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
|
||
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||
*/
|
||
|
||
#include <alloca.h>
|
||
#include <stdint.h>
|
||
#include <grub/kernel.h>
|
||
#include <grub/misc.h>
|
||
#include <grub/types.h>
|
||
#include <grub/machine/kernel.h>
|
||
#include <grub/ieee1275/ieee1275.h>
|
||
|
||
int (*grub_ieee1275_entry_fn) (void *);
|
||
|
||
grub_ieee1275_phandle_t grub_ieee1275_chosen;
|
||
grub_ieee1275_ihandle_t grub_ieee1275_mmu;
|
||
|
||
static grub_uint32_t grub_ieee1275_flags;
|
||
|
||
|
||
|
||
int
|
||
grub_ieee1275_test_flag (enum grub_ieee1275_flag flag)
|
||
{
|
||
return (grub_ieee1275_flags & (1 << flag));
|
||
}
|
||
|
||
void
|
||
grub_ieee1275_set_flag (enum grub_ieee1275_flag flag)
|
||
{
|
||
grub_ieee1275_flags |= (1 << flag);
|
||
}
|
||
|
||
static void
|
||
grub_ieee1275_find_options (void)
|
||
{
|
||
grub_ieee1275_phandle_t options;
|
||
grub_ieee1275_phandle_t openprom;
|
||
int rc;
|
||
int realmode = 0;
|
||
char tmp[32];
|
||
int is_smartfirmware = 0;
|
||
|
||
grub_ieee1275_finddevice ("/options", &options);
|
||
rc = grub_ieee1275_get_integer_property (options, "real-mode?", &realmode,
|
||
sizeof realmode, 0);
|
||
if (((rc >= 0) && realmode) || (grub_ieee1275_mmu == 0))
|
||
grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_REAL_MODE);
|
||
|
||
grub_ieee1275_finddevice ("/openprom", &openprom);
|
||
|
||
rc = grub_ieee1275_get_property (openprom, "CodeGen-copyright",
|
||
tmp, sizeof (tmp), 0);
|
||
#define SF "SmartFirmware(tm)"
|
||
if (rc >= 0 && !grub_strncmp (tmp, SF, sizeof (SF) - 1))
|
||
is_smartfirmware = 1;
|
||
|
||
if (is_smartfirmware)
|
||
{
|
||
/* Broken in all versions */
|
||
grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_BROKEN_OUTPUT);
|
||
|
||
/* There are two incompatible ways of checking the version number. Try
|
||
both. */
|
||
rc = grub_ieee1275_get_property (openprom, "SmartFirmware-version",
|
||
tmp, sizeof (tmp), 0);
|
||
if (rc < 0)
|
||
rc = grub_ieee1275_get_property (openprom, "firmware-version",
|
||
tmp, sizeof (tmp), 0);
|
||
if (rc >= 0)
|
||
{
|
||
/* It is tempting to implement a version parser to set the flags for
|
||
e.g. 1.3 and below. However, there's a special situation here.
|
||
3rd party updates which fix the partition bugs are common, and for
|
||
some reason their fixes aren't being merged into trunk. So for
|
||
example we know that 1.2 and 1.3 are broken, but there's 1.2.99
|
||
and 1.3.99 which are known good (and applying this workaround
|
||
would cause breakage). */
|
||
if (!grub_strcmp (tmp, "1.0")
|
||
|| !grub_strcmp (tmp, "1.1")
|
||
|| !grub_strcmp (tmp, "1.2")
|
||
|| !grub_strcmp (tmp, "1.3"))
|
||
{
|
||
grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_NO_PARTITION_0);
|
||
grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_0_BASED_PARTITIONS);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
void cmain (void);
|
||
void
|
||
cmain (void)
|
||
{
|
||
grub_ieee1275_finddevice ("/chosen", &grub_ieee1275_chosen);
|
||
|
||
if (grub_ieee1275_get_integer_property (grub_ieee1275_chosen, "mmu", &grub_ieee1275_mmu,
|
||
sizeof grub_ieee1275_mmu, 0) < 0)
|
||
grub_ieee1275_mmu = 0;
|
||
|
||
grub_ieee1275_find_options ();
|
||
|
||
/* Now invoke the main function. */
|
||
grub_main ();
|
||
|
||
/* Never reached. */
|
||
}
|