rockchip: add Bananapi-R2 Pro board support
[openwrt/openwrt.git] / scripts / qemustart
index 3b479860e9c5e9ecbf9a30ee25f5198055191fca..6c4c9be4cb0a898a34f518476b12badec41383d2 100755 (executable)
@@ -74,7 +74,7 @@ check_setup_() {
 }
 
 check_setup() {
-       [ -z $o_nonetwork ] || return 0
+       [ -n "$o_network" ] || return 0
        check_setup_ || {
                __errmsg "please check the script content to see the environment requirement"
                return 1
@@ -90,6 +90,7 @@ Usage: $SELF [-h|--help]
          [--kernel <kernel>]
          [--rootfs <rootfs>]
          [--machine <machine>]
+         [-n|--network]
 
 <subtarget> will default to "generic" and must be specified if
 <extra-qemu-options> are present
@@ -108,10 +109,10 @@ Examples
   $SELF malta be -m 64
   $SELF malta le64
   $SELF malta be-glibc
-  $SELF armvirt 32 \\
+  $SELF armsr armv7 \\
                 --machine virt,highmem=off \\
-                --kernel bin/targets/armvirt/32/openwrt-armvirt-32-zImage \\
-                --rootfs bin/targets/armvirt/32/openwrt-armvirt-32-root.ext4
+                --kernel bin/targets/armsr/armv7/openwrt-armsr-armv7-generic-kernel.bin \\
+                --rootfs bin/targets/armsr/armv7/openwrt-armsr-armv7-generic-ext4-rootfs.img
 EOF
 }
 
@@ -120,13 +121,19 @@ rand_mac() {
 }
 
 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
-                       --no-network|-n) o_nonetwork=1; shift ;;
                        --kernel) o_kernel="$2"; shift 2 ;;
                        --rootfs) o_rootfs="$2"; shift 2 ;;
                        --machine|-machine|-M) o_mach="$2"; shift 2 ;;
+                       --network|-n) o_network=1; shift ;;
                        --help|-h)
                                usage
                                exit 0
@@ -151,10 +158,11 @@ 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() {
+start_qemu_armsr() {
        local kernel="$o_kernel"
        local rootfs="$o_rootfs"
        local mach="${o_mach:-virt}"
@@ -162,15 +170,15 @@ start_qemu_armvirt() {
        local qemu_exe
 
        case "${o_subtarget%-*}" in
-               32)
+               armv7)
                        qemu_exe="qemu-system-arm"
                        cpu="cortex-a15"
-                       [ -n "$kernel" ] || kernel="$o_bindir/openwrt-$o_target-${o_subtarget%-*}-zImage-initramfs"
+                       [ -n "$kernel" ] || kernel="$o_bindir/openwrt-$o_target-${o_subtarget%-*}-generic-initramfs-kernel.bin"
                        ;;
-               64)
+               armv8)
                        qemu_exe="qemu-system-aarch64"
                        cpu="cortex-a57"
-                       [ -n "$kernel" ] || kernel="$o_bindir/openwrt-$o_target-${o_subtarget%-*}-Image-initramfs"
+                       [ -n "$kernel" ] || kernel="$o_bindir/openwrt-$o_target-${o_subtarget%-*}-generic-initramfs-kernel.bin"
                        ;;
                *)
                        __errmsg "target $o_target: unknown subtarget $o_subtarget"
@@ -187,7 +195,7 @@ start_qemu_armvirt() {
                )
        }
 
-       [ -n $o_nonetwork ] || {
+       [ -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" \
@@ -205,6 +213,8 @@ 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}"
 
@@ -212,33 +222,43 @@ 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"
 
+       [ -z "$rootfs" ] || {
+               if [ ! -f "$rootfs" -a -s "$rootfs.gz" ]; then
+                       gunzip "$rootfs.gz"
+               fi
+               o_qemu_extra+=( \
+                       "-drive" "file=$rootfs,format=raw" \
+                       "-append" "root=/dev/sda rootwait" \
+               )
+       }
+
        # NOTE: order of wan, lan -device arguments matters as it will affect which
        # one will be actually used as the wan, lan network interface inside the
        # guest machine
-       [ -n $o_nonetwork ] || {
-               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" \
+       [ -z "$o_network" ] || {
+               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[@]}"
 }
 
 start_qemu_x86() {
+       local qemu_exe
+       local kernel="$o_kernel"
        local rootfs="$o_rootfs"
        local mach="${o_mach:-pc}"
-       local qemu_exe
 
        [ -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
@@ -257,13 +277,28 @@ start_qemu_x86() {
                        ;;
        esac
 
-       [ -n $o_nonetwork ] || {
-               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" \
-               )
+       [ -n "$kernel" ] && {
+           o_qemu_extra+=( \
+               "-kernel" "$kernel" \
+               "-append" "root=/dev/vda console=ttyS0 rootwait" \
+           )
+       }
+
+       [ -z "$o_network" ] || {
+               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
@@ -274,12 +309,12 @@ start_qemu_x86() {
                        # To use AHCI interface
                        #
                        #       -device ich9-ahci,id=ahci \
-                       #       -device ide-drive,drive=drv0,bus=ahci.0 \
+                       #       -device ide-hd,drive=drv0,bus=ahci.0 \
                        #       -drive "file=$rootfs,format=raw,id=drv0,if=none" \
                        #
                        # [1] https://dev.openwrt.org/ticket/17947
                        "$qemu_exe" -machine "$mach" -nographic \
-                               -device ide-drive,drive=drv0 \
+                               -device ide-hd,drive=drv0 \
                                -drive "file=$rootfs,format=raw,id=drv0,if=none" \
                                "${o_qemu_extra[@]}"
                        ;;
@@ -293,7 +328,7 @@ start_qemu_x86() {
 
 start_qemu() {
        case "$o_target" in
-               armvirt)        start_qemu_armvirt      ;;
+               armsr)          start_qemu_armsr        ;;
                malta)          start_qemu_malta        ;;
                x86)            start_qemu_x86          ;;
                *)