tools/patchelf: update to 0.18.0
[openwrt/staging/dedeckeh.git] / scripts / qemustart
index 8daeac69a86d3db65f54d15bdae46f621ef3bbbf..764b0e65afa24bb9f0d25eb19a0ac8b7c5631538 100755 (executable)
@@ -124,6 +124,11 @@ parse_args() {
        o_network=
        o_qemu_extra=()
        while [ "$#" -gt 0 ]; do
+               # Cmdline options for the script itself SHOULD try to be
+               # prefixed with two dashes to distinguish them from those for
+               # qemu executables.
+               #
+               # Also note that qemu accepts both --opt and -opt
                case "$1" in
                        --kernel) o_kernel="$2"; shift 2 ;;
                        --rootfs) o_rootfs="$2"; shift 2 ;;
@@ -153,7 +158,8 @@ parse_args() {
                return 1
        }
        [ -n "$o_subtarget" ] || o_subtarget="generic"
-       o_bindir="bin/targets/$o_target/$o_subtarget"
+       eval "$(grep ^CONFIG_BINARY_FOLDER= .config 2>/dev/null)"
+       o_bindir="${CONFIG_BINARY_FOLDER:-bin}/targets/$o_target/$o_subtarget"
 }
 
 start_qemu_armvirt() {
@@ -207,6 +213,7 @@ start_qemu_malta() {
        local is64
        local isel
        local qemu_exe
+       local cpu
        local rootfs="$o_rootfs"
        local kernel="$o_kernel"
        local mach="${o_mach:-malta}"
@@ -215,6 +222,7 @@ start_qemu_malta() {
        is64="$(echo $o_subtarget | grep -o 64)"
        [ "$(echo "$o_subtarget" | grep -o '^..')" = "le" ] && isel="el"
        qemu_exe="qemu-system-mips$is64$isel"
+       [ -n "$is64" ] && cpu="MIPS64R2-generic" || cpu="24Kc"
 
        [ -n "$kernel" ] || kernel="$o_bindir/openwrt-malta-${o_subtarget%-*}-vmlinux-initramfs.elf"
 
@@ -232,15 +240,13 @@ start_qemu_malta() {
        # one will be actually used as the wan, lan network interface inside the
        # guest machine
        [ -z "$o_network" ] || {
-               o_qemu_extra+=( \
-                       "-netdev" "bridge,id=wan,br=$BR_WAN,helper=$HELPER" "-device" \
-                           "virtio-net-pci,id=devwan,netdev=wan,mac=$MAC_WAN" \
-                       "-netdev" "bridge,id=lan,br=$BR_LAN,helper=$HELPER" \
-                           "-device" "virtio-net-pci,id=devlan,netdev=lan,mac=$MAC_LAN" \
+               o_qemu_extra+=(
+                       -netdev bridge,id=wan,br="$BR_WAN,helper=$HELPER" -device pcnet,netdev=wan,mac="$MAC_WAN"
+                       -netdev bridge,id=lan,br="$BR_LAN,helper=$HELPER" -device pcnet,netdev=lan,mac="$MAC_LAN"
                )
        }
 
-       "$qemu_exe" -machine "$mach" -nographic \
+       "$qemu_exe" -machine "$mach" -cpu "$cpu" -nographic \
                -kernel "$kernel" \
                "${o_qemu_extra[@]}"
 }
@@ -252,7 +258,7 @@ start_qemu_x86() {
        local mach="${o_mach:-pc}"
 
        [ -n "$rootfs" ] || {
-               rootfs="$o_bindir/openwrt-$o_target-${o_subtarget%-*}-combined-ext4.img"
+               rootfs="$o_bindir/openwrt-$o_target-${o_subtarget%-*}-generic-squashfs-combined.img"
                if [ ! -f "$rootfs" -a -s "$rootfs.gz" ]; then
                        gunzip "$rootfs.gz"
                fi
@@ -279,12 +285,20 @@ start_qemu_x86() {
        }
 
        [ -z "$o_network" ] || {
-               o_qemu_extra+=( \
-                       "-netdev" "bridge,id=lan,br=$BR_LAN,helper=$HELPER" \
-                           "-device" "virtio-net-pci,id=devlan,netdev=lan,mac=$MAC_LAN" \
-                       "-netdev" "bridge,id=wan,br=$BR_WAN,helper=$HELPER" "-device" \
-                           "virtio-net-pci,id=devwan,netdev=wan,mac=$MAC_WAN" \
-               )
+               case "${o_subtarget%-*}" in
+                       legacy)
+                               o_qemu_extra+=(
+                                       -netdev "bridge,id=lan,br=$BR_LAN,helper=$HELPER" -device "e1000,id=devlan,netdev=lan,mac=$MAC_LAN"
+                                       -netdev "bridge,id=wan,br=$BR_WAN,helper=$HELPER" -device "e1000,id=devwan,netdev=wan,mac=$MAC_WAN"
+                               )
+                               ;;
+                       generic|64)
+                               o_qemu_extra+=(
+                                       -netdev "bridge,id=lan,br=$BR_LAN,helper=$HELPER" -device "virtio-net-pci,id=devlan,netdev=lan,mac=$MAC_LAN"
+                                       -netdev "bridge,id=wan,br=$BR_WAN,helper=$HELPER" -device "virtio-net-pci,id=devwan,netdev=wan,mac=$MAC_WAN"
+                               )
+                               ;;
+               esac
        }
 
        case "${o_subtarget%-*}" in