Hell[o]

Some time ago I decide to give a try to GRUB on my Pegasos 2 machine
(G4 1GHz, 1G of ram) and generaly it works with some problems.

1) Booting recent CVS snap on OF version dated 2005.12.16 gives me
only "Welcome to GRUB" and "Out of memory" message. After OF update to
half official 2006.10.23 it works, but as this version is not fully
official most of the
pegasos machines still uses old one.

I checked and GRUB 1.94 works fine on older OF (2005.12.16) and 1.95
gives instant reboot.

2) Backspace key seems to not working in GRUB console (I use cursor
key and del for now) but works fine in OF console.

Put some debug in ofconsole.c shows that getkey() gives 127 for backspace.

3) After "Welcome to GRUB" message I have a ~1-2s pause and error "ATA
device not present or not responding" Currently I have one HD (primary
master) and DVD (secondary master) attached.

No error when booting using 1.94.

4) Most of the Pegasos machines uses small affs partition for MorphOS boot
images, but it seems affs is broken for ieee1275 as affs  uses
total_sectors field from grub_disk_t, but looking at ofdisk.c:

 /* XXX: There is no property to read the number of blocks.  There
    should be a property `#blocks', but it is not there.  Perhaps it
    is possible to use seek for this.  */
 disk->total_sectors = 0xFFFFFFFFUL;

I changed affs to use grub_partition_get_len(). No ideas how correct is
it, but it seems to work here.

4) Grub2 can not load morphos boot images then I added ofboot command
to allow boot using OF interface (load, init-program, go).

Attached both patches, I am not completly sure how correct are both of
them as this was my first look inside grub2 sources. Anyway now I can
boot MorphOS and use affs partitions, but three problems are still
there.

Can anyone help with this ?

-- 
--- Marcin 'Morgoth' Kurek ---
diff -urN grub2.org/conf/powerpc-ieee1275.mk grub2/conf/powerpc-ieee1275.mk
--- grub2.org/conf/powerpc-ieee1275.mk	2007-08-29 19:49:46.000000000 +0200
+++ grub2/conf/powerpc-ieee1275.mk	2007-09-15 02:40:33.144459267 +0200
@@ -235,14 +235,14 @@
 	normal/menu_entry.c normal/misc.c normal/script.c		\
 	partmap/amiga.c	partmap/apple.c partmap/pc.c partmap/sun.c	\
 	partmap/acorn.c							\
-	util/console.c util/grub-emu.c util/misc.c			\
+	util/console.c util/hostfs.c util/grub-emu.c util/misc.c			\
 	util/biosdisk.c util/getroot.c			\
 	util/powerpc/ieee1275/misc.c grub_script.tab.c grub_emu_init.c
