grub-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] Running GRUB under qemu on PowerPC


From: Pavel Roskin
Subject: [PATCH] Running GRUB under qemu on PowerPC
Date: Wed, 16 Jan 2008 03:19:49 -0500
User-agent: Internet Messaging Program (IMP) H3 (4.1.4)

Hello!

I'm very close to being able to run GRUB2 on an emulated PowerPC machine. I haven't tried cross compiling. I compile GRUB on a PowerPC system and run it there under qemu. This saves time, as it allows to avoid lengthy reboots.

Only the latest qemu 0.9.1 appears to be working with bootable CD-ROMs for PowerPC. The new qemu is not even in Fedora 8, so I had to compile and install it locally.

A patch needs to be applied to the GRUB sources. First of all, the firmware used in qemu (Open Hack'Ware) doesn't have an interpreter. It knows how to interpret some commands, but not "output-device output", which means that GRUB_IEEE1275_FLAG_BROKEN_OUTPUT has to be set.

Also, setting colors doesn't work (i.e. the boot stops). I introduced a separate flag to suppress color settings.

Here's how to make a bootable image. Start in an empty directory. Make a subdirectory called "cdtree" with the "boot" subdirectory in it. Copy kernel.elf from the GRUB directory to cdtree/boot. Optionally, copy other files there. Create a file hfs.map in the current directory. Here's its contents:

# EXTN          XLate   CREATOR   TYPE     Comment
kernel.elf      Raw     'UNIX'    'tbxi'   "bootstrap"
.cfg            Raw     'UNIX'    'conf'   "bootstrap"

To create the HFS/ISO image, run

genisoimage -hfs -part -map hfs.map -no-desktop -r -J \
 -o bootcd.iso -hfs-bless cdtree/boot cdtree

The compressed image is available at
http://red-bean.com/proski/grub/bootcd.iso.bz2

To run it under qemu (PowerPC is not required!), run:

qemu-system-ppc -cdrom bootcd.iso -boot d

Please note that the "-hfs-bless" switch is extremely finicky and tends to fail silently if there is any extra slash or something like that. I could not find a way to bless the root directory with genisoimage. That's why "boot" is used.

The unresolved problem is that the "/memory/available" property is not available. I get the "grub rescue" prompt, but all commands fail with "out of memory".

ChangeLog:

        * include/grub/ieee1275/ieee1275.h: Introduce a flag for
        broken color support, needed for Open Hack'Ware.
        * kern/powerpc/ieee1275/cmain.c (grub_ieee1275_find_options):
        Recognize Open Hack'Ware.
        * term/ieee1275/ofconsole.c (grub_ofconsole_init): Skip color
        initialization for Open Hack'Ware.

diff --git a/include/grub/ieee1275/ieee1275.h b/include/grub/ieee1275/ieee1275.h
index 57285d8..ddfe1b1 100644
--- a/include/grub/ieee1275/ieee1275.h
+++ b/include/grub/ieee1275/ieee1275.h
@@ -82,6 +82,9 @@ enum grub_ieee1275_flag

   /* CodeGen firmware does not correctly implement "output-device output" */
   GRUB_IEEE1275_FLAG_BROKEN_OUTPUT,
+
+  /* Open Hack'Ware stops while trying to set colors */
+  GRUB_IEEE1275_FLAG_BROKEN_COLORS,
 };

extern int EXPORT_FUNC(grub_ieee1275_test_flag) (enum grub_ieee1275_flag flag);
diff --git a/kern/powerpc/ieee1275/cmain.c b/kern/powerpc/ieee1275/cmain.c
index f560a03..c34c934 100644
--- a/kern/powerpc/ieee1275/cmain.c
+++ b/kern/powerpc/ieee1275/cmain.c
@@ -50,6 +50,7 @@ grub_ieee1275_find_options (void)
 {
   grub_ieee1275_phandle_t options;
   grub_ieee1275_phandle_t openprom;
+  grub_ieee1275_phandle_t bootrom;
   int rc;
   int realmode = 0;
   char tmp[32];
@@ -100,6 +101,16 @@ grub_ieee1275_find_options (void)
            }
        }
     }
+
+  if (! grub_ieee1275_finddevice ("/rom/boot-rom", &bootrom)) {
+    rc = grub_ieee1275_get_property (bootrom, "model",
+                                    tmp, sizeof (tmp), 0);
+#define OHW "PPC Open Hack'Ware"
+    if (rc >= 0 && !grub_strncmp (tmp, OHW, sizeof (OHW) - 1)) {
+      grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_BROKEN_OUTPUT);
+      grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_BROKEN_COLORS);
+    }
+  }
 }

 void cmain (uint32_t r3, uint32_t r4, uint32_t r5);
diff --git a/term/ieee1275/ofconsole.c b/term/ieee1275/ofconsole.c
index 845f198..9246319 100644
--- a/term/ieee1275/ofconsole.c
+++ b/term/ieee1275/ofconsole.c
@@ -338,12 +338,14 @@ grub_ofconsole_init (void)
   stdin_ihandle = grub_ieee1275_decode_int_4 (data);

   /* Initialize colors.  */
-  for (col = 0; col < 7; col++)
-    grub_ieee1275_set_color (stdout_ihandle, col, colors[col].red,
-                            colors[col].green, colors[col].blue);
-
-  /* Set the right fg and bg colors.  */
-  grub_ofconsole_setcolorstate (GRUB_TERM_COLOR_NORMAL);
+  if (! grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_BROKEN_COLORS)) {
+    for (col = 0; col < 7; col++)
+      grub_ieee1275_set_color (stdout_ihandle, col, colors[col].red,
+                              colors[col].green, colors[col].blue);
+
+    /* Set the right fg and bg colors.  */
+    grub_ofconsole_setcolorstate (GRUB_TERM_COLOR_NORMAL);
+  }

   return 0;
 }

--
Regards,
Pavel Roskin




reply via email to

[Prev in Thread] Current Thread [Next in Thread]