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