blob: bf62ed0b1015c31148a12bd7a244defd8a080bc1 [file] [log] [blame]
Andrew Geissler0205e8d2016-08-10 07:46:19 -05001#!/bin/bash -xe
Alanny Lopezb24dccb2017-07-27 10:25:50 -05002###############################################################################
Andrew Geissler0205e8d2016-08-10 07:46:19 -05003# Launch QEMU using the raw commands
4#
Alanny Lopezb24dccb2017-07-27 10:25:50 -05005# Can be run by specifying the BASE_DIR and QEMU_ARCH when the script is
6# called. Additionally, this script is automatically called by running the
7# run-robot-qemu-test.sh, it's used to launch the QEMU test container.
8#
9###############################################################################
10#
11# Variables BASE_DIR and QEMU_ARCH are both required but can be optionally
12# input as parameters following the initial script call. Alternatively, they
13# can be input by exporting them or sourcing the script into an environment
14# that has them declared.
15#
Andrew Geissler0205e8d2016-08-10 07:46:19 -050016# Parameters:
17# parm1: <optional, QEMU architecture to use >
18# default is ${QEMU_ARCH} - ppc64le-linux or x86_64-linux
19# parm2: <optional, full path to base directory of qemu binary and images >
20# default is ${HOME}
Alanny Lopezb24dccb2017-07-27 10:25:50 -050021#
Andrew Geissler7a88f292018-01-04 15:16:02 -060022# Optional Env Variable:
23#
24# QEMU_BIN = Location of qemu-system-arm binary to use when starting
25# QEMU relative to upstream workspace. Default is
26# ./tmp/sysroots/${QEMU_ARCH}/usr/bin/qemu-system-arm
27# which is the default location when doing a bitbake
28# of obmc-phosphor-image
Alanny Lopezb24dccb2017-07-27 10:25:50 -050029###############################################################################
Andrew Geissler0205e8d2016-08-10 07:46:19 -050030
31set -uo pipefail
32
33QEMU_ARCH=${1:-$QEMU_ARCH}
Alanny Lopezb24dccb2017-07-27 10:25:50 -050034# If QEMU_ARCH is empty exit, it is required to continue
Andrew Geissler0205e8d2016-08-10 07:46:19 -050035echo "QEMU_ARCH = $QEMU_ARCH"
36if [[ -z $QEMU_ARCH ]]; then
37 echo "Did not pass in required QEMU arch parameter"
38 exit -1
39fi
40
41BASE_DIR=${2:-$HOME}
Alanny Lopezb24dccb2017-07-27 10:25:50 -050042# If BASE_DIR doesn't exist exit, it is required to continue
Andrew Geissler0205e8d2016-08-10 07:46:19 -050043echo "BASE_DIR = $BASE_DIR"
44if [[ ! -d $BASE_DIR ]]; then
45 echo "No input directory and HOME not set!"
46 exit -1
47fi
48
Andrew Geissler7a88f292018-01-04 15:16:02 -060049# Set the location of the qemu binary relative to BASE_DIR
50QEMU_BIN=${QEMU_BIN:-./tmp/sysroots/${QEMU_ARCH}/usr/bin/qemu-system-arm}
51
Alanny Lopezb24dccb2017-07-27 10:25:50 -050052# Enter the base directory
Andrew Geissler0205e8d2016-08-10 07:46:19 -050053cd ${BASE_DIR}
54
Alanny Lopezb24dccb2017-07-27 10:25:50 -050055# Find the correct drive file, and save its name
56DRIVE=$(ls ./tmp/deploy/images/qemuarm | grep rootfs.ext4)
57
Alanny Lopezebf07942017-08-04 11:53:37 -050058# Obtain IP from /etc/hosts if IP is not valid set to localhost
59IP=$(awk 'END{print $1}' /etc/hosts)
60if [[ "$IP" != *.*.*.* ]]; then
61 IP=127.0.0.1
62fi
63
Alanny Lopezb24dccb2017-07-27 10:25:50 -050064# Launch QEMU using the qemu-system-arm
Andrew Geissler7a88f292018-01-04 15:16:02 -060065${QEMU_BIN} \
Alanny Lopezebf07942017-08-04 11:53:37 -050066 -device virtio-net,netdev=mynet \
67 -netdev user,id=mynet,hostfwd=tcp:${IP}:22-:22,hostfwd=tcp:${IP}:443-:443,hostfwd=tcp:${IP}:80-:80 \
Andrew Geissler0205e8d2016-08-10 07:46:19 -050068 -machine versatilepb \
Alanny Lopezb24dccb2017-07-27 10:25:50 -050069 -m 256 \
70 -drive file=./tmp/deploy/images/qemuarm/${DRIVE},if=virtio,format=raw \
Andrew Geissler0205e8d2016-08-10 07:46:19 -050071 -show-cursor \
72 -usb \
Alanny Lopezb24dccb2017-07-27 10:25:50 -050073 -usbdevice tablet \
74 -device virtio-rng-pci \
75 -serial mon:vc \
76 -serial mon:stdio \
77 -serial null \
78 -kernel ./tmp/deploy/images/qemuarm/zImage \
79 -append 'root=/dev/vda rw highres=off console=ttyS0 mem=256M ip=dhcp console=ttyAMA0,115200 console=tty'\
80 -dtb ./tmp/deploy/images/qemuarm/zImage-versatile-pb.dtb