contrib: Add scripts to run qemu
[openembedded.git] / contrib / qemu / run-qemu.sh
1 #!/bin/sh
2 # set -x
3 # on debian-like systems
4 # set up bridge aptitude install bridge-utils
5
6 # change /etc/network/interfaces to something like below and restart
7 # network
8
9 #auto lo
10 #iface lo inet loopback
11 #
12 #auto br0
13 #iface br0 inet static
14 #        address 10.0.1.37
15 #        netmask 255.255.0.0
16 #        gateway 10.0.0.1
17 #        bridge_ports eth0
18 #        bridge_maxwait 0
19 #        bridge_fd 9
20 #        bridge_stp off
21 #
22 #iface eth0 inet ipv4ll
23 #
24 #auto eth0
25
26 supported_archs="{arm mips x86}"
27 if [ $# -ne 1 ]; then
28     echo -en "
29     Usage: `basename $0` <arch>
30     where <arch> is one $supported_archs
31     Example: `basename $0` arm
32 "
33     exit 1
34 fi
35
36 arch=$1
37 case $arch in
38     arm)
39         address="10.0.1.101"
40         macaddr="00:16:3e:00:00:01"
41         machine="versatilepb"
42         gdbport="1234"
43         consoleopt="console=ttyAMA0 console=ttyS0"
44         rootdisk="sda"
45         qemu="qemu-system-arm"
46         libc="uclibc"
47         kernel="/scratch/oe/deploy/$libc/images/qemu$arch/zImage-qemuarm.bin"
48         hdimage="/scratch/oe/deploy/$libc/images/qemu$arch/native-sdk-image-qemuarm.ext2"
49         #hdimage="/scratch/oe/deploy/$libc/images/qemu$arch/console-image-qemuarm.ext2"
50         ;;
51     mips)
52         address="10.0.1.102"
53         macaddr="00:16:3e:00:00:02"
54         machine="malta"
55         gdbport="1235"
56         consoleopt="console=ttyS0"
57         rootdisk="hda"
58         qemu="qemu-system-mips"
59         libc="uclibc"
60         kernel="/scratch/oe/deploy/$libc/images/qemu$arch/vmlinux-qemumips.bin"
61         hdimage="/scratch/oe/deploy/$libc/images/qemu$arch/native-sdk-image-qemumips.ext2"
62         hdimage="/scratch/oe/deploy/$libc/images/qemu$arch/console-image-qemumips.ext2"
63         ;;
64     ppc|powerpc)
65         arch=ppc
66         address="10.0.1.103"
67         macaddr="00:16:3e:00:00:03"
68         machine="bamboo"
69         gdbport="1236"
70         consoleopt="console=ttyS0"
71         rootdisk="hdc" #hdc4
72         qemu="qemu-system-ppcemb"
73         libc="eglibc"
74         kernel="/scratch/oe/deploy/$libc/images/qemu$arch/uImage-qemuppc.bin"
75         hdimage="/scratch/oe/deploy/$libc/images/qemu$arch/helloworld-image-qemuppc.ext2"
76         ;;
77     sh|sh4)
78         arch=sh4
79         address="10.0.1.104"
80         macaddr="00:16:3e:00:00:04"
81         machine="r2d"
82         gdbport="1237"
83         #consoleopt="console=tty0 console=ttySC1"
84         rootdisk="sdc2" #hdc4
85         qemu="qemu-system-sh4 -serial vc -serial stdio"
86         #qemu="qemu-system-sh4"
87         libc="uclibc"
88         kernel="/scratch/oe/deploy/$libc/images/qemu$arch/zImage-qemush4.bin"
89         #kernel="/home/kraj/qemu/sh/sh-test-0.2/zImage"
90         hdimage="/scratch/oe/deploy/$libc/images/qemu$arch/console-image-qemush4.ext2"
91         #hdimage="/home/kraj/qemu/sh/sh-test-0.2/sh-linux-mini.img"
92         ;;
93     x86)
94         address="10.0.1.105"
95         macaddr="00:16:3e:00:00:05"
96         gdbport="1237"
97         machine="pc"
98         consoleopt="console=ttyS0"
99         rootdisk="hda"
100         qemu="qemu"
101         libc="uclibc"
102         kernel="/scratch/oe/deploy/$libc/images/qemu$arch/bzImage-qemux86.bin"
103         hdimage="/scratch/oe/deploy/$libc/images/qemu$arch/native-sdk-image-qemux86.ext2"
104         hdimage="/scratch/oe/deploy/$libc/images/qemu$arch/minimalist-image-qemux86.ext2"
105         hdimage="/scratch/oe/deploy/$libc/images/qemu$arch/console-image-qemux86.ext2"
106         ;;
107     *)
108         echo "Specify one architectures out of $supported_archs to emulate."
109         exit 1
110         ;;
111     esac
112
113 nfsserver="10.0.1.37"           # address of NFS server
114 gateway="10.0.0.1"              # default gateway
115 netmask="255.255.0.0"           # subnet mask
116 hostname="qemu$arch"            # hostname for guest server
117 nfsdir="/opt/oe/$hostname"      # nfs directory where root file system is
118 device="eth0"                   # interface that guest server will use
119 mem=256                         # memory for guest server in Mb
120 gdbit="-gdb tcp::$gdbport"      # debug the kernel using gdb set it to -s
121                                 # add -S to stop after launch and wait for
122                                 # gdb to connect
123
124 nfsopts="rsize=8192,wsize=8192,hard,intr,tcp,nolock"    # nfs options
125
126 # for NFS root 
127 rootfs="root=/dev/nfs rw nfsroot=$nfsserver:$nfsdir,$nfsopts"
128
129 # Boot from a Disk Image
130
131 rootfs="root=/dev/$rootdisk rw"
132
133 # ip format
134 #ip=<client-ip>:<server-ip>:<gw-ip>:<netmask>:<hostname>:<device>:<autoconf>
135 ipopt="ip=$address::$gateway:$netmask:$hostname:$device:off"
136
137 # get IP from DHCP server on network
138 #ipopt="ip=dhcp"
139
140 init=""
141 qemuifup="/home/kraj/work/oe/openembedded/contrib/qemu/qemu-ifup"
142 qemuifdown="/home/kraj/work/oe/openembedded/contrib/qemu/qemu-ifdown"
143
144 uid=`whoami`
145 iface=`sudo tunctl -b -u $uid`
146
147 netopt="-net nic,vlan=0,macaddr=$macaddr -net tap,vlan=0,ifname=$iface,script=$qemuifup,downscript=$qemuifdown"
148
149 if [ "x$1" == "xsingle" ]
150 then
151     init="init=/bin/sh"
152 fi
153 echo "Starting QEMU ..."
154 set -x
155         #-L /scratch/oe/deploy/$libc/images/qemu$arch \
156 $qemu -M $machine --snapshot $gdbit -m $mem -kernel $kernel -hda $hdimage \
157         -usb -usbdevice wacom-tablet -nographic --no-reboot -localtime \
158         -append "$consoleopt $rootfs $ipopt $init debug user_debug=-1" \
159         $netopt
160 set +x
161 #destroy the tap interface
162 sudo tunctl -b -d $iface
163 stty sane
164 # qemu-system-sh4 -M r2d -kernel ~/zImage -nographic -monitor null -serial null -serial stdio