[oe-commits] Khem Raj : contrib: Add scripts to run qemu

git version control git at git.openembedded.org
Thu Apr 1 22:20:44 UTC 2010


Module: openembedded.git
Branch: org.openembedded.dev
Commit: c652a39e6c87f4d4e5efdda3bcc7a120a99b14d8
URL:    http://gitweb.openembedded.net/?p=openembedded.git&a=commit;h=c652a39e6c87f4d4e5efdda3bcc7a120a99b14d8

Author: Khem Raj <raj.khem at gmail.com>
Date:   Thu Apr  1 15:20:13 2010 -0700

contrib: Add scripts to run qemu

* These scripts are tested on ubuntu and should
  run on debian like systems.

* For networking to work it needs ethernet does
  not work on wireless.

Signed-off-by: Khem Raj <raj.khem at gmail.com>

---

 contrib/qemu/qemu-ifdown |    9 +++
 contrib/qemu/qemu-ifup   |   10 +++
 contrib/qemu/run-qemu.sh |  164 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 183 insertions(+), 0 deletions(-)

diff --git a/contrib/qemu/qemu-ifdown b/contrib/qemu/qemu-ifdown
new file mode 100755
index 0000000..204f298
--- /dev/null
+++ b/contrib/qemu/qemu-ifdown
@@ -0,0 +1,9 @@
+#!/bin/sh
+
+# NOTE: This script is intended to run in conjunction with qemu-ifup
+#       which uses the same logic to find your bridge/switch
+
+switch=$(/sbin/ip route list | awk '/^default / { print $5 }')
+
+sudo /usr/sbin/brctl delif $switch $1
+sudo /sbin/ifconfig $1 0.0.0.0 down
diff --git a/contrib/qemu/qemu-ifup b/contrib/qemu/qemu-ifup
new file mode 100755
index 0000000..34ae960
--- /dev/null
+++ b/contrib/qemu/qemu-ifup
@@ -0,0 +1,10 @@
+#!/bin/sh
+echo "executing qemu-ifup"
+sudo /sbin/modprobe tun # to network QEMU
+echo "bringing up $1 for bridged mode..."
+
+sudo /sbin/ifconfig $1 0.0.0.0 up
+bridge=$(/sbin/ip route list | /usr/bin/awk '/^default / { print $5 }')
+echo "adding $1 to $bridge ..."
+sudo /usr/sbin/brctl addif ${bridge} $1
+
diff --git a/contrib/qemu/run-qemu.sh b/contrib/qemu/run-qemu.sh
new file mode 100755
index 0000000..922d282
--- /dev/null
+++ b/contrib/qemu/run-qemu.sh
@@ -0,0 +1,164 @@
+#!/bin/sh
+# set -x
+# on debian-like systems
+# set up bridge aptitude install bridge-utils
+# 
+# change /etc/network/interfaces to something like below and restart
+# network
+
+#auto lo
+#iface lo inet loopback
+#
+#auto br0
+#iface br0 inet static
+#        address 10.0.1.37
+#        netmask 255.255.0.0
+#        gateway 10.0.0.1
+#        bridge_ports eth0
+#        bridge_maxwait 0
+#        bridge_fd 9
+#        bridge_stp off
+#
+#iface eth0 inet ipv4ll
+#
+#auto eth0
+
+supported_archs="{arm mips x86}"
+if [ $# -ne 1 ]; then
+    echo -en "
+    Usage: `basename $0` <arch>
+    where <arch> is one $supported_archs
+    Example: `basename $0` arm
+"
+    exit 1
+fi
+
+arch=$1
+case $arch in
+    arm)
+	address="10.0.1.101"
+        macaddr="00:16:3e:00:00:01"
+	machine="versatilepb"
+	gdbport="1234"
+	consoleopt="console=ttyAMA0 console=ttyS0"
+	rootdisk="sda"
+	qemu="qemu-system-arm"
+	libc="uclibc"
+        kernel="/scratch/oe/deploy/$libc/images/qemu$arch/zImage-qemuarm.bin"
+        hdimage="/scratch/oe/deploy/$libc/images/qemu$arch/native-sdk-image-qemuarm.ext2"
+        #hdimage="/scratch/oe/deploy/$libc/images/qemu$arch/console-image-qemuarm.ext2"
+        ;;
+    mips)
+	address="10.0.1.102"
+        macaddr="00:16:3e:00:00:02"
+	machine="malta"
+	gdbport="1235"
+        consoleopt="console=ttyS0"
+	rootdisk="hda"
+	qemu="qemu-system-mips"
+	libc="uclibc"
+        kernel="/scratch/oe/deploy/$libc/images/qemu$arch/vmlinux-qemumips.bin"
+        hdimage="/scratch/oe/deploy/$libc/images/qemu$arch/native-sdk-image-qemumips.ext2"
+        hdimage="/scratch/oe/deploy/$libc/images/qemu$arch/console-image-qemumips.ext2"
+        ;;
+    ppc|powerpc)
+    	arch=ppc
+	address="10.0.1.103"
+        macaddr="00:16:3e:00:00:03"
+	machine="bamboo"
+	gdbport="1236"
+        consoleopt="console=ttyS0"
+	rootdisk="hdc" #hdc4
+	qemu="qemu-system-ppcemb"
+	libc="eglibc"
+        kernel="/scratch/oe/deploy/$libc/images/qemu$arch/uImage-qemuppc.bin"
+        hdimage="/scratch/oe/deploy/$libc/images/qemu$arch/helloworld-image-qemuppc.ext2"
+        ;;
+    sh|sh4)
+    	arch=sh4
+	address="10.0.1.104"
+        macaddr="00:16:3e:00:00:04"
+	machine="r2d"
+	gdbport="1237"
+        #consoleopt="console=tty0 console=ttySC1"
+	rootdisk="sdc2" #hdc4
+	qemu="qemu-system-sh4 -serial vc -serial stdio"
+	#qemu="qemu-system-sh4"
+	libc="uclibc"
+        kernel="/scratch/oe/deploy/$libc/images/qemu$arch/zImage-qemush4.bin"
+        #kernel="/home/kraj/qemu/sh/sh-test-0.2/zImage"
+        hdimage="/scratch/oe/deploy/$libc/images/qemu$arch/console-image-qemush4.ext2"
+        #hdimage="/home/kraj/qemu/sh/sh-test-0.2/sh-linux-mini.img"
+        ;;
+    x86)
+	address="10.0.1.105"
+        macaddr="00:16:3e:00:00:05"
+	gdbport="1237"
+	machine="pc"
+        consoleopt="console=ttyS0"
+	rootdisk="hda"
+	qemu="qemu"
+	libc="uclibc"
+        kernel="/scratch/oe/deploy/$libc/images/qemu$arch/bzImage-qemux86.bin"
+        hdimage="/scratch/oe/deploy/$libc/images/qemu$arch/native-sdk-image-qemux86.ext2"
+        hdimage="/scratch/oe/deploy/$libc/images/qemu$arch/minimalist-image-qemux86.ext2"
+        hdimage="/scratch/oe/deploy/$libc/images/qemu$arch/console-image-qemux86.ext2"
+        ;;
+    *)
+        echo "Specify one architectures out of $supported_archs to emulate."
+   	exit 1
+    	;;
+    esac
+
+nfsserver="10.0.1.37"		# address of NFS server
+gateway="10.0.0.1"		# default gateway
+netmask="255.255.0.0"		# subnet mask
+hostname="qemu$arch"		# hostname for guest server
+nfsdir="/opt/oe/$hostname"	# nfs directory where root file system is
+device="eth0"			# interface that guest server will use
+mem=256				# memory for guest server in Mb
+gdbit="-gdb tcp::$gdbport"	# debug the kernel using gdb set it to -s
+				# add -S to stop after launch and wait for
+				# gdb to connect
+
+nfsopts="rsize=8192,wsize=8192,hard,intr,tcp,nolock"	# nfs options
+
+# for NFS root 
+rootfs="root=/dev/nfs rw nfsroot=$nfsserver:$nfsdir,$nfsopts"
+
+# Boot from a Disk Image
+
+rootfs="root=/dev/$rootdisk rw"
+
+# ip format
+#ip=<client-ip>:<server-ip>:<gw-ip>:<netmask>:<hostname>:<device>:<autoconf>
+ipopt="ip=$address::$gateway:$netmask:$hostname:$device:off"
+
+# get IP from DHCP server on network
+#ipopt="ip=dhcp"
+
+init=""
+qemuifup="/home/kraj/work/oe/openembedded/contrib/qemu/qemu-ifup"
+qemuifdown="/home/kraj/work/oe/openembedded/contrib/qemu/qemu-ifdown"
+
+uid=`whoami`
+iface=`sudo tunctl -b -u $uid`
+
+netopt="-net nic,vlan=0,macaddr=$macaddr -net tap,vlan=0,ifname=$iface,script=$qemuifup,downscript=$qemuifdown"
+
+if [ "x$1" == "xsingle" ]
+then
+    init="init=/bin/sh"
+fi
+echo "Starting QEMU ..."
+set -x
+	#-L /scratch/oe/deploy/$libc/images/qemu$arch \
+$qemu -M $machine --snapshot $gdbit -m $mem -kernel $kernel -hda $hdimage \
+	-usb -usbdevice wacom-tablet -nographic --no-reboot -localtime \
+	-append "$consoleopt $rootfs $ipopt $init debug user_debug=-1" \
+	$netopt
+set +x
+#destroy the tap interface
+sudo tunctl -b -d $iface
+stty sane
+# qemu-system-sh4 -M r2d -kernel ~/zImage -nographic -monitor null -serial null -serial stdio  





More information about the Openembedded-commits mailing list