grub/grub-core/loader/xnu.c

1491 lines
37 KiB
C
Raw Normal View History

2009-06-10 21:04:23 +00:00
/* xnu.c - load xnu kernel. Thanks to Florian Idelberger for all the
time he spent testing this
*/
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2009 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/file.h>
#include <grub/xnu.h>
#include <grub/cpu/xnu.h>
#include <grub/mm.h>
#include <grub/dl.h>
#include <grub/loader.h>
#include <grub/machoload.h>
#include <grub/macho.h>
#include <grub/cpu/macho.h>
#include <grub/command.h>
#include <grub/misc.h>
2009-11-20 09:46:30 +00:00
#include <grub/extcmd.h>
2009-11-09 17:43:53 +00:00
#include <grub/env.h>
2010-01-08 Carles Pina i Estany <carles@pina.cat> * loader/efi/appleloader.c: Include `<grub/i18n.h>'. (GRUB_MOD_INIT): Gettextizze. * loader/efi/chainloader.c: Include `<grub/i18n.h>'. (GRUB_MOD_INIT): Gettextizze. * loader/i386/efi/linux.c: Include `<grub/i18n.h>'. (grub_cmd_linux): Capitalise Linux. (GRUB_MOD_INIT): Gettextizze. * loader/i386/ieee1275/linux.c: Include `<grub/i18n.h>'. (grub_cmd_linux): Capitalise Linux. (GRUB_MOD_INIT): Gettextizze. * loader/i386/linux.c: Include `<grub/i18n.h>'. (grub_cmd_linux): Capitalise Linux. (GRUB_MOD_INIT): Gettextizze. * loader/i386/pc/chainloader.c: Include `<grub/i18n.h>'. (GRUB_MOD_INIT): Gettextizze. * loader/i386/pc/linux.c: Include `<grub/i18n.h>'. (grub_cmd_linux): Capitalise Linux. (GRUB_MOD_INIT): Gettextizze. * loader/i386/xnu.c: Include `<grub/i18n.h>'. (grub_cpu_xnu_init): Gettextizze. * loader/multiboot_loader.c: Include `<grub/i18n.h>'. (GRUB_MOD_INIT): Gettextizze. * loader/powerpc/ieee1275/linux.c: Include `<grub/i18n.h>'. (GRUB_MOD_INIT): Gettextizze. * loader/sparc64/ieee1275/linux.c: Include `<grub/i18n.h>'. (grub_linux_load64): Capitalise Linux. (GRUB_MOD_INIT): Gettextizze. * loader/xnu.c: Include `<grub/i18n.h>'. (GRUB_MOD_INIT): Gettextizze. * po/POTFILES: Add `loader/efi/appleloader.c', `loader/efi/chainloader.c', `loader/i386/efi/linux.c', `loader/i386/ieee1275/linux.c', `loader/i386/linux.c', `loader/i386/pc/chainloader.c', `loader/i386/pc/linux.c', `loader/i386/xnu.c', `loader/multiboot_loader.c', `loader/powerpc/ieee1275/linux.c', `loader/sparc64/ieee1275/linux.c' and `loader/xnu.c'.
2010-01-08 21:35:38 +00:00
#include <grub/i18n.h>
GRUB_MOD_LICENSE ("GPLv3+");
#if defined (__i386) && !defined (GRUB_MACHINE_EFI)
#include <grub/autoefi.h>
#endif
struct grub_xnu_devtree_key *grub_xnu_devtree_root = 0;
static int driverspackagenum = 0;
static int driversnum = 0;
2009-09-02 11:34:40 +00:00
int grub_xnu_is_64bit = 0;
int grub_xnu_darwin_version = 0;
2010-01-11 12:43:44 +00:00
grub_addr_t grub_xnu_heap_target_start = 0;
2009-11-27 08:42:50 +00:00
grub_size_t grub_xnu_heap_size = 0;
2010-01-11 12:43:44 +00:00
struct grub_relocator *grub_xnu_relocator;
static grub_err_t
Add missing const qualifiers. * grub-core/commands/i386/pc/sendkey.c (keysym): Add missing const. * grub-core/commands/lspci.c (grub_pci_classname): Likewise. * grub-core/commands/menuentry.c (hotkey_aliases): Likewise. * grub-core/disk/lvm.c (grub_lvm_getvalue): Likewise. (grub_lvm_check_flag): Likewise. * grub-core/efiemu/i386/coredetect.c (grub_efiemu_get_default_core_name): Likewise * grub-core/efiemu/main.c (grub_efiemu_autocore): Likewise. * grub-core/fs/hfsplus.c (grub_hfsplus_catkey_internal): Likewise. * grub-core/fs/ntfs.c (fixup): Likewise. * grub-core/fs/xfs.c (grub_xfs_iterate_dir): Likewise. * grub-core/fs/zfs/zfs.c (decomp_entry): Likewise. (fzap_lookup): Likewise. (zap_lookup): Likewise. * grub-core/gnulib/regcomp.c (init_dfa): Likewise. * grub-core/lib/legacy_parse.c (check_option): Likewise. * grub-core/lib/posix_wrap/langinfo.h (nl_langinfo): Likewise. * grub-core/loader/i386/bsd.c (grub_bsd_add_meta): Likewise. (grub_freebsd_add_meta_module): Likewise. (grub_cmd_freebsd_module): Likewise. * grub-core/loader/i386/xnu.c (tbl_alias): Likewise. * grub-core/loader/xnu.c (grub_xnu_register_memory): Likewise. (grub_xnu_writetree_get_size): Likewise. (grub_xnu_writetree_toheap_real): Likewise. (grub_xnu_find_key): Likewise. (grub_xnu_create_key): Likewise. (grub_xnu_create_value): Likewise. (grub_xnu_register_memory): Likewise. (grub_xnu_check_os_bundle_required): Likewise. (grub_xnu_scan_dir_for_kexts): Likewise. (grub_xnu_load_kext_from_dir): Likewise. * grub-core/normal/color.c (color_list): Likewise. * grub-core/normal/completion.c (current_word): Likewise. * grub-core/normal/menu_entry.c (insert_string): Likewise. * grub-core/term/serial.c (grub_serial_find): Likewise. * grub-core/term/tparm.c (grub_terminfo_tparm): Likewise. * include/grub/efiemu/efiemu.h (grub_efiemu_get_default_core_name): Likewise. * include/grub/i386/bsd.h (grub_bsd_add_meta): Likewise. (grub_freebsd_add_meta_module): Likewise. * include/grub/lib/arg.h (grub_arg_option): Likewise. * include/grub/net.h (grub_net_card_driver): Likewise. (grub_net_card): Likewise. (grub_net_app_protocol): Likewise. * include/grub/parttool.h (grub_parttool_argdesc): Likewise. * include/grub/serial.h (grub_serial_find): Likewise. * include/grub/tparm.h (grub_terminfo_tparm): Likewise. * include/grub/xnu.h (grub_xnu_create_key): Likewise. (grub_xnu_create_value): Likewise. (grub_xnu_find_key): Likewise. (grub_xnu_scan_dir_for_kexts): Likewise. (grub_xnu_load_kext_from_dir): Likewise. * include/grub/zfs/zio_checksum.h (zio_checksum_t): Moved from here ... * grub-core/fs/zfs/zfs.c (zio_checksum_t): ...here. * include/grub/zfs/zio_checksum.h (zio_checksum_info): Moved from here ... * grub-core/fs/zfs/zfs.c (zio_checksum_info): ... here. Added missing const.
2011-11-30 15:20:13 +00:00
grub_xnu_register_memory (const char *prefix, int *suffix,
2010-01-11 12:43:44 +00:00
grub_addr_t addr, grub_size_t size);
grub_err_t
grub_xnu_heap_malloc (int size, void **src, grub_addr_t *target)
{
2010-01-11 12:43:44 +00:00
grub_err_t err;
2010-04-21 17:13:45 +00:00
grub_relocator_chunk_t ch;
2010-01-11 12:43:44 +00:00
2010-04-21 17:13:45 +00:00
err = grub_relocator_alloc_chunk_addr (grub_xnu_relocator, &ch,
2010-01-11 12:43:44 +00:00
grub_xnu_heap_target_start
+ grub_xnu_heap_size, size);
if (err)
return err;
2010-04-21 17:13:45 +00:00
*src = get_virtual_current_address (ch);
2010-01-11 12:43:44 +00:00
*target = grub_xnu_heap_target_start + grub_xnu_heap_size;
grub_xnu_heap_size += size;
2010-01-11 12:43:44 +00:00
grub_dprintf ("xnu", "val=%p\n", *src);
return GRUB_ERR_NONE;
}
2009-06-10 21:04:23 +00:00
/* Make sure next block of the heap will be aligned.
Please notice: aligned are pointers AFTER relocation
and not the current ones. */
grub_err_t
grub_xnu_align_heap (int align)
{
2010-01-11 12:43:44 +00:00
grub_xnu_heap_size
= ALIGN_UP (grub_xnu_heap_target_start+ grub_xnu_heap_size, align)
- grub_xnu_heap_target_start;
return GRUB_ERR_NONE;
}
/* Free subtree pointed by CUR. */
void
grub_xnu_free_devtree (struct grub_xnu_devtree_key *cur)
{
struct grub_xnu_devtree_key *d;
while (cur)
{
grub_free (cur->name);
if (cur->datasize == -1)
grub_xnu_free_devtree (cur->first_child);
else if (cur->data)
grub_free (cur->data);
d = cur->next;
2009-06-10 21:04:23 +00:00
grub_free (cur);
cur = d;
2009-06-10 21:04:23 +00:00
}
}
/* Compute the size of device tree in xnu format. */
static grub_size_t
Add missing const qualifiers. * grub-core/commands/i386/pc/sendkey.c (keysym): Add missing const. * grub-core/commands/lspci.c (grub_pci_classname): Likewise. * grub-core/commands/menuentry.c (hotkey_aliases): Likewise. * grub-core/disk/lvm.c (grub_lvm_getvalue): Likewise. (grub_lvm_check_flag): Likewise. * grub-core/efiemu/i386/coredetect.c (grub_efiemu_get_default_core_name): Likewise * grub-core/efiemu/main.c (grub_efiemu_autocore): Likewise. * grub-core/fs/hfsplus.c (grub_hfsplus_catkey_internal): Likewise. * grub-core/fs/ntfs.c (fixup): Likewise. * grub-core/fs/xfs.c (grub_xfs_iterate_dir): Likewise. * grub-core/fs/zfs/zfs.c (decomp_entry): Likewise. (fzap_lookup): Likewise. (zap_lookup): Likewise. * grub-core/gnulib/regcomp.c (init_dfa): Likewise. * grub-core/lib/legacy_parse.c (check_option): Likewise. * grub-core/lib/posix_wrap/langinfo.h (nl_langinfo): Likewise. * grub-core/loader/i386/bsd.c (grub_bsd_add_meta): Likewise. (grub_freebsd_add_meta_module): Likewise. (grub_cmd_freebsd_module): Likewise. * grub-core/loader/i386/xnu.c (tbl_alias): Likewise. * grub-core/loader/xnu.c (grub_xnu_register_memory): Likewise. (grub_xnu_writetree_get_size): Likewise. (grub_xnu_writetree_toheap_real): Likewise. (grub_xnu_find_key): Likewise. (grub_xnu_create_key): Likewise. (grub_xnu_create_value): Likewise. (grub_xnu_register_memory): Likewise. (grub_xnu_check_os_bundle_required): Likewise. (grub_xnu_scan_dir_for_kexts): Likewise. (grub_xnu_load_kext_from_dir): Likewise. * grub-core/normal/color.c (color_list): Likewise. * grub-core/normal/completion.c (current_word): Likewise. * grub-core/normal/menu_entry.c (insert_string): Likewise. * grub-core/term/serial.c (grub_serial_find): Likewise. * grub-core/term/tparm.c (grub_terminfo_tparm): Likewise. * include/grub/efiemu/efiemu.h (grub_efiemu_get_default_core_name): Likewise. * include/grub/i386/bsd.h (grub_bsd_add_meta): Likewise. (grub_freebsd_add_meta_module): Likewise. * include/grub/lib/arg.h (grub_arg_option): Likewise. * include/grub/net.h (grub_net_card_driver): Likewise. (grub_net_card): Likewise. (grub_net_app_protocol): Likewise. * include/grub/parttool.h (grub_parttool_argdesc): Likewise. * include/grub/serial.h (grub_serial_find): Likewise. * include/grub/tparm.h (grub_terminfo_tparm): Likewise. * include/grub/xnu.h (grub_xnu_create_key): Likewise. (grub_xnu_create_value): Likewise. (grub_xnu_find_key): Likewise. (grub_xnu_scan_dir_for_kexts): Likewise. (grub_xnu_load_kext_from_dir): Likewise. * include/grub/zfs/zio_checksum.h (zio_checksum_t): Moved from here ... * grub-core/fs/zfs/zfs.c (zio_checksum_t): ...here. * include/grub/zfs/zio_checksum.h (zio_checksum_info): Moved from here ... * grub-core/fs/zfs/zfs.c (zio_checksum_info): ... here. Added missing const.
2011-11-30 15:20:13 +00:00
grub_xnu_writetree_get_size (struct grub_xnu_devtree_key *start,
const char *name)
{
grub_size_t ret;
struct grub_xnu_devtree_key *cur;
2009-06-10 21:04:23 +00:00
/* Key header. */
ret = 2 * sizeof (grub_uint32_t);
/* "name" value. */
ret += 32 + sizeof (grub_uint32_t)
2009-06-10 21:04:23 +00:00
+ grub_strlen (name) + 4
- (grub_strlen (name) % 4);
for (cur = start; cur; cur = cur->next)
if (cur->datasize != -1)
{
int align_overhead;
2009-06-10 21:04:23 +00:00
align_overhead = 4 - (cur->datasize % 4);
if (align_overhead == 4)
align_overhead = 0;
ret += 32 + sizeof (grub_uint32_t) + cur->datasize + align_overhead;
}
else
ret += grub_xnu_writetree_get_size (cur->first_child, cur->name);
return ret;
}
/* Write devtree in XNU format at curptr assuming the head is named NAME.*/
static void *
2009-06-10 21:04:23 +00:00
grub_xnu_writetree_toheap_real (void *curptr,
Add missing const qualifiers. * grub-core/commands/i386/pc/sendkey.c (keysym): Add missing const. * grub-core/commands/lspci.c (grub_pci_classname): Likewise. * grub-core/commands/menuentry.c (hotkey_aliases): Likewise. * grub-core/disk/lvm.c (grub_lvm_getvalue): Likewise. (grub_lvm_check_flag): Likewise. * grub-core/efiemu/i386/coredetect.c (grub_efiemu_get_default_core_name): Likewise * grub-core/efiemu/main.c (grub_efiemu_autocore): Likewise. * grub-core/fs/hfsplus.c (grub_hfsplus_catkey_internal): Likewise. * grub-core/fs/ntfs.c (fixup): Likewise. * grub-core/fs/xfs.c (grub_xfs_iterate_dir): Likewise. * grub-core/fs/zfs/zfs.c (decomp_entry): Likewise. (fzap_lookup): Likewise. (zap_lookup): Likewise. * grub-core/gnulib/regcomp.c (init_dfa): Likewise. * grub-core/lib/legacy_parse.c (check_option): Likewise. * grub-core/lib/posix_wrap/langinfo.h (nl_langinfo): Likewise. * grub-core/loader/i386/bsd.c (grub_bsd_add_meta): Likewise. (grub_freebsd_add_meta_module): Likewise. (grub_cmd_freebsd_module): Likewise. * grub-core/loader/i386/xnu.c (tbl_alias): Likewise. * grub-core/loader/xnu.c (grub_xnu_register_memory): Likewise. (grub_xnu_writetree_get_size): Likewise. (grub_xnu_writetree_toheap_real): Likewise. (grub_xnu_find_key): Likewise. (grub_xnu_create_key): Likewise. (grub_xnu_create_value): Likewise. (grub_xnu_register_memory): Likewise. (grub_xnu_check_os_bundle_required): Likewise. (grub_xnu_scan_dir_for_kexts): Likewise. (grub_xnu_load_kext_from_dir): Likewise. * grub-core/normal/color.c (color_list): Likewise. * grub-core/normal/completion.c (current_word): Likewise. * grub-core/normal/menu_entry.c (insert_string): Likewise. * grub-core/term/serial.c (grub_serial_find): Likewise. * grub-core/term/tparm.c (grub_terminfo_tparm): Likewise. * include/grub/efiemu/efiemu.h (grub_efiemu_get_default_core_name): Likewise. * include/grub/i386/bsd.h (grub_bsd_add_meta): Likewise. (grub_freebsd_add_meta_module): Likewise. * include/grub/lib/arg.h (grub_arg_option): Likewise. * include/grub/net.h (grub_net_card_driver): Likewise. (grub_net_card): Likewise. (grub_net_app_protocol): Likewise. * include/grub/parttool.h (grub_parttool_argdesc): Likewise. * include/grub/serial.h (grub_serial_find): Likewise. * include/grub/tparm.h (grub_terminfo_tparm): Likewise. * include/grub/xnu.h (grub_xnu_create_key): Likewise. (grub_xnu_create_value): Likewise. (grub_xnu_find_key): Likewise. (grub_xnu_scan_dir_for_kexts): Likewise. (grub_xnu_load_kext_from_dir): Likewise. * include/grub/zfs/zio_checksum.h (zio_checksum_t): Moved from here ... * grub-core/fs/zfs/zfs.c (zio_checksum_t): ...here. * include/grub/zfs/zio_checksum.h (zio_checksum_info): Moved from here ... * grub-core/fs/zfs/zfs.c (zio_checksum_info): ... here. Added missing const.
2011-11-30 15:20:13 +00:00
struct grub_xnu_devtree_key *start,
const char *name)
{
struct grub_xnu_devtree_key *cur;
int nkeys = 0, nvals = 0;
for (cur = start; cur; cur = cur->next)
{
if (cur->datasize == -1)
nkeys++;
else
nvals++;
}
/* For the name. */
2009-06-10 21:04:23 +00:00
nvals++;
*((grub_uint32_t *) curptr) = nvals;
curptr = ((grub_uint32_t *) curptr) + 1;
*((grub_uint32_t *) curptr) = nkeys;
curptr = ((grub_uint32_t *) curptr) + 1;
/* First comes "name" value. */
grub_memset (curptr, 0, 32);
grub_memcpy (curptr, "name", 4);
curptr = ((grub_uint8_t *) curptr) + 32;
*((grub_uint32_t *)curptr) = grub_strlen (name) + 1;
curptr = ((grub_uint32_t *) curptr) + 1;
grub_memcpy (curptr, name, grub_strlen (name));
curptr = ((grub_uint8_t *) curptr) + grub_strlen (name);
grub_memset (curptr, 0, 4 - (grub_strlen (name) % 4));
curptr = ((grub_uint8_t *) curptr) + (4 - (grub_strlen (name) % 4));
/* Then the other values. */
for (cur = start; cur; cur = cur->next)
if (cur->datasize != -1)
{
int align_overhead;
2009-06-10 21:04:23 +00:00
align_overhead = 4 - (cur->datasize % 4);
if (align_overhead == 4)
align_overhead = 0;
grub_memset (curptr, 0, 32);
grub_strncpy (curptr, cur->name, 31);
curptr = ((grub_uint8_t *) curptr) + 32;
*((grub_uint32_t *) curptr) = cur->datasize;
curptr = ((grub_uint32_t *) curptr) + 1;
grub_memcpy (curptr, cur->data, cur->datasize);
curptr = ((grub_uint8_t *) curptr) + cur->datasize;
grub_memset (curptr, 0, align_overhead);
curptr = ((grub_uint8_t *) curptr) + align_overhead;
}
2009-06-10 21:04:23 +00:00
/* And then the keys. Recursively use this function. */
for (cur = start; cur; cur = cur->next)
if (cur->datasize == -1)
{
curptr = grub_xnu_writetree_toheap_real (curptr,
cur->first_child,
cur->name);
if (!curptr)
return 0;
}
return curptr;
}
grub_err_t
2010-01-11 12:43:44 +00:00
grub_xnu_writetree_toheap (grub_addr_t *target, grub_size_t *size)
{
struct grub_xnu_devtree_key *chosen;
struct grub_xnu_devtree_key *memorymap;
struct grub_xnu_devtree_key *driverkey;
struct grub_xnu_extdesc *extdesc;
grub_err_t err;
2010-01-11 12:43:44 +00:00
void *src;
2009-06-10 21:04:23 +00:00
err = grub_xnu_align_heap (GRUB_XNU_PAGESIZE);
if (err)
return err;
2009-06-10 21:04:23 +00:00
/* Device tree itself is in the memory map of device tree. */
/* Create a dummy value in memory-map. */
chosen = grub_xnu_create_key (&grub_xnu_devtree_root, "chosen");
if (! chosen)
return grub_errno;
memorymap = grub_xnu_create_key (&(chosen->first_child), "memory-map");
if (! memorymap)
return grub_errno;
driverkey = (struct grub_xnu_devtree_key *) grub_malloc (sizeof (*driverkey));
if (! driverkey)
return grub_errno;
driverkey->name = grub_strdup ("DeviceTree");
if (! driverkey->name)
return grub_errno;
driverkey->datasize = sizeof (*extdesc);
driverkey->next = memorymap->first_child;
memorymap->first_child = driverkey;
2009-06-10 21:04:23 +00:00
driverkey->data = extdesc
= (struct grub_xnu_extdesc *) grub_malloc (sizeof (*extdesc));
if (! driverkey->data)
return grub_errno;
/* Allocate the space based on the size with dummy value. */
*size = grub_xnu_writetree_get_size (grub_xnu_devtree_root, "/");
2010-01-11 12:43:44 +00:00
err = grub_xnu_heap_malloc (ALIGN_UP (*size + 1, GRUB_XNU_PAGESIZE),
&src, target);
if (err)
return err;
/* Put real data in the dummy. */
2010-01-11 12:43:44 +00:00
extdesc->addr = *target;
extdesc->size = (grub_uint32_t) *size;
/* Write the tree to heap. */
2010-01-11 12:43:44 +00:00
grub_xnu_writetree_toheap_real (src, grub_xnu_devtree_root, "/");
return GRUB_ERR_NONE;
}
/* Find a key or value in parent key. */
struct grub_xnu_devtree_key *
Add missing const qualifiers. * grub-core/commands/i386/pc/sendkey.c (keysym): Add missing const. * grub-core/commands/lspci.c (grub_pci_classname): Likewise. * grub-core/commands/menuentry.c (hotkey_aliases): Likewise. * grub-core/disk/lvm.c (grub_lvm_getvalue): Likewise. (grub_lvm_check_flag): Likewise. * grub-core/efiemu/i386/coredetect.c (grub_efiemu_get_default_core_name): Likewise * grub-core/efiemu/main.c (grub_efiemu_autocore): Likewise. * grub-core/fs/hfsplus.c (grub_hfsplus_catkey_internal): Likewise. * grub-core/fs/ntfs.c (fixup): Likewise. * grub-core/fs/xfs.c (grub_xfs_iterate_dir): Likewise. * grub-core/fs/zfs/zfs.c (decomp_entry): Likewise. (fzap_lookup): Likewise. (zap_lookup): Likewise. * grub-core/gnulib/regcomp.c (init_dfa): Likewise. * grub-core/lib/legacy_parse.c (check_option): Likewise. * grub-core/lib/posix_wrap/langinfo.h (nl_langinfo): Likewise. * grub-core/loader/i386/bsd.c (grub_bsd_add_meta): Likewise. (grub_freebsd_add_meta_module): Likewise. (grub_cmd_freebsd_module): Likewise. * grub-core/loader/i386/xnu.c (tbl_alias): Likewise. * grub-core/loader/xnu.c (grub_xnu_register_memory): Likewise. (grub_xnu_writetree_get_size): Likewise. (grub_xnu_writetree_toheap_real): Likewise. (grub_xnu_find_key): Likewise. (grub_xnu_create_key): Likewise. (grub_xnu_create_value): Likewise. (grub_xnu_register_memory): Likewise. (grub_xnu_check_os_bundle_required): Likewise. (grub_xnu_scan_dir_for_kexts): Likewise. (grub_xnu_load_kext_from_dir): Likewise. * grub-core/normal/color.c (color_list): Likewise. * grub-core/normal/completion.c (current_word): Likewise. * grub-core/normal/menu_entry.c (insert_string): Likewise. * grub-core/term/serial.c (grub_serial_find): Likewise. * grub-core/term/tparm.c (grub_terminfo_tparm): Likewise. * include/grub/efiemu/efiemu.h (grub_efiemu_get_default_core_name): Likewise. * include/grub/i386/bsd.h (grub_bsd_add_meta): Likewise. (grub_freebsd_add_meta_module): Likewise. * include/grub/lib/arg.h (grub_arg_option): Likewise. * include/grub/net.h (grub_net_card_driver): Likewise. (grub_net_card): Likewise. (grub_net_app_protocol): Likewise. * include/grub/parttool.h (grub_parttool_argdesc): Likewise. * include/grub/serial.h (grub_serial_find): Likewise. * include/grub/tparm.h (grub_terminfo_tparm): Likewise. * include/grub/xnu.h (grub_xnu_create_key): Likewise. (grub_xnu_create_value): Likewise. (grub_xnu_find_key): Likewise. (grub_xnu_scan_dir_for_kexts): Likewise. (grub_xnu_load_kext_from_dir): Likewise. * include/grub/zfs/zio_checksum.h (zio_checksum_t): Moved from here ... * grub-core/fs/zfs/zfs.c (zio_checksum_t): ...here. * include/grub/zfs/zio_checksum.h (zio_checksum_info): Moved from here ... * grub-core/fs/zfs/zfs.c (zio_checksum_info): ... here. Added missing const.
2011-11-30 15:20:13 +00:00
grub_xnu_find_key (struct grub_xnu_devtree_key *parent, const char *name)
{
struct grub_xnu_devtree_key *cur;
for (cur = parent; cur; cur = cur->next)
if (grub_strcmp (cur->name, name) == 0)
return cur;
return 0;
}
struct grub_xnu_devtree_key *
Add missing const qualifiers. * grub-core/commands/i386/pc/sendkey.c (keysym): Add missing const. * grub-core/commands/lspci.c (grub_pci_classname): Likewise. * grub-core/commands/menuentry.c (hotkey_aliases): Likewise. * grub-core/disk/lvm.c (grub_lvm_getvalue): Likewise. (grub_lvm_check_flag): Likewise. * grub-core/efiemu/i386/coredetect.c (grub_efiemu_get_default_core_name): Likewise * grub-core/efiemu/main.c (grub_efiemu_autocore): Likewise. * grub-core/fs/hfsplus.c (grub_hfsplus_catkey_internal): Likewise. * grub-core/fs/ntfs.c (fixup): Likewise. * grub-core/fs/xfs.c (grub_xfs_iterate_dir): Likewise. * grub-core/fs/zfs/zfs.c (decomp_entry): Likewise. (fzap_lookup): Likewise. (zap_lookup): Likewise. * grub-core/gnulib/regcomp.c (init_dfa): Likewise. * grub-core/lib/legacy_parse.c (check_option): Likewise. * grub-core/lib/posix_wrap/langinfo.h (nl_langinfo): Likewise. * grub-core/loader/i386/bsd.c (grub_bsd_add_meta): Likewise. (grub_freebsd_add_meta_module): Likewise. (grub_cmd_freebsd_module): Likewise. * grub-core/loader/i386/xnu.c (tbl_alias): Likewise. * grub-core/loader/xnu.c (grub_xnu_register_memory): Likewise. (grub_xnu_writetree_get_size): Likewise. (grub_xnu_writetree_toheap_real): Likewise. (grub_xnu_find_key): Likewise. (grub_xnu_create_key): Likewise. (grub_xnu_create_value): Likewise. (grub_xnu_register_memory): Likewise. (grub_xnu_check_os_bundle_required): Likewise. (grub_xnu_scan_dir_for_kexts): Likewise. (grub_xnu_load_kext_from_dir): Likewise. * grub-core/normal/color.c (color_list): Likewise. * grub-core/normal/completion.c (current_word): Likewise. * grub-core/normal/menu_entry.c (insert_string): Likewise. * grub-core/term/serial.c (grub_serial_find): Likewise. * grub-core/term/tparm.c (grub_terminfo_tparm): Likewise. * include/grub/efiemu/efiemu.h (grub_efiemu_get_default_core_name): Likewise. * include/grub/i386/bsd.h (grub_bsd_add_meta): Likewise. (grub_freebsd_add_meta_module): Likewise. * include/grub/lib/arg.h (grub_arg_option): Likewise. * include/grub/net.h (grub_net_card_driver): Likewise. (grub_net_card): Likewise. (grub_net_app_protocol): Likewise. * include/grub/parttool.h (grub_parttool_argdesc): Likewise. * include/grub/serial.h (grub_serial_find): Likewise. * include/grub/tparm.h (grub_terminfo_tparm): Likewise. * include/grub/xnu.h (grub_xnu_create_key): Likewise. (grub_xnu_create_value): Likewise. (grub_xnu_find_key): Likewise. (grub_xnu_scan_dir_for_kexts): Likewise. (grub_xnu_load_kext_from_dir): Likewise. * include/grub/zfs/zio_checksum.h (zio_checksum_t): Moved from here ... * grub-core/fs/zfs/zfs.c (zio_checksum_t): ...here. * include/grub/zfs/zio_checksum.h (zio_checksum_info): Moved from here ... * grub-core/fs/zfs/zfs.c (zio_checksum_info): ... here. Added missing const.
2011-11-30 15:20:13 +00:00
grub_xnu_create_key (struct grub_xnu_devtree_key **parent, const char *name)
{
struct grub_xnu_devtree_key *ret;
ret = grub_xnu_find_key (*parent, name);
if (ret)
return ret;
2009-07-16 Pavel Roskin <proski@gnu.org> * kern/mm.c (grub_zalloc): New function. (grub_debug_zalloc): Likewise. * include/grub/mm.h: Declare grub_zalloc() and grub_debug_zalloc(). * util/misc.c (grub_zalloc): New function. * bus/usb/uhci.c (grub_uhci_pci_iter): Use grub_zalloc() instead of grub_malloc(), remove unneeded initializations. * bus/usb/usbhub.c (grub_usb_hub_add_dev): Likewise. * commands/extcmd.c (grub_extcmd_dispatcher): Likewise. * commands/parttool.c (grub_cmd_parttool): Likewise. * disk/i386/pc/biosdisk.c (grub_biosdisk_open): Likewise. * disk/raid5_recover.c (grub_raid5_recover): Likewise. * disk/raid6_recover.c (grub_raid6_recover): Likewise. * disk/usbms.c (grub_usbms_finddevs): Likewise. * efiemu/mm.c (grub_efiemu_request_memalign): Likewise. * efiemu/pnvram.c (grub_efiemu_pnvram): Likewise. (grub_cmd_efiemu_pnvram): Likewise. * fs/i386/pc/pxe.c (grub_pxefs_open): Likewise. * fs/iso9660.c (grub_iso9660_mount): Likewise. (grub_iso9660_iterate_dir): Likewise. * fs/jfs.c (grub_jfs_opendir): Likewise. * fs/ntfs.c (list_file): Likewise. (grub_ntfs_mount): Likewise. * kern/disk.c (grub_disk_open): Likewise. * kern/dl.c (grub_dl_load_core): Likewise. * kern/elf.c (grub_elf_file): Likewise. * kern/env.c (grub_env_context_open): Likewise. (grub_env_set): Likewise. (grub_env_set_data_slot): Likewise. * kern/file.c (grub_file_open): Likewise. * kern/fs.c (grub_fs_blocklist_open): Likewise. * loader/i386/multiboot.c (grub_module): Likewise. * loader/xnu.c (grub_xnu_create_key): Likewise. (grub_xnu_create_value): Likewise. * normal/main.c (grub_normal_add_menu_entry): Likewise. (read_config_file): Likewise. * normal/menu_entry.c (make_screen): Likewise. * partmap/sun.c (sun_partition_map_iterate): Likewise. * script/sh/lexer.c (grub_script_lexer_init): Likewise. * script/sh/script.c (grub_script_parse): Likewise. * video/bitmap.c (grub_video_bitmap_create): Likewise. * video/readers/jpeg.c (grub_video_reader_jpeg): Likewise. * video/readers/png.c (grub_png_output_byte): Likewise. (grub_video_reader_png): Likewise.
2009-07-16 22:14:09 +00:00
ret = (struct grub_xnu_devtree_key *) grub_zalloc (sizeof (*ret));
if (! ret)
return 0;
ret->name = grub_strdup (name);
if (! ret->name)
{
grub_free (ret);
return 0;
}
ret->datasize = -1;
ret->next = *parent;
*parent = ret;
return ret;
}
struct grub_xnu_devtree_key *
Add missing const qualifiers. * grub-core/commands/i386/pc/sendkey.c (keysym): Add missing const. * grub-core/commands/lspci.c (grub_pci_classname): Likewise. * grub-core/commands/menuentry.c (hotkey_aliases): Likewise. * grub-core/disk/lvm.c (grub_lvm_getvalue): Likewise. (grub_lvm_check_flag): Likewise. * grub-core/efiemu/i386/coredetect.c (grub_efiemu_get_default_core_name): Likewise * grub-core/efiemu/main.c (grub_efiemu_autocore): Likewise. * grub-core/fs/hfsplus.c (grub_hfsplus_catkey_internal): Likewise. * grub-core/fs/ntfs.c (fixup): Likewise. * grub-core/fs/xfs.c (grub_xfs_iterate_dir): Likewise. * grub-core/fs/zfs/zfs.c (decomp_entry): Likewise. (fzap_lookup): Likewise. (zap_lookup): Likewise. * grub-core/gnulib/regcomp.c (init_dfa): Likewise. * grub-core/lib/legacy_parse.c (check_option): Likewise. * grub-core/lib/posix_wrap/langinfo.h (nl_langinfo): Likewise. * grub-core/loader/i386/bsd.c (grub_bsd_add_meta): Likewise. (grub_freebsd_add_meta_module): Likewise. (grub_cmd_freebsd_module): Likewise. * grub-core/loader/i386/xnu.c (tbl_alias): Likewise. * grub-core/loader/xnu.c (grub_xnu_register_memory): Likewise. (grub_xnu_writetree_get_size): Likewise. (grub_xnu_writetree_toheap_real): Likewise. (grub_xnu_find_key): Likewise. (grub_xnu_create_key): Likewise. (grub_xnu_create_value): Likewise. (grub_xnu_register_memory): Likewise. (grub_xnu_check_os_bundle_required): Likewise. (grub_xnu_scan_dir_for_kexts): Likewise. (grub_xnu_load_kext_from_dir): Likewise. * grub-core/normal/color.c (color_list): Likewise. * grub-core/normal/completion.c (current_word): Likewise. * grub-core/normal/menu_entry.c (insert_string): Likewise. * grub-core/term/serial.c (grub_serial_find): Likewise. * grub-core/term/tparm.c (grub_terminfo_tparm): Likewise. * include/grub/efiemu/efiemu.h (grub_efiemu_get_default_core_name): Likewise. * include/grub/i386/bsd.h (grub_bsd_add_meta): Likewise. (grub_freebsd_add_meta_module): Likewise. * include/grub/lib/arg.h (grub_arg_option): Likewise. * include/grub/net.h (grub_net_card_driver): Likewise. (grub_net_card): Likewise. (grub_net_app_protocol): Likewise. * include/grub/parttool.h (grub_parttool_argdesc): Likewise. * include/grub/serial.h (grub_serial_find): Likewise. * include/grub/tparm.h (grub_terminfo_tparm): Likewise. * include/grub/xnu.h (grub_xnu_create_key): Likewise. (grub_xnu_create_value): Likewise. (grub_xnu_find_key): Likewise. (grub_xnu_scan_dir_for_kexts): Likewise. (grub_xnu_load_kext_from_dir): Likewise. * include/grub/zfs/zio_checksum.h (zio_checksum_t): Moved from here ... * grub-core/fs/zfs/zfs.c (zio_checksum_t): ...here. * include/grub/zfs/zio_checksum.h (zio_checksum_info): Moved from here ... * grub-core/fs/zfs/zfs.c (zio_checksum_info): ... here. Added missing const.
2011-11-30 15:20:13 +00:00
grub_xnu_create_value (struct grub_xnu_devtree_key **parent, const char *name)
{
struct grub_xnu_devtree_key *ret;
ret = grub_xnu_find_key (*parent, name);
if (ret)
{
if (ret->datasize == -1)
grub_xnu_free_devtree (ret->first_child);
else if (ret->datasize)
grub_free (ret->data);
ret->datasize = 0;
ret->data = 0;
return ret;
}
2009-07-16 Pavel Roskin <proski@gnu.org> * kern/mm.c (grub_zalloc): New function. (grub_debug_zalloc): Likewise. * include/grub/mm.h: Declare grub_zalloc() and grub_debug_zalloc(). * util/misc.c (grub_zalloc): New function. * bus/usb/uhci.c (grub_uhci_pci_iter): Use grub_zalloc() instead of grub_malloc(), remove unneeded initializations. * bus/usb/usbhub.c (grub_usb_hub_add_dev): Likewise. * commands/extcmd.c (grub_extcmd_dispatcher): Likewise. * commands/parttool.c (grub_cmd_parttool): Likewise. * disk/i386/pc/biosdisk.c (grub_biosdisk_open): Likewise. * disk/raid5_recover.c (grub_raid5_recover): Likewise. * disk/raid6_recover.c (grub_raid6_recover): Likewise. * disk/usbms.c (grub_usbms_finddevs): Likewise. * efiemu/mm.c (grub_efiemu_request_memalign): Likewise. * efiemu/pnvram.c (grub_efiemu_pnvram): Likewise. (grub_cmd_efiemu_pnvram): Likewise. * fs/i386/pc/pxe.c (grub_pxefs_open): Likewise. * fs/iso9660.c (grub_iso9660_mount): Likewise. (grub_iso9660_iterate_dir): Likewise. * fs/jfs.c (grub_jfs_opendir): Likewise. * fs/ntfs.c (list_file): Likewise. (grub_ntfs_mount): Likewise. * kern/disk.c (grub_disk_open): Likewise. * kern/dl.c (grub_dl_load_core): Likewise. * kern/elf.c (grub_elf_file): Likewise. * kern/env.c (grub_env_context_open): Likewise. (grub_env_set): Likewise. (grub_env_set_data_slot): Likewise. * kern/file.c (grub_file_open): Likewise. * kern/fs.c (grub_fs_blocklist_open): Likewise. * loader/i386/multiboot.c (grub_module): Likewise. * loader/xnu.c (grub_xnu_create_key): Likewise. (grub_xnu_create_value): Likewise. * normal/main.c (grub_normal_add_menu_entry): Likewise. (read_config_file): Likewise. * normal/menu_entry.c (make_screen): Likewise. * partmap/sun.c (sun_partition_map_iterate): Likewise. * script/sh/lexer.c (grub_script_lexer_init): Likewise. * script/sh/script.c (grub_script_parse): Likewise. * video/bitmap.c (grub_video_bitmap_create): Likewise. * video/readers/jpeg.c (grub_video_reader_jpeg): Likewise. * video/readers/png.c (grub_png_output_byte): Likewise. (grub_video_reader_png): Likewise.
2009-07-16 22:14:09 +00:00
ret = (struct grub_xnu_devtree_key *) grub_zalloc (sizeof (*ret));
if (! ret)
return 0;
ret->name = grub_strdup (name);
if (! ret->name)
{
grub_free (ret);
return 0;
}
ret->next = *parent;
*parent = ret;
return ret;
}
static grub_err_t
grub_xnu_unload (void)
{
2009-11-09 17:43:53 +00:00
grub_cpu_xnu_unload ();
grub_xnu_free_devtree (grub_xnu_devtree_root);
grub_xnu_devtree_root = 0;
/* Free loaded image. */
driversnum = 0;
driverspackagenum = 0;
2010-01-11 12:43:44 +00:00
grub_relocator_unload (grub_xnu_relocator);
grub_xnu_relocator = NULL;
grub_xnu_heap_target_start = 0;
grub_xnu_heap_size = 0;
grub_xnu_unlock ();
return GRUB_ERR_NONE;
}
static grub_err_t
grub_cmd_xnu_kernel (grub_command_t cmd __attribute__ ((unused)),
int argc, char *args[])
{
grub_err_t err;
grub_macho_t macho;
2009-09-02 00:52:10 +00:00
grub_uint32_t startcode, endcode;
int i;
char *ptr;
void *loadaddr;
2010-01-11 12:43:44 +00:00
grub_addr_t loadaddr_target;
if (argc < 1)
return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
grub_xnu_unload ();
macho = grub_macho_open (args[0], 0);
if (! macho)
return grub_errno;
err = grub_macho_size32 (macho, &startcode, &endcode, GRUB_MACHO_NOBSS,
args[0]);
if (err)
{
grub_macho_close (macho);
grub_xnu_unload ();
return err;
}
2009-06-10 21:04:23 +00:00
grub_dprintf ("xnu", "endcode = %lx, startcode = %lx\n",
(unsigned long) endcode, (unsigned long) startcode);
2010-01-11 12:43:44 +00:00
grub_xnu_relocator = grub_relocator_new ();
if (!grub_xnu_relocator)
return grub_errno;
grub_xnu_heap_target_start = startcode;
err = grub_xnu_heap_malloc (endcode - startcode, &loadaddr,
2010-01-11 12:43:44 +00:00
&loadaddr_target);
2010-01-11 12:43:44 +00:00
if (err)
{
grub_macho_close (macho);
grub_xnu_unload ();
2010-01-11 12:43:44 +00:00
return err;
}
/* Load kernel. */
err = grub_macho_load32 (macho, args[0], (char *) loadaddr - startcode,
GRUB_MACHO_NOBSS, &grub_xnu_darwin_version);
if (err)
{
grub_macho_close (macho);
grub_xnu_unload ();
return err;
}
grub_xnu_entry_point = grub_macho_get_entry_point32 (macho, args[0]);
if (! grub_xnu_entry_point)
{
grub_macho_close (macho);
grub_xnu_unload ();
return grub_error (GRUB_ERR_BAD_OS, "couldn't find entry point");
}
grub_macho_close (macho);
err = grub_xnu_align_heap (GRUB_XNU_PAGESIZE);
if (err)
{
grub_xnu_unload ();
return err;
}
/* Copy parameters to kernel command line. */
ptr = grub_xnu_cmdline;
for (i = 1; i < argc; i++)
{
2009-06-10 21:04:23 +00:00
if (ptr + grub_strlen (args[i]) + 1
>= grub_xnu_cmdline + sizeof (grub_xnu_cmdline))
break;
grub_memcpy (ptr, args[i], grub_strlen (args[i]));
ptr += grub_strlen (args[i]);
*ptr = ' ';
ptr++;
}
/* Replace last space by '\0'. */
if (ptr != grub_xnu_cmdline)
2009-06-10 21:04:23 +00:00
*(ptr - 1) = 0;
#if defined (__i386) && !defined (GRUB_MACHINE_EFI)
err = grub_efiemu_autocore ();
if (err)
return err;
#endif
2009-06-10 21:04:23 +00:00
grub_loader_set (grub_xnu_boot, grub_xnu_unload, 0);
grub_xnu_lock ();
2009-09-02 11:34:40 +00:00
grub_xnu_is_64bit = 0;
2009-09-02 00:52:10 +00:00
return 0;
}
static grub_err_t
grub_cmd_xnu_kernel64 (grub_command_t cmd __attribute__ ((unused)),
int argc, char *args[])
{
grub_err_t err;
grub_macho_t macho;
grub_uint64_t startcode, endcode;
int i;
char *ptr;
void *loadaddr;
2010-01-11 12:43:44 +00:00
grub_addr_t loadaddr_target;
2009-09-02 00:52:10 +00:00
if (argc < 1)
return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
2009-09-02 00:52:10 +00:00
grub_xnu_unload ();
macho = grub_macho_open (args[0], 1);
2009-09-02 00:52:10 +00:00
if (! macho)
return grub_errno;
err = grub_macho_size64 (macho, &startcode, &endcode, GRUB_MACHO_NOBSS,
args[0]);
if (err)
2009-09-02 00:52:10 +00:00
{
grub_macho_close (macho);
grub_xnu_unload ();
return err;
}
startcode &= 0x0fffffff;
endcode &= 0x0fffffff;
grub_dprintf ("xnu", "endcode = %lx, startcode = %lx\n",
(unsigned long) endcode, (unsigned long) startcode);
2010-01-11 12:43:44 +00:00
grub_xnu_relocator = grub_relocator_new ();
if (!grub_xnu_relocator)
return grub_errno;
grub_xnu_heap_target_start = startcode;
err = grub_xnu_heap_malloc (endcode - startcode, &loadaddr,
2010-01-11 12:43:44 +00:00
&loadaddr_target);
2009-09-02 00:52:10 +00:00
2010-01-11 12:43:44 +00:00
if (err)
2009-09-02 00:52:10 +00:00
{
grub_macho_close (macho);
grub_xnu_unload ();
2010-01-11 12:43:44 +00:00
return err;
2009-09-02 00:52:10 +00:00
}
/* Load kernel. */
err = grub_macho_load64 (macho, args[0], (char *) loadaddr - startcode,
GRUB_MACHO_NOBSS, &grub_xnu_darwin_version);
2009-09-02 00:52:10 +00:00
if (err)
{
grub_macho_close (macho);
grub_xnu_unload ();
return err;
}
grub_xnu_entry_point = grub_macho_get_entry_point64 (macho, args[0])
& 0x0fffffff;
2009-09-02 00:52:10 +00:00
if (! grub_xnu_entry_point)
{
grub_macho_close (macho);
grub_xnu_unload ();
return grub_error (GRUB_ERR_BAD_OS, "couldn't find entry point");
}
grub_macho_close (macho);
err = grub_xnu_align_heap (GRUB_XNU_PAGESIZE);
if (err)
{
grub_xnu_unload ();
return err;
}
/* Copy parameters to kernel command line. */
ptr = grub_xnu_cmdline;
for (i = 1; i < argc; i++)
{
if (ptr + grub_strlen (args[i]) + 1
>= grub_xnu_cmdline + sizeof (grub_xnu_cmdline))
break;
grub_memcpy (ptr, args[i], grub_strlen (args[i]));
ptr += grub_strlen (args[i]);
*ptr = ' ';
ptr++;
}
/* Replace last space by '\0'. */
if (ptr != grub_xnu_cmdline)
*(ptr - 1) = 0;
#if defined (__i386) && !defined (GRUB_MACHINE_EFI)
err = grub_efiemu_autocore ();
if (err)
return err;
#endif
2009-06-10 21:04:23 +00:00
grub_loader_set (grub_xnu_boot, grub_xnu_unload, 0);
grub_xnu_lock ();
2009-09-02 11:34:40 +00:00
grub_xnu_is_64bit = 1;
2009-09-02 00:52:10 +00:00
return 0;
}
2009-06-10 21:04:23 +00:00
/* Register a memory in a memory map under name PREFIXSUFFIX
and increment SUFFIX. */
static grub_err_t
Add missing const qualifiers. * grub-core/commands/i386/pc/sendkey.c (keysym): Add missing const. * grub-core/commands/lspci.c (grub_pci_classname): Likewise. * grub-core/commands/menuentry.c (hotkey_aliases): Likewise. * grub-core/disk/lvm.c (grub_lvm_getvalue): Likewise. (grub_lvm_check_flag): Likewise. * grub-core/efiemu/i386/coredetect.c (grub_efiemu_get_default_core_name): Likewise * grub-core/efiemu/main.c (grub_efiemu_autocore): Likewise. * grub-core/fs/hfsplus.c (grub_hfsplus_catkey_internal): Likewise. * grub-core/fs/ntfs.c (fixup): Likewise. * grub-core/fs/xfs.c (grub_xfs_iterate_dir): Likewise. * grub-core/fs/zfs/zfs.c (decomp_entry): Likewise. (fzap_lookup): Likewise. (zap_lookup): Likewise. * grub-core/gnulib/regcomp.c (init_dfa): Likewise. * grub-core/lib/legacy_parse.c (check_option): Likewise. * grub-core/lib/posix_wrap/langinfo.h (nl_langinfo): Likewise. * grub-core/loader/i386/bsd.c (grub_bsd_add_meta): Likewise. (grub_freebsd_add_meta_module): Likewise. (grub_cmd_freebsd_module): Likewise. * grub-core/loader/i386/xnu.c (tbl_alias): Likewise. * grub-core/loader/xnu.c (grub_xnu_register_memory): Likewise. (grub_xnu_writetree_get_size): Likewise. (grub_xnu_writetree_toheap_real): Likewise. (grub_xnu_find_key): Likewise. (grub_xnu_create_key): Likewise. (grub_xnu_create_value): Likewise. (grub_xnu_register_memory): Likewise. (grub_xnu_check_os_bundle_required): Likewise. (grub_xnu_scan_dir_for_kexts): Likewise. (grub_xnu_load_kext_from_dir): Likewise. * grub-core/normal/color.c (color_list): Likewise. * grub-core/normal/completion.c (current_word): Likewise. * grub-core/normal/menu_entry.c (insert_string): Likewise. * grub-core/term/serial.c (grub_serial_find): Likewise. * grub-core/term/tparm.c (grub_terminfo_tparm): Likewise. * include/grub/efiemu/efiemu.h (grub_efiemu_get_default_core_name): Likewise. * include/grub/i386/bsd.h (grub_bsd_add_meta): Likewise. (grub_freebsd_add_meta_module): Likewise. * include/grub/lib/arg.h (grub_arg_option): Likewise. * include/grub/net.h (grub_net_card_driver): Likewise. (grub_net_card): Likewise. (grub_net_app_protocol): Likewise. * include/grub/parttool.h (grub_parttool_argdesc): Likewise. * include/grub/serial.h (grub_serial_find): Likewise. * include/grub/tparm.h (grub_terminfo_tparm): Likewise. * include/grub/xnu.h (grub_xnu_create_key): Likewise. (grub_xnu_create_value): Likewise. (grub_xnu_find_key): Likewise. (grub_xnu_scan_dir_for_kexts): Likewise. (grub_xnu_load_kext_from_dir): Likewise. * include/grub/zfs/zio_checksum.h (zio_checksum_t): Moved from here ... * grub-core/fs/zfs/zfs.c (zio_checksum_t): ...here. * include/grub/zfs/zio_checksum.h (zio_checksum_info): Moved from here ... * grub-core/fs/zfs/zfs.c (zio_checksum_info): ... here. Added missing const.
2011-11-30 15:20:13 +00:00
grub_xnu_register_memory (const char *prefix, int *suffix,
2010-01-11 12:43:44 +00:00
grub_addr_t addr, grub_size_t size)
{
struct grub_xnu_devtree_key *chosen;
struct grub_xnu_devtree_key *memorymap;
struct grub_xnu_devtree_key *driverkey;
struct grub_xnu_extdesc *extdesc;
if (! grub_xnu_heap_size)
return grub_error (GRUB_ERR_BAD_OS, N_("you need to load the kernel first"));
chosen = grub_xnu_create_key (&grub_xnu_devtree_root, "chosen");
if (! chosen)
return grub_errno;
memorymap = grub_xnu_create_key (&(chosen->first_child), "memory-map");
if (! memorymap)
return grub_errno;
driverkey = (struct grub_xnu_devtree_key *) grub_malloc (sizeof (*driverkey));
if (! driverkey)
return grub_errno;
if (suffix)
driverkey->name = grub_xasprintf ("%s%d", prefix, (*suffix)++);
else
driverkey->name = grub_strdup (prefix);
if (!driverkey->name)
{
grub_free (driverkey);
return grub_errno;
}
driverkey->datasize = sizeof (*extdesc);
driverkey->next = memorymap->first_child;
2009-06-10 21:04:23 +00:00
driverkey->data = extdesc
= (struct grub_xnu_extdesc *) grub_malloc (sizeof (*extdesc));
if (! driverkey->data)
{
grub_free (driverkey->name);
grub_free (driverkey);
return grub_errno;
}
memorymap->first_child = driverkey;
2010-01-11 12:43:44 +00:00
extdesc->addr = addr;
extdesc->size = (grub_uint32_t) size;
return GRUB_ERR_NONE;
}
2009-08-30 12:26:41 +00:00
static inline char *
get_name_ptr (char *name)
{
char *p = name, *p2;
/* Skip Info.plist. */
p2 = grub_strrchr (p, '/');
if (!p2)
return name;
if (p2 == name)
return name + 1;
p = p2 - 1;
p2 = grub_strrchr (p, '/');
if (!p2)
return name;
if (p2 == name)
return name + 1;
if (grub_memcmp (p2, "/Contents/", sizeof ("/Contents/") - 1) != 0)
return p2 + 1;
p = p2 - 1;
p2 = grub_strrchr (p, '/');
if (!p2)
return name;
return p2 + 1;
}
/* Load .kext. */
static grub_err_t
grub_xnu_load_driver (char *infoplistname, grub_file_t binaryfile,
const char *filename)
{
grub_macho_t macho;
grub_err_t err;
grub_file_t infoplist;
struct grub_xnu_extheader *exthead;
int neededspace = sizeof (*exthead);
grub_uint8_t *buf;
void *buf0;
2010-01-11 12:43:44 +00:00
grub_addr_t buf_target;
grub_size_t infoplistsize = 0, machosize = 0;
2009-08-30 12:26:41 +00:00
char *name, *nameend;
int namelen;
name = get_name_ptr (infoplistname);
nameend = grub_strchr (name, '/');
if (nameend)
namelen = nameend - name;
else
namelen = grub_strlen (name);
neededspace += namelen + 1;
if (! grub_xnu_heap_size)
return grub_error (GRUB_ERR_BAD_OS, N_("you need to load the kernel first"));
2009-06-10 21:04:23 +00:00
/* Compute the needed space. */
if (binaryfile)
{
macho = grub_macho_file (binaryfile, filename, grub_xnu_is_64bit);
if (!macho)
grub_file_close (binaryfile);
else
{
if (grub_xnu_is_64bit)
machosize = grub_macho_filesize64 (macho);
else
machosize = grub_macho_filesize32 (macho);
}
neededspace += machosize;
}
else
macho = 0;
if (infoplistname)
infoplist = grub_file_open (infoplistname);
else
infoplist = 0;
grub_errno = GRUB_ERR_NONE;
if (infoplist)
{
infoplistsize = grub_file_size (infoplist);
neededspace += infoplistsize + 1;
}
else
infoplistsize = 0;
/* Allocate the space. */
err = grub_xnu_align_heap (GRUB_XNU_PAGESIZE);
if (err)
return err;
err = grub_xnu_heap_malloc (neededspace, &buf0, &buf_target);
2010-01-11 12:43:44 +00:00
if (err)
return err;
buf = buf0;
exthead = (struct grub_xnu_extheader *) buf;
grub_memset (exthead, 0, sizeof (*exthead));
buf += sizeof (*exthead);
/* Load the binary. */
if (macho)
{
exthead->binaryaddr = buf_target + (buf - (grub_uint8_t *) buf0);
exthead->binarysize = machosize;
2009-09-02 11:34:40 +00:00
if (grub_xnu_is_64bit)
err = grub_macho_readfile64 (macho, filename, buf);
2009-09-02 00:52:10 +00:00
else
err = grub_macho_readfile32 (macho, filename, buf);
2009-09-02 00:52:10 +00:00
if (err)
{
grub_macho_close (macho);
return err;
}
grub_macho_close (macho);
buf += machosize;
}
grub_errno = GRUB_ERR_NONE;
/* Load the plist. */
if (infoplist)
{
exthead->infoplistaddr = buf_target + (buf - (grub_uint8_t *) buf0);
exthead->infoplistsize = infoplistsize + 1;
if (grub_file_read (infoplist, buf, infoplistsize)
!= (grub_ssize_t) (infoplistsize))
{
grub_file_close (infoplist);
if (!grub_errno)
Clarify and unify messages. * grub-core/commands/hashsum.c (options): Unify messages. * grub-core/commands/keystatus.c (GRUB_MOD_INIT): Don't mark a literal-only message as translatable. * grub-core/commands/lsacpi.c (GRUB_MOD_INIT): Likewise. * grub-core/loader/ia64/efi/linux.c (GRUB_MOD_INIT): Likewise. * grub-core/commands/legacycfg.c (GRUB_MOD_INIT): Add quoting around commands. * grub-core/commands/menuentry.c (options): Clarify that it's a keyboard key, not the key used to unlock. Clarify what it's used for. * grub-core/kern/emu/hostdisk.c (read_device_map): Unify error message. * grub-core/loader/xnu.c (grub_xnu_load_driver): Remove erroneous colon. * grub-core/script/main.c (GRUB_MOD_INIT): Clarify [n] to be [NUM]. * util/grub-editenv.c (options): Unify "verbose" message. * util/grub-fstest.c (read_file): Unify error message. (fstest): Add quotes around commands. (options): Unify "verbose" message. * util/grub-install.in: Add quotes around variable name. * util/grub-kbdcomp.in: Unify error message. * util/grub-mkfont.c (main): Likewise. * util/grub-mkrescue.in: Likewise. * util/grub-mklayout.c (options): Unify "verbose" message. * util/grub-mkstandalone.in: Unify help and verbose messages. * util/grub-mount.c (options): Unify "verbose" message. * util/grub-probe.c (options): Likewise. * util/grub-script-check.c (options): Likewise. * util/grub-setup.c (setup): Unify no-terminator message. (options): Use DEVICE and not DEV. Unify "verbose" message. * util/ieee1275/ofpath.c (xrealpath): Unify error message.
2012-02-05 10:23:47 +00:00
grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"),
infoplistname);
return grub_errno;
}
grub_file_close (infoplist);
buf[infoplistsize] = 0;
2009-08-30 12:26:41 +00:00
buf += infoplistsize + 1;
}
grub_errno = GRUB_ERR_NONE;
exthead->nameaddr = (buf - (grub_uint8_t *) buf0) + buf_target;
2009-08-30 12:26:41 +00:00
exthead->namesize = namelen + 1;
grub_memcpy (buf, name, namelen);
buf[namelen] = 0;
buf += namelen + 1;
/* Announce to kernel */
2010-01-11 12:43:44 +00:00
return grub_xnu_register_memory ("Driver-", &driversnum, buf_target,
2009-06-10 21:04:23 +00:00
neededspace);
}
/* Load mkext. */
static grub_err_t
grub_cmd_xnu_mkext (grub_command_t cmd __attribute__ ((unused)),
int argc, char *args[])
{
grub_file_t file;
void *loadto;
2010-01-11 12:43:44 +00:00
grub_addr_t loadto_target;
grub_err_t err;
grub_off_t readoff = 0;
grub_ssize_t readlen = -1;
struct grub_macho_fat_header head;
struct grub_macho_fat_arch *archs;
int narchs, i;
if (argc != 1)
return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
if (! grub_xnu_heap_size)
return grub_error (GRUB_ERR_BAD_OS, N_("you need to load the kernel first"));
file = grub_file_open (args[0]);
if (! file)
return grub_errno;
/* Sometimes caches are fat binary. Errgh. */
if (grub_file_read (file, &head, sizeof (head))
!= (grub_ssize_t) (sizeof (head)))
{
2009-06-10 21:04:23 +00:00
/* I don't know the internal structure of package but
can hardly imagine a valid package shorter than 20 bytes. */
grub_file_close (file);
if (!grub_errno)
grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"), args[0]);
return grub_errno;
}
/* Find the corresponding architecture. */
if (grub_be_to_cpu32 (head.magic) == GRUB_MACHO_FAT_MAGIC)
{
narchs = grub_be_to_cpu32 (head.nfat_arch);
archs = grub_malloc (sizeof (struct grub_macho_fat_arch) * narchs);
if (! archs)
{
grub_file_close (file);
return grub_errno;
2009-06-10 21:04:23 +00:00
}
if (grub_file_read (file, archs,
sizeof (struct grub_macho_fat_arch) * narchs)
!= (grub_ssize_t) sizeof(struct grub_macho_fat_arch) * narchs)
{
grub_free (archs);
if (!grub_errno)
grub_error (GRUB_ERR_READ_ERROR, N_("premature end of file %s"),
args[0]);
return grub_errno;
}
for (i = 0; i < narchs; i++)
{
2009-09-02 11:34:40 +00:00
if (!grub_xnu_is_64bit && GRUB_MACHO_CPUTYPE_IS_HOST32
2009-09-02 00:52:10 +00:00
(grub_be_to_cpu32 (archs[i].cputype)))
{
readoff = grub_be_to_cpu32 (archs[i].offset);
readlen = grub_be_to_cpu32 (archs[i].size);
}
2009-09-02 11:34:40 +00:00
if (grub_xnu_is_64bit && GRUB_MACHO_CPUTYPE_IS_HOST64
(grub_be_to_cpu32 (archs[i].cputype)))
{
readoff = grub_be_to_cpu32 (archs[i].offset);
readlen = grub_be_to_cpu32 (archs[i].size);
}
}
grub_free (archs);
}
else
{
/* It's a flat file. Some sane people still exist. */
readoff = 0;
readlen = grub_file_size (file);
}
if (readlen == -1)
{
grub_file_close (file);
return grub_error (GRUB_ERR_BAD_OS, "no suitable architecture is found");
}
/* Allocate space. */
err = grub_xnu_align_heap (GRUB_XNU_PAGESIZE);
if (err)
{
grub_file_close (file);
return err;
}
2010-01-11 12:43:44 +00:00
err = grub_xnu_heap_malloc (readlen, &loadto, &loadto_target);
if (err)
{
grub_file_close (file);
2010-01-11 12:43:44 +00:00
return err;
}
/* Read the file. */
grub_file_seek (file, readoff);
if (grub_file_read (file, loadto, readlen) != (grub_ssize_t) (readlen))
{
grub_file_close (file);
if (!grub_errno)
grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"), args[0]);
return grub_errno;
}
grub_file_close (file);
/* Pass it to kernel. */
return grub_xnu_register_memory ("DriversPackage-", &driverspackagenum,
2010-01-11 12:43:44 +00:00
loadto_target, readlen);
}
static grub_err_t
grub_cmd_xnu_ramdisk (grub_command_t cmd __attribute__ ((unused)),
int argc, char *args[])
{
grub_file_t file;
void *loadto;
2010-01-11 12:43:44 +00:00
grub_addr_t loadto_target;
grub_err_t err;
grub_size_t size;
if (argc != 1)
return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
if (! grub_xnu_heap_size)
return grub_error (GRUB_ERR_BAD_OS, N_("you need to load the kernel first"));
file = grub_file_open (args[0]);
if (! file)
return grub_errno;
err = grub_xnu_align_heap (GRUB_XNU_PAGESIZE);
if (err)
return err;
size = grub_file_size (file);
2009-06-10 21:04:23 +00:00
2010-01-11 12:43:44 +00:00
err = grub_xnu_heap_malloc (size, &loadto, &loadto_target);
if (err)
return err;
if (grub_file_read (file, loadto, size) != (grub_ssize_t) (size))
{
grub_file_close (file);
if (!grub_errno)
grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"), args[0]);
return grub_errno;
}
2010-01-11 12:43:44 +00:00
return grub_xnu_register_memory ("RAMDisk", 0, loadto_target, size);
}
2009-06-10 21:04:23 +00:00
/* Returns true if the kext should be loaded according to plist
and osbundlereq. Also fill BINNAME. */
static int
Add missing const qualifiers. * grub-core/commands/i386/pc/sendkey.c (keysym): Add missing const. * grub-core/commands/lspci.c (grub_pci_classname): Likewise. * grub-core/commands/menuentry.c (hotkey_aliases): Likewise. * grub-core/disk/lvm.c (grub_lvm_getvalue): Likewise. (grub_lvm_check_flag): Likewise. * grub-core/efiemu/i386/coredetect.c (grub_efiemu_get_default_core_name): Likewise * grub-core/efiemu/main.c (grub_efiemu_autocore): Likewise. * grub-core/fs/hfsplus.c (grub_hfsplus_catkey_internal): Likewise. * grub-core/fs/ntfs.c (fixup): Likewise. * grub-core/fs/xfs.c (grub_xfs_iterate_dir): Likewise. * grub-core/fs/zfs/zfs.c (decomp_entry): Likewise. (fzap_lookup): Likewise. (zap_lookup): Likewise. * grub-core/gnulib/regcomp.c (init_dfa): Likewise. * grub-core/lib/legacy_parse.c (check_option): Likewise. * grub-core/lib/posix_wrap/langinfo.h (nl_langinfo): Likewise. * grub-core/loader/i386/bsd.c (grub_bsd_add_meta): Likewise. (grub_freebsd_add_meta_module): Likewise. (grub_cmd_freebsd_module): Likewise. * grub-core/loader/i386/xnu.c (tbl_alias): Likewise. * grub-core/loader/xnu.c (grub_xnu_register_memory): Likewise. (grub_xnu_writetree_get_size): Likewise. (grub_xnu_writetree_toheap_real): Likewise. (grub_xnu_find_key): Likewise. (grub_xnu_create_key): Likewise. (grub_xnu_create_value): Likewise. (grub_xnu_register_memory): Likewise. (grub_xnu_check_os_bundle_required): Likewise. (grub_xnu_scan_dir_for_kexts): Likewise. (grub_xnu_load_kext_from_dir): Likewise. * grub-core/normal/color.c (color_list): Likewise. * grub-core/normal/completion.c (current_word): Likewise. * grub-core/normal/menu_entry.c (insert_string): Likewise. * grub-core/term/serial.c (grub_serial_find): Likewise. * grub-core/term/tparm.c (grub_terminfo_tparm): Likewise. * include/grub/efiemu/efiemu.h (grub_efiemu_get_default_core_name): Likewise. * include/grub/i386/bsd.h (grub_bsd_add_meta): Likewise. (grub_freebsd_add_meta_module): Likewise. * include/grub/lib/arg.h (grub_arg_option): Likewise. * include/grub/net.h (grub_net_card_driver): Likewise. (grub_net_card): Likewise. (grub_net_app_protocol): Likewise. * include/grub/parttool.h (grub_parttool_argdesc): Likewise. * include/grub/serial.h (grub_serial_find): Likewise. * include/grub/tparm.h (grub_terminfo_tparm): Likewise. * include/grub/xnu.h (grub_xnu_create_key): Likewise. (grub_xnu_create_value): Likewise. (grub_xnu_find_key): Likewise. (grub_xnu_scan_dir_for_kexts): Likewise. (grub_xnu_load_kext_from_dir): Likewise. * include/grub/zfs/zio_checksum.h (zio_checksum_t): Moved from here ... * grub-core/fs/zfs/zfs.c (zio_checksum_t): ...here. * include/grub/zfs/zio_checksum.h (zio_checksum_info): Moved from here ... * grub-core/fs/zfs/zfs.c (zio_checksum_info): ... here. Added missing const.
2011-11-30 15:20:13 +00:00
grub_xnu_check_os_bundle_required (char *plistname,
const char *osbundlereq,
char **binname)
{
grub_file_t file;
char *buf = 0, *tagstart = 0, *ptr1 = 0, *keyptr = 0;
char *stringptr = 0, *ptr2 = 0;
grub_size_t size;
int depth = 0;
int ret;
int osbundlekeyfound = 0, binnamekeyfound = 0;
if (binname)
*binname = 0;
file = grub_file_open (plistname);
if (! file)
return 0;
size = grub_file_size (file);
buf = grub_malloc (size);
if (! buf)
{
2009-06-10 21:04:23 +00:00
grub_file_close (file);
return 0;
}
if (grub_file_read (file, buf, size) != (grub_ssize_t) (size))
{
2009-06-10 21:04:23 +00:00
grub_file_close (file);
if (!grub_errno)
grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"), plistname);
return 0;
}
2009-06-10 21:04:23 +00:00
grub_file_close (file);
/* Set the return value for the case when no OSBundleRequired tag is found. */
if (osbundlereq)
ret = grub_strword (osbundlereq, "all") || grub_strword (osbundlereq, "-");
else
ret = 1;
2009-06-10 21:04:23 +00:00
/* Parse plist. It's quite dirty and inextensible but does its job. */
for (ptr1 = buf; ptr1 < buf + size; ptr1++)
switch (*ptr1)
{
case '<':
tagstart = ptr1;
*ptr1 = 0;
2009-06-10 21:04:23 +00:00
if (keyptr && depth == 4
&& grub_strcmp (keyptr, "OSBundleRequired") == 0)
osbundlekeyfound = 1;
2009-06-10 21:04:23 +00:00
if (keyptr && depth == 4 &&
grub_strcmp (keyptr, "CFBundleExecutable") == 0)
binnamekeyfound = 1;
if (stringptr && osbundlekeyfound && osbundlereq && depth == 4)
{
for (ptr2 = stringptr; *ptr2; ptr2++)
*ptr2 = grub_tolower (*ptr2);
2009-06-10 21:04:23 +00:00
ret = grub_strword (osbundlereq, stringptr)
|| grub_strword (osbundlereq, "all");
}
if (stringptr && binnamekeyfound && binname && depth == 4)
{
if (*binname)
grub_free (*binname);
*binname = grub_strdup (stringptr);
}
*ptr1 = '<';
keyptr = 0;
stringptr = 0;
break;
case '>':
if (! tagstart)
{
grub_free (buf);
grub_error (GRUB_ERR_BAD_OS, "can't parse %s", plistname);
return 0;
}
*ptr1 = 0;
if (tagstart[1] == '?' || ptr1[-1] == '/')
{
osbundlekeyfound = 0;
*ptr1 = '>';
break;
}
if (depth == 3 && grub_strcmp (tagstart + 1, "key") == 0)
keyptr = ptr1 + 1;
if (depth == 3 && grub_strcmp (tagstart + 1, "string") == 0)
2009-06-10 21:04:23 +00:00
stringptr = ptr1 + 1;
else if (grub_strcmp (tagstart + 1, "/key") != 0)
{
osbundlekeyfound = 0;
binnamekeyfound = 0;
}
*ptr1 = '>';
2009-06-10 21:04:23 +00:00
if (tagstart[1] == '/')
depth--;
else
depth++;
break;
}
grub_free (buf);
2009-06-10 21:04:23 +00:00
return ret;
}
/* Load all loadable kexts placed under DIRNAME and matching OSBUNDLEREQUIRED */
grub_err_t
Add missing const qualifiers. * grub-core/commands/i386/pc/sendkey.c (keysym): Add missing const. * grub-core/commands/lspci.c (grub_pci_classname): Likewise. * grub-core/commands/menuentry.c (hotkey_aliases): Likewise. * grub-core/disk/lvm.c (grub_lvm_getvalue): Likewise. (grub_lvm_check_flag): Likewise. * grub-core/efiemu/i386/coredetect.c (grub_efiemu_get_default_core_name): Likewise * grub-core/efiemu/main.c (grub_efiemu_autocore): Likewise. * grub-core/fs/hfsplus.c (grub_hfsplus_catkey_internal): Likewise. * grub-core/fs/ntfs.c (fixup): Likewise. * grub-core/fs/xfs.c (grub_xfs_iterate_dir): Likewise. * grub-core/fs/zfs/zfs.c (decomp_entry): Likewise. (fzap_lookup): Likewise. (zap_lookup): Likewise. * grub-core/gnulib/regcomp.c (init_dfa): Likewise. * grub-core/lib/legacy_parse.c (check_option): Likewise. * grub-core/lib/posix_wrap/langinfo.h (nl_langinfo): Likewise. * grub-core/loader/i386/bsd.c (grub_bsd_add_meta): Likewise. (grub_freebsd_add_meta_module): Likewise. (grub_cmd_freebsd_module): Likewise. * grub-core/loader/i386/xnu.c (tbl_alias): Likewise. * grub-core/loader/xnu.c (grub_xnu_register_memory): Likewise. (grub_xnu_writetree_get_size): Likewise. (grub_xnu_writetree_toheap_real): Likewise. (grub_xnu_find_key): Likewise. (grub_xnu_create_key): Likewise. (grub_xnu_create_value): Likewise. (grub_xnu_register_memory): Likewise. (grub_xnu_check_os_bundle_required): Likewise. (grub_xnu_scan_dir_for_kexts): Likewise. (grub_xnu_load_kext_from_dir): Likewise. * grub-core/normal/color.c (color_list): Likewise. * grub-core/normal/completion.c (current_word): Likewise. * grub-core/normal/menu_entry.c (insert_string): Likewise. * grub-core/term/serial.c (grub_serial_find): Likewise. * grub-core/term/tparm.c (grub_terminfo_tparm): Likewise. * include/grub/efiemu/efiemu.h (grub_efiemu_get_default_core_name): Likewise. * include/grub/i386/bsd.h (grub_bsd_add_meta): Likewise. (grub_freebsd_add_meta_module): Likewise. * include/grub/lib/arg.h (grub_arg_option): Likewise. * include/grub/net.h (grub_net_card_driver): Likewise. (grub_net_card): Likewise. (grub_net_app_protocol): Likewise. * include/grub/parttool.h (grub_parttool_argdesc): Likewise. * include/grub/serial.h (grub_serial_find): Likewise. * include/grub/tparm.h (grub_terminfo_tparm): Likewise. * include/grub/xnu.h (grub_xnu_create_key): Likewise. (grub_xnu_create_value): Likewise. (grub_xnu_find_key): Likewise. (grub_xnu_scan_dir_for_kexts): Likewise. (grub_xnu_load_kext_from_dir): Likewise. * include/grub/zfs/zio_checksum.h (zio_checksum_t): Moved from here ... * grub-core/fs/zfs/zfs.c (zio_checksum_t): ...here. * include/grub/zfs/zio_checksum.h (zio_checksum_info): Moved from here ... * grub-core/fs/zfs/zfs.c (zio_checksum_info): ... here. Added missing const.
2011-11-30 15:20:13 +00:00
grub_xnu_scan_dir_for_kexts (char *dirname, const char *osbundlerequired,
int maxrecursion)
{
grub_device_t dev;
char *device_name;
grub_fs_t fs;
const char *path;
2009-06-10 21:04:23 +00:00
auto int load_hook (const char *filename,
const struct grub_dirhook_info *info);
int load_hook (const char *filename, const struct grub_dirhook_info *info)
{
char *newdirname;
if (! info->dir)
return 0;
if (filename[0] == '.')
return 0;
if (grub_strlen (filename) < 5 ||
grub_memcmp (filename + grub_strlen (filename) - 5, ".kext", 5) != 0)
return 0;
2009-06-10 21:04:23 +00:00
newdirname
= grub_malloc (grub_strlen (dirname) + grub_strlen (filename) + 2);
/* It's a .kext. Try to load it. */
if (newdirname)
{
grub_strcpy (newdirname, dirname);
newdirname[grub_strlen (newdirname) + 1] = 0;
newdirname[grub_strlen (newdirname)] = '/';
grub_strcpy (newdirname + grub_strlen (newdirname), filename);
2009-06-10 21:04:23 +00:00
grub_xnu_load_kext_from_dir (newdirname, osbundlerequired,
maxrecursion);
if (grub_errno == GRUB_ERR_BAD_OS)
grub_errno = GRUB_ERR_NONE;
grub_free (newdirname);
}
return 0;
}
if (! grub_xnu_heap_size)
return grub_error (GRUB_ERR_BAD_OS, N_("you need to load the kernel first"));
device_name = grub_file_get_device_name (dirname);
dev = grub_device_open (device_name);
if (dev)
{
fs = grub_fs_probe (dev);
path = grub_strchr (dirname, ')');
if (! path)
path = dirname;
else
path++;
if (fs)
(fs->dir) (dev, path, load_hook);
grub_device_close (dev);
}
grub_free (device_name);
return GRUB_ERR_NONE;
}
/* Load extension DIRNAME. (extensions are directories in xnu) */
grub_err_t
Add missing const qualifiers. * grub-core/commands/i386/pc/sendkey.c (keysym): Add missing const. * grub-core/commands/lspci.c (grub_pci_classname): Likewise. * grub-core/commands/menuentry.c (hotkey_aliases): Likewise. * grub-core/disk/lvm.c (grub_lvm_getvalue): Likewise. (grub_lvm_check_flag): Likewise. * grub-core/efiemu/i386/coredetect.c (grub_efiemu_get_default_core_name): Likewise * grub-core/efiemu/main.c (grub_efiemu_autocore): Likewise. * grub-core/fs/hfsplus.c (grub_hfsplus_catkey_internal): Likewise. * grub-core/fs/ntfs.c (fixup): Likewise. * grub-core/fs/xfs.c (grub_xfs_iterate_dir): Likewise. * grub-core/fs/zfs/zfs.c (decomp_entry): Likewise. (fzap_lookup): Likewise. (zap_lookup): Likewise. * grub-core/gnulib/regcomp.c (init_dfa): Likewise. * grub-core/lib/legacy_parse.c (check_option): Likewise. * grub-core/lib/posix_wrap/langinfo.h (nl_langinfo): Likewise. * grub-core/loader/i386/bsd.c (grub_bsd_add_meta): Likewise. (grub_freebsd_add_meta_module): Likewise. (grub_cmd_freebsd_module): Likewise. * grub-core/loader/i386/xnu.c (tbl_alias): Likewise. * grub-core/loader/xnu.c (grub_xnu_register_memory): Likewise. (grub_xnu_writetree_get_size): Likewise. (grub_xnu_writetree_toheap_real): Likewise. (grub_xnu_find_key): Likewise. (grub_xnu_create_key): Likewise. (grub_xnu_create_value): Likewise. (grub_xnu_register_memory): Likewise. (grub_xnu_check_os_bundle_required): Likewise. (grub_xnu_scan_dir_for_kexts): Likewise. (grub_xnu_load_kext_from_dir): Likewise. * grub-core/normal/color.c (color_list): Likewise. * grub-core/normal/completion.c (current_word): Likewise. * grub-core/normal/menu_entry.c (insert_string): Likewise. * grub-core/term/serial.c (grub_serial_find): Likewise. * grub-core/term/tparm.c (grub_terminfo_tparm): Likewise. * include/grub/efiemu/efiemu.h (grub_efiemu_get_default_core_name): Likewise. * include/grub/i386/bsd.h (grub_bsd_add_meta): Likewise. (grub_freebsd_add_meta_module): Likewise. * include/grub/lib/arg.h (grub_arg_option): Likewise. * include/grub/net.h (grub_net_card_driver): Likewise. (grub_net_card): Likewise. (grub_net_app_protocol): Likewise. * include/grub/parttool.h (grub_parttool_argdesc): Likewise. * include/grub/serial.h (grub_serial_find): Likewise. * include/grub/tparm.h (grub_terminfo_tparm): Likewise. * include/grub/xnu.h (grub_xnu_create_key): Likewise. (grub_xnu_create_value): Likewise. (grub_xnu_find_key): Likewise. (grub_xnu_scan_dir_for_kexts): Likewise. (grub_xnu_load_kext_from_dir): Likewise. * include/grub/zfs/zio_checksum.h (zio_checksum_t): Moved from here ... * grub-core/fs/zfs/zfs.c (zio_checksum_t): ...here. * include/grub/zfs/zio_checksum.h (zio_checksum_info): Moved from here ... * grub-core/fs/zfs/zfs.c (zio_checksum_info): ... here. Added missing const.
2011-11-30 15:20:13 +00:00
grub_xnu_load_kext_from_dir (char *dirname, const char *osbundlerequired,
int maxrecursion)
{
grub_device_t dev;
char *plistname = 0;
char *newdirname;
char *newpath;
char *device_name;
grub_fs_t fs;
const char *path;
char *binsuffix;
int usemacos = 0;
grub_file_t binfile;
2009-06-10 21:04:23 +00:00
auto int load_hook (const char *filename,
const struct grub_dirhook_info *info);
int load_hook (const char *filename, const struct grub_dirhook_info *info)
{
if (grub_strlen (filename) > 15)
return 0;
2009-06-10 21:04:23 +00:00
grub_strcpy (newdirname + grub_strlen (dirname) + 1, filename);
2009-06-10 21:04:23 +00:00
/* If the kext contains directory "Contents" all real stuff is in
this directory. */
if (info->dir && grub_strcasecmp (filename, "Contents") == 0)
grub_xnu_load_kext_from_dir (newdirname, osbundlerequired,
maxrecursion - 1);
/* Directory "Plugins" contains nested kexts. */
if (info->dir && grub_strcasecmp (filename, "Plugins") == 0)
2009-06-10 21:04:23 +00:00
grub_xnu_scan_dir_for_kexts (newdirname, osbundlerequired,
maxrecursion - 1);
2009-06-10 21:04:23 +00:00
/* Directory "MacOS" contains executable, otherwise executable is
on the top. */
if (info->dir && grub_strcasecmp (filename, "MacOS") == 0)
usemacos = 1;
2009-06-10 21:04:23 +00:00
/* Info.plist is the file which governs our future actions. */
2009-06-10 21:04:23 +00:00
if (! info->dir && grub_strcasecmp (filename, "Info.plist") == 0
&& ! plistname)
plistname = grub_strdup (newdirname);
return 0;
}
newdirname = grub_malloc (grub_strlen (dirname) + 20);
if (! newdirname)
return grub_errno;
grub_strcpy (newdirname, dirname);
newdirname[grub_strlen (dirname)] = '/';
2009-06-10 21:04:23 +00:00
newdirname[grub_strlen (dirname) + 1] = 0;
device_name = grub_file_get_device_name (dirname);
dev = grub_device_open (device_name);
if (dev)
{
fs = grub_fs_probe (dev);
path = grub_strchr (dirname, ')');
if (! path)
path = dirname;
else
path++;
newpath = grub_strchr (newdirname, ')');
if (! newpath)
newpath = newdirname;
else
newpath++;
2009-06-10 21:04:23 +00:00
/* Look at the directory. */
if (fs)
(fs->dir) (dev, path, load_hook);
2009-06-10 21:04:23 +00:00
if (plistname && grub_xnu_check_os_bundle_required
(plistname, osbundlerequired, &binsuffix))
{
if (binsuffix)
{
/* Open the binary. */
2009-06-10 21:04:23 +00:00
char *binname = grub_malloc (grub_strlen (dirname)
+ grub_strlen (binsuffix)
+ sizeof ("/MacOS/"));
grub_strcpy (binname, dirname);
if (usemacos)
grub_strcpy (binname + grub_strlen (binname), "/MacOS/");
else
grub_strcpy (binname + grub_strlen (binname), "/");
grub_strcpy (binname + grub_strlen (binname), binsuffix);
grub_dprintf ("xnu", "%s:%s\n", plistname, binname);
binfile = grub_file_open (binname);
2009-06-10 21:04:23 +00:00
if (! binfile)
grub_errno = GRUB_ERR_NONE;
2009-06-10 21:04:23 +00:00
/* Load the extension. */
grub_xnu_load_driver (plistname, binfile,
binname);
grub_free (binname);
grub_free (binsuffix);
}
else
{
grub_dprintf ("xnu", "%s:0\n", plistname);
grub_xnu_load_driver (plistname, 0, 0);
}
}
grub_free (plistname);
grub_device_close (dev);
}
grub_free (device_name);
return GRUB_ERR_NONE;
}
static int locked=0;
static grub_dl_t my_mod;
/* Load the kext. */
static grub_err_t
grub_cmd_xnu_kext (grub_command_t cmd __attribute__ ((unused)),
int argc, char *args[])
{
grub_file_t binfile = 0;
if (! grub_xnu_heap_size)
return grub_error (GRUB_ERR_BAD_OS, N_("you need to load the kernel first"));
if (argc == 2)
{
/* User explicitly specified plist and binary. */
if (grub_strcmp (args[1], "-") != 0)
{
binfile = grub_file_open (args[1]);
if (! binfile)
return grub_errno;
}
return grub_xnu_load_driver (grub_strcmp (args[0], "-") ? args[0] : 0,
binfile, args[1]);
}
/* load kext normally. */
if (argc == 1)
return grub_xnu_load_kext_from_dir (args[0], 0, 10);
return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
}
/* Load a directory containing kexts. */
static grub_err_t
grub_cmd_xnu_kextdir (grub_command_t cmd __attribute__ ((unused)),
int argc, char *args[])
{
if (argc != 1 && argc != 2)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "directory name required");
if (! grub_xnu_heap_size)
return grub_error (GRUB_ERR_BAD_OS, N_("you need to load the kernel first"));
if (argc == 1)
2009-06-10 21:04:23 +00:00
return grub_xnu_scan_dir_for_kexts (args[0],
"console,root,local-root,network-root",
10);
else
{
char *osbundlerequired = grub_strdup (args[1]), *ptr;
grub_err_t err;
if (! osbundlerequired)
return grub_errno;
for (ptr = osbundlerequired; *ptr; ptr++)
*ptr = grub_tolower (*ptr);
err = grub_xnu_scan_dir_for_kexts (args[0], osbundlerequired, 10);
grub_free (osbundlerequired);
return err;
}
}
2009-11-09 17:43:53 +00:00
static inline int
hextoval (char c)
{
if (c >= '0' && c <= '9')
return c - '0';
if (c >= 'a' && c <= 'z')
return c - 'a' + 10;
if (c >= 'A' && c <= 'Z')
return c - 'A' + 10;
return 0;
}
static inline void
unescape (char *name, char *curdot, char *nextdot, int *len)
{
char *ptr, *dptr;
dptr = name;
for (ptr = curdot; ptr < nextdot;)
if (ptr + 2 < nextdot && *ptr == '%')
{
*dptr = (hextoval (ptr[1]) << 4) | (hextoval (ptr[2]));
ptr += 3;
dptr++;
}
else
{
*dptr = *ptr;
ptr++;
dptr++;
}
*len = dptr - name;
}
grub_err_t
grub_xnu_fill_devicetree (void)
{
auto int iterate_env (struct grub_env_var *var);
int iterate_env (struct grub_env_var *var)
{
char *nextdot = 0, *curdot;
struct grub_xnu_devtree_key **curkey = &grub_xnu_devtree_root;
struct grub_xnu_devtree_key *curvalue;
char *name = 0, *data;
int len;
if (grub_memcmp (var->name, "XNU.DeviceTree.",
sizeof ("XNU.DeviceTree.") - 1) != 0)
return 0;
curdot = var->name + sizeof ("XNU.DeviceTree.") - 1;
nextdot = grub_strchr (curdot, '.');
if (nextdot)
nextdot++;
while (nextdot)
{
name = grub_realloc (name, nextdot - curdot + 1);
if (!name)
return 1;
unescape (name, curdot, nextdot, &len);
name[len - 1] = 0;
curkey = &(grub_xnu_create_key (curkey, name)->first_child);
curdot = nextdot;
nextdot = grub_strchr (nextdot, '.');
if (nextdot)
nextdot++;
}
nextdot = curdot + grub_strlen (curdot) + 1;
name = grub_realloc (name, nextdot - curdot + 1);
2009-12-23 Felix Zielcke <fzielcke@z-51.de> * commands/i386/pc/drivemap.c: Remove all trailing whitespace. * commands/lspci.c: Likewise. * commands/probe.c: Likewise. * commands/xnu_uuid.c: Likewise. * conf/i386-coreboot.rmk: Likewise. * conf/i386-efi.rmk: Likewise. * conf/i386-ieee1275.rmk: Likewise. * conf/i386-pc.rmk: Likewise. * conf/powerpc-ieee1275.rmk: Likewise. * conf/sparc64-ieee1275.rmk: Likewise. * conf/x86_64-efi.rmk: Likewise. * fs/i386/pc/pxe.c: Likewise. * gettext/gettext.c: Likewise. * include/grub/efi/graphics_output.h: Likewise. * include/grub/i386/pc/memory.h: Likewise. * kern/env.c: Likewise. * kern/i386/qemu/startup.S: Likewise. * lib/i386/pc/biosnum.c: Likewise. * lib/i386/relocator.c: Likewise. * lib/i386/relocator_asm.S: Likewise. * lib/relocator.c: Likewise. * loader/i386/bsd.c: Likewise. * loader/i386/multiboot.c: Likewise. * loader/i386/pc/chainloader.c: Likewise. * loader/i386/xnu.c: Likewise. * loader/xnu.c: Likewise. * normal/main.c: Likewise. * normal/menu_text.c: Likewise. * util/getroot.c: Likewise. * util/grub-mkconfig_lib.in: Likewise. * util/grub.d/00_header.in: Likewise. * util/i386/pc/grub-mkimage.c: Likewise. * util/mkisofs/eltorito.c: Likewise. * util/mkisofs/exclude.h: Likewise. * util/mkisofs/hash.c: Likewise. * util/mkisofs/iso9660.h: Likewise. * util/mkisofs/joliet.c: Likewise. * util/mkisofs/mkisofs.c: Likewise. * util/mkisofs/mkisofs.h: Likewise. * util/mkisofs/multi.c: Likewise. * util/mkisofs/name.c: Likewise. * util/mkisofs/rock.c: Likewise. * util/mkisofs/tree.c: Likewise. * util/mkisofs/write.c: Likewise. * video/efi_gop.c: Likewise.
2009-12-23 16:41:32 +00:00
2009-11-09 17:43:53 +00:00
if (!name)
return 1;
2009-12-23 Felix Zielcke <fzielcke@z-51.de> * commands/i386/pc/drivemap.c: Remove all trailing whitespace. * commands/lspci.c: Likewise. * commands/probe.c: Likewise. * commands/xnu_uuid.c: Likewise. * conf/i386-coreboot.rmk: Likewise. * conf/i386-efi.rmk: Likewise. * conf/i386-ieee1275.rmk: Likewise. * conf/i386-pc.rmk: Likewise. * conf/powerpc-ieee1275.rmk: Likewise. * conf/sparc64-ieee1275.rmk: Likewise. * conf/x86_64-efi.rmk: Likewise. * fs/i386/pc/pxe.c: Likewise. * gettext/gettext.c: Likewise. * include/grub/efi/graphics_output.h: Likewise. * include/grub/i386/pc/memory.h: Likewise. * kern/env.c: Likewise. * kern/i386/qemu/startup.S: Likewise. * lib/i386/pc/biosnum.c: Likewise. * lib/i386/relocator.c: Likewise. * lib/i386/relocator_asm.S: Likewise. * lib/relocator.c: Likewise. * loader/i386/bsd.c: Likewise. * loader/i386/multiboot.c: Likewise. * loader/i386/pc/chainloader.c: Likewise. * loader/i386/xnu.c: Likewise. * loader/xnu.c: Likewise. * normal/main.c: Likewise. * normal/menu_text.c: Likewise. * util/getroot.c: Likewise. * util/grub-mkconfig_lib.in: Likewise. * util/grub.d/00_header.in: Likewise. * util/i386/pc/grub-mkimage.c: Likewise. * util/mkisofs/eltorito.c: Likewise. * util/mkisofs/exclude.h: Likewise. * util/mkisofs/hash.c: Likewise. * util/mkisofs/iso9660.h: Likewise. * util/mkisofs/joliet.c: Likewise. * util/mkisofs/mkisofs.c: Likewise. * util/mkisofs/mkisofs.h: Likewise. * util/mkisofs/multi.c: Likewise. * util/mkisofs/name.c: Likewise. * util/mkisofs/rock.c: Likewise. * util/mkisofs/tree.c: Likewise. * util/mkisofs/write.c: Likewise. * video/efi_gop.c: Likewise.
2009-12-23 16:41:32 +00:00
2009-11-09 17:43:53 +00:00
unescape (name, curdot, nextdot, &len);
name[len] = 0;
curvalue = grub_xnu_create_value (curkey, name);
grub_free (name);
2009-12-23 Felix Zielcke <fzielcke@z-51.de> * commands/i386/pc/drivemap.c: Remove all trailing whitespace. * commands/lspci.c: Likewise. * commands/probe.c: Likewise. * commands/xnu_uuid.c: Likewise. * conf/i386-coreboot.rmk: Likewise. * conf/i386-efi.rmk: Likewise. * conf/i386-ieee1275.rmk: Likewise. * conf/i386-pc.rmk: Likewise. * conf/powerpc-ieee1275.rmk: Likewise. * conf/sparc64-ieee1275.rmk: Likewise. * conf/x86_64-efi.rmk: Likewise. * fs/i386/pc/pxe.c: Likewise. * gettext/gettext.c: Likewise. * include/grub/efi/graphics_output.h: Likewise. * include/grub/i386/pc/memory.h: Likewise. * kern/env.c: Likewise. * kern/i386/qemu/startup.S: Likewise. * lib/i386/pc/biosnum.c: Likewise. * lib/i386/relocator.c: Likewise. * lib/i386/relocator_asm.S: Likewise. * lib/relocator.c: Likewise. * loader/i386/bsd.c: Likewise. * loader/i386/multiboot.c: Likewise. * loader/i386/pc/chainloader.c: Likewise. * loader/i386/xnu.c: Likewise. * loader/xnu.c: Likewise. * normal/main.c: Likewise. * normal/menu_text.c: Likewise. * util/getroot.c: Likewise. * util/grub-mkconfig_lib.in: Likewise. * util/grub.d/00_header.in: Likewise. * util/i386/pc/grub-mkimage.c: Likewise. * util/mkisofs/eltorito.c: Likewise. * util/mkisofs/exclude.h: Likewise. * util/mkisofs/hash.c: Likewise. * util/mkisofs/iso9660.h: Likewise. * util/mkisofs/joliet.c: Likewise. * util/mkisofs/mkisofs.c: Likewise. * util/mkisofs/mkisofs.h: Likewise. * util/mkisofs/multi.c: Likewise. * util/mkisofs/name.c: Likewise. * util/mkisofs/rock.c: Likewise. * util/mkisofs/tree.c: Likewise. * util/mkisofs/write.c: Likewise. * video/efi_gop.c: Likewise.
2009-12-23 16:41:32 +00:00
2009-11-09 17:43:53 +00:00
data = grub_malloc (grub_strlen (var->value) + 1);
if (!data)
return 1;
2009-12-23 Felix Zielcke <fzielcke@z-51.de> * commands/i386/pc/drivemap.c: Remove all trailing whitespace. * commands/lspci.c: Likewise. * commands/probe.c: Likewise. * commands/xnu_uuid.c: Likewise. * conf/i386-coreboot.rmk: Likewise. * conf/i386-efi.rmk: Likewise. * conf/i386-ieee1275.rmk: Likewise. * conf/i386-pc.rmk: Likewise. * conf/powerpc-ieee1275.rmk: Likewise. * conf/sparc64-ieee1275.rmk: Likewise. * conf/x86_64-efi.rmk: Likewise. * fs/i386/pc/pxe.c: Likewise. * gettext/gettext.c: Likewise. * include/grub/efi/graphics_output.h: Likewise. * include/grub/i386/pc/memory.h: Likewise. * kern/env.c: Likewise. * kern/i386/qemu/startup.S: Likewise. * lib/i386/pc/biosnum.c: Likewise. * lib/i386/relocator.c: Likewise. * lib/i386/relocator_asm.S: Likewise. * lib/relocator.c: Likewise. * loader/i386/bsd.c: Likewise. * loader/i386/multiboot.c: Likewise. * loader/i386/pc/chainloader.c: Likewise. * loader/i386/xnu.c: Likewise. * loader/xnu.c: Likewise. * normal/main.c: Likewise. * normal/menu_text.c: Likewise. * util/getroot.c: Likewise. * util/grub-mkconfig_lib.in: Likewise. * util/grub.d/00_header.in: Likewise. * util/i386/pc/grub-mkimage.c: Likewise. * util/mkisofs/eltorito.c: Likewise. * util/mkisofs/exclude.h: Likewise. * util/mkisofs/hash.c: Likewise. * util/mkisofs/iso9660.h: Likewise. * util/mkisofs/joliet.c: Likewise. * util/mkisofs/mkisofs.c: Likewise. * util/mkisofs/mkisofs.h: Likewise. * util/mkisofs/multi.c: Likewise. * util/mkisofs/name.c: Likewise. * util/mkisofs/rock.c: Likewise. * util/mkisofs/tree.c: Likewise. * util/mkisofs/write.c: Likewise. * video/efi_gop.c: Likewise.
2009-12-23 16:41:32 +00:00
2009-11-09 17:43:53 +00:00
unescape (data, var->value, var->value + grub_strlen (var->value),
&len);
curvalue->datasize = len;
curvalue->data = data;
return 0;
}
grub_env_iterate (iterate_env);
return grub_errno;
}
struct grub_video_bitmap *grub_xnu_bitmap = 0;
2009-11-20 09:46:30 +00:00
grub_xnu_bitmap_mode_t grub_xnu_bitmap_mode;
/* Option array indices. */
#define XNU_SPLASH_CMD_ARGINDEX_MODE 0
static const struct grub_arg_option xnu_splash_cmd_options[] =
{
{"mode", 'm', 0, N_("Background image mode."), N_("stretch|normal"),
2009-11-20 09:46:30 +00:00
ARG_TYPE_STRING},
{0, 0, 0, 0, 0, 0}
};
static grub_err_t
2010-06-10 06:42:03 +00:00
grub_cmd_xnu_splash (grub_extcmd_context_t ctxt,
int argc, char *args[])
{
grub_err_t err;
if (argc != 1)
return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
2009-06-10 21:04:23 +00:00
if (! grub_xnu_heap_size)
return grub_error (GRUB_ERR_BAD_OS, N_("you need to load the kernel first"));
2010-06-10 06:42:03 +00:00
if (ctxt->state[XNU_SPLASH_CMD_ARGINDEX_MODE].set &&
grub_strcmp (ctxt->state[XNU_SPLASH_CMD_ARGINDEX_MODE].arg,
2009-11-20 09:46:30 +00:00
"stretch") == 0)
grub_xnu_bitmap_mode = GRUB_XNU_BITMAP_STRETCH;
else
grub_xnu_bitmap_mode = GRUB_XNU_BITMAP_CENTER;
err = grub_video_bitmap_load (&grub_xnu_bitmap, args[0]);
if (err)
grub_xnu_bitmap = 0;
2009-11-20 09:46:30 +00:00
return err;
}
#ifndef GRUB_MACHINE_EMU
static grub_err_t
grub_cmd_xnu_resume (grub_command_t cmd __attribute__ ((unused)),
int argc, char *args[])
{
if (argc != 1)
return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
2009-06-10 21:04:23 +00:00
return grub_xnu_resume (args[0]);
}
#endif
void
grub_xnu_lock (void)
{
if (!locked)
grub_dl_ref (my_mod);
locked = 1;
}
void
grub_xnu_unlock (void)
{
if (locked)
grub_dl_unref (my_mod);
locked = 0;
}
2009-09-02 00:52:10 +00:00
static grub_command_t cmd_kernel64, cmd_kernel, cmd_mkext, cmd_kext;
2009-11-20 09:46:30 +00:00
static grub_command_t cmd_kextdir, cmd_ramdisk, cmd_resume;
static grub_extcmd_t cmd_splash;
GRUB_MOD_INIT(xnu)
{
cmd_kernel = grub_register_command ("xnu_kernel", grub_cmd_xnu_kernel, 0,
2010-01-08 Carles Pina i Estany <carles@pina.cat> * loader/efi/appleloader.c: Include `<grub/i18n.h>'. (GRUB_MOD_INIT): Gettextizze. * loader/efi/chainloader.c: Include `<grub/i18n.h>'. (GRUB_MOD_INIT): Gettextizze. * loader/i386/efi/linux.c: Include `<grub/i18n.h>'. (grub_cmd_linux): Capitalise Linux. (GRUB_MOD_INIT): Gettextizze. * loader/i386/ieee1275/linux.c: Include `<grub/i18n.h>'. (grub_cmd_linux): Capitalise Linux. (GRUB_MOD_INIT): Gettextizze. * loader/i386/linux.c: Include `<grub/i18n.h>'. (grub_cmd_linux): Capitalise Linux. (GRUB_MOD_INIT): Gettextizze. * loader/i386/pc/chainloader.c: Include `<grub/i18n.h>'. (GRUB_MOD_INIT): Gettextizze. * loader/i386/pc/linux.c: Include `<grub/i18n.h>'. (grub_cmd_linux): Capitalise Linux. (GRUB_MOD_INIT): Gettextizze. * loader/i386/xnu.c: Include `<grub/i18n.h>'. (grub_cpu_xnu_init): Gettextizze. * loader/multiboot_loader.c: Include `<grub/i18n.h>'. (GRUB_MOD_INIT): Gettextizze. * loader/powerpc/ieee1275/linux.c: Include `<grub/i18n.h>'. (GRUB_MOD_INIT): Gettextizze. * loader/sparc64/ieee1275/linux.c: Include `<grub/i18n.h>'. (grub_linux_load64): Capitalise Linux. (GRUB_MOD_INIT): Gettextizze. * loader/xnu.c: Include `<grub/i18n.h>'. (GRUB_MOD_INIT): Gettextizze. * po/POTFILES: Add `loader/efi/appleloader.c', `loader/efi/chainloader.c', `loader/i386/efi/linux.c', `loader/i386/ieee1275/linux.c', `loader/i386/linux.c', `loader/i386/pc/chainloader.c', `loader/i386/pc/linux.c', `loader/i386/xnu.c', `loader/multiboot_loader.c', `loader/powerpc/ieee1275/linux.c', `loader/sparc64/ieee1275/linux.c' and `loader/xnu.c'.
2010-01-08 21:35:38 +00:00
N_("Load XNU image."));
2009-09-02 00:52:10 +00:00
cmd_kernel64 = grub_register_command ("xnu_kernel64", grub_cmd_xnu_kernel64,
2010-01-08 Carles Pina i Estany <carles@pina.cat> * loader/efi/appleloader.c: Include `<grub/i18n.h>'. (GRUB_MOD_INIT): Gettextizze. * loader/efi/chainloader.c: Include `<grub/i18n.h>'. (GRUB_MOD_INIT): Gettextizze. * loader/i386/efi/linux.c: Include `<grub/i18n.h>'. (grub_cmd_linux): Capitalise Linux. (GRUB_MOD_INIT): Gettextizze. * loader/i386/ieee1275/linux.c: Include `<grub/i18n.h>'. (grub_cmd_linux): Capitalise Linux. (GRUB_MOD_INIT): Gettextizze. * loader/i386/linux.c: Include `<grub/i18n.h>'. (grub_cmd_linux): Capitalise Linux. (GRUB_MOD_INIT): Gettextizze. * loader/i386/pc/chainloader.c: Include `<grub/i18n.h>'. (GRUB_MOD_INIT): Gettextizze. * loader/i386/pc/linux.c: Include `<grub/i18n.h>'. (grub_cmd_linux): Capitalise Linux. (GRUB_MOD_INIT): Gettextizze. * loader/i386/xnu.c: Include `<grub/i18n.h>'. (grub_cpu_xnu_init): Gettextizze. * loader/multiboot_loader.c: Include `<grub/i18n.h>'. (GRUB_MOD_INIT): Gettextizze. * loader/powerpc/ieee1275/linux.c: Include `<grub/i18n.h>'. (GRUB_MOD_INIT): Gettextizze. * loader/sparc64/ieee1275/linux.c: Include `<grub/i18n.h>'. (grub_linux_load64): Capitalise Linux. (GRUB_MOD_INIT): Gettextizze. * loader/xnu.c: Include `<grub/i18n.h>'. (GRUB_MOD_INIT): Gettextizze. * po/POTFILES: Add `loader/efi/appleloader.c', `loader/efi/chainloader.c', `loader/i386/efi/linux.c', `loader/i386/ieee1275/linux.c', `loader/i386/linux.c', `loader/i386/pc/chainloader.c', `loader/i386/pc/linux.c', `loader/i386/xnu.c', `loader/multiboot_loader.c', `loader/powerpc/ieee1275/linux.c', `loader/sparc64/ieee1275/linux.c' and `loader/xnu.c'.
2010-01-08 21:35:38 +00:00
0, N_("Load 64-bit XNU image."));
cmd_mkext = grub_register_command ("xnu_mkext", grub_cmd_xnu_mkext, 0,
2010-01-08 Carles Pina i Estany <carles@pina.cat> * loader/efi/appleloader.c: Include `<grub/i18n.h>'. (GRUB_MOD_INIT): Gettextizze. * loader/efi/chainloader.c: Include `<grub/i18n.h>'. (GRUB_MOD_INIT): Gettextizze. * loader/i386/efi/linux.c: Include `<grub/i18n.h>'. (grub_cmd_linux): Capitalise Linux. (GRUB_MOD_INIT): Gettextizze. * loader/i386/ieee1275/linux.c: Include `<grub/i18n.h>'. (grub_cmd_linux): Capitalise Linux. (GRUB_MOD_INIT): Gettextizze. * loader/i386/linux.c: Include `<grub/i18n.h>'. (grub_cmd_linux): Capitalise Linux. (GRUB_MOD_INIT): Gettextizze. * loader/i386/pc/chainloader.c: Include `<grub/i18n.h>'. (GRUB_MOD_INIT): Gettextizze. * loader/i386/pc/linux.c: Include `<grub/i18n.h>'. (grub_cmd_linux): Capitalise Linux. (GRUB_MOD_INIT): Gettextizze. * loader/i386/xnu.c: Include `<grub/i18n.h>'. (grub_cpu_xnu_init): Gettextizze. * loader/multiboot_loader.c: Include `<grub/i18n.h>'. (GRUB_MOD_INIT): Gettextizze. * loader/powerpc/ieee1275/linux.c: Include `<grub/i18n.h>'. (GRUB_MOD_INIT): Gettextizze. * loader/sparc64/ieee1275/linux.c: Include `<grub/i18n.h>'. (grub_linux_load64): Capitalise Linux. (GRUB_MOD_INIT): Gettextizze. * loader/xnu.c: Include `<grub/i18n.h>'. (GRUB_MOD_INIT): Gettextizze. * po/POTFILES: Add `loader/efi/appleloader.c', `loader/efi/chainloader.c', `loader/i386/efi/linux.c', `loader/i386/ieee1275/linux.c', `loader/i386/linux.c', `loader/i386/pc/chainloader.c', `loader/i386/pc/linux.c', `loader/i386/xnu.c', `loader/multiboot_loader.c', `loader/powerpc/ieee1275/linux.c', `loader/sparc64/ieee1275/linux.c' and `loader/xnu.c'.
2010-01-08 21:35:38 +00:00
N_("Load XNU extension package."));
cmd_kext = grub_register_command ("xnu_kext", grub_cmd_xnu_kext, 0,
2010-01-08 Carles Pina i Estany <carles@pina.cat> * loader/efi/appleloader.c: Include `<grub/i18n.h>'. (GRUB_MOD_INIT): Gettextizze. * loader/efi/chainloader.c: Include `<grub/i18n.h>'. (GRUB_MOD_INIT): Gettextizze. * loader/i386/efi/linux.c: Include `<grub/i18n.h>'. (grub_cmd_linux): Capitalise Linux. (GRUB_MOD_INIT): Gettextizze. * loader/i386/ieee1275/linux.c: Include `<grub/i18n.h>'. (grub_cmd_linux): Capitalise Linux. (GRUB_MOD_INIT): Gettextizze. * loader/i386/linux.c: Include `<grub/i18n.h>'. (grub_cmd_linux): Capitalise Linux. (GRUB_MOD_INIT): Gettextizze. * loader/i386/pc/chainloader.c: Include `<grub/i18n.h>'. (GRUB_MOD_INIT): Gettextizze. * loader/i386/pc/linux.c: Include `<grub/i18n.h>'. (grub_cmd_linux): Capitalise Linux. (GRUB_MOD_INIT): Gettextizze. * loader/i386/xnu.c: Include `<grub/i18n.h>'. (grub_cpu_xnu_init): Gettextizze. * loader/multiboot_loader.c: Include `<grub/i18n.h>'. (GRUB_MOD_INIT): Gettextizze. * loader/powerpc/ieee1275/linux.c: Include `<grub/i18n.h>'. (GRUB_MOD_INIT): Gettextizze. * loader/sparc64/ieee1275/linux.c: Include `<grub/i18n.h>'. (grub_linux_load64): Capitalise Linux. (GRUB_MOD_INIT): Gettextizze. * loader/xnu.c: Include `<grub/i18n.h>'. (GRUB_MOD_INIT): Gettextizze. * po/POTFILES: Add `loader/efi/appleloader.c', `loader/efi/chainloader.c', `loader/i386/efi/linux.c', `loader/i386/ieee1275/linux.c', `loader/i386/linux.c', `loader/i386/pc/chainloader.c', `loader/i386/pc/linux.c', `loader/i386/xnu.c', `loader/multiboot_loader.c', `loader/powerpc/ieee1275/linux.c', `loader/sparc64/ieee1275/linux.c' and `loader/xnu.c'.
2010-01-08 21:35:38 +00:00
N_("Load XNU extension."));
2009-06-10 21:04:23 +00:00
cmd_kextdir = grub_register_command ("xnu_kextdir", grub_cmd_xnu_kextdir,
/* TRANSLATORS: OSBundleRequired is a
variable name in xnu extensions
manifests. It behaves mostly like
GNU/Linux runlevels.
*/
2010-01-08 Carles Pina i Estany <carles@pina.cat> * loader/efi/appleloader.c: Include `<grub/i18n.h>'. (GRUB_MOD_INIT): Gettextizze. * loader/efi/chainloader.c: Include `<grub/i18n.h>'. (GRUB_MOD_INIT): Gettextizze. * loader/i386/efi/linux.c: Include `<grub/i18n.h>'. (grub_cmd_linux): Capitalise Linux. (GRUB_MOD_INIT): Gettextizze. * loader/i386/ieee1275/linux.c: Include `<grub/i18n.h>'. (grub_cmd_linux): Capitalise Linux. (GRUB_MOD_INIT): Gettextizze. * loader/i386/linux.c: Include `<grub/i18n.h>'. (grub_cmd_linux): Capitalise Linux. (GRUB_MOD_INIT): Gettextizze. * loader/i386/pc/chainloader.c: Include `<grub/i18n.h>'. (GRUB_MOD_INIT): Gettextizze. * loader/i386/pc/linux.c: Include `<grub/i18n.h>'. (grub_cmd_linux): Capitalise Linux. (GRUB_MOD_INIT): Gettextizze. * loader/i386/xnu.c: Include `<grub/i18n.h>'. (grub_cpu_xnu_init): Gettextizze. * loader/multiboot_loader.c: Include `<grub/i18n.h>'. (GRUB_MOD_INIT): Gettextizze. * loader/powerpc/ieee1275/linux.c: Include `<grub/i18n.h>'. (GRUB_MOD_INIT): Gettextizze. * loader/sparc64/ieee1275/linux.c: Include `<grub/i18n.h>'. (grub_linux_load64): Capitalise Linux. (GRUB_MOD_INIT): Gettextizze. * loader/xnu.c: Include `<grub/i18n.h>'. (GRUB_MOD_INIT): Gettextizze. * po/POTFILES: Add `loader/efi/appleloader.c', `loader/efi/chainloader.c', `loader/i386/efi/linux.c', `loader/i386/ieee1275/linux.c', `loader/i386/linux.c', `loader/i386/pc/chainloader.c', `loader/i386/pc/linux.c', `loader/i386/xnu.c', `loader/multiboot_loader.c', `loader/powerpc/ieee1275/linux.c', `loader/sparc64/ieee1275/linux.c' and `loader/xnu.c'.
2010-01-08 21:35:38 +00:00
N_("DIRECTORY [OSBundleRequired]"),
/* TRANSLATORS: There are many extensions
in extension directory. */
2010-01-08 Carles Pina i Estany <carles@pina.cat> * loader/efi/appleloader.c: Include `<grub/i18n.h>'. (GRUB_MOD_INIT): Gettextizze. * loader/efi/chainloader.c: Include `<grub/i18n.h>'. (GRUB_MOD_INIT): Gettextizze. * loader/i386/efi/linux.c: Include `<grub/i18n.h>'. (grub_cmd_linux): Capitalise Linux. (GRUB_MOD_INIT): Gettextizze. * loader/i386/ieee1275/linux.c: Include `<grub/i18n.h>'. (grub_cmd_linux): Capitalise Linux. (GRUB_MOD_INIT): Gettextizze. * loader/i386/linux.c: Include `<grub/i18n.h>'. (grub_cmd_linux): Capitalise Linux. (GRUB_MOD_INIT): Gettextizze. * loader/i386/pc/chainloader.c: Include `<grub/i18n.h>'. (GRUB_MOD_INIT): Gettextizze. * loader/i386/pc/linux.c: Include `<grub/i18n.h>'. (grub_cmd_linux): Capitalise Linux. (GRUB_MOD_INIT): Gettextizze. * loader/i386/xnu.c: Include `<grub/i18n.h>'. (grub_cpu_xnu_init): Gettextizze. * loader/multiboot_loader.c: Include `<grub/i18n.h>'. (GRUB_MOD_INIT): Gettextizze. * loader/powerpc/ieee1275/linux.c: Include `<grub/i18n.h>'. (GRUB_MOD_INIT): Gettextizze. * loader/sparc64/ieee1275/linux.c: Include `<grub/i18n.h>'. (grub_linux_load64): Capitalise Linux. (GRUB_MOD_INIT): Gettextizze. * loader/xnu.c: Include `<grub/i18n.h>'. (GRUB_MOD_INIT): Gettextizze. * po/POTFILES: Add `loader/efi/appleloader.c', `loader/efi/chainloader.c', `loader/i386/efi/linux.c', `loader/i386/ieee1275/linux.c', `loader/i386/linux.c', `loader/i386/pc/chainloader.c', `loader/i386/pc/linux.c', `loader/i386/xnu.c', `loader/multiboot_loader.c', `loader/powerpc/ieee1275/linux.c', `loader/sparc64/ieee1275/linux.c' and `loader/xnu.c'.
2010-01-08 21:35:38 +00:00
N_("Load XNU extension directory."));
cmd_ramdisk = grub_register_command ("xnu_ramdisk", grub_cmd_xnu_ramdisk, 0,
/* TRANSLATORS: ramdisk here isn't identifier. It can be translated. */
N_("Load XNU ramdisk. "
"It will be available in OS as md0."));
2009-11-20 09:46:30 +00:00
cmd_splash = grub_register_extcmd ("xnu_splash",
grub_cmd_xnu_splash, 0, 0,
2010-02-03 00:24:07 +00:00
N_("Load a splash image for XNU."),
2009-11-20 09:46:30 +00:00
xnu_splash_cmd_options);
#ifndef GRUB_MACHINE_EMU
2009-06-10 21:04:23 +00:00
cmd_resume = grub_register_command ("xnu_resume", grub_cmd_xnu_resume,
0, N_("Load an image of hibernated"
" XNU."));
#endif
2009-11-09 17:43:53 +00:00
grub_cpu_xnu_init ();
my_mod = mod;
}
GRUB_MOD_FINI(xnu)
{
#ifndef GRUB_MACHINE_EMU
grub_unregister_command (cmd_resume);
#endif
grub_unregister_command (cmd_mkext);
grub_unregister_command (cmd_kext);
grub_unregister_command (cmd_kextdir);
grub_unregister_command (cmd_ramdisk);
grub_unregister_command (cmd_kernel);
2009-11-20 09:46:30 +00:00
grub_unregister_extcmd (cmd_splash);
2009-09-02 00:52:10 +00:00
grub_unregister_command (cmd_kernel64);
2009-11-09 17:43:53 +00:00
grub_cpu_xnu_fini ();
}