}
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
[--kernel <kernel>]
[--rootfs <rootfs>]
[--machine <machine>]
+ [-n|--network]
<subtarget> will default to "generic" and must be specified if
<extra-qemu-options> are present
$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
}
}
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
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}"
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"
)
}
- [ -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" \
local is64
local isel
local qemu_exe
+ local cpu
+ local rootfs="$o_rootfs"
local kernel="$o_kernel"
local mach="${o_mach:-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[@]}"
}
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
)
}
- [ -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" \
- )
+ [ -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
# 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[@]}"
;;
start_qemu() {
case "$o_target" in
- armvirt) start_qemu_armvirt ;;
+ armsr) start_qemu_armsr ;;
malta) start_qemu_malta ;;
x86) start_qemu_x86 ;;
*)