blob: 7b3b7a4275b22f6ddd90b49131730e5d98a6b307 [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
Andrew Geisslerf9dbc8d2018-01-05 14:49:39 -060029#
30# MACHINE = Machine to run test against. Options are "witherspoon",
31# "palmetto", "romulus", or undefined (default). Default
32# will use the versatilepb model.
Alanny Lopezb24dccb2017-07-27 10:25:50 -050033###############################################################################
Andrew Geissler0205e8d2016-08-10 07:46:19 -050034
35set -uo pipefail
36
37QEMU_ARCH=${1:-$QEMU_ARCH}
Alanny Lopezb24dccb2017-07-27 10:25:50 -050038# If QEMU_ARCH is empty exit, it is required to continue
Andrew Geissler0205e8d2016-08-10 07:46:19 -050039echo "QEMU_ARCH = $QEMU_ARCH"
40if [[ -z $QEMU_ARCH ]]; then
41 echo "Did not pass in required QEMU arch parameter"
Patrick Williams384d7412020-11-06 16:15:41 -060042 exit 1
Andrew Geissler0205e8d2016-08-10 07:46:19 -050043fi
44
45BASE_DIR=${2:-$HOME}
Alanny Lopezb24dccb2017-07-27 10:25:50 -050046# If BASE_DIR doesn't exist exit, it is required to continue
Andrew Geissler0205e8d2016-08-10 07:46:19 -050047echo "BASE_DIR = $BASE_DIR"
48if [[ ! -d $BASE_DIR ]]; then
49 echo "No input directory and HOME not set!"
Patrick Williams384d7412020-11-06 16:15:41 -060050 exit 1
Andrew Geissler0205e8d2016-08-10 07:46:19 -050051fi
52
Andrew Geissler7a88f292018-01-04 15:16:02 -060053# Set the location of the qemu binary relative to BASE_DIR
54QEMU_BIN=${QEMU_BIN:-./tmp/sysroots/${QEMU_ARCH}/usr/bin/qemu-system-arm}
55
Andrew Geissler4290d582018-01-05 23:34:52 -060056DEFAULT_MACHINE=versatilepb
57MACHINE=${MACHINE:-${DEFAULT_MACHINE}}
Andrew Geisslerf9dbc8d2018-01-05 14:49:39 -060058
Alanny Lopezb24dccb2017-07-27 10:25:50 -050059# Enter the base directory
Patrick Williams384d7412020-11-06 16:15:41 -060060cd "${BASE_DIR}"
Andrew Geissler0205e8d2016-08-10 07:46:19 -050061
Andrew Geisslerf9dbc8d2018-01-05 14:49:39 -060062# Find the correct drive file, and save its name. OpenBMC has 3 different
63# image formats. The UBI based one, the standard static.mtd one, and the
64# default QEMU basic image (rootfs.ext4).
Nan Zhoue4146672022-01-28 21:37:16 +000065DEFAULT_IMAGE_LOC="${DEFAULT_IMAGE_LOC:-./tmp/deploy/images/}"
66if [ -f "${DEFAULT_IMAGE_LOC}/${MACHINE}/obmc-phosphor-image-${MACHINE}".ubi.mtd ]; then
Patrick Williams384d7412020-11-06 16:15:41 -060067 DRIVE="obmc-phosphor-image-${MACHINE}.ubi.mtd"
Nan Zhoue4146672022-01-28 21:37:16 +000068elif [ -f "${DEFAULT_IMAGE_LOC}/${MACHINE}/obmc-phosphor-image-${MACHINE}".static.mtd ]; then
Patrick Williams384d7412020-11-06 16:15:41 -060069 DRIVE="obmc-phosphor-image-${MACHINE}.static.mtd"
Andrew Geissler4290d582018-01-05 23:34:52 -060070else
Patrick Williams384d7412020-11-06 16:15:41 -060071 # shellcheck disable=SC2010
Nan Zhoue4146672022-01-28 21:37:16 +000072 DRIVE=$(ls "${DEFAULT_IMAGE_LOC}"/qemuarm | grep rootfs.ext4)
Andrew Geisslerf9dbc8d2018-01-05 14:49:39 -060073fi
74
Charles Paul Hofer86de2962018-06-08 11:00:43 -050075# Copy the drive file off to /tmp so that QEMU does not write anything back
76# to the drive file and make it unusable for future QEMU runs.
77
78TMP_DRIVE_PATH=$(mktemp "/tmp/${DRIVE}-XXXXX")
79
80# The drive file is stored in different locations depending on if we are
81# using the default or real platforms.
Patrick Williams384d7412020-11-06 16:15:41 -060082if [ "${MACHINE}" = "${DEFAULT_MACHINE}" ]; then
Nan Zhoue4146672022-01-28 21:37:16 +000083 cp "${DEFAULT_IMAGE_LOC}/qemuarm/${DRIVE}" "${TMP_DRIVE_PATH}"
Charles Paul Hofer86de2962018-06-08 11:00:43 -050084else
Nan Zhoue4146672022-01-28 21:37:16 +000085 cp "${DEFAULT_IMAGE_LOC}/${MACHINE}/${DRIVE}" "${TMP_DRIVE_PATH}"
Charles Paul Hofer86de2962018-06-08 11:00:43 -050086fi
87
Alanny Lopezebf07942017-08-04 11:53:37 -050088# Obtain IP from /etc/hosts if IP is not valid set to localhost
89IP=$(awk 'END{print $1}' /etc/hosts)
90if [[ "$IP" != *.*.*.* ]]; then
Patrick Williams476a7e92022-12-06 09:52:53 -060091 IP=127.0.0.1
Alanny Lopezebf07942017-08-04 11:53:37 -050092fi
93
Andrew Geissler8ccdf1b2020-03-25 13:48:28 -050094# Forward all needed ports for the robot test framework to run
95# Since this is run in docker, the standard ports can be used
96NET_FORWARDING=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
97
98# Most system only have one NIC so set this as default
99NIC="-net nic,model=ftgmac100,netdev=netdev1 -netdev user,id=netdev1,$NET_FORWARDING"
Patrick Williams384d7412020-11-06 16:15:41 -0600100if [ "${MACHINE}" = "tacoma" ]; then
Andrew Geissler8ccdf1b2020-03-25 13:48:28 -0500101 # Tacoma requires us to specify up to four NICs, with the third one being
102 # the active device.
103 NIC="-net nic,model=ftgmac100,netdev=netdev1 -netdev user,id=netdev1 "
104 NIC+="-net nic,model=ftgmac100,netdev=netdev2 -netdev user,id=netdev2 "
105 NIC+="-net nic,model=ftgmac100,netdev=netdev3 -netdev user,id=netdev3,$NET_FORWARDING "
106 NIC+="-net nic,model=ftgmac100,netdev=netdev4 -netdev user,id=netdev4"
107fi
108
Andrew Geissler4290d582018-01-05 23:34:52 -0600109# The syntax to start old qemu / default version requires different syntax
110# then new qemu with the real platforms
Patrick Williams384d7412020-11-06 16:15:41 -0600111if [ "${MACHINE}" = "${DEFAULT_MACHINE}" ]; then
Andrew Geissler4290d582018-01-05 23:34:52 -0600112 # Launch default QEMU using the qemu-system-arm
113 ${QEMU_BIN} \
114 -device virtio-net,netdev=mynet \
Patrick Williams4920cb52023-04-12 06:51:10 -0500115 -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" \
Andrew Geissler4290d582018-01-05 23:34:52 -0600116 -machine versatilepb \
117 -m 256 \
Patrick Williams384d7412020-11-06 16:15:41 -0600118 -drive file="${TMP_DRIVE_PATH}",if=virtio,format=raw \
Andrew Geissler4290d582018-01-05 23:34:52 -0600119 -show-cursor \
120 -usb \
121 -usbdevice tablet \
122 -device virtio-rng-pci \
123 -serial mon:vc \
124 -serial mon:stdio \
125 -serial null \
Nan Zhoue4146672022-01-28 21:37:16 +0000126 -kernel "${DEFAULT_IMAGE_LOC}"/qemuarm/zImage \
Andrew Geissler4290d582018-01-05 23:34:52 -0600127 -append 'root=/dev/vda rw highres=off console=ttyS0 mem=256M ip=dhcp console=ttyAMA0,115200 console=tty'\
Nan Zhoue4146672022-01-28 21:37:16 +0000128 -dtb "${DEFAULT_IMAGE_LOC}"/qemuarm/zImage-versatile-pb.dtb
Andrew Geissler4290d582018-01-05 23:34:52 -0600129else
Patrick Williams384d7412020-11-06 16:15:41 -0600130 # shellcheck disable=SC2086 # NIC is intentionally word-split.
Andrew Geissler4290d582018-01-05 23:34:52 -0600131 ${QEMU_BIN} \
Patrick Williams384d7412020-11-06 16:15:41 -0600132 -machine "${MACHINE}"-bmc \
Andrew Geissler4290d582018-01-05 23:34:52 -0600133 -nographic \
Patrick Williams384d7412020-11-06 16:15:41 -0600134 -drive file="${TMP_DRIVE_PATH}",format=raw,if=mtd \
Andrew Geissler8ccdf1b2020-03-25 13:48:28 -0500135 ${NIC}
Andrew Geissler4290d582018-01-05 23:34:52 -0600136fi