Switch the Vagrantfile default to use the arm32 runtime VM
[training-lab.git] / scripts / start_runtime
1 #!/bin/sh
2
3 SSH_PORT=2222
4 SHARE=/vagrant
5 MEM=512
6 TIMEOUT=600 # 10 minutes
7
8 # Are we native, or running under full emulation?
9 MACHINE=$(uname -m)
10 case $MACHINE in
11     aarch64)
12         if [ "$MACH"x = ""x ] || \
13                [ "$MACH"x = "aarch64"x ] || \
14                [ "$MACH"x = "arm64"x ] ; then
15             MACH=aarch64
16             QEMU=qemu-system-aarch64
17             CPU_OPTS="-cpu host --enable-kvm"
18             MACH_OPTS="-machine virt,gic-version=host,kernel_irqchip=on"
19         elif [ "$MACH"x = "arm"x ] ||\
20                 [ "$MACH"x = "arm32"x ] ; then
21             MACH=arm
22             QEMU=qemu-system-aarch64
23             CPU_OPTS="-cpu host,aarch64=off --enable-kvm"
24             MACH_OPTS="-machine virt,gic-version=host,kernel_irqchip=on"
25         else
26             echo "Unknown MACH $MACH; abort"
27             exit 1
28         fi
29         ;;
30     *)
31         if [ "$MACH"x = ""x ] || \
32                [ "$MACH"x = "aarch64"x ] || \
33                [ "$MACH"x = "arm64"x ] ; then
34             MACH=aarch64
35             QEMU=qemu-system-aarch64
36             CPU_OPTS="-cpu cortex-a57"
37             MACH_OPTS="-M virt"
38         elif [ "$MACH"x = "arm"x ] ||\
39                 [ "$MACH"x = "arm32"x ] ; then
40             MACH=arm
41             QEMU=qemu-system-arm
42             CPU_OPTS="-cpu cortex-a15"
43             MACH_OPTS="-M virt"
44         else
45             echo "Unknown MACH $MACH; abort"
46             exit 1
47         fi
48         ;;
49 esac
50
51 if [ "$DISK"x = ""x ] ; then
52     DISK=runtime-hd.img
53 fi
54
55 #DISPLAY="-vga none -nographic"
56 DISPLAY="-daemonize -vnc :1"
57 PFLASH="-pflash $MACH-OVMF.fd -pflash $MACH-storage.fd"
58
59 if [ "$CD"x != ""x ]; then
60     CD="-device virtio-scsi-pci,id=scsi -drive if=none,id=cd,file=$CD,readonly -device scsi-cd,drive=cd,bootindex=0"
61 fi
62
63 if [ "$NOSHARE"x = ""x ]; then
64     P9="-virtfs local,path=$SHARE/,mount_tag=host0,security_model=passthrough,id=host0"
65     AUTHKEYS=/home/vagrant/.ssh/authorized_keys
66     if [ -f $AUTHKEYS ]; then
67         cp -v $AUTHKEYS $SHARE/runtime/vagrant-pub-key
68     fi
69     touch $SHARE/runtime/waiting_runtime_vm
70 fi
71
72 NET="-netdev user"
73 NET="$NET,id=eth0"
74 NET="$NET,hostfwd=tcp:127.0.0.1:${SSH_PORT}-10.0.2.15:22"
75 NET="$NET -device virtio-net-device,netdev=eth0"
76
77 CMD="$QEMU -m $MEM \
78     $DISPLAY \
79     $MACH_OPTS $CPU_OPTS \
80     $PFLASH \
81     -drive file=$DISK,format=raw,if=virtio \
82     $NET \
83     $CD \
84     $P9"
85
86 echo $CMD
87 $CMD
88
89 i=0
90 while true; do
91     echo "Waiting for qemu $MACH VM to come ready ($i seconds)"
92     if [ ! -f $SHARE/runtime/waiting_runtime_vm ]; then
93         echo "ready after $i seconds"
94         exit 0
95     fi
96     sleep 1
97     i=$(($i + 1))
98 done
99
100 # else the VM timed out
101 echo "qemu VM startup took too long: $i seconds. Abort"
102 exit 1