1#!/bin/bash 2# 3# Copyright 2016 Google Inc. All Rights Reserved. 4# 5# This is a generic ChromeOS package/image test setup script. It is meant to 6# be used for either the object file or package bisection tools. This script 7# does one of the following depending on what ${BISECT_MODE} is set to: 8# 9# 1) ${BISECT_MODE} is PACKAGE_MODE: 10# build_image is called and generates a new ChromeOS image using whatever 11# packages are currently in the build tree. This image is then pushed to the 12# remote machine using flash over ethernet (or usb flash if ethernet flash 13# fails). 14# 15# 2) ${BISECT_MODE} is OBJECT_MODE: 16# emerge is called for ${BISECT_PACKAGE} and generates a build for said 17# package. This package is then deployed to the remote machine and the machine 18# is rebooted. If deploying fails then a new ChromeOS image is built from 19# scratch and pushed to the machine like in PACKAGE_MODE. 20# 21# This script is intended to be used by binary_search_state.py, as 22# part of the binary search triage on ChromeOS objects and packages. It should 23# return '0' if the setup succeeds; and '1' if the setup fails (the image 24# could not build or be flashed). 25# 26 27export PYTHONUNBUFFERED=1 28 29source common/common.sh 30 31usb_flash() 32{ 33 echo 34 echo "Insert a usb stick into the current machine" 35 echo "Note: The cros flash will take time and doesn't give much output." 36 echo " Be patient. If your usb access light is flashing it's working." 37 sleep 1 38 read -p "Press enter to continue" notused 39 40 cros flash --board=${BISECT_BOARD} --clobber-stateful usb:// ~/trunk/src/build/images/${BISECT_BOARD}/latest/chromiumos_test_image.bin 41 42 echo 43 echo "Flash to usb complete!" 44 echo "Plug the usb into your chromebook and install the image." 45 echo "Refer to the ChromiumOS Developer's Handbook for more details." 46 echo "http://www.chromium.org/chromium-os/developer-guide#TOC-Boot-from-your-USB-disk" 47 while true; do 48 sleep 1 49 read -p "Was the installation of the image successful? " choice 50 case $choice in 51 [Yy]*) return 0;; 52 [Nn]*) return 1;; 53 *) echo "Please answer y or n.";; 54 esac 55 done 56} 57 58ethernet_flash() 59{ 60 echo 61 echo "Please ensure your Chromebook is up and running Chrome so" 62 echo "cros flash may run." 63 echo "If your Chromebook has a broken image you can try:" 64 echo "1. Rebooting your Chromebook 6 times to install the last working image" 65 echo "2. Alternatively, running the following command on the Chromebook" 66 echo " will also rollback to the last working image:" 67 echo " 'update_engine_client --rollback --nopowerwash --reboot'" 68 echo "3. Flashing a new image through USB" 69 echo 70 sleep 1 71 read -p $'Press enter to continue and retry the ethernet flash' notused 72 cros flash --board=${BISECT_BOARD} --clobber-stateful ${BISECT_REMOTE} ~/trunk/src/build/images/${BISECT_BOARD}/latest/chromiumos_test_image.bin 73} 74 75reboot() 76{ 77 ret_val=0 78 pushd ~/trunk/src/scripts > /dev/null 79 set -- --remote=${BISECT_REMOTE} 80 . ./common.sh || ret_val=1 81 . ./remote_access.sh || ret_val=1 82 TMP=$(mktemp -d) 83 FLAGS "$@" || ret_val=1 84 remote_access_init || ret_val=1 85 remote_reboot || ret_val=1 86 popd > /dev/null 87 88 return $ret_val 89} 90 91echo 92echo "INSTALLATION BEGIN" 93echo 94 95if [[ "${BISECT_MODE}" == "OBJECT_MODE" ]]; then 96 echo "EMERGING ${BISECT_PACKAGE}" 97 echo "sudo rm -rf /build/${BISECT_BOARD}/var/cache/portage/*" 98 sudo rm -rf /build/${BISECT_BOARD}/var/cache/portage/* 99 echo "sudo rm -rf /build/${BISECT_BOARD}/tmp/portage/${BISECT_PACKAGE}*" 100 sudo rm -rf /build/${BISECT_BOARD}/tmp/portage/${BISECT_PACKAGE}* 101 CLEAN_DELAY=0 emerge-${BISECT_BOARD} -C ${BISECT_PACKAGE} 102 emerge-${BISECT_BOARD} ${BISECT_PACKAGE} 103 emerge_status=$? 104 105 if [[ ${emerge_status} -ne 0 ]] ; then 106 echo "emerging ${BISECT_PACKAGE} returned a non-zero status: $emerge_status" 107 exit 1 108 fi 109 110 echo 111 echo "DEPLOYING" 112 if [[ ${PACKAGE} == sys-kernel/chromeos-kernel-* ]]; then 113 echo "/mnt/host/source/src/scripts/update_kernel.sh \ 114 --remote=${BISECT_REMOTE}" 115 /mnt/host/source/src/scripts/update_kernel.sh --remote=${BISECT_REMOTE} 116 else 117 echo "cros deploy ${BISECT_REMOTE} ${BISECT_PACKAGE}" 118 cros deploy ${BISECT_REMOTE} ${BISECT_PACKAGE} --log-level=info 119 fi 120 121 deploy_status=$? 122 123 if [[ ${deploy_status} -eq 0 ]] ; then 124 echo "Deploy successful. Rebooting device..." 125 reboot 126 if [[ $? -ne 0 ]] ; then 127 echo 128 echo "Could not automatically reboot device!" 129 read -p "Please manually reboot device and press enter to continue" notused 130 fi 131 exit 0 132 fi 133 134 echo "Deploy failed! Trying build_image/cros flash instead..." 135 echo 136fi 137 138echo "BUILDING IMAGE" 139pushd ~/trunk/src/scripts 140./build_image test --board=${BISECT_BOARD} --noenable_rootfs_verification --noeclean 141build_status=$? 142popd 143 144if [[ ${build_status} -eq 0 ]] ; then 145 echo 146 echo "FLASHING" 147 echo "Pushing built image onto device." 148 echo "cros flash --board=${BISECT_BOARD} --clobber-stateful ${BISECT_REMOTE} ~/trunk/src/build/images/${BISECT_BOARD}/latest/chromiumos_test_image.bin" 149 cros flash --board=${BISECT_BOARD} --clobber-stateful ${BISECT_REMOTE} ~/trunk/src/build/images/${BISECT_BOARD}/latest/chromiumos_test_image.bin 150 cros_flash_status=$? 151 while [[ ${cros_flash_status} -ne 0 ]] ; do 152 while true; do 153 echo 154 echo "cros flash has failed! From here you can:" 155 echo "1. Flash through USB" 156 echo "2. Retry flashing over ethernet" 157 echo "3. Abort this installation and skip this image" 158 echo "4. Abort this installation and mark test as failed" 159 sleep 1 160 read -p "Which method would you like to do? " choice 161 case $choice in 162 1) usb_flash && break;; 163 2) ethernet_flash && break;; 164 3) exit 125;; 165 4) exit 1;; 166 *) echo "Please answer 1, 2, 3, or 4.";; 167 esac 168 done 169 170 cros_flash_status=$? 171 done 172else 173 echo "build_image returned a non-zero status: ${build_status}" 174 exit 1 175fi 176 177exit 0 178