-
Notifications
You must be signed in to change notification settings - Fork 1
/
qemu-goes
executable file
·97 lines (88 loc) · 2.33 KB
/
qemu-goes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/bin/sh
# Copyright 2015-2016 Platina Systems, Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license described in
# /usr/share/doc/qemu-goes/copyright
pid=$$
usage="qemu-goes [-n | --dry-run] [-q | --quiet] [KERNEL [INITRD [DTB]]]"
if test "$1" = "-h" -o "$1" = "-help" -o "$1" = "--help"; then
echo $usage
exit 0
fi
if test "$1" = "-n" -o "$1" = "-dry-run" -o "$1" = "--dry-run"; then
dryrun=echo
shift
fi
if test "$1" = "-q" -o "$1" = "-quiet" -o "$1" = "--quiet"; then
quiet=quiet
shift
fi
for f in $@; do
if test \! -r $f; then
echo can\'t read $f >/dev/stderr
exit 2
fi
done
if [ -n "$ROOT" -a -n "$DISK" ]; then
echo "Specify either ROOT or DISK, but not both"
exit 1
fi
if [ -z "$BIOS" ]; then
kernel=${1:-example-amd64.vmlinuz}
initrd=${2:-${kernel%.*}.cpio.xz}
dtb=$3
arch=$(file ${kernel})
else
bios=${BIOS}
arch=x86
fi
case "$arch" in
*ARM*)
qemu=qemu-system-arm
console=ttyAMA0,115200
M=vexpress-a9
device=virtio-net-device,netdev=${USER}-${pid}
if test "$dtb" = ""; then
dtb=${kernel%.*}.dtb
if test \! -r $dtb; then
echo can\'t read $dtb >/dev/stderr
exit 2
fi
fi
;;
*x86*)
qemu=qemu-system-x86_64
console=ttyS0
M=q35
device=virtio-net,netdev=${USER}-${pid}
kvm=kvm
;;
*) echo $kernel unsupported >/dev/stderr
exit 2
;;
esac
netdev=user,id=${USER}-${pid},\
hostfwd=tcp:127.0.0.1:6379-:6379,\
hostfwd=tcp:127.0.0.1:2345-:2345,\
hostfwd=udp:127.0.0.1:2623-:623,\
hostfwd=tcp:127.0.0.1:2022-:22
append="console=${console}"
append="${append}${quiet:+ quiet}"
append="${append}${IP:+ ip=}${IP}"
append="${append}${GOES:+ goes=}${GOES}"
append="${append}${GOESRC:+ goesrc=}${GOESRC}"
append="${append}${ROOT:+ root=/dev/vda}"
append="${append} loglevel=7 dyndbg=\"file\ init/initramfs.c:484\ +p\""
quote=${dryrun:+\\\"}
eval ${dryrun} ${qemu} ${M:+-M ${M}} -m 1G ${kvm:+--enable-kvm} \
${bios:+-bios }${bios} \
${kernel:+-kernel }${kernel} \
${initrd:+-initrd }${initrd} \
${dtb:+-dtb }${dtb} \
-no-reboot \
-nographic \
-device virtio-rng-pci \
${ROOT:+-drive file=${ROOT},if=ide,index=0,media=disk} \
${DISK:+-drive file=${DISK},if=ide,index=0,media=disk,format=raw} \
${netdev:+-netdev ${quote}\"${netdev}\"${quote}} \
${device:+-device ${quote}\"${device}\"${quote}} \
${kernel:+${append:+-append ${quote}\"${append}\"${quote}}}