import ast import codegen import logging import os.path import bb.utils, bb.data from itertools import chain from pysh import pyshyacc, pyshlex, sherrors from bb.cache import MultiProcessCache logger = logging.getLogger('BitBake.CodeParser') try: import cPickle as pickle except ImportError: import pickle logger.info('Importing cPickle failed. Falling back to a very slow implementation.') def check_indent(codestr): """If the code is indented, add a top level piece of code to 'remove' the indentation""" i = 0 while codestr[i] in ["\n", "\t", " "]: i = i + 1 if i == 0: return codestr if codestr[i-1] == "\t" or codestr[i-1] == " ": return "if 1:\n" + codestr return codestr # Basically pickle, in python 2.7.3 at least, does badly with data duplication # upon pickling and unpickling. Combine this with duplicate objects and things # are a mess. # # When the sets are originally created, python calls intern() on the set keys # which significantly improves memory usage. Sadly the pickle/unpickle process # doesn't call intern() on the keys and results in the same strings being duplicated # in memory. This also means pickle will save the same string multiple times in # the cache file. # # By having shell and python cacheline objects with setstate/getstate, we force # the object creation through our own routine where we can call intern (via internSet). # # We also use hashable frozensets and ensure we use references to these so that # duplicates can be removed, both in memory and in the resulting pickled data. # # By playing these games, the size of the cache file shrinks dramatically # meaning faster load times and the reloaded cache files also consume much less # memory. Smaller cache files, faster load times and lower memory usage is good. # # A custom getstate/setstate using tuples is actually worth 15% cachesize by # avoiding duplication of the attribute names! class SetCache(object): def __init__(self): self.setcache = {} def internSet(self, items): new = [] for i in items: new.append(intern(i)) s = frozenset(new) if hash(s) in self.setcache: return self.setcache[hash(s)] self.setcache[hash(s)] = s return s codecache = SetCache() class pythonCacheLine(object): def __init__(self, refs, execs, contains): self.refs = codecache.internSet(refs) self.execs = codecache.internSet(execs) self.contains = {} for c in contains: self.contains[c] = codecache.internSet(contains[c]) def __getstate__(self): return (self.refs, self.execs, self.contains) def __setstate__(self, state): (refs, execs, contains) = state self.__init__(refs, execs, contains) def __hash__(self): l = (hash(self.refs), hash(self.execs)) for c in sorted(self.contains.keys()): l = l + (c, hash(self.contains[c])) return hash(l) class shellCacheLine(object): def __init__(self, execs): self.execs = codecache.internSet(execs) def __getstate__(self): return (self.execs) def __setstate__(self, state): (execs) = state self.__init__(execs) def __hash__(self): return hash(self.execs) class CodeParserCache(MultiProcessCache): cache_file_name = "bb_codeparser.dat" CACHE_VERSION = 7 def __init__(self): MultiProcessCache.__init__(self) self.pythoncache = self.cachedata[0] self.shellcache = self.cachedata[1] self.pythoncacheextras = self.cachedata_extras[0] self.shellcacheextras = self.cachedata_extras[1] # To avoid duplication in the codeparser cache, keep # a lookup of hashes of objects we already have self.pythoncachelines = {} self.shellcachelines = {} def newPythonCacheLine(self, refs, execs, contains): cacheline = pythonCacheLine(refs, execs, contains) h = hash(cacheline) if h in self.pythoncachelines: return self.pythoncachelines[h] self.pythoncachelines[h] = cacheline return cacheline def newShellCacheLine(self, execs): cacheline = shellCacheLine(execs) h = hash(cacheline) if h in self.shellcachelines: return self.shellcachelines[h] self.shellcachelines[h] = cacheline return cacheline def init_cache(self, d): MultiProcessCache.init_cache(self, d) # cachedata gets re-assigned in the parent self.pythoncache = self.cachedata[0] self.shellcache = self.cachedata[1] def create_cachedata(self): data = [{}, {}] return data codeparsercache = CodeParserCache() def parser_cache_init(d): codeparsercache.init_cache(d) def parser_cache_save(d): codeparsercache.save_extras(d) def parser_cache_savemerge(d): codeparsercache.save_merge(d) Logger = logging.getLoggerClass() class BufferedLogger(Logger): def __init__(self, name, level=0, target=None): Logger.__init__(self, name) self.setLevel(level) self.buffer = [] self.target = target def handle(self, record): self.buffer.append(record) def flush(self): for record in self.buffer: self.target.handle(record) self.buffer = [] class PythonParser(): getvars = (".getVar", ".appendVar", ".prependVar") containsfuncs = ("bb.utils.contains", "base_contains", "bb.utils.contains_any") execfuncs = ("bb.build.exec_func", "bb.build.exec_task") def warn(self, func, arg): """Warn about calls of bitbake APIs which pass a non-literal argument for the variable name, as we're not able to track such a reference. """ try: funcstr = codegen.to_source(func) argstr = codegen.to_source(arg) except TypeError: self.log.debug(2, 'Failed to convert function and argument to source form') else: self.log.debug(1, self.unhandled_message % (funcstr, argstr)) def visit_Call(self, node): name = self.called_node_name(node.func) if name and name.endswith(self.getvars) or name in self.containsfuncs: if isinstance(node.args[0], ast.Str): varname = node.args[0].s if name in self.containsfuncs and isinstance(node.args[1], ast.Str): if varname not in self.contains: self.contains[varname] = set() self.contains[varname].add(node.args[1].s) else: self.references.add(node.args[0].s) else: self.warn(node.func, node.args[0]) elif name in self.execfuncs: if isinstance(node.args[0], ast.Str): self.var_execs.add(node.args[0].s) else: self.warn(node.func, node.args[0]) elif name and isinstance(node.func, (ast.Name, ast.Attribute)): self.execs.add(name) def called_node_name(self, node): """Given a called node, return its original string form""" components = [] while node: if isinstance(node, ast.Attribute): components.append(node.attr) node = node.value elif isinstance(node, ast.Name): components.append(node.id) return '.'.join(reversed(components)) else: break def __init__(self, name, log): self.var_execs = set() self.contains = {} self.execs = set() self.references = set() self.log = BufferedLogger('BitBake.Data.PythonParser', logging.DEBUG, log) self.unhandled_message = "in call of %s, argument '%s' is not a string literal" self.unhandled_message = "while parsing %s, %s" % (name, self.unhandled_message) def parse_python(self, node): h = hash(str(node)) if h in codeparsercache.pythoncache: self.references = set(codeparsercache.pythoncache[h].refs) self.execs = set(codeparsercache.pythoncache[h].execs) self.contains = {} for i in codeparsercache.pythoncache[h].contains: self.contains[i] = set(codeparsercache.pythoncache[h].contains[i]) return if h in codeparsercache.pythoncacheextras: self.references = set(codeparsercache.pythoncacheextras[h].refs) self.execs = set(codeparsercache.pythoncacheextras[h].execs) self.contains = {} for i in codeparsercache.pythoncacheextras[h].contains: self.contains @media only all and (prefers-color-scheme: dark) { .highlight .hll { background-color: #49483e } .highlight .c { color: #75715e } /* Comment */ .highlight .err { color: #960050; background-color: #1e0010 } /* Error */ .highlight .k { color: #66d9ef } /* Keyword */ .highlight .l { color: #ae81ff } /* Literal */ .highlight .n { color: #f8f8f2 } /* Name */ .highlight .o { color: #f92672 } /* Operator */ .highlight .p { color: #f8f8f2 } /* Punctuation */ .highlight .ch { color: #75715e } /* Comment.Hashbang */ .highlight .cm { color: #75715e } /* Comment.Multiline */ .highlight .cp { color: #75715e } /* Comment.Preproc */ .highlight .cpf { color: #75715e } /* Comment.PreprocFile */ .highlight .c1 { color: #75715e } /* Comment.Single */ .highlight .cs { color: #75715e } /* Comment.Special */ .highlight .gd { color: #f92672 } /* Generic.Deleted */ .highlight .ge { font-style: italic } /* Generic.Emph */ .highlight .gi { color: #a6e22e } /* Generic.Inserted */ .highlight .gs { font-weight: bold } /* Generic.Strong */ .highlight .gu { color: #75715e } /* Generic.Subheading */ .highlight .kc { color: #66d9ef } /* Keyword.Constant */ .highlight .kd { color: #66d9ef } /* Keyword.Declaration */ .highlight .kn { color: #f92672 } /* Keyword.Namespace */ .highlight .kp { color: #66d9ef } /* Keyword.Pseudo */ .highlight .kr { color: #66d9ef } /* Keyword.Reserved */ .highlight .kt { color: #66d9ef } /* Keyword.Type */ .highlight .ld { color: #e6db74 } /* Literal.Date */ .highlight .m { color: #ae81ff } /* Literal.Number */ .highlight .s { color: #e6db74 } /* Literal.String */ .highlight .na { color: #a6e22e } /* Name.Attribute */ .highlight .nb { color: #f8f8f2 } /* Name.Builtin */ .highlight .nc { color: #a6e22e } /* Name.Class */ .highlight .no { color: #66d9ef } /* Name.Constant */ .highlight .nd { color: #a6e22e } /* Name.Decorator */ .highlight .ni { color: #f8f8f2 } /* Name.Entity */ .highlight .ne { color: #a6e22e } /* Name.Exception */ .highlight .nf { color: #a6e22e } /* Name.Function */ .highlight .nl { color: #f8f8f2 } /* Name.Label */ .highlight .nn { color: #f8f8f2 } /* Name.Namespace */ .highlight .nx { color: #a6e22e } /* Name.Other */ .highlight .py { color: #f8f8f2 } /* Name.Property */ .highlight .nt { color: #f92672 } /* Name.Tag */ .highlight .nv { color: #f8f8f2 } /* Name.Variable */ .highlight .ow { color: #f92672 } /* Operator.Word */ .highlight .w { color: #f8f8f2 } /* Text.Whitespace */ .highlight .mb { color: #ae81ff } /* Literal.Number.Bin */ .highlight .mf { color: #ae81ff } /* Literal.Number.Float */ .highlight .mh { color: #ae81ff } /* Literal.Number.Hex */ .highlight .mi { color: #ae81ff } /* Literal.Number.Integer */ .highlight .mo { color: #ae81ff } /* Literal.Number.Oct */ .highlight .sa { color: #e6db74 } /* Literal.String.Affix */ .highlight .sb { color: #e6db74 } /* Literal.String.Backtick */ .highlight .sc { color: #e6db74 } /* Literal.String.Char */ .highlight .dl { color: #e6db74 } /* Literal.String.Delimiter */ .highlight .sd { color: #e6db74 } /* Literal.String.Doc */ .highlight .s2 { color: #e6db74 } /* Literal.String.Double */ .highlight .se { color: #ae81ff } /* Literal.String.Escape */ .highlight .sh { color: #e6db74 } /* Literal.String.Heredoc */ .highlight .si { color: #e6db74 } /* Literal.String.Interpol */ .highlight .sx { color: #e6db74 } /* Literal.String.Other */ .highlight .sr { color: #e6db74 } /* Literal.String.Regex */ .highlight .s1 { color: #e6db74 } /* Literal.String.Single */ .highlight .ss { color: #e6db74 } /* Literal.String.Symbol */ .highlight .bp { color: #f8f8f2 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #a6e22e } /* Name.Function.Magic */ .highlight .vc { color: #f8f8f2 } /* Name.Variable.Class */ .highlight .vg { color: #f8f8f2 } /* Name.Variable.Global */ .highlight .vi { color: #f8f8f2 } /* Name.Variable.Instance */ .highlight .vm { color: #f8f8f2 } /* Name.Variable.Magic */ .highlight .il { color: #ae81ff } /* Literal.Number.Integer.Long */ } @media (prefers-color-scheme: light) { .highlight .hll { background-color: #ffffcc } .highlight .c { color: #888888 } /* Comment */ .highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */ .highlight .k { color: #008800; font-weight: bold } /* Keyword */ .highlight .ch { color: #888888 } /* Comment.Hashbang */ .highlight .cm { color: #888888 } /* Comment.Multiline */ .highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */ .highlight .cpf { color: #888888 } /* Comment.PreprocFile */ .highlight .c1 { color: #888888 } /* Comment.Single */ .highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */ .highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */ .highlight .ge { font-style: italic } /* Generic.Emph */ .highlight .gr { color: #aa0000 } /* Generic.Error */ .highlight .gh { color: #333333 } /* Generic.Heading */ .highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */ .highlight .go { color: #888888 } /* Generic.Output */ .highlight .gp { color: #555555 } /* Generic.Prompt */ .highlight .gs { font-weight: bold } /* Generic.Strong */ .highlight .gu { color: #666666 } /* Generic.Subheading */ .highlight .gt { color: #aa0000 } /* Generic.Traceback */ .highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */ .highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */ .highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */ .highlight .kp { color: #008800 } /* Keyword.Pseudo */ .highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */ } #!/bin/bash -x # Handle running OE images under qemu # # Copyright (C) 2006-2011 Linux Foundation # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 as # published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # Call setting: # QEMU_MEMORY (optional) - set the amount of memory in the emualted system. # SERIAL_LOGFILE (optional) - log the serial port output to a file # CROSSPATH - the path to any cross toolchain to use with distcc # # Image options: # MACHINE - the machine to run # FSTYPE - the image type to run # KERNEL - the kernel image file to use # ROOTFS - the disk image file to use # mem_size=-1 #Get rid of <> and get the contents of extra qemu running params SCRIPT_QEMU_EXTRA_OPT=`echo $SCRIPT_QEMU_EXTRA_OPT | sed -e 's/<//' -e 's/>//'` #if user set qemu memory, eg: -m 256 in qemu extra params, we need to do some # validation check mem_set=`expr "$SCRIPT_QEMU_EXTRA_OPT" : '.*\(-m[[:space:]] *[0-9]*\)'` if [ ! -z "$mem_set" ] ; then #Get memory setting size from user input mem_size=`echo $mem_set | sed 's/-m[[:space:]] *//'` else case "$MACHINE" in "qemux86") mem_size=128 ;; "qemux86-64") mem_size=128 ;; "qemuarm") mem_size=128 ;; "qemumips"|"qemumips64") mem_size=128 ;; "qemuppc") mem_size=128 ;; "qemush4") mem_size=1024 ;; *) mem_size=64 ;; esac fi # QEMU_MEMORY has 'M' appended to mem_size QEMU_MEMORY="$mem_size"M # Bug 433: qemuarm cannot use > 256 MB RAM if [ "$MACHINE" = "qemuarm" ]; then if [ -z "$mem_size" -o $mem_size -gt 256 ]; then echo "WARNING: qemuarm does not support > 256M of RAM." echo "Changing QEMU_MEMORY to default of 256M." QEMU_MEMORY="256M" mem_size="256" SCRIPT_QEMU_EXTRA_OPT=`echo $SCRIPT_QEMU_EXTRA_OPT | sed -e "s/$mem_set/-m 256/" ` fi fi # We need to specify -m <mem_size> to overcome a bug in qemu 0.14.0 # https://bugs.launchpad.net/ubuntu/+source/qemu-kvm/+bug/584480 if [ -z "$mem_set" ] ; then SCRIPT_QEMU_EXTRA_OPT="$SCRIPT_QEMU_EXTRA_OPT -m $mem_size" fi # This file is created when runqemu-gen-tapdevs creates a bank of tap # devices, indicating that the user should not bring up new ones using # sudo. NOSUDO_FLAG="/etc/runqemu-nosudo" QEMUIFUP=`which runqemu-ifup 2> /dev/null` QEMUIFDOWN=`which runqemu-ifdown 2> /dev/null` if [ -z "$QEMUIFUP" -o ! -x "$QEMUIFUP" ]; then echo "runqemu-ifup cannot be found or executed" exit 1 fi if [ -z "$QEMUIFDOWN" -o ! -x "$QEMUIFDOWN" ]; then echo "runqemu-ifdown cannot be found or executed" exit 1 fi NFSRUNNING="false" acquire_lock() { lockfile=$1 if [ -z "$lockfile" ]; then echo "Error: missing lockfile arg passed to acquire_lock()" return 1 fi if [ -e "$lockfile.lock" ]; then # Check that the lockfile is not stale ps=`ps -eo pid | grep $(cat $lockfile.lock)` if [ -z "$ps" ]; then echo "WARNING: Stale lock file detected, deleting $lockfile.lock." rm -f $lockfile.lock echo $$ > $lockfile.lock else return 1 fi else echo $$ > $lockfile.lock fi return 0 } release_lock() { lockfile=$1 if [ -z "$lockfile" ]; then echo "Error: missing lockfile arg passed to release_lock()" return 1 fi rm -f $lockfile.lock } LOCKDIR="/tmp/qemu-tap-locks" if [ ! -d "$LOCKDIR" ]; then mkdir $LOCKDIR chmod 777 $LOCKDIR fi IFCONFIG=`which ifconfig 2> /dev/null` if [ -z "$IFCONFIG" ]; then IFCONFIG=/sbin/ifconfig fi if [ ! -x "$IFCONFIG" ]; then echo "$IFCONFIG cannot be executed" exit 1 fi POSSIBLE=`$IFCONFIG -a | grep '^tap' | awk '{print $1}' | sed s/://` TAP="" LOCKFILE="" for tap in $POSSIBLE; do LOCKFILE="$LOCKDIR/$tap" echo "Acquiring lockfile for $tap..." acquire_lock $LOCKFILE if [ $? -eq 0 ]; then TAP=$tap break fi done if [ "$TAP" = "" ]; then if [ -e "$NOSUDO_FLAG" ]; then echo "Error: There are no available tap devices to use for networking," echo "and I see $NOSUDO_FLAG exists, so I am not going to try creating" echo "a new one with sudo." exit 1 fi GROUPID=`id -g` USERID=`id -u` echo "Setting up tap interface under sudo" # Redirect stderr since we could see a LD_PRELOAD warning here if pseudo is loaded # but inactive. This looks scary but is harmless tap=`sudo $QEMUIFUP $USERID $GROUPID $OECORE_NATIVE_SYSROOT 2> /dev/null` if [ $? -ne 0 ]; then # Re-run standalone to see verbose errors sudo $QEMUIFUP $USERID $GROUPID $OECORE_NATIVE_SYSROOT return 1 fi LOCKFILE="$LOCKDIR/$tap" echo "Acquiring lockfile for $tap..." acquire_lock $LOCKFILE if [ $? -eq 0 ]; then TAP=$tap fi else echo "Using preconfigured tap device '$TAP'" fi cleanup() { if [ ! -e "$NOSUDO_FLAG" ]; then # Redirect stderr since we could see a LD_PRELOAD warning here if pseudo is loaded # but inactive. This looks scary but is harmless sudo $QEMUIFDOWN $TAP $OECORE_NATIVE_SYSROOT 2> /dev/null fi echo "Releasing lockfile of preconfigured tap device '$TAP'" release_lock $LOCKFILE if [ "$NFSRUNNING" = "true" ]; then echo "Shutting down the userspace NFS server..." echo "runqemu-export-rootfs stop $ROOTFS" runqemu-export-rootfs stop $ROOTFS fi # If QEMU crashes or somehow tty properties are not restored # after qemu exits, we need to run stty sane stty sane } n0=$(echo $TAP | sed 's/tap//') n1=$(($n0 * 2 + 1)) n2=$(($n1 + 1)) KERNEL_NETWORK_CMD="ip=192.168.7.$n2::192.168.7.$n1:255.255.255.0" QEMU_TAP_CMD="-net tap,vlan=0,ifname=$TAP,script=no,downscript=no" if [ "$KVM_ACTIVE" = "yes" ]; then QEMU_NETWORK_CMD="-net nic,model=virtio $QEMU_TAP_CMD,vhost=on" DROOT="/dev/vda" ROOTFS_OPTIONS="-drive file=$ROOTFS,if=virtio" else QEMU_NETWORK_CMD="-net nic,vlan=0 $QEMU_TAP_CMD" DROOT="/dev/hda" ROOTFS_OPTIONS="-hda $ROOTFS" fi KERNCMDLINE="mem=$QEMU_MEMORY" QEMU_UI_OPTIONS="-show-cursor -usb -usbdevice wacom-tablet" NFS_INSTANCE=`echo $TAP | sed 's/tap//'` export NFS_INSTANCE SERIALOPTS="" if [ "x$SERIAL_LOGFILE" != "x" ]; then SERIALOPTS="-serial file:$SERIAL_LOGFILE" fi case "$MACHINE" in "qemuarm") ;; "qemumips") ;; "qemumipsel") ;; "qemumips64") ;; "qemush4") ;; "qemuppc") ;; "qemuarmv6") ;; "qemuarmv7") ;; "qemux86") ;; "qemux86-64") ;; "akita") ;; "spitz") ;; *) echo "Error: Unsupported machine type $MACHINE" return 1 ;; esac if [ ! -f "$KERNEL" -a "x$FSTYPE" != "xvmdk" ]; then echo "Error: Kernel image file $KERNEL doesn't exist" cleanup return 1 fi if [ "$FSTYPE" != "nfs" -a "$FSTYPE" != "vmdk" -a ! -f "$ROOTFS" ]; then echo "Error: Image file $ROOTFS doesn't exist" cleanup return 1 fi if [ "$FSTYPE" = "nfs" ]; then NFS_SERVER="192.168.7.1" NFS_DIR=`echo $ROOTFS | sed 's/^[^:]*:\(.*\)/\1/'` MOUNTD_RPCPORT=$[ 21111 + $NFS_INSTANCE ] NFSD_RPCPORT=$[ 11111 + $NFS_INSTANCE ] NFSD_PORT=$[ 3049 + 2 * $NFS_INSTANCE ] MOUNTD_PORT=$[ 3048 + 2 * $NFS_INSTANCE ] UNFS_OPTS="nfsvers=2,mountprog=$MOUNTD_RPCPORT,nfsprog=$NFSD_RPCPORT,udp,port=$NFSD_PORT,mountport=$MOUNTD_PORT" PSEUDO_LOCALSTATEDIR=~/.runqemu-sdk/pseudo export PSEUDO_LOCALSTATEDIR # Start the userspace NFS server echo "runqemu-export-rootfs restart $ROOTFS" runqemu-export-rootfs restart $ROOTFS if [ $? != 0 ]; then cleanup return 1 fi NFSRUNNING="true" fi if [ "$NFS_SERVER" = "" ]; then NFS_SERVER="192.168.7.1" NFS_DIR=$ROOTFS fi if [ "$MACHINE" = "qemuarm" -o "$MACHINE" = "qemuarmv6" -o "$MACHINE" = "qemuarmv7" ]; then QEMU=qemu-system-arm MACHINE_SUBTYPE=versatilepb export QEMU_AUDIO_DRV="none" QEMU_UI_OPTIONS="$QEMU_UI_OPTIONS" # QEMU_UI_OPTIONS="$QEMU_UI_OPTIONS -force-pointer" if [ "$FSTYPE" = "ext3" -o "$FSTYPE" = "btrfs" ]; then KERNCMDLINE="root=/dev/sda rw console=ttyAMA0,115200 console=tty $KERNEL_NETWORK_CMD mem=$QEMU_MEMORY highres=off" QEMUOPTIONS="$QEMU_NETWORK_CMD -M versatilepb -hda $ROOTFS -no-reboot $QEMU_UI_OPTIONS" fi if [ "$FSTYPE" = "nfs" ]; then if [ "$NFS_SERVER" = "192.168.7.1" -a ! -d "$NFS_DIR" ]; then echo "Error: NFS mount point $ROOTFS doesn't exist" cleanup return 1 fi KERNCMDLINE="root=/dev/nfs nfsroot=$NFS_SERVER:$NFS_DIR,$UNFS_OPTS rw $KERNEL_NETWORK_CMD mem=$QEMU_MEMORY" QEMUOPTIONS="$QEMU_NETWORK_CMD -M versatilepb --no-reboot $QEMU_UI_OPTIONS" fi if [ "$MACHINE" = "qemuarmv6" ]; then QEMUOPTIONS="$QEMUOPTIONS -cpu arm1136" fi if [ "$MACHINE" = "qemuarmv7" ]; then QEMUOPTIONS="$QEMUOPTIONS -cpu cortex-a8" fi fi if [ "$MACHINE" = "qemux86" ]; then QEMU=qemu-system-i386 QEMU_UI_OPTIONS="$QEMU_UI_OPTIONS -vga vmware" if [ "$FSTYPE" = "ext2" -o "$FSTYPE" = "ext3" -o "$FSTYPE" = "btrfs" ]; then KERNCMDLINE="vga=0 root=$DROOT rw mem=$QEMU_MEMORY $KERNEL_NETWORK_CMD" QEMUOPTIONS="$QEMU_NETWORK_CMD $ROOTFS_OPTIONS $QEMU_UI_OPTIONS" fi if [ "$FSTYPE" = "nfs" ]; then if [ "$NFS_SERVER" = "192.168.7.1" -a ! -d "$NFS_DIR" ]; then echo "Error: NFS mount point $ROOTFS doesn't exist." cleanup return 1 fi KERNCMDLINE="root=/dev/nfs nfsroot=$NFS_SERVER:$NFS_DIR,$UNFS_OPTS rw $KERNEL_NETWORK_CMD mem=$QEMU_MEMORY" QEMUOPTIONS="$QEMU_NETWORK_CMD $QEMU_UI_OPTIONS" fi if [ "$FSTYPE" = "vmdk" ]; then QEMUOPTIONS="$QEMU_NETWORK_CMD $QEMU_UI_OPTIONS" fi # Currently oprofile's event based interrupt mode doesn't work(Bug #828) in # qemux86 and qemux86-64. We can use timer interrupt mode for now. KERNCMDLINE="$KERNCMDLINE oprofile.timer=1" fi if [ "$MACHINE" = "qemux86-64" ]; then QEMU=qemu-system-x86_64 QEMU_UI_OPTIONS="$QEMU_UI_OPTIONS -vga vmware" if [ "$FSTYPE" = "ext3" -o "$FSTYPE" = "btrfs" ]; then KERNCMDLINE="vga=0 root=$DROOT rw mem=$QEMU_MEMORY $KERNEL_NETWORK_CMD" QEMUOPTIONS="$QEMU_NETWORK_CMD $ROOTFS_OPTIONS $QEMU_UI_OPTIONS" fi if [ "$FSTYPE" = "nfs" ]; then if [ "x$ROOTFS" = "x" ]; then ROOTFS=/srv/nfs/qemux86-64 fi if [ ! -d "$ROOTFS" ]; then echo "Error: NFS mount point $ROOTFS doesn't exist." cleanup return 1 fi KERNCMDLINE="root=/dev/nfs nfsroot=$NFS_SERVER:$NFS_DIR,$UNFS_OPTS rw $KERNEL_NETWORK_CMD mem=$QEMU_MEMORY" QEMUOPTIONS="$QEMU_NETWORK_CMD $QEMU_UI_OPTIONS" fi if [ "$FSTYPE" = "vmdk" ]; then QEMUOPTIONS="$QEMU_NETWORK_CMD $QEMU_UI_OPTIONS" fi # Currently oprofile's event based interrupt mode doesn't work(Bug #828) in # qemux86 and qemux86-64. We can use timer interrupt mode for now. KERNCMDLINE="$KERNCMDLINE oprofile.timer=1" fi if [ "$MACHINE" = "spitz" ]; then QEMU=qemu-system-arm if [ "$FSTYPE" = "ext3" -o "$FSTYPE" = "btrfs" ]; then echo $ROOTFS ROOTFS=`readlink -f $ROOTFS` echo $ROOTFS if [ ! -e "$ROOTFS.qemudisk" ]; then echo "Adding a partition table to the ext3 image for use by QEMU, please wait..." runqemu-addptable2image $ROOTFS $ROOTFS.qemudisk fi QEMUOPTIONS="$QEMU_NETWORK_CMD -M spitz -hda $ROOTFS.qemudisk -portrait" fi fi if [ "$MACHINE" = "qemumips" -o "$MACHINE" = "qemumipsel" -o "$MACHINE" = "qemumips64" ]; then case "$MACHINE" in qemumips) QEMU=qemu-system-mips ;; qemumipsel) QEMU=qemu-system-mipsel ;; qemumips64) QEMU=qemu-system-mips64 ;; esac MACHINE_SUBTYPE=malta QEMU_UI_OPTIONS="-vga cirrus $QEMU_UI_OPTIONS" if [ "$FSTYPE" = "ext3" -o "$FSTYPE" = "btrfs" ]; then #KERNCMDLINE="root=/dev/hda console=ttyS0 console=tty0 $KERNEL_NETWORK_CMD mem=$QEMU_MEMORY" KERNCMDLINE="root=/dev/hda rw console=ttyS0 console=tty $KERNEL_NETWORK_CMD mem=$QEMU_MEMORY" QEMUOPTIONS="$QEMU_NETWORK_CMD -M $MACHINE_SUBTYPE -hda $ROOTFS -no-reboot $QEMU_UI_OPTIONS" fi if [ "$FSTYPE" = "nfs" ]; then if [ "$NFS_SERVER" = "192.168.7.1" -a ! -d "$NFS_DIR" ]; then echo "Error: NFS mount point $ROOTFS doesn't exist" cleanup return 1 fi KERNCMDLINE="root=/dev/nfs console=ttyS0 console=tty nfsroot=$NFS_SERVER:$NFS_DIR,$UNFS_OPTS rw $KERNEL_NETWORK_CMD mem=$QEMU_MEMORY" QEMUOPTIONS="$QEMU_NETWORK_CMD -M $MACHINE_SUBTYPE -no-reboot $QEMU_UI_OPTIONS" fi fi if [ "$MACHINE" = "qemuppc" ]; then QEMU=qemu-system-ppc MACHINE_SUBTYPE=mac99 CPU_SUBTYPE=G4 QEMU_UI_OPTIONS="$QEMU_UI_OPTIONS" QEMU_NETWORK_CMD="-net nic,model=pcnet $QEMU_TAP_CMD" if [ "$FSTYPE" = "ext3" -o "$FSTYPE" = "btrfs" ]; then KERNCMDLINE="root=/dev/hda rw console=ttyS0 console=tty $KERNEL_NETWORK_CMD mem=$QEMU_MEMORY" QEMUOPTIONS="$QEMU_NETWORK_CMD -cpu $CPU_SUBTYPE -M $MACHINE_SUBTYPE -hda $ROOTFS -no-reboot $QEMU_UI_OPTIONS" fi if [ "$FSTYPE" = "nfs" ]; then if [ "$NFS_SERVER" = "192.168.7.1" -a ! -d "$NFS_DIR" ]; then echo "Error: NFS mount point $ROOTFS doesn't exist" cleanup return 1 fi KERNCMDLINE="root=/dev/nfs console=ttyS0 console=tty nfsroot=$NFS_SERVER:$NFS_DIR,$UNFS_OPTS rw $KERNEL_NETWORK_CMD mem=$QEMU_MEMORY" QEMUOPTIONS="$QEMU_NETWORK_CMD -cpu $CPU_SUBTYPE -M $MACHINE_SUBTYPE -no-reboot $QEMU_UI_OPTIONS" fi fi if [ "$MACHINE" = "qemush4" ]; then QEMU=qemu-system-sh4 MACHINE_SUBTYPE=r2d QEMU_UI_OPTIONS="$QEMU_UI_OPTIONS" if [ "$FSTYPE" = "ext3" -o "$FSTYPE" = "btrfs" ]; then #KERNCMDLINE="root=/dev/hda console=ttyS0 console=tty0 $KERNEL_NETWORK_CMD mem=$QEMU_MEMORY" KERNCMDLINE="root=/dev/hda rw console=ttySC1 noiotrap earlyprintk=sh-sci.1 console=tty $KERNEL_NETWORK_CMD mem=$QEMU_MEMORY" QEMUOPTIONS="$QEMU_NETWORK_CMD -M $MACHINE_SUBTYPE -hda $ROOTFS -no-reboot $QEMU_UI_OPTIONS -monitor null -serial vc -serial stdio" SERIALSTDIO="1" fi if [ "$FSTYPE" = "nfs" ]; then if [ "$NFS_SERVER" = "192.168.7.1" -a ! -d "$NFS_DIR" ]; then echo "Error: NFS mount point $ROOTFS doesn't exist" cleanup return 1 fi 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" QEMUOPTIONS="$QEMU_NETWORK_CMD -M $MACHINE_SUBTYPE -no-reboot $QEMU_UI_OPTIONS -monitor null -serial vc -serial stdio" SERIALSTDIO="1" fi fi if [ "$MACHINE" = "akita" ]; then QEMU=qemu-system-arm if [ "$FSTYPE" = "jffs2" ]; then ROOTFS=`readlink -f $ROOTFS` if [ ! -e "$ROOTFS.qemuflash" ]; then echo "Converting raw image into flash image format for use by QEMU, please wait..." raw2flash.akita < $ROOTFS > $ROOTFS.qemuflash fi QEMUOPTIONS="$QEMU_NETWORK_CMD -M akita -mtdblock $ROOTFS.qemuflash -portrait" fi fi if [ "x$RAMFS" = "xtrue" ]; then QEMUOPTIONS="-initrd $ROOTFS -nographic" KERNCMDLINE="root=/dev/ram0 debugshell" fi if [ "x$ISOFS" = "xtrue" ]; then QEMUOPTIONS="-cdrom $ROOTFS" fi if [ "x$QEMUOPTIONS" = "x" ]; then echo "Error: Unable to support this combination of options" cleanup return 1 fi if [ "x$CROSSPATH" = "x" ]; then PATH=$OECORE_NATIVE_SYSROOT/usr/bin:$PATH else PATH=$CROSSPATH:$OECORE_NATIVE_SYSROOT/usr/bin:$PATH fi QEMUBIN=`which $QEMU 2> /dev/null` if [ ! -x "$QEMUBIN" ]; then echo "Error: No QEMU binary '$QEMU' could be found." cleanup return 1 fi NEED_GL=`ldd $QEMUBIN/$QEMU 2>&1 | grep libGLU` # We can't run without a libGL.so if [ "$NEED_GL" != "" ]; then libgl='no' [ -e /usr/lib/libGL.so -a -e /usr/lib/libGLU.so ] && libgl='yes' [ -e /usr/lib64/libGL.so -a -e /usr/lib64/libGLU.so ] && libgl='yes' [ -e /usr/lib/*-linux-gnu/libGL.so -a -e /usr/lib/*-linux-gnu/libGLU.so ] && libgl='yes' if [ "$libgl" != 'yes' ]; then echo "You need libGL.so and libGLU.so to exist in your library path to run the QEMU emulator. Ubuntu package names are: libgl1-mesa-dev and libglu1-mesa-dev. Fedora package names are: mesa-libGL-devel mesa-libGLU-devel." return 1; fi fi do_quit() { if [ -n "$PIDFILE" ]; then #echo kill `cat $PIDFILE` kill `cat $PIDFILE` fi cleanup return 1 } DISTCCD=`which distccd 2> /dev/null` PIDFILE="" trap do_quit INT TERM QUIT if [ -x "$DISTCCD" ]; then echo "Starting distccd..." PIDFILE=`mktemp` $DISTCCD --allow 192.168.7.2 --daemon --pid-file $PIDFILE & else echo "WARNING: distccd not present, no distcc support loaded." fi # qemu got segfault if linked with nVidia's libgl GL_LD_PRELOAD=$LD_PRELOAD if ldd $QEMUBIN | grep -i nvidia &> /dev/null then cat << EOM WARNING: nVidia proprietary OpenGL libraries detected. nVidia's OpenGL libraries are known to have compatibility issues with qemu, resulting in a segfault. Please uninstall these drivers or ensure the mesa libGL libraries precede nvidia's via LD_PRELOAD(Already do it on Ubuntu 10). EOM # Automatically use Ubuntu system's mesa libGL, other distro can add its own path if grep -i ubuntu /etc/lsb-release &> /dev/null then # precede nvidia's driver on Ubuntu 10 UBUNTU_MAIN_VERSION=`cat /etc/lsb-release |grep DISTRIB_RELEASE |cut -d= -f 2| cut -d. -f 1` if [ "$UBUNTU_MAIN_VERSION" = "10" ]; then GL_PATH="" if test -e /usr/lib/libGL.so then GL_PATH="/usr/lib/libGL.so" elif test -e /usr/lib/x86_64-linux-gnu/libGL.so then GL_PATH="/usr/lib/x86_64-linux-gnu/libGL.so" fi echo "Skip nVidia's libGL on Ubuntu 10!" GL_LD_PRELOAD="$GL_PATH $LD_PRELOAD" fi fi fi if [ "x$SERIALSTDIO" = "x1" ]; then echo "Interrupt character is '^]'" stty intr ^] fi echo "Running $QEMU..." # -no-reboot is a mandatory option - see bug #100 if [ "$FSTYPE" = "vmdk" ]; then echo $QEMUBIN $VM $QEMUOPTIONS $SERIALOPTS -no-reboot $SCRIPT_QEMU_OPT $SCRIPT_QEMU_EXTRA_OPT LD_PRELOAD="$GL_LD_PRELOAD" $QEMUBIN $VM $QEMUOPTIONS $SERIALOPTS -no-reboot $SCRIPT_QEMU_OPT $SCRIPT_QEMU_EXTRA_OPT elif [ "$FSTYPE" = "iso" ]; then echo $QEMUBIN $QEMUOPTIONS $SERIALOPTS -no-reboot $SCRIPT_QEMU_OPT $SCRIPT_QEMU_EXTRA_OPT LD_PRELOAD="$GL_LD_PRELOAD" $QEMUBIN $QEMUOPTIONS $SERIALOPTS -no-reboot $SCRIPT_QEMU_OPT $SCRIPT_QEMU_EXTRA_OPT else echo $QEMUBIN -kernel $KERNEL $QEMUOPTIONS $SERIALOPTS -no-reboot $SCRIPT_QEMU_OPT $SCRIPT_QEMU_EXTRA_OPT --append '"'$KERNCMDLINE $SCRIPT_KERNEL_OPT'"' LD_PRELOAD="$GL_LD_PRELOAD" $QEMUBIN -kernel $KERNEL $QEMUOPTIONS $SERIALOPTS -no-reboot $SCRIPT_QEMU_OPT $SCRIPT_QEMU_EXTRA_OPT --append "$KERNCMDLINE $SCRIPT_KERNEL_OPT" fi ret=$? cleanup trap - INT TERM QUIT return $ret
#!/bin/bash -x # Handle running OE images under qemu # # Copyright (C) 2006-2011 Linux Foundation # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 as # published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # Call setting: # QEMU_MEMORY (optional) - set the amount of memory in the emualted system. # SERIAL_LOGFILE (optional) - log the serial port output to a file # CROSSPATH - the path to any cross toolchain to use with distcc # # Image options: # MACHINE - the machine to run # FSTYPE - the image type to run # KERNEL - the kernel image file to use # ROOTFS - the disk image file to use # mem_size=-1 #Get rid of <> and get the contents of extra qemu running params SCRIPT_QEMU_EXTRA_OPT=`echo $SCRIPT_QEMU_EXTRA_OPT | sed -e 's/<//' -e 's/>//'` #if user set qemu memory, eg: -m 256 in qemu extra params, we need to do some # validation check mem_set=`expr "$SCRIPT_QEMU_EXTRA_OPT" : '.*\(-m[[:space:]] *[0-9]*\)'` if [ ! -z "$mem_set" ] ; then #Get memory setting size from user input mem_size=`echo $mem_set | sed 's/-m[[:space:]] *//'` else case "$MACHINE" in "qemux86") mem_size=128 ;; "qemux86-64") mem_size=128 ;; "qemuarm") mem_size=128 ;; "qemumips"|"qemumips64") mem_size=128 ;; "qemuppc") mem_size=128 ;; "qemush4") mem_size=1024 ;; *) mem_size=64 ;; esac fi # QEMU_MEMORY has 'M' appended to mem_size QEMU_MEMORY="$mem_size"M # Bug 433: qemuarm cannot use > 256 MB RAM if [ "$MACHINE" = "qemuarm" ]; then if [ -z "$mem_size" -o $mem_size -gt 256 ]; then echo "WARNING: qemuarm does not support > 256M of RAM." echo "Changing QEMU_MEMORY to default of 256M." QEMU_MEMORY="256M" mem_size="256" SCRIPT_QEMU_EXTRA_OPT=`echo $SCRIPT_QEMU_EXTRA_OPT | sed -e "s/$mem_set/-m 256/" ` fi fi # We need to specify -m <mem_size> to overcome a bug in qemu 0.14.0 # https://bugs.launchpad.net/ubuntu/+source/qemu-kvm/+bug/584480 if [ -z "$mem_set" ] ; then SCRIPT_QEMU_EXTRA_OPT="$SCRIPT_QEMU_EXTRA_OPT -m $mem_size" fi # This file is created when runqemu-gen-tapdevs creates a bank of tap # devices, indicating that the user should not bring up new ones using # sudo. NOSUDO_FLAG="/etc/runqemu-nosudo" QEMUIFUP=`which runqemu-ifup 2> /dev/null` QEMUIFDOWN=`which runqemu-ifdown 2> /dev/null` if [ -z "$QEMUIFUP" -o ! -x "$QEMUIFUP" ]; then echo "runqemu-ifup cannot be found or executed" exit 1 fi if [ -z "$QEMUIFDOWN" -o ! -x "$QEMUIFDOWN" ]; then echo "runqemu-ifdown cannot be found or executed" exit 1 fi NFSRUNNING="false" acquire_lock() { lockfile=$1 if [ -z "$lockfile" ]; then echo "Error: missing lockfile arg passed to acquire_lock()" return 1 fi if [ -e "$lockfile.lock" ]; then # Check that the lockfile is not stale ps=`ps -eo pid | grep $(cat $lockfile.lock)` if [ -z "$ps" ]; then echo "WARNING: Stale lock file detected, deleting $lockfile.lock." rm -f $lockfile.lock echo $$ > $lockfile.lock else return 1 fi else echo $$ > $lockfile.lock fi return 0 } release_lock() { lockfile=$1 if [ -z "$lockfile" ]; then echo "Error: missing lockfile arg passed to release_lock()" return 1 fi rm -f $lockfile.lock } LOCKDIR="/tmp/qemu-tap-locks" if [ ! -d "$LOCKDIR" ]; then mkdir $LOCKDIR chmod 777 $LOCKDIR fi IFCONFIG=`which ifconfig 2> /dev/null` if [ -z "$IFCONFIG" ]; then IFCONFIG=/sbin/ifconfig fi if [ ! -x "$IFCONFIG" ]; then echo "$IFCONFIG cannot be executed" exit 1 fi POSSIBLE=`$IFCONFIG -a | grep '^tap' | awk '{print $1}' | sed s/://` TAP="" LOCKFILE="" for tap in $POSSIBLE; do LOCKFILE="$LOCKDIR/$tap" echo "Acquiring lockfile for $tap..." acquire_lock $LOCKFILE if [ $? -eq 0 ]; then TAP=$tap break fi done if [ "$TAP" = "" ]; then if [ -e "$NOSUDO_FLAG" ]; then echo "Error: There are no available tap devices to use for networking," echo "and I see $NOSUDO_FLAG exists, so I am not going to try creating" echo "a new one with sudo." exit 1 fi GROUPID=`id -g` USERID=`id -u` echo "Setting up tap interface under sudo" # Redirect stderr since we could see a LD_PRELOAD warning here if pseudo is loaded # but inactive. This looks scary but is harmless tap=`sudo $QEMUIFUP $USERID $GROUPID $OECORE_NATIVE_SYSROOT 2> /dev/null` if [ $? -ne 0 ]; then # Re-run standalone to see verbose errors sudo $QEMUIFUP $USERID $GROUPID $OECORE_NATIVE_SYSROOT return 1 fi LOCKFILE="$LOCKDIR/$tap" echo "Acquiring lockfile for $tap..." acquire_lock $LOCKFILE if [ $? -eq 0 ]; then TAP=$tap fi else echo "Using preconfigured tap device '$TAP'" fi cleanup() { if [ ! -e "$NOSUDO_FLAG" ]; then # Redirect stderr since we could see a LD_PRELOAD warning here if pseudo is loaded # but inactive. This looks scary but is harmless sudo $QEMUIFDOWN $TAP $OECORE_NATIVE_SYSROOT 2> /dev/null fi echo "Releasing lockfile of preconfigured tap device '$TAP'" release_lock $LOCKFILE if [ "$NFSRUNNING" = "true" ]; then echo "Shutting down the userspace NFS server..." echo "runqemu-export-rootfs stop $ROOTFS" runqemu-export-rootfs stop $ROOTFS fi # If QEMU crashes or somehow tty properties are not restored # after qemu exits, we need to run stty sane stty sane } n0=$(echo $TAP | sed 's/tap//') n1=$(($n0 * 2 + 1)) n2=$(($n1 + 1)) KERNEL_NETWORK_CMD="ip=192.168.7.$n2::192.168.7.$n1:255.255.255.0" QEMU_TAP_CMD="-net tap,vlan=0,ifname=$TAP,script=no,downscript=no" if [ "$KVM_ACTIVE" = "yes" ]; then QEMU_NETWORK_CMD="-net nic,model=virtio $QEMU_TAP_CMD,vhost=on" DROOT="/dev/vda" ROOTFS_OPTIONS="-drive file=$ROOTFS,if=virtio" else QEMU_NETWORK_CMD="-net nic,vlan=0 $QEMU_TAP_CMD" DROOT="/dev/hda" ROOTFS_OPTIONS="-hda $ROOTFS" fi KERNCMDLINE="mem=$QEMU_MEMORY" QEMU_UI_OPTIONS="-show-cursor -usb -usbdevice wacom-tablet" NFS_INSTANCE=`echo $TAP | sed 's/tap//'` export NFS_INSTANCE SERIALOPTS="" if [ "x$SERIAL_LOGFILE" != "x" ]; then SERIALOPTS="-serial file:$SERIAL_LOGFILE" fi case "$MACHINE" in "qemuarm") ;; "qemumips") ;; "qemumipsel") ;; "qemumips64") ;; "qemush4") ;; "qemuppc") ;; "qemuarmv6") ;; "qemuarmv7") ;; "qemux86") ;; "qemux86-64") ;; "akita") ;; "spitz") ;; *) echo "Error: Unsupported machine type $MACHINE" return 1 ;; esac if [ ! -f "$KERNEL" -a "x$FSTYPE" != "xvmdk" ]; then echo "Error: Kernel image file $KERNEL doesn't exist" cleanup return 1 fi if [ "$FSTYPE" != "nfs" -a "$FSTYPE" != "vmdk" -a ! -f "$ROOTFS" ]; then echo "Error: Image file $ROOTFS doesn't exist" cleanup return 1 fi if [ "$FSTYPE" = "nfs" ]; then NFS_SERVER="192.168.7.1" NFS_DIR=`echo $ROOTFS | sed 's/^[^:]*:\(.*\)/\1/'` MOUNTD_RPCPORT=$[ 21111 + $NFS_INSTANCE ] NFSD_RPCPORT=$[ 11111 + $NFS_INSTANCE ] NFSD_PORT=$[ 3049 + 2 * $NFS_INSTANCE ] MOUNTD_PORT=$[ 3048 + 2 * $NFS_INSTANCE ] UNFS_OPTS="nfsvers=2,mountprog=$MOUNTD_RPCPORT,nfsprog=$NFSD_RPCPORT,udp,port=$NFSD_PORT,mountport=$MOUNTD_PORT" PSEUDO_LOCALSTATEDIR=~/.runqemu-sdk/pseudo export PSEUDO_LOCALSTATEDIR # Start the userspace NFS server echo "runqemu-export-rootfs restart $ROOTFS" runqemu-export-rootfs restart $ROOTFS if [ $? != 0 ]; then cleanup return 1 fi NFSRUNNING="true" fi if [ "$NFS_SERVER" = "" ]; then NFS_SERVER="192.168.7.1" NFS_DIR=$ROOTFS fi if [ "$MACHINE" = "qemuarm" -o "$MACHINE" = "qemuarmv6" -o "$MACHINE" = "qemuarmv7" ]; then QEMU=qemu-system-arm MACHINE_SUBTYPE=versatilepb export QEMU_AUDIO_DRV="none" QEMU_UI_OPTIONS="$QEMU_UI_OPTIONS" # QEMU_UI_OPTIONS="$QEMU_UI_OPTIONS -force-pointer" if [ "$FSTYPE" = "ext3" -o "$FSTYPE" = "btrfs" ]; then KERNCMDLINE="root=/dev/sda rw console=ttyAMA0,115200 console=tty $KERNEL_NETWORK_CMD mem=$QEMU_MEMORY highres=off" QEMUOPTIONS="$QEMU_NETWORK_CMD -M versatilepb -hda $ROOTFS -no-reboot $QEMU_UI_OPTIONS" fi if [ "$FSTYPE" = "nfs" ]; then if [ "$NFS_SERVER" = "192.168.7.1" -a ! -d "$NFS_DIR" ]; then echo "Error: NFS mount point $ROOTFS doesn't exist" cleanup return 1 fi KERNCMDLINE="root=/dev/nfs nfsroot=$NFS_SERVER:$NFS_DIR,$UNFS_OPTS rw $KERNEL_NETWORK_CMD mem=$QEMU_MEMORY" QEMUOPTIONS="$QEMU_NETWORK_CMD -M versatilepb --no-reboot $QEMU_UI_OPTIONS" fi if [ "$MACHINE" = "qemuarmv6" ]; then QEMUOPTIONS="$QEMUOPTIONS -cpu arm1136" fi if [ "$MACHINE" = "qemuarmv7" ]; then QEMUOPTIONS="$QEMUOPTIONS -cpu cortex-a8" fi fi if [ "$MACHINE" = "qemux86" ]; then QEMU=qemu-system-i386 QEMU_UI_OPTIONS="$QEMU_UI_OPTIONS -vga vmware" if [ "$FSTYPE" = "ext2" -o "$FSTYPE" = "ext3" -o "$FSTYPE" = "btrfs" ]; then KERNCMDLINE="vga=0 root=$DROOT rw mem=$QEMU_MEMORY $KERNEL_NETWORK_CMD" QEMUOPTIONS="$QEMU_NETWORK_CMD $ROOTFS_OPTIONS $QEMU_UI_OPTIONS" fi if [ "$FSTYPE" = "nfs" ]; then if [ "$NFS_SERVER" = "192.168.7.1" -a ! -d "$NFS_DIR" ]; then echo "Error: NFS mount point $ROOTFS doesn't exist." cleanup return 1 fi KERNCMDLINE="root=/dev/nfs nfsroot=$NFS_SERVER:$NFS_DIR,$UNFS_OPTS rw $KERNEL_NETWORK_CMD mem=$QEMU_MEMORY" QEMUOPTIONS="$QEMU_NETWORK_CMD $QEMU_UI_OPTIONS" fi if [ "$FSTYPE" = "vmdk" ]; then QEMUOPTIONS="$QEMU_NETWORK_CMD $QEMU_UI_OPTIONS" fi # Currently oprofile's event based interrupt mode doesn't work(Bug #828) in # qemux86 and qemux86-64. We can use timer interrupt mode for now. KERNCMDLINE="$KERNCMDLINE oprofile.timer=1" fi if [ "$MACHINE" = "qemux86-64" ]; then QEMU=qemu-system-x86_64 QEMU_UI_OPTIONS="$QEMU_UI_OPTIONS -vga vmware" if [ "$FSTYPE" = "ext3" -o "$FSTYPE" = "btrfs" ]; then KERNCMDLINE="vga=0 root=$DROOT rw mem=$QEMU_MEMORY $KERNEL_NETWORK_CMD" QEMUOPTIONS="$QEMU_NETWORK_CMD $ROOTFS_OPTIONS $QEMU_UI_OPTIONS" fi if [ "$FSTYPE" = "nfs" ]; then if [ "x$ROOTFS" = "x" ]; then ROOTFS=/srv/nfs/qemux86-64 fi if [ ! -d "$ROOTFS" ]; then echo "Error: NFS mount point $ROOTFS doesn't exist." cleanup return 1 fi KERNCMDLINE="root=/dev/nfs nfsroot=$NFS_SERVER:$NFS_DIR,$UNFS_OPTS rw $KERNEL_NETWORK_CMD mem=$QEMU_MEMORY" QEMUOPTIONS="$QEMU_NETWORK_CMD $QEMU_UI_OPTIONS" fi if [ "$FSTYPE" = "vmdk" ]; then QEMUOPTIONS="$QEMU_NETWORK_CMD $QEMU_UI_OPTIONS" fi # Currently oprofile's event based interrupt mode doesn't work(Bug #828) in # qemux86 and qemux86-64. We can use timer interrupt mode for now. KERNCMDLINE="$KERNCMDLINE oprofile.timer=1" fi if [ "$MACHINE" = "spitz" ]; then QEMU=qemu-system-arm if [ "$FSTYPE" = "ext3" -o "$FSTYPE" = "btrfs" ]; then echo $ROOTFS ROOTFS=`readlink -f $ROOTFS` echo $ROOTFS if [ ! -e "$ROOTFS.qemudisk" ]; then echo "Adding a partition table to the ext3 image for use by QEMU, please wait..." runqemu-addptable2image $ROOTFS $ROOTFS.qemudisk fi QEMUOPTIONS="$QEMU_NETWORK_CMD -M spitz -hda $ROOTFS.qemudisk -portrait" fi fi if [ "$MACHINE" = "qemumips" -o "$MACHINE" = "qemumipsel" -o "$MACHINE" = "qemumips64" ]; then case "$MACHINE" in qemumips) QEMU=qemu-system-mips ;; qemumipsel) QEMU=qemu-system-mipsel ;; qemumips64) QEMU=qemu-system-mips64 ;; esac MACHINE_SUBTYPE=malta QEMU_UI_OPTIONS="-vga cirrus $QEMU_UI_OPTIONS" if [ "$FSTYPE" = "ext3" -o "$FSTYPE" = "btrfs" ]; then #KERNCMDLINE="root=/dev/hda console=ttyS0 console=tty0 $KERNEL_NETWORK_CMD mem=$QEMU_MEMORY" KERNCMDLINE="root=/dev/hda rw console=ttyS0 console=tty $KERNEL_NETWORK_CMD mem=$QEMU_MEMORY" QEMUOPTIONS="$QEMU_NETWORK_CMD -M $MACHINE_SUBTYPE -hda $ROOTFS -no-reboot $QEMU_UI_OPTIONS" fi if [ "$FSTYPE" = "nfs" ]; then if [ "$NFS_SERVER" = "192.168.7.1" -a ! -d "$NFS_DIR" ]; then echo "Error: NFS mount point $ROOTFS doesn't exist" cleanup return 1 fi KERNCMDLINE="root=/dev/nfs console=ttyS0 console=tty nfsroot=$NFS_SERVER:$NFS_DIR,$UNFS_OPTS rw $KERNEL_NETWORK_CMD mem=$QEMU_MEMORY" QEMUOPTIONS="$QEMU_NETWORK_CMD -M $MACHINE_SUBTYPE -no-reboot $QEMU_UI_OPTIONS" fi fi if [ "$MACHINE" = "qemuppc" ]; then QEMU=qemu-system-ppc MACHINE_SUBTYPE=mac99 CPU_SUBTYPE=G4 QEMU_UI_OPTIONS="$QEMU_UI_OPTIONS" QEMU_NETWORK_CMD="-net nic,model=pcnet $QEMU_TAP_CMD" if [ "$FSTYPE" = "ext3" -o "$FSTYPE" = "btrfs" ]; then KERNCMDLINE="root=/dev/hda rw console=ttyS0 console=tty $KERNEL_NETWORK_CMD mem=$QEMU_MEMORY" QEMUOPTIONS="$QEMU_NETWORK_CMD -cpu $CPU_SUBTYPE -M $MACHINE_SUBTYPE -hda $ROOTFS -no-reboot $QEMU_UI_OPTIONS" fi if [ "$FSTYPE" = "nfs" ]; then if [ "$NFS_SERVER" = "192.168.7.1" -a ! -d "$NFS_DIR" ]; then echo "Error: NFS mount point $ROOTFS doesn't exist" cleanup return 1 fi KERNCMDLINE="root=/dev/nfs console=ttyS0 console=tty nfsroot=$NFS_SERVER:$NFS_DIR,$UNFS_OPTS rw $KERNEL_NETWORK_CMD mem=$QEMU_MEMORY" QEMUOPTIONS="$QEMU_NETWORK_CMD -cpu $CPU_SUBTYPE -M $MACHINE_SUBTYPE -no-reboot $QEMU_UI_OPTIONS" fi fi if [ "$MACHINE" = "qemush4" ]; then QEMU=qemu-system-sh4 MACHINE_SUBTYPE=r2d QEMU_UI_OPTIONS="$QEMU_UI_OPTIONS" if [ "$FSTYPE" = "ext3" -o "$FSTYPE" = "btrfs" ]; then #KERNCMDLINE="root=/dev/hda console=ttyS0 console=tty0 $KERNEL_NETWORK_CMD mem=$QEMU_MEMORY" KERNCMDLINE="root=/dev/hda rw console=ttySC1 noiotrap earlyprintk=sh-sci.1 console=tty $KERNEL_NETWORK_CMD mem=$QEMU_MEMORY" QEMUOPTIONS="$QEMU_NETWORK_CMD -M $MACHINE_SUBTYPE -hda $ROOTFS -no-reboot $QEMU_UI_OPTIONS -monitor null -serial vc -serial stdio" SERIALSTDIO="1" fi if [ "$FSTYPE" = "nfs" ]; then if [ "$NFS_SERVER" = "192.168.7.1" -a ! -d "$NFS_DIR" ]; then echo "Error: NFS mount point $ROOTFS doesn't exist" cleanup return 1 fi 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" QEMUOPTIONS="$QEMU_NETWORK_CMD -M $MACHINE_SUBTYPE -no-reboot $QEMU_UI_OPTIONS -monitor null -serial vc -serial stdio" SERIALSTDIO="1" fi fi if [ "$MACHINE" = "akita" ]; then QEMU=qemu-system-arm if [ "$FSTYPE" = "jffs2" ]; then ROOTFS=`readlink -f $ROOTFS` if [ ! -e "$ROOTFS.qemuflash" ]; then echo "Converting raw image into flash image format for use by QEMU, please wait..." raw2flash.akita < $ROOTFS > $ROOTFS.qemuflash fi QEMUOPTIONS="$QEMU_NETWORK_CMD -M akita -mtdblock $ROOTFS.qemuflash -portrait" fi fi if [ "x$RAMFS" = "xtrue" ]; then QEMUOPTIONS="-initrd $ROOTFS -nographic" KERNCMDLINE="root=/dev/ram0 debugshell" fi if [ "x$ISOFS" = "xtrue" ]; then QEMUOPTIONS="-cdrom $ROOTFS" fi if [ "x$QEMUOPTIONS" = "x" ]; then echo "Error: Unable to support this combination of options" cleanup return 1 fi if [ "x$CROSSPATH" = "x" ]; then PATH=$OECORE_NATIVE_SYSROOT/usr/bin:$PATH else PATH=$CROSSPATH:$OECORE_NATIVE_SYSROOT/usr/bin:$PATH fi QEMUBIN=`which $QEMU 2> /dev/null` if [ ! -x "$QEMUBIN" ]; then echo "Error: No QEMU binary '$QEMU' could be found." cleanup return 1 fi NEED_GL=`ldd $QEMUBIN/$QEMU 2>&1 | grep libGLU` # We can't run without a libGL.so if [ "$NEED_GL" != "" ]; then libgl='no' [ -e /usr/lib/libGL.so -a -e /usr/lib/libGLU.so ] && libgl='yes' [ -e /usr/lib64/libGL.so -a -e /usr/lib64/libGLU.so ] && libgl='yes' [ -e /usr/lib/*-linux-gnu/libGL.so -a -e /usr/lib/*-linux-gnu/libGLU.so ] && libgl='yes' if [ "$libgl" != 'yes' ]; then echo "You need libGL.so and libGLU.so to exist in your library path to run the QEMU emulator. Ubuntu package names are: libgl1-mesa-dev and libglu1-mesa-dev. Fedora package names are: mesa-libGL-devel mesa-libGLU-devel." return 1; fi fi do_quit() { if [ -n "$PIDFILE" ]; then #echo kill `cat $PIDFILE` kill `cat $PIDFILE` fi cleanup return 1 } DISTCCD=`which distccd 2> /dev/null` PIDFILE="" trap do_quit INT TERM QUIT if [ -x "$DISTCCD" ]; then echo "Starting distccd..." PIDFILE=`mktemp` $DISTCCD --allow 192.168.7.2 --daemon --pid-file $PIDFILE & else echo "WARNING: distccd not present, no distcc support loaded." fi # qemu got segfault if linked with nVidia's libgl GL_LD_PRELOAD=$LD_PRELOAD if ldd $QEMUBIN | grep -i nvidia &> /dev/null then cat << EOM WARNING: nVidia proprietary OpenGL libraries detected. nVidia's OpenGL libraries are known to have compatibility issues with qemu, resulting in a segfault. Please uninstall these drivers or ensure the mesa libGL libraries precede nvidia's via LD_PRELOAD(Already do it on Ubuntu 10). EOM # Automatically use Ubuntu system's mesa libGL, other distro can add its own path if grep -i ubuntu /etc/lsb-release &> /dev/null then # precede nvidia's driver on Ubuntu 10 UBUNTU_MAIN_VERSION=`cat /etc/lsb-release |grep DISTRIB_RELEASE |cut -d= -f 2| cut -d. -f 1` if [ "$UBUNTU_MAIN_VERSION" = "10" ]; then GL_PATH="" if test -e /usr/lib/libGL.so then GL_PATH="/usr/lib/libGL.so" elif test -e /usr/lib/x86_64-linux-gnu/libGL.so then GL_PATH="/usr/lib/x86_64-linux-gnu/libGL.so" fi echo "Skip nVidia's libGL on Ubuntu 10!" GL_LD_PRELOAD="$GL_PATH $LD_PRELOAD" fi fi fi if [ "x$SERIALSTDIO" = "x1" ]; then echo "Interrupt character is '^]'" stty intr ^] fi echo "Running $QEMU..." # -no-reboot is a mandatory option - see bug #100 if [ "$FSTYPE" = "vmdk" ]; then echo $QEMUBIN $VM $QEMUOPTIONS $SERIALOPTS -no-reboot $SCRIPT_QEMU_OPT $SCRIPT_QEMU_EXTRA_OPT LD_PRELOAD="$GL_LD_PRELOAD" $QEMUBIN $VM $QEMUOPTIONS $SERIALOPTS -no-reboot $SCRIPT_QEMU_OPT $SCRIPT_QEMU_EXTRA_OPT elif [ "$FSTYPE" = "iso" ]; then echo $QEMUBIN $QEMUOPTIONS $SERIALOPTS -no-reboot $SCRIPT_QEMU_OPT $SCRIPT_QEMU_EXTRA_OPT LD_PRELOAD="$GL_LD_PRELOAD" $QEMUBIN $QEMUOPTIONS $SERIALOPTS -no-reboot $SCRIPT_QEMU_OPT $SCRIPT_QEMU_EXTRA_OPT else echo $QEMUBIN -kernel $KERNEL $QEMUOPTIONS $SERIALOPTS -no-reboot $SCRIPT_QEMU_OPT $SCRIPT_QEMU_EXTRA_OPT --append '"'$KERNCMDLINE $SCRIPT_KERNEL_OPT'"' LD_PRELOAD="$GL_LD_PRELOAD" $QEMUBIN -kernel $KERNEL $QEMUOPTIONS $SERIALOPTS -no-reboot $SCRIPT_QEMU_OPT $SCRIPT_QEMU_EXTRA_OPT --append "$KERNCMDLINE $SCRIPT_KERNEL_OPT" fi ret=$? cleanup trap - INT TERM QUIT return $ret