Hi,

When building  openwrt-x86-ext2.vmdk vmware-image on Mac OS Snow Leopard the 
image won't boot on VMWare Fusion. The essential problem seems to be that Mac 
OS would need to run the 'grub'-executable to initialize the grub boot-loader, 
but the grub shell is not host-compiled into Mach-O executable. 

We have preliminarily fixed the problem in the following way (see the 
patch-files below):
- defining a patch that compiles the full grub-package for the x86 target like 
in the linux host case.
- defining a patch that host-compiles only the so-called grub-shell 'grub'  to 
Mach-O executable to avoid Linux dependencies with the stage1 and stage2 part.

Mac OS X host environment:
- we have used gcc45 (and gcc44) for OpenWRT compilation in Mac OS X host since 
the default (i686-apple-darwin10-gcc-4.2.1) compiler results in compilation 
problems.
- installed macports (see 
http://laufer.cs.luc.edu/2009/09/prerequisites-for-building-openwrt-sdk.html):  
coreutils gawk qemu gcc45 gcc_select binutils gpatch bzip2 flex bison gmake 
gettext pkgconfig unzip libzip wget findutils getopt gnutar md5sha1sum

Currently, we are able to generate a proper openwrt-x86-ext2.vmdk image which 
boots and grub seems to be working fine with the image. However, the kernel 
panics during the booting process and prints the following message:
...
sd 0:0:0:0: [sda] Attached SCSI disk
VFS: Mounted root (ext2 filesystem) readonly on device 8:2.
Freeing unused kernel memory: 292k freed
Please be patient, while OpenWrt loads ...
Kernel panic - not syncing: Attempted to kill init! 

Any feedback is welcome to solve the problem and to get the image boot.

Signed-off-by: Jukka Ylitalo <jukka.ylit...@ericsson.com>

---

diff --git a/package/grub/Makefile b/package/grub/Makefile
index 94695ec..a1f52cc 100644
--- a/package/grub/Makefile
+++ b/package/grub/Makefile
@@ -19,7 +19,15 @@ PKG_MD5SUM:=cd3f3eb54446be6003156158d51f4884
 PKG_BUILD_DIR:=$(KERNEL_BUILD_DIR)/grub-$(PKG_VERSION)
 PKG_TARGETS:=bin
 
+ifneq ($(HOST_OS),Linux)
+  PKG_BUILD_DEPENDS:=grub/host
+  HOST_PATCH_DIR=host_patches
+endif
+
 include $(INCLUDE_DIR)/package.mk
+ifneq ($(HOST_OS),Linux)
+  include $(INCLUDE_DIR)/host-build.mk
+endif
 
 export grub_cv_prog_objcopy_absolute=yes
 
@@ -46,7 +54,6 @@ else
 CONFIGURE_FLAGS:=
 endif
 
-ifneq ($(HOST_OS),Darwin)
 define Build/Configure
        (cd $(PKG_BUILD_DIR); \
                LDFLAGS="-static" \
@@ -79,12 +86,30 @@ define Build/Compile
                STAGE1_CFLAGS="\$$$$(STAGE2_CFLAGS)"
 endef
 
+ifeq ($(HOST_OS),Linux)
 define Build/InstallDev
        $(MAKE) -C $(PKG_BUILD_DIR) \
                DESTDIR="$(STAGING_DIR_HOST)" \
                install
        mv $(STAGING_DIR_HOST)/usr/sbin/grub $(STAGING_DIR_HOST)/bin
 endef
+else
+#
+# Non-Linux cross-compile
+#
+define Host/Install
+       $(CONF_OPTS) \
+       $(MAKE) -C $(HOST_BUILD_DIR) \
+               install
+       mv $(STAGING_DIR_HOST)/sbin/grub $(STAGING_DIR_HOST)/bin
+endef
+
+define Build/InstallDev
+       $(MAKE) -C $(PKG_BUILD_DIR) \
+               DESTDIR="$(STAGING_DIR)" \
+               install
+endef
+$(eval $(call HostBuild))
 endif
 
 $(eval $(call BuildPackage,grub))
diff --git a/package/grub/host_patches/100-configure.patch 
b/package/grub/host_patches/100-configure.patch
new file mode 100644
index 0000000..a316ce8
--- /dev/null
+++ b/package/grub/host_patches/100-configure.patch
@@ -0,0 +1,44 @@
+--- grub-0.97/configure.orig   2005-05-08 05:48:12.000000000 +0300
++++ grub-0.97/configure        2010-03-01 10:35:18.000000000 +0200
+@@ -4402,13 +4402,13 @@
+ echo "$as_me:$LINENO: result: $grub_cv_check_edata_symbol" >&5
+ echo "${ECHO_T}$grub_cv_check_edata_symbol" >&6
+ 
+-if test "x$grub_cv_check_uscore_uscore_bss_start_symbol" != "xyes" \
+-      -a "x$grub_cv_check_uscore_edata_symbol" != "xyes" \
+-      -a "x$grub_cv_check_edata_symbol" != "xyes"; then
+-  { { echo "$as_me:$LINENO: error: None of __bss_start, _edata, edata 
defined" >&5
+-echo "$as_me: error: None of __bss_start, _edata, edata defined" >&2;}
+-   { (exit 1); exit 1; }; }
+-fi
++#if test "x$grub_cv_check_uscore_uscore_bss_start_symbol" != "xyes" \
++#     -a "x$grub_cv_check_uscore_edata_symbol" != "xyes" \
++#     -a "x$grub_cv_check_edata_symbol" != "xyes"; then
++#  { { echo "$as_me:$LINENO: error: None of __bss_start, _edata, edata 
defined" >&5
++#echo "$as_me: error: None of __bss_start, _edata, edata defined" >&2;}
++#   { (exit 1); exit 1; }; }
++#fi
+ 
+ 
+ echo "$as_me:$LINENO: checking if end is defined by the compiler" >&5
+--- grub-0.97/configure.orig   2010-03-01 10:36:51.000000000 +0200
++++ grub-0.97/configure        2010-03-01 10:38:35.000000000 +0200
+@@ -4542,12 +4542,12 @@
+ echo "$as_me:$LINENO: result: $grub_cv_check_uscore_end_symbol" >&5
+ echo "${ECHO_T}$grub_cv_check_uscore_end_symbol" >&6
+ 
+-if test "x$grub_cv_check_end_symbol" != "xyes" \
+-      -a "x$grub_cv_check_uscore_end_symbol" != "xyes"; then
+-  { { echo "$as_me:$LINENO: error: Neither end nor _end is defined" >&5
+-echo "$as_me: error: Neither end nor _end is defined" >&2;}
+-   { (exit 1); exit 1; }; }
+-fi
++#if test "x$grub_cv_check_end_symbol" != "xyes" \
++#     -a "x$grub_cv_check_uscore_end_symbol" != "xyes"; then
++#  { { echo "$as_me:$LINENO: error: Neither end nor _end is defined" >&5
++#echo "$as_me: error: Neither end nor _end is defined" >&2;}
++#   { (exit 1); exit 1; }; }
++#fi
+ 
+ # Check for curses libraries.
+ 
diff --git a/package/grub/host_patches/110-configure_ac.patch 
b/package/grub/host_patches/110-configure_ac.patch
new file mode 100644
index 0000000..14bc424
--- /dev/null
+++ b/package/grub/host_patches/110-configure_ac.patch
@@ -0,0 +1,30 @@
+--- grub-0.97/configure.ac.orig        2010-03-01 10:40:32.000000000 +0200
++++ grub-0.97/configure.ac     2010-03-01 10:38:43.000000000 +0200
+@@ -183,18 +183,18 @@
+ grub_CHECK_USCORE_USCORE_BSS_START_SYMBOL
+ grub_CHECK_USCORE_EDATA_SYMBOL
+ grub_CHECK_EDATA_SYMBOL
+-if test "x$grub_cv_check_uscore_uscore_bss_start_symbol" != "xyes" \
+-      -a "x$grub_cv_check_uscore_edata_symbol" != "xyes" \
+-      -a "x$grub_cv_check_edata_symbol" != "xyes"; then
+-  AC_MSG_ERROR([None of __bss_start, _edata, edata defined])
+-fi
++# if test "x$grub_cv_check_uscore_uscore_bss_start_symbol" != "xyes" \
++#     -a "x$grub_cv_check_uscore_edata_symbol" != "xyes" \
++#     -a "x$grub_cv_check_edata_symbol" != "xyes"; then
++#  AC_MSG_ERROR([None of __bss_start, _edata, edata defined])
++# fi
+ 
+ grub_CHECK_END_SYMBOL
+ grub_CHECK_USCORE_END_SYMBOL
+-if test "x$grub_cv_check_end_symbol" != "xyes" \
+-      -a "x$grub_cv_check_uscore_end_symbol" != "xyes"; then
+-  AC_MSG_ERROR([Neither end nor _end is defined])
+-fi
++#if test "x$grub_cv_check_end_symbol" != "xyes" \
++#     -a "x$grub_cv_check_uscore_end_symbol" != "xyes"; then
++#  AC_MSG_ERROR([Neither end nor _end is defined])
++#fi
+ 
+ # Check for curses libraries.
+ AC_ARG_WITH(curses,
diff --git a/package/grub/host_patches/200-Makefile_in.patch 
b/package/grub/host_patches/200-Makefile_in.patch
new file mode 100644
index 0000000..5ae0673
--- /dev/null
+++ b/package/grub/host_patches/200-Makefile_in.patch
@@ -0,0 +1,11 @@
+--- grub-0.97/Makefile.in.orig 2005-05-08 05:42:40.000000000 +0300
++++ grub-0.97/Makefile.in      2010-03-01 10:42:46.000000000 +0200
+@@ -185,7 +185,7 @@
+ 
+ # Do not change this order if you don't know what you are doing.
+ AUTOMAKE_OPTIONS = 1.7 gnu
+-SUBDIRS = netboot stage2 stage1 lib grub util docs
++SUBDIRS = stage2 lib grub util docs
+ EXTRA_DIST = BUGS MAINTENANCE
+ all: config.h
+       $(MAKE) $(AM_MAKEFLAGS) all-recursive
diff --git a/package/grub/host_patches/210-Makefile_am.patch 
b/package/grub/host_patches/210-Makefile_am.patch
new file mode 100644
index 0000000..b50b25a
--- /dev/null
+++ b/package/grub/host_patches/210-Makefile_am.patch
@@ -0,0 +1,8 @@
+--- grub-0.97/Makefile.am.orig 2004-04-27 23:48:06.000000000 +0300
++++ grub-0.97/Makefile.am      2010-03-01 10:42:03.000000000 +0200
+@@ -1,4 +1,4 @@
+ # Do not change this order if you don't know what you are doing.
+ AUTOMAKE_OPTIONS = 1.7 gnu
+-SUBDIRS = netboot stage2 stage1 lib grub util docs
++SUBDIRS = stage2 lib grub util docs
+ EXTRA_DIST = BUGS MAINTENANCE
diff --git a/package/grub/host_patches/300-stage2_Makefile_in.patch 
b/package/grub/host_patches/300-stage2_Makefile_in.patch
new file mode 100644
index 0000000..c40435f
--- /dev/null
+++ b/package/grub/host_patches/300-stage2_Makefile_in.patch
@@ -0,0 +1,42 @@
+--- grub-0.97/stage2/Makefile.in.orig  2005-05-08 05:42:39.000000000 +0300
++++ grub-0.97/stage2/Makefile.in       2010-03-01 11:07:14.000000000 +0200
+@@ -427,7 +427,7 @@
+ target_alias = @target_alias@
+ 
+ # For test target.
+-TESTS = size_test
++# TESTS = size_test
+ noinst_SCRIPTS = $(TESTS)
+ 
+ # For dist target.
+@@ -496,8 +496,8 @@
+ pre_stage2_exec_CCASFLAGS = $(STAGE2_COMPILE) $(FSYS_CFLAGS)
+ pre_stage2_exec_LDFLAGS = $(PRE_STAGE2_LINK)
+ @netboot_support_t...@pre_stage2_exec_ldadd = ../netboot/libdrivers.a
+...@diskless_support_false@BUILT_SOURCES = stage2_size.h
+...@diskless_support_true@BUILT_SOURCES = stage2_size.h diskless_size.h
+...@diskless_support_false@BUILT_SOURCES = stage2_size.h
+...@diskless_support_true@BUILT_SOURCES = stage2_size.h diskless_size.h
+ CLEANFILES = $(pkglib_DATA) $(noinst_DATA) $(BUILT_SOURCES)
+ start_exec_SOURCES = start.S
+ start_exec_CCASFLAGS = $(STAGE2_COMPILE)
+@@ -3105,7 +3105,7 @@
+       $(MAKE) $(AM_MAKEFLAGS) check-TESTS
+ check: $(BUILT_SOURCES)
+       $(MAKE) $(AM_MAKEFLAGS) check-am
+-all-am: Makefile $(LIBRARIES) $(PROGRAMS) $(SCRIPTS) $(DATA) \
++all-am: Makefile $(LIBRARIES) $(SCRIPTS) \
+               $(HEADERS)
+ installdirs:
+       for dir in "$(DESTDIR)$(pkglibdir)"; do \
+--- grub-0.97/stage2/Makefile.in.orig  2010-03-01 11:08:25.000000000 +0200
++++ grub-0.97/stage2/Makefile.in       2010-03-01 11:10:25.000000000 +0200
+@@ -3118,7 +3118,7 @@
+ uninstall: uninstall-am
+ 
+ install-am: all-am
+-      @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
++      @$(MAKE) $(AM_MAKEFLAGS) 
+ 
+ installcheck: installcheck-am
+ install-strip:
diff --git a/target/linux/x86/image/Makefile b/target/linux/x86/image/Makefile
index b2167e7..fb61e0c 100644
--- a/target/linux/x86/image/Makefile
+++ b/target/linux/x86/image/Makefile
@@ -42,7 +42,6 @@ endif
 
 
 ifeq ($(CONFIG_X86_GRUB_IMAGES),y)
-ifneq ($(HOST_OS),Darwin)
   define Image/cmdline/squashfs
     block2mtd.block2mtd=$(ROOTPART),65536,rootfs root=/dev/mtdblock0 
rootfstype=squashfs rootwait
   endef
@@ -75,6 +74,7 @@ ifneq ($(HOST_OS),Darwin)
        $(call Image/Build/grub/$(1))
   endef
 
+ifneq ($(HOST_OS),Darwin)
   define Image/Prepare/grub
        # for the image builder
        $(CP) \
@@ -84,8 +84,13 @@ ifneq ($(HOST_OS),Darwin)
                $(KDIR)/
   endef
 else
-  define Image/Build/grub
-       PADDING="$(CONFIG_X86_GRUB_IMAGES_PAD)" PATH="$(TARGET_PATH)" NOGRUB=1 
./gen_image_x86.sh $(BIN_DIR)/openwrt-$(BOARD)-$(1).image 
$(CONFIG_X86_GRUB_KERNELPART) "" $(CONFIG_TARGET_ROOTFS_FSPART) 
$(KDIR)/root.$(1)
+  define Image/Prepare/grub
+       # for the image builder
+       $(CP) \
+               $(STAGING_DIR)/usr/lib/grub/i386-*/stage1 \
+               $(STAGING_DIR)/usr/lib/grub/i386-*/stage2 \
+               $(STAGING_DIR)/usr/lib/grub/i386-*/e2fs_stage1_5 \
+               $(KDIR)/
   endef
 endif
 endif
@@ -105,8 +110,8 @@ ifeq ($(CONFIG_X86_VMDK_IMAGES),y)
     # left here because the image builder doesnt need these
     ifeq ($(1),ext2)
                rm $(BIN_DIR)/openwrt-$(BOARD)-ext2.vmdk || true
-               qemu-img convert -f raw $(BIN_DIR)/openwrt-$(BOARD)-ext2.image \
-                       -O vmdk $(BIN_DIR)/openwrt-$(BOARD)-ext2.vmdk
+               qemu-img convert -f raw -O vmdk 
$(BIN_DIR)/openwrt-$(BOARD)-ext2.image \
+                       $(BIN_DIR)/openwrt-$(BOARD)-ext2.vmdk
     endif
   endef
 endif




_______________________________________________
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel

Reply via email to