Use initvm: Add recognition and use of initvm over initscript_qemu_vm
authorJames Perkins <james.perkins@linuxfoundation.org>
Fri, 17 Sep 2010 23:50:38 +0000 (16:50 -0700)
committerJan-Simon Möller <jsmoeller@linuxfoundation.org>
Sun, 20 Mar 2011 19:18:07 +0000 (20:18 +0100)
build
    - looks for and uses initvm in preference to initscript_qemu_vm

common_functions
    - check_use_emulator uses initvm in preference to initscript_qemu_vm

init_buildsystem
    - copy_qemu cleanup, qemu_register_binfmt and static install
- this is now based off the list of $EMULATOR_DEVS
- don't assume qemu-binfmt-conf.sh, bash-static or mount-static
  are present
    - after copy_qemu is called, prefer initvm over qemu-binfmt-conf.sh
      when initializing binfmts

Signed-off-by: James Perkins <james.perkins@linuxfoundation.org>
build
common_functions
init_buildsystem

diff --git a/build b/build
index 4c33734..70c1b36 100755 (executable)
--- a/build
+++ b/build
@@ -1423,7 +1423,13 @@ for SPECFILE in "${SPECFILES[@]}" ; do
        fi
 
        if check_use_emulator; then
-           vm_init_script="/.build/initscript_qemu_vm"
+           if [ -e $BUILD_DIR/initvm ]; then
+               vm_init_script="/.build/initvm"
+           elif [ -e $BUILD_DIR/initscript_qemu_vm ]; then
+               vm_init_script="/.build/initscript_qemu_vm"
+           else
+               echo "Warning: can't find initscript to register binfmts"
+           fi
        else
            vm_init_script="/.build/build"
        fi
index 6759a47..12258ba 100755 (executable)
@@ -61,13 +61,17 @@ check_use_emulator()
        return 0
     fi
 
-    # to run the qemu initialization in the XEN chroot, we need to register it with a statically build shell
+    # to run the qemu initialization in the XEN chroot, we need to
+    # register it with a static program or shell script
     case "$BUILD_HOST_ARCH" in
        i?86|x86_64)
-           if test -e /bin/bash-static \
+           if test -e /usr/lib/build/initvm && \
+               test -e /usr/lib/build/qemu-reg -o -e /.build/qemu-reg; then
+               return 0        # prefer initvm to handle registration
+           elif test -e /bin/bash-static \
                -a -e /bin/mount-static \
                -a -e /usr/sbin/qemu-binfmt-conf.sh; then
-               return 0
+               return 0        # as backup use /usr/sbin/qemu-binfmt.conf.sh
            else
                # XXX: error?
                echo "Warning: cross compile not possible due to missing static binaries"
index 294215c..457ec33 100755 (executable)
@@ -348,22 +348,45 @@ validate_cache_file()
 }
 
 #
-# Detect cross-build (fixed code) and copy qemus for cross-build emulation mode
-# And copy also a static host binary shell to run the init scripts in the target chroot
+# Copy qemu static binaries for cross-build emulation mode.
+# If initvm is available it will be in $BUILD_DIR; otherwise prepare to
+# fall back to initscript_qemu_vm shell script with corresponding static
+# bash and mount programs.
 #
 copy_qemu()
 {
+    local dev path
+
     echo "copying qemu"
-    mkdir -p  $BUILD_ROOT/usr/bin $BUILD_ROOT/usr/sbin
-    install -m755 /usr/bin/qemu-* $BUILD_ROOT/usr/bin
-    install -m755 /usr/sbin/qemu-binfmt-conf.sh $BUILD_ROOT/usr/sbin
-    # To initially run the init script, there needs to be also a
-    # static bash to register qemu in this chroot and to start up
-    # /.build/build
+
+    mkdir -p $BUILD_ROOT/usr/bin
+    for dev in $EMULATOR_DEVS; do
+       for path in /usr/bin/qemu-${dev}*; do
+           if file $path | grep -q static; then
+               if [ -f "$path" -a ! -x "$BUILD_ROOT/$path" ]; then
+                   echo -n " $path"                    # report copy
+                   install -m755 "$path" "$BUILD_ROOT/$path"
+               fi
+           fi
+       done
+    done
+    echo ""
+
+    # Below for backward compatibility when /.build/initvm is not present
+    if [ -e /usr/sbin/qemu-binfmt-conf.sh \
+       -a ! -e $BUILD_ROOT/usr/sbin/qemu-binfmt-conf.sh ]; then
+       echo " /usr/sbin/qemu-binfmt-conf.sh"           # report copy
+       mkdir -p $BUILD_ROOT/usr/sbin
+       install -m755 /usr/sbin/qemu-binfmt-conf.sh $BUILD_ROOT/usr/sbin
+    fi
+
     if [ -n "$PREPARE_VM" ]; then
-       mkdir -p  $BUILD_ROOT/bin
-       install -m755 /bin/bash-static $BUILD_ROOT/bin
-       install -m755 /bin/mount-static $BUILD_ROOT/bin
+       if [ -x /bin/bash-static -a -x /bin/mount-static ]; then
+           echo " /bin/bash-static /bin/mount-static"  # report copy
+           mkdir -p $BUILD_ROOT/bin
+           install -m755 /bin/bash-static $BUILD_ROOT/bin
+           install -m755 /bin/mount-static $BUILD_ROOT/bin
+       fi
     fi
 }
 
@@ -547,7 +570,18 @@ else
        if [ -z "$PREPARE_VM" ]; then
            if ! check_binfmt_registered; then
                echo "registering binfmt handlers"
-               /usr/sbin/qemu-binfmt-conf.sh
+               # prefer initvm over qemu-binfmt-conf.sh
+               success=false
+               for cmd in $BUILD_DIR/initvm /usr/sbin/qemu-binfmt-conf.sh
+               do
+                   if [ -x $cmd ] && $cmd; then
+                       success=true
+                       break
+                   fi
+               done
+               if [ success = false ]; then
+                   echo "Warning: could not register binfmt handlers"
+               fi
            fi
            read mmap_min_addr < /proc/sys/vm/mmap_min_addr
            if [ "$mmap_min_addr" != 0 ]; then