All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mike Small <smallm@panix.com>
To: The development of GRUB 2 <grub-devel@gnu.org>
Subject: Re: grub-install on powermac newworld
Date: Mon, 21 Nov 2005 01:00:32 -0500	[thread overview]
Message-ID: <20051121060032.GA9198@panix.com> (raw)
In-Reply-To: <1132207501.2541.26.camel@silence>

[-- Attachment #1: Type: text/plain, Size: 3233 bytes --]

On Thu, Nov 17, 2005 at 12:05:00AM -0600, Hollis Blanchard wrote:
...
> > I didn't really exercise the nvsetenv part of the script since I've
> > had problems setting the boot device on this machine before (466
> > Powermac G4 - it seems to want to add ,\\:tbxi to whatever
> > boot-device string I set)
> 
> Are you sure it's not ybin trying to do that? I would be very surprised
> if nvsetenv or OF itself do.

I was confused here.  What I thought was the appended string was
hd:,\\:tbxi and it was only the next column over in the openfirmware
printenv output, showing the factory defaults.  I was fooled because
the long device string pushed the columns out of alignment.  Sorry
about that.

I tried testing the nvsetenv part of grub-install and it almost
worked.  There's a problem with the regex that pulls off the partition
number from a device file name.  If you have more than one digit in
your partition (mine was at /dev/hda11) it only grabs the last one
because of greedy matching on .*.  I included a fix for this in the
attached patch.

> > After I moved the files from /mnt/boot/grub to the root of my boot
> > partition (which is hfs) and rebooted, grub seemed to work okay (more
> > than okay really, I love that you can cat files from the bootloader -
> > neat stuff) until I typed in an initrd command.  Then I got the error
> > message: "Can not claim memory."  This was with a backported 2.6.12
> > kernel from a debian developer's site (Sven Luther) but the same thing
> > happened with the standard Sarge 2.6.8 kernel.  The kernel was 4641711
> > bytes and the initrd image was 4820992 bytes.
...

> grub_claimmap is a call to firmware to request access to a particular
> area of memory. Trying to access memory without it could result in
> scribbling over memory somebody else (e.g. OF itself) is using, or could
> result in a page fault because it wasn't mapped.
> 
> Two related notes: I believe Marco mentioned that we should keep
> attempting to find a space for the initrd. We do this already for the
> kernel (notice the for loop around the other grub_claimmap call), but
> not yet for initrd.

This worked for me, and I've enclosed a patch with the a similar loop
to the one used for the linux command.  It also has debugging messages
before the grub_claimmap calls.  

I'm wondering though, does it matter very much how grub grabs memory?
Once the operating system takes over it takes all of memory and
whatever grub allocated doesn't matter anymore.  Is that correct?  The
reason I ask is that I tried making that loop retry the claim at every
4 bytes instead of at every megabyte and found it settled on an
address only four bytes higher than the one it failed on.  So maybe
it's possible to be more precise than the code in this patch is.

My guess would be that open firmware allocates with a resolution of 8
bytes, at least on my machine.  In that second test, the address that
the grub_claimmap failed on was 1b99F84 and the one it succeeded on
was 1b99F88.  1b99F84 was the exact end of the space allocated by the
linux command (at 1400000, size 799f84), so if o.f. grabbed in 8 bytes
increments it would have had up to 1b99F88, causing the failure.
Plausible?

-- 
Mike Small
smallm@panix.com

[-- Attachment #2: initrdclaim.patch --]
[-- Type: text/plain, Size: 2652 bytes --]


#
# Patch managed by http://www.holgerschurig.de/patcher.html
#

--- grub2/ChangeLog~initrdclaim
+++ grub2/ChangeLog
@@ -1,3 +1,15 @@
+2005-11-21  Mike Small  <smallm@panix.com>
+
+	* util/powerpc/ieee1275/grub-install.in (grubdir): Fixed partition
+	number regex so multidigit numbers are recognized correctly.
+
+2005-11-20  Mike Small  <smallm@panix.com>
+
+	* loader/powerpc/ieee1275/linux.c (grub_rescue_cmd_linux): Add a
+	debugging message before attempting to claim memory.
+	(grub_rescue_cmd_initrd): A new claim debugging message and try
+	multiple addresses in case of failure.
+
 2005-11-18  Timothy Baldwin  <T.E.Baldwin99@members.leeds.ac.uk>
 
 	* genmk.rb: Fixed list rules moved to Makefile.in.  Recognise
--- grub2/loader/powerpc/ieee1275/linux.c~initrdclaim
+++ grub2/loader/powerpc/ieee1275/linux.c
@@ -173,6 +173,8 @@
      try some other addresses just like yaboot does.  */
   for (linux_addr = entry; linux_addr < entry + 200 * 0x100000; linux_addr += 0x100000)
     {
+      grub_dprintf ("loader", "Attempting to claim at 0x%x, size 0x%x.\n", 
+		    linux_addr, linux_size);
       found_addr = grub_claimmap (linux_addr, linux_size);
       if (found_addr != -1)
 	break;
@@ -261,7 +263,9 @@
 {
   grub_file_t file = 0;
   grub_ssize_t size;
+  grub_addr_t first_addr;
   grub_addr_t addr;
+  int found_addr = 0;
 
   if (argc == 0)
     {
@@ -279,10 +283,21 @@
   if (! file)
     goto fail;
 
-  addr = linux_addr + linux_size;
+  first_addr = linux_addr + linux_size;
   size = grub_file_size (file);
 
-  if (grub_claimmap (addr, size) == -1)
+  /* Attempt to claim at a series of addresses until successful in
+     the same way that grub_rescue_cmd_linux does.  */
+  for (addr = first_addr; addr < first_addr + 200 * 0x100000; addr += 0x100000) 
+    {
+      grub_dprintf ("loader", "Attempting to claim at 0x%x, size 0x%x.\n", 
+		    addr, size);
+      found_addr = grub_claimmap (addr, size);
+      if (found_addr != -1)
+	break;
+    }
+
+  if (found_addr == -1)
     {
       grub_error (GRUB_ERR_OUT_OF_MEMORY, "Can not claim memory");
       goto fail;
--- grub2/util/powerpc/ieee1275/grub-install.in~initrdclaim
+++ grub2/util/powerpc/ieee1275/grub-install.in
@@ -171,7 +171,7 @@
 
     # Get the Open Firmware device tree path translation.
     dev=`echo $install_device | sed -e 's/\/dev\///' -e 's/[0-9]\+//'`
-    partno=`echo $install_device | sed -e 's/.*\([0-9]\+\)$/\1/'`
+    partno=`echo $install_device | sed -e 's/.*[^0-9]\([0-9]\+\)$/\1/'`
     ofpath=`$ofpathname $dev` || {
 	echo "Couldn't find Open Firmware device tree path for $dev."
 	echo "You will have to set boot-device manually."

  parent reply	other threads:[~2005-11-21  6:00 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-11-17  4:17 grub-install on powermac newworld Mike Small
2005-11-17  6:05 ` Hollis Blanchard
2005-11-18 10:56   ` Yoshinori K. Okuji
2005-11-21  6:00   ` Mike Small [this message]
2005-11-23  4:42     ` Hollis Blanchard
2005-11-23  3:55 ` grub-install --root-directory Hollis Blanchard
2005-11-25 20:27   ` Yoshinori K. Okuji

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20051121060032.GA9198@panix.com \
    --to=smallm@panix.com \
    --cc=grub-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.