Andrew Geissler | 0205e8d | 2016-08-10 07:46:19 -0500 | [diff] [blame] | 1 | #!/bin/bash -xe |
Alanny Lopez | b24dccb | 2017-07-27 10:25:50 -0500 | [diff] [blame] | 2 | ############################################################################### |
Andrew Geissler | 0205e8d | 2016-08-10 07:46:19 -0500 | [diff] [blame] | 3 | # Launch QEMU using the raw commands |
| 4 | # |
Alanny Lopez | b24dccb | 2017-07-27 10:25:50 -0500 | [diff] [blame] | 5 | # 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 Geissler | 0205e8d | 2016-08-10 07:46:19 -0500 | [diff] [blame] | 16 | # 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 Lopez | b24dccb | 2017-07-27 10:25:50 -0500 | [diff] [blame] | 21 | # |
Andrew Geissler | 7a88f29 | 2018-01-04 15:16:02 -0600 | [diff] [blame] | 22 | # 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 Geissler | f9dbc8d | 2018-01-05 14:49:39 -0600 | [diff] [blame] | 29 | # |
| 30 | # MACHINE = Machine to run test against. Options are "witherspoon", |
| 31 | # "palmetto", "romulus", or undefined (default). Default |
| 32 | # will use the versatilepb model. |
Alanny Lopez | b24dccb | 2017-07-27 10:25:50 -0500 | [diff] [blame] | 33 | ############################################################################### |
Andrew Geissler | 0205e8d | 2016-08-10 07:46:19 -0500 | [diff] [blame] | 34 | |
| 35 | set -uo pipefail |
| 36 | |
| 37 | QEMU_ARCH=${1:-$QEMU_ARCH} |
Alanny Lopez | b24dccb | 2017-07-27 10:25:50 -0500 | [diff] [blame] | 38 | # If QEMU_ARCH is empty exit, it is required to continue |
Andrew Geissler | 0205e8d | 2016-08-10 07:46:19 -0500 | [diff] [blame] | 39 | echo "QEMU_ARCH = $QEMU_ARCH" |
| 40 | if [[ -z $QEMU_ARCH ]]; then |
| 41 | echo "Did not pass in required QEMU arch parameter" |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 42 | exit 1 |
Andrew Geissler | 0205e8d | 2016-08-10 07:46:19 -0500 | [diff] [blame] | 43 | fi |
| 44 | |
| 45 | BASE_DIR=${2:-$HOME} |
Alanny Lopez | b24dccb | 2017-07-27 10:25:50 -0500 | [diff] [blame] | 46 | # If BASE_DIR doesn't exist exit, it is required to continue |
Andrew Geissler | 0205e8d | 2016-08-10 07:46:19 -0500 | [diff] [blame] | 47 | echo "BASE_DIR = $BASE_DIR" |
| 48 | if [[ ! -d $BASE_DIR ]]; then |
| 49 | echo "No input directory and HOME not set!" |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 50 | exit 1 |
Andrew Geissler | 0205e8d | 2016-08-10 07:46:19 -0500 | [diff] [blame] | 51 | fi |
| 52 | |
Andrew Geissler | 7a88f29 | 2018-01-04 15:16:02 -0600 | [diff] [blame] | 53 | # Set the location of the qemu binary relative to BASE_DIR |
| 54 | QEMU_BIN=${QEMU_BIN:-./tmp/sysroots/${QEMU_ARCH}/usr/bin/qemu-system-arm} |
| 55 | |
Andrew Geissler | 4290d58 | 2018-01-05 23:34:52 -0600 | [diff] [blame] | 56 | DEFAULT_MACHINE=versatilepb |
| 57 | MACHINE=${MACHINE:-${DEFAULT_MACHINE}} |
Andrew Geissler | f9dbc8d | 2018-01-05 14:49:39 -0600 | [diff] [blame] | 58 | |
Alanny Lopez | b24dccb | 2017-07-27 10:25:50 -0500 | [diff] [blame] | 59 | # Enter the base directory |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 60 | cd "${BASE_DIR}" |
Andrew Geissler | 0205e8d | 2016-08-10 07:46:19 -0500 | [diff] [blame] | 61 | |
Andrew Geissler | f9dbc8d | 2018-01-05 14:49:39 -0600 | [diff] [blame] | 62 | # 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). |
| 65 | |
| 66 | DEFAULT_IMAGE_LOC="./tmp/deploy/images/" |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 67 | if [ -f ${DEFAULT_IMAGE_LOC}/"${MACHINE}"/obmc-phosphor-image-"${MACHINE}".ubi.mtd ]; then |
| 68 | DRIVE="obmc-phosphor-image-${MACHINE}.ubi.mtd" |
| 69 | elif [ -f ${DEFAULT_IMAGE_LOC}/"${MACHINE}"/obmc-phosphor-image-"${MACHINE}".static.mtd ]; then |
| 70 | DRIVE="obmc-phosphor-image-${MACHINE}.static.mtd" |
Andrew Geissler | 4290d58 | 2018-01-05 23:34:52 -0600 | [diff] [blame] | 71 | else |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 72 | # shellcheck disable=SC2010 |
Andrew Geissler | f9dbc8d | 2018-01-05 14:49:39 -0600 | [diff] [blame] | 73 | DRIVE=$(ls ${DEFAULT_IMAGE_LOC}/qemuarm | grep rootfs.ext4) |
| 74 | fi |
| 75 | |
Charles Paul Hofer | 86de296 | 2018-06-08 11:00:43 -0500 | [diff] [blame] | 76 | # Copy the drive file off to /tmp so that QEMU does not write anything back |
| 77 | # to the drive file and make it unusable for future QEMU runs. |
| 78 | |
| 79 | TMP_DRIVE_PATH=$(mktemp "/tmp/${DRIVE}-XXXXX") |
| 80 | |
| 81 | # The drive file is stored in different locations depending on if we are |
| 82 | # using the default or real platforms. |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 83 | if [ "${MACHINE}" = "${DEFAULT_MACHINE}" ]; then |
| 84 | cp ${DEFAULT_IMAGE_LOC}/qemuarm/"${DRIVE}" "${TMP_DRIVE_PATH}" |
Charles Paul Hofer | 86de296 | 2018-06-08 11:00:43 -0500 | [diff] [blame] | 85 | else |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 86 | cp ${DEFAULT_IMAGE_LOC}/"${MACHINE}"/"${DRIVE}" "${TMP_DRIVE_PATH}" |
Charles Paul Hofer | 86de296 | 2018-06-08 11:00:43 -0500 | [diff] [blame] | 87 | fi |
| 88 | |
Alanny Lopez | ebf0794 | 2017-08-04 11:53:37 -0500 | [diff] [blame] | 89 | # Obtain IP from /etc/hosts if IP is not valid set to localhost |
| 90 | IP=$(awk 'END{print $1}' /etc/hosts) |
| 91 | if [[ "$IP" != *.*.*.* ]]; then |
| 92 | IP=127.0.0.1 |
| 93 | fi |
| 94 | |
Andrew Geissler | 8ccdf1b | 2020-03-25 13:48:28 -0500 | [diff] [blame] | 95 | # Forward all needed ports for the robot test framework to run |
| 96 | # Since this is run in docker, the standard ports can be used |
| 97 | NET_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 |
| 98 | |
| 99 | # Most system only have one NIC so set this as default |
| 100 | NIC="-net nic,model=ftgmac100,netdev=netdev1 -netdev user,id=netdev1,$NET_FORWARDING" |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 101 | if [ "${MACHINE}" = "tacoma" ]; then |
Andrew Geissler | 8ccdf1b | 2020-03-25 13:48:28 -0500 | [diff] [blame] | 102 | # Tacoma requires us to specify up to four NICs, with the third one being |
| 103 | # the active device. |
| 104 | NIC="-net nic,model=ftgmac100,netdev=netdev1 -netdev user,id=netdev1 " |
| 105 | NIC+="-net nic,model=ftgmac100,netdev=netdev2 -netdev user,id=netdev2 " |
| 106 | NIC+="-net nic,model=ftgmac100,netdev=netdev3 -netdev user,id=netdev3,$NET_FORWARDING " |
| 107 | NIC+="-net nic,model=ftgmac100,netdev=netdev4 -netdev user,id=netdev4" |
| 108 | fi |
| 109 | |
Andrew Geissler | 4290d58 | 2018-01-05 23:34:52 -0600 | [diff] [blame] | 110 | # The syntax to start old qemu / default version requires different syntax |
| 111 | # then new qemu with the real platforms |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 112 | if [ "${MACHINE}" = "${DEFAULT_MACHINE}" ]; then |
Andrew Geissler | 4290d58 | 2018-01-05 23:34:52 -0600 | [diff] [blame] | 113 | # Launch default QEMU using the qemu-system-arm |
| 114 | ${QEMU_BIN} \ |
| 115 | -device virtio-net,netdev=mynet \ |
Andrew Geissler | 6e972b1 | 2018-03-05 08:55:34 -0800 | [diff] [blame] | 116 | -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 Geissler | 4290d58 | 2018-01-05 23:34:52 -0600 | [diff] [blame] | 117 | -machine versatilepb \ |
| 118 | -m 256 \ |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 119 | -drive file="${TMP_DRIVE_PATH}",if=virtio,format=raw \ |
Andrew Geissler | 4290d58 | 2018-01-05 23:34:52 -0600 | [diff] [blame] | 120 | -show-cursor \ |
| 121 | -usb \ |
| 122 | -usbdevice tablet \ |
| 123 | -device virtio-rng-pci \ |
| 124 | -serial mon:vc \ |
| 125 | -serial mon:stdio \ |
| 126 | -serial null \ |
| 127 | -kernel ${DEFAULT_IMAGE_LOC}/qemuarm/zImage \ |
| 128 | -append 'root=/dev/vda rw highres=off console=ttyS0 mem=256M ip=dhcp console=ttyAMA0,115200 console=tty'\ |
| 129 | -dtb ${DEFAULT_IMAGE_LOC}/qemuarm/zImage-versatile-pb.dtb |
| 130 | else |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 131 | # shellcheck disable=SC2086 # NIC is intentionally word-split. |
Andrew Geissler | 4290d58 | 2018-01-05 23:34:52 -0600 | [diff] [blame] | 132 | ${QEMU_BIN} \ |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 133 | -machine "${MACHINE}"-bmc \ |
Andrew Geissler | 4290d58 | 2018-01-05 23:34:52 -0600 | [diff] [blame] | 134 | -nographic \ |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 135 | -drive file="${TMP_DRIVE_PATH}",format=raw,if=mtd \ |
Andrew Geissler | 8ccdf1b | 2020-03-25 13:48:28 -0500 | [diff] [blame] | 136 | ${NIC} |
Andrew Geissler | 4290d58 | 2018-01-05 23:34:52 -0600 | [diff] [blame] | 137 | fi |