Skip to contentSkip to conversation

another regression on Efika

PATCH In review Robert Millan 5 participants 35 messages Jul 2, 2007 – Oct 4, 2007 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

Hi,

I spotted another regression, caused by the following commits:

2007-02-21 Hollis Blanchard <[email protected]>

* kern/powerpc/ieee1275/init.c (HEAP_SIZE): Removed. (HEAP_LIMIT): New macro. (grub_claim_heap): Claim memory up to `heaplimit'.

2007-02-21 Hollis Blanchard <[email protected]>

* conf/powerpc-ieee1275.rmk (kernel_elf_LDFLAGS): Link at 64KB.
* kern/powerpc/ieee1275/init.c (_end): Add declaration. (_start): Likewise.
(grub_arch_modules_addr): Return address after `_end'.
* util/powerpc/ieee1275/grub-mkimage.c: Include grub/misc.h. (load_modules): Use new parameter as p_paddr' and p_vaddr'. (add_segments): Calculate `_end' from phdr size and location. (ALIGN_UP): Moved to ...
* include/grub/misc.h: here.
* include/grub/powerpc/ieee1275/kernel.h (GRUB_IEEE1275_MOD_ALIGN):
New macro.
(GRUB_IEEE1275_MODULE_BASE): Removed.

They move GRUB from being able to initialise and fire up the menu (although still unable to access disks), to abort with:

  kern/mm.c:  grub_error (GRUB_ERR_OUT_OF_MEMORY, "out of memory");

Unfortunately my limited expertise doesn't let me figure out what these changes are doing. I'm attaching a reverse diff of the commit, such that when applied to HEAD makes GRUB work again (verified) [1]. Perhaps someone can make sense of it.

[1] Provided that the other regression caused by MacWorld hack is also fixed, of course.

Signature · 4 lines
Robert Millan

My spam trap is [email protected].  Note: this address is only intended
for spam harvesters.  Writing to it will get you added to my black list.

-2007-02-21 Hollis Blanchard <[email protected]> -
- * kern/powerpc/ieee1275/init.c (HEAP_SIZE): Removed.
- (HEAP_LIMIT): New macro.
- (grub_claim_heap): Claim memory up to `heaplimit'.
-
-2007-02-21 Hollis Blanchard <[email protected]> -
- * conf/powerpc-ieee1275.rmk (kernel_elf_LDFLAGS): Link at 64KB.
- * kern/powerpc/ieee1275/init.c (_end): Add declaration.
- (_start): Likewise.
- (grub_arch_modules_addr): Return address after `_end'.
- * util/powerpc/ieee1275/grub-mkimage.c: Include grub/misc.h.
- (load_modules): Use new parameter as p_paddr' and p_vaddr'.
- (add_segments): Calculate `_end' from phdr size and location.
- (ALIGN_UP): Moved to ...
- * include/grub/misc.h: here.
- * include/grub/powerpc/ieee1275/kernel.h (GRUB_IEEE1275_MOD_ALIGN):
- New macro.
- (GRUB_IEEE1275_MODULE_BASE): Removed.

conf/powerpc-ieee1275.mk +1 -2
diff -ur grub2-bad/conf/powerpc-ieee1275.mk grub2-good/conf/powerpc-ieee1275.mk
@@ -468,7 +468,7 @@
 kernel_elf_CFLAGS = $(COMMON_CFLAGS)
 kernel_elf_ASFLAGS = $(COMMON_ASFLAGS)
 kernel_elf_LDFLAGS = $(COMMON_LDFLAGS) -static-libgcc -lgcc \
-	-Wl,-N,-S,-Ttext,0x10000,-Bstatic
+	-Wl,-N,-S,-Ttext,0x200000,-Bstatic
 
 # Scripts.
 sbin_SCRIPTS = grub-install
@@ -1004,4 +1004,3 @@
 halt_mod_LDFLAGS = $(COMMON_LDFLAGS)
 
 include $(srcdir)/conf/common.mk
-
conf/powerpc-ieee1275.rmk +1 -2
diff -ur grub2-bad/conf/powerpc-ieee1275.rmk grub2-good/conf/powerpc-ieee1275.rmk
@@ -74,7 +74,7 @@
 kernel_elf_CFLAGS = $(COMMON_CFLAGS)
 kernel_elf_ASFLAGS = $(COMMON_ASFLAGS)
 kernel_elf_LDFLAGS = $(COMMON_LDFLAGS) -static-libgcc -lgcc \
-	-Wl,-N,-S,-Ttext,0x10000,-Bstatic
+	-Wl,-N,-S,-Ttext,0x200000,-Bstatic
 
 # Scripts.
 sbin_SCRIPTS = grub-install
@@ -127,4 +127,3 @@
 halt_mod_LDFLAGS = $(COMMON_LDFLAGS)
 
 include $(srcdir)/conf/common.mk
-
include/grub/misc.h +0 -2
diff -ur grub2-bad/include/grub/misc.h grub2-good/include/grub/misc.h
@@ -26,8 +26,6 @@
 #include <grub/symbol.h>
 #include <grub/err.h>
 
-#define ALIGN_UP(addr, align) ((long)((char *)addr + align - 1) & ~(align - 1))
-
 #define grub_dprintf(condition, fmt, args...) grub_real_dprintf(__FILE__, __LINE__, condition, fmt, ## args);
 /* XXX: If grub_memmove is too slow, we must implement grub_memcpy.  */
 #define grub_memcpy(d,s,n)	grub_memmove ((d), (s), (n))
include/grub/powerpc/ieee1275/kernel.h +3 -2
diff -ur grub2-bad/include/grub/powerpc/ieee1275/kernel.h grub2-good/include/grub/powerpc/ieee1275/kernel.h
@@ -22,9 +22,10 @@
 
 #include <grub/symbol.h>
 
-#define GRUB_IEEE1275_MOD_ALIGN 0x1000
-
 void EXPORT_FUNC (grub_reboot) (void);
 void EXPORT_FUNC (grub_halt) (void);
 
+/* Where grub-mkimage places the core modules in memory.  */
+#define GRUB_IEEE1275_MODULE_BASE 0x00300000
+
 #endif /* ! GRUB_KERNEL_MACHINE_HEADER */
kern/powerpc/ieee1275/init.c +20 -21

69 lines not on this page · raw message

util/powerpc/ieee1275/grub-mkimage.c +7 -21
diff -ur grub2-bad/util/powerpc/ieee1275/grub-mkimage.c grub2-good/util/powerpc/ieee1275/grub-mkimage.c
@@ -1,6 +1,6 @@
 /*
  *  GRUB  --  GRand Unified Bootloader
- *  Copyright (C) 2004,2005,2006,2007  Free Software Foundation, Inc.
+ *  Copyright (C) 2004,2005,2006  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
@@ -27,12 +27,13 @@
 #include <stdlib.h>
 #include <string.h>
 #include <grub/elf.h>
-#include <grub/misc.h>
 #include <grub/util/misc.h>
 #include <grub/util/resolve.h>
 #include <grub/kernel.h>
 #include <grub/machine/kernel.h>
 
+#define ALIGN_UP(addr, align) ((long)((char *)addr + align - 1) & ~(align - 1))
+
 #define GRUB_IEEE1275_NOTE_NAME "PowerPC"
 #define GRUB_IEEE1275_NOTE_TYPE 0x1275
 
@@ -97,8 +98,7 @@
 }
 
 void
-load_modules (grub_addr_t modbase, Elf32_Phdr *phdr, const char *dir,
-	      char *mods[], FILE *out)
+load_modules (Elf32_Phdr *phdr, const char *dir, char *mods[], FILE *out)
 {
   char *module_img;
   struct grub_util_path_list *path_list;
@@ -152,8 +152,8 @@
   phdr->p_type = grub_cpu_to_be32 (PT_LOAD);
   phdr->p_flags = grub_cpu_to_be32 (PF_R | PF_W | PF_X);
   phdr->p_align = grub_cpu_to_be32 (sizeof (long));
-  phdr->p_vaddr = grub_cpu_to_be32 (modbase);
-  phdr->p_paddr = grub_cpu_to_be32 (modbase);
+  phdr->p_vaddr = grub_cpu_to_be32 (GRUB_IEEE1275_MODULE_BASE);
+  phdr->p_paddr = grub_cpu_to_be32 (GRUB_IEEE1275_MODULE_BASE);
   phdr->p_filesz = grub_cpu_to_be32 (total_module_size);
   phdr->p_memsz = grub_cpu_to_be32 (total_module_size);
 }
@@ -166,7 +166,6 @@
   Elf32_Phdr *phdr;
   FILE *in;
   char *kernel_path;
-  grub_addr_t grub_end = 0;
   off_t phdroff;
   int i;
 
@@ -184,7 +183,6 @@
   for (i = 0; i < grub_be_to_cpu16 (ehdr.e_phnum); i++)
     {
       char *segment_img;
-      grub_size_t segment_end;
 
       phdr = phdrs + i;
 
@@ -196,13 +194,6 @@
       grub_util_info ("copying segment %d, type %d", i,
 		      grub_be_to_cpu32 (phdr->p_type));
 
-      /* Locate _end.  */
-      segment_end = grub_be_to_cpu32 (phdr->p_paddr)
-		    + grub_be_to_cpu32 (phdr->p_memsz);
-      grub_util_info ("segment %u end 0x%lx", i, segment_end);
-      if (segment_end > grub_end)
-	grub_end = segment_end;
-
       /* Read segment data and write it to new file.  */
       segment_img = xmalloc (grub_be_to_cpu32 (phdr->p_filesz));
   
@@ -216,11 +207,6 @@
 
   if (mods[0] != NULL)
     {
-      grub_addr_t modbase;
-
-      /* Place modules just after grub segment.  */
-      modbase = ALIGN_UP(grub_end, GRUB_IEEE1275_MOD_ALIGN);
-
       /* Construct new segment header for modules.  */
       phdr = phdrs + grub_be_to_cpu16 (ehdr.e_phnum);
       ehdr.e_phnum = grub_cpu_to_be16 (grub_be_to_cpu16 (ehdr.e_phnum) + 1);
@@ -229,7 +215,7 @@
       phdr->p_offset = grub_cpu_to_be32 (ALIGN_UP (grub_util_get_fp_size (out),
 						   sizeof (long)));
 
-      load_modules (modbase, phdr, dir, mods, out);
+      load_modules (phdr, dir, mods, out);
     }
 
   if (chrp)