-CLEANFILES += grub-emu grub_emu-commands_boot.o grub_emu-commands_cat.o grub_emu-commands_cmp.o grub_emu-commands_configfile.o grub_emu-commands_help.o grub_emu-commands_search.o grub_emu-commands_terminal.o grub_emu-commands_test.o grub_emu-commands_ls.o grub_emu-commands_blocklist.o grub_emu-commands_ieee1275_halt.o grub_emu-commands_ieee1275_reboot.o grub_emu-disk_loopback.o grub_emu-fs_affs.o grub_emu-fs_ext2.o grub_emu-fs_fat.o grub_emu-fs_fshelp.o grub_emu-fs_hfs.o grub_emu-fs_iso9660.o grub_emu-fs_jfs.o grub_emu-fs_minix.o grub_emu-fs_sfs.o grub_emu-fs_ufs.o grub_emu-fs_xfs.o grub_emu-fs_hfsplus.o grub_emu-fs_ntfs.o grub_emu-io_gzio.o grub_emu-kern_device.o grub_emu-kern_disk.o grub_emu-kern_dl.o grub_emu-kern_elf.o grub_emu-kern_env.o grub_emu-kern_err.o grub_emu-kern_file.o grub_emu-kern_fs.o grub_emu-kern_loader.o grub_emu-kern_main.o grub_emu-kern_misc.o grub_emu-kern_parser.o grub_emu-kern_partition.o grub_emu-kern_rescue.o grub_emu-kern_term.o grub_emu-normal_arg.o grub_emu-normal_cmdline.o grub_emu-normal_command.o grub_emu-normal_completion.o grub_emu-normal_execute.o grub_emu-normal_function.o grub_emu-normal_lexer.o grub_emu-normal_main.o grub_emu-normal_menu.o grub_emu-normal_menu_entry.o grub_emu-normal_misc.o grub_emu-normal_script.o grub_emu-partmap_amiga.o grub_emu-partmap_apple.o grub_emu-partmap_pc.o grub_emu-partmap_sun.o grub_emu-partmap_acorn.o grub_emu-util_console.o grub_emu-util_grub_emu.o grub_emu-util_misc.o grub_emu-util_biosdisk.o grub_emu-util_getroot.o grub_emu-util_powerpc_ieee1275_misc.o grub_emu-grub_script_tab.o grub_emu-grub_emu_init.o
-MOSTLYCLEANFILES += grub_emu-commands_boot.d grub_emu-commands_cat.d grub_emu-commands_cmp.d grub_emu-commands_configfile.d grub_emu-commands_help.d grub_emu-commands_search.d grub_emu-commands_terminal.d grub_emu-commands_test.d grub_emu-commands_ls.d grub_emu-commands_blocklist.d grub_emu-commands_ieee1275_halt.d grub_emu-commands_ieee1275_reboot.d grub_emu-disk_loopback.d grub_emu-fs_affs.d grub_emu-fs_ext2.d grub_emu-fs_fat.d grub_emu-fs_fshelp.d grub_emu-fs_hfs.d grub_emu-fs_iso9660.d grub_emu-fs_jfs.d grub_emu-fs_minix.d grub_emu-fs_sfs.d grub_emu-fs_ufs.d grub_emu-fs_xfs.d grub_emu-fs_hfsplus.d grub_emu-fs_ntfs.d grub_emu-io_gzio.d grub_emu-kern_device.d grub_emu-kern_disk.d grub_emu-kern_dl.d grub_emu-kern_elf.d grub_emu-kern_env.d grub_emu-kern_err.d grub_emu-kern_file.d grub_emu-kern_fs.d grub_emu-kern_loader.d grub_emu-kern_main.d grub_emu-kern_misc.d grub_emu-kern_parser.d grub_emu-kern_partition.d grub_emu-kern_rescue.d grub_emu-kern_term.d grub_emu-normal_arg.d grub_emu-normal_cmdline.d grub_emu-normal_command.d grub_emu-normal_completion.d grub_emu-normal_execute.d grub_emu-normal_function.d grub_emu-normal_lexer.d grub_emu-normal_main.d grub_emu-normal_menu.d grub_emu-normal_menu_entry.d grub_emu-normal_misc.d grub_emu-normal_script.d grub_emu-partmap_amiga.d grub_emu-partmap_apple.d grub_emu-partmap_pc.d grub_emu-partmap_sun.d grub_emu-partmap_acorn.d grub_emu-util_console.d grub_emu-util_grub_emu.d grub_emu-util_misc.d grub_emu-util_biosdisk.d grub_emu-util_getroot.d grub_emu-util_powerpc_ieee1275_misc.d grub_emu-grub_script_tab.d grub_emu-grub_emu_init.d
+CLEANFILES += grub-emu grub_emu-commands_boot.o grub_emu-commands_cat.o grub_emu-commands_cmp.o grub_emu-commands_configfile.o grub_emu-commands_help.o grub_emu-commands_search.o grub_emu-commands_terminal.o grub_emu-commands_test.o grub_emu-commands_ls.o grub_emu-commands_blocklist.o grub_emu-commands_ieee1275_halt.o grub_emu-commands_ieee1275_reboot.o grub_emu-disk_loopback.o grub_emu-fs_affs.o grub_emu-fs_ext2.o grub_emu-fs_fat.o grub_emu-fs_fshelp.o grub_emu-fs_hfs.o grub_emu-fs_iso9660.o grub_emu-fs_jfs.o grub_emu-fs_minix.o grub_emu-fs_sfs.o grub_emu-fs_ufs.o grub_emu-fs_xfs.o grub_emu-fs_hfsplus.o grub_emu-fs_ntfs.o grub_emu-io_gzio.o grub_emu-kern_device.o grub_emu-kern_disk.o grub_emu-kern_dl.o grub_emu-kern_elf.o grub_emu-kern_env.o grub_emu-kern_err.o grub_emu-kern_file.o grub_emu-kern_fs.o grub_emu-kern_loader.o grub_emu-kern_main.o grub_emu-kern_misc.o grub_emu-kern_parser.o grub_emu-kern_partition.o grub_emu-kern_rescue.o grub_emu-kern_term.o grub_emu-normal_arg.o grub_emu-normal_cmdline.o grub_emu-normal_command.o grub_emu-normal_completion.o grub_emu-normal_execute.o grub_emu-normal_function.o grub_emu-normal_lexer.o grub_emu-normal_main.o grub_emu-normal_menu.o grub_emu-normal_menu_entry.o grub_emu-normal_misc.o grub_emu-normal_script.o grub_emu-partmap_amiga.o grub_emu-partmap_apple.o grub_emu-partmap_pc.o grub_emu-partmap_sun.o grub_emu-partmap_acorn.o grub_emu-util_console.o grub_emu-util_hostfs.o grub_emu-util_grub_emu.o grub_emu-util_misc.o grub_emu-util_biosdisk.o grub_emu-util_getroot.o grub_emu-util_powerpc_ieee1275_misc.o grub_emu-grub_script_tab.o grub_emu-grub_emu_init.o
+MOSTLYCLEANFILES += grub_emu-commands_boot.d grub_emu-commands_cat.d grub_emu-commands_cmp.d grub_emu-commands_configfile.d grub_emu-commands_help.d grub_emu-commands_search.d grub_emu-commands_terminal.d grub_emu-commands_test.d grub_emu-commands_ls.d grub_emu-commands_blocklist.d grub_emu-commands_ieee1275_halt.d grub_emu-commands_ieee1275_reboot.d grub_emu-disk_loopback.d grub_emu-fs_affs.d grub_emu-fs_ext2.d grub_emu-fs_fat.d grub_emu-fs_fshelp.d grub_emu-fs_hfs.d grub_emu-fs_iso9660.d grub_emu-fs_jfs.d grub_emu-fs_minix.d grub_emu-fs_sfs.d grub_emu-fs_ufs.d grub_emu-fs_xfs.d grub_emu-fs_hfsplus.d grub_emu-fs_ntfs.d grub_emu-io_gzio.d grub_emu-kern_device.d grub_emu-kern_disk.d grub_emu-kern_dl.d grub_emu-kern_elf.d grub_emu-kern_env.d grub_emu-kern_err.d grub_emu-kern_file.d grub_emu-kern_fs.d grub_emu-kern_loader.d grub_emu-kern_main.d grub_emu-kern_misc.d grub_emu-kern_parser.d grub_emu-kern_partition.d grub_emu-kern_rescue.d grub_emu-kern_term.d grub_emu-normal_arg.d grub_emu-normal_cmdline.d grub_emu-normal_command.d grub_emu-normal_completion.d grub_emu-normal_execute.d grub_emu-normal_function.d grub_emu-normal_lexer.d grub_emu-normal_main.d grub_emu-normal_menu.d grub_emu-normal_menu_entry.d grub_emu-normal_misc.d grub_emu-normal_script.d grub_emu-partmap_amiga.d grub_emu-partmap_apple.d grub_emu-partmap_pc.d grub_emu-partmap_sun.d grub_emu-partmap_acorn.d grub_emu-util_console.d grub_emu-util_hostfs.d grub_emu-util_grub_emu.d grub_emu-util_misc.d grub_emu-util_biosdisk.d grub_emu-util_getroot.d grub_emu-util_powerpc_ieee1275_misc.d grub_emu-grub_script_tab.d grub_emu-grub_emu_init.d
 
