Subject: pkg/36627: sysutils/grub: will not boot with >= 2GB memory [patch]
To: None <pkg-manager@netbsd.org, gnats-admin@netbsd.org,>
From: None <andrew@balin.tamu.edu>
List: pkgsrc-bugs
Date: 07/11/2007 01:15:01
>Number:         36627
>Category:       pkg
>Synopsis:       GRUB Error 28 when loading kernel on systems with >= 2GB RAM.
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    pkg-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Jul 11 01:15:00 +0000 2007
>Originator:     andrew.daugherity@gmail.com
>Release:        NetBSD 4.0_BETA2
>Organization:
	
>Environment:
	
	
System: NetBSD balin.tamu.edu 4.0_BETA2 NetBSD 4.0_BETA2 (BALIN) #0: Mon Jun 18 12:28:16 CDT 2007 root@balin.tamu.edu:/usr/obj/sys/arch/i386/compile/BALIN i386
Architecture: i386
Machine: i386
>Description:
I discovered that the GRUB shipped in pkgsrc does not boot on systems
with >= 2GB RAM.  Apparently this is a known issue and a bug with a
patch has been filed with GNU several years ago[1]  but they haven't
done anything about it.  Other distributions like Debian have applied
this patch to their packages, but pkgsrc has not.

A GRUB boot CD made with the stage2_eltorito from pkgsrc GRUB fails to
boot on machines with large memory, giving the message "Error 28:
Selected item cannot fit into memory" when attempting to load a
kernel.  If I enable the "OS Install Mode" in the BIOS, which limits
the available memory to 256MB, it works fine.  Also, using the
stage2_eltorito from Debian works.  Looking through the Debian
changelog [2], I saw this:
====
 * patches/2gb_limit.diff: New.  Fix problem with systems with more than
     2 GB memory (notably, x86_64-based systems).  Thanks Goswin Brederlow.
====

I adapted the 2gb_limit.diff from the Debian source package into
pkgsrc.  With this patch, GRUB works correctly.

	
>How-To-Repeat:
Install GRUB, either to hard disk, or use stage2_eltorito in a bootable CD
image.  Attempting to load any kernel (Linux or NetBSD) on a system with
2GB or more RAM will fail with "Error 28: Selected item cannot fit into 
memory".
	
>Fix:
	
(Apply with patch -p0 to pkgsrc/sysutils/grub directory.)
====

Index: patches/patch-ae
===================================================================
RCS file: /cvsroot/pkgsrc/sysutils/grub/patches/patch-ae,v
retrieving revision 1.3
diff -u -r1.3 patch-ae
--- patches/patch-ae	21 Aug 2005 15:08:46 -0000	1.3
+++ patches/patch-ae	10 Jul 2007 22:25:48 -0000
@@ -2,6 +2,15 @@
 
 --- stage2/shared.h	2004-06-19 18:40:09.000000000 +0200
 +++ stage2/shared.h	2005-07-25 21:33:19.000000000 +0200
+@@ -911,7 +911,7 @@ int substring (const char *s1, const cha
+ int nul_terminate (char *str);
+ int get_based_digit (int c, int base);
+ int safe_parse_maxint (char **str_ptr, int *myint_ptr);
+-int memcheck (int start, int len);
++int memcheck (unsigned long int start, unsigned long int len);
+ void grub_putstr (const char *str);
+
+ #ifndef NO_DECOMPRESSION
 @@ -975,6 +975,8 @@
  #ifndef STAGE1_5
  void bsd_boot (kernel_t type, int bootdev, char *arg)
Index: Makefile
===================================================================
RCS file: /cvsroot/pkgsrc/sysutils/grub/Makefile,v
retrieving revision 1.47
diff -u -r1.47 Makefile
--- Makefile	25 Jun 2007 13:05:56 -0000	1.47
+++ Makefile	10 Jul 2007 22:31:02 -0000
@@ -1,7 +1,7 @@
 # $NetBSD: Makefile,v 1.47 2007/06/25 13:05:56 tron Exp $
 
 DISTNAME=	grub-0.97
-PKGREVISION=	7
+PKGREVISION=	8
 CATEGORIES=	sysutils
 MASTER_SITES=	ftp://alpha.gnu.org/gnu/grub/
 
Index: distinfo
===================================================================
RCS file: /cvsroot/pkgsrc/sysutils/grub/distinfo,v
retrieving revision 1.22
diff -u -r1.22 distinfo
--- distinfo	25 Jun 2007 13:05:56 -0000	1.22
+++ distinfo	10 Jul 2007 22:33:39 -0000
@@ -7,7 +7,7 @@
 SHA1 (patch-ab) = 945ee0385d82f4ea98e86acfa449bcbf2a214285
 SHA1 (patch-ac) = dc7774a09ca88f6696e0680a7be39df56244eedc
 SHA1 (patch-ad) = 613e915a015ad22c9bd5712d416e12b1b81fdb93
-SHA1 (patch-ae) = 96d8283e90ceb3e887ba0ada05619858c52bc144
+SHA1 (patch-ae) = 9e41bd80a6aed16d7d638c808d81c34f4114578a
 SHA1 (patch-af) = 9447ead52940203c998afb67e38ae3d3d26097f8
 SHA1 (patch-ag) = 1dd709652d457ba03dda47b64d22cd9320f81e26
 SHA1 (patch-ah) = ff62b64177a0e68400c32e013cb585526db94217
@@ -16,3 +16,4 @@
 SHA1 (patch-ak) = 8e67eb603e639ca47536cb191e7e29ec48b95642
 SHA1 (patch-al) = 58761e867ff182ad46c42b15575395ba8c38fbd6
 SHA1 (patch-am) = d848f67f7f21fa076751d14bd3235ae7351be1b7
+SHA1 (patch-an) = b86401eceed91ff49a00a1e2a7aa49009e01a875
--- /dev/null	2007-07-10 18:20:56.000000000 -0500
+++ patches/patch-an	2007-07-10 18:21:12.000000000 -0500
@@ -0,0 +1,31 @@
+$NetBSD$
+
+--- stage2/char_io.c
++++ stage2/char_io.c
+@@ -1175,13 +1175,13 @@
+ #endif /* ! STAGE1_5 */
+ 
+ int
+-memcheck (int addr, int len)
++memcheck (unsigned long int addr, unsigned long int len)
+ {
+ #ifdef GRUB_UTIL
+-  auto int start_addr (void);
+-  auto int end_addr (void);
++  auto unsigned long int start_addr (void);
++  auto int unsigned long end_addr (void);
+   
+-  auto int start_addr (void)
++  auto unsigned long int start_addr (void)
+     {
+       int ret;
+ # if defined(HAVE_START_SYMBOL)
+@@ -1192,7 +1192,7 @@
+       return ret;
+     }
+
+-  auto int end_addr (void)
++  auto unsigned long int end_addr (void)
+     {
+       int ret;
+ # if defined(HAVE_END_SYMBOL)

>Unformatted: