Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- # generic_qemu_loader.sh
- # Last changed 2011/08/05
- #
- # Starts QEMU with specified Openembedded kernel and image
- # Originally idea and basic network code from http://en.wikibooks.org/wiki/QEMU/Networking
- #
- # Copyright 2011 Samuel Stirtzel <[email protected]>
- # Dual licensed BSD / GPL (you can use this script either with BSD or GPL license)
- #
- # BSD
- #
- # Redistribution and use in source and binary forms, with or without
- # modification, are permitted provided that the following conditions are
- # met:
- #
- # * Redistributions of source code must retain the above copyright
- # notice, this list of conditions and the following disclaimer.
- # * Redistributions in binary form must reproduce the above
- # copyright notice, this list of conditions and the following disclaimer
- # in the documentation and/or other materials provided with the
- # distribution.
- # * Neither the name of the authors nor the names of its
- # contributors may be used to endorse or promote products derived from
- # this software without specific prior written permission.
- #
- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
- #
- #
- # GPL
- #
- # This program is free software; you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation; either version 2 of the License, or
- # (at your option) any later version.
- #
- # 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.
- #
- function print_usage() {
- echo "Usage for the shell script: $0 [-bkmor]
- ___________________
- Brief description: \\_______________________________________________________________________________
- Starts QEMU with standard networking or network over a bridge/tap interface.
- This script needs no sudo or root user rights if executed without parameter -b.
- ____________
- Parameters: \\______________________________________________________________________________________
- -h Shows this information.
- -b [optional] Will create a local bridge and tap interface (needs root user rights),
- the interface will be deleted after QEMU stops.
- -k * Uses the file after -k as kernel image.
- Usage: ... -k /mydir/zImage-qemuarm.bin (or similar images)
- -m [optional] Sets the main memory, default is 128M.
- Usage: ... -m 256M
- -o [optional] Additional parameters passed to QEMU, use quotes or -o multiple times
- -r * Uses the file after -r as root filesystem.
- Usage: ... -r /mydir/console-image-qemuarm.ext2 (or similar filesystems)
- _________
- Example: \\_________________________________________________________________________________________
- The script can be used like this.
- user@machine:/somedir$ sh $0 -k /mydir/zImage-qemuarm.bin \\
- -r /mydir/console-image-qemuarm.ext2 -b -m 256M
- or with chmod +x instead of sh
- This will set up the bridge/tap, start QEMU with the kernel (-k) / root filesystem (-r)
- and close the bridge/tap after QEMU exited."
- }
- # pre start
- SCRIPT=$(readlink -f $0)
- scriptPath=$(dirname $SCRIPT)
- # set standard variables
- memoryMB="128M"
- qemuOptions=
- kernelPath=0
- rootFSPath=0
- # check options from parameters
- while getopts "hbk:m:o:r:" Option
- do
- case $Option in
- h ) print_usage
- exit 0
- ;;
- b ) bridge=1
- ;;
- k ) kernelPath=$OPTARG
- ;;
- m ) memoryMB=$OPTARG
- ;;
- o ) qemuOptions+=" "+$OPTARG
- ;;
- r ) rootFSPath=$OPTARG
- ;;
- ? ) print_usage
- exit 0
- ;;
- esac
- done
- shift $(($OPTIND - 1))
- if [ $kernelPath = 0 ]
- then
- echo "No kernel image set."
- print_usage
- exit 0
- fi
- if [ $rootFSPath = 0 ]
- then
- echo "No root filesystem set."
- print_usage
- exit 0
- fi
- # pre stop
- # actual script start
- if [ $bridge = 1 ]
- then
- ## setup the network connection for QEMU (this will abort your other connections)
- sudo sh ${scriptPath}/start_qemu_networking.sh tap0 `id -un`
- else
- echo "0. Standard network interface will be used"
- fi
- ## Start QEMU
- echo "Starting QEMU"
- if [ $bridge = 1 ]
- then
- ### start QEMU with network bridge and tap support
- sudo qemu-system-arm -M versatilepb -m 128M -kernel ${kernelPath} -hda ${rootFSPath} -append 'root=/dev/sda rw console=tty0 raid=noautodetect' -net nic -net tap,ifname=tap0,script=no $qemuOption
- else
- ### start QEMU with standard network
- qemu-system-arm -M versatilepb -m 128M -kernel ${kernelPath} -hda ${rootFSPath} -append 'root=/dev/sda rw console=tty0 raid=noautodetect' $qemuOption
- fi
- echo "QEMU stopped with exit code $?"
- if [ $bridge = 1 ]
- then
- ## restart the original network connection and refresh the dhcp
- sudo sh ${scriptPath}/stop_qemu_networking.sh tap0
- fi
- # actual script stop
Advertisement
Add Comment
Please, Sign In to add comment