Skip to contentSkip to conversation

runqemu: Use OE_TMPDIR

PATCH In review Bernhard Reutner-Fischer 7 participants 17 messages May 3, 2012 – May 15, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/6 runqemu: Use OE_TMPDIR

The error message erroneously talked about TMPDIR.
Just use OE_TMPDIR everywhere to make the name of the variable obvious.

---
 scripts/runqemu |   27 +++++++++++----------------
 1 file changed, 11 insertions(+), 16 deletions(-)
scripts/runqemu +11 -16
index caabf61..7c2c4b3 100755
@@ -55,11 +55,6 @@ SCRIPT_QEMU_OPT=""
 SCRIPT_QEMU_EXTRA_OPT=""
 SCRIPT_KERNEL_OPT=""
 
-# Don't use TMPDIR from the external environment, it may be a distro
-# variable pointing to /tmp (e.g. within X on OpenSUSE)
-# Instead, use OE_TMPDIR for passing this in externally.
-TMPDIR="$OE_TMPDIR"
-
 # Determine whether the file is a kernel or QEMU image, and set the
 # appropriate variables
 process_filename() {
@@ -273,8 +268,8 @@ SPITZ_DEFAULT_KERNEL=zImage-spitz.bin
 SPITZ_DEFAULT_FSTYPE=ext3
 
 setup_tmpdir() {
-    if [ -z "$TMPDIR" ]; then
-        # Try to get TMPDIR from bitbake
+    if [ -z "$OE_TMPDIR" ]; then
+        # Try to get OE_TMPDIR from bitbake
         type -P bitbake &>/dev/null || {
             echo "In order for this script to dynamically infer paths";
             echo "to kernels or filesystem images, you either need";
@@ -282,11 +277,11 @@ setup_tmpdir() {
             echo "before running this script" >&2;
             exit 1; }
 
-        # We have bitbake in PATH, get TMPDIR from bitbake
-        TMPDIR=`bitbake -e | grep ^TMPDIR=\" | cut -d '=' -f2 | cut -d '"' -f2`
-        if [ -z "$TMPDIR" ]; then
+        # We have bitbake in PATH, get OE_TMPDIR from bitbake
+        OE_TMPDIR=`bitbake -e | grep ^TMPDIR=\" | cut -d '=' -f2 | cut -d '"' -f2`
+        if [ -z "$OE_TMPDIR" ]; then
             echo "Error: this script needs to be run from your build directory,"
-            echo "or you need to explicitly set TMPDIR in your environment"
+            echo "or you need to explicitly set OE_TMPDIR in your environment"
             exit 1
         fi
     fi
@@ -303,7 +298,7 @@ setup_sysroot() {
         BUILD_OS=`uname | tr '[A-Z]' '[a-z]'`
         BUILD_SYS="$BUILD_ARCH-$BUILD_OS"
 
-        OECORE_NATIVE_SYSROOT=$TMPDIR/sysroots/$BUILD_SYS
+        OECORE_NATIVE_SYSROOT=$OE_TMPDIR/sysroots/$BUILD_SYS
     fi 
 }
 
@@ -348,7 +343,7 @@ fi
 if [ -z "$KERNEL" ]; then
     setup_tmpdir
     eval kernel_file=\$${machine2}_DEFAULT_KERNEL
-    KERNEL=$TMPDIR/deploy/images/$kernel_file
+    KERNEL=$OE_TMPDIR/deploy/images/$kernel_file
 
     if [ -z "$KERNEL" ]; then
         echo "Error: Unable to determine default kernel for MACHINE [$MACHINE]"
@@ -372,13 +367,13 @@ fi
 # core-image-sato
 if [ "$LAZY_ROOTFS" = "true" ]; then
     setup_tmpdir
-    echo "Assuming $ROOTFS really means $TMPDIR/deploy/images/$ROOTFS-$MACHINE.$FSTYPE"
-    ROOTFS=$TMPDIR/deploy/images/$ROOTFS-$MACHINE.$FSTYPE
+    echo "Assuming $ROOTFS really means $OE_TMPDIR/deploy/images/$ROOTFS-$MACHINE.$FSTYPE"
+    ROOTFS=$OE_TMPDIR/deploy/images/$ROOTFS-$MACHINE.$FSTYPE
 fi
 
 if [ -z "$ROOTFS" ]; then
     setup_tmpdir
-    T=$TMPDIR/deploy/images
+    T=$OE_TMPDIR/deploy/images
     eval rootfs_list=\$${machine2}_DEFAULT_ROOTFS
     findimage $T $MACHINE $FSTYPE
 
Signature · 1 line
1.7.10
#1 lore raw

PATCH 2/6 runqemu: use modern, single-char name of test(1)

I do not have "[[", just "[". Be gentle to users of legacy-free setups, also by using '=' instead of the double notation.

---
 scripts/runqemu |   46 +++++++++++++++++++++++-----------------------
 1 file changed, 23 insertions(+), 23 deletions(-)
scripts/runqemu +23 -23
index 7c2c4b3..18fd691 100755
@@ -70,10 +70,10 @@ process_filename() {
             echo "Error: conflicting KERNEL args [$KERNEL] and [$filename]"
             usage
         fi
-    elif [[ "x$EXT" == "xext2" || "x$EXT" == "xext3" ||
-            "x$EXT" == "xjffs2" || "x$EXT" == "xbtrfs" ]]; then
+    elif [ "x$EXT" = "xext2" -o "x$EXT" = "xext3" -o \
+            "x$EXT" = "xjffs2" -o "x$EXT" = "xbtrfs" ]; then
         # A file ending in a supportted fs type is a rootfs image
-        if [[ -z "$FSTYPE" || "$FSTYPE" == "$EXT" ]]; then
+        if [ -z "$FSTYPE" -o "$FSTYPE" = "$EXT" ]; then
             FSTYPE=$EXT
             ROOTFS=$filename
         else
@@ -102,7 +102,7 @@ while [ $i -le $# ]; do
             fi
             ;;
         "ext2" | "ext3" | "jffs2" | "nfs" | "btrfs")
-            if [[ -z "$FSTYPE" || "$FSTYPE" == "$arg" ]]; then
+            if [ -z "$FSTYPE" -o "$FSTYPE" = "$arg" ]; then
                 FSTYPE=$arg
             else
                 echo "Error: conflicting FSTYPE types [$FSTYPE] and [$arg]"
@@ -143,7 +143,7 @@ while [ $i -le $# ]; do
             # to use simplified options instead
             serial_option=`expr "$SCRIPT_QEMU_EXTRA_OPT" : '.*\(-serial\)'`
             kvm_option=`expr "$SCRIPT_QEMU_EXTRA_OPT" : '.*\(-enable-kvm\)'`
-            if [[ ! -z "$serial_option" || ! -z "$kvm_option" ]]; then
+            if [ ! -z "$serial_option" -o ! -z "$kvm_option" ]; then
                 echo "Error: Please use simplified serial or kvm options instead"
                 usage
             fi
@@ -152,7 +152,7 @@ while [ $i -le $# ]; do
             SCRIPT_KERNEL_OPT="$SCRIPT_KERNEL_OPT ${arg##bootparams=}"
             ;;
         "audio")
-            if [[ "x$MACHINE" == "xqemux86" || "x$MACHINE" == "xqemux86-64" ]]; then
+            if [ "x$MACHINE" = "xqemux86" -o "x$MACHINE" = "xqemux86-64" ]; then
                 echo "Enable audio on qemu. Pls. install snd_intel8x0 or snd_ens1370 driver in linux guest.";
                 QEMU_AUDIO_DRV="alsa"
                 SCRIPT_QEMU_OPT="$SCRIPT_QEMU_OPT -soundhw ac97,es1370"
@@ -166,7 +166,7 @@ while [ $i -le $# ]; do
             # A directory name is an nfs rootfs
             if [ -d "$arg" ]; then
                 echo "Assuming $arg is an nfs rootfs"
-                if [[ -z "$FSTYPE" || "$FSTYPE" == "nfs" ]]; then
+                if [ -z "$FSTYPE" -o "$FSTYPE" = "nfs" ]; then
                     FSTYPE=nfs
                 else
                     echo "Error: conflicting FSTYPE types [$arg] and nfs"
@@ -200,13 +200,13 @@ fi
 
 YOCTO_KVM_WIKI="https://wiki.yoctoproject.org/wiki/How_to_enable_KVM_for_Poky_qemu"
 # Detect KVM configuration
-if [[ "x$KVM_ENABLED" == "xyes" ]]; then
-    if [[ -z "$KVM_CAPABLE" ]]; then
+if [ "x$KVM_ENABLED" = "xyes" ]; then
+    if [ -z "$KVM_CAPABLE" ]; then
         echo "You are tring to enable KVM on cpu without VT support. Remove kvm from the command-line, or refer";
         echo "$YOCTO_KVM_WIKI";
         exit 1;
     fi
-    if [[ "x$MACHINE" != "xqemux86" && "x$MACHINE" != "xqemux86-64" ]]; then
+    if [ "x$MACHINE" != "xqemux86" -a "x$MACHINE" != "xqemux86-64" ]; then
         echo "KVM only support x86 & x86-64. Remove kvm from the command-line";
         exit 1;
     fi
@@ -225,11 +225,11 @@ if [[ "x$KVM_ENABLED" == "xyes" ]]; then
 fi
 
 # Report errors for missing combinations of options
-if [[ -z "$MACHINE" && -z "$KERNEL" ]]; then
+if [ -z "$MACHINE" -a -z "$KERNEL" ]; then
     echo "Error: you must specify at least a MACHINE or KERNEL argument"
     usage
 fi
-if [[ "$FSTYPE" == "nfs" && -z "$ROOTFS" ]]; then
+if [ "$FSTYPE" = "nfs" -a -z "$ROOTFS" ]; then
     echo "Error: NFS booting without an explicit ROOTFS path is not yet supported"
     usage
 fi
@@ -313,11 +313,11 @@ findimage() {
     # recently created one is the one we most likely want to boot.
     filenames=`ls -t $where/*-image*$machine.$extension 2>/dev/null | xargs`
     for name in $filenames; do
-        if [[ "$name" =~ core-image-sato-sdk ||
-              "$name" =~ core-image-sato     ||
-              "$name" =~ core-image-lsb      ||
-              "$name" =~ core-image-basic    ||
-              "$name" =~ core-image-minimal ]]; then
+        if [ "$name" =~ core-image-sato-sdk -o \
+              "$name" =~ core-image-sato     -o \
+              "$name" =~ core-image-lsb      -o \
+              "$name" =~ core-image-basic    -o \
+              "$name" =~ core-image-minimal ]; then
             ROOTFS=$name
             return
         fi	
@@ -327,11 +327,11 @@ findimage() {
     exit 1
 }
 
-if [[ -e "$ROOTFS" && -z "$FSTYPE" ]]; then
+if [ -e "$ROOTFS" -a -z "$FSTYPE" ]; then
     # Extract the filename extension
     EXT=`echo $ROOTFS | awk -F . '{ print \$NF }'`
-    if [[ "x$EXT" == "xext2" || "x$EXT" == "xext3" || 
-          "x$EXT" == "xjffs2" || "x$EXT" == "xbtrfs" ]]; then
+    if [ "x$EXT" = "xext2" -o "x$EXT" = "xext3" -o \
+          "x$EXT" = "xjffs2" -o "x$EXT" = "xbtrfs" ]; then
         FSTYPE=$EXT
     else
         echo "Note: Unable to determine filesystem extension for $ROOTFS"
@@ -396,9 +396,9 @@ setup_sysroot
 # We can't run without a libGL.so
 libgl='no'
 
-test -e /usr/lib/libGL.so -a -e /usr/lib/libGLU.so && libgl='yes'
-test -e /usr/lib64/libGL.so -a -e /usr/lib64/libGLU.so && libgl='yes'
-test -e /usr/lib/*-linux-gnu/libGL.so -a -e /usr/lib/*-linux-gnu/libGLU.so && libgl='yes'
+[ -e /usr/lib/libGL.so -a -e /usr/lib/libGLU.so ] && libgl='yes'
+[ -e /usr/lib64/libGL.so -a -e /usr/lib64/libGLU.so ] && libgl='yes'
+[ -e /usr/lib/*-linux-gnu/libGL.so -a -e /usr/lib/*-linux-gnu/libGLU.so ] && libgl='yes'
 
 if [ "$libgl" != 'yes' ]; then
     echo "You need libGL.so and libGLU.so to exist in your library path to run the QEMU emulator.
Signature · 1 line
1.7.10
#2 lore raw

Re: [PATCH 2/6] runqemu: use modern, single-char name of test(1)

Quoted 7 lines · Bernhard Reutner-Fischer
scripts/runqemu +0 -3
@@ -313,11 +313,11 @@ findimage() {
      # recently created one is the one we most likely want to boot.
      filenames=`ls -t $where/*-image*$machine.$extension 2>/dev/null | xargs`
      for name in $filenames; do
-        if [[ "$name" =~ core-image-sato-sdk ||
-              "$name" =~ core-image-sato     ||
-              "$name" =~ core-image-lsb      ||

scripts/runqemu findimage() { · line 323

Quoted 10 lines
scripts/runqemu +5 -2
-              "$name" =~ core-image-basic    ||
-              "$name" =~ core-image-minimal ]]; then
+        if [ "$name" =~ core-image-sato-sdk -o \
+              "$name" =~ core-image-sato     -o \
+              "$name" =~ core-image-lsb      -o \
+              "$name" =~ core-image-basic    -o \
+              "$name" =~ core-image-minimal ]; then
              ROOTFS=$name
              return
          fi	

This change broke findimage() for me on both bash and dash. Reproducer is 'runqemu qemux86'.

Under bash I get:

/srv/yocto/poky/scripts/runqemu: line 303: [: too many arguments

Undoing this change fixes things for me. Note: this change doesn't revert cleanly.

I've filed this as Yocto #2433:
https://bugzilla.yoctoproject.org/show_bug.cgi?id=2433

As an aside, when trying (unsuccessfully) to figure out a fix for this I ran across Ubuntu's page on dash[1] which indicates changing || for -o isn't right. Anyone have a strong opinion on that?

Cheers,
Joshua

1. https://wiki.ubuntu.com/DashAsBinSh

Signature · 3 lines
Joshua Lock
        Yocto Project
        Intel Open Source Technology Centre
#3 lore raw

Re: [PATCH 2/6] runqemu: use modern, single-char name of test(1)

Quoted 29 lines · Joshua Lock
Quoted 7 lines · Bernhard Reutner-Fischer
scripts/runqemu +0 -3
@@ -313,11 +313,11 @@ findimage() {
     # recently created one is the one we most likely want to boot.
     filenames=`ls -t $where/*-image*$machine.$extension 2>/dev/null | xargs`
     for name in $filenames; do
-        if [[ "$name" =~ core-image-sato-sdk ||
-              "$name" =~ core-image-sato     ||
-              "$name" =~ core-image-lsb      ||

scripts/runqemu findimage() { · line 323

Quoted 10 lines
scripts/runqemu +5 -2
-              "$name" =~ core-image-basic    ||
-              "$name" =~ core-image-minimal ]]; then
+        if [ "$name" =~ core-image-sato-sdk -o \
+              "$name" =~ core-image-sato     -o \
+              "$name" =~ core-image-lsb      -o \
+              "$name" =~ core-image-basic    -o \
+              "$name" =~ core-image-minimal ]; then
             ROOTFS=$name
             return
         fi	

This change broke findimage() for me on both bash and dash. Reproducer is 'runqemu qemux86'.

Under bash I get:

/srv/yocto/poky/scripts/runqemu: line 303: [: too many arguments

Undoing this change fixes things for me. Note: this change doesn't revert cleanly.

Quoted 6 lines

I've filed this as Yocto #2433:
https://bugzilla.yoctoproject.org/show_bug.cgi?id=2433

As an aside, when trying (unsuccessfully) to figure out a fix for this I ran across Ubuntu's page on dash[1] which indicates changing || for -o isn't right. Anyone have a strong opinion on that?

just a weak. That whole style is utterly broken.
case "$name" in
core-image-sato-sdk*|blah)
esac

Really that whole name hardcoding is plain stupid and over-engineered. If the darn image exists then, heck, just use it.

But that's politics i fear -- not even sure if that intel-guy ment to imply that, though. Somehow doubt it |-/

Any sane way out of that mess?

Quoted 5 lines

Cheers,
Joshua

1. https://wiki.ubuntu.com/DashAsBinSh

#4 lore raw

Re: [PATCH 2/6] runqemu: use modern, single-char name of test(1)

Quoted 2 lines · Bernhard Reutner-Fischer

Any sane way out of that mess?

there is a patch to fix it differently on ml.

#5 lore raw

Re: [PATCH 2/6] runqemu: use modern, single-char name of test(1)

In reply to Bernhard Reutner-Fischer
Quoted 2 lines · On Tue, 15 May 2012 21:59:15 +0200 Bernhard Reutner-Fischer…

Really that whole name hardcoding is plain stupid and over-engineered. If the darn image exists then, heck, just use it.

This may not be a bad idea, but it's a larger change than I wanted to make, which is why I didn't change the effect as a whole in the proposed patch.

-s

Signature · 1 line
Listen, get this.  Nobody with a good compiler needs to be justified.
#6 lore raw

PATCH 3/6 runqemu: simplify process_filename()

In reply to Bernhard Reutner-Fischer
---
 scripts/runqemu |   47 +++++++++++++++++++++++++----------------------
 1 file changed, 25 insertions(+), 22 deletions(-)
scripts/runqemu +25 -22
index 18fd691..dfa7f4b 100755
@@ -62,28 +62,31 @@ process_filename() {
 
     # Extract the filename extension
     EXT=`echo $filename | awk -F . '{ print \$NF }'`
-    # A file ending in .bin is a kernel
-    if [ "x$EXT" = "xbin" ]; then
-        if [ -z "$KERNEL" ]; then
-            KERNEL=$filename
-        else
-            echo "Error: conflicting KERNEL args [$KERNEL] and [$filename]"
-            usage
-        fi
-    elif [ "x$EXT" = "xext2" -o "x$EXT" = "xext3" -o \
-            "x$EXT" = "xjffs2" -o "x$EXT" = "xbtrfs" ]; then
-        # A file ending in a supportted fs type is a rootfs image
-        if [ -z "$FSTYPE" -o "$FSTYPE" = "$EXT" ]; then
-            FSTYPE=$EXT
-            ROOTFS=$filename
-        else
-            echo "Error: conflicting FSTYPE types [$FSTYPE] and [$EXT]"
-            usage
-        fi
-    else
-       echo "Error: unknown file arg [$filename]"
-       usage
-    fi
+    case /$EXT/ in
+	/bin/)
+		# A file ending in .bin is a kernel
+		if [ -z "$KERNEL" ]; then
+		    KERNEL=$filename
+		else
+		    echo "Error: conflicting KERNEL args [$KERNEL] and [$filename]"
+		    usage
+		fi
+		;;
+	/ext[234]/|/jffs2/|/btrfs/)
+		# A file ending in a supportted fs type is a rootfs image
+		if [ -z "$FSTYPE" -o "$FSTYPE" = "$EXT" ]; then
+		    FSTYPE=$EXT
+		    ROOTFS=$filename
+		else
+		    echo "Error: conflicting FSTYPE types [$FSTYPE] and [$EXT]"
+		    usage
+		fi
+		;;
+	*)
+		echo "Error: unknown file arg [$filename]"
+		usage
+		;;
+    esac
 }
 
 # Parse command line args without requiring specific ordering. It's a
Signature · 1 line
1.7.10
#7 lore raw

PATCH 4/6 runqemu: add and use error()

In reply to Bernhard Reutner-Fischer
---
 scripts/runqemu |   71 ++++++++++++++++++++-----------------------------------
 1 file changed, 25 insertions(+), 46 deletions(-)
scripts/runqemu +25 -46
index dfa7f4b..231b1bf 100755
@@ -46,6 +46,11 @@ if [ "x$1" = "x" ]; then
     usage
 fi
 
+error() {
+    echo "Error: "$*
+    usage
+}
+
 MACHINE=${MACHINE:=""}
 KERNEL=""
 FSTYPE=""
@@ -65,12 +70,8 @@ process_filename() {
     case /$EXT/ in
 	/bin/)
 		# A file ending in .bin is a kernel
-		if [ -z "$KERNEL" ]; then
-		    KERNEL=$filename
-		else
-		    echo "Error: conflicting KERNEL args [$KERNEL] and [$filename]"
-		    usage
-		fi
+		[ -z "$KERNEL" ] && KERNEL=$filename || \
+		    error "conflicting KERNEL args [$KERNEL] and [$filename]"
 		;;
 	/ext[234]/|/jffs2/|/btrfs/)
 		# A file ending in a supportted fs type is a rootfs image
@@ -78,13 +79,11 @@ process_filename() {
 		    FSTYPE=$EXT
 		    ROOTFS=$filename
 		else
-		    echo "Error: conflicting FSTYPE types [$FSTYPE] and [$EXT]"
-		    usage
+		    error "conflicting FSTYPE types [$FSTYPE] and [$EXT]"
 		fi
 		;;
 	*)
-		echo "Error: unknown file arg [$filename]"
-		usage
+		error "unknown file arg [$filename]"
 		;;
     esac
 }
@@ -97,20 +96,12 @@ while [ $i -le $# ]; do
     arg=${!i}
     case $arg in
         "qemux86" | "qemux86-64" | "qemuarm" | "qemumips" | "qemuppc")
-            if [ -z "$MACHINE" ]; then
-                MACHINE=$arg
-            else
-                echo "Error: conflicting MACHINE types [$MACHINE] and [$arg]"
-                usage
-            fi
+            [ -z "$MACHINE" ] && MACHINE=$arg || \
+                error "conflicting MACHINE types [$MACHINE] and [$arg]"
             ;;
         "ext2" | "ext3" | "jffs2" | "nfs" | "btrfs")
-            if [ -z "$FSTYPE" -o "$FSTYPE" = "$arg" ]; then
-                FSTYPE=$arg
-            else
-                echo "Error: conflicting FSTYPE types [$FSTYPE] and [$arg]"
-                usage
-            fi
+            [ -z "$FSTYPE" -o "$FSTYPE" = "$arg" ] && FSTYPE=$arg || \
+                error "conflicting FSTYPE types [$FSTYPE] and [$arg]"
             ;;
         *-image*)
             if [ -z "$ROOTFS" ]; then
@@ -127,8 +118,7 @@ while [ $i -le $# ]; do
                     LAZY_ROOTFS="true"
                 fi
             else
-                echo "Error: conflicting ROOTFS args [$ROOTFS] and [$arg]"
-                usage
+                error "conflicting ROOTFS args [$ROOTFS] and [$arg]"
             fi
             ;;
         "nographic")
@@ -146,10 +136,8 @@ while [ $i -le $# ]; do
             # to use simplified options instead
             serial_option=`expr "$SCRIPT_QEMU_EXTRA_OPT" : '.*\(-serial\)'`
             kvm_option=`expr "$SCRIPT_QEMU_EXTRA_OPT" : '.*\(-enable-kvm\)'`
-            if [ ! -z "$serial_option" -o ! -z "$kvm_option" ]; then
-                echo "Error: Please use simplified serial or kvm options instead"
-                usage
-            fi
+            [ ! -z "$serial_option" -o ! -z "$kvm_option" ] && \
+                error "Please use simplified serial or kvm options instead"
             ;;
         "bootparams="*)
             SCRIPT_KERNEL_OPT="$SCRIPT_KERNEL_OPT ${arg##bootparams=}"
@@ -172,21 +160,18 @@ while [ $i -le $# ]; do
                 if [ -z "$FSTYPE" -o "$FSTYPE" = "nfs" ]; then
                     FSTYPE=nfs
                 else
-                    echo "Error: conflicting FSTYPE types [$arg] and nfs"
-                    usage
+                    error "conflicting FSTYPE types [$arg] and nfs"
                 fi
 
                 if [ -z "$ROOTFS" ]; then
                     ROOTFS=$arg
                 else
-                    echo "Error: conflicting ROOTFS args [$ROOTFS] and [$arg]"
-                    usage
+                    error "conflicting ROOTFS args [$ROOTFS] and [$arg]"
                 fi
             elif [ -f "$arg" ]; then
                 process_filename $arg
             else
-                echo "Error: unable to classify arg [$arg]"
-                usage
+                error "unable to classify arg [$arg]"
             fi
             ;;
     esac
@@ -229,19 +214,16 @@ fi
 
 # Report errors for missing combinations of options
 if [ -z "$MACHINE" -a -z "$KERNEL" ]; then
-    echo "Error: you must specify at least a MACHINE or KERNEL argument"
-    usage
+    error "you must specify at least a MACHINE or KERNEL argument"
 fi
 if [ "$FSTYPE" = "nfs" -a -z "$ROOTFS" ]; then
-    echo "Error: NFS booting without an explicit ROOTFS path is not yet supported"
-    usage
+    error "NFS booting without an explicit ROOTFS path is not yet supported"
 fi
 
 if [ -z "$MACHINE" ]; then
     MACHINE=`basename $KERNEL | sed 's/.*-\(qemux86-64\|qemux86\|qemuarm\|qemumips\|qemuppc\).*/\1/'`
     if [ -z "$MACHINE" ]; then
-        echo "Error: Unable to set MACHINE from kernel filename [$KERNEL]"
-        usage
+        error "Unable to set MACHINE from kernel filename [$KERNEL]"
     fi
     echo "Set MACHINE to [$MACHINE] based on kernel [$KERNEL]"
 fi
@@ -349,8 +331,7 @@ if [ -z "$KERNEL" ]; then
     KERNEL=$OE_TMPDIR/deploy/images/$kernel_file
 
     if [ -z "$KERNEL" ]; then
-        echo "Error: Unable to determine default kernel for MACHINE [$MACHINE]"
-        usage
+        error "Unable to determine default kernel for MACHINE [$MACHINE]"
     fi
 fi
 # KERNEL is now set for all cases
@@ -359,8 +340,7 @@ if [ -z "$FSTYPE" ]; then
     eval FSTYPE=\$${machine2}_DEFAULT_FSTYPE
 
     if [ -z "$FSTYPE" ]; then
-        echo "Error: Unable to determine default fstype for MACHINE [$MACHINE]"
-        usage
+        error "Unable to determine default fstype for MACHINE [$MACHINE]"
     fi
 fi
 
@@ -381,8 +361,7 @@ if [ -z "$ROOTFS" ]; then
     findimage $T $MACHINE $FSTYPE
 
     if [ -z "$ROOTFS" ]; then
-        echo "Error: Unable to determine default rootfs for MACHINE [$MACHINE]"
-        usage
+        error "Unable to determine default rootfs for MACHINE [$MACHINE]"
     fi
 fi
 # ROOTFS is now set for all cases
Signature · 1 line
1.7.10
#8 lore raw

PATCH 5/6 runqemu: minor tweaks

In reply to Bernhard Reutner-Fischer
---
 scripts/runqemu |   40 +++++++++++++++++++++-------------------
 1 file changed, 21 insertions(+), 19 deletions(-)
scripts/runqemu +21 -19
index 231b1bf..000d93a 100755
@@ -104,21 +104,19 @@ while [ $i -le $# ]; do
                 error "conflicting FSTYPE types [$FSTYPE] and [$arg]"
             ;;
         *-image*)
-            if [ -z "$ROOTFS" ]; then
-                if [ -f "$arg" ]; then
-                    process_filename $arg
-                elif [ -d "$arg" ]; then
-                    # Handle the case where the nfsroot dir has -image-
-                    # in the pathname
-                    echo "Assuming $arg is an nfs rootfs"
-                    FSTYPE=nfs
-                    ROOTFS=$arg
-                else
-                    ROOTFS=$arg
-                    LAZY_ROOTFS="true"
-                fi
+            [ -z "$ROOTFS" ] || \
+		error "conflicting ROOTFS args [$ROOTFS] and [$arg]"
+            if [ -f "$arg" ]; then
+                process_filename $arg
+            elif [ -d "$arg" ]; then
+                # Handle the case where the nfsroot dir has -image-
+                # in the pathname
+                echo "Assuming $arg is an nfs rootfs"
+                FSTYPE=nfs
+                ROOTFS=$arg
             else
-                error "conflicting ROOTFS args [$ROOTFS] and [$arg]"
+                ROOTFS=$arg
+                LAZY_ROOTFS="true"
             fi
             ;;
         "nographic")
@@ -144,14 +142,15 @@ while [ $i -le $# ]; do
             ;;
         "audio")
             if [ "x$MACHINE" = "xqemux86" -o "x$MACHINE" = "xqemux86-64" ]; then
-                echo "Enable audio on qemu. Pls. install snd_intel8x0 or snd_ens1370 driver in linux guest.";
+                echo "Enabling audio in qemu."
+                echo "Please install snd_intel8x0 or snd_ens1370 driver in linux guest."
                 QEMU_AUDIO_DRV="alsa"
                 SCRIPT_QEMU_OPT="$SCRIPT_QEMU_OPT -soundhw ac97,es1370"
             fi
             ;;
         "kvm")
             KVM_ENABLED="yes"
-            KVM_CAPABLE=`grep 'vmx\|smx' /proc/cpuinfo`
+            KVM_CAPABLE=`grep -q 'vmx\|smx' /proc/cpuinfo && echo 1`
             ;;
         *)
             # A directory name is an nfs rootfs
@@ -190,7 +189,8 @@ YOCTO_KVM_WIKI="https://wiki.yoctoproject.org/wiki/How_to_enable_KVM_for_Poky_qe
 # Detect KVM configuration
 if [ "x$KVM_ENABLED" = "xyes" ]; then
     if [ -z "$KVM_CAPABLE" ]; then
-        echo "You are tring to enable KVM on cpu without VT support. Remove kvm from the command-line, or refer";
+        echo "You are trying to enable KVM on a cpu without VT support."
+        echo "Remove kvm from the command-line, or refer"
         echo "$YOCTO_KVM_WIKI";
         exit 1;
     fi
@@ -199,14 +199,16 @@ if [ "x$KVM_ENABLED" = "xyes" ]; then
         exit 1;
     fi
     if [ ! -e /dev/kvm ]; then
-        echo "Missing KVM device. Have you inserted kvm modules? Pls. refer";
+        echo "Missing KVM device. Have you inserted kvm modules?"
+        echo "For further help see"
         echo "$YOCTO_KVM_WIKI";
         exit 1;
     fi
     if 9<>/dev/kvm ; then
         SCRIPT_QEMU_OPT="$SCRIPT_QEMU_OPT -enable-kvm"
     else
-        echo "You have no rights on /dev/kvm. Pls. change the owndership as described at";
+        echo "You have no rights on /dev/kvm."
+        echo "Please change the ownership of this file as described at"
         echo "$YOCTO_KVM_WIKI";
         exit 1;
     fi
Signature · 1 line
1.7.10
#9 lore raw

PATCH 6/6 runqemu: be sh neutral

In reply to Bernhard Reutner-Fischer

Now runs with dash and busybox' ash as well as with bash

---
 scripts/runqemu          |   13 ++++++++-----
 scripts/runqemu-internal |   16 ++++++++--------
 2 files changed, 16 insertions(+), 13 deletions(-)
scripts/runqemu +8 -5
index 000d93a..305e46a 100755
@@ -91,10 +91,9 @@ process_filename() {
 # Parse command line args without requiring specific ordering. It's a
 # bit more complex, but offers a great user experience.
 KVM_ENABLED="no"
-i=1
-while [ $i -le $# ]; do
-    arg=${!i}
-    case $arg in
+while true; do
+    arg=${1}
+    case "$arg" in
         "qemux86" | "qemux86-64" | "qemuarm" | "qemumips" | "qemuppc")
             [ -z "$MACHINE" ] && MACHINE=$arg || \
                 error "conflicting MACHINE types [$MACHINE] and [$arg]"
@@ -152,6 +151,7 @@ while [ $i -le $# ]; do
             KVM_ENABLED="yes"
             KVM_CAPABLE=`grep -q 'vmx\|smx' /proc/cpuinfo && echo 1`
             ;;
+        "") break ;;
         *)
             # A directory name is an nfs rootfs
             if [ -d "$arg" ]; then
@@ -174,7 +174,7 @@ while [ $i -le $# ]; do
             fi
             ;;
     esac
-    i=$((i + 1))
+    shift
 done
 
 if [ ! -c /dev/net/tun ] ; then
@@ -391,6 +391,9 @@ if [ "$libgl" != 'yes' ]; then
     exit 1;
 fi
 
+INTERNAL_SCRIPT="$0-internal"
+if [ ! -f "$INTERNAL_SCRIPT" -o ! -r "$INTERNAL_SCRIPT" ]; then
 INTERNAL_SCRIPT=`which runqemu-internal`
+fi
 
 . $INTERNAL_SCRIPT
scripts/runqemu-internal +8 -8
index 1831a09..80a6d3c 100755
@@ -69,7 +69,7 @@ QEMU_MEMORY="$mem_size"M
 
 # Bug 433: qemuarm cannot use > 256 MB RAM
 if [ "$MACHINE" = "qemuarm" ]; then
-    if [[ -z "$mem_size" || $mem_size -gt 256 ]]; then
+    if [ -z "$mem_size" -o $mem_size -gt 256 ]; then
         echo "WARNING: qemuarm does not support > 256M of RAM."
         echo "Changing QEMU_MEMORY to default of 256M."
         QEMU_MEMORY="256M"
@@ -111,7 +111,7 @@ acquire_lock() {
 
     if [ -e "$lockfile.lock" ]; then
         # Check that the lockfile is not stale
-        ps=`ps -ewwo pid | grep $(cat $lockfile.lock)`
+        ps=`ps -eo pid | grep $(cat $lockfile.lock)`
         if [ -z "$ps" ]; then
             echo "WARNING: Stale lock file detected, deleting $lockfile.lock."
             rm -f $lockfile.lock
@@ -211,8 +211,9 @@ cleanup() {
     stty sane
 }
 
-n1=$[ (`echo $TAP | sed 's/tap//'` * 2) + 1 ]
-n2=$[ (`echo $TAP | sed 's/tap//'` * 2) + 2 ]
+n0=$(echo $TAP | sed 's/tap//')
+n1=$(($n0 * 2 + 1))
+n2=$(($n1 + 1))
 
 KERNEL_NETWORK_CMD="ip=192.168.7.$n2::192.168.7.$n1:255.255.255.0"
 QEMU_TAP_CMD="-net tap,vlan=0,ifname=$TAP,script=no,downscript=no"
@@ -436,7 +437,7 @@ if [ ! -x "$QEMUBIN" ]; then
     return
 fi
 
-function _quit() {
+do_quit() {
     if [ -n "$PIDFILE" ]; then
         #echo kill `cat $PIDFILE`
         kill `cat $PIDFILE`
@@ -448,7 +449,7 @@ function _quit() {
 DISTCCD=`which distccd 2> /dev/null`
 PIDFILE=""
 
-trap _quit INT TERM QUIT
+trap do_quit INT TERM QUIT
 
 if [ -x "$DISTCCD" ]; then
     echo "Starting distccd..."
@@ -475,7 +476,7 @@ if grep -i ubuntu /etc/lsb-release &> /dev/null
 then
     # precede nvidia's driver on Ubuntu 10
     UBUNTU_MAIN_VERSION=`cat /etc/lsb-release |grep DISTRIB_RELEASE |cut -d=  -f 2| cut -d. -f 1`
-    if [ $UBUNTU_MAIN_VERSION -eq 10 ];
+    if [ "$UBUNTU_MAIN_VERSION" = "10" ];
     then
         GL_PATH=""
         if test -e /usr/lib/libGL.so
@@ -501,4 +502,3 @@ LD_PRELOAD="$GL_LD_PRELOAD" $QEMUBIN -kernel $KERNEL $QEMUOPTIONS $SERIALOPTS -n
 cleanup
 
 trap - INT TERM QUIT
-return
Signature · 1 line
1.7.10
#10 lore raw
In reply to Bernhard Reutner-Fischer
Quoted 4 lines · Bernhard Reutner-Fischer

The error message erroneously talked about TMPDIR.
Just use OE_TMPDIR everywhere to make the name of the variable obvious.

Bernhard, these are great improvements - thanks for refactoring this!

Full series Acked-by: Scott Garman <[email protected]>

Scott

Signature · 3 lines
Scott Garman
Embedded Linux Engineer - Yocto Project
Intel Open Source Technology Center
#11 lore raw
In reply to Bernhard Reutner-Fischer
Quoted 4 lines · Bernhard Reutner-Fischer

The error message erroneously talked about TMPDIR.
Just use OE_TMPDIR everywhere to make the name of the variable obvious.

Bernhard,

This change wasn't well-tested and has broken the runqemu script for both bash and dash. :(

From what I can tell, the =~ regex operator is a bashism. It's also one that helps a lot with the code readability. So now that we're faced with re-writing the script to avoid using that operator, I'm having second thoughts about whether the runqemu script really needs to be shell-agnostic. The alternative of invoking grep or other commands to process the name patterns does not appeal to me.

I can understand why we're trying to ensure our build system doesn't require /bin/sh to be bash, but I think support scripts like runqemu might be a special case.

What do other people in the community think of this? The runqemu script isn't trivial, and it has to run in a lot of different contexts. Should we put the time in to make it shell-agnostic, or allow it to require bash?

Scott

Signature · 3 lines
Scott Garman
Embedded Linux Engineer - Yocto Project
Intel Open Source Technology Center
#12 lore raw
Quoted 7 lines · On Mon, 7 May 2012 16:56:11 -0700 Scott Garman <[email protected]> wrote:

From what I can tell, the =~ regex operator is a bashism. It's also
one that helps a lot with the code readability. So now that we're faced with re-writing the script to avoid using that operator, I'm having second thoughts about whether the runqemu script really needs to be shell-agnostic. The alternative of invoking grep or other commands to process the name patterns does not appeal to me.

Quoted 8 lines

I can understand why we're trying to ensure our build system doesn't require /bin/sh to be bash, but I think support scripts like runqemu might be a special case.

What do other people in the community think of this? The runqemu script isn't trivial, and it has to run in a lot of different contexts. Should we put the time in to make it shell-agnostic, or allow it to require bash?

Hmm. I am honestly not a big fan of the =~, simply because I almost never remember it, and I can never think whether it's like perl's ~= or Lua's ~=. (One is "matches", the other is "is not".)

I tend to write stuff like this as

case $name in
*pat1* | *pat2* | ... )

  # code goes here
  ;;
esac

because that's the natural shell idiom. It can't do full regex processing, but we really don't need that here; we just want an unanchored pattern match. (And I'm not even sure we *want* a fully-unanchored match.) I think the bash [[ ]] thing is one of the kshisms, but "bash or ksh" is not much better. :P

From a maintenance standpoint, I like the case construct better than [[]]. My interest in reading the bash man page to figure out what some unfamiliar bit of punctuation means this week has declined over the years.

-s

Signature · 1 line
Listen, get this.  Nobody with a good compiler needs to be justified.
#13 lore raw
Quoted 14 lines · Peter Seebach
Quoted 11 lines · On Mon, 7 May 2012 16:56:11 -0700 Scott Garman<[email protected]> wrote:

From what I can tell, the =~ regex operator is a bashism. It's also
one that helps a lot with the code readability. So now that we're faced with re-writing the script to avoid using that operator, I'm having second thoughts about whether the runqemu script really needs to be shell-agnostic. The alternative of invoking grep or other commands to process the name patterns does not appeal to me.

I can understand why we're trying to ensure our build system doesn't require /bin/sh to be bash, but I think support scripts like runqemu might be a special case.

Quoted 8 lines
Quoted 4 lines

What do other people in the community think of this? The runqemu script isn't trivial, and it has to run in a lot of different contexts. Should we put the time in to make it shell-agnostic, or allow it to require bash?

Hmm. I am honestly not a big fan of the =~, simply because I almost never remember it, and I can never think whether it's like perl's ~= or Lua's ~=. (One is "matches", the other is "is not".)

It's actually worse then =~ is a bashism, it's a specific version of bash. I'm using bash as my shell, and it simply doesn't work my system.

The following works for me:

scripts/runqemu +8 -6
@@ -300,14 +300,16 @@ findimage() {
     # recently created one is the one we most likely want to boot.
     filenames=`ls -t $where/*-image*$machine.$extension 2>/dev/null | xargs`
     for name in $filenames; do
-        if [ "$name" =~ core-image-sato-sdk -o \
-              "$name" =~ core-image-sato     -o \
-              "$name" =~ core-image-lsb      -o \
-              "$name" =~ core-image-basic    -o \
-              "$name" =~ core-image-minimal ]; then
+       case $name in
+          *core-image-sato-sdk* | \
+          *core-image-sato* | \
+          *core-image-lsb* | \
+          *core-image-basic* | \
+          *core-image-minimal*)
             ROOTFS=$name
             return
-        fi
+           ;;
+       esac
     done
 
     echo "Couldn't find a $machine rootfs image in $where."
Quoted 14 lines

I tend to write stuff like this as

case $name in
*pat1* | *pat2* | ... )

   # code goes here
   ;;
esac

because that's the natural shell idiom. It can't do full regex processing, but we really don't need that here; we just want an unanchored pattern match. (And I'm not even sure we *want* a fully-unanchored match.) I think the bash [[ ]] thing is one of the kshisms, but "bash or ksh" is not much better. :P

Quoted 4 lines

From a maintenance standpoint, I like the case construct better
than [[]]. My interest in reading the bash man page to figure out what some unfamiliar bit of punctuation means this week has declined over the years.

I agree, besides the =~ doesn't work at all of me..

[mhatle@msp-mhatle-lx2 build-ia32-4]$ bash --version
GNU bash, version 4.1.7(1)-release (x86_64-redhat-linux-gnu) Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.

that is on FC-13. (ya, I know it's old.. but it's intentional we support older machines.)

--Mark

Quoted 1 line

-s

#14 lore raw
Quoted 24 lines · Mark Hatle
scripts/runqemu +0 -0
@@ -300,14 +300,16 @@ findimage() {
     # recently created one is the one we most likely want to boot.

    filenames=ls -t $where/*-image*$machine.$extension 2>/dev/null | xargs for name in $filenames; do
-        if [ "$name" =~ core-image-sato-sdk -o \
-              "$name" =~ core-image-sato     -o \
-              "$name" =~ core-image-lsb      -o \
-              "$name" =~ core-image-basic    -o \
-              "$name" =~ core-image-minimal ]; then
+       case $name in
+          *core-image-sato-sdk* | \
+          *core-image-sato* | \
+          *core-image-lsb* | \
+          *core-image-basic* | \
+          *core-image-minimal*)
            ROOTFS=$name
            return
-        fi
+           ;;
+       esac
    done

Quoted 1 line

    echo "Couldn't find a $machine rootfs image in $where."

thats a better thing can you formulate it into a patch please.

#15 lore raw
In reply to Scott Garman
Quoted 8 lines · Scott Garman

I can understand why we're trying to ensure our build system doesn't require /bin/sh to be bash, but I think support scripts like runqemu might be a special case.

What do other people in the community think of this? The runqemu script isn't trivial, and it has to run in a lot of different contexts. Should we put the time in to make it shell-agnostic, or allow it to require bash?

1) Do not require /bin/sh to be bash
2) It's ok, and for "right tool for the job" -reasons often prefered,
to require that development machine has also bash installed.

So I'm happy with how runqemu currently has #!/bin/bash shebang. It
requires bash to be present, but not necessarily as /bin/sh

- ML

#16 lore raw
Quoted 10 lines · Marko Lindqvist
Quoted 8 lines · Scott Garman

I can understand why we're trying to ensure our build system doesn't require /bin/sh to be bash, but I think support scripts like runqemu might be a special case.

What do other people in the community think of this? The runqemu script isn't trivial, and it has to run in a lot of different contexts. Should we put the time in to make it shell-agnostic, or allow it to require bash?

Quoted 6 lines

1) Do not require /bin/sh to be bash
2) It's ok, and for "right tool for the job" -reasons often prefered,
to require that development machine has also bash installed.

So I'm happy with how runqemu currently has #!/bin/bash shebang. It
requires bash to be present, but not necessarily as /bin/sh

I don't mind it using bash as long as it has bash-isms. Note, the recent =~ stuff didn't work on my machine, even with bash.

--Mark

Quoted 7 lines

- ML

_______________________________________________
Openembedded-core mailing list
[email protected]
http://lists.linuxtogo.org/cgi-bin/mailman/listinfo/openembedded-core