-grub-emu: $(grub_emu_DEPENDENCIES) grub_emu-commands_boot.o grub_emu-commands_cat.o grub_emu-commands_cmp.o grub_emu-commands_configfile.o grub_emu-commands_help.o grub_emu-commands_search.o grub_emu-commands_terminal.o grub_emu-commands_test.o grub_emu-commands_ls.o grub_emu-commands_blocklist.o grub_emu-commands_ieee1275_halt.o grub_emu-commands_ieee1275_reboot.o grub_emu-disk_loopback.o grub_emu-fs_affs.o grub_emu-fs_ext2.o grub_emu-fs_fat.o grub_emu-fs_fshelp.o grub_emu-fs_hfs.o grub_emu-fs_iso9660.o grub_emu-fs_jfs.o grub_emu-fs_minix.o grub_emu-fs_sfs.o grub_emu-fs_ufs.o grub_emu-fs_xfs.o grub_emu-fs_hfsplus.o grub_emu-fs_ntfs.o grub_emu-io_gzio.o grub_emu-kern_device.o grub_emu-kern_disk.o grub_emu-kern_dl.o grub_emu-kern_elf.o grub_emu-kern_env.o grub_emu-kern_err.o grub_emu-kern_file.o grub_emu-kern_fs.o grub_emu-kern_loader.o grub_emu-kern_main.o grub_emu-kern_misc.o grub_emu-kern_parser.o grub_emu-kern_partition.o grub_emu-kern_rescue.o grub_emu-kern_term.o grub_emu-normal_arg.o grub_emu-normal_cmdline.o grub_emu-normal_command.o grub_emu-normal_completion.o grub_emu-normal_execute.o grub_emu-normal_function.o grub_emu-normal_lexer.o grub_emu-normal_main.o grub_emu-normal_menu.o grub_emu-normal_menu_entry.o grub_emu-normal_misc.o grub_emu-normal_script.o grub_emu-partmap_amiga.o grub_emu-partmap_apple.o grub_emu-partmap_pc.o grub_emu-partmap_sun.o grub_emu-partmap_acorn.o grub_emu-util_console.o grub_emu-util_grub_emu.o grub_emu-util_misc.o grub_emu-util_biosdisk.o grub_emu-util_getroot.o grub_emu-util_powerpc_ieee1275_misc.o grub_emu-grub_script_tab.o grub_emu-grub_emu_init.o
-	$(CC) -o $@ grub_emu-commands_boot.o grub_emu-commands_cat.o grub_emu-commands_cmp.o grub_emu-commands_configfile.o grub_emu-commands_help.o grub_emu-commands_search.o grub_emu-commands_terminal.o grub_emu-commands_test.o grub_emu-commands_ls.o grub_emu-commands_blocklist.o grub_emu-commands_ieee1275_halt.o grub_emu-commands_ieee1275_reboot.o grub_emu-disk_loopback.o grub_emu-fs_affs.o grub_emu-fs_ext2.o grub_emu-fs_fat.o grub_emu-fs_fshelp.o grub_emu-fs_hfs.o grub_emu-fs_iso9660.o grub_emu-fs_jfs.o grub_emu-fs_minix.o grub_emu-fs_sfs.o grub_emu-fs_ufs.o grub_emu-fs_xfs.o grub_emu-fs_hfsplus.o grub_emu-fs_ntfs.o grub_emu-io_gzio.o grub_emu-kern_device.o grub_emu-kern_disk.o grub_emu-kern_dl.o grub_emu-kern_elf.o grub_emu-kern_env.o grub_emu-kern_err.o grub_emu-kern_file.o grub_emu-kern_fs.o grub_emu-kern_loader.o grub_emu-kern_main.o grub_emu-kern_misc.o grub_emu-kern_parser.o grub_emu-kern_partition.o grub_emu-kern_rescue.o grub_emu-kern_term.o grub_emu-normal_arg.o grub_emu-normal_cmdline.o grub_emu-normal_command.o grub_emu-normal_completion.o grub_emu-normal_execute.o grub_emu-normal_function.o grub_emu-normal_lexer.o grub_emu-normal_main.o grub_emu-normal_menu.o grub_emu-normal_menu_entry.o grub_emu-normal_misc.o grub_emu-normal_script.o grub_emu-partmap_amiga.o grub_emu-partmap_apple.o grub_emu-partmap_pc.o grub_emu-partmap_sun.o grub_emu-partmap_acorn.o grub_emu-util_console.o grub_emu-util_grub_emu.o grub_emu-util_misc.o grub_emu-util_biosdisk.o grub_emu-util_getroot.o grub_emu-util_powerpc_ieee1275_misc.o grub_emu-grub_script_tab.o grub_emu-grub_emu_init.o $(LDFLAGS) $(grub_emu_LDFLAGS)
+grub-emu: $(grub_emu_DEPENDENCIES) grub_emu-commands_boot.o grub_emu-commands_cat.o grub_emu-commands_cmp.o grub_emu-commands_configfile.o grub_emu-commands_help.o grub_emu-commands_search.o grub_emu-commands_terminal.o grub_emu-commands_test.o grub_emu-commands_ls.o grub_emu-commands_blocklist.o grub_emu-commands_ieee1275_halt.o grub_emu-commands_ieee1275_reboot.o grub_emu-disk_loopback.o grub_emu-fs_affs.o grub_emu-fs_ext2.o grub_emu-fs_fat.o grub_emu-fs_fshelp.o grub_emu-fs_hfs.o grub_emu-fs_iso9660.o grub_emu-fs_jfs.o grub_emu-fs_minix.o grub_emu-fs_sfs.o grub_emu-fs_ufs.o grub_emu-fs_xfs.o grub_emu-fs_hfsplus.o grub_emu-fs_ntfs.o grub_emu-io_gzio.o grub_emu-kern_device.o grub_emu-kern_disk.o grub_emu-kern_dl.o grub_emu-kern_elf.o grub_emu-kern_env.o grub_emu-kern_err.o grub_emu-kern_file.o grub_emu-kern_fs.o grub_emu-kern_loader.o grub_emu-kern_main.o grub_emu-kern_misc.o grub_emu-kern_parser.o grub_emu-kern_partition.o grub_emu-kern_rescue.o grub_emu-kern_term.o grub_emu-normal_arg.o grub_emu-normal_cmdline.o grub_emu-normal_command.o grub_emu-normal_completion.o grub_emu-normal_execute.o grub_emu-normal_function.o grub_emu-normal_lexer.o grub_emu-normal_main.o grub_emu-normal_menu.o grub_emu-normal_menu_entry.o grub_emu-normal_misc.o grub_emu-normal_script.o grub_emu-partmap_amiga.o grub_emu-partmap_apple.o grub_emu-partmap_pc.o grub_emu-partmap_sun.o grub_emu-partmap_acorn.o grub_emu-util_console.o grub_emu-util_hostfs.o grub_emu-util_grub_emu.o grub_emu-util_misc.o grub_emu-util_biosdisk.o grub_emu-util_getroot.o grub_emu-util_powerpc_ieee1275_misc.o grub_emu-grub_script_tab.o grub_emu-grub_emu_init.o
+	$(CC) -o $@ grub_emu-commands_boot.o grub_emu-commands_cat.o grub_emu-commands_cmp.o grub_emu-commands_configfile.o grub_emu-commands_help.o grub_emu-commands_search.o grub_emu-commands_terminal.o grub_emu-commands_test.o grub_emu-commands_ls.o grub_emu-commands_blocklist.o grub_emu-commands_ieee1275_halt.o grub_emu-commands_ieee1275_reboot.o grub_emu-disk_loopback.o grub_emu-fs_affs.o grub_emu-fs_ext2.o grub_emu-fs_fat.o grub_emu-fs_fshelp.o grub_emu-fs_hfs.o grub_emu-fs_iso9660.o grub_emu-fs_jfs.o grub_emu-fs_minix.o grub_emu-fs_sfs.o grub_emu-fs_ufs.o grub_emu-fs_xfs.o grub_emu-fs_hfsplus.o grub_emu-fs_ntfs.o grub_emu-io_gzio.o grub_emu-kern_device.o grub_emu-kern_disk.o grub_emu-kern_dl.o grub_emu-kern_elf.o grub_emu-kern_env.o grub_emu-kern_err.o grub_emu-kern_file.o grub_emu-kern_fs.o grub_emu-kern_loader.o grub_emu-kern_main.o grub_emu-kern_misc.o grub_emu-kern_parser.o grub_emu-kern_partition.o grub_emu-kern_rescue.o grub_emu-kern_term.o grub_emu-normal_arg.o grub_emu-normal_cmdline.o grub_emu-normal_command.o grub_emu-normal_completion.o grub_emu-normal_execute.o grub_emu-normal_function.o grub_emu-normal_lexer.o grub_emu-normal_main.o grub_emu-normal_menu.o grub_emu-normal_menu_entry.o grub_emu-normal_misc.o grub_emu-normal_script.o grub_emu-partmap_amiga.o grub_emu-partmap_apple.o grub_emu-partmap_pc.o grub_emu-partmap_sun.o grub_emu-partmap_acorn.o grub_emu-util_console.o grub_emu-util_hostfs.o grub_emu-util_grub_emu.o grub_emu-util_misc.o grub_emu-util_biosdisk.o grub_emu-util_getroot.o grub_emu-util_powerpc_ieee1275_misc.o grub_emu-grub_script_tab.o grub_emu-grub_emu_init.o $(LDFLAGS) $(grub_emu_LDFLAGS)
 
 grub_emu-commands_boot.o: commands/boot.c $(commands/boot.c_DEPENDENCIES)
 	$(CC) -Icommands -I$(srcdir)/commands $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 $(grub_emu_CFLAGS) -MD -c -o $@ $<
