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.

-- 
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.

diff -ur grub2-bad/conf/powerpc-ieee1275.mk grub2-good/conf/powerpc-ieee1275.mk
--- grub2-bad/conf/powerpc-ieee1275.mk	2007-02-22 00:22:20.000000000 +0100
+++ grub2-good/conf/powerpc-ieee1275.mk	2006-12-13 23:34:04.000000000 +0100
@@ -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
-
diff -ur grub2-bad/conf/powerpc-ieee1275.rmk grub2-good/conf/powerpc-ieee1275.rmk
--- grub2-bad/conf/powerpc-ieee1275.rmk	2007-02-22 00:22:20.000000000 +0100
+++ grub2-good/conf/powerpc-ieee1275.rmk	2006-12-13 23:30:19.000000000 +0100
@@ -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
-
diff -ur grub2-bad/include/grub/misc.h grub2-good/include/grub/misc.h
--- grub2-bad/include/grub/misc.h	2007-02-22 00:22:20.000000000 +0100
+++ grub2-good/include/grub/misc.h	2006-10-14 17:24:52.000000000 +0200
@@ -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))
diff -ur grub2-bad/include/grub/powerpc/ieee1275/kernel.h grub2-good/include/grub/powerpc/ieee1275/kernel.h
--- grub2-bad/include/grub/powerpc/ieee1275/kernel.h	2007-02-22 00:22:20.000000000 +0100
+++ grub2-good/include/grub/powerpc/ieee1275/kernel.h	2006-04-23 15:37:36.000000000 +0200
@@ -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 */
diff -ur grub2-bad/kern/powerpc/ieee1275/init.c grub2-good/kern/powerpc/ieee1275/init.c
--- grub2-bad/kern/powerpc/ieee1275/init.c	2007-02-22 00:27:36.000000000 +0100
+++ grub2-good/kern/powerpc/ieee1275/init.c	2007-02-13 04:49:43.000000000 +0100
@@ -34,10 +34,7 @@
 #include <grub/ieee1275/ofdisk.h>
 #include <grub/ieee1275/ieee1275.h>
 
-#define HEAP_LIMIT (4<<20) /* 4 MiB */
-
-extern char _start[];
-extern char _end[];
+#define HEAP_SIZE (8<<20) /* 8 MiB */
 
 void
 grub_exit (void)
@@ -114,27 +111,29 @@
 }
 
 /* Claim some available memory in the first /memory node. */
-static void grub_claim_heap (unsigned long heaplimit)
+static void grub_claim_heap (unsigned long heapsize)
 {
+  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 (len)
-      {
-	/* 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_mm_init_region ((void *) (grub_addr_t) addr, len);
-      }
-
+    /* Limit heap to `heapsize'.  */
+    if (total + len > heapsize)
+      len = heapsize - total;
+
+    /* 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_mm_init_region ((void *) (grub_addr_t) addr, len);
+
+    total += len;
+    if (total >= heapsize)
+      return 1;
     return 0;
   }
 
@@ -148,7 +147,7 @@
   int actual;
 
   grub_console_init ();
-  grub_claim_heap (HEAP_LIMIT);
+  grub_claim_heap (HEAP_SIZE);
   grub_ofdisk_init ();
 
   /* Process commandline.  */
@@ -206,5 +205,5 @@
 grub_addr_t
 grub_arch_modules_addr (void)
 {
-  return ALIGN_UP(_end, GRUB_IEEE1275_MOD_ALIGN);
+  return GRUB_IEEE1275_MODULE_BASE;
 }
diff -ur grub2-bad/util/powerpc/ieee1275/grub-mkimage.c grub2-good/util/powerpc/ieee1275/grub-mkimage.c
--- grub2-bad/util/powerpc/ieee1275/grub-mkimage.c	2007-02-22 00:22:20.000000000 +0100
+++ grub2-good/util/powerpc/ieee1275/grub-mkimage.c	2006-09-26 06:24:38.000000000 +0200
@@ -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)
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/grub-devel

Reply via email to