#1 lore raw
Quoted 13 lines · Robert Millan

Hi,

I spotted another regression, caused by the following commits:

2007-02-21 Hollis Blanchard <[email protected]>

* kern/powerpc/ieee1275/init.c (HEAP_SIZE): Removed. (HEAP_LIMIT): New macro. (grub_claim_heap): Claim memory up to `heaplimit'.

2007-02-21 Hollis Blanchard <[email protected]>

Quoted 12 lines

* conf/powerpc-ieee1275.rmk (kernel_elf_LDFLAGS): Link at 64KB.
* kern/powerpc/ieee1275/init.c (_end): Add declaration. (_start): Likewise.
(grub_arch_modules_addr): Return address after `_end'.
* util/powerpc/ieee1275/grub-mkimage.c: Include grub/misc.h. (load_modules): Use new parameter as p_paddr' and p_vaddr'. (add_segments): Calculate `_end' from phdr size and location. (ALIGN_UP): Moved to ...
* include/grub/misc.h: here.
* include/grub/powerpc/ieee1275/kernel.h (GRUB_IEEE1275_MOD_ALIGN):
New macro.
(GRUB_IEEE1275_MODULE_BASE): Removed.

Btw, splitting the commits doesn't help. In-between version fails differently, and just reverting one of them in any later version doesn't solve the problem.

Signature · 4 lines
Robert Millan

My spam trap is [email protected].  Note: this address is only intended
for spam harvesters.  Writing to it will get you added to my black list.
#2 lore raw
In reply to Robert Millan
Quoted 25 lines · Robert Millan

Hi,

I spotted another regression, caused by the following commits:

2007-02-21 Hollis Blanchard <[email protected]>

* kern/powerpc/ieee1275/init.c (HEAP_SIZE): Removed. (HEAP_LIMIT): New macro. (grub_claim_heap): Claim memory up to `heaplimit'.

2007-02-21 Hollis Blanchard <[email protected]>

* conf/powerpc-ieee1275.rmk (kernel_elf_LDFLAGS): Link at 64KB.
* kern/powerpc/ieee1275/init.c (_end): Add declaration. (_start): Likewise.
(grub_arch_modules_addr): Return address after `_end'.
* util/powerpc/ieee1275/grub-mkimage.c: Include grub/misc.h. (load_modules): Use new parameter as p_paddr' and p_vaddr'. (add_segments): Calculate `_end' from phdr size and location. (ALIGN_UP): Moved to ...
* include/grub/misc.h: here.
* include/grub/powerpc/ieee1275/kernel.h (GRUB_IEEE1275_MOD_ALIGN):
New macro.
(GRUB_IEEE1275_MODULE_BASE): Removed.

Quoted 4 lines

They move GRUB from being able to initialise and fire up the menu (although still unable to access disks), to abort with:

  kern/mm.c:  grub_error (GRUB_ERR_OUT_OF_MEMORY, "out of memory");

This is probably because grub_mm_init_region() was never called, or wasn't called enough.

Quoted 4 lines

Unfortunately my limited expertise doesn't let me figure out what these changes are doing. I'm attaching a reverse diff of the commit, such that when applied to HEAD makes GRUB work again (verified) [1]. Perhaps someone can make sense of it.

This problem could be caused by firmware presenting an incorrect /memory/available property. I would instrument grub_available_iterate() and heap_init() to confirm.

That property lists unclaimed areas of memory, which are free for us to use as heap. The memory used for firmware itself (including exception handlers at 0), and the memory used by the loaded ELF file (GRUB), are missing from /memory/available, so we know not to try to use those regions for the heap.

If that is in fact the problem (which wouldn't surprise me given this particular firmware's track record), then we'll have to add some hardcoded hack particularly for Efika in grub_machine_init(), bypassing the more general code we have now.

-Hollis

#3 lore raw

Hey,

Quoted 10 lines · Hollis

This problem could be caused by firmware presenting an incorrect /memory/available property. I would instrument grub_available_iterate() and heap_init() to confirm.

That property lists unclaimed areas of memory, which are free for us to use as heap. The memory used for firmware itself (including exception handlers at 0), and the memory used by the loaded ELF file (GRUB), are missing from /memory/available, so we know not to try to use those regions for the heap.

Quoted 4 lines

If that is in fact the problem (which wouldn't surprise me given this particular firmware's track record), then we'll have to add some hardcoded hack particularly for Efika in grub_machine_init(), bypassing the more general code we have now.

I'm afraid there must be more to this.

The last version of GRUB which worked for me was Debian's 1.95-5, albeit it wouldn't show a valid menu (but that was caused by another bug, more or less fixed now). At that time, I could at least type in my linux+initrd commands to make the laptop boot.

When the package was later on updated to a CVS snapshot of 20070505, GRUB started dropping me to OF at boot time. On Saturday, Robert helped me track this regression down to this same commit. After reverting and regenerating grub, I'm happy to report that for the first time my Powerbook G4 laptop was able to boot with me pressing no keys at all, using GRUB.

In short, whatever is causing these crashes is not only an Efika issue. I suspect Apple, or Apple powerbooks at least, are also affected. I got Sjoerd to try this on his powerbook, and he confirms this fixes for him. Paul also tried, with the same results. Not all the powerbooks are the very same model, there are different model revisions involved.

The biggest issue now is that we all had to fix our generated configurations, as grub-probe and update-grub won't cope with a device.map that looks like this:

(hd) /dev/hda

This is a minor issue that I can fix by hand, luckily.

Thanks,
Jordi

Signature · 1 line
Jordi Mallach <[email protected]>
#4 lore raw

memory management issue (Re: another regression on Efika)

Quoted 29 lines · Jordi Mallach

Hey,

Quoted 10 lines · Hollis

This problem could be caused by firmware presenting an incorrect /memory/available property. I would instrument grub_available_iterate() and heap_init() to confirm.

That property lists unclaimed areas of memory, which are free for us to use as heap. The memory used for firmware itself (including exception handlers at 0), and the memory used by the loaded ELF file (GRUB), are missing from /memory/available, so we know not to try to use those regions for the heap.

Quoted 4 lines

If that is in fact the problem (which wouldn't surprise me given this particular firmware's track record), then we'll have to add some hardcoded hack particularly for Efika in grub_machine_init(), bypassing the more general code we have now.

I'm afraid there must be more to this.

[...]

When the package was later on updated to a CVS snapshot of 20070505, GRUB started dropping me to OF at boot time. On Saturday, Robert helped me track this regression down to this same commit. After reverting and regenerating grub, I'm happy to report that for the first time my Powerbook G4 laptop was able to boot with me pressing no keys at all, using GRUB.

Quoted 5 lines

In short, whatever is causing these crashes is not only an Efika issue. I suspect Apple, or Apple powerbooks at least, are also affected. I got Sjoerd to try this on his powerbook, and he confirms this fixes for him. Paul also tried, with the same results. Not all the powerbooks are the very same model, there are different model revisions involved.

The error Jordi was seeing before reverting your commits was very similar to what I get on my Efika (something like "claim failed").

Hollis, do you still think this is a firmware bug?

Signature · 4 lines
Robert Millan

My spam trap is [email protected].  Note: this address is only intended
for spam harvesters.  Writing to it will get you added to my black list.
#5 lore raw

Re: memory management issue (Re: another regression on Efika)

Quoted 21 lines · Robert Millan
Quoted 20 lines · Jordi Mallach

Hey,

Quoted 10 lines · Hollis

This problem could be caused by firmware presenting an incorrect /memory/available property. I would instrument grub_available_iterate() and heap_init() to confirm.

That property lists unclaimed areas of memory, which are free for us to use as heap. The memory used for firmware itself (including exception handlers at 0), and the memory used by the loaded ELF file (GRUB), are missing from /memory/available, so we know not to try to use those regions for the heap.

Quoted 4 lines

If that is in fact the problem (which wouldn't surprise me given this particular firmware's track record), then we'll have to add some hardcoded hack particularly for Efika in grub_machine_init(), bypassing the more general code we have now.

I'm afraid there must be more to this.

Quoted 8 lines
Quoted 8 lines

[...]

When the package was later on updated to a CVS snapshot of 20070505, GRUB started dropping me to OF at boot time. On Saturday, Robert helped me track this regression down to this same commit. After reverting and regenerating grub, I'm happy to report that for the first time my Powerbook G4 laptop was able to boot with me pressing no keys at all, using GRUB.

So you're talking about a completely different failure mode, correct?

Quoted 10 lines
Quoted 5 lines

In short, whatever is causing these crashes is not only an Efika issue. I suspect Apple, or Apple powerbooks at least, are also affected. I got Sjoerd to try this on his powerbook, and he confirms this fixes for him. Paul also tried, with the same results. Not all the powerbooks are the very same model, there are different model revisions involved.

The error Jordi was seeing before reverting your commits was very similar to what I get on my Efika (something like "claim failed").

Hollis, do you still think this is a firmware bug?

Could somebody please debug it and report back if it is really a GRUB issue? It could be as simple as adjusting the link address, or it could mean instrumenting grub_available_iterate() and checking that output with the contents of /memory/available.

-Hollis

#6 lore raw

Re: memory management issue (Re: another regression on Efika)

Quoted 9 lines · Hollis Blanchard
Quoted 9 lines
Quoted 5 lines

In short, whatever is causing these crashes is not only an Efika issue. I suspect Apple, or Apple powerbooks at least, are also affected. I got Sjoerd to try this on his powerbook, and he confirms this fixes for him. Paul also tried, with the same results. Not all the powerbooks are the very same model, there are different model revisions involved.

The error Jordi was seeing before reverting your commits was very similar to what I get on my Efika (something like "claim failed").

Quoted 6 lines
Quoted 1 line

Hollis, do you still think this is a firmware bug?

Could somebody please debug it and report back if it is really a GRUB issue? It could be as simple as adjusting the link address, or it could mean instrumenting grub_available_iterate() and checking that output with the contents of /memory/available.

It turns out that grub_claim_heap() was asked to claim a region that starts after the heap limit. The start address (0x19111e4) is correctly obtained from /memory/available.

Should heap limit be increased?