@@ -484,6 +484,10 @@
 	$(CC) -Iutil -I$(srcdir)/util $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 $(grub_emu_CFLAGS) -MD -c -o $@ $<
 -include grub_emu-util_console.d
 
+grub_emu-util_hostfs.o: util/hostfs.c $(util/hostfs.c_DEPENDENCIES)
+	$(CC) -Iutil -I$(srcdir)/util $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 $(grub_emu_CFLAGS) -MD -c -o $@ $<
+-include grub_emu-util_hostfs.d
+
 grub_emu-util_grub_emu.o: util/grub-emu.c $(util/grub-emu.c_DEPENDENCIES)
 	$(CC) -Iutil -I$(srcdir)/util $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 $(grub_emu_CFLAGS) -MD -c -o $@ $<
 -include grub_emu-util_grub_emu.d
@@ -649,6 +653,8 @@
 
 # Modules.
 pkgdata_MODULES = halt.mod \
+	_ofboot.mod \
+	ofboot.mod \
 	_linux.mod \
 	linux.mod \
 	normal.mod \
@@ -657,6 +663,110 @@
         _multiboot.mod \
         multiboot.mod
 
+# For _ofboot.mod.
+_ofboot_mod_SOURCES = loader/powerpc/ieee1275/ofboot.c
+CLEANFILES += _ofboot.mod mod-_ofboot.o mod-_ofboot.c pre-_ofboot.o _ofboot_mod-loader_powerpc_ieee1275_ofboot.o und-_ofboot.lst
+ifneq ($(_ofboot_mod_EXPORTS),no)
+CLEANFILES += def-_ofboot.lst
+DEFSYMFILES += def-_ofboot.lst
+endif
+MOSTLYCLEANFILES += _ofboot_mod-loader_powerpc_ieee1275_ofboot.d
+UNDSYMFILES += und-_ofboot.lst
+
+_ofboot.mod: pre-_ofboot.o mod-_ofboot.o
+	-rm -f $@
+	$(TARGET_CC) $(_ofboot_mod_LDFLAGS) $(TARGET_LDFLAGS) -Wl,-r,-d -o $@ $^
+	$(STRIP) --strip-unneeded -K grub_mod_init -K grub_mod_fini -R .note -R .comment $@
+
+pre-_ofboot.o: $(_ofboot_mod_DEPENDENCIES) _ofboot_mod-loader_powerpc_ieee1275_ofboot.o
+	-rm -f $@
+	$(TARGET_CC) $(_ofboot_mod_LDFLAGS) $(TARGET_LDFLAGS) -Wl,-r,-d -o $@ _ofboot_mod-loader_powerpc_ieee1275_ofboot.o
+
+mod-_ofboot.o: mod-_ofboot.c
+	$(TARGET_CC) $(TARGET_CPPFLAGS) $(TARGET_CFLAGS) $(_ofboot_mod_CFLAGS) -c -o $@ $<
+
+mod-_ofboot.c: moddep.lst genmodsrc.sh
+	sh $(srcdir)/genmodsrc.sh '_ofboot' $< > $@ || (rm -f $@; exit 1)
+
+ifneq ($(_ofboot_mod_EXPORTS),no)
+def-_ofboot.lst: pre-_ofboot.o
+	$(NM) -g --defined-only -P -p $< | sed 's/^\([^ ]*\).*/\1 _ofboot/' > $@
+endif
+
+und-_ofboot.lst: pre-_ofboot.o
+	echo '_ofboot' > $@
+	$(NM) -u -P -p $< | cut -f1 -d' ' >> $@
+
+_ofboot_mod-loader_powerpc_ieee1275_ofboot.o: loader/powerpc/ieee1275/ofboot.c
+	$(TARGET_CC) -Iloader/powerpc/ieee1275 -I$(srcdir)/loader/powerpc/ieee1275 $(TARGET_CPPFLAGS) $(TARGET_CFLAGS) $(_ofboot_mod_CFLAGS) -MD -c -o $@ $<
+-include _ofboot_mod-loader_powerpc_ieee1275_ofboot.d
+
+CLEANFILES += cmd-_ofboot_mod-loader_powerpc_ieee1275_ofboot.lst fs-_ofboot_mod-loader_powerpc_ieee1275_ofboot.lst
+COMMANDFILES += cmd-_ofboot_mod-loader_powerpc_ieee1275_ofboot.lst
+FSFILES += fs-_ofboot_mod-loader_powerpc_ieee1275_ofboot.lst
+
+cmd-_ofboot_mod-loader_powerpc_ieee1275_ofboot.lst: loader/powerpc/ieee1275/ofboot.c gencmdlist.sh
+	set -e; 	  $(TARGET_CC) -Iloader/powerpc/ieee1275 -I$(srcdir)/loader/powerpc/ieee1275 $(TARGET_CPPFLAGS) $(TARGET_CFLAGS) $(_ofboot_mod_CFLAGS) -E $< 	  | sh $(srcdir)/gencmdlist.sh _ofboot > $@ || (rm -f $@; exit 1)
+
+fs-_ofboot_mod-loader_powerpc_ieee1275_ofboot.lst: loader/powerpc/ieee1275/ofboot.c genfslist.sh
+	set -e; 	  $(TARGET_CC) -Iloader/powerpc/ieee1275 -I$(srcdir)/loader/powerpc/ieee1275 $(TARGET_CPPFLAGS) $(TARGET_CFLAGS) $(_ofboot_mod_CFLAGS) -E $< 	  | sh $(srcdir)/genfslist.sh _ofboot > $@ || (rm -f $@; exit 1)
+
+
+_ofboot_mod_CFLAGS = $(COMMON_CFLAGS)
+_ofboot_mod_LDFLAGS = $(COMMON_LDFLAGS)
+
+# For ofboot.mod.
+ofboot_mod_SOURCES = loader/powerpc/ieee1275/ofboot_normal.c
+CLEANFILES += ofboot.mod mod-ofboot.o mod-ofboot.c pre-ofboot.o ofboot_mod-loader_powerpc_ieee1275_ofboot_normal.o und-ofboot.lst
+ifneq ($(ofboot_mod_EXPORTS),no)
+CLEANFILES += def-ofboot.lst
+DEFSYMFILES += def-ofboot.lst
+endif
+MOSTLYCLEANFILES += ofboot_mod-loader_powerpc_ieee1275_ofboot_normal.d
+UNDSYMFILES += und-ofboot.lst
+
+ofboot.mod: pre-ofboot.o mod-ofboot.o
+	-rm -f $@
+	$(TARGET_CC) $(ofboot_mod_LDFLAGS) $(TARGET_LDFLAGS) -Wl,-r,-d -o $@ $^
+	$(STRIP) --strip-unneeded -K grub_mod_init -K grub_mod_fini -R .note -R .comment $@
+
+pre-ofboot.o: $(ofboot_mod_DEPENDENCIES) ofboot_mod-loader_powerpc_ieee1275_ofboot_normal.o
+	-rm -f $@
+	$(TARGET_CC) $(ofboot_mod_LDFLAGS) $(TARGET_LDFLAGS) -Wl,-r,-d -o $@ ofboot_mod-loader_powerpc_ieee1275_ofboot_normal.o
+
+mod-ofboot.o: mod-ofboot.c
+	$(TARGET_CC) $(TARGET_CPPFLAGS) $(TARGET_CFLAGS) $(ofboot_mod_CFLAGS) -c -o $@ $<
+
+mod-ofboot.c: moddep.lst genmodsrc.sh
+	sh $(srcdir)/genmodsrc.sh 'ofboot' $< > $@ || (rm -f $@; exit 1)
+
+ifneq ($(ofboot_mod_EXPORTS),no)
+def-ofboot.lst: pre-ofboot.o
+	$(NM) -g --defined-only -P -p $< | sed 's/^\([^ ]*\).*/\1 ofboot/' > $@
+endif
+
+und-ofboot.lst: pre-ofboot.o
+	echo 'ofboot' > $@
+	$(NM) -u -P -p $< | cut -f1 -d' ' >> $@
+
+ofboot_mod-loader_powerpc_ieee1275_ofboot_normal.o: loader/powerpc/ieee1275/ofboot_normal.c
+	$(TARGET_CC) -Iloader/powerpc/ieee1275 -I$(srcdir)/loader/powerpc/ieee1275 $(TARGET_CPPFLAGS) $(TARGET_CFLAGS) $(ofboot_mod_CFLAGS) -MD -c -o $@ $<
+-include ofboot_mod-loader_powerpc_ieee1275_ofboot_normal.d
+
+CLEANFILES += cmd-ofboot_mod-loader_powerpc_ieee1275_ofboot_normal.lst fs-ofboot_mod-loader_powerpc_ieee1275_ofboot_normal.lst
+COMMANDFILES += cmd-ofboot_mod-loader_powerpc_ieee1275_ofboot_normal.lst
+FSFILES += fs-ofboot_mod-loader_powerpc_ieee1275_ofboot_normal.lst
+
+cmd-ofboot_mod-loader_powerpc_ieee1275_ofboot_normal.lst: loader/powerpc/ieee1275/ofboot_normal.c gencmdlist.sh
+	set -e; 	  $(TARGET_CC) -Iloader/powerpc/ieee1275 -I$(srcdir)/loader/powerpc/ieee1275 $(TARGET_CPPFLAGS) $(TARGET_CFLAGS) $(ofboot_mod_CFLAGS) -E $< 	  | sh $(srcdir)/gencmdlist.sh ofboot > $@ || (rm -f $@; exit 1)
+
+fs-ofboot_mod-loader_powerpc_ieee1275_ofboot_normal.lst: loader/powerpc/ieee1275/ofboot_normal.c genfslist.sh
+	set -e; 	  $(TARGET_CC) -Iloader/powerpc/ieee1275 -I$(srcdir)/loader/powerpc/ieee1275 $(TARGET_CPPFLAGS) $(TARGET_CFLAGS) $(ofboot_mod_CFLAGS) -E $< 	  | sh $(srcdir)/genfslist.sh ofboot > $@ || (rm -f $@; exit 1)
+
+
+ofboot_mod_CFLAGS = $(COMMON_CFLAGS)
+ofboot_mod_LDFLAGS = $(COMMON_LDFLAGS)
+
 # For _linux.mod.
 _linux_mod_SOURCES = loader/powerpc/ieee1275/linux.c
 CLEANFILES += _linux.mod mod-_linux.o mod-_linux.c pre-_linux.o _linux_mod-loader_powerpc_ieee1275_linux.o und-_linux.lst
