scripts/qemustart: add riscv64 support qemu-riscv
authorYousong Zhou <yszhou4tech@gmail.com>
Thu, 23 May 2019 07:41:20 +0000 (07:41 +0000)
committerYousong Zhou <yszhou4tech@gmail.com>
Sat, 6 Jul 2019 03:04:33 +0000 (03:04 +0000)
scripts/qemustart

index dbb8deddafd8093887d6dfcd37d5743a5e1ba48a..c860ab88d6e290e27155135fa3a7fde8fb0dfc4c 100755 (executable)
@@ -248,6 +248,41 @@ start_qemu_malta() {
                "${o_qemu_extra[@]}"
 }
 
+start_qemu_riscv() {
+       local is64
+       local qemu_exe
+       local rootfs="$o_rootfs"
+       local kernel="$o_kernel"
+       local mach="${o_mach:-virt}"
+
+       # o_subtarget can be xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, etc..
+       is64="$(echo $o_subtarget | grep -o 64)"
+       qemu_exe="qemu-system-riscv$is64"
+
+       [ -n "$kernel" ] || kernel="$o_bindir/openwrt-riscv64-${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" \
+               )
+       }
+
+       [ -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 \
+               -kernel "$kernel" \
+               "${o_qemu_extra[@]}"
+}
+
 start_qemu_x86() {
        local qemu_exe
        local kernel="$o_kernel"
@@ -327,6 +362,7 @@ start_qemu() {
        case "$o_target" in
                armvirt)        start_qemu_armvirt      ;;
                malta)          start_qemu_malta        ;;
+               riscv)          start_qemu_riscv        ;;
                x86)            start_qemu_x86          ;;
                *)
                        __errmsg "target $o_target is not supported yet"