Signature · 4 lines
Robert Millan

My spam trap is [email protected].  Note: this address is only intended
for spam harvesters.  Writing to it will get you added to my black list.
#7 lore raw

Re: memory management issue (Re: another regression on Efika)

Quoted 17 lines · Robert Millan
Quoted 9 lines · Hollis Blanchard
Quoted 9 lines
Quoted 5 lines

In short, whatever is causing these crashes is not only an Efika issue. I suspect Apple, or Apple powerbooks at least, are also affected. I got Sjoerd to try this on his powerbook, and he confirms this fixes for him. Paul also tried, with the same results. Not all the powerbooks are the very same model, there are different model revisions involved.

The error Jordi was seeing before reverting your commits was very similar to what I get on my Efika (something like "claim failed").

Quoted 6 lines
Quoted 1 line

Hollis, do you still think this is a firmware bug?

Could somebody please debug it and report back if it is really a GRUB issue? It could be as simple as adjusting the link address, or it could mean instrumenting grub_available_iterate() and checking that output with the contents of /memory/available.

Quoted 5 lines

It turns out that grub_claim_heap() was asked to claim a region that starts after the heap limit. The start address (0x19111e4) is correctly obtained from /memory/available.

Should heap limit be increased?

The attached patch fixes the problem for Efika, although I'm not 1:1 sure of its correctness.

It seems to me that heaplimit is meant to be used as a relative offset, not as an absolute memory address. This makes the current code fail when the start address in /memory/available is higher than heaplimit, and I don't think there's anything that can grant us this won't happen. From this POV, it's clear that moving from relative to absolute address is wrong.

OTOH, your commit indicates (as per variable names, etc) that this change was done intentionally; so I have to assume there would be a reason for that. Please can you clarify?

Btw, the attached patch doesn't fix the problem for Jordi (Mac). Maybe we're talking about two separate bugs after all.

Signature · 4 lines
Robert Millan

My spam trap is [email protected].  Note: this address is only intended
for spam harvesters.  Writing to it will get you added to my black list.

Index: kern/powerpc/ieee1275/init.c
===================================================================
RCS file: /sources/grub/grub2/kern/powerpc/ieee1275/init.c,v retrieving revision 1.31

powerpc/ieee1275/init.c +8 -2
diff -u -r1.31 init.c
@@ -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;
   }
 
#8 lore raw

Re: memory management issue (Re: another regression on Efika)

Quoted 33 lines · Robert Millan
Quoted 17 lines · Robert Millan
Quoted 9 lines · Hollis Blanchard
Quoted 9 lines
Quoted 5 lines

In short, whatever is causing these crashes is not only an Efika issue. I suspect Apple, or Apple powerbooks at least, are also affected. I got Sjoerd to try this on his powerbook, and he confirms this fixes for him. Paul also tried, with the same results. Not all the powerbooks are the very same model, there are different model revisions involved.

The error Jordi was seeing before reverting your commits was very similar to what I get on my Efika (something like "claim failed").

Quoted 6 lines
Quoted 1 line

Hollis, do you still think this is a firmware bug?

Could somebody please debug it and report back if it is really a GRUB issue? It could be as simple as adjusting the link address, or it could mean instrumenting grub_available_iterate() and checking that output with the contents of /memory/available.

Quoted 5 lines

It turns out that grub_claim_heap() was asked to claim a region that starts after the heap limit. The start address (0x19111e4) is correctly obtained from /memory/available.

Should heap limit be increased?

The attached patch fixes the problem for Efika, although I'm not 1:1 sure of its correctness.

It seems to me that heaplimit is meant to be used as a relative offset, not as an absolute memory address. This makes the current code fail when the start address in /memory/available is higher than heaplimit, and I don't think there's anything that can grant us this won't happen. From this POV, it's clear that moving from relative to absolute address is wrong.

Quoted 6 lines

OTOH, your commit indicates (as per variable names, etc) that this change was done intentionally; so I have to assume there would be a reason for that. Please can you clarify?

Btw, the attached patch doesn't fix the problem for Jordi (Mac). Maybe we're talking about two separate bugs after all.

I was indeed trying to make it absolute. GRUB is linked at 0x10000, or 64KB. Add in all the modules and you still are only using a couple hundred KB.

I don't remember *why* I was trying to make it absolute; I'm sure it was to fix a problem (rather than I was bored). If we could get away from this anachronistic Changelog crap, the commit message would have told us exactly what we need to know.

I *think* it was because we have a relocation problem with OSes that are linked at 4MB, which is the case with Xen (and I believe yaboot). If GRUB is using that memory, we simply can't load anything there.

I think we can add some somewhat-special-case logic that says if there is nothing available below HEAP_LIMIT, claim something beginning as low as we can. That reduces functionality on such platforms (as described above), but there's little we can do about that unless firmware is fixed.

My big question is this: why is Efika firmware saying that 0x19111e4 (around 25MB) is the first available address?

BTW, does Jordi have any details on this Mac problem?

-Hollis

#9 lore raw

Re: memory management issue (Re: another regression on Efika)

Quoted 4 lines · Hollis Blanchard

I was indeed trying to make it absolute. GRUB is linked at 0x10000, or 64KB. Add in all the modules and you still are only using a couple hundred KB.

But if GRUB is linked at 0x10000, how come the firmware loads it since that's below the 0x19111e4 limit? (or am I missing some physical vs logical issue here?)

Quoted 4 lines

I don't remember *why* I was trying to make it absolute; I'm sure it was to fix a problem (rather than I was bored). If we could get away from this anachronistic Changelog crap, the commit message would have told us exactly what we need to know.

I pasted the ChangeLog entries in an earlier mail. Do you mean the CVS commit message might have more information?

Quoted 9 lines

I *think* it was because we have a relocation problem with OSes that are linked at 4MB, which is the case with Xen (and I believe yaboot). If GRUB is using that memory, we simply can't load anything there.

I think we can add some somewhat-special-case logic that says if there is nothing available below HEAP_LIMIT, claim something beginning as low as we can. That reduces functionality on such platforms (as described above), but there's little we can do about that unless firmware is fixed.

So the purpose of HEAP_LIMIT is to support code that is linked at fixed addresses?

Quoted 2 lines

My big question is this: why is Efika firmware saying that 0x19111e4 (around 25MB) is the first available address?

What is wrong with that? Is it general practice that all firmwares load at low addresses so that non-relocatable code can be linked at 4MB or such?

Quoted 1 line

BTW, does Jordi have any details on this Mac problem?

He said that after appliing the patch that makes heaplimit a relative address it still won't work. /memory/available:

00003000 0000d000 0002d000 007d3000 00848000 1f3b8000

I'm CCing him.

Signature · 4 lines
Robert Millan

My spam trap is [email protected].  Note: this address is only intended
for spam harvesters.  Writing to it will get you added to my black list.
#10 lore raw

Re: memory management issue (Re: another regression on Efika)

Quoted 9 lines · Robert Millan
Quoted 4 lines · Hollis Blanchard

I was indeed trying to make it absolute. GRUB is linked at 0x10000, or 64KB. Add in all the modules and you still are only using a couple hundred KB.

But if GRUB is linked at 0x10000, how come the firmware loads it since that's below the 0x19111e4 limit? (or am I missing some physical vs logical issue here?)

No, you are correct; obviously firmware is doing something wrong. The question is can we accommodate it, and if so, how?

Quoted 7 lines
Quoted 4 lines

I don't remember *why* I was trying to make it absolute; I'm sure it was to fix a problem (rather than I was bored). If we could get away from this anachronistic Changelog crap, the commit message would have told us exactly what we need to know.

I pasted the ChangeLog entries in an earlier mail. Do you mean the CVS commit message might have more information?

I mean if this were any other project I participate in, I would have explicitly spelled out why the commit was done.

Quoted 4 lines
Quoted 4 lines

I *think* it was because we have a relocation problem with OSes that are linked at 4MB, which is the case with Xen (and I believe yaboot). If GRUB is using that memory, we simply can't load anything there.

Quoted 8 lines
Quoted 5 lines

I think we can add some somewhat-special-case logic that says if there is nothing available below HEAP_LIMIT, claim something beginning as low as we can. That reduces functionality on such platforms (as described above), but there's little we can do about that unless firmware is fixed.

So the purpose of HEAP_LIMIT is to support code that is linked at fixed addresses?

Yes. This includes yaboot, Xen, and Linux zImages. I think zImages relocate themselves no matter where they were loaded though.

Quoted 5 lines
Quoted 2 lines

My big question is this: why is Efika firmware saying that 0x19111e4 (around 25MB) is the first available address?

What is wrong with that? Is it general practice that all firmwares load at low addresses so that non-relocatable code can be linked at 4MB or such?

Not at all. IBM pSeries firmwares load at a default of 12MB, and I've seen others that load at the top of RAM to stay out of the way.

It's clear that Efika firmware isn't *really* using all memory below 25MB; we know this because we managed to load grub there. This undoubtedly an Efika firmware bug, but as I described earlier I think we can devise another workaround for it without hurting the common case.

-Hollis

#11 lore raw

Re: memory management issue (Re: another regression on Efika)

Quoted 15 lines · Hollis Blanchard
Quoted 10 lines · Robert Millan
Quoted 4 lines · Hollis Blanchard

I was indeed trying to make it absolute. GRUB is linked at 0x10000, or 64KB. Add in all the modules and you still are only using a couple hundred KB.

But if GRUB is linked at 0x10000, how come the firmware loads it since that's below the 0x19111e4 limit? (or am I missing some physical vs logical
issue here?)

No, you are correct; obviously firmware is doing something wrong. The question is can we accommodate it, and if so, how?

Quoted 6 lines

[...]

25MB; we know this because we managed to load grub there. This undoubtedly an Efika firmware bug, but as I described earlier I think we can devise another workaround for it without hurting the common case.

I contacted Sven Luther (CCed) about it. This is what he said:

17:19 <svenl> nyu: this is another not really bug but ugly feature of the efika firmware, not present in the pegasos branch. 17:19 <svenl> the problem is that the graphic memory is mapped at the start, and the firmware is located from 16MB to 24MB or so, maybe a bit more with the
stack.
17:20 <svenl> normally; the area between 0 and 16MB, except for the interrupt vectors, should be available.