diff -urN grub2.org/conf/powerpc-ieee1275.rmk grub2/conf/powerpc-ieee1275.rmk
--- grub2.org/conf/powerpc-ieee1275.rmk	2007-08-29 19:49:46.000000000 +0200
+++ grub2/conf/powerpc-ieee1275.rmk	2007-09-15 02:39:55.481459267 +0200
@@ -73,7 +73,7 @@
 	normal/menu_entry.c normal/misc.c normal/script.c		\
 	partmap/amiga.c	partmap/apple.c partmap/pc.c partmap/sun.c	\
 	partmap/acorn.c							\
-	util/console.c util/grub-emu.c util/misc.c			\
+	util/console.c util/hostfs.c util/grub-emu.c util/misc.c			\
 	util/biosdisk.c util/getroot.c			\
 	util/powerpc/ieee1275/misc.c grub_script.tab.c grub_emu_init.c
 
@@ -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-09-14 23:08:09.932217034 +0200
@@ -23,10 +23,13 @@
    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_linux_init (void);
 void grub_linux_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/kern/powerpc/ieee1275/init.c grub2/kern/powerpc/ieee1275/init.c
--- grub2.org/kern/powerpc/ieee1275/init.c	2007-07-22 01:32:27.000000000 +0200
+++ grub2/kern/powerpc/ieee1275/init.c	2007-09-15 04:45:39.129133111 +0200
@@ -115,14 +115,16 @@
 /* Claim some available memory in the first /memory node. */
 static void grub_claim_heap (unsigned long heaplimit)
 {
+  unsigned long total = 0;
+
   auto int heap_init (grub_uint64_t addr, grub_uint64_t len);
   int heap_init (grub_uint64_t addr, grub_uint64_t len)
   {
     len -= 1; /* Required for some firmware.  */
 
     /* Don't claim anything above `heaplimit'.  */
-    if (addr + len > heaplimit)
-      len = heaplimit - addr;
+    if (total + len > heaplimit)
+      len = heaplimit - total;
 
     if (len)
       {
@@ -134,6 +136,10 @@
 	grub_mm_init_region ((void *) (grub_addr_t) addr, len);
       }
 
+    total += len;
+    if (total >= heaplimit)
+      return 1;
+
     return 0;
   }
 
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-09-15 04:45:47.960133111 +0200
@@ -0,0 +1,135 @@
+/* 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 <http://www.gnu.org/licenses/>.
+ */
+
+#include <grub/loader.h>
+#include <grub/dl.h>
+#include <grub/mm.h>
+#include <grub/rescue.h>
+#include <grub/misc.h>
+#include <grub/ieee1275/ieee1275.h>
+#include <grub/machine/loader.h>
+
+static grub_dl_t my_mod;
+
+static char *ofboot_args;
+
+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_release_mem (void)
+{
+  grub_free (ofboot_args);
+  ofboot_args = 0;
+      
+  return GRUB_ERR_NONE;
+}
+
+static grub_err_t
+grub_ofboot_unload (void)
+{
+  grub_err_t err;
+
+  err = grub_ofboot_release_mem ();
+  grub_dl_unref (my_mod);
+
+  return err;
+}
+
+void
+grub_rescue_cmd_ofboot (int argc, char *argv[])
+{
+  int i;
+  int size;
+  grub_err_t err;
+  grub_ieee1275_cell_t res;
+  char *dest;
+
+  grub_dl_ref (my_mod);
+
+  if (argc == 0)
+    {
+      grub_error (GRUB_ERR_BAD_ARGUMENT, "no file specified");
+      goto out;
+    }
+
+  /* Release the previously used memory.  */
+  grub_loader_unset ();
+
+  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 (grub_errno != GRUB_ERR_NONE)
+    {
+      grub_ofboot_release_mem ();
+      grub_dl_unref (my_mod);
+    }
+  else
+    {
+      grub_loader_set (grub_ofboot_boot, grub_ofboot_unload, 1);
+    }
+}
+
+
+GRUB_MOD_INIT(ofboot)
+{
+  grub_rescue_register_command ("ofboot", grub_rescue_cmd_ofboot,
+				"load using OF interface");
+  my_mod = mod;
+}
+
+GRUB_MOD_FINI(ofboot)
+{
+  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-09-14 22:54:03.573217034 +0200
@@ -0,0 +1,48 @@
+/* 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 <http://www.gnu.org/licenses/>.
+ */
+
+#include <grub/normal.h>
+#include <grub/dl.h>
+#include <grub/machine/loader.h>
+
+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;
+}
+
+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_MOD_FINI(ofboot_normal)
+{
+  grub_unregister_command ("ofboot");
+}
diff -urN grub2.org/fs/affs.c grub2/fs/affs.c
--- grub2.org/fs/affs.c	2007-08-02 20:40:36.000000000 +0200
+++ grub2/fs/affs.c	2007-09-15 10:23:35.550133111 +0200
@@ -25,6 +25,7 @@
 #include <grub/dl.h>
 #include <grub/types.h>
 #include <grub/fshelp.h>
+#include <grub/partition.h>
 
 /* The affs bootblock.  */
 struct grub_affs_bblock
@@ -97,6 +98,9 @@
   struct grub_fshelp_node diropen;
   grub_disk_t disk;
 
+  /* Size in sectors */
+  grub_uint64_t len;
+
   /* Blocksize in sectors.  */
   int blocksize;
 
@@ -170,10 +174,17 @@
   int checksumr = 0;
   int blocksize = 0;
 
+
   data = grub_malloc (sizeof (struct grub_affs_data));
   if (!data)
     return 0;
 
+  /* total_sectors are not valid on ieee1275 */
+  if(disk->partition)
+    data->len = grub_partition_get_len (disk->partition);
+  else
+    data->len = disk->total_sectors;
+
   /* Read the bootblock.  */
   grub_disk_read (disk, 0, 0, sizeof (struct grub_affs_bblock),
 		  (char *) &data->bblock);
@@ -194,12 +205,6 @@
       goto fail;
     }
 
