WIP: script to start the runtime VM
authorSteve McIntyre <steve.mcintyre@arm.com>
Tue, 5 May 2020 14:09:59 +0000 (15:09 +0100)
committerSteve McIntyre <steve.mcintyre@arm.com>
Tue, 5 May 2020 14:09:59 +0000 (15:09 +0100)
Should work natively on an arm64 host, or emulated on amd64

scripts/start_runtime [new file with mode: 0755]

diff --git a/scripts/start_runtime b/scripts/start_runtime
new file mode 100755 (executable)
index 0000000..2feba5b
--- /dev/null
@@ -0,0 +1,92 @@
+#!/bin/sh
+
+VM_IP=127.16.2.1
+SSH_PORT=2222
+SHARE=/vagrant
+MEM=512
+TIMEOUT=600 # 10 minutes
+
+# Are we native, or running under full emulation?
+MACHINE=$(uname -m)
+case $MACHINE in
+    aarch64)
+       if [ "$MACH"x = ""x ] || \
+              [ "$MACH"x = "aarch64"x ] || \
+              [ "$MACH"x = "arm64" ] ; then
+           MACH=aarch64
+           CPU_OPTS="-cpu host --enable-kvm"
+           MACH_OPTS="-machine virt,gic-version=host,kernel_irqchip=on"
+       elif [ "$MACH"x = "arm"x ]; then
+           MACH=arm
+           CPU_OPTS="-cpu host,aarch64=off --enable-kvm"
+           MACH_OPTS="-machine virt,gic-version=host,kernel_irqchip=on"
+       else
+           echo "Unknown MACH $MACH; abort"
+           exit 1
+       fi
+       ;;
+    *)
+       if [ "$MACH"x = ""x ] || \
+              [ "$MACH"x = "aarch64"x ] || \
+              [ "$MACH"x = "arm64" ] ; then
+           MACH=aarch64
+           CPU_OPTS="-cpu cortex-a57"
+           MACH_OPTS="-M virt"
+       elif [ "$MACH"x = "arm"x ]; then
+           MACH=arm
+           CPU_OPTS="-cpu cortex-a15"
+           MACH_OPTS="-M virt"
+       else
+           echo "Unknown MACH $MACH; abort"
+           exit 1
+       fi
+       ;;
+esac
+
+if [ "$DISK"x = ""x ] ; then
+    DISK=runtime-hd.img
+fi
+
+#DISPLAY="-vga none -nographic"
+DISPLAY="-daemonize -vnc :1"
+PFLASH="-pflash $MACH-OVMF.fd -pflash $MACH-storage.fd"
+
+
+if [ "$NOSHARE"x = ""x ]; then
+    P9="-virtfs local,path=$SHARE/,mount_tag=host0,security_model=passthrough,id=host0"
+    if [ -f ~/.ssh/authorized_keys ]; then
+       cp ~/.ssh/authorized_keys $SHARE/runtime/vagrant-pub-key
+    fi
+    touch $SHARE/runtime/waiting_runtime_vm
+fi
+
+NET="-netdev user"
+NET="$NET,id=eth0"
+NET="$NET,hostfwd=tcp:${VM_IP}:${SSH_PORT}-10.0.2.15:22"
+NET="$NET -device virtio-net-device,netdev=eth0"
+
+CMD="qemu-system-$MACH -m $MEM \
+    $DISPLAY \
+    $MACH_OPTS $CPU_OPTS \
+    $PFLASH \
+    -drive file=$DISK,format=raw,if=virtio \
+    $NET \
+    $P9"
+
+echo $CMD
+$CMD
+
+i=0
+while true; do
+    echo "Waiting for VM to come ready ($i seconds)"
+    if [ ! -f $SHARE/runtime/waiting_runtime_vm ]; then
+       echo "ready after $i seconds"
+        exit 0
+    fi
+    sleep 1
+    i=$(($i + 1))
+done
+
+# else the VM timed out
+echo "qemu VM startup took too long: $i seconds. Abort"
+exit 1