So we could do as you suggested before, and only claim memory below heaplimit when possible, or we could register the area between end of grub image and 16MB as claimed. That is, assuming 0x1000000 (or whatever the exact address is) is exactly the last unused address in that region.

Though, the idea of registering an area as claimed without telling the firmware about it sounds like a no-no to me. What do you think? Is it really worth it?

Signature · 4 lines
Robert Millan

My spam trap is [email protected].  Note: this address is only intended
for spam harvesters.  Writing to it will get you added to my black list.

A message that is not in the archive (sent off-list or not yet received): [email protected]

#13 lore raw

Re: memory management issue (Re: another regression on Efika)

Forwarding reply from Sven since he wasn't subscribed when it was sent.

Quoted 29 lines · Sven Luther

The efika has 128MB of builtin memory, and we know that everything above 24MB except a little heap at the top is free, so this should be enough for everyone, no ?

The 0 to 16MB area is also free normally, and the pre-powerpc kernel loaded themselves at 4 or 8 MB, and relocate the kernel at 0.

Using the 16MB to 24MB area is a big no-no though, since it would kill the firmware.

The efika/pegasos firmware is not able to relocate itself dynamically, and as it reserves the first 256MB (1 BAT area), but it could be used with a 128 MB (like the efika) or smaller memory DIMM, so it cannot reside on the top area of ram where it belongs.

There is a small stack going down from min(top-of-memory,256MB) of a couple MB though.

The efika/pegasos firmware furthermore runs in physical memory, and cannot switch to virtual memory.

Hope this helps, altough obviously i can make no prediction about future efika firmwares.

Friendly,

Sven Luther

Signature · 4 lines
Robert Millan

My spam trap is [email protected].  Note: this address is only intended
for spam harvesters.  Writing to it will get you added to my black list.
#14 lore raw

Re: memory management issue (Re: another regression on Efika)

Hi Sven,

I have a pair of questions about the memory issue..

Quoted 1 line

17:19 <svenl> nyu: this is another not really bug but ugly feature of the efika firmware, not present in the pegasos branch.

We need to detect if we're running on an affected system somehow. Does the SmartFirmware version number (1.3 here) completely reflect wether the problem is present, or do we need to check /openprom/model too?

Quoted 2 lines

17:19 <svenl> the problem is that the graphic memory is mapped at the start, and the firmware is located from 16MB to 24MB or so, maybe a bit more with stack. 17:20 <svenl> normally; the area between 0 and 16MB, except for the interrupt vectors, should be available.

I'm not sure how big is the interrupt vector, but since we succesfuly loaded GRUB at 0x10000, I think it's safe to assume that as the lower bound. As for the higher bound, is 0x1000000 exactly it, or was that a rough estimate?

Signature · 4 lines
Robert Millan

My spam trap is [email protected].  Note: this address is only intended
for spam harvesters.  Writing to it will get you added to my black list.
#15 lore raw

PATCH 1/1 efika memory issues

Quoted 6 lines · Robert Millan

Hi Sven,

I have a pair of questions about the memory issue..

[...]

Ok, after some discussion on IRC, and invaluable help by Sven in documenting smartfirmware behaviour, I came up with this patch.

Please let me know what you think. If there are no objections I'll check it in in a few days.

2007-07-30 Robert Millan <[email protected]>

* include/grub/ieee1275/ieee1275.h (grub_ieee1275_flag): Add GRUB_IEEE1275_FLAG_EFIKA_SECRET_AVAILABLE_REGION flag.
* kern/powerpc/ieee1275/cmain.c (grub_ieee1275_find_options): Set GRUB_IEEE1275_FLAG_EFIKA_SECRET_AVAILABLE_REGION flag when running on an Efika (SmartFirmware).
* kern/powerpc/ieee1275/init.c (grub_claim_heap): Fail gracefuly when addr > heaplimit.
Use grub_printf instead of grub_error for error reporting, since grub_error doesn't work at this point of execution.
When GRUB_IEEE1275_FLAG_EFIKA_SECRET_AVAILABLE_REGION was set, release hardcoded 0x4000:0xffc000 region.

Signature · 4 lines
Robert Millan

My spam trap is [email protected].  Note: this address is only intended
for spam harvesters.  Writing to it will get you added to my black list.

2007-07-30 Robert Millan <[email protected]>

* include/grub/ieee1275/ieee1275.h (grub_ieee1275_flag): Add GRUB_IEEE1275_FLAG_EFIKA_SECRET_AVAILABLE_REGION flag.
* kern/powerpc/ieee1275/cmain.c (grub_ieee1275_find_options): Set GRUB_IEEE1275_FLAG_EFIKA_SECRET_AVAILABLE_REGION flag when running on an Efika (SmartFirmware).
* kern/powerpc/ieee1275/init.c (grub_claim_heap): Fail gracefuly when addr > heaplimit.
Use grub_printf instead of grub_error for error reporting, since grub_error doesn't work at this point of execution.
When GRUB_IEEE1275_FLAG_EFIKA_SECRET_AVAILABLE_REGION was set, release hardcoded 0x4000:0xffc000 region.

Index: include/grub/ieee1275/ieee1275.h
===================================================================
RCS file: /sources/grub/grub2/include/grub/ieee1275/ieee1275.h,v retrieving revision 1.7

grub/ieee1275/ieee1275.h +4 -0
diff -u -r1.7 ieee1275.h
@@ -82,6 +82,10 @@
 
   /* CodeGen firmware does not correctly implement "output-device output" */
   GRUB_IEEE1275_FLAG_BROKEN_OUTPUT,
+
+  /* Efika version of CodeGen firmware has an available memory region that
+     is not represented in /memory/available.  */
+  GRUB_IEEE1275_FLAG_EFIKA_SECRET_AVAILABLE_REGION,
 };
 
 extern int EXPORT_FUNC(grub_ieee1275_test_flag) (enum grub_ieee1275_flag flag);

Index: kern/powerpc/ieee1275/cmain.c
===================================================================
RCS file: /sources/grub/grub2/kern/powerpc/ieee1275/cmain.c,v retrieving revision 1.9

powerpc/ieee1275/cmain.c +5 -0
diff -u -r1.9 cmain.c
@@ -63,9 +63,14 @@
   rc = grub_ieee1275_get_property (openprom, "SmartFirmware-version", 0, 0, 0);
   if (rc >= 0)
     {
+      char model[32];
       grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_NO_PARTITION_0);
       grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_0_BASED_PARTITIONS);
       grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_BROKEN_OUTPUT);
+
+      rc = grub_ieee1275_get_property (openprom, "model", &model, sizeof model, 0);
+      if ((rc >= 0) && !grub_strncmp (model, "EFIKA", 5))
+	grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_EFIKA_SECRET_AVAILABLE_REGION);
     }
 }
 

Index: kern/powerpc/ieee1275/init.c
===================================================================
RCS file: /sources/grub/grub2/kern/powerpc/ieee1275/init.c,v retrieving revision 1.31

powerpc/ieee1275/init.c +13 -3
diff -u -r1.31 init.c
@@ -121,6 +121,12 @@
     len -= 1; /* Required for some firmware.  */
 
     /* Don't claim anything above `heaplimit'.  */
+    if (addr > heaplimit)
+      {
+        grub_printf ("Cannot claim heap above limit (0x%llx > 0x%lx)\n", addr, heaplimit);
+        return GRUB_ERR_OUT_OF_MEMORY;
+      }
+
     if (addr + len > heaplimit)
       len = heaplimit - addr;
 
@@ -128,15 +134,19 @@
       {
 	/* Claim and use it.  */
 	if (grub_claimmap (addr, len) < 0)
-	  return grub_error (GRUB_ERR_OUT_OF_MEMORY,
-			     "Failed to claim heap at 0x%llx, len 0x%llx\n",
-			     addr, len);
+	  {
+	    grub_printf ("Failed to claim heap at 0x%llx, len 0x%llx\n", addr, len);
+	    return GRUB_ERR_OUT_OF_MEMORY;
+	  }
 	grub_mm_init_region ((void *) (grub_addr_t) addr, len);
       }
 
     return 0;
   }
 
+  if (grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_EFIKA_SECRET_AVAILABLE_REGION));
+    grub_ieee1275_release (0x4000, 0xffc000);
+
   grub_available_iterate (heap_init);
 }
 
#16 lore raw

Re: [PATCH] efika memory issues

Quoted 16 lines · Robert Millan
Quoted 6 lines · Robert Millan

Hi Sven,

I have a pair of questions about the memory issue..

[...]

Ok, after some discussion on IRC, and invaluable help by Sven in documenting smartfirmware behaviour, I came up with this patch.

Please let me know what you think. If there are no objections I'll check it in in a few days.

2007-07-30 Robert Millan <[email protected]>

Quoted 11 lines

* include/grub/ieee1275/ieee1275.h (grub_ieee1275_flag): Add GRUB_IEEE1275_FLAG_EFIKA_SECRET_AVAILABLE_REGION flag.
* kern/powerpc/ieee1275/cmain.c (grub_ieee1275_find_options): Set GRUB_IEEE1275_FLAG_EFIKA_SECRET_AVAILABLE_REGION flag when running on an Efika (SmartFirmware).
* kern/powerpc/ieee1275/init.c (grub_claim_heap): Fail gracefuly when addr > heaplimit.
Use grub_printf instead of grub_error for error reporting, since grub_error doesn't work at this point of execution.
When GRUB_IEEE1275_FLAG_EFIKA_SECRET_AVAILABLE_REGION was set, release hardcoded 0x4000:0xffc000 region.

Hmm, does this actually work? Since GRUB itself falls within that regions, the grub_ieee1275_release() call will mark all the memory that the GRUB kernel and modules occupy as free, which means they will be clobbered by heap usage.

-Hollis

#17 lore raw

Re: [PATCH] efika memory issues

Quoted 7 lines · Hollis Blanchard
Quoted 2 lines

When GRUB_IEEE1275_FLAG_EFIKA_SECRET_AVAILABLE_REGION was set, release hardcoded 0x4000:0xffc000 region.

Hmm, does this actually work? Since GRUB itself falls within that regions, the grub_ieee1275_release() call will mark all the memory that the GRUB kernel and modules occupy as free, which means they will be clobbered by heap usage.

