xref: /DragonOS/tools/run-qemu.sh (revision 5fb12ce447710edf8566f250655a06cb27519fca)
1# 进行启动前检查
2flag_can_run=1
3ARGS=`getopt -o p -l bios: -- "$@"`
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    case "$1" in
40        --bios)
41      case "$2" in
42              uefi) #uefi启动新增ovmf.fd固件
43              if [ ${ARCH} == x86_64 ] ;then
44              sudo ${QEMU} -bios arch/x86_64/efi/OVMF-pure-efi.fd ${QEMU_ARGUMENT}
45              elif [ ${ARCH} == i386 ] ;then
46              sudo ${QEMU} -bios arch/i386/efi/OVMF-pure-efi.fd ${QEMU_ARGUMENT}
47              fi
48            ;;
49              legacy)
50              sudo ${QEMU} ${QEMU_ARGUMENT}
51              ;;
52            esac
53
54esac
55else
56  echo "不满足运行条件"
57fi
58