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 |
Alanny Lopez | b24dccb | 2017-07-27 10:25:50 -0500 | [diff] [blame] | 29 | ############################################################################### |
Andrew Geissler | 0205e8d | 2016-08-10 07:46:19 -0500 | [diff] [blame] | 30 | |
| 31 | set -uo pipefail |
| 32 | |
| 33 | QEMU_ARCH=${1:-$QEMU_ARCH} |
Alanny Lopez | b24dccb | 2017-07-27 10:25:50 -0500 | [diff] [blame] | 34 | # If QEMU_ARCH is empty exit, it is required to continue |
Andrew Geissler | 0205e8d | 2016-08-10 07:46:19 -0500 | [diff] [blame] | 35 | echo "QEMU_ARCH = $QEMU_ARCH" |
| 36 | if [[ -z $QEMU_ARCH ]]; then |
| 37 | echo "Did not pass in required QEMU arch parameter" |
| 38 | exit -1 |
| 39 | fi |
| 40 | |
| 41 | BASE_DIR=${2:-$HOME} |
Alanny Lopez | b24dccb | 2017-07-27 10:25:50 -0500 | [diff] [blame] | 42 | # If BASE_DIR doesn't exist exit, it is required to continue |
Andrew Geissler | 0205e8d | 2016-08-10 07:46:19 -0500 | [diff] [blame] | 43 | echo "BASE_DIR = $BASE_DIR" |
| 44 | if [[ ! -d $BASE_DIR ]]; then |
| 45 | echo "No input directory and HOME not set!" |
| 46 | exit -1 |
| 47 | fi |
| 48 | |
Andrew Geissler | 7a88f29 | 2018-01-04 15:16:02 -0600 | [diff] [blame^] | 49 | # Set the location of the qemu binary relative to BASE_DIR |
| 50 | QEMU_BIN=${QEMU_BIN:-./tmp/sysroots/${QEMU_ARCH}/usr/bin/qemu-system-arm} |
| 51 | |
Alanny Lopez | b24dccb | 2017-07-27 10:25:50 -0500 | [diff] [blame] | 52 | # Enter the base directory |
Andrew Geissler | 0205e8d | 2016-08-10 07:46:19 -0500 | [diff] [blame] | 53 | cd ${BASE_DIR} |
| 54 | |
Alanny Lopez | b24dccb | 2017-07-27 10:25:50 -0500 | [diff] [blame] | 55 | # Find the correct drive file, and save its name |
| 56 | DRIVE=$(ls ./tmp/deploy/images/qemuarm | grep rootfs.ext4) |
| 57 | |
Alanny Lopez | ebf0794 | 2017-08-04 11:53:37 -0500 | [diff] [blame] | 58 | # Obtain IP from /etc/hosts if IP is not valid set to localhost |
| 59 | IP=$(awk 'END{print $1}' /etc/hosts) |
| 60 | if [[ "$IP" != *.*.*.* ]]; then |
| 61 | IP=127.0.0.1 |
| 62 | fi |
| 63 | |
Alanny Lopez | b24dccb | 2017-07-27 10:25:50 -0500 | [diff] [blame] | 64 | # Launch QEMU using the qemu-system-arm |
Andrew Geissler | 7a88f29 | 2018-01-04 15:16:02 -0600 | [diff] [blame^] | 65 | ${QEMU_BIN} \ |
Alanny Lopez | ebf0794 | 2017-08-04 11:53:37 -0500 | [diff] [blame] | 66 | -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 Geissler | 0205e8d | 2016-08-10 07:46:19 -0500 | [diff] [blame] | 68 | -machine versatilepb \ |
Alanny Lopez | b24dccb | 2017-07-27 10:25:50 -0500 | [diff] [blame] | 69 | -m 256 \ |
| 70 | -drive file=./tmp/deploy/images/qemuarm/${DRIVE},if=virtio,format=raw \ |
Andrew Geissler | 0205e8d | 2016-08-10 07:46:19 -0500 | [diff] [blame] | 71 | -show-cursor \ |
| 72 | -usb \ |
Alanny Lopez | b24dccb | 2017-07-27 10:25:50 -0500 | [diff] [blame] | 73 | -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 |