Linux loader for the PPC
Hi,
Here is, as promised, the linux loader for the PPC. Just like Tomas did for the PC, I made the loader accessible from both rescue mode and normal mode. There is just one bug in this code, when a kernel is loaded it is not possible to load another kernel (which should replace the previous loaded kernel). I think that problem is caused by a bug elsewhere in GRUB 2.
The biggest missing feature in this loader is initrd support. It is just 30 minutes hacking at most, but I simply don't have a kernel+initrd around to test it with. Most code is already there and it won't be hard for me to add this later.
If you can not test the patch, please proof read it for me. I started too long at this code to be sure that I did the right stuff. ;)
I really hope people will try this to boot GNU/Linux from GRUB 2 on the PPC. At the moment only module loading and HFS+ support is missing. After that just a few small features should be added to make this port complete.
If I don't hear any complaints, I will commit this patch tomorrow or so.
Thanks,
Marco
2004-07-13 Marco Gerards <[email protected]>
* boot/powerpc/ieee1275/ieee1275.c (grub_ieee1275_release): New function.
* commands/boot.c: Remove the check for `GRUB_UTIL'.
* conf/powerpc-ieee1275.rmk (grubof_SOURCES): Add loader/powerpc/ieee1275/linux.c', loader/powerpc/ieee1275/linux_normal.c' and `commands/boot.c'.
* include/grub/powerpc/ieee1275/ieee1275.h (grub_ieee1275_release): New prototype.
* include/grub/powerpc/ieee1275/loader.h: Rewritten.
* kern/powerpc/ieee1275/init.c (grub_machine_init): Initialize normal, boot, linux and linux_normal.
* loader/powerpc/ieee1275/linux.c: New file.
* loader/powerpc/ieee1275/linux_normal.c: Likewise.
boot/powerpc/ieee1275/ieee1275.c renamed from grub2/boot/powerpc/ieee1275/ieee1275.c +19 -0
@@ -420,6 +420,25 @@ grub_ieee1275_claim (void *p, grub_size_ }int +grub_ieee1275_release (void *p,grub_size_t size) +{ +struct release_args { +struct grub_ieee1275_common_hdr common; +void *p; +grub_size_t size; + } args; + +INIT_IEEE1275_COMMON (&args.common,"release" ,2 ,0 ); + args.p = p; + args.size = size; + +if (IEEE1275_CALL_ENTRY_FN (&args) ==-1 ) +return -1 ; + +return 0 ; +} + +int grub_ieee1275_set_property (grub_ieee1275_phandle_t phandle,const char *propname,void *buf,grub_size_t size,grub_size_t *actual)
commands/boot.c renamed from grub2/commands/boot.c +3 -3
@@ -37,7 +37,7 @@ grub_cmd_boot (struct grub_arg_list *sta } -#ifdef GRUB_UTIL +void grub_boot_init (void ) {
@@ -50,7 +50,7 @@ grub_boot_fini (void) {grub_unregister_command ("boot" ); } -#else /* ! GRUB_UTIL */ + GRUB_MOD_INIT { (void )mod;/* To stop warning. */
@@ -62,4 +62,4 @@ GRUB_MOD_FINI {grub_unregister_command ("boot" ); } -#endif /* ! GRUB_UTIL */ +
conf/powerpc-ieee1275.rmk renamed from grub2/conf/powerpc-ieee1275.rmk +1 -1
@@ -41,7 +41,7 @@ grubof_SOURCES = boot/powerpc/ieee1275/c kern/powerpc/ieee1275/openfw.c fs/ext2.c fs/ufs.c fs/minix.c normal/cmdline.c \ normal/command.c normal/main.c normal/menu.c \ disk/powerpc/ieee1275/ofdisk.c disk/powerpc/ieee1275/partition.c \ - kern/env.c normal/arg.c + kern/env.c normal/arg.c loader/powerpc/ieee1275/linux.c loader/powerpc/ieee1275/linux_normal.c commands/boot.c grubof_HEADERS = grub/powerpc/ieee1275/ieee1275.h grubof_CFLAGS = $(COMMON_CFLAGS) grubof_ASFLAGS = $(COMMON_ASFLAGS)
include/grub/powerpc/ieee1275/ieee1275.h renamed from grub2/include/grub/powerpc/ieee1275/ieee1275.h +1 -0
@@ -84,6 +84,7 @@ int EXPORT_FUNC(grub_ieee1275_open) (chaint EXPORT_FUNC (grub_ieee1275_close ) (grub_ieee1275_ihandle_t ihandle);int EXPORT_FUNC (grub_ieee1275_claim ) (void *p,grub_size_t size,unsigned int align,void **result); +int EXPORT_FUNC (grub_ieee1275_release ) (void *p,grub_size_t size); int EXPORT_FUNC(grub_ieee1275_set_property) (grub_ieee1275_phandle_t phandle, const char *propname, void *buf, grub_size_t size,
include/grub/powerpc/ieee1275/loader.h renamed from grub2/include/grub/powerpc/ieee1275/loader.h +9 -28
@@ -1,7 +1,6 @@/* * GRUB -- GRand Unified Bootloader -* Copyright (C) 2002 Yoshinori K. Okuji <[email protected]> -* Copyright (C) 2003 Jeroen Dekkers <[email protected]> +* Copyright (C) 2004 Free Software Foundation, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by
@@ -21,31 +20,13 @@#ifndef GRUB_LOADER_MACHINE_HEADER #define GRUB_LOADER_MACHINE_HEADER 1 -#include <grub/types.h> -#include <grub/symbol.h> -#include <grub/machine/multiboot.h> - -extern grub_uint32_t EXPORT_VAR (grub_linux_prot_size ); -extern char *EXPORT_VAR (grub_linux_tmp_addr ); -extern char *EXPORT_VAR (grub_linux_real_addr ); - -void EXPORT_FUNC (grub_linux_boot_zimage ) (void ) __attribute__ ((noreturn)); -void EXPORT_FUNC (grub_linux_boot_bzimage ) (void ) __attribute__ ((noreturn)); - -/* This is an asm part of the chainloader. */ -void EXPORT_FUNC (grub_chainloader_real_boot ) (int drive,void *part_addr) __attribute__ ((noreturn)); - -/* The asm part of the multiboot loader. */ -void EXPORT_FUNC (grub_multiboot_real_boot ) (grub_addr_t entry, -struct grub_multiboot_info *mbi) - __attribute__ ((noreturn)); - -/* It is necessary to export these functions, because normal mode commands -reuse rescue mode commands. */ -void grub_rescue_cmd_chainloader (int argc,char *argv[]); -void grub_rescue_cmd_linux (int argc,char *argv[]); -void grub_rescue_cmd_initrd (int argc,char *argv[]); -void grub_rescue_cmd_multiboot (int argc,char *argv[]); -void grub_rescue_cmd_module (int argc,char *argv[]); +/* The symbol shared between the normal mode and rescue mode +loader. */ +void grub_load_linux (int argc,char *argv[]); + +void grub_linux_init (void ); +void grub_linux_fini (void ); +void grub_linux_normal_init (void ); +void grub_linux_normal_fini (void );#endif /* ! GRUB_LOADER_MACHINE_HEADER */
kern/powerpc/ieee1275/init.c renamed from grub2/kern/powerpc/ieee1275/init.c +4 -0
@@ -58,6 +58,10 @@ grub_machine_init (void)grub_env_set ("prefix" ,"" );grub_ext2_init (); +grub_normal_init (); +grub_boot_init (); +grub_linux_init (); +grub_linux_normal_init ();grub_ofdisk_init ();grub_console_init (); }
loader/powerpc/ieee1275/linux.c renamed from grub2/loader/powerpc/ieee1275/linux.c +289 -0
289 lines not on this page · raw message
loader/powerpc/ieee1275/linux_normal.c renamed from grub2/loader/powerpc/ieee1275/linux_normal.c +63 -0
63 lines not on this page · raw message
At Tue, 13 Jul 2004 19:01:22 +0200,
loader/powerpc/ieee1275/linux.c line 271
Quoted 12 lines · Marco Gerards
loader/powerpc/ieee1275/linux.c renamed from grub2/loader/powerpc/ieee1275/linux.c +12
-0+static void +grub_rescue_cmd_linux (int argc,char *argv[]) +{ +grub_load_linux (argc, argv); +} + +GRUB_MOD_INIT +{ +grub_rescue_register_command ("linux" , grub_rescue_cmd_linux, +"load a linux kernel" ); + my_mod = mod; +}
Why don't you just use grub_load_linux as argument to grub_rescue_register_command()?
Jeroen Dekkers
Quoted 17 lines · Jeroen Dekkers
At Tue, 13 Jul 2004 19:01:22 +0200,
loader/powerpc/ieee1275/linux.c line 271
Quoted 12 lines · Marco Gerards
loader/powerpc/ieee1275/linux.c renamed from grub2/loader/powerpc/ieee1275/linux.c +12
-0+static void +grub_rescue_cmd_linux (int argc,char *argv[]) +{ +grub_load_linux (argc, argv); +} + +GRUB_MOD_INIT +{ +grub_rescue_register_command ("linux" , grub_rescue_cmd_linux, +"load a linux kernel" ); + my_mod = mod; +}Why don't you just use
grub_load_linuxas argument togrub_rescue_register_command()?
Because that will make it harder to change the interface of grub_load_linux afterwards.
--
Marco
At Tue, 13 Jul 2004 21:03:09 +0200,
Quoted 21 lines · Marco Gerards
Quoted 17 lines · Jeroen Dekkers
At Tue, 13 Jul 2004 19:01:22 +0200,
loader/powerpc/ieee1275/linux.c line 271
Quoted 12 lines · Marco Gerards
loader/powerpc/ieee1275/linux.c renamed from grub2/loader/powerpc/ieee1275/linux.c +12
-0+static void +grub_rescue_cmd_linux (int argc,char *argv[]) +{ +grub_load_linux (argc, argv); +} + +GRUB_MOD_INIT +{ +grub_rescue_register_command ("linux" , grub_rescue_cmd_linux, +"load a linux kernel" ); + my_mod = mod; +}Why don't you just use
grub_load_linuxas argument togrub_rescue_register_command()?
Quoted 2 lines
Because that will make it harder to change the interface of
grub_load_linuxafterwards.
Why? It's in the same file as the register command. If it gets a different interface, you can update the register call with it to point to some new function that wraps is.
Jeroen Dekkers
Quoted 9 lines · Jeroen Dekkers
Quoted 5 lines
Quoted 2 lines
Why don't you just use
grub_load_linuxas argument togrub_rescue_register_command()?Because that will make it harder to change the interface of
grub_load_linuxafterwards.Why? It's in the same file as the register command. If it gets a different interface, you can update the register call with it to point to some new function that wraps is.
Well, ok. I have no strong opinion about it. I can change this before committing the patch.
Anything else? :)
--
Marco
Quoted 6 lines · Marco Gerards
Here is, as promised, the linux loader for the PPC. Just like Tomas did for the PC, I made the loader accessible from both rescue mode and normal mode. There is just one bug in this code, when a kernel is loaded it is not possible to load another kernel (which should replace the previous loaded kernel). I think that problem is caused by a bug elsewhere in GRUB 2.
I just committed this (Better late then never ;)).
I did not commit hfs support yet because I want to finish hfs+ support first. Unless someone has a good reason for me to commit it now. This can take quite a while before I will finish it.
So now GRUB 2 can be used to boot GNU/Linux on the open firmware PPCs.
If I am not mistaken, Maurizio is working on module loaded for this port (what is the status, btw?). Hopefully soon I will find the time to finish the interface so it becomes easy to use GRUB 2. The last important missing feature is a loader for macos. And we will need multiboot support, of course.
I really hope anyone reading this with a PPC will test this code and tell me which features are missing. If there is any mac/ppc specific feature that is not implemented or mentioned that will most likely mean it will not be implemented. So don't be shy and tell me what you need.
And to make it ready for production usage someday, GRUB 2 on the PPC needs to be tested. You can do that by following these steps (a=disk, b=network):
1) Make a CVS checkout of GRUB 2.
2) ./configure && make
3a) Copy grubof to your HFS[+] boot partition. This is the same
partition yaboot uses.
3b) Copy grubof to your tftp directory. Setup bootp to load this
kernel.
4a) Boot your mac into the open firmware console and boot the grubof
ELF.
4b) Boot from network.
5) GRUB is started. You can load and boot GNU/Linux using (for example):
linux (hd,10)/vmlinux root=/dev/hda11
boot
6) Or instead of booting just play a bit. Try to access files and find bugs. :)
Please send me a report if this does or doesn't work for you. What went wrong, etc. It would be useful for me to hear what kind of machine you were using.
Thanks,
Marco