Didn't think of this.. (by chance it worked here, though). How about using max(_end,0x4000) instead of 0x4000 ?

(and adjusting region length not to overflow 0x1000000)

Signature · 4 lines
Robert Millan

My spam trap is [email protected].  Note: this address is only intended
for spam harvesters.  Writing to it will get you added to my black list.
#18 lore raw

Re: [PATCH] efika memory issues

Quoted 9 lines · Robert Millan
Quoted 7 lines · Hollis Blanchard
Quoted 2 lines

When GRUB_IEEE1275_FLAG_EFIKA_SECRET_AVAILABLE_REGION was set, release hardcoded 0x4000:0xffc000 region.

Hmm, does this actually work? Since GRUB itself falls within that regions, the grub_ieee1275_release() call will mark all the memory that the GRUB kernel and modules occupy as free, which means they will be clobbered by heap usage.

Quoted 4 lines

Didn't think of this.. (by chance it worked here, though). How about using max(_end,0x4000) instead of 0x4000 ?

(and adjusting region length not to overflow 0x1000000)

That won't quite work because the modules are loaded in the area immediately following the kernel. However, because they are added in a post-processing step, we don't know their end address at link time.

I think the simplest solution will be to allocate Efika's heap high, as we talked about earlier. If the first "available" region is above 4MB, just reserve 4MB and don't worry about where it is. In general we should try to keep 4MB free, but at the end of the day it's Efika's fault and probably won't be a big deal for them anyways.

-Hollis

#19 lore raw

Re: [PATCH] efika memory issues

Quoted 19 lines · Hollis Blanchard
Quoted 9 lines · Robert Millan
Quoted 7 lines · Hollis Blanchard
Quoted 2 lines

When GRUB_IEEE1275_FLAG_EFIKA_SECRET_AVAILABLE_REGION was set, release hardcoded 0x4000:0xffc000 region.

Hmm, does this actually work? Since GRUB itself falls within that regions, the grub_ieee1275_release() call will mark all the memory that the GRUB kernel and modules occupy as free, which means they will be clobbered by heap usage.

Quoted 4 lines

Didn't think of this.. (by chance it worked here, though). How about using max(_end,0x4000) instead of 0x4000 ?

(and adjusting region length not to overflow 0x1000000)

That won't quite work because the modules are loaded in the area immediately following the kernel. However, because they are added in a post-processing step, we don't know their end address at link time.

Quoted 5 lines

I think the simplest solution will be to allocate Efika's heap high, as we talked about earlier. If the first "available" region is above 4MB, just reserve 4MB and don't worry about where it is. In general we should try to keep 4MB free, but at the end of the day it's Efika's fault and probably won't be a big deal for them anyways.

Ok, let's do that. But what do we do if the first available region is just a few kBs below 4MB? Or if it's just too small? I think we need to determine what is the minimum heap size we want to accept, such that the ability to keep 4MB free still compensates having a small heap.

Any suggestion?

Signature · 4 lines
Robert Millan

My spam trap is [email protected].  Note: this address is only intended
for spam harvesters.  Writing to it will get you added to my black list.
#20 lore raw

Re: [PATCH] efika memory issues

Quoted 7 lines · Robert Millan
Quoted 5 lines · Hollis Blanchard

I think the simplest solution will be to allocate Efika's heap high, as we talked about earlier. If the first "available" region is above 4MB, just reserve 4MB and don't worry about where it is. In general we should try to keep 4MB free, but at the end of the day it's Efika's fault and probably won't be a big deal for them anyways.

Quoted 6 lines

Ok, let's do that. But what do we do if the first available region is just a few kBs below 4MB? Or if it's just too small? I think we need to determine what is the minimum heap size we want to accept, such that the ability to keep 4MB free still compensates having a small heap.

Any suggestion?

Yup, it's a pain. Here's one idea: set a "GET_HEAP_FROM_WHEREVER" flag, then later do

  if (GET_HEAP_FROM_WHEREVER) {
    grub_addr_t heap_addr;
    grub_ieee1275_claim(0, MIN_HEAP_SIZE, 4, &heap_addr);

}

That will ask firmware to find us a suitable area of memory.and return the address. It might even work.

We could try doing that in all situations, except:
- this method isn't often used, so firmwares can have bugs here
- if MIN_HEAP_SIZE were small enough (e.g. 2MB), it would mean we probably would still have 4MB+ free. However, that depends on the size of the modules. I would hate to document "oh, if you can't load your OS, try using fewer GRUB modules." On the other hand, we already have this problem to some extent: if our modules are too large, we will fail to allocate any heap. So maybe this isn't a practical concern.

-Hollis

#21 lore raw

Re: [PATCH] efika memory issues

Quoted 3 lines · Hollis Blanchard

Yup, it's a pain. Here's one idea: set a "GET_HEAP_FROM_WHEREVER" flag, then later do

Why a flag? Don't we want to do this unconditionally? MIN_HEAP_SIZE already determines wether it's appropiate or not.

Quoted 2 lines

We could try doing that in all situations, except:
- this method isn't often used, so firmwares can have bugs here

Our code already implements most of this (in grub_available_iterate). Why not doing it ourselves instead of reliing on potentially-broken firmware?

Quoted 6 lines

- if MIN_HEAP_SIZE were small enough (e.g. 2MB), it would mean we probably would still have 4MB+ free. However, that depends on the size of the modules. I would hate to document "oh, if you can't load your OS, try using fewer GRUB modules." On the other hand, we already have this problem to some extent: if our modules are too large, we will fail to allocate any heap. So maybe this isn't a practical concern.

Yep, the problem already exists. In the end, it's just a matter of which MIN_HEAP_SIZE do we pick.

Signature · 4 lines
Robert Millan

My spam trap is [email protected].  Note: this address is only intended
for spam harvesters.  Writing to it will get you added to my black list.
#22 lore raw

PATCH 1/1 fix memory management on efika/pegasos

Finally, I think I got this right now. My efika boots and all the other setups should be happy as well. Please, review/test this and report.

Signature · 5 lines
Robert Millan

<GPLv2> I know my rights; I want my phone call!
<DRM> What use is a phone call, if you are unable to speak?
(as seen on /.)

2007-09-30 Robert Millan <[email protected]>

* kern/powerpc/ieee1275/init.c: Rename HEAP_LIMIT to HEAP_MAX_ADDR, and make it easier to figure out.
Add HEAP_MIN_SIZE and HEAP_MAX_ADDR definitions. (grub_claim_heap): Use HEAP_MAX_ADDR rather than taking a parameter. Do not avoid claiming a region above HEAP_MAX_ADDR if that would leave us with less than HEAP_MIN_SIZE total heap.
Avoid our total amount of heap to surpass HEAP_MAX_SIZE.

kern/powerpc/ieee1275/init.c +26 -6
diff -ur grub2/kern/powerpc/ieee1275/init.c grub2.efika/kern/powerpc/ieee1275/init.c
@@ -33,7 +33,15 @@
 #include <grub/ieee1275/ofdisk.h>
 #include <grub/ieee1275/ieee1275.h>
 
-#define HEAP_LIMIT (4<<20) /* 4 MiB */
+/* The minimal heap size we can live with. */
+#define HEAP_MIN_SIZE		(unsigned long) (2 * 1024 * 1024)
+
+/* The maximum heap size we're going to claim */
+#define HEAP_MAX_SIZE		(unsigned long) (4 * 1024 * 1024)
+
+/* If possible, we will avoid claiming heap above this address, because it
+   seems to cause relocation problems with OSes that link at 4 MiB */
+#define HEAP_MAX_ADDR		(unsigned long) (4 * 1024 * 1024)
 
 extern char _start[];
 extern char _end[];
@@ -113,16 +121,24 @@
 }
 
 /* Claim some available memory in the first /memory node. */
-static void grub_claim_heap (unsigned long heaplimit)
+static void grub_claim_heap ()
 {
+  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;
+    /* Never exceed HEAP_MAX_SIZE  */
+    if (total + len > HEAP_MAX_SIZE)
+      len = HEAP_MAX_SIZE - total;
+
+    /* Avoid claiming anything above HEAP_MAX_ADDR, if possible. */
+    if ((addr < HEAP_MAX_ADDR) &&				/* if it's too late, don't bother */
+        (addr + len > HEAP_MAX_ADDR) &&				/* if it wasn't available anyway, don't bother */
+        (total + (HEAP_MAX_ADDR - addr) > HEAP_MIN_SIZE))	/* only limit ourselves when we can afford to */
+       len = HEAP_MAX_ADDR - addr;
 
     if (len)
       {
@@ -134,6 +150,10 @@
 	grub_mm_init_region ((void *) (grub_addr_t) addr, len);
       }
 
+    total += len;
+    if (total >= HEAP_MAX_SIZE)
+      return 1;
+
     return 0;
   }
 
@@ -147,7 +167,7 @@
   int actual;
 
   grub_console_init ();
-  grub_claim_heap (HEAP_LIMIT);
+  grub_claim_heap ();
   grub_ofdisk_init ();
 
   /* Process commandline.  */
#23 lore raw

Re: [PATCH] fix memory management on efika/pegasos

Hell[o]

Quoted 2 lines

Finally, I think I got this right now. My efika boots and all the other setups should be happy as well. Please, review/test this and report.

Tested on ODW && Efika, works fine in both cases.

Signature · 1 line
--- Marcin 'Morgoth' Kurek ---
#24 lore raw

Re: [PATCH] fix memory management on efika/pegasos

In reply to Robert Millan

Hell[o]

Quoted 1 line

[...]

I just checked cvs grub2 with this patch on older version of pegasos firmware (1.2 - 20040810) and it seems to fail with out of memory message.

Then it seems to fix problem for efika and for latest version of pegasos firmware.

Signature · 1 line
--- Marcin 'Morgoth' Kurek ---
#25 lore raw

Re: [PATCH] fix memory management on efika/pegasos

Quoted 7 lines · Marcin Kurek

Hell[o]

Quoted 1 line

[...]

I just checked cvs grub2 with this patch on older version of pegasos firmware (1.2 - 20040810) and it seems to fail with out of memory message.

What happens if you increase HEAP_MIN_SIZE ?

Signature · 5 lines
Robert Millan

<GPLv2> I know my rights; I want my phone call!
<DRM> What use is a phone call, if you are unable to speak?
(as seen on /.)
#26 lore raw

