runqemu 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #!/usr/bin/env bash
  2. set -e
  3. # CLI handling.
  4. arch=x86_64
  5. debug=false
  6. debug_qemu=''
  7. kgdb=false
  8. nographic=false
  9. extra_append=''
  10. extra_flags=''
  11. while getopts a:dkn OPT; do
  12. case "$OPT" in
  13. a)
  14. arch=$OPTARG
  15. ;;
  16. d)
  17. debug=true
  18. extra_flags="$extra_flags -S -s"
  19. ;;
  20. k)
  21. debug=true
  22. extra_append="$extra_append kgdbwait"
  23. # For those who want to try KDB.
  24. #extra_append="$extra_append kgdbwait kgdboc=kbd"
  25. extra_flags="$extra_flags -serial tcp::1234,server,nowait"
  26. kgdb=true
  27. ;;
  28. n)
  29. extra_append="$extra_append console=ttyS0"
  30. extra_flags="$extra_flags -nographic"
  31. nographic=true
  32. ;;
  33. q)
  34. debug_qemu='gdb -q -ex start --args'
  35. ;;
  36. esac
  37. done
  38. shift "$(($OPTIND - 1))"
  39. extra_flags="$extra_flags $@"
  40. images_dir='buildroot/output/images'
  41. case "$arch" in
  42. x86_64)
  43. if $kgdb; then
  44. extra_append="$extra_append kgdboc=ttyS0,115200"
  45. fi
  46. cmd="$debug_qemu ./buildroot/output/host/usr/bin/qemu-system-x86_64 \
  47. -M pc \
  48. -append 'root=/dev/vda $extra_append' \
  49. -drive file=${images_dir}/rootfs.ext2,if=virtio,format=raw \
  50. -kernel ${images_dir}/bzImage \
  51. -m 128M \
  52. -net nic,model=virtio \
  53. -net user \
  54. -smp 1 \
  55. $extra_flags
  56. "
  57. ;;
  58. arm)
  59. if $kgdb; then
  60. extra_append="$extra_append kgdboc=ttyAMA0,115200"
  61. fi
  62. cmd="qemu-system-arm \
  63. -M versatilepb \
  64. -append 'root=/dev/sda $extra_append' \
  65. -drive file=${images_dir}/rootfs.ext2,if=scsi,format=raw \
  66. -dtb ${images_dir}/versatile-pb.dtb \
  67. -kernel ${images_dir}/zImage \
  68. -m 128M \
  69. -net nic,model=rtl8139 \
  70. -net user \
  71. -serial stdio \
  72. -smp 1 \
  73. $extra_flags"
  74. ;;
  75. esac
  76. if "$debug" && ! "$nographic" && [ ! "$arch" = 'arm' ]; then
  77. eval "$cmd" &>/dev/null &
  78. # TODO: Ctrl +C gets sent to QEMU? Why? Does not happen if I run
  79. # ./rungdb manually from outside this script!!! But why?!?!
  80. # eval has nothing to do with it, minimized example with explicit
  81. # commands also fails in the same way...
  82. #./rungdb
  83. else
  84. eval "$cmd"
  85. fi