#!/bin/bash # # Handle running OE images standalone with 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. usage() { MYNAME=`basename $0` echo "" echo "Usage: you can run this script with any valid combination" echo "of the following options (in any order):" echo " QEMUARCH - the qemu machine architecture to use" echo " KERNEL - the kernel image file to use" echo " ROOTFS - the rootfs image file or nfsroot directory to use" echo " MACHINE=xyz - the machine name (optional, autodetected from KERNEL filename if unspecified)" echo " Additional QEMU command-line options can be passed with:" echo " nographic - disables video console" echo " serial - enables a serial console on /dev/ttyS0" echo " kvm - enables KVM when running qemux86/qemux86-64, VT capable CPU required" echo " \"<extra-qemu-options>\" - enables extra qemu options, excluding serial and kvm" echo "" echo "Examples:" echo " $MYNAME qemuarm" echo " $MYNAME qemux86-64 core-image-sato ext3" echo " $MYNAME path/to/bzImage-qemux86.bin path/to/nfsrootdir/ serial" echo " $MYNAME qemux86 \"<-m 256>\"" exit 1 } if [ "x$1" = "x" ]; then usage fi MACHINE=${MACHINE:=""} KERNEL="" FSTYPE="" ROOTFS="" LAZY_ROOTFS="" SCRIPT_QEMU_OPT="" SCRIPT_QEMU_EXTRA_OPT="" SCRIPT_KERNEL_OPT="" TMPDIR="" # Determine whether the file is a kernel or QEMU image, and set the # appropriate variables process_filename() { filename=$1 # Extract the filename extension EXT=`echo $filename | awk -F . '{ print \$NF }'` # A file ending in .bin is a kernel if [ "x$EXT" = "xbin" ]; then if [ -z "$KERNEL" ]; then KERNEL=$filename else echo "Error: conflicting KERNEL args [$KERNEL] and [$filename]" usage fi elif [[ "x$EXT" == "xext2" || "x$EXT" == "xext3" || "x$EXT" == "xjffs2" || "x$EXT" == "xbtrfs" ]]; then # A file ending in a supportted fs type is a rootfs image if [[ -z "$FSTYPE" || "$FSTYPE" == "$EXT" ]]; then FSTYPE=$EXT ROOTFS=$filename else echo "Error: conflicting FSTYPE types [$FSTYPE] and [$EXT]" usage fi else echo "Error: unknown file arg [$filename]" usage fi } # Parse command line args without requiring specific ordering. It's a # bit more complex, but offers a great user experience. KVM_ENABLED="no" i=1 while [ $i -le $# ]; do arg=${!i} case $arg in "qemux86" | "qemux86-64" | "qemuarm" | "qemumips" | "qemuppc") if [ -z "$MACHINE" ]; then MACHINE=$arg else echo "Error: conflicting MACHINE types [$MACHINE] and [$arg]" usage fi ;; "ext2" | "ext3" | "jffs2" | "nfs" | "btrfs") if [[ -z "$FSTYPE" || "$FSTYPE" == "$arg" ]]; then FSTYPE=$arg else echo "Error: conflicting FSTYPE types [$FSTYPE] and [$arg]" usage fi ;; *-image-*) if [ -z "$ROOTFS" ]; then if [ -f "$arg" ]; then process_filename $arg elif [ -d "$arg" ]; then # Handle the case where the nfsroot dir has -image- # in the pathname echo "Assuming $arg is an nfs rootfs" FSTYPE=nfs ROOTFS=$arg else ROOTFS=$arg LAZY_ROOTFS="true" fi else echo "Error: conflicting ROOTFS args [$ROOTFS] and [$arg]" usage fi ;; "nographic") SCRIPT_QEMU_OPT="$SCRIPT_QEMU_OPT -nographic" ;; "serial") SCRIPT_QEMU_OPT="$SCRIPT_QEMU_OPT -serial stdio" SCRIPT_KERNEL_OPT="$SCRIPT_KERNEL_OPT console=ttyS0" ;; "audio") if [[ "x$MACHINE" == "xqemux86" || "x$MACHINE" == "xqemux86-64" ]]; then echo "Enable audio on qemu. Pls. install snd_intel8x0 or snd_ens1370 driver in linux guest."; QEMU_AUDIO_DRV="alsa" SCRIPT_QEMU_OPT="$SCRIPT_QEMU_OPT -soundhw ac97,es1370" fi ;; "kvm") KVM_ENABLED="yes" KVM_CAPABLE=`grep 'vmx\|smx' /proc/cpuinfo` ;; \<*\>) SCRIPT_QEMU_EXTRA_OPT=$arg serial_option=`expr "$SCRIPT_QEMU_EXTRA_OPT" : '.*\(-serial\)'` kvm_option=`expr "$SCRIPT_QEMU_EXTRA_OPT" : '.*\(-enable-kvm\)'` echo2018-10-21mm: Convert __do_page_cache_readahead to XArrayMatthew Wilcox