diff -urN grub2.org/conf/powerpc-ieee1275.rmk grub2/conf/powerpc-ieee1275.rmk --- grub2.org/conf/powerpc-ieee1275.rmk 2007-10-03 10:45:57.000000000 +0200 +++ grub2/conf/powerpc-ieee1275.rmk 2007-10-03 16:41:03.000000000 +0200 @@ -101,6 +101,8 @@ # Modules. pkgdata_MODULES = halt.mod \ + _ofboot.mod \ + ofboot.mod \ _linux.mod \ linux.mod \ normal.mod \ @@ -109,6 +111,16 @@ _multiboot.mod \ multiboot.mod +# For _ofboot.mod. +_ofboot_mod_SOURCES = loader/powerpc/ieee1275/ofboot.c +_ofboot_mod_CFLAGS = $(COMMON_CFLAGS) +_ofboot_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For ofboot.mod. +ofboot_mod_SOURCES = loader/powerpc/ieee1275/ofboot_normal.c +ofboot_mod_CFLAGS = $(COMMON_CFLAGS) +ofboot_mod_LDFLAGS = $(COMMON_LDFLAGS) + # For _linux.mod. _linux_mod_SOURCES = loader/powerpc/ieee1275/linux.c _linux_mod_CFLAGS = $(COMMON_CFLAGS) diff -urN grub2.org/include/grub/powerpc/ieee1275/loader.h grub2/include/grub/powerpc/ieee1275/loader.h --- grub2.org/include/grub/powerpc/ieee1275/loader.h 2007-07-22 01:32:24.000000000 +0200 +++ grub2/include/grub/powerpc/ieee1275/loader.h 2007-10-03 16:07:43.000000000 +0200 @@ -23,10 +23,16 @@ loader. */ void grub_rescue_cmd_linux (int argc, char *argv[]); void grub_rescue_cmd_initrd (int argc, char *argv[]); +void grub_rescue_cmd_ofboot (int argc, char *argv[]); +void grub_rescue_cmd_ofrun (int argc, char *argv[]); void grub_linux_init (void); void grub_linux_fini (void); +void grub_ofboot_init (void); +void grub_ofboot_fini (void); void grub_linux_normal_init (void); void grub_linux_normal_fini (void); +void grub_ofboot_normal_init (void); +void grub_ofboot_normal_fini (void); #endif /* ! GRUB_LOADER_MACHINE_HEADER */ diff -urN grub2.org/loader/powerpc/ieee1275/ofboot.c grub2/loader/powerpc/ieee1275/ofboot.c --- grub2.org/loader/powerpc/ieee1275/ofboot.c 1970-01-01 01:00:00.000000000 +0100 +++ grub2/loader/powerpc/ieee1275/ofboot.c 2007-10-03 16:09:51.000000000 +0200 @@ -0,0 +1,140 @@ +/* ofboot.c - OF boot */ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2003, 2004, 2005, 2007 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 . + */ + +#include +#include +#include +#include +#include +#include +#include + +static grub_dl_t my_mod; + +static grub_err_t +grub_ofboot_boot (void) +{ + grub_err_t err; + + err = grub_ieee1275_interpret("go", 0); + + return err; +} + +static grub_err_t +grub_ofboot_unload (void) +{ + grub_dl_unref (my_mod); + return GRUB_ERR_NONE; +} + +static grub_err_t +grub_ofboot_prepare (int argc, char *argv[]) +{ + int i; + int size; + char *dest; + char *ofboot_args = 0; + + grub_err_t err; + grub_ieee1275_cell_t res; + + if (argc == 0) + { + grub_error (GRUB_ERR_BAD_ARGUMENT, "no file specified"); + goto out; + } + + size = sizeof("load") + 1; + for (i = 0; i < argc; i++) + size += grub_strlen (argv[i]) + 1; + + ofboot_args = grub_malloc (size); + if (! ofboot_args) + goto out; + + dest = grub_stpcpy (ofboot_args, "load"); + for (i = 0; i < argc; i++) + { + *dest++ = ' '; + dest = grub_stpcpy (dest, argv[i]); + } + + err = grub_ieee1275_interpret(ofboot_args, &res); + if (err || res) + { + grub_error (GRUB_ERR_UNKNOWN_OS, "Failed to \"load\""); + goto out; + } + + err = grub_ieee1275_interpret("init-program", &res); + if (err || res) + { + grub_error (GRUB_ERR_UNKNOWN_OS, "Failed to \"init-program\""); + goto out; + } + +out: + if(ofboot_args) + grub_free (ofboot_args); + + return grub_errno; +} + +void +grub_rescue_cmd_ofrun (int argc, char *argv[]) +{ + grub_ofboot_prepare (argc, argv); + + if (grub_errno == GRUB_ERR_NONE) + grub_ofboot_boot (); +} + +void +grub_rescue_cmd_ofboot (int argc, char *argv[]) +{ + grub_dl_ref (my_mod); + + /* Release the previously used memory. */ + grub_loader_unset (); + + grub_ofboot_prepare (argc, argv); + + if (grub_errno == GRUB_ERR_NONE) + grub_loader_set (grub_ofboot_boot, grub_ofboot_unload, 1); + else + grub_ofboot_unload (); +} + + + +GRUB_MOD_INIT(ofboot) +{ + grub_rescue_register_command ("ofboot", grub_rescue_cmd_ofboot, + "load using OF interface"); + grub_rescue_register_command ("ofrun", grub_rescue_cmd_ofrun, + "load&run using OF interface"); + my_mod = mod; +} + +GRUB_MOD_FINI(ofboot) +{ + grub_rescue_unregister_command ("ofrun"); + grub_rescue_unregister_command ("ofboot"); +} diff -urN grub2.org/loader/powerpc/ieee1275/ofboot_normal.c grub2/loader/powerpc/ieee1275/ofboot_normal.c --- grub2.org/loader/powerpc/ieee1275/ofboot_normal.c 1970-01-01 01:00:00.000000000 +0100 +++ grub2/loader/powerpc/ieee1275/ofboot_normal.c 2007-10-03 16:08:59.000000000 +0200 @@ -0,0 +1,60 @@ +/* ofboot_normal.c - OF boot */ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2004,2007 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 . + */ + +#include +#include +#include + +static const struct grub_arg_option options[] = + { + {0, 0, 0, 0, 0, 0} + }; + +static grub_err_t +grub_cmd_ofboot (struct grub_arg_list *state __attribute__ ((unused)), + int argc, char **args) +{ + grub_rescue_cmd_ofboot (argc, args); + return GRUB_ERR_NONE; +} + +static grub_err_t +grub_cmd_ofrun (struct grub_arg_list *state __attribute__ ((unused)), + int argc, char **args) +{ + grub_rescue_cmd_ofrun (argc, args); + return GRUB_ERR_NONE; +} + +GRUB_MOD_INIT(ofboot_normal) +{ + (void) mod; + grub_register_command ("ofboot", grub_cmd_ofboot, GRUB_COMMAND_FLAG_BOTH, + "ofboot [ARGS...]", + "Loads using OF interface", options); + grub_register_command ("ofrun", grub_cmd_ofrun, GRUB_COMMAND_FLAG_BOTH, + "ofrun [ARGS...]", + "Loads&Run using OF interface", options); +} + +GRUB_MOD_FINI(ofboot_normal) +{ + grub_unregister_command ("ofrun"); + grub_unregister_command ("ofboot"); +}