| #!/bin/bash |
| |
| efi=${EFI-/usr/share/AAVMF/AAVMF_CODE.fd} |
| efivar=${EFIVAR-/home/maz/disk-images/stretch-arm64-efi-vars.fd} |
| disk=${DISK-/home/maz/disk-images/stretch-arm64.img} |
| bus=${BUS-pci} |
| netif=${NETIF} |
| gic=${GIC-host} |
| bit=${BIT-64} |
| cpus=${CPUS-4} |
| ram=${RAM-1G} |
| cdrom=${CDROM-nocdimage} |
| qemu=${QEMU-/usr/bin/qemu-system-aarch64} |
| |
| if [ "$bit" = 64 ]; then |
| sf=on |
| else |
| sf=off |
| fi |
| |
| qvers=$(qemu-system-aarch64 --version| cut -f4 -d' ' | cut -f1,2 -d.) |
| qversmaj=$(echo $qvers | cut -f1 -d.) |
| qversmin=$(echo $qvers | cut -f2 -d.) |
| |
| # Disable virtio legacy if < 2.7 |
| if [ $qversmaj -eq 2 -a $qversmin -ge 7 ]; then |
| if [ $bus = pci ]; then |
| virtio=",disable-legacy=on" |
| fi |
| fi |
| |
| if [ "$cdrom" != nocdimage ]; then |
| cddev="-drive file=$cdrom,id=cdrom,if=none,media=cdrom \ |
| -device virtio-scsi-$bus$virtio \ |
| -device scsi-cd,drive=cdrom" |
| fi |
| |
| if [ -z "$netif" -o $bus != pci ]; then |
| |
| netdev="-netdev user,id=hostnet0 -device virtio-net-$bus$virtio,netdev=hostnet0" |
| |
| elif [ -e /dev/tap$(< /sys/class/net/$netif/ifindex) ]; then |
| |
| addr=$(< /sys/class/net/$netif/address) |
| tap=/dev/tap$(< /sys/class/net/$netif/ifindex) |
| mq=$((`ls -1 /sys/class/net/$netif/queues/ | wc -l ` / 2)) |
| tapfd=128 |
| |
| tapfds="$(($tapfd))" |
| tapredir="$(($tapfd))<>$tap" |
| vhfds="$(($tapfd+$mq))" |
| vhredir="$(($tapfd+$mq))<>/dev/vhost-net" |
| |
| for i in `seq 1 $(($mq-1))` |
| do |
| tapfds+=":$((i+$tapfd))" |
| tapredir+=" $((i+$tapfd))<>$tap" |
| vhfds+=":$((i+$tapfd+$mq))" |
| vhredir+=" $((i+$tapfd+$mq))<>/dev/vhost-net" |
| done |
| |
| netdev="-netdev tap,fds=$tapfds,id=hostnet0,vhost=on,vhostfds=$vhfds \ |
| -device virtio-net-$bus$virtio,mac=$addr,netdev=hostnet0,mq=on,vectors=$((2*$mq+2))" |
| |
| else |
| mq=$((`ls -1 /sys/class/net/$netif/queues/ | wc -l ` / 2)) |
| mq=4 |
| vectors="mq=on,vectors=$((2*$mq+2))" |
| suffix=`echo $disk | md5sum | sed -e 's/^\(..\)\(..\)\(..\)\(.*\)/\1:\2:\3/'` |
| netdev="-netdev tap,vhost=on,queues=$mq,id=hostnet0,ifname=$netif,script=no,downscript=no \ |
| -device virtio-net-$bus$virtio,netdev=hostnet0,mac=5a:fe:00:$suffix,$vectors" |
| fi |
| |
| args=" -m 1024 -smp $cpus -cpu host,aarch64=$sf -machine virt,accel=kvm,gic_version=$gic \ |
| -nographic \ |
| -drive if=pflash,format=raw,readonly,file=$efi \ |
| -drive if=pflash,format=raw,file=$efivar \ |
| $netdev \ |
| -drive if=none,format=raw,file=$disk,id=disk0 \ |
| -device virtio-blk-$bus$virtio,drive=disk0 \ |
| $cddev \ |
| $* \ |
| $tapredir $vhredir \ |
| " |
| |
| dtb=`mktemp -p tmp --suffix=.dtb` |
| dts=`mktemp -p tmp --suffix=.dts` |
| |
| dtc -q -I fs /sys/firmware/devicetree/base/ | grep fsl,erratum-a008585 && ( |
| echo Enabling erratum for fsl,erratum-a008585 |
| |
| eval "$qemu -machine dumpdtb=$dtb $args" |
| dtc -I dtb $dtb > $dts |
| |
| cat <<EOF >>$dts |
| &{/timer} { |
| fsl,erratum-a008585; |
| }; |
| EOF |
| |
| dtc -I dts -O dtb -o $dtb $dts |
| ) && forcedtb="-dtb $dtb" |
| |
| rm $dts |
| eval "$qemu $forcedtb $args" |
| rm $dtb |