xref: /DragonOS/tools/run-qemu.sh (revision 52ab5d904e307e92fc6c323e1834bb0dbc432dcd)
1# 进行启动前检查
2flag_can_run=1
3ARGS=`getopt -o p -l bios:,display: -- "$@"`
4eval set -- "${ARGS}"
5echo "$@"
6allflags=$(qemu-system-x86_64 -cpu help | awk '/flags/ {y=1; getline}; y {print}' | tr ' ' '\n' | grep -Ev "^$" | sed -r 's|^|+|' | tr '\n' ',' | sed -r "s|,$||")
7ARCH="x86_64"
8#ARCH="i386"
9# 请根据自己的需要,在-d 后方加入所需的trace事件
10
11# 标准的trace events
12qemu_trace_std=cpu_reset,guest_errors,exec,cpu,trace:virtio*
13# 调试usb的trace
14qemu_trace_usb=trace:usb_xhci_reset,trace:usb_xhci_run,trace:usb_xhci_stop,trace:usb_xhci_irq_msi,trace:usb_xhci_irq_msix,trace:usb_xhci_port_reset,trace:msix_write_config,trace:usb_xhci_irq_msix,trace:usb_xhci_irq_msix_use,trace:usb_xhci_irq_msix_unuse,trace:usb_xhci_irq_msi,trace:usb_xhci_*
15qemu_accel=kvm
16if [ $(uname) == Darwin ]; then
17    qemu_accel=hvf
18fi
19
20
21QEMU=qemu-system-x86_64
22QEMU_DISK_IMAGE="../bin/disk.img"
23QEMU_MEMORY="512M"
24QEMU_SMP="2,cores=2,threads=1,sockets=1"
25QEMU_MONITOR="stdio"
26QEMU_TRACE="${qemu_trace_std}"
27QEMU_CPU_FEATURES="IvyBridge,apic,x2apic,+fpu,check,${allflags}"
28QEMU_RTC_CLOCK="clock=host,base=localtime"
29QEMU_SERIAL="file:../serial_opt.txt"
30QEMU_DRIVE="id=disk,file=${QEMU_DISK_IMAGE},if=none"
31
32QEMU_DEVICES="-device ahci,id=ahci -device ide-hd,drive=disk,bus=ahci.0 -nic user,model=virtio  -usb -device qemu-xhci,id=xhci,p2=8,p3=4 -machine accel=${qemu_accel}"
33
34QEMU_ARGUMENT="-d ${QEMU_DISK_IMAGE} -m ${QEMU_MEMORY} -smp ${QEMU_SMP} -boot order=d -monitor ${QEMU_MONITOR} -d ${qemu_trace_std} "
35
36QEMU_ARGUMENT+="-s -S -cpu ${QEMU_CPU_FEATURES} -rtc ${QEMU_RTC_CLOCK} -serial ${QEMU_SERIAL} -drive ${QEMU_DRIVE} ${QEMU_DEVICES}"
37
38if [ $flag_can_run -eq 1 ]; then
39  while true;do
40    case "$1" in
41        --bios)
42        case "$2" in
43              uefi) #uefi启动新增ovmf.fd固件
44              BIOS_TYPE=uefi
45            ;;
46              legacy)
47              BIOS_TYPE=lagacy
48              ;;
49        esac;shift 2;;
50        --display)
51        case "$2" in
52              vnc)
53              QEMU_ARGUMENT+=" -display vnc=:5900"
54              ;;
55              window)
56              ;;
57        esac;shift 2;;
58        *) break
59      esac
60  done
61
62if [ ${BIOS_TYPE} == uefi ] ;then
63  if [ ${ARCH} == x86_64 ] ;then
64    sudo ${QEMU} -bios arch/x86_64/efi/OVMF-pure-efi.fd ${QEMU_ARGUMENT}
65  elif [ ${ARCH} == i386 ] ;then
66    sudo ${QEMU} -bios arch/i386/efi/OVMF-pure-efi.fd ${QEMU_ARGUMENT}
67  fi
68else
69  sudo ${QEMU} ${QEMU_ARGUMENT}
70fi
71
72else
73  echo "不满足运行条件"
74fi
75