Re: [PATCH] fix memory management on efika/pegasos

Hell[o]

Quoted 1 line

What happens if you increase HEAP_MIN_SIZE ?

Still fails I am affraid. I wonder is there any reason to use only first 4MB for heap ? I guess higer memory areas can be still accessed excluding 4-16 MB ?

I attached my proposed patch to solve this problem. It tires to allocate 4MB heap at fixed position at 28MB (To avoid problems with relocation later on) and if it fails use the grub_available_iterate() as before. If should be used with ealier patch from this thread. I tested it on Pegasos 1 (Only one machine), Pegasos 2 (With few OF revisions starting from 2004 to 2006) and efika and it works quite well.

Signature · 1 line
--- Marcin 'Morgoth' Kurek ---
kern/powerpc/ieee1275/init.c +16 -1
diff -urN grub2.org/kern/powerpc/ieee1275/init.c grub2/kern/powerpc/ieee1275/init.c
@@ -34,7 +34,7 @@
 #include <grub/ieee1275/ieee1275.h>
 
 /* The minimal heap size we can live with. */
-#define HEAP_MIN_SIZE		(unsigned long) (2 * 1024 * 1024)
+#define HEAP_MIN_SIZE		(unsigned long) (3 * 1024 * 1024)
 
 /* The maximum heap size we're going to claim */
 #define HEAP_MAX_SIZE		(unsigned long) (4 * 1024 * 1024)
@@ -43,6 +43,11 @@
    seems to cause relocation problems with OSes that link at 4 MiB */
 #define HEAP_MAX_ADDR		(unsigned long) (4 * 1024 * 1024)
 
+/* Try to claim heap from static address before use grub_available_iterate
+   to help broken firmwares. */
+#define HEAP_STATIC_SIZE	(unsigned long) (4 * 1024 * 1024)
+#define HEAP_STATIC_ADDR	(unsigned long) (28 * 1024 * 1024)
+
 extern char _start[];
 extern char _end[];
 
@@ -157,6 +162,16 @@
     return 0;
   }
 
+  /* Firmware not always mark our executable as claimed */
+  grub_ieee1275_claim ((unsigned long) _start, _end - _start, 0, 0);
+
+  /* Try with static heap addr first */
+  if (grub_claimmap (HEAP_STATIC_ADDR, HEAP_STATIC_SIZE) == 0)
+    {
+      grub_mm_init_region ((void *) (grub_addr_t) HEAP_STATIC_ADDR, HEAP_STATIC_SIZE);
+      return;
+    }
+
   grub_available_iterate (heap_init);
 }
 
#27 lore raw

Re: [PATCH] fix memory management on efika/pegasos

Quoted 8 lines · Marcin Kurek

Hell[o]

Quoted 1 line

What happens if you increase HEAP_MIN_SIZE ?

Still fails I am affraid. I wonder is there any reason to use only first 4MB for heap ? I guess higer memory areas can be still accessed excluding 4-16 MB ?

Quoted 7 lines

I attached my proposed patch to solve this problem. It tires to allocate 4MB heap at fixed position at 28MB (To avoid problems with relocation later on) and if it fails use the grub_available_iterate() as before. If should be used with ealier patch from this thread. I tested it on Pegasos 1 (Only one machine), Pegasos 2 (With few OF revisions starting from 2004 to 2006) and efika and it works quite well.

Doesn't sound correct to me. It seems like a workaround for a bug that we don't know exactly what it is.

Why does it still fail if you increase HEAP_MIN_SIZE ? Is there any value big enough that makes it work ? Does it still fail with the same error? (not enough memory). Was _any_ region claimed at all by our code?

Signature · 5 lines
Robert Millan

<GPLv2> I know my rights; I want my phone call!
<DRM> What use is a phone call, if you are unable to speak?
(as seen on /.)
#28 lore raw

OF disk naming scheme (Re: another regression on Efika)

In reply to Jordi Mallach
Quoted 8 lines · Jordi Mallach

The biggest issue now is that we all had to fix our generated configurations, as grub-probe and update-grub won't cope with a device.map that looks like this:

(hd) /dev/hda

This is a minor issue that I can fix by hand, luckily.

What naming/numbering scheme does this follow when you add more disks?

Signature · 4 lines
Robert Millan

My spam trap is [email protected].  Note: this address is only intended
for spam harvesters.  Writing to it will get you added to my black list.
#29 lore raw

Re: OF disk naming scheme (Re: another regression on Efika)

Quoted 1 line · Robert Millan

What naming/numbering scheme does this follow when you add more disks?

hd, hd1, hd2. Luckily Mozillion has Firewire disks.

Signature · 3 lines
Jordi Mallach Pérez  --  Debian developer     http://www.debian.org/
[email protected]     [email protected]     http://www.sindominio.net/
GnuPG public key information available at http://oskuro.net/
#30 lore raw

Re: OF disk naming scheme (Re: another regression on Efika)

Quoted 4 lines · Jordi Mallach
Quoted 1 line · Robert Millan

What naming/numbering scheme does this follow when you add more disks?

hd, hd1, hd2. Luckily Mozillion has Firewire disks.

My Efika counts: hd, hd0 ...

IEEE 1275 does not seem to cover this. What scheme should we follow when generating device.map ?

Signature · 4 lines
Robert Millan

My spam trap is [email protected].  Note: this address is only intended
for spam harvesters.  Writing to it will get you added to my black list.
#31 lore raw

Re: OF disk naming scheme (Re: another regression on Efika)

Quoted 10 lines · Robert Millan
Quoted 4 lines · Jordi Mallach
Quoted 1 line · Robert Millan

What naming/numbering scheme does this follow when you add more disks?

hd, hd1, hd2. Luckily Mozillion has Firewire disks.

My Efika counts: hd, hd0 ...

IEEE 1275 does not seem to cover this. What scheme should we follow when generating device.map ?

Since "hd, hd1, hd2 ..." seems to be much more common, I propose we use that and let user override it via device.map in case of disparity (which may only happen in systems with more than 1 disk).

See attached patch.

Signature · 4 lines
Robert Millan

My spam trap is [email protected].  Note: this address is only intended
for spam harvesters.  Writing to it will get you added to my black list.
conf/i386-efi.rmk +2 -1
diff -Nur grub2/conf/i386-efi.rmk grub2.new/conf/i386-efi.rmk
@@ -24,7 +24,8 @@
 #	kern/fs.c kern/env.c fs/fshelp.c
 
 # For grub-mkdevicemap.
-grub_mkdevicemap_SOURCES = util/grub-mkdevicemap.c util/misc.c
+grub_mkdevicemap_SOURCES = util/grub-mkdevicemap.c util/misc.c		\
+	util/i386/get_disk_name.c
 
 # For grub-probe.
 grub_probe_SOURCES = util/grub-probe.c	\
conf/i386-pc.rmk +2 -1
diff -Nur grub2/conf/i386-pc.rmk grub2.new/conf/i386-pc.rmk
@@ -71,7 +71,8 @@
 	util/raid.c util/lvm.c
 
 # For grub-mkdevicemap.
-grub_mkdevicemap_SOURCES = util/grub-mkdevicemap.c util/misc.c
+grub_mkdevicemap_SOURCES = util/grub-mkdevicemap.c util/misc.c		\
+	util/i386/get_disk_name.c
 
 # For grub-probe.
 grub_probe_SOURCES = util/grub-probe.c	\
conf/powerpc-ieee1275.rmk +2 -1
diff -Nur grub2/conf/powerpc-ieee1275.rmk grub2.new/conf/powerpc-ieee1275.rmk
@@ -36,7 +36,8 @@
         util/resolve.c 
 
 # For grub-mkdevicemap.
-grub_mkdevicemap_SOURCES = util/grub-mkdevicemap.c util/misc.c
+grub_mkdevicemap_SOURCES = util/grub-mkdevicemap.c util/misc.c		\
+	util/ieee1275/get_disk_name.c
 
 # For grub-probe.
 grub_probe_SOURCES = util/grub-probe.c	\
include/grub/util/misc.h +1 -0
diff -Nur grub2/include/grub/util/misc.h grub2.new/include/grub/util/misc.h
@@ -53,5 +53,6 @@
 void grub_util_write_image (const char *img, size_t size, FILE *out);
 void grub_util_write_image_at (const void *img, size_t size, off_t offset,
 			       FILE *out);
+char *grub_util_get_disk_name (int disk);
 
 #endif /* ! GRUB_UTIL_MISC_HEADER */
util/grub-mkdevicemap.c +24 -6
diff -Nur grub2/util/grub-mkdevicemap.c grub2.new/util/grub-mkdevicemap.c
@@ -402,8 +402,11 @@
 	  
 	  if (realpath (discn, name))
 	    {
+	      char *p;
 	      strcat (name, "/disc");
-	      fprintf (fp, "(hd%d)\t%s\n", num_hd, name);
+	      p = grub_util_get_disk_name (num_hd);
+	      fprintf (fp, "(%s)\t%s\n", p, name);
+	      free (p);
 	    }
 	  
 	  num_hd++;
@@ -421,7 +424,10 @@
       get_ide_disk_name (name, i);
       if (check_device (name))
 	{
-	  fprintf (fp, "(hd%d)\t%s\n", num_hd, name);
+	  char *p;
+	  p = grub_util_get_disk_name (num_hd);
+	  fprintf (fp, "(%s)\t%s\n", p, name);
+	  free (p);
 	  num_hd++;
 	}
     }
@@ -435,7 +441,10 @@
       get_ataraid_disk_name (name, i);
       if (check_device (name))
 	{
-	  fprintf (fp, "(hd%d)\t%s\n", num_hd, name);
+	  char *p;
+	  p = grub_util_get_disk_name (num_hd);
+	  fprintf (fp, "(%s)\t%s\n", p, name);
+	  free (p);
           num_hd++;
         }
     }
@@ -449,7 +458,10 @@
       get_scsi_disk_name (name, i);
       if (check_device (name))
 	{
-	  fprintf (fp, "(hd%d)\t%s\n", num_hd, name);
+	  char *p;
+	  p = grub_util_get_disk_name (num_hd);
+	  fprintf (fp, "(%s)\t%s\n", p, name);
+	  free (p);
 	  num_hd++;
 	}
     }
