blob: f0a54f2051a03b91462ed351ffdd493b928d9dc3 [file] [log] [blame]
#!/bin/bash -xe
###############################################################################
# Launch QEMU using the raw commands
#
# Can be run by specifying the BASE_DIR and QEMU_ARCH when the script is
# called. Additionally, this script is automatically called by running the
# run-robot-qemu-test.sh, it's used to launch the QEMU test container.
#
###############################################################################
#
# Variables BASE_DIR and QEMU_ARCH are both required but can be optionally
# input as parameters following the initial script call. Alternatively, they
# can be input by exporting them or sourcing the script into an environment
# that has them declared.
#
# Parameters:
# parm1: <optional, QEMU architecture to use >
# default is ${QEMU_ARCH} - ppc64le-linux or x86_64-linux
# parm2: <optional, full path to base directory of qemu binary and images >
# default is ${HOME}
#
# Optional Env Variable:
#
# QEMU_BIN = Location of qemu-system-arm binary to use when starting
# QEMU relative to upstream workspace. Default is
# ./tmp/sysroots/${QEMU_ARCH}/usr/bin/qemu-system-arm
# which is the default location when doing a bitbake
# of obmc-phosphor-image
#
# MACHINE = Machine to run test against. Options are "witherspoon",
# "palmetto", "romulus", or undefined (default). Default
# will use the versatilepb model.
###############################################################################
set -uo pipefail
QEMU_ARCH=${1:-$QEMU_ARCH}
# If QEMU_ARCH is empty exit, it is required to continue
echo "QEMU_ARCH = $QEMU_ARCH"
if [[ -z $QEMU_ARCH ]]; then
echo "Did not pass in required QEMU arch parameter"
exit -1
fi
BASE_DIR=${2:-$HOME}
# If BASE_DIR doesn't exist exit, it is required to continue
echo "BASE_DIR = $BASE_DIR"
if [[ ! -d $BASE_DIR ]]; then
echo "No input directory and HOME not set!"
exit -1
fi
# Set the location of the qemu binary relative to BASE_DIR
QEMU_BIN=${QEMU_BIN:-./tmp/sysroots/${QEMU_ARCH}/usr/bin/qemu-system-arm}
DEFAULT_MACHINE=versatilepb
MACHINE=${MACHINE:-${DEFAULT_MACHINE}}
# Enter the base directory
cd ${BASE_DIR}
# Find the correct drive file, and save its name. OpenBMC has 3 different
# image formats. The UBI based one, the standard static.mtd one, and the
# default QEMU basic image (rootfs.ext4).
DEFAULT_IMAGE_LOC="./tmp/deploy/images/"
if [ -f ${DEFAULT_IMAGE_LOC}/${MACHINE}/obmc-phosphor-image-${MACHINE}.ubi.mtd ]; then
DRIVE=obmc-phosphor-image-${MACHINE}.ubi.mtd
elif [ -f ${DEFAULT_IMAGE_LOC}/${MACHINE}/obmc-phosphor-image-${MACHINE}.static.mtd ]; then
DRIVE=obmc-phosphor-image-${MACHINE}.static.mtd
else
DRIVE=$(ls ${DEFAULT_IMAGE_LOC}/qemuarm | grep rootfs.ext4)
fi
# Obtain IP from /etc/hosts if IP is not valid set to localhost
IP=$(awk 'END{print $1}' /etc/hosts)
if [[ "$IP" != *.*.*.* ]]; then
IP=127.0.0.1
fi
# The syntax to start old qemu / default version requires different syntax
# then new qemu with the real platforms
if [ ${MACHINE} = ${DEFAULT_MACHINE} ]; then
# Launch default QEMU using the qemu-system-arm
${QEMU_BIN} \
-device virtio-net,netdev=mynet \
-netdev user,id=mynet,hostfwd=tcp:${IP}:22-:22,hostfwd=tcp:${IP}:443-:443,hostfwd=tcp:${IP}:80-:80,hostfwd=tcp:${IP}:2200-:2200,hostfwd=udp:${IP}:623-:623,hostfwd=udp:${IP}:664-:664 \
-machine versatilepb \
-m 256 \
-drive file=${DEFAULT_IMAGE_LOC}/qemuarm/${DRIVE},if=virtio,format=raw \
-show-cursor \
-usb \
-usbdevice tablet \
-device virtio-rng-pci \
-serial mon:vc \
-serial mon:stdio \
-serial null \
-kernel ${DEFAULT_IMAGE_LOC}/qemuarm/zImage \
-append 'root=/dev/vda rw highres=off console=ttyS0 mem=256M ip=dhcp console=ttyAMA0,115200 console=tty'\
-dtb ${DEFAULT_IMAGE_LOC}/qemuarm/zImage-versatile-pb.dtb
else
${QEMU_BIN} \
-m 256 \
-machine ${MACHINE}-bmc \
-nographic \
-drive file=${DEFAULT_IMAGE_LOC}/${MACHINE}/${DRIVE},format=raw,if=mtd \
-net nic \
-net user,hostfwd=:${IP}:22-:22,hostfwd=:${IP}:443-:443,hostfwd=tcp:${IP}:80-:80,hostfwd=tcp:${IP}:2200-:2200,hostfwd=udp:${IP}:623-:623,hostfwd=udp:${IP}:664-:664,hostname=qemu
fi