Greg Hartman | 71633c8 | 2018-06-21 18:49:01 -0700 | [diff] [blame] | 1 | #!/bin/bash |
Jorge E. Moreira | a8142f9 | 2018-06-13 17:33:55 -0700 | [diff] [blame] | 2 | |
| 3 | # |
| 4 | # Copyright (C) 2018 The Android Open Source Project |
| 5 | # |
| 6 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | # you may not use this file except in compliance with the License. |
| 8 | # You may obtain a copy of the License at |
| 9 | # |
| 10 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | # |
| 12 | # Unless required by applicable law or agreed to in writing, software |
| 13 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | # See the License for the specific language governing permissions and |
| 16 | # limitations under the License. |
| 17 | # |
| 18 | |
| 19 | default_instance_number() { |
| 20 | if [[ "${USER::5}" == "vsoc-" ]]; then |
| 21 | echo "${USER: -2}" |
| 22 | else |
| 23 | echo "01" |
| 24 | fi |
| 25 | } |
| 26 | CUTTLEFISH_INSTANCE="${CUTTLEFISH_INSTANCE:-$(default_instance_number)}" |
| 27 | default_instance_name="cvd-${CUTTLEFISH_INSTANCE}" |
| 28 | default_uuid="699acfc4-c8c4-11e7-882b-5065f31dc1${CUTTLEFISH_INSTANCE}" |
Jorge E. Moreira | 285b48b | 2018-06-27 10:33:24 -0700 | [diff] [blame] | 29 | default_dir="${HOME}/cuttlefish_runtime" |
Jorge E. Moreira | a8142f9 | 2018-06-13 17:33:55 -0700 | [diff] [blame] | 30 | default_mobile_tap_name="cvd-mtap-${CUTTLEFISH_INSTANCE}" |
Jorge E. Moreira | 029dc0e | 2018-06-22 19:46:19 -0700 | [diff] [blame] | 31 | default_wifi_tap_name="cvd-wtap-${CUTTLEFISH_INSTANCE}" |
Jorge E. Moreira | a8142f9 | 2018-06-13 17:33:55 -0700 | [diff] [blame] | 32 | |
| 33 | if [[ -z "${ivshmem_vector_count}" ]]; then |
| 34 | echo "The required ivshmem_vector_count environment variable is not set" >&2 |
| 35 | exit 1 |
| 36 | fi |
| 37 | |
Greg Hartman | 71633c8 | 2018-06-21 18:49:01 -0700 | [diff] [blame] | 38 | args=( |
| 39 | -enable-kvm |
| 40 | -name "guest=${instance_name:-${default_instance_name}},debug-threads=on" |
| 41 | -machine "pc-i440fx-2.8,accel=kvm,usb=off,dump-guest-core=off" |
| 42 | -m "${memory_mb:-2048}" |
| 43 | -realtime mlock=off |
| 44 | -smp "${cpus:-2},sockets=${cpus:-2},cores=1,threads=1" |
| 45 | -uuid "${uuid:-${default_uuid}}" |
| 46 | -display none |
| 47 | -no-user-config |
| 48 | -nodefaults |
Jorge E. Moreira | 2b00301 | 2018-07-22 17:46:27 -0700 | [diff] [blame^] | 49 | -chardev "socket,id=charmonitor,path=${monitor_path:-${default_dir}/qemu_monitor.sock},nowait" |
Greg Hartman | 71633c8 | 2018-06-21 18:49:01 -0700 | [diff] [blame] | 50 | -mon "chardev=charmonitor,id=monitor,mode=control" |
| 51 | -rtc "base=utc" |
| 52 | -no-shutdown |
| 53 | -boot "strict=on" |
| 54 | -kernel "${kernel_image_path:-${HOME}/kernel}" |
| 55 | -append "${kernel_args:-"loop.max_part=7 console=ttyS0 androidboot.console=ttyS1 androidboot.hardware=vsoc enforcing=0 audit=1 androidboot.selinux=permissive mac80211_hwsim.radios=0 security=selinux buildvariant=userdebug androidboot.serialno=CUTTLEFISHCVD01 androidboot.lcd_density=160"}" |
| 56 | -dtb "${dtb_path:-${HOME}/config/cuttlefish.dtb}" |
| 57 | -device "piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2" |
Jorge E. Moreira | 029dc0e | 2018-06-22 19:46:19 -0700 | [diff] [blame] | 58 | -device "virtio-serial-pci,id=virtio-serial0,bus=pci.0,addr=0x4" |
Greg Hartman | 71633c8 | 2018-06-21 18:49:01 -0700 | [diff] [blame] | 59 | -drive "file=${system_image_path:-${HOME}/system.img},format=raw,if=none,id=drive-virtio-disk0,aio=threads" |
Jorge E. Moreira | 029dc0e | 2018-06-22 19:46:19 -0700 | [diff] [blame] | 60 | -device "virtio-blk-pci,scsi=off,bus=pci.0,addr=0x5,drive=drive-virtio-disk0,id=virtio-disk0,bootindex=1" |
Greg Hartman | 71633c8 | 2018-06-21 18:49:01 -0700 | [diff] [blame] | 61 | -drive "file=${data_image_path:-${HOME}/userdata.img},format=raw,if=none,id=drive-virtio-disk1,aio=threads" |
Jorge E. Moreira | 029dc0e | 2018-06-22 19:46:19 -0700 | [diff] [blame] | 62 | -device "virtio-blk-pci,scsi=off,bus=pci.0,addr=0x6,drive=drive-virtio-disk1,id=virtio-disk1" |
Greg Hartman | 71633c8 | 2018-06-21 18:49:01 -0700 | [diff] [blame] | 63 | -drive "file=${cache_image_path:-${HOME}/cache.img},format=raw,if=none,id=drive-virtio-disk2,aio=threads" |
Jorge E. Moreira | 029dc0e | 2018-06-22 19:46:19 -0700 | [diff] [blame] | 64 | -device "virtio-blk-pci,scsi=off,bus=pci.0,addr=0x7,drive=drive-virtio-disk2,id=virtio-disk2" |
Greg Hartman | 71633c8 | 2018-06-21 18:49:01 -0700 | [diff] [blame] | 65 | -drive "file=${vendor_image_path:-${HOME}/vendor.img},format=raw,if=none,id=drive-virtio-disk3,aio=threads" |
Jorge E. Moreira | 029dc0e | 2018-06-22 19:46:19 -0700 | [diff] [blame] | 66 | -device "virtio-blk-pci,scsi=off,bus=pci.0,addr=0x8,drive=drive-virtio-disk3,id=virtio-disk3" |
| 67 | -netdev "tap,id=hostnet0,ifname=${wifi_tap_name:-${default_wifi_tap_name}},script=no,downscript=no" |
Greg Hartman | 71633c8 | 2018-06-21 18:49:01 -0700 | [diff] [blame] | 68 | -device "virtio-net-pci,netdev=hostnet0,id=net0,bus=pci.0,addr=0x2" |
Jorge E. Moreira | 029dc0e | 2018-06-22 19:46:19 -0700 | [diff] [blame] | 69 | -netdev "tap,id=hostnet1,ifname=${mobile_tap_name:-${default_mobile_tap_name}},script=no,downscript=no" |
| 70 | -device "virtio-net-pci,netdev=hostnet1,id=net1,bus=pci.0,addr=0x3" |
Greg Hartman | 71633c8 | 2018-06-21 18:49:01 -0700 | [diff] [blame] | 71 | -chardev "socket,id=charserial0,path=${kernel_log_socket_name:-${default_dir}/kernel-log}" |
| 72 | -device "isa-serial,chardev=charserial0,id=serial0" |
| 73 | -chardev "socket,id=charserial1,path=${console_path:-${default_dir}/console},server,nowait" |
| 74 | -device "isa-serial,chardev=charserial1,id=serial1" |
| 75 | -chardev "file,id=charchannel0,path=${logcat_path:-${default_dir}/logcat},append=on" |
| 76 | -device "virtserialport,bus=virtio-serial0.0,nr=1,chardev=charchannel0,id=channel0,name=cf-logcat" |
Jorge E. Moreira | 029dc0e | 2018-06-22 19:46:19 -0700 | [diff] [blame] | 77 | -device "virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x9" |
Greg Hartman | 71633c8 | 2018-06-21 18:49:01 -0700 | [diff] [blame] | 78 | -object "rng-random,id=objrng0,filename=/dev/urandom" |
Jorge E. Moreira | 029dc0e | 2018-06-22 19:46:19 -0700 | [diff] [blame] | 79 | -device "virtio-rng-pci,rng=objrng0,id=rng0,max-bytes=1024,period=2000,bus=pci.0,addr=0xa" |
Greg Hartman | 71633c8 | 2018-06-21 18:49:01 -0700 | [diff] [blame] | 80 | -chardev "socket,path=${ivshmem_qemu_socket_path:-${default_dir}/ivshmem_socket_qemu},id=ivsocket" |
| 81 | -device "ivshmem-doorbell,chardev=ivsocket,vectors=${ivshmem_vector_count}" |
| 82 | -cpu host |
Jorge E. Moreira | a8142f9 | 2018-06-13 17:33:55 -0700 | [diff] [blame] | 83 | -msg "timestamp=on" |
Greg Hartman | 71633c8 | 2018-06-21 18:49:01 -0700 | [diff] [blame] | 84 | ) |
| 85 | |
Greg Hartman | 91f8142 | 2018-07-09 16:04:49 -0700 | [diff] [blame] | 86 | if [[ -n "${gdb_flag}" ]]; then |
| 87 | args+=(-gdb "${gdb_flag}") |
| 88 | fi |
| 89 | |
Greg Hartman | 71633c8 | 2018-06-21 18:49:01 -0700 | [diff] [blame] | 90 | if [[ -n "${ramdisk_image_path}" ]]; then |
| 91 | args+=(-initrd "${ramdisk_image_path}") |
| 92 | fi |
| 93 | |
Ryan Haining | f138357 | 2018-07-10 15:31:57 -0700 | [diff] [blame] | 94 | if [[ -n "${usb_v1_socket_name}" ]]; then |
| 95 | args+=( |
| 96 | -chardev "socket,id=charchannel1,path=${usb_v1_socket_name:-${default_dir}/usb-v1}" |
| 97 | -device "virtserialport,bus=virtio-serial0.0,nr=2,chardev=charchannel1,id=channel1,name=cf-gadget-usb-v1" |
| 98 | ) |
| 99 | fi |
Greg Hartman | 213a8a7 | 2018-06-28 23:43:40 -0700 | [diff] [blame] | 100 | printf %s "exec ${qemu_binary=/usr/bin/qemu-system-x86_64}" |
| 101 | for i in "${args[@]}"; do |
| 102 | case "$i" in |
| 103 | -*) printf "\\%s %s " $'\n' "$i" ;; |
| 104 | *) printf "%s " "$i" ;; |
| 105 | esac |
| 106 | done |
| 107 | echo |
| 108 | |
Greg Hartman | 71633c8 | 2018-06-21 18:49:01 -0700 | [diff] [blame] | 109 | exec "${qemu_binary=/usr/bin/qemu-system-x86_64}" \ |
| 110 | "${args[@]}" |