@@ -472,7 +484,10 @@
 	    get_dac960_disk_name (name, controller, drive);
 	    if (check_device (name))
 	      {
-		fprintf (fp, "(hd%d)\t%s\n", num_hd, name);
+		char *p;
+		p = grub_util_get_disk_name (num_hd);
+		fprintf (fp, "(%s)\t%s\n", p, name);
+		free (p);
 		num_hd++;
 	      }
 	  }
@@ -490,7 +505,10 @@
 	get_i2o_disk_name (name, unit);
 	if (check_device (name))
 	  {
-	    fprintf (fp, "(hd%d)\t%s\n", num_hd, name);
+	    char *p;
+	    p = grub_util_get_disk_name (num_hd);
+	    fprintf (fp, "(%s)\t%s\n", p, name);
+	    free (p);
 	    num_hd++;
 	  }
       }
util/i386/get_disk_name.c +31 -0
diff -Nur grub2/util/i386/get_disk_name.c grub2.new/util/i386/get_disk_name.c
@@ -0,0 +1,31 @@
+/* get_disk_name.c */
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 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/util/misc.h>
+
+char *
+grub_util_get_disk_name (int disk)
+{
+  char *p;
+
+  p = xmalloc (16);
+  sprintf (p, "hd%d", disk);
+  
+  return p;
+}
util/ieee1275/get_disk_name.c +36 -0
diff -Nur grub2/util/ieee1275/get_disk_name.c grub2.new/util/ieee1275/get_disk_name.c
@@ -0,0 +1,36 @@
+/* get_disk_name.c */
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 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/util/misc.h>
+
+#include <string.h>
+
+char *
+grub_util_get_disk_name (int disk)
+{
+  char *p;
+
+  p = xmalloc (16);
+  sprintf (p, "hd");
+
+  if (disk > 0)
+    sprintf (p + strlen (p), "%d", disk);
+  
+  return p;
+}
#32 lore raw

Re: OF disk naming scheme (Re: another regression on Efika)

Quoted 7 lines · Robert Millan
Quoted 6 lines · Robert Millan
Quoted 4 lines · Jordi Mallach
Quoted 1 line · Robert Millan

What naming/numbering scheme does this follow when you add more disks?

hd, hd1, hd2. Luckily Mozillion has Firewire disks.

Quoted 8 lines
Quoted 4 lines

My Efika counts: hd, hd0 ...

IEEE 1275 does not seem to cover this. What scheme should we follow when generating device.map ?

Since "hd, hd1, hd2 ..." seems to be much more common, I propose we use that and let user override it via device.map in case of disparity (which may only happen in systems with more than 1 disk).

Can we actually read via /proc or so how this mapping in reality is realised?

--
Marco

#33 lore raw

Re: OF disk naming scheme (Re: another regression on Efika)

Quoted 14 lines · Marco Gerards
Quoted 12 lines · Robert Millan
Quoted 10 lines · Robert Millan
Quoted 4 lines · Jordi Mallach
Quoted 1 line · Robert Millan

What naming/numbering scheme does this follow when you add more disks?

hd, hd1, hd2. Luckily Mozillion has Firewire disks.

My Efika counts: hd, hd0 ...

IEEE 1275 does not seem to cover this. What scheme should we follow when generating device.map ?

Quoted 6 lines
Quoted 3 lines

Since "hd, hd1, hd2 ..." seems to be much more common, I propose we use that and let user override it via device.map in case of disparity (which may only happen in systems with more than 1 disk).

Can we actually read via /proc or so how this mapping in reality is realised?

AFAIK we can only read the full OF path from /proc (with helper tools like ofpath / ofpathname), but not the short alias which grub uses. These can only be obtained when grub is running.

If the proposed solution is not good, maybe we could instead remap all disks to "standard" grub device names (hd0, hd1..), which grub-mkdevicemap already knows how to guess reasonably well.

Signature · 4 lines
Robert Millan

My spam trap is [email protected].  Note: this address is only intended
for spam harvesters.  Writing to it will get you added to my black list.
#34 lore raw

proposed solution using "ofpathname -a" (Re: OF disk naming scheme)

Quoted 8 lines · Robert Millan

AFAIK we can only read the full OF path from /proc (with helper tools like ofpath / ofpathname), but not the short alias which grub uses. These can only be obtained when grub is running.

If the proposed solution is not good, maybe we could instead remap all disks to "standard" grub device names (hd0, hd1..), which grub-mkdevicemap already knows how to guess reasonably well.

Ok, I think I finally managed to make it work the way you wanted. Please see attached patch.

You will also need alias.diff for ofpathname (I've sent it to the author already).

Signature · 5 lines
Robert Millan

<GPLv2> I know my rights; I want my phone call!
<DRM> What use is a phone call, if you are unable to speak?
(as seen on /.)

2007-08-12 Robert Millan <[email protected]>

* util/i386/get_disk_name.c: New. Implement grub_util_get_disk_name() to tell grub-mkdevicemap how to name devices.
* util/ieee1275/get_disk_name.c: Likewise (using "ofpathname -a" feature).

* conf/i386-efi.rmk (grub_mkdevicemap_SOURCES): Add util/i386/get_disk_name.c.
* conf/i386-pc.rmk (grub_mkdevicemap_SOURCES): Likewise.
* conf/powerpc-ieee1275.rmk (grub_mkdevicemap_SOURCES): Add util/ieee1275/get_disk_name.c.

* include/grub/util/misc.h: grub_util_get_disk_name() declaration.

* DISTLIST: Add util/i386/get_disk_name.c and util/ieee1275/get_disk_name.c.

* util/grub-mkdevicemap.c: Replace device naming logic with grub_util_get_disk_name() calls.

conf/i386-efi.rmk +2 -1
diff -Nur grub2/conf/i386-efi.rmk grub2.mkdevicemap/conf/i386-efi.rmk
@@ -24,7 +24,8 @@
 #	kern/fs.c kern/env.c fs/fshelp.c
 
 # For grub-mkdevicemap.
-grub_mkdevicemap_SOURCES = util/grub-mkdevicemap.c util/misc.c
+grub_mkdevicemap_SOURCES = util/grub-mkdevicemap.c util/misc.c		\
+	util/i386/get_disk_name.c
 
 # For grub-probe.
 grub_probe_DEPENDENCIES = grub_probe_init.h
conf/i386-pc.rmk +2 -1
diff -Nur grub2/conf/i386-pc.rmk grub2.mkdevicemap/conf/i386-pc.rmk
@@ -72,7 +72,8 @@
 	util/raid.c util/lvm.c grub_setup_init.c
 
 # For grub-mkdevicemap.
-grub_mkdevicemap_SOURCES = util/grub-mkdevicemap.c util/misc.c
+grub_mkdevicemap_SOURCES = util/grub-mkdevicemap.c util/misc.c		\
+	util/i386/get_disk_name.c
 
 # For grub-probe.
 grub_probe_DEPENDENCIES = grub_probe_init.h
conf/powerpc-ieee1275.rmk +2 -1
diff -Nur grub2/conf/powerpc-ieee1275.rmk grub2.mkdevicemap/conf/powerpc-ieee1275.rmk
@@ -36,7 +36,8 @@
         util/resolve.c 
 
 # For grub-mkdevicemap.
-grub_mkdevicemap_SOURCES = util/grub-mkdevicemap.c util/misc.c
+grub_mkdevicemap_SOURCES = util/grub-mkdevicemap.c util/misc.c		\
+	util/ieee1275/get_disk_name.c
 
 # For grub-probe.
 grub_probe_DEPENDENCIES = grub_probe_init.h
include/grub/util/misc.h +1 -0
diff -Nur grub2/include/grub/util/misc.h grub2.mkdevicemap/include/grub/util/misc.h
@@ -53,5 +53,6 @@
 void grub_util_write_image (const char *img, size_t size, FILE *out);
 void grub_util_write_image_at (const void *img, size_t size, off_t offset,
 			       FILE *out);
+char *grub_util_get_disk_name (int disk, char *name);
 
 #endif /* ! GRUB_UTIL_MISC_HEADER */
util/grub-mkdevicemap.c +24 -6
diff -Nur grub2/util/grub-mkdevicemap.c grub2.mkdevicemap/util/grub-mkdevicemap.c
@@ -402,8 +402,11 @@
 	  
 	  if (realpath (discn, name))
 	    {
+	      char *p;
 	      strcat (name, "/disc");
-	      fprintf (fp, "(hd%d)\t%s\n", num_hd, name);
+	      p = grub_util_get_disk_name (num_hd, name);
+	      fprintf (fp, "(%s)\t%s\n", p, name);
+	      free (p);
 	    }
 	  
 	  num_hd++;
@@ -421,7 +424,10 @@
       get_ide_disk_name (name, i);
       if (check_device (name))
 	{
-	  fprintf (fp, "(hd%d)\t%s\n", num_hd, name);
+	  char *p;
+	  p = grub_util_get_disk_name (num_hd, name);
+	  fprintf (fp, "(%s)\t%s\n", p, name);
+	  free (p);
 	  num_hd++;
 	}
     }
@@ -435,7 +441,10 @@
       get_ataraid_disk_name (name, i);
       if (check_device (name))
 	{
-	  fprintf (fp, "(hd%d)\t%s\n", num_hd, name);
+	  char *p;
+	  p = grub_util_get_disk_name (num_hd, name);
+	  fprintf (fp, "(%s)\t%s\n", p, name);
+	  free (p);
           num_hd++;
         }
     }
@@ -449,7 +458,10 @@
       get_scsi_disk_name (name, i);
       if (check_device (name))
 	{
-	  fprintf (fp, "(hd%d)\t%s\n", num_hd, name);
+	  char *p;
+	  p = grub_util_get_disk_name (num_hd, name);
+	  fprintf (fp, "(%s)\t%s\n", p, name);
+	  free (p);
 	  num_hd++;
 	}
     }
@@ -472,7 +484,10 @@
 	    get_dac960_disk_name (name, controller, drive);
 	    if (check_device (name))
 	      {
-		fprintf (fp, "(hd%d)\t%s\n", num_hd, name);
+		char *p;
+		p = grub_util_get_disk_name (num_hd, name);
+		fprintf (fp, "(%s)\t%s\n", p, name);
+		free (p);
 		num_hd++;
 	      }
 	  }
