2N/A/* cmain.c - Startup code for the PowerPC. */
2N/A/*
2N/A * GRUB -- GRand Unified Bootloader
2N/A * Copyright (C) 2003,2004,2005,2006,2007,2008 Free Software Foundation, Inc.
2N/A *
2N/A * GRUB is free software: you can redistribute it and/or modify
2N/A * it under the terms of the GNU General Public License as published by
2N/A * the Free Software Foundation, either version 3 of the License, or
2N/A * (at your option) any later version.
2N/A *
2N/A * GRUB is distributed in the hope that it will be useful,
2N/A * but WITHOUT ANY WARRANTY; without even the implied warranty of
2N/A * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2N/A * GNU General Public License for more details.
2N/A *
2N/A * You should have received a copy of the GNU General Public License
2N/A * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
2N/A */
2N/A
2N/A#include <grub/kernel.h>
2N/A#include <grub/misc.h>
2N/A#include <grub/types.h>
2N/A#include <grub/ieee1275/ieee1275.h>
2N/A
2N/Aint (*grub_ieee1275_entry_fn) (void *);
2N/A
2N/Agrub_ieee1275_phandle_t grub_ieee1275_chosen;
2N/Agrub_ieee1275_ihandle_t grub_ieee1275_mmu;
2N/A
2N/Astatic grub_uint32_t grub_ieee1275_flags;
2N/A
2N/A
2N/A
2N/Aint
2N/Agrub_ieee1275_test_flag (enum grub_ieee1275_flag flag)
2N/A{
2N/A return (grub_ieee1275_flags & (1 << flag));
2N/A}
2N/A
2N/Avoid
2N/Agrub_ieee1275_set_flag (enum grub_ieee1275_flag flag)
2N/A{
2N/A grub_ieee1275_flags |= (1 << flag);
2N/A}
2N/A
2N/A#define SF "SmartFirmware(tm)"
2N/A#define OHW "PPC Open Hack'Ware"
2N/A
2N/Astatic void
2N/Agrub_ieee1275_find_options (void)
2N/A{
2N/A grub_ieee1275_phandle_t root;
2N/A grub_ieee1275_phandle_t options;
2N/A grub_ieee1275_phandle_t openprom;
2N/A grub_ieee1275_phandle_t bootrom;
2N/A int rc;
2N/A grub_uint32_t realmode = 0;
2N/A char tmp[32];
2N/A int is_smartfirmware = 0;
2N/A int is_olpc = 0;
2N/A int is_qemu = 0;
2N/A
2N/A#ifdef __sparc__
2N/A grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_NO_PARTITION_0);
2N/A#endif
2N/A
2N/A grub_ieee1275_finddevice ("/", &root);
2N/A grub_ieee1275_finddevice ("/options", &options);
2N/A grub_ieee1275_finddevice ("/openprom", &openprom);
2N/A
2N/A rc = grub_ieee1275_get_integer_property (options, "real-mode?", &realmode,
2N/A sizeof realmode, 0);
2N/A if (((rc >= 0) && realmode) || (grub_ieee1275_mmu == 0))
2N/A grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_REAL_MODE);
2N/A
2N/A rc = grub_ieee1275_get_property (openprom, "CodeGen-copyright",
2N/A tmp, sizeof (tmp), 0);
2N/A if (rc >= 0 && !grub_strncmp (tmp, SF, sizeof (SF) - 1))
2N/A is_smartfirmware = 1;
2N/A
2N/A rc = grub_ieee1275_get_property (root, "architecture",
2N/A tmp, sizeof (tmp), 0);
2N/A if (rc >= 0 && !grub_strcmp (tmp, "OLPC"))
2N/A is_olpc = 1;
2N/A
2N/A rc = grub_ieee1275_get_property (root, "model",
2N/A tmp, sizeof (tmp), 0);
2N/A if (rc >= 0 && !grub_strcmp (tmp, "Emulated PC"))
2N/A is_qemu = 1;
2N/A
2N/A if (grub_strncmp (tmp, "PowerMac", sizeof ("PowerMac") - 1) == 0)
2N/A grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_BROKEN_ADDRESS_CELLS);
2N/A
2N/A if (is_smartfirmware)
2N/A {
2N/A /* Broken in all versions */
2N/A grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_BROKEN_OUTPUT);
2N/A
2N/A /* There are two incompatible ways of checking the version number. Try
2N/A both. */
2N/A rc = grub_ieee1275_get_property (openprom, "SmartFirmware-version",
2N/A tmp, sizeof (tmp), 0);
2N/A if (rc < 0)
2N/A rc = grub_ieee1275_get_property (openprom, "firmware-version",
2N/A tmp, sizeof (tmp), 0);
2N/A if (rc >= 0)
2N/A {
2N/A /* It is tempting to implement a version parser to set the flags for
2N/A e.g. 1.3 and below. However, there's a special situation here.
2N/A 3rd party updates which fix the partition bugs are common, and for
2N/A some reason their fixes aren't being merged into trunk. So for
2N/A example we know that 1.2 and 1.3 are broken, but there's 1.2.99
2N/A and 1.3.99 which are known good (and applying this workaround
2N/A would cause breakage). */
2N/A if (!grub_strcmp (tmp, "1.0")
2N/A || !grub_strcmp (tmp, "1.1")
2N/A || !grub_strcmp (tmp, "1.2")
2N/A || !grub_strcmp (tmp, "1.3"))
2N/A {
2N/A grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_NO_PARTITION_0);
2N/A grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_0_BASED_PARTITIONS);
2N/A }
2N/A }
2N/A }
2N/A
2N/A if (is_olpc)
2N/A {
2N/A /* OLPC / XO laptops have three kinds of storage devices:
2N/A
2N/A - NAND flash. These are accessible via OFW callbacks, but:
2N/A - Follow strange semantics, imposed by hardware constraints.
2N/A - Its ABI is undocumented, and not stable.
2N/A They lack "device_type" property, which conveniently makes GRUB
2N/A skip them.
2N/A
2N/A - USB drives. Not accessible, because OFW shuts down the controller
2N/A in order to prevent collisions with applications accessing it
2N/A directly. Even worse, attempts to access it will NOT return
2N/A control to the caller, so we have to avoid probing them.
2N/A
2N/A - SD cards. These work fine.
2N/A
2N/A To avoid breakage, we only need to skip USB probing. However,
2N/A since detecting SD cards is more reliable, we do that instead.
2N/A */
2N/A
2N/A grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_OFDISK_SDCARD_ONLY);
2N/A grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_HAS_CURSORONOFF);
2N/A }
2N/A
2N/A if (is_qemu)
2N/A {
2N/A /* OpenFirmware hangs on qemu if one requests any memory below 1.5 MiB. */
2N/A grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_NO_PRE1_5M_CLAIM);
2N/A
2N/A grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_HAS_CURSORONOFF);
2N/A }
2N/A
2N/A if (! grub_ieee1275_finddevice ("/rom/boot-rom", &bootrom))
2N/A {
2N/A rc = grub_ieee1275_get_property (bootrom, "model", tmp, sizeof (tmp), 0);
2N/A if (rc >= 0 && !grub_strncmp (tmp, OHW, sizeof (OHW) - 1))
2N/A {
2N/A grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_BROKEN_OUTPUT);
2N/A grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_CANNOT_SET_COLORS);
2N/A grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_CANNOT_INTERPRET);
2N/A grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_FORCE_CLAIM);
2N/A grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_NO_ANSI);
2N/A }
2N/A }
2N/A}
2N/A
2N/A#undef SF
2N/A#undef OHW
2N/A
2N/Avoid
2N/Agrub_ieee1275_init (void)
2N/A{
2N/A grub_ieee1275_finddevice ("/chosen", &grub_ieee1275_chosen);
2N/A
2N/A if (grub_ieee1275_get_integer_property (grub_ieee1275_chosen, "mmu", &grub_ieee1275_mmu,
2N/A sizeof grub_ieee1275_mmu, 0) < 0)
2N/A grub_ieee1275_mmu = 0;
2N/A
2N/A grub_ieee1275_find_options ();
2N/A}