-
Notifications
You must be signed in to change notification settings - Fork 0
/
run-magenta
executable file
·202 lines (179 loc) · 4.81 KB
/
run-magenta
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#!/usr/bin/env bash
# Copyright 2016 The Fuchsia Authors
#
# Use of this source code is governed by a MIT-style
# license that can be found in the LICENSE file or at
# https://opensource.org/licenses/MIT
function HELP {
echo "help:"
echo "-a <arch> : arm32, arm64, or x86-64"
echo "-b : build first"
echo "-c : add item to kernel commandline"
echo "-d : run with emulated disk"
echo "-g : use graphical console"
echo "-I <interface name> : network interface name, default is qemu."
echo "-k : use KVM"
echo "-m <memory in MB> : default 512MB"
echo "-n : run with emulated nic"
echo "-N : run with emulated nic via tun/tap"
echo "-o <dir> : build directory"
echo "-r : run release build"
echo "-s <number of cpus> : number of cpus, 1 for uniprocessor, default is 4"
echo "-v : use vnc based display"
echo "-x <bootfs> : add eXtra bootfs"
echo "-h for help"
echo "all arguments after -- are passed to qemu directly"
exit 1
}
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
ARCH=
AUDIO=0
BUILD=0
DISK=0
BUILDDIR=
GRAPHICS=0
DO_KVM=0
MEMSIZE=2048
NET=0
RELEASE=0
VNC=0
SMP=4
INITRD=
CMDLINE=""
if [ $(uname -s) == "Darwin" ]; then
IFNAME="tap0"
else
IFNAME="qemu"
fi
while getopts a:Abc:dgI:km:nNo:rs:vx:h FLAG; do
case $FLAG in
a) ARCH=$OPTARG;;
A) AUDIO=1;;
b) BUILD=1;;
c) CMDLINE+="$OPTARG ";;
d) DISK=1;;
g) GRAPHICS=1;;
I) IFNAME=$OPTARG;;
k) DO_KVM=1;;
m) MEMSIZE=$OPTARG;;
n) NET=1;;
N) NET=2;;
o) BUILDDIR=$OPTARG;;
r) RELEASE=1;;
s) SMP=$OPTARG;;
v) VNC=1;;
x) INITRD=$OPTARG;;
h) HELP;;
\?)
echo unrecognized option
HELP
esac
done
shift $((OPTIND-1))
# arch argument is non optional
if [ "$ARCH" == "" ]; then
echo must specify arch
HELP
fi
if [ "$ARCH" = "x86-64" ]; then
PROJECT=magenta-pc-x86-64
else
PROJECT=magenta-qemu-$ARCH
fi
# build the project if asked for
if [ "$BUILD" -eq 1 ]; then
if [ "$RELEASE" -eq 1 ]; then
$DIR/make-release $PROJECT || exit 1
else
$DIR/make-parallel $PROJECT || exit 1
fi
fi
# append the release path if requested
if [ "$RELEASE" -eq 1 ]; then
PROJECT=$PROJECT-release
fi
if [ "$BUILDDIR" == "" ]; then
BUILDDIR="$(dirname "$DIR")/build-$PROJECT"
fi
# construct the args for qemu
ARGS=" -m $MEMSIZE"
if [ "$VNC" -eq 1 ]; then
ARGS+=" -vnc :0"
fi
if [ "$GRAPHICS" -eq 0 ]; then
ARGS+=" -nographic"
else
ARGS+=" -serial stdio"
if [ "$ARCH" = "x86-64" ]; then
# Enable Bochs VBE device, which Magenta has a device for
ARGS+=" -vga std"
else
ARGS+=" -device virtio-gpu-device"
fi
fi
if [ "$DISK" -eq 1 ]; then
if [ "$ARCH" == "x86-64" ]; then
# ahci
ARGS+=" -drive file=blk.bin,if=none,id=mydisk -device ich9-ahci,id=ahci -device ide-drive,drive=mydisk,bus=ahci.0"
else
# virtio based block device
ARGS+=" -drive if=none,file=blk.bin,id=blk,format=raw -device virtio-blk-device,drive=blk"
fi
fi
if [ "$NET" -eq 1 ]; then
# virtio based network interface
if [ "$ARCH" == "x86-64" ]; then
ARGS+=" -netdev type=user,hostname=$IFNAME,id=net0 -device virtio-net-pci,netdev=net0"
else
ARGS+=" -netdev user,id=vmnic,hostname=$IFNAME -device virtio-net-device,netdev=vmnic"
fi
fi
if [ "$NET" -eq 2 ]; then
if [ $(uname -s) == "Darwin" ]; then
ARGS+=" -netdev type=tap,ifname=$IFNAME,script=no,id=net0"
else
ARGS+=" -netdev type=tap,ifname=$IFNAME,script=no,id=net0"
fi
if [ "$ARCH" == "x86-64" ]; then
ARGS+=" -device e1000,netdev=net0"
else
ARGS+=" -device virtio-net-device,netdev=net0"
fi
fi
if [ "$AUDIO" -ne 0 ]; then
ARGS+=" -soundhw hda"
export QEMU_AUDIO_DRV=none
fi
if [ "$SMP" -ne 1 ]; then
ARGS+=" -smp $SMP"
fi
case $ARCH in
arm32)
QEMU=qemu-system-arm
ARGS+=" -machine virt -cpu cortex-a15 -kernel $BUILDDIR/magenta.elf"
;;
arm64)
QEMU=qemu-system-aarch64
ARGS+=" -machine virt -cpu cortex-a53 -kernel $BUILDDIR/magenta.elf"
;;
x86-64)
QEMU=qemu-system-x86_64
ARGS+=" -machine q35 -kernel $BUILDDIR/magenta.bin"
if [ $DO_KVM -ne 0 ]; then
ARGS+=" -enable-kvm -cpu host"
else
ARGS+=" -cpu Haswell,+smap"
fi
;;
*)
echo unsupported arch
HELP
;;
esac
# ramdisk image
if [ "$INITRD" != "" ]; then
ARGS+=" -initrd $INITRD"
fi
# run qemu
echo $QEMU $ARGS -append "$CMDLINE" $@
$QEMU $ARGS -append "$CMDLINE" $@