Hi, I've made some effort to port GNU GRUB to NetBSD/i386, possibly making it more system independent and portable.
Most of my work is a couple of small bugfixes, but there are some bigger issues that have to be dealt with and undoubtly need some more work and discussion. Anyways, with my patches whole grub builds, but since I didn't do any extensive testing I can't tell whether it behaves correctly. My environment is: NetBSD/i386 3.99.9 (gcc 3.3.3) Well, here is summary of issues: ================================ 1.) Non-executable stack mappings. ---------------------------------- Files affected: kern/mm.c, normal/misc.c This is probably more a gcc issue (my is gcc version 3.3.3 (NetBSD nb3 20040520)). As of 2.0, NetBSD/i386 uses non-executable mapping of stack and thus when nested functions are used it generates call to __enable_execute_stack() (which is actually in libgcc) even if -nostdlib is used. Since I know no way to disable this behavior (but there might be some) only workaround known to me is providing dumb __enable_execute_stack() functions where apropriate. Anyways, kern/mm.c and normal/misc.c are really not the best places for such a hack to take place. 2.) memalign() -------------- Files affected: util/misc.c configure.ac Makefile.in conf/i386-pc.rmk The missing memalign() issue is was already discussed some time ago, and mr. Okuji also provided some solution here: http://lists.gnu.org/archive/html/grub-devel/2004-03/msg00048.html http://lists.gnu.org/archive/html/grub-devel/2004-03/msg00053.html I don't know about other systems, but NetBSD base installation contains GNU malloc library, which provides memalign(). Unlike some other commercial UNIX environments Microsoft SFU's Interix has no memalign() implementation, but I think there is no need and probably no way to support this plattform. 3.) argp -------- Files affected: util/grub-emu.c, configure.ac, Makefile.in, conf/i386-pc.rmk Argp framework is also GNU libc specific. For it is not present in other libcs we might have to exclude grub-emu from nonGNU builds, replace argp with getopt, or provide argp routines. As excluding grub-emu is undoubtly unacceptable and there was certainly some reason why argp was used, glibc's argp needs some replacement. The same problem rose in effort to make LSH portable. LSH authors decided to include argp code in their distribution. Their version is a hacked glibc splitout that is not even dependent on getopt. Fortunatelly, they provide and maintain the agrp code also separately from LSH. LSH and their way to handle argp dependency: http://www.lysator.liu.se/~nisse/lsh/ http://cvs.lysator.liu.se/viewcvs/viewcvs.cgi/lsh/src/argp/?root=lsh Argp-standalone: http://www.lysator.liu.se/~nisse/misc/ http://lists.gnu.org/archive/html/bug-gnulib/2003-03/msg00002.html http://www.freshports.org/devel/argp-standalone/ The way that seems most wise to me is not to incude argp code, but make GRUB on nonGNU platforms dependent on arpg-standalone. Assuming that package systems (such as Free|OpenBSD ports and pkgsrc) will be primary way to install GRUB, we will need argp-standalone package to appear in them. There already exists FreeBSD package for it and I may write pkgsrc package (for NetBSD and DragonFly). And small bugfixes: =================== 1.) BUILD_ options handling --------------------------- Files affected: configure.ac, Makefile.in I found no better way to specify build flags than passsing BUILD_* options. This is what my configure line looks like: (i have liblzo in /usr/pkg and argp-standalone in /usr/local) ./configure \ BUILD_LDFLAGS='-L/usr/pkg/lib -L/usr/local/lib' \ BUILD_CPPFLAGS='-I/usr/pkg/include -I/usr/local/include -Wall -W' \ BUILD_CFLAGS='-g' Another issue is that -O2 doesn't work correctly for me. In util/i386/pc/getroot.c:find_root_device() dev variable is stored in ebx register (when level 2 optimalizations used) and this register is modified by call to lstat(). And call to lstat() also clobbers ent structure ... I haven’t investigated that yet. This is likely not a GRUB bug, but to work it around I had to override BUILD_CFLAGS ommiting -O2. 2.) GNU bison dependency ------------------------ Files affected: configure.ac, Makefile.in Set $(YACC) to bison if bison is found. This is currently mandatory on platforms where 'yacc' binary is not bison, because only bison works. Should this be changed (corrected?). 3.) bindir's not sbindir ------------------------ Files affected: util/i386/pc/grub-install.in 4.) GNU uniq ------------ Files affected: geninit.sh Still haven't found out what uniq's -W1 and -t':' parameters do. Found them in some manuals (ok, didn't read them :) and in some no. Are they still part of current coreutils? And if yes, they are certainly not standard and should be replaced by something else. My opinion about using utils like uniq is that only SUSv2 or POSIX or ...I mean that only standard and portable switches should be used. Compile-time Warnings: ====================== $ gmake -s 2>&1 | sort | uniq ...Will certainly need some more work uniq: unknown option -- W usage: uniq [-c | -du] [-f fields] [-s chars] [input [output]] Patch follows: ============== Machine generated files (configure, i386-pc.mk) are ommited, so one should autoreconf before ./configure -ing. Index: INSTALL =================================================================== RCS file: /usr/home/lkundrak/cvs/grub/grub/INSTALL,v retrieving revision 1.3 retrieving revision 1.3.2.2 diff -u -r1.3 -r1.3.2.2 --- INSTALL 4 Apr 2004 13:45:59 -0000 1.3 +++ INSTALL 29 Nov 2005 20:41:45 -0000 1.3.2.2 @@ -14,6 +14,8 @@ * GCC 2.95 or later * GNU Make * GNU binutils 2.9.1.0.23 or later +* GNU glibc or argp-standalone and memalign +* GNU bison * Other standard GNU/Unix tools * LZO 1.02 or later Index: Makefile.in =================================================================== RCS file: /usr/home/lkundrak/cvs/grub/grub/Makefile.in,v retrieving revision 1.16 retrieving revision 1.16.2.5 diff -u -r1.16 -r1.16.2.5 --- Makefile.in 18 Nov 2005 14:56:55 -0000 1.16 +++ Makefile.in 30 Nov 2005 08:46:24 -0000 1.16.2.5 @@ -57,17 +57,23 @@ CC = @CC@ CFLAGS = @CFLAGS@ CPPFLAGS = -I. -Iinclude -I$(srcdir)/include -Wall -W + BUILD_CC = @BUILD_CC@ -BUILD_CFLAGS = -g -O2 -BUILD_CPPFLAGS = -I. -Iinclude -I$(srcdir)/include -Wall -W \ - -DGRUB_DATADIR=\"$(pkgdatadir)\" +BUILD_CFLAGS = @BUILD_CFLAGS@ +BUILD_CPPFLAGS = @BUILD_CPPFLAGS@ +BUILD_CPPFLAGS += -I. -Iinclude -I$(srcdir)/include -DGRUB_DATADIR=\"$(pkgdatadir)\" +BUILD_LDFLAGS = @BUILD_LDFLAGS@ + OBJCOPY = @OBJCOPY@ STRIP = @STRIP@ NM = @NM@ LD = @LD@ RUBY = @RUBY@ +YACC = @YACC@ LIBCURSES = @LIBCURSES@ LIBLZO = @LIBLZO@ +LIBARGP = @LIBARGP@ +LIBMALLOC = @LIBMALLOC@ ### General variables. Index: configure.ac =================================================================== RCS file: /usr/home/lkundrak/cvs/grub/grub/configure.ac,v retrieving revision 1.16 retrieving revision 1.16.2.4 diff -u -r1.16 -r1.16.2.4 --- configure.ac 6 Nov 2005 22:19:58 -0000 1.16 +++ configure.ac 30 Nov 2005 08:46:25 -0000 1.16.2.4 @@ -122,7 +122,6 @@ [AC_MSG_ERROR([none of gcc, egcs and cc is found. set BUILD_CC manually.])]) else BUILD_CC="$CC" - AC_SUBST(BUILD_CC) fi # Test the C compiler for the build environment. @@ -133,7 +132,20 @@ CC="$BUILD_CC" CFLAGS="$BUILD_CFLAGS" CPPFLAGS="$BUILD_CPPFLAGS" -LDFLAGS="$BUILD_LDDFLAGS" +LDFLAGS="$BUILD_LDFLAGS" + +if test "x$BUILD_CFLAGS" = x; then + BUILD_CFLAGS="-g -O2" +fi + +if test "x$BUILD_CPPFLAGS" = x; then + BUILD_CPPFLAGS="-Wall -W" +fi + +AC_SUBST(BUILD_CC) +AC_SUBST(BUILD_CFLAGS) +AC_SUBST(BUILD_CPPFLAGS) +AC_SUBST(BUILD_LDFLAGS) # Identify characteristics of the build architecture. AC_C_BIGENDIAN @@ -162,6 +174,18 @@ [AC_CHECK_LIB(curses, wgetch, [LIBCURSES="-lcurses"])]) AC_SUBST(LIBCURSES) +# Check for argp +AC_CHECK_FUNC(argp_parse,, + AC_CHECK_LIB(argp, argp_parse, [LIBARGP="-largp"], + AC_MSG_ERROR([Argp required. Either use glibc or install argp-standalone.]))) +AC_SUBST(LIBARGP) + +# Check for memalign() +AC_CHECK_FUNC(memalign,, + AC_CHECK_LIB(gnumalloc, memalign, [LIBMALLOC="-lgnumalloc"], + AC_MSG_ERROR([memalign() required. Either use glibc or install libgnumalloc.]))) +AC_SUBST(LIBMALLOC) + # Check for headers. AC_CHECK_HEADERS(ncurses/curses.h ncurses.h curses.h) Index: conf/i386-pc.rmk =================================================================== RCS file: /usr/home/lkundrak/cvs/grub/grub/conf/i386-pc.rmk,v retrieving revision 1.55 retrieving revision 1.55.2.2 diff -u -r1.55 -r1.55.2.2 --- conf/i386-pc.rmk 18 Nov 2005 14:56:55 -0000 1.55 +++ conf/i386-pc.rmk 29 Nov 2005 20:27:29 -0000 1.55.2.2 @@ -57,7 +57,7 @@ # For grub-mkimage. grub_mkimage_SOURCES = util/i386/pc/grub-mkimage.c util/misc.c \ util/resolve.c -grub_mkimage_LDFLAGS = $(LIBLZO) +grub_mkimage_LDFLAGS = $(LIBLZO) $(LIBMALLOC) # For grub-setup. grub_setup_SOURCES = util/i386/pc/grub-setup.c util/i386/pc/biosdisk.c \ @@ -65,9 +65,11 @@ kern/err.c kern/misc.c fs/fat.c fs/ext2.c fs/xfs.c fs/affs.c \ fs/sfs.c kern/parser.c kern/partition.c partmap/pc.c \ fs/ufs.c fs/minix.c fs/hfs.c fs/jfs.c kern/file.c kern/fs.c kern/env.c fs/fshelp.c +grub_setup_LDFLAGS = $(LIBMALLOC) # For grub-mkdevicemap. grub_mkdevicemap_SOURCES = util/i386/pc/grub-mkdevicemap.c util/misc.c +grub_mkdevicemap_LDFLAGS = $(LIBMALLOC) # For grub-probefs. grub_probefs_SOURCES = util/i386/pc/grub-probefs.c \ @@ -76,6 +78,7 @@ fs/ext2.c kern/parser.c kern/partition.c partmap/pc.c fs/ufs.c \ fs/minix.c fs/hfs.c fs/jfs.c kern/fs.c kern/env.c fs/fshelp.c \ fs/xfs.c fs/affs.c fs/sfs.c +grub_probefs_LDFLAGS = $(LIBMALLOC) # For grub-emu. grub_emu_SOURCES = commands/boot.c commands/cat.c commands/cmp.c \ @@ -100,7 +103,7 @@ util/i386/pc/biosdisk.c util/i386/pc/getroot.c \ util/i386/pc/misc.c grub_emu_init.c -grub_emu_LDFLAGS = $(LIBCURSES) +grub_emu_LDFLAGS = $(LIBCURSES) $(LIBARGP) $(LIBMALLOC) # For genmoddep. genmoddep_SOURCES = util/genmoddep.c Index: kern/mm.c =================================================================== RCS file: /usr/home/lkundrak/cvs/grub/grub/kern/mm.c,v retrieving revision 1.13 retrieving revision 1.13.2.1 diff -u -r1.13 -r1.13.2.1 --- kern/mm.c 21 Aug 2005 18:42:54 -0000 1.13 +++ kern/mm.c 28 Nov 2005 19:36:06 -0000 1.13.2.1 @@ -420,3 +420,13 @@ grub_printf ("\n"); } #endif /* MM_DEBUG */ + +/* + * XXX: gcc on systems using non-executable mapping of stack generate + * reference to __enable_execute_stack() (libgcc) + * Probably there's better way to solve this, than such an ugly workaround. + */ + +void __enable_execute_stack (void); +void __enable_execute_stack (void) {} + Index: normal/misc.c =================================================================== RCS file: /usr/home/lkundrak/cvs/grub/grub/normal/misc.c,v retrieving revision 1.2 retrieving revision 1.2.2.1 diff -u -r1.2 -r1.2.2.1 --- normal/misc.c 19 Aug 2005 00:32:01 -0000 1.2 +++ normal/misc.c 28 Nov 2005 19:36:08 -0000 1.2.2.1 @@ -69,3 +69,13 @@ grub_printf ("\n"); return grub_errno; } + +/* + * XXX: gcc on systems using non-executable mapping of stack generate + * reference to __enable_execute_stack() (libgcc) + * Probably there's better way to solve this, than such an ugly workaround. + */ + +void __enable_execute_stack (void); +void __enable_execute_stack (void) {} + Index: util/i386/pc/grub-install.in =================================================================== RCS file: /usr/home/lkundrak/cvs/grub/grub/util/i386/pc/grub-install.in,v retrieving revision 1.4 retrieving revision 1.4.2.1 diff -u -r1.4 -r1.4.2.1 --- util/i386/pc/grub-install.in 7 Aug 2005 17:12:52 -0000 1.4 +++ util/i386/pc/grub-install.in 27 Nov 2005 13:03:56 -0000 1.4.2.1 @@ -21,6 +21,7 @@ [EMAIL PROTECTED]@ [EMAIL PROTECTED]@ [EMAIL PROTECTED]@ [EMAIL PROTECTED]@ [EMAIL PROTECTED]@ [EMAIL PROTECTED]@ [EMAIL PROTECTED]@ @@ -31,7 +32,7 @@ pkgdatadir=${datadir}/${PACKAGE_TARNAME}/${host_cpu}-${host_vendor} grub_setup=${sbindir}/grub-setup -grub_mkimage=${sbindir}/grub-mkimage +grub_mkimage=${bindir}/grub-mkimage grub_mkdevicemap=${sbindir}/grub-mkdevicemap grub_probefs=${sbindir}/grub-probefs rootdir= Cheers! --------------------------------------------------------------------------- o Lubomir Kundrak °O° <[EMAIL PROTECTED]>, http://skosi.org/~lkundrak/ (_) SKOSI -- Slovak OpenSource Initiative --------------------------------------------------------------------------- _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org http://lists.gnu.org/mailman/listinfo/grub-devel