Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # Handle running OE images standalone with QEMU |
| 4 | # |
| 5 | # Copyright (C) 2006-2011 Linux Foundation |
| 6 | # |
| 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 |
| 9 | # published by the Free Software Foundation. |
| 10 | # |
| 11 | # This program is distributed in the hope that it will be useful, |
| 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | # GNU General Public License for more details. |
| 15 | # |
| 16 | # You should have received a copy of the GNU General Public License along |
| 17 | # with this program; if not, write to the Free Software Foundation, Inc., |
| 18 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 19 | |
| 20 | usage() { |
| 21 | MYNAME=`basename $0` |
| 22 | echo "" |
| 23 | echo "Usage: you can run this script with any valid combination" |
| 24 | echo "of the following environment variables (in any order):" |
| 25 | echo " QEMUARCH - the qemu machine architecture to use" |
| 26 | echo " KERNEL - the kernel image file to use" |
| 27 | echo " ROOTFS - the rootfs image file or nfsroot directory to use" |
| 28 | echo " MACHINE - the machine name (optional, autodetected from KERNEL filename if unspecified)" |
| 29 | echo " RAMFS - boot a ramfs-based image" |
| 30 | echo " ISO - boot an ISO image" |
| 31 | echo " VM - boot a virtual machine image (= a file representing a full disk with boot loader)" |
| 32 | echo " Simplified QEMU command-line options can be passed with:" |
| 33 | echo " nographic - disables video console" |
| 34 | echo " serial - enables a serial console on /dev/ttyS0" |
| 35 | echo " kvm - enables KVM when running qemux86/qemux86-64 (VT-capable CPU required)" |
| 36 | echo " publicvnc - enable a VNC server open to all hosts" |
| 37 | echo " qemuparams=\"xyz\" - specify custom parameters to QEMU" |
| 38 | echo " bootparams=\"xyz\" - specify custom kernel parameters during boot" |
| 39 | echo "" |
| 40 | echo "Examples:" |
| 41 | echo " $MYNAME qemuarm" |
| 42 | echo " $MYNAME qemux86-64 core-image-sato ext4" |
| 43 | echo " $MYNAME path/to/bzImage-qemux86.bin path/to/nfsrootdir/ serial" |
| 44 | echo " $MYNAME qemux86 ramfs" |
| 45 | echo " $MYNAME qemux86 iso" |
| 46 | echo " $MYNAME qemux86 qemuparams=\"-m 256\"" |
| 47 | echo " $MYNAME qemux86 bootparams=\"psplash=false\"" |
| 48 | echo " $MYNAME path/to/<image>-<machine>.vmdk" |
| 49 | exit 1 |
| 50 | } |
| 51 | |
| 52 | if [ "x$1" = "x" ]; then |
| 53 | usage |
| 54 | fi |
| 55 | |
| 56 | error() { |
| 57 | echo "Error: "$* |
| 58 | usage |
| 59 | } |
| 60 | |
| 61 | MACHINE=${MACHINE:=""} |
| 62 | KERNEL=${KERNEL:=""} |
| 63 | ROOTFS=${ROOTFS:=""} |
| 64 | VM=${VM:=""} |
| 65 | FSTYPE=${FSTYPE:=""} |
| 66 | LAZY_ROOTFS="" |
| 67 | SCRIPT_QEMU_OPT="" |
| 68 | SCRIPT_QEMU_EXTRA_OPT="" |
| 69 | SCRIPT_KERNEL_OPT="" |
| 70 | SERIALSTDIO="" |
| 71 | TCPSERIAL_PORTNUM="" |
| 72 | KVM_ENABLED="no" |
| 73 | KVM_ACTIVE="no" |
| 74 | |
| 75 | # Determine whether the file is a kernel or QEMU image, and set the |
| 76 | # appropriate variables |
| 77 | process_filename() { |
| 78 | filename=$1 |
| 79 | |
| 80 | # Extract the filename extension |
| 81 | EXT=`echo $filename | awk -F . '{ print \$NF }'` |
| 82 | case /$EXT/ in |
| 83 | /bin/) |
| 84 | # A file ending in .bin is a kernel |
| 85 | [ -z "$KERNEL" ] && KERNEL=$filename || \ |
| 86 | error "conflicting KERNEL args [$KERNEL] and [$filename]" |
| 87 | ;; |
| 88 | /ext[234]/|/jffs2/|/btrfs/) |
| 89 | # A file ending in a supportted fs type is a rootfs image |
| 90 | if [ -z "$FSTYPE" -o "$FSTYPE" = "$EXT" ]; then |
| 91 | FSTYPE=$EXT |
| 92 | ROOTFS=$filename |
| 93 | else |
| 94 | error "conflicting FSTYPE types [$FSTYPE] and [$EXT]" |
| 95 | fi |
| 96 | ;; |
| 97 | /hddimg/|/hdddirect/|/vmdk/) |
| 98 | FSTYPE=$EXT |
| 99 | VM=$filename |
| 100 | ;; |
| 101 | *) |
| 102 | error "unknown file arg [$filename]" |
| 103 | ;; |
| 104 | esac |
| 105 | } |
| 106 | |
| 107 | # Parse command line args without requiring specific ordering. It's a |
| 108 | # bit more complex, but offers a great user experience. |
| 109 | while true; do |
| 110 | arg=${1} |
| 111 | case "$arg" in |
| 112 | "qemux86" | "qemux86-64" | "qemuarm" | "qemuarm64" | "qemumips" | "qemumipsel" | \ |
| 113 | "qemumips64" | "qemush4" | "qemuppc" | "qemumicroblaze" | "qemuzynq") |
| 114 | [ -z "$MACHINE" ] && MACHINE=$arg || \ |
| 115 | error "conflicting MACHINE types [$MACHINE] and [$arg]" |
| 116 | ;; |
| 117 | "ext2" | "ext3" | "ext4" | "jffs2" | "nfs" | "btrfs" | "hddimg" | "hdddirect" ) |
| 118 | [ -z "$FSTYPE" -o "$FSTYPE" = "$arg" ] && FSTYPE=$arg || \ |
| 119 | error "conflicting FSTYPE types [$FSTYPE] and [$arg]" |
| 120 | ;; |
| 121 | "ramfs") |
| 122 | FSTYPE=cpio.gz |
| 123 | RAMFS=true |
| 124 | ;; |
| 125 | "iso") |
| 126 | FSTYPE=iso |
| 127 | ISOFS=true |
| 128 | ;; |
| 129 | "nographic") |
| 130 | SCRIPT_QEMU_OPT="$SCRIPT_QEMU_OPT -nographic" |
| 131 | SCRIPT_KERNEL_OPT="$SCRIPT_KERNEL_OPT console=ttyS0" |
| 132 | ;; |
| 133 | "serial") |
| 134 | SCRIPT_QEMU_OPT="$SCRIPT_QEMU_OPT -serial stdio" |
| 135 | SCRIPT_KERNEL_OPT="$SCRIPT_KERNEL_OPT console=ttyS0" |
| 136 | SERIALSTDIO="1" |
| 137 | ;; |
| 138 | "tcpserial="*) |
| 139 | TCPSERIAL_PORTNUM=${arg##tcpserial=} |
| 140 | ;; |
| 141 | "biosdir="*) |
| 142 | CUSTOMBIOSDIR="${arg##biosdir=}" |
| 143 | ;; |
| 144 | "biosfilename="*) |
| 145 | SCRIPT_QEMU_OPT="$SCRIPT_QEMU_OPT -bios ${arg##biosfilename=}" |
| 146 | ;; |
| 147 | "qemuparams="*) |
| 148 | SCRIPT_QEMU_EXTRA_OPT="${arg##qemuparams=}" |
| 149 | |
| 150 | # Warn user if they try to specify serial or kvm options |
| 151 | # to use simplified options instead |
| 152 | serial_option=`expr "$SCRIPT_QEMU_EXTRA_OPT" : '.*\(-serial\)'` |
| 153 | kvm_option=`expr "$SCRIPT_QEMU_EXTRA_OPT" : '.*\(-enable-kvm\)'` |
| 154 | vga_option=`expr "$SCRIPT_QEMU_EXTRA_OPT" : '.*\(-vga\)'` |
| 155 | [ ! -z "$serial_option" -o ! -z "$kvm_option" ] && \ |
| 156 | echo "Please use simplified serial or kvm options instead" |
| 157 | ;; |
| 158 | "bootparams="*) |
| 159 | SCRIPT_KERNEL_OPT="$SCRIPT_KERNEL_OPT ${arg##bootparams=}" |
| 160 | ;; |
| 161 | "audio") |
| 162 | if [ "x$MACHINE" = "xqemux86" -o "x$MACHINE" = "xqemux86-64" ]; then |
| 163 | echo "Enabling audio in qemu." |
| 164 | echo "Please install snd_intel8x0 or snd_ens1370 driver in linux guest." |
| 165 | QEMU_AUDIO_DRV="alsa" |
| 166 | SCRIPT_QEMU_OPT="$SCRIPT_QEMU_OPT -soundhw ac97,es1370" |
| 167 | fi |
| 168 | ;; |
| 169 | "kvm") |
| 170 | KVM_ENABLED="yes" |
| 171 | KVM_CAPABLE=`grep -q 'vmx\|svm' /proc/cpuinfo && echo 1` |
| 172 | ;; |
| 173 | "slirp") |
| 174 | SLIRP_ENABLED="yes" |
| 175 | ;; |
| 176 | "publicvnc") |
| 177 | SCRIPT_QEMU_OPT="$SCRIPT_QEMU_OPT -vnc 0.0.0.0:0" |
| 178 | ;; |
| 179 | *-image*) |
| 180 | [ -z "$ROOTFS" ] || \ |
| 181 | error "conflicting ROOTFS args [$ROOTFS] and [$arg]" |
| 182 | if [ -f "$arg" ]; then |
| 183 | process_filename $arg |
| 184 | elif [ -d "$arg" ]; then |
| 185 | # Handle the case where the nfsroot dir has -image- |
| 186 | # in the pathname |
| 187 | echo "Assuming $arg is an nfs rootfs" |
| 188 | FSTYPE=nfs |
| 189 | ROOTFS=$arg |
| 190 | else |
| 191 | ROOTFS=$arg |
| 192 | LAZY_ROOTFS="true" |
| 193 | fi |
| 194 | ;; |
| 195 | "") break ;; |
| 196 | *) |
| 197 | # A directory name is an nfs rootfs |
| 198 | if [ -d "$arg" ]; then |
| 199 | echo "Assuming $arg is an nfs rootfs" |
| 200 | if [ -z "$FSTYPE" -o "$FSTYPE" = "nfs" ]; then |
| 201 | FSTYPE=nfs |
| 202 | else |
| 203 | error "conflicting FSTYPE types [$arg] and nfs" |
| 204 | fi |
| 205 | |
| 206 | if [ -z "$ROOTFS" ]; then |
| 207 | ROOTFS=$arg |
| 208 | else |
| 209 | error "conflicting ROOTFS args [$ROOTFS] and [$arg]" |
| 210 | fi |
| 211 | elif [ -f "$arg" ]; then |
| 212 | process_filename $arg |
| 213 | else |
| 214 | error "unable to classify arg [$arg]" |
| 215 | fi |
| 216 | ;; |
| 217 | esac |
| 218 | shift |
| 219 | done |
| 220 | |
| 221 | if [ ! -c /dev/net/tun ] ; then |
| 222 | echo "TUN control device /dev/net/tun is unavailable; you may need to enable TUN (e.g. sudo modprobe tun)" |
| 223 | exit 1 |
| 224 | elif [ ! -w /dev/net/tun ] ; then |
| 225 | echo "TUN control device /dev/net/tun is not writable, please fix (e.g. sudo chmod 666 /dev/net/tun)" |
| 226 | exit 1 |
| 227 | fi |
| 228 | |
| 229 | # Report errors for missing combinations of options |
| 230 | if [ -z "$MACHINE" -a -z "$KERNEL" -a -z "$VM" ]; then |
| 231 | error "you must specify at least a MACHINE, VM, or KERNEL argument" |
| 232 | fi |
| 233 | if [ "$FSTYPE" = "nfs" -a -z "$ROOTFS" ]; then |
| 234 | error "NFS booting without an explicit ROOTFS path is not yet supported" |
| 235 | fi |
| 236 | |
| 237 | if [ -z "$MACHINE" ]; then |
| 238 | if [ "x$FSTYPE" = "xvmdk" ] || [ "x$FSTYPE" = "xhddimg" ] || [ "x$FSTYPE" = "xhdddirect" ]; then |
| 239 | MACHINE=`basename $VM | sed -n 's/.*\(qemux86-64\|qemux86\|qemuarm64\|qemuarm\|qemumips64\|qemumips\|qemuppc\|qemush4\).*/\1/p'` |
| 240 | if [ -z "$MACHINE" ]; then |
| 241 | error "Unable to set MACHINE from image filename [$VM]" |
| 242 | fi |
| 243 | echo "Set MACHINE to [$MACHINE] based on image [$VM]" |
| 244 | else |
| 245 | MACHINE=`basename $KERNEL | sed -n 's/.*\(qemux86-64\|qemux86\|qemuarm64\|qemuarm\|qemumips64\|qemumips\|qemuppc\|qemush4\).*/\1/p'` |
| 246 | if [ -z "$MACHINE" ]; then |
| 247 | error "Unable to set MACHINE from kernel filename [$KERNEL]" |
| 248 | fi |
| 249 | echo "Set MACHINE to [$MACHINE] based on kernel [$KERNEL]" |
| 250 | fi |
| 251 | fi |
| 252 | |
| 253 | YOCTO_KVM_WIKI="https://wiki.yoctoproject.org/wiki/How_to_enable_KVM_for_Poky_qemu" |
| 254 | YOCTO_PARAVIRT_KVM_WIKI="https://wiki.yoctoproject.org/wiki/Running_an_x86_Yocto_Linux_image_under_QEMU_KVM" |
| 255 | # Detect KVM configuration |
| 256 | if [ "x$KVM_ENABLED" = "xyes" ]; then |
| 257 | if [ -z "$KVM_CAPABLE" ]; then |
| 258 | echo "You are trying to enable KVM on a cpu without VT support." |
| 259 | echo "Remove kvm from the command-line, or refer" |
| 260 | echo "$YOCTO_KVM_WIKI"; |
| 261 | exit 1; |
| 262 | fi |
| 263 | if [ "x$MACHINE" != "xqemux86" -a "x$MACHINE" != "xqemux86-64" ]; then |
| 264 | echo "KVM only support x86 & x86-64. Remove kvm from the command-line"; |
| 265 | exit 1; |
| 266 | fi |
| 267 | if [ ! -e /dev/kvm ]; then |
| 268 | echo "Missing KVM device. Have you inserted kvm modules?" |
| 269 | echo "For further help see:" |
| 270 | echo "$YOCTO_KVM_WIKI"; |
| 271 | exit 1; |
| 272 | fi |
| 273 | if [ ! -e /dev/vhost-net ]; then |
| 274 | echo "Missing virtio net device. Have you inserted vhost-net module?" |
| 275 | echo "For further help see:" |
| 276 | echo "$YOCTO_PARAVIRT_KVM_WIKI"; |
| 277 | exit 1; |
| 278 | fi |
| 279 | if [ -w /dev/kvm -a -r /dev/kvm ]; then |
| 280 | SCRIPT_QEMU_OPT="$SCRIPT_QEMU_OPT -enable-kvm" |
| 281 | KVM_ACTIVE="yes" |
| 282 | else |
| 283 | echo "You have no rights on /dev/kvm." |
| 284 | echo "Please change the ownership of this file as described at:" |
| 285 | echo "$YOCTO_KVM_WIKI"; |
| 286 | exit 1; |
| 287 | fi |
| 288 | if [ ! -w /dev/vhost-net -o ! -r /dev/vhost-net ]; then |
| 289 | if [ "$SLIRP_ENABLED" != "yes" ] ; then |
| 290 | echo "You have no rights on /dev/vhost-net." |
| 291 | echo "Please change the ownership of this file as described at:" |
| 292 | echo "$YOCTO_PARAVIRT_KVM_WIKI"; |
| 293 | exit 1; |
| 294 | fi |
| 295 | fi |
| 296 | fi |
| 297 | |
| 298 | machine2=`echo $MACHINE | tr 'a-z' 'A-Z' | sed 's/-/_/'` |
| 299 | # MACHINE is now set for all cases |
| 300 | |
| 301 | # Defaults used when these vars need to be inferred |
| 302 | QEMUX86_DEFAULT_KERNEL=bzImage-qemux86.bin |
| 303 | QEMUX86_DEFAULT_FSTYPE=ext4 |
| 304 | |
| 305 | QEMUX86_64_DEFAULT_KERNEL=bzImage-qemux86-64.bin |
| 306 | QEMUX86_64_DEFAULT_FSTYPE=ext4 |
| 307 | |
| 308 | QEMUARM_DEFAULT_KERNEL=zImage-qemuarm.bin |
| 309 | QEMUARM_DEFAULT_FSTYPE=ext4 |
| 310 | |
| 311 | QEMUARM64_DEFAULT_KERNEL=Image-qemuarm64.bin |
| 312 | QEMUARM64_DEFAULT_FSTYPE=ext4 |
| 313 | |
| 314 | QEMUMIPS_DEFAULT_KERNEL=vmlinux-qemumips.bin |
| 315 | QEMUMIPS_DEFAULT_FSTYPE=ext4 |
| 316 | |
| 317 | QEMUMIPSEL_DEFAULT_KERNEL=vmlinux-qemumipsel.bin |
| 318 | QEMUMIPSEL_DEFAULT_FSTYPE=ext4 |
| 319 | |
| 320 | QEMUMIPS64_DEFAULT_KERNEL=vmlinux-qemumips64.bin |
| 321 | QEMUMIPS64_DEFAULT_FSTYPE=ext4 |
| 322 | |
| 323 | QEMUSH4_DEFAULT_KERNEL=vmlinux-qemumips.bin |
| 324 | QEMUSH4_DEFAULT_FSTYPE=ext4 |
| 325 | |
| 326 | QEMUPPC_DEFAULT_KERNEL=vmlinux-qemuppc.bin |
| 327 | QEMUPPC_DEFAULT_FSTYPE=ext4 |
| 328 | |
| 329 | QEMUMICROBLAZE_DEFAULT_KERNEL=linux.bin.ub |
| 330 | QEMUMICROBLAZE_DEFAULT_FSTYPE=cpio |
| 331 | |
| 332 | QEMUZYNQ_DEFAULT_KERNEL=uImage |
| 333 | QEMUZYNQ_DEFAULT_FSTYPE=cpio |
| 334 | |
| 335 | AKITA_DEFAULT_KERNEL=zImage-akita.bin |
| 336 | AKITA_DEFAULT_FSTYPE=jffs2 |
| 337 | |
| 338 | SPITZ_DEFAULT_KERNEL=zImage-spitz.bin |
| 339 | SPITZ_DEFAULT_FSTYPE=ext3 |
| 340 | |
| 341 | setup_path_vars() { |
| 342 | if [ -z "$OE_TMPDIR" ] ; then |
| 343 | PATHS_REQUIRED=true |
| 344 | elif [ "$1" = "1" -a -z "$DEPLOY_DIR_IMAGE" ] ; then |
| 345 | PATHS_REQUIRED=true |
| 346 | else |
| 347 | PATHS_REQUIRED=false |
| 348 | fi |
| 349 | |
| 350 | if [ "$PATHS_REQUIRED" = "true" ]; then |
| 351 | # Try to get the variable values from bitbake |
| 352 | type -P bitbake &>/dev/null || { |
| 353 | echo "In order for this script to dynamically infer paths"; |
| 354 | echo "to kernels or filesystem images, you either need"; |
| 355 | echo "bitbake in your PATH or to source oe-init-build-env"; |
| 356 | echo "before running this script" >&2; |
| 357 | exit 1; } |
| 358 | |
| 359 | # We have bitbake in PATH, get the variable values from bitbake |
| 360 | BITBAKE_ENV_TMPFILE=`mktemp --tmpdir runqemu.XXXXXXXXXX` |
| 361 | if [ "$?" != "0" ] ; then |
| 362 | echo "Error: mktemp failed for bitbake environment output" |
| 363 | exit 1 |
| 364 | fi |
| 365 | |
| 366 | MACHINE=$MACHINE bitbake -e > $BITBAKE_ENV_TMPFILE |
| 367 | if [ -z "$OE_TMPDIR" ] ; then |
| 368 | OE_TMPDIR=`sed -n 's/^TMPDIR=\"\(.*\)\"/\1/p' $BITBAKE_ENV_TMPFILE` |
| 369 | fi |
| 370 | if [ -z "$DEPLOY_DIR_IMAGE" ] ; then |
| 371 | DEPLOY_DIR_IMAGE=`sed -n 's/^DEPLOY_DIR_IMAGE=\"\(.*\)\"/\1/p' $BITBAKE_ENV_TMPFILE` |
| 372 | fi |
| 373 | if [ -z "$OE_TMPDIR" ]; then |
| 374 | # Check for errors from bitbake that the user needs to know about |
| 375 | BITBAKE_OUTPUT=`cat $BITBAKE_ENV_TMPFILE | wc -l` |
| 376 | if [ "$BITBAKE_OUTPUT" -eq "0" ]; then |
| 377 | echo "Error: this script needs to be run from your build directory, or you need" |
| 378 | echo "to explicitly set OE_TMPDIR and DEPLOY_DIR_IMAGE in your environment" |
| 379 | else |
| 380 | echo "There was an error running bitbake to determine TMPDIR" |
| 381 | echo "Here is the output from 'bitbake -e':" |
| 382 | cat $BITBAKE_ENV_TMPFILE |
| 383 | fi |
| 384 | rm $BITBAKE_ENV_TMPFILE |
| 385 | exit 1 |
| 386 | fi |
| 387 | rm $BITBAKE_ENV_TMPFILE |
| 388 | fi |
| 389 | } |
| 390 | |
| 391 | setup_sysroot() { |
| 392 | # Toolchain installs set up $OECORE_NATIVE_SYSROOT in their |
| 393 | # environment script. If that variable isn't set, we're |
| 394 | # either in an in-tree build scenario or the environment |
| 395 | # script wasn't source'd. |
| 396 | if [ -z "$OECORE_NATIVE_SYSROOT" ]; then |
| 397 | setup_path_vars |
| 398 | BUILD_ARCH=`uname -m` |
| 399 | BUILD_OS=`uname | tr '[A-Z]' '[a-z]'` |
| 400 | BUILD_SYS="$BUILD_ARCH-$BUILD_OS" |
| 401 | |
| 402 | OECORE_NATIVE_SYSROOT=$OE_TMPDIR/sysroots/$BUILD_SYS |
| 403 | fi |
| 404 | |
| 405 | # Some recipes store the BIOS under $OE_TMPDIR/sysroots/$MACHINE, |
| 406 | # now defined as OECORE_MACHINE_SYSROOT. The latter is used when searching |
| 407 | # BIOS, VGA BIOS and keymaps. |
| 408 | if [ -z "$OECORE_MACHINE_SYSROOT" ]; then |
| 409 | OECORE_MACHINE_SYSROOT=$OE_TMPDIR/sysroots/$MACHINE |
| 410 | fi |
| 411 | } |
| 412 | |
| 413 | # Locate a rootfs image to boot which matches our expected |
| 414 | # machine and fstype. |
| 415 | findimage() { |
| 416 | where=$1 |
| 417 | machine=$2 |
| 418 | extension=$3 |
| 419 | |
| 420 | # Sort rootfs candidates by modification time - the most |
| 421 | # recently created one is the one we most likely want to boot. |
| 422 | filename=`ls -t1 $where/*-image*$machine.$extension 2>/dev/null | head -n1` |
| 423 | if [ "x$filename" != "x" ]; then |
| 424 | ROOTFS=$filename |
| 425 | return |
| 426 | fi |
| 427 | |
| 428 | echo "Couldn't find a $machine rootfs image in $where." |
| 429 | exit 1 |
| 430 | } |
| 431 | |
| 432 | if [ -e "$ROOTFS" -a -z "$FSTYPE" ]; then |
| 433 | # Extract the filename extension |
| 434 | EXT=`echo $ROOTFS | awk -F . '{ print \$NF }'` |
| 435 | if [ "x$EXT" = "xext2" -o "x$EXT" = "xext3" -o \ |
| 436 | "x$EXT" = "xjffs2" -o "x$EXT" = "xbtrfs" -o \ |
| 437 | "x$EXT" = "xext4" ]; then |
| 438 | FSTYPE=$EXT |
| 439 | else |
| 440 | echo "Note: Unable to determine filesystem extension for $ROOTFS" |
| 441 | echo "We will use the default FSTYPE for $MACHINE" |
| 442 | # ...which is done further below... |
| 443 | fi |
| 444 | fi |
| 445 | |
| 446 | if [ -z "$KERNEL" -a "x$FSTYPE" != "xvmdk" -a "x$FSTYPE" != "xhddimg" -a "x$FSTYPE" != "xhdddirect" ]; then |
| 447 | setup_path_vars 1 |
| 448 | eval kernel_file=\$${machine2}_DEFAULT_KERNEL |
| 449 | KERNEL=$DEPLOY_DIR_IMAGE/$kernel_file |
| 450 | |
| 451 | if [ -z "$KERNEL" ]; then |
| 452 | error "Unable to determine default kernel for MACHINE [$MACHINE]" |
| 453 | fi |
| 454 | fi |
| 455 | # KERNEL is now set for all cases |
| 456 | |
| 457 | if [ -z "$FSTYPE" ]; then |
| 458 | eval FSTYPE=\$${machine2}_DEFAULT_FSTYPE |
| 459 | |
| 460 | if [ -z "$FSTYPE" ]; then |
| 461 | error "Unable to determine default fstype for MACHINE [$MACHINE]" |
| 462 | fi |
| 463 | fi |
| 464 | |
| 465 | # FSTYPE is now set for all cases |
| 466 | |
| 467 | # Handle cases where a ROOTFS type is given instead of a filename, e.g. |
| 468 | # core-image-sato |
| 469 | if [ "$LAZY_ROOTFS" = "true" ]; then |
| 470 | setup_path_vars 1 |
| 471 | echo "Assuming $ROOTFS really means $DEPLOY_DIR_IMAGE/$ROOTFS-$MACHINE.$FSTYPE" |
| 472 | if [ "$FSTYPE" = "hddimg" -o "x$FSTYPE" = "xhdddirect" ]; then |
| 473 | VM=$DEPLOY_DIR_IMAGE/$ROOTFS-$MACHINE.$FSTYPE |
| 474 | else |
| 475 | ROOTFS=$DEPLOY_DIR_IMAGE/$ROOTFS-$MACHINE.$FSTYPE |
| 476 | fi |
| 477 | fi |
| 478 | |
| 479 | if [ -z "$ROOTFS" -a "x$FSTYPE" != "xvmdk" -a "x$FSTYPE" != "xhddimg" -a "x$FSTYPE" != "xhdddirect" ]; then |
| 480 | setup_path_vars 1 |
| 481 | T=$DEPLOY_DIR_IMAGE |
| 482 | eval rootfs_list=\$${machine2}_DEFAULT_ROOTFS |
| 483 | findimage $T $MACHINE $FSTYPE |
| 484 | |
| 485 | if [ -z "$ROOTFS" ]; then |
| 486 | error "Unable to determine default rootfs for MACHINE [$MACHINE]" |
| 487 | fi |
| 488 | fi |
| 489 | # ROOTFS is now set for all cases, now expand it to be an absolute path, it should exist at this point |
| 490 | |
| 491 | ROOTFS=`readlink -f $ROOTFS` |
| 492 | |
| 493 | echo "" |
| 494 | echo "Continuing with the following parameters:" |
| 495 | if [ "x$FSTYPE" != "xvmdk" -a "x$FSTYPE" != "xhddimg" -a "x$FSTYPE" != "xhdddirect" ]; then |
| 496 | echo "KERNEL: [$KERNEL]" |
| 497 | echo "ROOTFS: [$ROOTFS]" |
| 498 | else |
| 499 | echo "VMDK: [$VM]" |
| 500 | fi |
| 501 | echo "FSTYPE: [$FSTYPE]" |
| 502 | |
| 503 | setup_sysroot |
| 504 | # OECORE_NATIVE_SYSROOT and OECORE_MACHINE_SYSROOT are now set for all cases |
| 505 | |
| 506 | INTERNAL_SCRIPT="$0-internal" |
| 507 | if [ ! -f "$INTERNAL_SCRIPT" -o ! -r "$INTERNAL_SCRIPT" ]; then |
| 508 | INTERNAL_SCRIPT=`which runqemu-internal` |
| 509 | fi |
| 510 | |
| 511 | # Specify directory for BIOS, VGA BIOS and keymaps |
| 512 | if [ ! -z "$CUSTOMBIOSDIR" ]; then |
| 513 | if [ -d "$OECORE_NATIVE_SYSROOT/$CUSTOMBIOSDIR" ]; then |
| 514 | echo "Assuming biosdir is $OECORE_NATIVE_SYSROOT/$CUSTOMBIOSDIR" |
| 515 | SCRIPT_QEMU_OPT="$SCRIPT_QEMU_OPT -L $OECORE_NATIVE_SYSROOT/$CUSTOMBIOSDIR" |
| 516 | elif [ -d "$OECORE_MACHINE_SYSROOT/$CUSTOMBIOSDIR" ]; then |
| 517 | echo "Assuming biosdir is $OECORE_MACHINE_SYSROOT/$CUSTOMBIOSDIR" |
| 518 | SCRIPT_QEMU_OPT="$SCRIPT_QEMU_OPT -L $OECORE_MACHINE_SYSROOT/$CUSTOMBIOSDIR" |
| 519 | else |
| 520 | if [ ! -d "$CUSTOMBIOSDIR" ]; then |
| 521 | echo "Custom BIOS directory not found. Tried: $CUSTOMBIOSDIR" |
| 522 | echo "and $OECORE_NATIVE_SYSROOT/$CUSTOMBIOSDIR" |
| 523 | echo "and $OECORE_MACHINE_SYSROOT/$CUSTOMBIOSDIR" |
| 524 | exit 1; |
| 525 | fi |
| 526 | echo "Assuming biosdir is $CUSTOMBIOSDIR" |
| 527 | SCRIPT_QEMU_OPT="$SCRIPT_QEMU_OPT -L $CUSTOMBIOSDIR" |
| 528 | fi |
| 529 | fi |
| 530 | |
| 531 | . $INTERNAL_SCRIPT |
| 532 | exit $? |