diff options
author | Scott Garman <scott.a.garman@intel.com> | 2010-10-04 21:04:15 -0700 |
---|---|---|
committer | Richard Purdie <rpurdie@linux.intel.com> | 2010-10-07 19:57:34 +0100 |
commit | 0f973ed66551cdd1112ee9df42df5603835b8384 (patch) | |
tree | 753442dd27a029749846a718353e1fba02a09e49 /scripts/poky-qemu | |
parent | e70c8981f250ead9e025ecd27aef94b67d784fc6 (diff) | |
download | poky-0f973ed66551cdd1112ee9df42df5603835b8384.tar.gz |
Merge runqemu features into poky-qemu
This merges the functionality of the runqemu script into poky-qemu.
It also removes the requirement to order command line args to poky-qemu
in any particular order.
This fixes a slew of runqemu-related bugs by making the runqemu script
obsolete (and fixing the issues in the new poky-qemu), including
[BUGID #294] [BUGID #295] [BUGID #371] and [BUGID #324].
Signed-off-by: Scott Garman <scott.a.garman@intel.com>
Diffstat (limited to 'scripts/poky-qemu')
-rwxr-xr-x | scripts/poky-qemu | 280 |
1 files changed, 250 insertions, 30 deletions
diff --git a/scripts/poky-qemu b/scripts/poky-qemu index 111aa15b70..ad4bdbf91c 100755 --- a/scripts/poky-qemu +++ b/scripts/poky-qemu | |||
@@ -1,8 +1,8 @@ | |||
1 | #!/bin/bash | 1 | #!/bin/bash |
2 | 2 | # | |
3 | # Handle running Poky images standalone with QEMU | 3 | # Handle running Poky images standalone with QEMU |
4 | # | 4 | # |
5 | # Copyright (C) 2006-2007 OpenedHand Ltd. | 5 | # Copyright (C) 2006-2010 Intel Corp. |
6 | # | 6 | # |
7 | # This program is free software; you can redistribute it and/or modify | 7 | # This program is free software; you can redistribute it and/or modify |
8 | # it under the terms of the GNU General Public License version 2 as | 8 | # it under the terms of the GNU General Public License version 2 as |
@@ -17,47 +17,267 @@ | |||
17 | # with this program; if not, write to the Free Software Foundation, Inc., | 17 | # with this program; if not, write to the Free Software Foundation, Inc., |
18 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | 18 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
19 | 19 | ||
20 | 20 | usage() { | |
21 | if [ "x$1" = "x" ]; then | ||
22 | MYNAME=`basename $0` | 21 | MYNAME=`basename $0` |
23 | echo "Run as MACHINE=xyz $MYNAME KERNEL ROOTFS [OPTIONS]" | 22 | echo "" |
24 | echo "where:" | 23 | echo "Usage: you can run this script with any valid combination" |
24 | echo "of the following options (in any order):" | ||
25 | echo " QEMUARCH - the qemu machine architecture to use" | ||
25 | echo " KERNEL - the kernel image file to use" | 26 | echo " KERNEL - the kernel image file to use" |
26 | echo " ROOTFS - the rootfs image file or nfsroot directory to use" | 27 | echo " ROOTFS - the rootfs image file or nfsroot directory to use" |
27 | # echo " (NFS booting assumed if ROOTFS not specified)" | ||
28 | echo " MACHINE=xyz - the machine name (optional, autodetected from KERNEL filename if unspecified)" | 28 | echo " MACHINE=xyz - the machine name (optional, autodetected from KERNEL filename if unspecified)" |
29 | echo " OPTIONS - extra options to pass to QEMU" | 29 | echo " Additional QEMU command-line options can be passed with:" |
30 | echo " serial - enables a serial console on /dev/ttyS0" | ||
31 | echo "" | ||
32 | echo "Examples:" | ||
33 | echo " $0 qemuarm" | ||
34 | echo " $0 qemux86-64 poky-image-sato ext3" | ||
35 | echo " $0 path/to/bzImage-qemux86.bin path/to/nfsrootdir/ serial" | ||
30 | exit 1 | 36 | exit 1 |
31 | else | 37 | } |
32 | KERNEL=$1 | 38 | |
33 | shift | 39 | if [ "x$1" = "x" ]; then |
40 | usage | ||
34 | fi | 41 | fi |
35 | 42 | ||
36 | if [ "x$MACHINE" = "x" ]; then | 43 | MACHINE=${MACHINE:=""} |
44 | KERNEL="" | ||
45 | FSTYPE="" | ||
46 | ROOTFS="" | ||
47 | SCRIPT_QEMU_OPT="" | ||
48 | SCRIPT_KERNEL_OPT="" | ||
49 | |||
50 | TMPDIR="" | ||
51 | |||
52 | # Parse command line args without requiring specific ordering. It's a | ||
53 | # bit more complex, but offers a great user experience. | ||
54 | i=1 | ||
55 | while [ $i -le $# ]; do | ||
56 | arg=${!i} | ||
57 | case $arg in | ||
58 | "qemux86" | "qemux86-64" | "qemuarm" | "qemumips" | "qemuppc") | ||
59 | if [ -z "$MACHINE" ]; then | ||
60 | MACHINE=$arg | ||
61 | else | ||
62 | echo "Error: conflicting MACHINE types [$MACHINE] and [$arg]" | ||
63 | usage | ||
64 | fi | ||
65 | ;; | ||
66 | "ext2" | "ext3" | "jffs2" | "nfs") | ||
67 | if [ -z "$FSTYPE" ]; then | ||
68 | FSTYPE=$arg | ||
69 | else | ||
70 | echo "Error: conflicting FSTYPE types [$FSTYPE] and [$arg]" | ||
71 | usage | ||
72 | fi | ||
73 | ;; | ||
74 | *-image-*) | ||
75 | if [ -z "$ROOTFS" ]; then | ||
76 | ROOTFS=$arg | ||
77 | else | ||
78 | echo "Error: conflicting ROOTFS args [$ROOTFS] and [$arg]" | ||
79 | usage | ||
80 | fi | ||
81 | ;; | ||
82 | "serial") | ||
83 | # Will need to append to these variables when we | ||
84 | # accept more values | ||
85 | SCRIPT_QEMU_OPT="-serial stdio" | ||
86 | SCRIPT_KERNEL_OPT="console=ttyS0" | ||
87 | ;; | ||
88 | *) | ||
89 | # A directory name is an nfs rootfs | ||
90 | if [ -d "$arg" ]; then | ||
91 | echo "Assuming $arg is an nfs rootfs" | ||
92 | if [[ -z "$FSTYPE" || "$FSTYPE" == "nfs" ]]; then | ||
93 | FSTYPE=nfs | ||
94 | else | ||
95 | echo "Error: conflicting FSTYPE types [$arg] and nfs" | ||
96 | usage | ||
97 | fi | ||
98 | |||
99 | if [ -z "$ROOTFS" ]; then | ||
100 | ROOTFS=$arg | ||
101 | else | ||
102 | echo "Error: conflicting ROOTFS args [$ROOTFS] and [$arg]" | ||
103 | usage | ||
104 | fi | ||
105 | elif [ -f "$arg" ]; then | ||
106 | # Extract the filename extension | ||
107 | EXT=`echo $arg | awk -F . '{ print \$NF }'` | ||
108 | # A file ending in .bin is a kernel | ||
109 | if [ "x$EXT" = "xbin" ]; then | ||
110 | if [ -z "$KERNEL" ]; then | ||
111 | KERNEL=$arg | ||
112 | else | ||
113 | echo "Error: conflicting KERNEL args [$KERNEL] and [$arg]" | ||
114 | usage | ||
115 | fi | ||
116 | elif [[ "x$EXT" == "xext2" || "x$EXT" == "xext3" || | ||
117 | "x$EXT" == "xjffs2" ]]; then | ||
118 | # A file ending in a supportted fs type is a rootfs image | ||
119 | if [[ -z "$FSTYPE" || "$FSTYPE" == "$EXT" ]]; then | ||
120 | FSTYPE=$EXT | ||
121 | ROOTFS=$arg | ||
122 | else | ||
123 | echo "Error: conflicting FSTYPE types [$FSTYPE] and [$arg]" | ||
124 | usage | ||
125 | fi | ||
126 | else | ||
127 | echo "Error: unknown file arg [$arg]" | ||
128 | usage | ||
129 | fi | ||
130 | else | ||
131 | echo "Error: unable to classify arg [$arg]" | ||
132 | usage | ||
133 | fi | ||
134 | ;; | ||
135 | esac | ||
136 | i=$((i + 1)) | ||
137 | done | ||
138 | |||
139 | # Report errors for missing combinations of options | ||
140 | if [[ -z "$MACHINE" && -z "$KERNEL" ]]; then | ||
141 | echo "Error: you must specify at least a MACHINE or KERNEL argument" | ||
142 | usage | ||
143 | fi | ||
144 | if [[ "$FSTYPE" == "nfs" && -z "$ROOTFS" ]]; then | ||
145 | echo "Error: NFS booting without an explicit ROOTFS path is not yet supported" | ||
146 | usage | ||
147 | fi | ||
148 | |||
149 | if [ -z "$MACHINE" ]; then | ||
37 | MACHINE=`basename $KERNEL | sed -r -e 's#.*-([a-z]+[0-9\-]*)-?[0-9]*..*#\1#'` | 150 | MACHINE=`basename $KERNEL | sed -r -e 's#.*-([a-z]+[0-9\-]*)-?[0-9]*..*#\1#'` |
151 | if [ -z "$MACHINE" ]; then | ||
152 | echo "Error: Unable to set MACHINE from kernel filename [$KERNEL]" | ||
153 | usage | ||
154 | fi | ||
155 | echo "Set MACHINE to [$MACHINE] based on kernel [$KERNEL]" | ||
38 | fi | 156 | fi |
157 | machine2=`echo $MACHINE | tr 'a-z' 'A-Z' | sed 's/-/_/'` | ||
158 | # MACHINE is now set for all cases | ||
39 | 159 | ||
40 | if [ "x$1" = "x" ]; then | 160 | # Defaults used when these vars need to be inferred |
41 | FSTYPE="nfs" | 161 | QEMUX86_DEFAULT_KERNEL=bzImage-qemux86.bin |
42 | echo "Error: NFS booting without an explicit ROOTFS path is not yet supported" | 162 | QEMUX86_DEFAULT_FSTYPE=ext3 |
43 | exit 1 | 163 | QEMUX86_DEFAULT_ROOTFS="poky-image-sdk poky-image-sato poky-image-lsb poky-image-basic poky-image-minimal" |
44 | else | 164 | |
45 | ROOTFS=$1 | 165 | QEMUX86_64_DEFAULT_KERNEL=bzImage-qemux86-64.bin |
46 | 166 | QEMUX86_64_DEFAULT_FSTYPE=ext3 | |
47 | if [ -d "$1" ]; then | 167 | QEMUX86_64_DEFAULT_ROOTFS="poky-image-sdk poky-image-sato poky-image-lsb poky-image-basic poky-image-minimal" |
48 | echo "$ROOTFS is a directory, assuming nfsroot" | 168 | |
49 | FSTYPE="nfs" | 169 | QEMUARM_DEFAULT_KERNEL=zImage-qemuarm.bin |
50 | else | 170 | QEMUARM_DEFAULT_FSTYPE=ext3 |
51 | FSTYPE="ext3" | 171 | QEMUARM_DEFAULT_ROOTFS="poky-image-sdk poky-image-sato poky-image-lsb poky-image-basic poky-image-minimal" |
52 | EXT=${ROOTFS##.*} | 172 | |
53 | if [[ "x$EXT" == "xext2" || "x$EXT" == "xext3" || | 173 | QEMUMIPS_DEFAULT_KERNEL=vmlinux-qemumips.bin |
54 | "x$EXT" == "xjffs2" ]]; then | 174 | QEMUMIPS_DEFAULT_FSTYPE=ext3 |
55 | FSTYPE=$EXT | 175 | QEMUMIPS_DEFAULT_ROOTFS="poky-image-sdk poky-image-sato poky-image-lsb poky-image-basic poky-image-minimal" |
176 | |||
177 | QEMUPPC_DEFAULT_KERNEL=zImage-qemuppc.bin | ||
178 | QEMUPPC_DEFAULT_FSTYPE=ext3 | ||
179 | QEMUPPC_DEFAULT_ROOTFS="poky-image-sdk poky-image-sato poky-image-lsb poky-image-basic poky-image-minimal" | ||
180 | |||
181 | AKITA_DEFAULT_KERNEL=zImage-akita.bin | ||
182 | AKITA_DEFAULT_FSTYPE=jffs2 | ||
183 | AKITA_DEFAULT_ROOTFS="poky-image-sato" | ||
184 | |||
185 | SPITZ_DEFAULT_KERNEL=zImage-spitz.bin | ||
186 | SPITZ_DEFAULT_FSTYPE=ext3 | ||
187 | SPITZ_DEFAULT_ROOTFS="poky-image-sato" | ||
188 | |||
189 | setup_tmpdir() { | ||
190 | if [ -z "$TMPDIR" ]; then | ||
191 | if [ "x$BUILDDIR" = "x" ]; then | ||
192 | # BUILDDIR unset, try and get TMPDIR from bitbake | ||
193 | type -P bitbake &>/dev/null || { | ||
194 | echo "In order for this script to dynamically infer paths"; | ||
195 | echo "to kernels or filesystem images, you either need"; | ||
196 | echo "bitbake in your PATH or to source poky-init-build-env"; | ||
197 | echo "before running this script" >&2; | ||
198 | exit 1; } | ||
199 | |||
200 | # We have bitbake in PATH, get TMPDIR and BUILD_SYS | ||
201 | # from the environment | ||
202 | TMPDIR=`bitbake -e | grep TMPDIR=\" | cut -d '=' -f2 | cut -d '"' -f2` | ||
203 | BUILD_SYS=`bitbake -e | grep BUILD_SYS=\" | cut -d '=' -f2 | cut -d '"' -f2` | ||
204 | else | ||
205 | BUILD_ARCH=`uname -m` | ||
206 | BUILD_OS=`uname | tr '[A-Z]' '[a-z]'` | ||
207 | BUILD_SYS="$BUILD_ARCH-$BUILD_OS" | ||
208 | TMPDIR=$BUILDDIR/tmp | ||
56 | fi | 209 | fi |
57 | echo "Using $FSTYPE as filesytem type for $ROOTFS" | 210 | if [ -z "$POKY_NATIVE_SYSROOT" ]; then |
211 | POKY_NATIVE_SYSROOT=$TMPDIR/sysroots/$BUILD_SYS | ||
212 | fi | ||
213 | CROSSPATH=$POKY_NATIVE_SYSROOT/usr/bin | ||
214 | fi | ||
215 | } | ||
216 | |||
217 | # Locate a rootfs image based on defaults defined above | ||
218 | findimage() { | ||
219 | where=$1 | ||
220 | machine=$2 | ||
221 | extension=$3 | ||
222 | names=$4 | ||
223 | |||
224 | for name in $names; do | ||
225 | fullname=$where/$name-$machine.$extension | ||
226 | if [ -e "$fullname" ]; then | ||
227 | ROOTFS=$fullname | ||
228 | return | ||
229 | fi | ||
230 | done | ||
231 | |||
232 | echo "Couldn't find image in $where. Attempted image names were:" | ||
233 | for name in $names; do | ||
234 | echo $name-$machine.$extension | ||
235 | done | ||
236 | |||
237 | exit 1 | ||
238 | } | ||
239 | |||
240 | if [ -z "$KERNEL" ]; then | ||
241 | setup_tmpdir | ||
242 | eval kernel_file=\$${machine2}_DEFAULT_KERNEL | ||
243 | KERNEL=$TMPDIR/deploy/images/$kernel_file | ||
244 | |||
245 | if [ -z "$KERNEL" ]; then | ||
246 | echo "Error: Unable to determine default kernel for MACHINE [$MACHINE]" | ||
247 | usage | ||
248 | fi | ||
249 | fi | ||
250 | # KERNEL is now set for all cases | ||
251 | |||
252 | if [ -z "$FSTYPE" ]; then | ||
253 | setup_tmpdir | ||
254 | eval FSTYPE=\$${machine2}_DEFAULT_FSTYPE | ||
255 | |||
256 | if [ -z "$FSTYPE" ]; then | ||
257 | echo "Error: Unable to determine default fstype for MACHINE [$MACHINE]" | ||
258 | usage | ||
58 | fi | 259 | fi |
59 | shift | ||
60 | fi | 260 | fi |
261 | # FSTYPE is now set for all cases | ||
262 | |||
263 | if [ -z "$ROOTFS" ]; then | ||
264 | setup_tmpdir | ||
265 | T=$TMPDIR/deploy/images | ||
266 | eval rootfs_list=\$${machine2}_DEFAULT_ROOTFS | ||
267 | findimage $T $MACHINE $FSTYPE "$rootfs_list" | ||
268 | |||
269 | if [ -z "$ROOTFS" ]; then | ||
270 | echo "Error: Unable to determine default rootfs for MACHINE [$MACHINE]" | ||
271 | usage | ||
272 | fi | ||
273 | fi | ||
274 | # ROOTFS is now set for all cases | ||
275 | |||
276 | echo "" | ||
277 | echo "Continuing with the following parameters:" | ||
278 | echo "KERNEL: [$KERNEL]" | ||
279 | echo "ROOTFS: [$ROOTFS]" | ||
280 | echo "FSTYPE: [$FSTYPE]" | ||
61 | 281 | ||
62 | # We can't run without a libGL.so | 282 | # We can't run without a libGL.so |
63 | libgl='no' | 283 | libgl='no' |