summaryrefslogtreecommitdiffstats
path: root/scripts/runqemu-internal
diff options
context:
space:
mode:
authorAdrian Dudau <adrian.dudau@enea.com>2013-12-12 13:38:32 +0100
committerAdrian Dudau <adrian.dudau@enea.com>2013-12-12 13:50:20 +0100
commite2e6f6fe07049f33cb6348780fa975162752e421 (patch)
treeb1813295411235d1297a0ed642b1346b24fdfb12 /scripts/runqemu-internal
downloadpoky-e2e6f6fe07049f33cb6348780fa975162752e421.tar.gz
initial commit of Enea Linux 3.1
Migrated from the internal git server on the dora-enea branch Signed-off-by: Adrian Dudau <adrian.dudau@enea.com>
Diffstat (limited to 'scripts/runqemu-internal')
-rwxr-xr-xscripts/runqemu-internal634
1 files changed, 634 insertions, 0 deletions
diff --git a/scripts/runqemu-internal b/scripts/runqemu-internal
new file mode 100755
index 0000000000..74b0c356d0
--- /dev/null
+++ b/scripts/runqemu-internal
@@ -0,0 +1,634 @@
1#!/bin/bash -x
2
3# Handle running OE images under qemu
4#
5# Copyright (C) 2006-2011 Linux Foundation
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#
24# Image options:
25# MACHINE - the machine to run
26# FSTYPE - the image type to run
27# KERNEL - the kernel image file to use
28# ROOTFS - the disk image file to use
29#
30
31
32mem_size=-1
33
34#Get rid of <> and get the contents of extra qemu running params
35SCRIPT_QEMU_EXTRA_OPT=`echo $SCRIPT_QEMU_EXTRA_OPT | sed -e 's/<//' -e 's/>//'`
36#if user set qemu memory, eg: -m 256 in qemu extra params, we need to do some
37# validation check
38mem_set=`expr "$SCRIPT_QEMU_EXTRA_OPT" : '.*\(-m[[:space:]] *[0-9]*\)'`
39if [ ! -z "$mem_set" ] ; then
40#Get memory setting size from user input
41 mem_size=`echo $mem_set | sed 's/-m[[:space:]] *//'`
42else
43 case "$MACHINE" in
44 "qemux86")
45 mem_size=256
46 ;;
47 "qemux86-64")
48 mem_size=256
49 ;;
50 "qemuarm")
51 mem_size=128
52 ;;
53 "qemumicroblaze")
54 mem_size=64
55 ;;
56 "qemumips"|"qemumips64")
57 mem_size=256
58 ;;
59 "qemuppc")
60 mem_size=256
61 ;;
62 "qemush4")
63 mem_size=1024
64 ;;
65 "qemuzynq")
66 mem_size=1024
67 ;;
68 *)
69 mem_size=64
70 ;;
71 esac
72
73fi
74
75# QEMU_MEMORY has 'M' appended to mem_size
76QEMU_MEMORY="$mem_size"M
77
78# Bug 433: qemuarm cannot use > 256 MB RAM
79if [ "$MACHINE" = "qemuarm" ]; then
80 if [ -z "$mem_size" -o $mem_size -gt 256 ]; then
81 echo "WARNING: qemuarm does not support > 256M of RAM."
82 echo "Changing QEMU_MEMORY to default of 256M."
83 QEMU_MEMORY="256M"
84 mem_size="256"
85 SCRIPT_QEMU_EXTRA_OPT=`echo $SCRIPT_QEMU_EXTRA_OPT | sed -e "s/$mem_set/-m 256/" `
86 fi
87fi
88
89# We need to specify -m <mem_size> to overcome a bug in qemu 0.14.0
90# https://bugs.launchpad.net/ubuntu/+source/qemu-kvm/+bug/584480
91
92if [ -z "$mem_set" ] ; then
93 SCRIPT_QEMU_EXTRA_OPT="$SCRIPT_QEMU_EXTRA_OPT -m $mem_size"
94fi
95# This file is created when runqemu-gen-tapdevs creates a bank of tap
96# devices, indicating that the user should not bring up new ones using
97# sudo.
98NOSUDO_FLAG="/etc/runqemu-nosudo"
99
100QEMUIFUP=`which runqemu-ifup 2> /dev/null`
101QEMUIFDOWN=`which runqemu-ifdown 2> /dev/null`
102if [ -z "$QEMUIFUP" -o ! -x "$QEMUIFUP" ]; then
103 echo "runqemu-ifup cannot be found or executed"
104 exit 1
105fi
106if [ -z "$QEMUIFDOWN" -o ! -x "$QEMUIFDOWN" ]; then
107 echo "runqemu-ifdown cannot be found or executed"
108 exit 1
109fi
110
111NFSRUNNING="false"
112
113#capture original stty values
114ORIG_STTY=$(stty -g)
115
116if [ "$SLIRP_ENABLED" = "yes" ]; then
117 KERNEL_NETWORK_CMD=""
118 QEMU_TAP_CMD=""
119 QEMU_UI_OPTIONS="-show-cursor -usb -usbdevice wacom-tablet"
120 if [ "$KVM_ACTIVE" = "yes" ]; then
121 QEMU_NETWORK_CMD=""
122 DROOT="/dev/vda"
123 ROOTFS_OPTIONS="-drive file=$ROOTFS,if=virtio"
124 else
125 QEMU_NETWORK_CMD=""
126 DROOT="/dev/hda"
127 ROOTFS_OPTIONS="-hda $ROOTFS"
128 fi
129
130else
131 acquire_lock() {
132 lockfile=$1
133 if [ -z "$lockfile" ]; then
134 echo "Error: missing lockfile arg passed to acquire_lock()"
135 return 1
136 fi
137
138 touch $lockfile.lock
139 exec 8>$lockfile.lock
140 flock -n -x 8
141 if [ $? -ne 0 ]; then
142 exec 8>&-
143 return 1
144 fi
145
146 return 0
147 }
148
149 release_lock() {
150 lockfile=$1
151 if [ -z "$lockfile" ]; then
152 echo "Error: missing lockfile arg passed to release_lock()"
153 return 1
154 fi
155
156 rm -f $lockfile.lock
157 exec 8>&-
158 }
159
160 LOCKDIR="/tmp/qemu-tap-locks"
161 if [ ! -d "$LOCKDIR" ]; then
162 mkdir $LOCKDIR
163 chmod 777 $LOCKDIR
164 fi
165
166 IFCONFIG=`which ip 2> /dev/null`
167 if [ -z "$IFCONFIG" ]; then
168 IFCONFIG=/sbin/ip
169 fi
170 if [ ! -x "$IFCONFIG" ]; then
171 echo "$IFCONFIG cannot be executed"
172 exit 1
173 fi
174
175 POSSIBLE=`$IFCONFIG link | grep 'tap' | awk '{print $2}' | sed s/://`
176 TAP=""
177 LOCKFILE=""
178 USE_PRECONF_TAP="no"
179 for tap in $POSSIBLE; do
180 LOCKFILE="$LOCKDIR/$tap"
181 echo "Acquiring lockfile for $tap..."
182 acquire_lock $LOCKFILE
183 if [ $? -eq 0 ]; then
184 TAP=$tap
185 USE_PRECONF_TAP="yes"
186 break
187 fi
188 done
189
190 if [ "$TAP" = "" ]; then
191 if [ -e "$NOSUDO_FLAG" ]; then
192 echo "Error: There are no available tap devices to use for networking,"
193 echo "and I see $NOSUDO_FLAG exists, so I am not going to try creating"
194 echo "a new one with sudo."
195 exit 1
196 fi
197
198 GROUPID=`id -g`
199 USERID=`id -u`
200 echo "Setting up tap interface under sudo"
201 # Redirect stderr since we could see a LD_PRELOAD warning here if pseudo is loaded
202 # but inactive. This looks scary but is harmless
203 tap=`sudo $QEMUIFUP $USERID $GROUPID $OECORE_NATIVE_SYSROOT 2> /dev/null`
204 if [ $? -ne 0 ]; then
205 # Re-run standalone to see verbose errors
206 sudo $QEMUIFUP $USERID $GROUPID $OECORE_NATIVE_SYSROOT
207 return 1
208 fi
209 LOCKFILE="$LOCKDIR/$tap"
210 echo "Acquiring lockfile for $tap..."
211 acquire_lock $LOCKFILE
212 if [ $? -eq 0 ]; then
213 TAP=$tap
214 fi
215 else
216 echo "Using preconfigured tap device '$TAP'"
217 echo "If this is not intended, use flock on $LOCKFILE.lock to make runqemu skip $TAP."
218 fi
219
220 cleanup() {
221 if [ ! -e "$NOSUDO_FLAG" -a "$USE_PRECONF_TAP" = "no" ]; then
222 # Redirect stderr since we could see a LD_PRELOAD warning here if pseudo is loaded
223 # but inactive. This looks scary but is harmless
224 sudo $QEMUIFDOWN $TAP $OECORE_NATIVE_SYSROOT 2> /dev/null
225 fi
226 echo "Releasing lockfile of preconfigured tap device '$TAP'"
227 release_lock $LOCKFILE
228
229 if [ "$NFSRUNNING" = "true" ]; then
230 echo "Shutting down the userspace NFS server..."
231 echo "runqemu-export-rootfs stop $ROOTFS"
232 runqemu-export-rootfs stop $ROOTFS
233 fi
234 # If QEMU crashes or somehow tty properties are not restored
235 # after qemu exits, we need to run stty sane
236 #stty sane
237
238 #instead of using stty sane we set the original stty values
239 stty ${ORIG_STTY}
240
241 }
242
243
244 n0=$(echo $TAP | sed 's/tap//')
245 n1=$(($n0 * 2 + 1))
246 n2=$(($n1 + 1))
247
248 KERNEL_NETWORK_CMD="ip=192.168.7.$n2::192.168.7.$n1:255.255.255.0"
249 QEMU_TAP_CMD="-net tap,vlan=0,ifname=$TAP,script=no,downscript=no"
250 if [ "$KVM_ACTIVE" = "yes" ]; then
251 QEMU_NETWORK_CMD="-net nic,model=virtio $QEMU_TAP_CMD,vhost=on"
252 DROOT="/dev/vda"
253 ROOTFS_OPTIONS="-drive file=$ROOTFS,if=virtio"
254 else
255 QEMU_NETWORK_CMD="-net nic,vlan=0 $QEMU_TAP_CMD"
256 DROOT="/dev/hda"
257 ROOTFS_OPTIONS="-hda $ROOTFS"
258 fi
259 KERNCMDLINE="mem=$QEMU_MEMORY"
260 QEMU_UI_OPTIONS="-show-cursor -usb -usbdevice wacom-tablet"
261
262 NFS_INSTANCE=`echo $TAP | sed 's/tap//'`
263 export NFS_INSTANCE
264
265 SERIALOPTS=""
266 if [ "x$SERIAL_LOGFILE" != "x" ]; then
267 SERIALOPTS="-serial file:$SERIAL_LOGFILE"
268 fi
269fi
270
271case "$MACHINE" in
272 "qemuarm") ;;
273 "qemumicroblaze") ;;
274 "qemumips") ;;
275 "qemumipsel") ;;
276 "qemumips64") ;;
277 "qemush4") ;;
278 "qemuppc") ;;
279 "qemuarmv6") ;;
280 "qemuarmv7") ;;
281 "qemux86") ;;
282 "qemux86-64") ;;
283 "qemuzynq") ;;
284 "akita") ;;
285 "spitz") ;;
286 *)
287 echo "Error: Unsupported machine type $MACHINE"
288 return 1
289 ;;
290esac
291
292if [ ! -f "$KERNEL" -a "x$FSTYPE" != "xvmdk" ]; then
293 echo "Error: Kernel image file $KERNEL doesn't exist"
294 cleanup
295 return 1
296fi
297
298if [ "$FSTYPE" != "nfs" -a "$FSTYPE" != "vmdk" -a ! -f "$ROOTFS" ]; then
299 echo "Error: Image file $ROOTFS doesn't exist"
300 cleanup
301 return 1
302fi
303
304if [ "$FSTYPE" = "nfs" ]; then
305 NFS_SERVER="192.168.7.1"
306 NFS_DIR=`echo $ROOTFS | sed 's/^[^:]*:\(.*\)/\1/'`
307 MOUNTD_RPCPORT=$[ 21111 + $NFS_INSTANCE ]
308 NFSD_RPCPORT=$[ 11111 + $NFS_INSTANCE ]
309 NFSD_PORT=$[ 3049 + 2 * $NFS_INSTANCE ]
310 MOUNTD_PORT=$[ 3048 + 2 * $NFS_INSTANCE ]
311 UNFS_OPTS="nfsvers=2,mountprog=$MOUNTD_RPCPORT,nfsprog=$NFSD_RPCPORT,udp,port=$NFSD_PORT,mountport=$MOUNTD_PORT"
312
313 PSEUDO_LOCALSTATEDIR=~/.runqemu-sdk/pseudo
314 export PSEUDO_LOCALSTATEDIR
315
316 # Start the userspace NFS server
317 echo "runqemu-export-rootfs restart $ROOTFS"
318 runqemu-export-rootfs restart $ROOTFS
319 if [ $? != 0 ]; then
320 cleanup
321 return 1
322 fi
323 NFSRUNNING="true"
324fi
325
326if [ "$NFS_SERVER" = "" ]; then
327 NFS_SERVER="192.168.7.1"
328 NFS_DIR=$ROOTFS
329fi
330
331if [ "$MACHINE" = "qemuarm" -o "$MACHINE" = "qemuarmv6" -o "$MACHINE" = "qemuarmv7" ]; then
332 QEMU=qemu-system-arm
333 MACHINE_SUBTYPE=versatilepb
334 export QEMU_AUDIO_DRV="none"
335 QEMU_UI_OPTIONS="$QEMU_UI_OPTIONS"
336 # QEMU_UI_OPTIONS="$QEMU_UI_OPTIONS -force-pointer"
337 if [ "${FSTYPE:0:3}" = "ext" -o "$FSTYPE" = "btrfs" ]; then
338 KERNCMDLINE="root=/dev/sda rw console=ttyAMA0,115200 console=tty $KERNEL_NETWORK_CMD mem=$QEMU_MEMORY highres=off"
339 QEMUOPTIONS="$QEMU_NETWORK_CMD -M ${MACHINE_SUBTYPE} -hda $ROOTFS -no-reboot $QEMU_UI_OPTIONS"
340 fi
341 if [ "$FSTYPE" = "nfs" ]; then
342 if [ "$NFS_SERVER" = "192.168.7.1" -a ! -d "$NFS_DIR" ]; then
343 echo "Error: NFS mount point $ROOTFS doesn't exist"
344 cleanup
345 return 1
346 fi
347 KERNCMDLINE="root=/dev/nfs nfsroot=$NFS_SERVER:$NFS_DIR,$UNFS_OPTS rw $KERNEL_NETWORK_CMD mem=$QEMU_MEMORY"
348 QEMUOPTIONS="$QEMU_NETWORK_CMD -M ${MACHINE_SUBTYPE} --no-reboot $QEMU_UI_OPTIONS"
349 fi
350 if [ "$MACHINE" = "qemuarmv6" ]; then
351 QEMUOPTIONS="$QEMUOPTIONS -cpu arm1136"
352 fi
353 if [ "$MACHINE" = "qemuarmv7" ]; then
354 QEMUOPTIONS="$QEMUOPTIONS -cpu cortex-a8"
355 fi
356fi
357
358if [ "$MACHINE" = "qemux86" ]; then
359 QEMU=qemu-system-i386
360 QEMU_UI_OPTIONS="$QEMU_UI_OPTIONS -vga vmware"
361 if [ "${FSTYPE:0:3}" = "ext" -o "$FSTYPE" = "btrfs" ]; then
362 KERNCMDLINE="vga=0 uvesafb.mode_option=640x480-32 root=$DROOT rw mem=$QEMU_MEMORY $KERNEL_NETWORK_CMD"
363 QEMUOPTIONS="$QEMU_NETWORK_CMD $ROOTFS_OPTIONS $QEMU_UI_OPTIONS"
364 fi
365 if [ "$FSTYPE" = "nfs" ]; then
366 if [ "$NFS_SERVER" = "192.168.7.1" -a ! -d "$NFS_DIR" ]; then
367 echo "Error: NFS mount point $ROOTFS doesn't exist."
368 cleanup
369 return 1
370 fi
371 KERNCMDLINE="root=/dev/nfs nfsroot=$NFS_SERVER:$NFS_DIR,$UNFS_OPTS rw $KERNEL_NETWORK_CMD mem=$QEMU_MEMORY"
372 QEMUOPTIONS="$QEMU_NETWORK_CMD $QEMU_UI_OPTIONS"
373 fi
374 if [ "$FSTYPE" = "vmdk" ]; then
375 QEMUOPTIONS="$QEMU_NETWORK_CMD $QEMU_UI_OPTIONS"
376 fi
377 # Currently oprofile's event based interrupt mode doesn't work(Bug #828) in
378 # qemux86 and qemux86-64. We can use timer interrupt mode for now.
379 KERNCMDLINE="$KERNCMDLINE oprofile.timer=1"
380fi
381
382if [ "$MACHINE" = "qemux86-64" ]; then
383 QEMU=qemu-system-x86_64
384 QEMU_UI_OPTIONS="$QEMU_UI_OPTIONS -vga vmware"
385 if [ "${FSTYPE:0:3}" = "ext" -o "$FSTYPE" = "btrfs" ]; then
386 KERNCMDLINE="vga=0 uvesafb.mode_option=640x480-32 root=$DROOT rw mem=$QEMU_MEMORY $KERNEL_NETWORK_CMD"
387 QEMUOPTIONS="$QEMU_NETWORK_CMD $ROOTFS_OPTIONS $QEMU_UI_OPTIONS"
388 fi
389 if [ "$FSTYPE" = "nfs" ]; then
390 if [ "x$ROOTFS" = "x" ]; then
391 ROOTFS=/srv/nfs/qemux86-64
392 fi
393 if [ ! -d "$ROOTFS" ]; then
394 echo "Error: NFS mount point $ROOTFS doesn't exist."
395 cleanup
396 return 1
397 fi
398 KERNCMDLINE="root=/dev/nfs nfsroot=$NFS_SERVER:$NFS_DIR,$UNFS_OPTS rw $KERNEL_NETWORK_CMD mem=$QEMU_MEMORY"
399 QEMUOPTIONS="$QEMU_NETWORK_CMD $QEMU_UI_OPTIONS"
400 fi
401 if [ "$FSTYPE" = "vmdk" ]; then
402 QEMUOPTIONS="$QEMU_NETWORK_CMD $QEMU_UI_OPTIONS"
403 fi
404 # Currently oprofile's event based interrupt mode doesn't work(Bug #828) in
405 # qemux86 and qemux86-64. We can use timer interrupt mode for now.
406 KERNCMDLINE="$KERNCMDLINE oprofile.timer=1"
407fi
408
409if [ "$MACHINE" = "spitz" ]; then
410 QEMU=qemu-system-arm
411 if [ "${FSTYPE:0:3}" = "ext" -o "$FSTYPE" = "btrfs" ]; then
412 echo $ROOTFS
413 ROOTFS=`readlink -f $ROOTFS`
414 echo $ROOTFS
415 if [ ! -e "$ROOTFS.qemudisk" ]; then
416 echo "Adding a partition table to the ext3 image for use by QEMU, please wait..."
417 runqemu-addptable2image $ROOTFS $ROOTFS.qemudisk
418 fi
419 QEMUOPTIONS="$QEMU_NETWORK_CMD -M spitz -hda $ROOTFS.qemudisk -portrait"
420 fi
421fi
422
423if [ "$MACHINE" = "qemumips" -o "$MACHINE" = "qemumipsel" -o "$MACHINE" = "qemumips64" ]; then
424 case "$MACHINE" in
425 qemumips) QEMU=qemu-system-mips ;;
426 qemumipsel) QEMU=qemu-system-mipsel ;;
427 qemumips64) QEMU=qemu-system-mips64 ;;
428 esac
429 MACHINE_SUBTYPE=malta
430 QEMU_UI_OPTIONS="-vga cirrus $QEMU_UI_OPTIONS"
431 if [ "${FSTYPE:0:3}" = "ext" -o "$FSTYPE" = "btrfs" ]; then
432 #KERNCMDLINE="root=/dev/hda console=ttyS0 console=tty0 $KERNEL_NETWORK_CMD mem=$QEMU_MEMORY"
433 KERNCMDLINE="root=/dev/hda rw console=ttyS0 console=tty $KERNEL_NETWORK_CMD mem=$QEMU_MEMORY"
434 QEMUOPTIONS="$QEMU_NETWORK_CMD -M $MACHINE_SUBTYPE -hda $ROOTFS -no-reboot $QEMU_UI_OPTIONS"
435 fi
436 if [ "$FSTYPE" = "nfs" ]; then
437 if [ "$NFS_SERVER" = "192.168.7.1" -a ! -d "$NFS_DIR" ]; then
438 echo "Error: NFS mount point $ROOTFS doesn't exist"
439 cleanup
440 return 1
441 fi
442 KERNCMDLINE="root=/dev/nfs console=ttyS0 console=tty nfsroot=$NFS_SERVER:$NFS_DIR,$UNFS_OPTS rw $KERNEL_NETWORK_CMD mem=$QEMU_MEMORY"
443 QEMUOPTIONS="$QEMU_NETWORK_CMD -M $MACHINE_SUBTYPE -no-reboot $QEMU_UI_OPTIONS"
444 fi
445fi
446
447if [ "$MACHINE" = "qemuppc" ]; then
448 QEMU=qemu-system-ppc
449 MACHINE_SUBTYPE=mac99
450 CPU_SUBTYPE=G4
451 QEMU_UI_OPTIONS="$QEMU_UI_OPTIONS"
452 if [ "$SLIRP_ENABLED" = "yes" ]; then
453 QEMU_NETWORK_CMD=""
454 else
455 QEMU_NETWORK_CMD="-net nic,model=pcnet $QEMU_TAP_CMD"
456 fi
457 if [ "${FSTYPE:0:3}" = "ext" -o "$FSTYPE" = "btrfs" ]; then
458 KERNCMDLINE="root=/dev/hda rw console=ttyS0 console=tty $KERNEL_NETWORK_CMD mem=$QEMU_MEMORY"
459 QEMUOPTIONS="$QEMU_NETWORK_CMD -cpu $CPU_SUBTYPE -M $MACHINE_SUBTYPE -hda $ROOTFS -no-reboot $QEMU_UI_OPTIONS"
460 fi
461 if [ "$FSTYPE" = "nfs" ]; then
462 if [ "$NFS_SERVER" = "192.168.7.1" -a ! -d "$NFS_DIR" ]; then
463 echo "Error: NFS mount point $ROOTFS doesn't exist"
464 cleanup
465 return 1
466 fi
467 KERNCMDLINE="root=/dev/nfs console=ttyS0 console=tty nfsroot=$NFS_SERVER:$NFS_DIR,$UNFS_OPTS rw $KERNEL_NETWORK_CMD mem=$QEMU_MEMORY"
468 QEMUOPTIONS="$QEMU_NETWORK_CMD -cpu $CPU_SUBTYPE -M $MACHINE_SUBTYPE -no-reboot $QEMU_UI_OPTIONS"
469 fi
470fi
471
472if [ "$MACHINE" = "qemush4" ]; then
473 QEMU=qemu-system-sh4
474 MACHINE_SUBTYPE=r2d
475 QEMU_UI_OPTIONS="$QEMU_UI_OPTIONS"
476 if [ "${FSTYPE:0:3}" = "ext" -o "$FSTYPE" = "btrfs" ]; then
477 #KERNCMDLINE="root=/dev/hda console=ttyS0 console=tty0 $KERNEL_NETWORK_CMD mem=$QEMU_MEMORY"
478 KERNCMDLINE="root=/dev/hda rw console=ttySC1 noiotrap earlyprintk=sh-sci.1 console=tty $KERNEL_NETWORK_CMD mem=$QEMU_MEMORY"
479 QEMUOPTIONS="$QEMU_NETWORK_CMD -M $MACHINE_SUBTYPE -hda $ROOTFS -no-reboot $QEMU_UI_OPTIONS -monitor null -serial vc -serial stdio"
480 SERIALSTDIO="1"
481 fi
482 if [ "$FSTYPE" = "nfs" ]; then
483 if [ "$NFS_SERVER" = "192.168.7.1" -a ! -d "$NFS_DIR" ]; then
484 echo "Error: NFS mount point $ROOTFS doesn't exist"
485 cleanup
486 return 1
487 fi
488 KERNCMDLINE="root=/dev/nfs console=ttySC1 noiotrap earlyprintk=sh-sci.1 console=tty nfsroot=$NFS_SERVER:$NFS_DIR,$UNFS_OPTS rw $KERNEL_NETWORK_CMD mem=$QEMU_MEMORY"
489 QEMUOPTIONS="$QEMU_NETWORK_CMD -M $MACHINE_SUBTYPE -no-reboot $QEMU_UI_OPTIONS -monitor null -serial vc -serial stdio"
490 SERIALSTDIO="1"
491 fi
492fi
493
494if [ "$MACHINE" = "akita" ]; then
495 QEMU=qemu-system-arm
496 if [ "$FSTYPE" = "jffs2" ]; then
497 ROOTFS=`readlink -f $ROOTFS`
498 if [ ! -e "$ROOTFS.qemuflash" ]; then
499 echo "Converting raw image into flash image format for use by QEMU, please wait..."
500 raw2flash.akita < $ROOTFS > $ROOTFS.qemuflash
501 fi
502 QEMUOPTIONS="$QEMU_NETWORK_CMD -M akita -mtdblock $ROOTFS.qemuflash -portrait"
503 fi
504fi
505
506if [ "$MACHINE" = "qemumicroblaze" ]; then
507 QEMU=qemu-system-microblazeel
508 QEMU_SYSTEM_OPTIONS="-M petalogix-ml605 -serial mon:stdio -dtb $KERNEL-$MACHINE.dtb"
509 if [ "${FSTYPE:0:3}" = "ext" -o "${FSTYPE:0:4}" = "cpio" ]; then
510 KERNCMDLINE="earlyprintk root=/dev/ram rw"
511 QEMUOPTIONS="$QEMU_SYSTEM_OPTIONS -initrd $ROOTFS"
512 fi
513fi
514
515if [ "$MACHINE" = "qemuzynq" ]; then
516 QEMU=qemu-system-arm
517 QEMU_SYSTEM_OPTIONS="-M xilinx-zynq-a9 -serial null -serial mon:stdio -dtb $KERNEL-$MACHINE.dtb"
518 # zynq serial ports are named 'ttyPS0' and 'ttyPS1', fixup the default values
519 SCRIPT_KERNEL_OPT=$(echo "$SCRIPT_KERNEL_OPT" | sed 's/console=ttyS/console=ttyPS/g')
520 if [ "${FSTYPE:0:3}" = "ext" -o "${FSTYPE:0:4}" = "cpio" ]; then
521 KERNCMDLINE="earlyprintk root=/dev/ram rw"
522 QEMUOPTIONS="$QEMU_SYSTEM_OPTIONS -initrd $ROOTFS"
523 fi
524fi
525
526if [ "x$RAMFS" = "xtrue" ]; then
527 QEMUOPTIONS="-initrd $ROOTFS -nographic"
528 KERNCMDLINE="root=/dev/ram0 debugshell"
529fi
530
531if [ "x$ISOFS" = "xtrue" ]; then
532 QEMUOPTIONS="$QEMU_NETWORK_CMD -cdrom $ROOTFS $QEMU_UI_OPTIONS"
533fi
534
535if [ "x$QEMUOPTIONS" = "x" ]; then
536 echo "Error: Unable to support this combination of options"
537 cleanup
538 return 1
539fi
540
541PATH=$OECORE_NATIVE_SYSROOT/usr/bin:$PATH
542
543QEMUBIN=`which $QEMU 2> /dev/null`
544if [ ! -x "$QEMUBIN" ]; then
545 echo "Error: No QEMU binary '$QEMU' could be found."
546 cleanup
547 return 1
548fi
549
550NEED_GL=`ldd $QEMUBIN/$QEMU 2>&1 | grep libGLU`
551# We can't run without a libGL.so
552if [ "$NEED_GL" != "" ]; then
553 libgl='no'
554
555 [ -e /usr/lib/libGL.so -a -e /usr/lib/libGLU.so ] && libgl='yes'
556 [ -e /usr/lib64/libGL.so -a -e /usr/lib64/libGLU.so ] && libgl='yes'
557 [ -e /usr/lib/*-linux-gnu/libGL.so -a -e /usr/lib/*-linux-gnu/libGLU.so ] && libgl='yes'
558
559 if [ "$libgl" != 'yes' ]; then
560 echo "You need libGL.so and libGLU.so to exist in your library path to run the QEMU emulator.
561 Ubuntu package names are: libgl1-mesa-dev and libglu1-mesa-dev.
562 Fedora package names are: mesa-libGL-devel mesa-libGLU-devel."
563 return 1;
564 fi
565fi
566
567do_quit() {
568 cleanup
569 return 1
570}
571
572trap do_quit INT TERM QUIT
573
574# qemu got segfault if linked with nVidia's libgl
575GL_LD_PRELOAD=$LD_PRELOAD
576
577if ldd $QEMUBIN | grep -i nvidia &> /dev/null
578then
579cat << EOM
580WARNING: nVidia proprietary OpenGL libraries detected.
581nVidia's OpenGL libraries are known to have compatibility issues with qemu,
582resulting in a segfault. Please uninstall these drivers or ensure the mesa libGL
583libraries precede nvidia's via LD_PRELOAD(Already do it on Ubuntu 10).
584EOM
585
586# Automatically use Ubuntu system's mesa libGL, other distro can add its own path
587if grep -i ubuntu /etc/lsb-release &> /dev/null
588then
589 # precede nvidia's driver on Ubuntu 10
590 UBUNTU_MAIN_VERSION=`cat /etc/lsb-release |grep DISTRIB_RELEASE |cut -d= -f 2| cut -d. -f 1`
591 if [ "$UBUNTU_MAIN_VERSION" = "10" ];
592 then
593 GL_PATH=""
594 if test -e /usr/lib/libGL.so
595 then
596 GL_PATH="/usr/lib/libGL.so"
597 elif test -e /usr/lib/x86_64-linux-gnu/libGL.so
598 then
599 GL_PATH="/usr/lib/x86_64-linux-gnu/libGL.so"
600 fi
601
602 echo "Skip nVidia's libGL on Ubuntu 10!"
603 GL_LD_PRELOAD="$GL_PATH $LD_PRELOAD"
604 fi
605fi
606fi
607
608if [ "x$SERIALSTDIO" = "x1" ]; then
609 echo "Interrupt character is '^]'"
610 stty intr ^]
611fi
612
613echo "Running $QEMU..."
614# -no-reboot is a mandatory option - see bug #100
615if [ "$FSTYPE" = "vmdk" ]; then
616 echo $QEMUBIN $VM $QEMUOPTIONS $SERIALOPTS -no-reboot $SCRIPT_QEMU_OPT $SCRIPT_QEMU_EXTRA_OPT
617 LD_PRELOAD="$GL_LD_PRELOAD" $QEMUBIN $VM $QEMUOPTIONS $SERIALOPTS -no-reboot $SCRIPT_QEMU_OPT $SCRIPT_QEMU_EXTRA_OPT
618elif [ "$FSTYPE" = "iso" ]; then
619 echo $QEMUBIN $QEMUOPTIONS $SERIALOPTS -no-reboot $SCRIPT_QEMU_OPT $SCRIPT_QEMU_EXTRA_OPT
620 LD_PRELOAD="$GL_LD_PRELOAD" $QEMUBIN $QEMUOPTIONS $SERIALOPTS -no-reboot $SCRIPT_QEMU_OPT $SCRIPT_QEMU_EXTRA_OPT
621else
622 echo $QEMUBIN -kernel $KERNEL $QEMUOPTIONS $SLIRP_CMD $SERIALOPTS -no-reboot $SCRIPT_QEMU_OPT $SCRIPT_QEMU_EXTRA_OPT --append '"'$KERNCMDLINE $SCRIPT_KERNEL_OPT'"'
623 LD_PRELOAD="$GL_LD_PRELOAD" $QEMUBIN -kernel $KERNEL $QEMUOPTIONS $SERIALOPTS -no-reboot $SCRIPT_QEMU_OPT $SCRIPT_QEMU_EXTRA_OPT --append "$KERNCMDLINE $SCRIPT_KERNEL_OPT"
624fi
625ret=$?
626if [ "$SLIRP_ENABLED" != "yes" ]; then
627 cleanup
628fi
629
630#set the original stty values before exit
631stty ${ORIG_STTY}
632trap - INT TERM QUIT
633
634return $ret