summaryrefslogtreecommitdiffstats
path: root/scripts/runqemu-internal
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2011-04-20 16:44:10 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2011-04-21 00:29:29 +0100
commit08127d444e05d8d33ce39abdce677655bd4766ea (patch)
tree926947a62cc4b1cbed4afc31a717305de9b1c57d /scripts/runqemu-internal
parent46d0cc3dc88307d69a7884c0e5c79e0c8d5e4dc7 (diff)
downloadpoky-08127d444e05d8d33ce39abdce677655bd4766ea.tar.gz
Rename poky-qemu to runqemu
(From OE-Core rev: 7687d91f73f4a116593315b3b1488ac3f0904905) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/runqemu-internal')
-rwxr-xr-xscripts/runqemu-internal470
1 files changed, 470 insertions, 0 deletions
diff --git a/scripts/runqemu-internal b/scripts/runqemu-internal
new file mode 100755
index 0000000000..206e1cfe8a
--- /dev/null
+++ b/scripts/runqemu-internal
@@ -0,0 +1,470 @@
1#!/bin/bash -x
2
3# Handle running Poky images under qemu
4#
5# Copyright (C) 2006-2008 OpenedHand Ltd.
6#
7# This program is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License version 2 as
9# published by the Free Software Foundation.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License along
17# with this program; if not, write to the Free Software Foundation, Inc.,
18# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20# Call setting:
21# QEMU_MEMORY (optional) - set the amount of memory in the emualted system.
22# SERIAL_LOGFILE (optional) - log the serial port output to a file
23# CROSSPATH - the path to any cross toolchain to use with distcc
24#
25# Image options:
26# MACHINE - the machine to run
27# FSTYPE - the image type to run
28# KERNEL - the kernel image file to use
29# ROOTFS - the disk image file to use
30#
31
32
33mem_size=-1
34
35#Get rid of <> and get the contents of extra qemu running params
36SCRIPT_QEMU_EXTRA_OPT=`echo $SCRIPT_QEMU_EXTRA_OPT | sed -e 's/<//' -e 's/>//'`
37#if user set qemu memory, eg: -m 256 in qemu extra params, we need to do some
38# validation check
39mem_set=`expr "$SCRIPT_QEMU_EXTRA_OPT" : '.*\(-m[[:space:]] *[0-9]*\)'`
40if [ ! -z "$mem_set" ] ; then
41#Get memory setting size from user input
42 mem_size=`echo $mem_set | sed 's/-m[[:space:]] *//'`
43else
44 case "$MACHINE" in
45 "qemux86")
46 mem_size=128
47 ;;
48 "qemux86-64")
49 mem_size=128
50 ;;
51 "qemuarm")
52 mem_size=128
53 ;;
54 "qemumips")
55 mem_size=128
56 ;;
57 "qemuppc")
58 mem_size=128
59 ;;
60 *)
61 mem_size=64
62 ;;
63 esac
64
65fi
66
67# QEMU_MEMORY has 'M' appended to mem_size
68QEMU_MEMORY="$mem_size"M
69
70# Bug 433: qemuarm cannot use > 128 MB RAM
71if [ "$MACHINE" = "qemuarm" ]; then
72 if [[ -z "$mem_size" || $mem_size -gt 128 ]]; then
73 echo "WARNING: qemuarm does not support > 128M of RAM."
74 echo "Changing QEMU_MEMORY to default of 128M."
75 QEMU_MEMORY="128M"
76 SCRIPT_QEMU_EXTRA_OPT=`echo $SCRIPT_QEMU_EXTRA_OPT | sed -e "s/$mem_set/-m 128/" `
77 fi
78fi
79
80# We need to specify -m <mem_size> to overcome a bug in qemu 0.14.0
81# https://bugs.launchpad.net/ubuntu/+source/qemu-kvm/+bug/584480
82
83if [ -z "$mem_set" ] ; then
84 SCRIPT_QEMU_EXTRA_OPT="$SCRIPT_QEMU_EXTRA_OPT -m $mem_size"
85fi
86# This file is created when poky-gen-tapdevs creates a bank of tap
87# devices, indicating that the user should not bring up new ones using
88# sudo.
89NOSUDO_FLAG="/etc/poky-nosudo"
90
91QEMUIFUP=`which runqemu-ifup`
92QEMUIFDOWN=`which runqemu-ifdown`
93
94NFSRUNNING="false"
95
96acquire_lock() {
97 lockfile=$1
98 if [ -z "$lockfile" ]; then
99 echo "Error: missing lockfile arg passed to acquire_lock()"
100 return 1
101 fi
102
103 if [ -e "$lockfile.lock" ]; then
104 # Check that the lockfile is not stale
105 ps=`ps -ewwo pid | grep $(cat $lockfile.lock)`
106 if [ -z "$ps" ]; then
107 echo "WARNING: Stale lock file detected, deleting $lockfile.lock."
108 rm -f $lockfile.lock
109 echo $$ > $lockfile.lock
110 else
111 return 1
112 fi
113 else
114 echo $$ > $lockfile.lock
115 fi
116
117 return 0
118}
119
120release_lock() {
121 lockfile=$1
122 if [ -z "$lockfile" ]; then
123 echo "Error: missing lockfile arg passed to release_lock()"
124 return 1
125 fi
126
127 rm -f $lockfile.lock
128}
129
130LOCKDIR="/tmp/qemu-tap-locks"
131if [ ! -d "$LOCKDIR" ]; then
132 mkdir $LOCKDIR
133 chmod 777 $LOCKDIR
134fi
135
136IFCONFIG=`which ifconfig`
137if [ -z "$IFCONFIG" ]; then
138 IFCONFIG=/sbin/ifconfig
139fi
140
141POSSIBLE=`$IFCONFIG -a | grep '^tap' | awk '{print $1}'`
142TAP=""
143LOCKFILE=""
144for tap in $POSSIBLE; do
145 LOCKFILE="$LOCKDIR/$tap"
146 echo "Acquiring lockfile for $tap..."
147 acquire_lock $LOCKFILE
148 if [ $? -eq 0 ]; then
149 TAP=$tap
150 break
151 fi
152done
153
154if [ "$TAP" = "" ]; then
155 if [ -e "$NOSUDO_FLAG" ]; then
156 echo "Error: There are no available tap devices to use for networking,"
157 echo "and I see $NOSUDO_FLAG exists, so I am not going to try creating"
158 echo "a new one with sudo."
159 exit 1
160 fi
161
162 GROUPID=`id -g`
163 echo "Setting up tap interface under sudo"
164 tap=`sudo $QEMUIFUP $GROUPID $POKY_NATIVE_SYSROOT`
165 if [ $? -ne 0 ]; then
166 # Re-run standalone to see verbose errors
167 sudo $QEMUIFUP $GROUPID $POKY_NATIVE_SYSROOT
168 return
169 fi
170 LOCKFILE="$LOCKDIR/$tap"
171 echo "Acquiring lockfile for $tap..."
172 acquire_lock $LOCKFILE
173 if [ $? -eq 0 ]; then
174 TAP=$tap
175 fi
176else
177 echo "Using preconfigured tap device '$TAP'"
178fi
179
180cleanup() {
181 if [ ! -e "$NOSUDO_FLAG" ]; then
182 sudo $QEMUIFDOWN $TAP $POKY_NATIVE_SYSROOT
183 fi
184 echo "Releasing lockfile of preconfigured tap device '$TAP'"
185 release_lock $LOCKFILE
186
187 if [ "$NFSRUNNING" = "true" ]; then
188 echo "Shutting down the userspace NFS server..."
189 echo "poky-export-rootfs stop $ROOTFS"
190 poky-export-rootfs stop $ROOTFS
191 fi
192 # If QEMU crashes or somehow tty properties are not restored
193 # after qemu exits, we need to run stty sane
194 stty sane
195}
196
197n1=$[ (`echo $TAP | sed 's/tap//'` * 2) + 1 ]
198n2=$[ (`echo $TAP | sed 's/tap//'` * 2) + 2 ]
199
200KERNEL_NETWORK_CMD="ip=192.168.7.$n2::192.168.7.$n1:255.255.255.0"
201QEMU_TAP_CMD="-net tap,vlan=0,ifname=$TAP,script=no,downscript=no"
202QEMU_NETWORK_CMD="-net nic,vlan=0 $QEMU_TAP_CMD"
203KERNCMDLINE="mem=$QEMU_MEMORY"
204QEMU_UI_OPTIONS="-show-cursor -usb -usbdevice wacom-tablet"
205
206NFS_INSTANCE=`echo $TAP | sed 's/tap//'`
207export NFS_INSTANCE
208
209SERIALOPTS=""
210if [ "x$SERIAL_LOGFILE" != "x" ]; then
211 SERIALOPTS="-serial file:$SERIAL_LOGFILE"
212fi
213
214case "$MACHINE" in
215 "qemuarm") ;;
216 "qemumips") ;;
217 "qemuppc") ;;
218 "qemuarmv6") ;;
219 "qemuarmv7") ;;
220 "qemux86") ;;
221 "qemux86-64") ;;
222 "akita") ;;
223 "spitz") ;;
224 *)
225 echo "Error: Unsupported machine type $MACHINE"
226 return
227 ;;
228esac
229
230if [ ! -f "$KERNEL" ]; then
231 echo "Error: Kernel image file $KERNEL doesn't exist"
232 cleanup
233 return
234fi
235
236if [ "$FSTYPE" != "nfs" -a ! -f "$ROOTFS" ]; then
237 echo "Error: Image file $ROOTFS doesn't exist"
238 cleanup
239 return
240fi
241
242if [ "$FSTYPE" = "nfs" ]; then
243 NFS_SERVER="192.168.7.1"
244 NFS_DIR=`echo $ROOTFS | sed 's/^[^:]*:\(.*\)/\1/'`
245 MOUNTD_PORT=$[ 21111 + $NFS_INSTANCE ]
246 NFSD_PORT=$[ 11111 + $NFS_INSTANCE ]
247 UNFS_OPTS="nfsvers=2,mountprog=$MOUNTD_PORT,nfsprog=$NFSD_PORT,udp"
248
249 PSEUDO_LOCALSTATEDIR=~/.poky-sdk/pseudo
250 export PSEUDO_LOCALSTATEDIR
251
252 rpcbind_running=`ps ax | grep rpcbind | grep -v grep | wc -l`
253 portmap_running=`ps ax | grep portmap | grep -v grep | wc -l`
254 if [[ $rpcbind_running == 0 && $portmap_running == 0 ]]; then
255 echo "You need to be running either rpcbind or portmap to continue"
256 cleanup
257 return
258 fi
259
260 # Start the userspace NFS server
261 echo "poky-export-rootfs restart $ROOTFS"
262 poky-export-rootfs restart $ROOTFS
263 if [ $? != 0 ]; then
264 cleanup
265 return
266 fi
267 NFSRUNNING="true"
268fi
269
270if [ "$NFS_SERVER" = "" ]; then
271 NFS_SERVER="192.168.7.1"
272 NFS_DIR=$ROOTFS
273fi
274
275if [ "$MACHINE" = "qemuarm" -o "$MACHINE" = "qemuarmv6" -o "$MACHINE" = "qemuarmv7" ]; then
276 QEMU=qemu-system-arm
277 MACHINE_SUBTYPE=versatilepb
278 QEMU_UI_OPTIONS="$QEMU_UI_OPTIONS"
279 # QEMU_UI_OPTIONS="$QEMU_UI_OPTIONS -force-pointer"
280 if [ "$FSTYPE" = "ext3" ]; then
281 KERNCMDLINE="root=/dev/sda rw console=ttyAMA0,115200 console=tty $KERNEL_NETWORK_CMD mem=$QEMU_MEMORY highres=off"
282 QEMUOPTIONS="$QEMU_NETWORK_CMD -M versatilepb -hda $ROOTFS -no-reboot $QEMU_UI_OPTIONS"
283 fi
284 if [ "$FSTYPE" = "nfs" ]; then
285 if [ "$NFS_SERVER" = "192.168.7.1" -a ! -d "$NFS_DIR" ]; then
286 echo "Error: NFS mount point $ROOTFS doesn't exist"
287 cleanup
288 return
289 fi
290 KERNCMDLINE="root=/dev/nfs nfsroot=$NFS_SERVER:$NFS_DIR,$UNFS_OPTS rw $KERNEL_NETWORK_CMD mem=$QEMU_MEMORY"
291 QEMUOPTIONS="$QEMU_NETWORK_CMD -M versatilepb --no-reboot $QEMU_UI_OPTIONS"
292 fi
293 if [ "$MACHINE" = "qemuarmv6" ]; then
294 QEMUOPTIONS="$QEMUOPTIONS -cpu arm1136"
295 fi
296 if [ "$MACHINE" = "qemuarmv7" ]; then
297 QEMUOPTIONS="$QEMUOPTIONS -cpu cortex-a8"
298 fi
299fi
300
301if [ "$MACHINE" = "qemux86" ]; then
302 QEMU=qemu
303 QEMU_UI_OPTIONS="$QEMU_UI_OPTIONS -vga vmware -enable-gl"
304 if [ "$FSTYPE" = "ext3" ]; then
305 KERNCMDLINE="vga=0 root=/dev/hda rw mem=$QEMU_MEMORY $KERNEL_NETWORK_CMD"
306 QEMUOPTIONS="$QEMU_NETWORK_CMD -hda $ROOTFS $QEMU_UI_OPTIONS"
307 fi
308 if [ "$FSTYPE" = "nfs" ]; then
309 if [ "$NFS_SERVER" = "192.168.7.1" -a ! -d "$NFS_DIR" ]; then
310 echo "Error: NFS mount point $ROOTFS doesn't exist."
311 cleanup
312 return
313 fi
314 KERNCMDLINE="root=/dev/nfs nfsroot=$NFS_SERVER:$NFS_DIR,$UNFS_OPTS rw $KERNEL_NETWORK_CMD mem=$QEMU_MEMORY"
315 QEMUOPTIONS="$QEMU_NETWORK_CMD $QEMU_UI_OPTIONS"
316 fi
317 # Currently oprofile's event based interrupt mode doesn't work(Bug #828) in
318 # qemux86 and qemux86-64. We can use timer interrupt mode for now.
319 KERNCMDLINE="$KERNCMDLINE oprofile.timer=1"
320fi
321
322if [ "$MACHINE" = "qemux86-64" ]; then
323 QEMU=qemu-system-x86_64
324 QEMU_UI_OPTIONS="$QEMU_UI_OPTIONS -vga vmware -enable-gl"
325 if [ "$FSTYPE" = "ext3" ]; then
326 KERNCMDLINE="vga=0 root=/dev/hda rw mem=$QEMU_MEMORY $KERNEL_NETWORK_CMD"
327 QEMUOPTIONS="$QEMU_NETWORK_CMD -hda $ROOTFS $QEMU_UI_OPTIONS"
328 fi
329 if [ "$FSTYPE" = "nfs" ]; then
330 if [ "x$ROOTFS" = "x" ]; then
331 ROOTFS=/srv/nfs/qemux86-64
332 fi
333 if [ ! -d "$ROOTFS" ]; then
334 echo "Error: NFS mount point $ROOTFS doesn't exist."
335 cleanup
336 return
337 fi
338 KERNCMDLINE="root=/dev/nfs nfsroot=$NFS_SERVER:$NFS_DIR,$UNFS_OPTS rw $KERNEL_NETWORK_CMD mem=$QEMU_MEMORY"
339 QEMUOPTIONS="$QEMU_NETWORK_CMD $QEMU_UI_OPTIONS"
340 fi
341 # Currently oprofile's event based interrupt mode doesn't work(Bug #828) in
342 # qemux86 and qemux86-64. We can use timer interrupt mode for now.
343 KERNCMDLINE="$KERNCMDLINE oprofile.timer=1"
344fi
345
346if [ "$MACHINE" = "spitz" ]; then
347 QEMU=qemu-system-arm
348 if [ "$FSTYPE" = "ext3" ]; then
349 echo $ROOTFS
350 ROOTFS=`readlink -f $ROOTFS`
351 echo $ROOTFS
352 if [ ! -e "$ROOTFS.qemudisk" ]; then
353 echo "Adding a partition table to the ext3 image for use by QEMU, please wait..."
354 poky-addptable2image $ROOTFS $ROOTFS.qemudisk
355 fi
356 QEMUOPTIONS="$QEMU_NETWORK_CMD -M spitz -hda $ROOTFS.qemudisk -portrait"
357 fi
358fi
359
360if [ "$MACHINE" = "qemumips" ]; then
361 QEMU=qemu-system-mips
362 MACHINE_SUBTYPE=malta
363 QEMU_UI_OPTIONS="-vga cirrus $QEMU_UI_OPTIONS"
364 if [ "$FSTYPE" = "ext3" ]; then
365 #KERNCMDLINE="root=/dev/hda console=ttyS0 console=tty0 $KERNEL_NETWORK_CMD mem=$QEMU_MEMORY"
366 KERNCMDLINE="root=/dev/hda rw console=ttyS0 console=tty $KERNEL_NETWORK_CMD mem=$QEMU_MEMORY"
367 QEMUOPTIONS="$QEMU_NETWORK_CMD -M $MACHINE_SUBTYPE -hda $ROOTFS -no-reboot $QEMU_UI_OPTIONS"
368 fi
369 if [ "$FSTYPE" = "nfs" ]; then
370 if [ "$NFS_SERVER" = "192.168.7.1" -a ! -d "$NFS_DIR" ]; then
371 echo "Error: NFS mount point $ROOTFS doesn't exist"
372 cleanup
373 return
374 fi
375 KERNCMDLINE="root=/dev/nfs console=ttyS0 console=tty nfsroot=$NFS_SERVER:$NFS_DIR,$UNFS_OPTS rw $KERNEL_NETWORK_CMD mem=$QEMU_MEMORY"
376 QEMUOPTIONS="$QEMU_NETWORK_CMD -M $MACHINE_SUBTYPE -no-reboot $QEMU_UI_OPTIONS"
377 fi
378fi
379
380if [ "$MACHINE" = "qemuppc" ]; then
381 QEMU=qemu-system-ppc
382 MACHINE_SUBTYPE=prep
383 CPU_SUBTYPE=603e
384 BIOS=powerpc_rom.bin
385 QEMU_UI_OPTIONS="$QEMU_UI_OPTIONS -nographic"
386 if [ "$FSTYPE" = "ext3" ]; then
387 KERNCMDLINE="root=/dev/hda rw console=ttyS0 console=tty0 $KERNEL_NETWORK_CMD mem=$QEMU_MEMORY"
388 QEMUOPTIONS="$QEMU_NETWORK_CMD -cpu $CPU_SUBTYPE -M $MACHINE_SUBTYPE -bios $BIOS -hda $ROOTFS -no-reboot $QEMU_UI_OPTIONS"
389 fi
390 if [ "$FSTYPE" = "nfs" ]; then
391 if [ "$NFS_SERVER" = "192.168.7.1" -a ! -d "$NFS_DIR" ]; then
392 echo "Error: NFS mount point $ROOTFS doesn't exist"
393 cleanup
394 return
395 fi
396 KERNCMDLINE="root=/dev/nfs console=ttyS0 console=tty0 nfsroot=$NFS_SERVER:$NFS_DIR,$UNFS_OPTS rw $KERNEL_NETWORK_CMD mem=$QEMU_MEMORY"
397 QEMUOPTIONS="$QEMU_NETWORK_CMD -cpu $CPU_SUBTYPE -M $MACHINE_SUBTYPE -bios $BIOS -no-reboot $QEMU_UI_OPTIONS"
398 fi
399fi
400
401if [ "$MACHINE" = "akita" ]; then
402 QEMU=qemu-system-arm
403 if [ "$FSTYPE" = "jffs2" ]; then
404 ROOTFS=`readlink -f $ROOTFS`
405 if [ ! -e "$ROOTFS.qemuflash" ]; then
406 echo "Converting raw image into flash image format for use by QEMU, please wait..."
407 raw2flash.akita < $ROOTFS > $ROOTFS.qemuflash
408 fi
409 QEMUOPTIONS="$QEMU_NETWORK_CMD -M akita -mtdblock $ROOTFS.qemuflash -portrait"
410 fi
411fi
412
413if [ "x$QEMUOPTIONS" = "x" ]; then
414 echo "Error: Unable to support this combination of options"
415 cleanup
416 return
417fi
418
419PATH=$CROSSPATH:$POKY_NATIVE_SYSROOT/usr/bin:$PATH
420
421QEMUBIN=`which $QEMU`
422if [ ! -x "$QEMUBIN" ]; then
423 echo "Error: No QEMU binary '$QEMU' could be found."
424 cleanup
425 return
426fi
427
428function _quit() {
429 if [ -n "$PIDFILE" ]; then
430 #echo kill `cat $PIDFILE`
431 kill `cat $PIDFILE`
432 fi
433 cleanup
434 return
435}
436
437DISTCCD=`which distccd`
438PIDFILE=""
439
440trap _quit INT TERM QUIT
441
442if [ -x "$DISTCCD" ]; then
443 echo "Starting distccd..."
444 PIDFILE=`mktemp`
445 $DISTCCD --allow 192.168.7.2 --daemon --pid-file $PIDFILE &
446else
447 echo "WARNING: distccd not present, no distcc support loaded."
448fi
449
450# qemu got segfault if linked with nVidia's libgl
451if ldd $QEMUBIN | grep -i nvidia &> /dev/null
452then
453cat << EOM
454WARNING: nVidia proprietary OpenGL libraries detected.
455nVidia's OpenGL libraries are known to have compatibility issues with qemu,
456resulting in a segfault. Please uninstall these drivers or ensure the mesa libGL
457libraries precede nvidia's via LD_PRELOAD.
458EOM
459fi
460
461echo "Running $QEMU..."
462# -no-reboot is a mandatory option - see bug #100
463echo $QEMUBIN -kernel $KERNEL $QEMUOPTIONS $SERIALOPTS -no-reboot $SCRIPT_QEMU_OPT $SCRIPT_QEMU_EXTRA_OPT --append '"'$KERNCMDLINE $SCRIPT_KERNEL_OPT'"'
464$QEMUBIN -kernel $KERNEL $QEMUOPTIONS $SERIALOPTS -no-reboot $SCRIPT_QEMU_OPT $SCRIPT_QEMU_EXTRA_OPT --append "$KERNCMDLINE $SCRIPT_KERNEL_OPT"
465
466
467cleanup
468
469trap - INT TERM QUIT
470return