blob: bb2e3e6484a9218e6ef202cd6df726f8dbf37708 [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#
22###############################################################################
Andrew Geissler0205e8d2016-08-10 07:46:19 -050023
24set -uo pipefail
25
26QEMU_ARCH=${1:-$QEMU_ARCH}
Alanny Lopezb24dccb2017-07-27 10:25:50 -050027# If QEMU_ARCH is empty exit, it is required to continue
Andrew Geissler0205e8d2016-08-10 07:46:19 -050028echo "QEMU_ARCH = $QEMU_ARCH"
29if [[ -z $QEMU_ARCH ]]; then
30 echo "Did not pass in required QEMU arch parameter"
31 exit -1
32fi
33
34BASE_DIR=${2:-$HOME}
Alanny Lopezb24dccb2017-07-27 10:25:50 -050035# If BASE_DIR doesn't exist exit, it is required to continue
Andrew Geissler0205e8d2016-08-10 07:46:19 -050036echo "BASE_DIR = $BASE_DIR"
37if [[ ! -d $BASE_DIR ]]; then
38 echo "No input directory and HOME not set!"
39 exit -1
40fi
41
Alanny Lopezb24dccb2017-07-27 10:25:50 -050042# Enter the base directory
Andrew Geissler0205e8d2016-08-10 07:46:19 -050043cd ${BASE_DIR}
44
Alanny Lopezb24dccb2017-07-27 10:25:50 -050045# Find the correct drive file, and save its name
46DRIVE=$(ls ./tmp/deploy/images/qemuarm | grep rootfs.ext4)
47
Alanny Lopezebf07942017-08-04 11:53:37 -050048# Obtain IP from /etc/hosts if IP is not valid set to localhost
49IP=$(awk 'END{print $1}' /etc/hosts)
50if [[ "$IP" != *.*.*.* ]]; then
51 IP=127.0.0.1
52fi
53
Alanny Lopezb24dccb2017-07-27 10:25:50 -050054# Launch QEMU using the qemu-system-arm
Andrew Geissler0205e8d2016-08-10 07:46:19 -050055./tmp/sysroots/${QEMU_ARCH}/usr/bin/qemu-system-arm \
Alanny Lopezebf07942017-08-04 11:53:37 -050056 -device virtio-net,netdev=mynet \
57 -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 -050058 -machine versatilepb \
Alanny Lopezb24dccb2017-07-27 10:25:50 -050059 -m 256 \
60 -drive file=./tmp/deploy/images/qemuarm/${DRIVE},if=virtio,format=raw \
Andrew Geissler0205e8d2016-08-10 07:46:19 -050061 -show-cursor \
62 -usb \
Alanny Lopezb24dccb2017-07-27 10:25:50 -050063 -usbdevice tablet \
64 -device virtio-rng-pci \
65 -serial mon:vc \
66 -serial mon:stdio \
67 -serial null \
68 -kernel ./tmp/deploy/images/qemuarm/zImage \
69 -append 'root=/dev/vda rw highres=off console=ttyS0 mem=256M ip=dhcp console=ttyAMA0,115200 console=tty'\
70 -dtb ./tmp/deploy/images/qemuarm/zImage-versatile-pb.dtb