@@ -490,7 +505,10 @@
 	get_i2o_disk_name (name, unit);
 	if (check_device (name))
 	  {
-	    fprintf (fp, "(hd%d)\t%s\n", num_hd, name);
+	    char *p;
+	    p = grub_util_get_disk_name (num_hd, name);
+	    fprintf (fp, "(%s)\t%s\n", p, name);
+	    free (p);
 	    num_hd++;
 	  }
       }
util/i386/get_disk_name.c +31 -0
diff -Nur grub2/util/i386/get_disk_name.c grub2.mkdevicemap/util/i386/get_disk_name.c
@@ -0,0 +1,31 @@
+/* get_disk_name.c */
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 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/util/misc.h>
+
+char *
+grub_util_get_disk_name (int disk, char *name)
+{
+  char *p;
+
+  p = xmalloc (16);
+  sprintf (p, "hd%d", disk);
+  
+  return p;
+}
util/ieee1275/get_disk_name.c +60 -0

60 lines not on this page · raw message

DISTLIST +2 -0
@@ -285,11 +285,13 @@
 util/grub.d/README
 util/i386/efi/grub-install.in
 util/i386/efi/grub-mkimage.c
+util/i386/get_disk_name.c
 util/i386/pc/grub-install.in
 util/i386/pc/grub-mkimage.c
 util/i386/pc/grub-setup.c
 util/i386/pc/misc.c
 util/i386/pc/grub-mkrescue.in
+util/ieee1275/get_disk_name.c
 util/powerpc/ieee1275/grub-install.in
 util/powerpc/ieee1275/grub-mkimage.c
 util/powerpc/ieee1275/misc.c
ofpathname renamed from ofpathname.orig +15 -1
@@ -27,6 +33,7 @@
     echo "Optional arguments."
     echo "  -l               Convert Open Firmware device pathname to"
     echo "                   logical device name."
+    echo "  -a               Find matching Open Firmware device alias[es]."
     echo "  -q, --quiet      do not report failures, exit quietly"
     echo "  -V, --version    display version information and exit"         
     echo "  -h, --help       display this help information and exit"
@@ -226,7 +234,16 @@
         OF_PATH=$OFPATH:1\\ppc\\bootinfo.txt
     fi
 
-    echo $OF_PATH
+    if [[ $do_alias = "0" ]]; then
+      echo $OF_PATH
+    else
+      (shopt -s nullglob
+       for i in /proc/device-tree/aliases/* ; do
+         if sed -e "s/\x00$//g" $i | grep -qx "$OF_PATH" ; then
+           basename $i
+         fi
+       done)
+    fi
 }
 
 #
@@ -613,10 +638,14 @@
 
 # default: convert logical => OFpath
 do_of2l=0
+# default: do not alias-ize
+do_alias=0
 
 getopt -o "l:Vqh" -l "help,version,quiet" $@ > /dev/null 2>&1
 while [[ -n $1 ]]; do
     case "$1" in
+        -a)             do_alias=1 ;;
+
         -l)             do_of2l=1 
                         DEVNAME_ARG=$2
                         shift ;;
#35 lore raw

updated regression diff (Re: another regression on Efika)

In reply to Robert Millan
Quoted 2 lines · Robert Millan

[...] I'm attaching a reverse diff of the commit, such that when applied to HEAD makes GRUB work again (verified) [1].

This patch broke. I'm updating it to HEAD. Removed some cosmetical changes to make it less error-prone.

Signature · 5 lines
Robert Millan

<GPLv2> I know my rights; I want my phone call!
<DRM> What use is a phone call, if you are unable to speak?
(as seen on /.)

-2007-02-21 Hollis Blanchard <[email protected]> -
- * kern/powerpc/ieee1275/init.c (HEAP_SIZE): Removed.
- (HEAP_LIMIT): New macro.
- (grub_claim_heap): Claim memory up to `heaplimit'.
-
-2007-02-21 Hollis Blanchard <[email protected]> -
- * conf/powerpc-ieee1275.rmk (kernel_elf_LDFLAGS): Link at 64KB.
- * kern/powerpc/ieee1275/init.c (_end): Add declaration.
- (_start): Likewise.
- (grub_arch_modules_addr): Return address after `_end'.
- * util/powerpc/ieee1275/grub-mkimage.c: Include grub/misc.h.
- (load_modules): Use new parameter as p_paddr' and p_vaddr'.
- (add_segments): Calculate `_end' from phdr size and location.
- (ALIGN_UP): Moved to ...
- * include/grub/misc.h: here.
- * include/grub/powerpc/ieee1275/kernel.h (GRUB_IEEE1275_MOD_ALIGN):
- New macro.
- (GRUB_IEEE1275_MODULE_BASE): Removed.

conf/powerpc-ieee1275.mk +1 -1
diff -ur grub2-bad/conf/powerpc-ieee1275.mk grub2-good/conf/powerpc-ieee1275.mk
@@ -468,7 +468,7 @@
 kernel_elf_CFLAGS = $(COMMON_CFLAGS)
 kernel_elf_ASFLAGS = $(COMMON_ASFLAGS)
 kernel_elf_LDFLAGS = $(COMMON_LDFLAGS) -static-libgcc -lgcc \
-	-Wl,-N,-S,-Ttext,0x10000,-Bstatic
+	-Wl,-N,-S,-Ttext,0x200000,-Bstatic
 
 # Scripts.
 sbin_SCRIPTS = grub-install
conf/powerpc-ieee1275.rmk +1 -1
diff -ur grub2-bad/conf/powerpc-ieee1275.rmk grub2-good/conf/powerpc-ieee1275.rmk
@@ -74,7 +74,7 @@
 kernel_elf_CFLAGS = $(COMMON_CFLAGS)
 kernel_elf_ASFLAGS = $(COMMON_ASFLAGS)
 kernel_elf_LDFLAGS = $(COMMON_LDFLAGS) -static-libgcc -lgcc \
-	-Wl,-N,-S,-Ttext,0x10000,-Bstatic
+	-Wl,-N,-S,-Ttext,0x200000,-Bstatic
 
 # Scripts.
 sbin_SCRIPTS = grub-install
include/grub/powerpc/ieee1275/kernel.h +3 -2
diff -ur grub2-bad/include/grub/powerpc/ieee1275/kernel.h grub2-good/include/grub/powerpc/ieee1275/kernel.h
@@ -22,9 +22,10 @@
 
 #include <grub/symbol.h>
 
-#define GRUB_IEEE1275_MOD_ALIGN 0x1000
-
 void EXPORT_FUNC (grub_reboot) (void);
 void EXPORT_FUNC (grub_halt) (void);
 
+/* Where grub-mkimage places the core modules in memory.  */
+#define GRUB_IEEE1275_MODULE_BASE 0x00300000
+
 #endif /* ! GRUB_KERNEL_MACHINE_HEADER */
kern/powerpc/ieee1275/init.c +20 -21

69 lines not on this page · raw message

util/powerpc/ieee1275/grub-mkimage.c +4 -19
diff -ur grub2-bad/util/powerpc/ieee1275/grub-mkimage.c grub2-good/util/powerpc/ieee1275/grub-mkimage.c
@@ -97,8 +98,7 @@
 }
 
 void
-load_modules (grub_addr_t modbase, Elf32_Phdr *phdr, const char *dir,
-	      char *mods[], FILE *out)
+load_modules (Elf32_Phdr *phdr, const char *dir, char *mods[], FILE *out)
 {
   char *module_img;
   struct grub_util_path_list *path_list;
@@ -152,8 +152,8 @@
   phdr->p_type = grub_cpu_to_be32 (PT_LOAD);
   phdr->p_flags = grub_cpu_to_be32 (PF_R | PF_W | PF_X);
   phdr->p_align = grub_cpu_to_be32 (sizeof (long));
-  phdr->p_vaddr = grub_cpu_to_be32 (modbase);
-  phdr->p_paddr = grub_cpu_to_be32 (modbase);
+  phdr->p_vaddr = grub_cpu_to_be32 (GRUB_IEEE1275_MODULE_BASE);
+  phdr->p_paddr = grub_cpu_to_be32 (GRUB_IEEE1275_MODULE_BASE);
   phdr->p_filesz = grub_cpu_to_be32 (total_module_size);
   phdr->p_memsz = grub_cpu_to_be32 (total_module_size);
 }
@@ -166,7 +166,6 @@
   Elf32_Phdr *phdr;
   FILE *in;
   char *kernel_path;
-  grub_addr_t grub_end = 0;
   off_t phdroff;
   int i;
 
@@ -184,7 +183,6 @@
   for (i = 0; i < grub_be_to_cpu16 (ehdr.e_phnum); i++)
     {
       char *segment_img;
-      grub_size_t segment_end;
 
       phdr = phdrs + i;
 
@@ -196,13 +194,6 @@
       grub_util_info ("copying segment %d, type %d", i,
 		      grub_be_to_cpu32 (phdr->p_type));
 
-      /* Locate _end.  */
-      segment_end = grub_be_to_cpu32 (phdr->p_paddr)
-		    + grub_be_to_cpu32 (phdr->p_memsz);
-      grub_util_info ("segment %u end 0x%lx", i, segment_end);
-      if (segment_end > grub_end)
-	grub_end = segment_end;
-
       /* Read segment data and write it to new file.  */
       segment_img = xmalloc (grub_be_to_cpu32 (phdr->p_filesz));
   
@@ -216,11 +207,6 @@
 
   if (mods[0] != NULL)
     {
-      grub_addr_t modbase;
-
-      /* Place modules just after grub segment.  */
-      modbase = ALIGN_UP(grub_end, GRUB_IEEE1275_MOD_ALIGN);
-
       /* Construct new segment header for modules.  */
       phdr = phdrs + grub_be_to_cpu16 (ehdr.e_phnum);
       ehdr.e_phnum = grub_cpu_to_be16 (grub_be_to_cpu16 (ehdr.e_phnum) + 1);
@@ -229,7 +215,7 @@
       phdr->p_offset = grub_cpu_to_be32 (ALIGN_UP (grub_util_get_fp_size (out),
 						   sizeof (long)));
 
-      load_modules (modbase, phdr, dir, mods, out);
+      load_modules (phdr, dir, mods, out);
     }
 
   if (chrp)