abee94edf9
* grub-core/Makefile.core.def (kernel): Use kern/ieee1275/init.c instead of kern/sparc64/ieee1275/init.c. * grub-core/kern/ieee1275/cmain.c (grub_ieee1275_find_options) [__sparc__]: Set GRUB_IEEE1275_FLAG_NO_PARTITION_0. * grub-core/kern/ieee1275/init.c [__sparc__]: Include grub/machine/kernel.h. (grub_ieee1275_original_stack) [__sparc__]: New variable. (grub_claim_heap) [__sparc__]: Use sparc version. (grub_machine_init): Moved args parsing to (grub_parse_cmdline): ...this. * grub-core/kern/sparc64/ieee1275/init.c: Removed. * include/grub/offsets.h (GRUB_KERNEL_SPARC64_IEEE1275_MOD_GAP): New definition. (GRUB_KERNEL_SPARC64_IEEE1275_MOD_ALIGN): Likewise. Move BOOTP to separate file. * grub-core/Makefile.core.def (net): Add net/bootp.c. * grub-core/net/net.c: Move all BOOTP functions to * grub-core/net/bootp.c: ... here. Use frame interface on PXE. * grub-core/Makefile.core.def (pxecmd): Removed. (pxe): Use net/drivers/i386/pc/pxe.c rather than net/i386/pc/pxe.c. * grub-core/commands/i386/pc/pxecmd.c: Removed. * grub-core/i386/pc/pxe.c: Moved from here ... * grub-core/net/i386/pc/pxe.c: ... here. Rewritten. * grub-core/net/net.c (grub_net_open_real): Handle old pxe syntax. * include/grub/i386/pc/pxe.h (grub_pxe_unload): Removed. EFI network support. * grub-core/Makefile.core.def (efinet): New module. * grub-core/disk/efi/efidisk.c (compare_device_paths): Moved from here... * grub-core/kern/efi/efi.c (grub_efi_compare_device_paths): ... here. All users updated. * grub-core/kern/efi/init.c (grub_efi_net_config): New variable. (grub_machine_get_bootlocation): Call grub_efi_net_config if needed. * grub-core/kern/x86_64/efi/callwrap.S (efi_wrap_7): New function. * grub-core/net/drivers/efi/efinet.c: New file. * include/grub/efi/efi.h (grub_efi_compare_device_paths): New proto. (grub_efi_net_config): New extern var. Various cleanups and bugfixes. * grub-core/disk/efi/efidisk.c (grub_efidisk_open): Fix off-by-one error. (grub_efidisk_get_device_name): Unify similar codepaths. Accept whole disk declared as partition. * grub-core/disk/ieee1275/ofdisk.c (grub_ofdisk_open): Fix memory leak on failure. * grub-core/kern/dl.c (grub_dl_load_file): Fix memory leak. * grub-core/kern/mm.c (grub_debug_malloc): Don't use unsupported %zx. (grub_debug_zalloc): Likewise. (grub_debug_realloc): Likewise. (grub_debug_memalign): Likewise. * grub-core/net/arp.c (grub_net_arp_receive): IPv4 is 4-byte wide. Check that target is IPv4. * grub-core/net/drivers/ieee1275/ofnet.c (grub_ofnet_findcards): Use local-mac-address as fallback. * grub-core/net/ethernet.c (grub_net_recv_ethernet_packet): Prevent memory leak. * grub-core/net/ip.c (ipchksum): Rename to ... (grub_net_ip_chksum): ... this. All users updated. (grub_net_recv_ip_packets): Special handling for DHCP. * util/grub-mkimage.c (generate_image): Zero-out aout header. Unify prefix handling * grub-core/kern/efi/init.c (grub_efi_set_prefix): Revamped into ... (grub_machine_get_bootlocation): ... this. * grub-core/kern/emu/main.c (grub_machine_set_prefix): Revamped into ... (grub_machine_get_bootlocation): ... this. (grub_prefix): New variable. (prefix): Removed. (root_dev): New variable. (dir): Likewise. (main): Use new variables. * grub-core/kern/i386/coreboot/init.c (grub_machine_set_prefix): Revamped into ... (grub_machine_get_bootlocation): ... this. * grub-core/kern/i386/efi/init.c (grub_machine_set_prefix): Removed. * grub-core/kern/i386/pc/init.c (make_install_device): Revamped into ... (grub_machine_get_bootlocation): ... this. (grub_machine_set_prefix): Removed. * grub-core/kern/ia64/efi/init.c (grub_machine_set_prefix): Removed. * grub-core/kern/ieee1275/init.c (grub_machine_set_prefix): Revamped into ... (grub_machine_get_bootlocation): ... this. * grub-core/kern/main.c (grub_set_root_dev): Revamped into ... (grub_set_prefix_and_root): ... this. All users updated. * grub-core/kern/mips/init.c (grub_machine_set_prefix): Revamped into ... (grub_machine_get_bootlocation): ... this. * include/grub/kernel.h (grub_machine_set_prefix): Removed. (grub_machine_get_bootlocation): New proto. * include/grub/i386/pc/kernel.h (grub_pc_net_config): New var. Less intrusive and more reliable seek on network implementation. * grub-core/kern/file.c (grub_file_net_seek): Removed. (grub_file_seek): Don't call grub_file_net_seek. * grub-core/net/net.c (grub_net_fs_read): Renamed to ... (grub_net_fs_read_real): .. this. (grub_net_seek_real): Use net->offset. (grub_net_fs_read): Seek if necessary. Unify IEEE1275 netwotk config with the other platforms. * grub-core/kern/ieee1275/init.c (grub_ieee1275_net_config): New variable. (grub_machine_get_bootlocation): Support network. * grub-core/kern/ieee1275/openfw.c (grub_ieee1275_parse_args): Support type and device parsing. (grub_ieee1275_get_device_type): New function. * grub-core/net/drivers/ieee1275/ofnet.c (grub_getbootp_real): Revamped into ... (grub_ieee1275_net_config_real): ... this. (grub_ofnet_probecards): Removed. * grub-core/Makefile.am (KERNEL_HEADER_FILES): Remove ofnet.h. * include/grub/ieee1275/ofnet.h: Removed. * include/grub/ieee1275/ieee1275.h (grub_ieee1275_net_config): NEw extern var. (grub_ieee1275_get_device_type): New function. Unify network device closing across platforms and make more robust. * grub-core/kern/ieee1275/init.c (grub_machine_fini): Don't call grub_grubnet_fini. * grub-core/net/ethernet.c (send_ethernet_packet): Open card if it isn't already. * grub-core/net/net.c (grub_net_network_level_interface_register): Update num_ifaces. (grub_net_card_unregister): Close all interfaces. (receive_packets): Don't poll if no iterfaces are registered. Open if necessary. (grub_net_fini_hw): New function. (grub_net_restore_hw): Likewise. (fini_hnd): New variable. (GRUB_MOD_INIT): Register preboot hook. (GRUB_MOD_FINI): Run and unregister preboot hook. Poll network cards when idle. * grub-core/kern/term.c (grub_net_poll_cards_idle): New variable. (grub_checkkey): Call grub_net_poll_cards_idle if it's not NULL. * grub-core/net/net.c (receive_packets): Save last poll time. (grub_net_poll_cards_idle_real): New function. (GRUB_MOD_INIT): Register grub_net_poll_cards_idle. (GRUB_MOD_FINI): Unregister grub_net_poll_cards_idle. * include/grub/kernel.h (grub_poll_cards_idle): New extern variable. Rename ofnet interfaces. * grub-core/net/drivers/ieee1275/ofnet.c (find_alias): New function. (grub_ofnet_findcards): Use ofnet_%s names. * util/grub-mknetdir.in: Support for EFI and IEEE1275. Cleanup socket opening. * grub-core/net/net.c (grub_net_fs_open): Rewritten. (grub_net_fs_close): Likewise. (grub_net_fs_read_real): Use eof member. * include/grub/net/udp.h (+grub_net_udp_open): New proto. (+grub_net_udp_close): New inline function. * include/grub/net/tftp.h: Moved to the top of ... * grub-core/net/tftp.c: ... here. * include/grub/net/ip.h: Moved mostly to the top of ... * grub-core/net/ip.c: ... here. * include/grub/net/ethernet.h: Moved mostly to the top of ... * grub-core/net/ethernet.c: ... here. * grub-core/kern/device.c (grub_device_close): Free device->net->server. * grub-core/commands/probe.c (grub_cmd_probe): Use protocol name for FS name. * include/grub/net/ip.h (ipv4_ini): Removed. (ipv4_fini): Likewise. * include/grub/net/ip.h (grub_net_recv_ip_packets): New proto. (grub_net_send_ip_packets): Likewise.
186 lines
5.9 KiB
C
186 lines
5.9 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 <grub/kernel.h>
|
||
#include <grub/misc.h>
|
||
#include <grub/types.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);
|
||
}
|
||
|
||
#define SF "SmartFirmware(tm)"
|
||
#define OHW "PPC Open Hack'Ware"
|
||
|
||
static void
|
||
grub_ieee1275_find_options (void)
|
||
{
|
||
grub_ieee1275_phandle_t root;
|
||
grub_ieee1275_phandle_t options;
|
||
grub_ieee1275_phandle_t openprom;
|
||
grub_ieee1275_phandle_t bootrom;
|
||
int rc;
|
||
grub_uint32_t realmode = 0;
|
||
char tmp[32];
|
||
int is_smartfirmware = 0;
|
||
int is_olpc = 0;
|
||
int is_qemu = 0;
|
||
|
||
#ifdef __sparc__
|
||
grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_NO_PARTITION_0);
|
||
#endif
|
||
|
||
grub_ieee1275_finddevice ("/", &root);
|
||
grub_ieee1275_finddevice ("/options", &options);
|
||
grub_ieee1275_finddevice ("/openprom", &openprom);
|
||
|
||
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);
|
||
|
||
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;
|
||
|
||
rc = grub_ieee1275_get_property (root, "architecture",
|
||
tmp, sizeof (tmp), 0);
|
||
if (rc >= 0 && !grub_strcmp (tmp, "OLPC"))
|
||
is_olpc = 1;
|
||
|
||
rc = grub_ieee1275_get_property (root, "model",
|
||
tmp, sizeof (tmp), 0);
|
||
if (rc >= 0 && !grub_strcmp (tmp, "Emulated PC"))
|
||
is_qemu = 1;
|
||
|
||
if (grub_strncmp (tmp, "PowerMac", sizeof ("PowerMac") - 1) == 0)
|
||
grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_BROKEN_ADDRESS_CELLS);
|
||
|
||
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);
|
||
}
|
||
}
|
||
}
|
||
|
||
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.
|
||
|
||
To avoid breakage, we only need to skip USB probing. However,
|
||
since detecting SD cards is more reliable, we do that instead.
|
||
*/
|
||
|
||
grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_OFDISK_SDCARD_ONLY);
|
||
grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_HAS_CURSORONOFF);
|
||
}
|
||
|
||
if (is_qemu)
|
||
{
|
||
/* OpenFirmware hangs on qemu if one requests any memory below 1.5 MiB. */
|
||
grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_NO_PRE1_5M_CLAIM);
|
||
|
||
grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_HAS_CURSORONOFF);
|
||
}
|
||
|
||
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);
|
||
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);
|
||
}
|
||
}
|
||
}
|
||
|
||
#undef SF
|
||
#undef OHW
|
||
|
||
void
|
||
grub_ieee1275_init (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 ();
|
||
}
|