2004-03-28 21:52:02 +00:00
|
|
|
|
/* cmain.c - Startup code for the PowerPC. */
|
|
|
|
|
/*
|
2004-04-04 13:46:03 +00:00
|
|
|
|
* GRUB -- GRand Unified Bootloader
|
2008-01-19 11:41:00 +00:00
|
|
|
|
* Copyright (C) 2003,2004,2005,2006,2007,2008 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
|
|
|
|
*/
|
|
|
|
|
|
2004-12-27 Marco Gerards <metgerards@student.han.nl>
* genmk.rb: Handle the `Program' class in the main loop. Written
by Johan Rydberg <jrydberg@gnu.org>.
(Program): New class.
(programs): New variable.
* boot/powerpc/ieee1275/cmain.c: Include <grub/machine/ieee1275.h>
instead of "grub/machine/ieee1275.h". Include <grub/kernel.h>
instead of "grub/kernel.h". Include <grub/machine/init.h>.
(help_arch): Function removed.
* conf/powerpc-ieee1275.rmk (grubof_HEADERS): Add
`powerpc/libgcc.h' and `loader.h'.
(pkgdata_PROGRAMS): New variable.
(sbin_UTILITIES): Variable removed.
(grub_emu_SOURCES): Added kern/powerpc/cache.S.
(grubof_SOURCES): Variable re-defined so it only includes the
core functionality.
(grubof_CFLAGS): Remove `-DGRUBOF'.
(pkgdata_MODULES, fshelp_mod_SOURCES, fshelp_mod_CFLAGS,
(fat_mod_SOURCES, fat_mod_CFLAGS, ext2_mod_SOURCES)
(ext2_mod_CFLAGS, ufs_mod_SOURCES, ufs_mod_CFLAGS)
(minix_mod_SOURCES, minix_mod_CFLAGS, hfs_mod_SOURCES)
(hfs_mod_CFLAGS, jfs_mod_SOURCES, jfs_mod_CFLAGS)
(iso9660_mod_SOURCES, iso9660_mod_CFLAGS, _linux_mod_SOURCES)
(_linux_mod_CFLAGS, linux_mod_SOURCES, linux_mod_CFLAGS)
(normal_mod_SOURCES, normal_mod_CFLAGS, normal_mod_ASFLAGS)
(hello_mod_SOURCES, hello_mod_CFLAGS, boot_mod_SOURCES)
(boot_mod_CFLAGS, terminal_mod_SOURCES, terminal_mod_CFLAGS)
(ls_mod_SOURCES, ls_mod_CFLAGS, cmp_mod_SOURCES, cmp_mod_CFLAGS)
(cat_mod_SOURCES, cat_mod_CFLAGS, font_mod_SOURCES)
(font_mod_CFLAGS, amiga_mod_SOURCES, amiga_mod_CFLAGS)
(apple_mod_SOURCES, apple_mod_CFLAGS, pc_mod_SOURCES)
(pc_mod_CFLAGS): New variables.
* disk/powerpc/ieee1275/ofdisk.c: Include <grub/machine/init.h>.
(grub_ofdisk_iterate): Add a prototype for `dev_iterate'.
* include/grub/dl.h (grub_arch_dl_sync_caches): New prototype.
* include/grub/loader.h (grub_os_area_addr, grub_os_area_size):
Moved from here...
* include/grub/i386/pc/init.h (grub_os_area_addr)
(rub_os_area_size): ... to here.
* include/grub/powerpc/ieee1275/ieee1275.h
(grub_ieee1275_entry_fn): Export symbol.
* include/grub/powerpc/ieee1275/init.h: New file.
* include/grub/powerpc/libgcc.h: Likewise.
* include/grub/cache.h: Likewise.
* kern/powerpc/cache.S: Likewise. Written by Hollis Blanchard
<hollis@penguinppc.org>.
* kern/dl.c: Include <grub/cache.h>.
(grub_dl_flush_cache): New function.
(grub_dl_load_core): Call `grub_dl_flush_cache' to flush the cache
for this module.
* kern/powerpc/ieee1275/init.c (grub_ofdisk_init)
(grub_console_init): Removed prototypes.
(grub_machine_init): Don't initialize the modules anymore.
* kern/powerpc/ieee1275/openfw.c (grub_map): Make the function
static.
* include/grub/powerpc/types.h (GRUB_HOST_WORDS_LITTLEENDIAN):
Macro undef removed.
(GRUB_HOST_WORDS_BIGENDIAN): New macro.
* kern/powerpc/dl.c (grub_arch_dl_relocate_symbols): Add
relocation `R_PPC_REL32'. Return an error when the relocation is
unknown.
* Makefile.in (DATA): Add `$(pkgdata_PROGRAMS)'.
* kern/i386/pc/init.c (grub_arch_sync_caches): New function.
* util/misc.c (grub_arch_sync_caches): Likewise.
2004-12-27 13:46:20 +00:00
|
|
|
|
#include <grub/kernel.h>
|
2006-09-26 03:49:41 +00:00
|
|
|
|
#include <grub/misc.h>
|
2006-12-08 21:16:47 +00:00
|
|
|
|
#include <grub/types.h>
|
2005-08-03 22:53:51 +00:00
|
|
|
|
#include <grub/machine/kernel.h>
|
|
|
|
|
#include <grub/ieee1275/ieee1275.h>
|
2004-03-28 21:52:02 +00:00
|
|
|
|
|
2005-08-03 22:53:51 +00:00
|
|
|
|
int (*grub_ieee1275_entry_fn) (void *);
|
2004-03-28 21:52:02 +00:00
|
|
|
|
|
2005-06-21 02:33:52 +00:00
|
|
|
|
grub_ieee1275_phandle_t grub_ieee1275_chosen;
|
2008-01-20 14:08:54 +00:00
|
|
|
|
grub_ieee1275_ihandle_t grub_ieee1275_mmu;
|
2005-06-21 02:33:52 +00:00
|
|
|
|
|
2005-05-01 03:45:36 +00:00
|
|
|
|
static grub_uint32_t grub_ieee1275_flags;
|
2004-03-28 21:52:02 +00:00
|
|
|
|
|
2005-01-03 17:44:25 +00:00
|
|
|
|
|
2007-09-07 21:59:03 +00:00
|
|
|
|
|
2005-05-01 03:45:36 +00:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-24 08:21:43 +00:00
|
|
|
|
#define SF "SmartFirmware(tm)"
|
|
|
|
|
#define OHW "PPC Open Hack'Ware"
|
|
|
|
|
|
2005-01-03 17:44:25 +00:00
|
|
|
|
static void
|
2005-05-01 03:45:36 +00:00
|
|
|
|
grub_ieee1275_find_options (void)
|
2005-01-03 17:44:25 +00:00
|
|
|
|
{
|
2008-01-22 20:13:14 +00:00
|
|
|
|
grub_ieee1275_phandle_t root;
|
2005-01-03 17:44:25 +00:00
|
|
|
|
grub_ieee1275_phandle_t options;
|
2005-05-01 03:45:36 +00:00
|
|
|
|
grub_ieee1275_phandle_t openprom;
|
2008-01-24 08:21:43 +00:00
|
|
|
|
grub_ieee1275_phandle_t bootrom;
|
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
|
|
|
|
int rc;
|
2008-04-04 06:45:07 +00:00
|
|
|
|
grub_uint32_t realmode = 0;
|
2007-09-07 21:59:03 +00:00
|
|
|
|
char tmp[32];
|
|
|
|
|
int is_smartfirmware = 0;
|
2008-01-22 20:13:14 +00:00
|
|
|
|
int is_olpc = 0;
|
2005-01-03 17:44:25 +00:00
|
|
|
|
|
2008-01-22 20:13:14 +00:00
|
|
|
|
grub_ieee1275_finddevice ("/", &root);
|
2005-01-03 17:44:25 +00:00
|
|
|
|
grub_ieee1275_finddevice ("/options", &options);
|
2008-01-22 20:13:14 +00:00
|
|
|
|
grub_ieee1275_finddevice ("/openprom", &openprom);
|
|
|
|
|
|
2008-01-15 16:14:33 +00:00
|
|
|
|
rc = grub_ieee1275_get_integer_property (options, "real-mode?", &realmode,
|
|
|
|
|
sizeof realmode, 0);
|
2008-01-20 14:08:54 +00:00
|
|
|
|
if (((rc >= 0) && realmode) || (grub_ieee1275_mmu == 0))
|
2005-05-01 03:45:36 +00:00
|
|
|
|
grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_REAL_MODE);
|
|
|
|
|
|
2007-09-07 21:59:03 +00:00
|
|
|
|
rc = grub_ieee1275_get_property (openprom, "CodeGen-copyright",
|
|
|
|
|
tmp, sizeof (tmp), 0);
|
|
|
|
|
if (rc >= 0 && !grub_strncmp (tmp, SF, sizeof (SF) - 1))
|
|
|
|
|
is_smartfirmware = 1;
|
|
|
|
|
|
2008-01-22 20:13:14 +00:00
|
|
|
|
rc = grub_ieee1275_get_property (root, "architecture",
|
|
|
|
|
tmp, sizeof (tmp), 0);
|
|
|
|
|
if (rc >= 0 && !grub_strcmp (tmp, "OLPC"))
|
|
|
|
|
is_olpc = 1;
|
|
|
|
|
|
2007-09-07 21:59:03 +00:00
|
|
|
|
if (is_smartfirmware)
|
2007-07-22 09:05:11 +00:00
|
|
|
|
{
|
2007-09-07 21:59:03 +00:00
|
|
|
|
/* Broken in all versions */
|
2007-07-22 09:05:11 +00:00
|
|
|
|
grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_BROKEN_OUTPUT);
|
2007-09-07 21:59:03 +00:00
|
|
|
|
|
|
|
|
|
/* 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
|
2007-12-30 08:52:06 +00:00
|
|
|
|
and 1.3.99 which are known good (and applying this workaround
|
2007-09-07 21:59:03 +00:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-07-22 09:05:11 +00:00
|
|
|
|
}
|
2008-01-22 20:13:14 +00:00
|
|
|
|
|
|
|
|
|
if (is_olpc)
|
|
|
|
|
{
|
|
|
|
|
/* OLPC / XO laptops have three kinds of storage devices:
|
|
|
|
|
|
|
|
|
|
- NAND flash. These are accessible via OFW callbacks, but:
|
|
|
|
|
- Follow strange semantics, imposed by hardware constraints.
|
|
|
|
|
- Its ABI is undocumented, and not stable.
|
|
|
|
|
They lack "device_type" property, which conveniently makes GRUB
|
|
|
|
|
skip them.
|
|
|
|
|
|
|
|
|
|
- USB drives. Not accessible, because OFW shuts down the controller
|
|
|
|
|
in order to prevent collisions with applications accessing it
|
|
|
|
|
directly. Even worse, attempts to access it will NOT return
|
|
|
|
|
control to the caller, so we have to avoid probing them.
|
|
|
|
|
|
|
|
|
|
- SD cards. These work fine.
|
|
|
|
|
|
2009-05-04 20:06:05 +00:00
|
|
|
|
To avoid breakage, we only need to skip USB probing. However,
|
2008-01-22 20:13:14 +00:00
|
|
|
|
since detecting SD cards is more reliable, we do that instead.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_OFDISK_SDCARD_ONLY);
|
|
|
|
|
}
|
2008-01-24 08:21:43 +00:00
|
|
|
|
|
|
|
|
|
if (! grub_ieee1275_finddevice ("/rom/boot-rom", &bootrom))
|
|
|
|
|
{
|
|
|
|
|
rc = grub_ieee1275_get_property (bootrom, "model", tmp, sizeof (tmp), 0);
|
|
|
|
|
if (rc >= 0 && !grub_strncmp (tmp, OHW, sizeof (OHW) - 1))
|
|
|
|
|
{
|
|
|
|
|
grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_BROKEN_OUTPUT);
|
|
|
|
|
grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_CANNOT_SET_COLORS);
|
2008-07-02 07:38:46 +00:00
|
|
|
|
grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_CANNOT_INTERPRET);
|
|
|
|
|
grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_FORCE_CLAIM);
|
|
|
|
|
grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_NO_ANSI);
|
2008-01-24 08:21:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2005-01-03 17:44:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-01-24 08:21:43 +00:00
|
|
|
|
#undef SF
|
|
|
|
|
#undef OHW
|
|
|
|
|
|
2004-03-28 21:52:02 +00:00
|
|
|
|
void
|
2008-04-18 15:53:20 +00:00
|
|
|
|
grub_ieee1275_init (void)
|
2004-03-28 21:52:02 +00:00
|
|
|
|
{
|
2005-06-21 03:12:15 +00:00
|
|
|
|
grub_ieee1275_finddevice ("/chosen", &grub_ieee1275_chosen);
|
|
|
|
|
|
2008-01-20 14:08:54 +00:00
|
|
|
|
if (grub_ieee1275_get_integer_property (grub_ieee1275_chosen, "mmu", &grub_ieee1275_mmu,
|
|
|
|
|
sizeof grub_ieee1275_mmu, 0) < 0)
|
|
|
|
|
grub_ieee1275_mmu = 0;
|
|
|
|
|
|
2005-05-01 03:45:36 +00:00
|
|
|
|
grub_ieee1275_find_options ();
|
2004-03-28 21:52:02 +00:00
|
|
|
|
}
|