123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- #!/usr/bin/env bash
- set -e
- # CLI handling.
- arch=x86_64
- debug_qemu=''
- kgdb=false
- nographic=false
- # norandmaps: Don't use address space randomization. Equivalent to echo 0 > /proc/sys/kernel/randomize_va_space.
- # printk.time=y: log in format: "[time ] msg" for all printk messages.
- # nokaslr: https://unix.stackexchange.com/questions/397939/turning-off-kaslr-to-debug-linux-kernel-using-qemu-and-gdb
- # Turned on by default since v4.12
- extra_append='nokaslr norandmaps printk.devkmsg=on printk.time=y'
- extra_flags=''
- initrd=false
- root=''
- while getopts a:de:iknqt:x OPT; do
- case "$OPT" in
- a)
- arch="$OPTARG"
- ;;
- d)
- extra_flags="$extra_flags -S -s"
- ;;
- e)
- extra_append="$extra_append $OPTARG"
- ;;
- k)
- extra_append="$extra_append kgdbwait"
- # For those who want to try KDB.
- #extra_append="$extra_append kgdbwait kgdboc=kbd"
- extra_flags="$extra_flags -serial tcp::1234,server,nowait"
- kgdb=true
- ;;
- i)
- initrd=true
- ;;
- n)
- extra_append="$extra_append console=ttyS0"
- extra_flags="$extra_flags -nographic"
- nographic=true
- ;;
- q)
- debug_qemu='gdb -q -ex start --args'
- ;;
- esac
- done
- shift "$(($OPTIND - 1))"
- extra_flags="$extra_flags $@"
- buildroot_out_dir="./buildroot/output.${arch}~"
- images_dir="$buildroot_out_dir/images"
- qemu_common="\
- $debug_qemu \
- $buildroot_out_dir/host/usr/bin/qemu-system-${arch} \
- -m 128M \
- -monitor telnet::45454,server,nowait \
- -netdev user,hostfwd=tcp::45455-:45455,id=net0 \
- -smp 1 \
- "
- if $initrd; then
- extra_flags="$extra_flags -initrd '${images_dir}/rootfs.cpio'"
- fi
- # The base QEMU commands are found under board/qemu/*/readme.tx
- case "$arch" in
- x86_64)
- if $kgdb; then
- extra_append="$extra_append kgdboc=ttyS0,115200"
- fi
- if ! $initrd; then
- root='root=/dev/vda'
- extra_flags="$extra_flags -drive file='${images_dir}/rootfs.ext2.qcow2,if=virtio,format=qcow2'"
- fi
- cmd="$qemu_common \
- -M pc \
- -append '$root nopat $extra_append' \
- -device edu \
- -device lkmc_pci_min \
- -device virtio-net-pci,netdev=net0 \
- -kernel ${images_dir}/bzImage \
- $extra_flags \
- "
- ;;
- arm)
- if $kgdb; then
- extra_append="$extra_append kgdboc=ttyAMA0,115200"
- fi
- if ! $initrd; then
- root='root=/dev/sda'
- extra_flags="$extra_flags -drive file='${images_dir}/rootfs.ext2.qcow2,if=scsi,format=qcow2'"
- fi
- cmd="$qemu_common \
- -M versatilepb \
- -append '$root $extra_append' \
- -device rtl8139,netdev=net0 \
- -dtb ${images_dir}/versatile-pb.dtb \
- -kernel ${images_dir}/zImage \
- -serial stdio \
- $extra_flags \
- "
- ;;
- aarch64)
- if $kgdb; then
- extra_append="$extra_append kgdboc=ttyAMA0,115200"
- fi
- cmd="$qemu_common \
- -M virt \
- -append 'root=/dev/sda $extra_append' \
- -cpu cortex-a57 \
- -device virtio-net-device,netdev=net0 \
- -kernel ${images_dir}/Image \
- -nographic \
- -serial stdio \
- $extra_flags \
- "
- ;;
- mips64)
- if ! $initrd; then
- root='root=/dev/hda'
- extra_flags="$extra_flags -drive file='${images_dir}/rootfs.ext2.qcow2,format=qcow2'"
- fi
- cmd="$qemu_common \
- -M malta \
- -append 'root=/dev/hda $extra_append' \
- -cpu I6400 \
- -device pcnet \
- -kernel ${images_dir}/vmlinux \
- -nographic \
- $extra_flags \
- "
- ;;
- esac
- echo "$cmd"
- eval "$cmd"
|