-  /* Read the bootblock.  */
-  grub_disk_read (disk, 0, 0, sizeof (struct grub_affs_bblock),
-		  (char *) &data->bblock);
-  if (grub_errno)
-    goto fail;
-
   /* No sane person uses more than 8KB for a block.  At least I hope
      for that person because in that case this won't work.  */
   rootblock = grub_malloc (GRUB_DISK_SECTOR_SIZE * 16);
@@ -209,7 +214,7 @@
   rblock = (struct grub_affs_rblock *) rootblock;
 
   /* Read the rootblock.  */
-  grub_disk_read (disk, (disk->total_sectors >> 1) + blocksize, 0,
+  grub_disk_read (disk, (data->len >> 1) + blocksize, 0,
 		  GRUB_DISK_SECTOR_SIZE * 16, (char *) rootblock);
   if (grub_errno)
     goto fail;
@@ -241,7 +246,7 @@
   data->disk = disk;
   data->htsize = grub_be_to_cpu32 (rblock->htsize);
   data->diropen.data = data;
-  data->diropen.block = (disk->total_sectors >> 1);
+  data->diropen.block = (data->len >> 1);
 
   grub_free (rootblock);
 
@@ -522,7 +527,7 @@
     {
       /* The rootblock maps quite well on a file header block, it's
 	 something we can use here.  */
-      grub_disk_read (data->disk, disk->total_sectors >> 1,
+      grub_disk_read (data->disk, data->len >> 1,
 		      data->blocksize * (GRUB_DISK_SECTOR_SIZE
 					 - GRUB_AFFS_FILE_LOCATION),
 		      sizeof (file), (char *) &file);
_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel

Reply via email to