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