1#!/bin/bash 2# 3# Copyright 2016 Google Inc. All Rights Reserved. 4# 5# This is the test setup script for generating an Android image based off the 6# current working build tree. make is called to relink the object files and 7# generate the new Android image to be flashed. The device is then rebooted into 8# bootloader mode and fastboot is used to flash the new image. The device is 9# then rebooted so the user's test script can run. 10# 11# This script is intended to be used by binary_search_state.py, as 12# part of the binary search triage on the Android source tree. It should 13# return '0' if the setup succeeds; and '1' if the setup fails (the image 14# could not build or be flashed). 15# 16 17source android/common.sh 18 19manual_flash() 20{ 21 echo 22 echo "Please manually flash the built image to your device." 23 echo "To do so follow these steps:" 24 echo " 1. Boot your device into fastboot mode." 25 echo " 2. cd to '${BISECT_ANDROID_SRC}'" 26 echo " 2. Run 'source build/envsetup.sh'" 27 echo " 3. Run 'lunch'" 28 echo " 4. Run '${ADB_DEVICE}fastboot flashall -w'" 29 echo "Or see the following link for more in depth steps:" 30 echo "https://source.android.com/source/running.html" 31 echo 32 while true; do 33 sleep 1 34 read -p "Was the flashing of the image successful? " choice 35 case $choice in 36 [Yy]*) return 0;; 37 [Nn]*) return 1;; 38 *) echo "Please answer y or n.";; 39 esac 40 done 41} 42 43auto_flash() 44{ 45 echo 46 echo "Please ensure your Android device is on and in fastboot mode so" 47 echo "fastboot flash may run." 48 echo 49 sleep 1 50 read -p $'Press enter to continue and retry the flashing' notused 51 52 echo " ${ADB_DEVICE}fastboot flashall -w" 53 fastboot flashall -w 54} 55 56flash() 57{ 58 echo 59 echo "FLASHING" 60 echo "Rebooting device into fastboot mode." 61 echo " ${ADB_DEVICE}adb reboot bootloader" 62 adb reboot bootloader 63 64 echo 65 echo "Waiting for device to reach fastboot mode." 66 echo "(will timeout after 60 seconds)" 67 # fastboot will block indefinitely until device comes online. 68 # Grab random variable to test if device is online. 69 # If takes >60s then we error out and ask the user for help. 70 timeout 60 fastboot getvar 0 2>/dev/null 71 fastboot_flash_status=$? 72 73 if [[ ${fastboot_flash_status} -eq 0 ]]; then 74 echo 75 echo "Flashing image." 76 echo " ${ADB_DEVICE}fastboot flashall -w" 77 fastboot flashall -w 78 fastboot_flash_status=$? 79 fi 80 81 while [[ ${fastboot_flash_status} -ne 0 ]] ; do 82 echo 83 echo "fastboot flash has failed! From here you can:" 84 echo "1. Debug and/or flash manually" 85 echo "2. Retry flashing automatically" 86 echo "3. Abort this installation and skip this image" 87 echo "4. Abort this installation and mark test as failed" 88 sleep 1 89 read -p "Which method would you like to do? " choice 90 case $choice in 91 1) manual_flash && break;; 92 2) auto_flash && break;; 93 3) return 125;; 94 4) return 1;; 95 *) echo "Please answer 1, 2, 3, or 4.";; 96 esac 97 done 98} 99 100# Number of jobs make will use. Can be customized and played with. 101MAKE_JOBS=${BISECT_NUM_JOBS} 102 103# Set ADB_DEVICE to "ANDROID_SERIAL=${ANDROID_SERIAL}" or "" if device id not 104# set. This is used for debugging info so users can confirm which device 105# commands are being sent to. 106ADB_DEVICE=${ANDROID_SERIAL:+"ANDROID_SERIAL=${ANDROID_SERIAL} "} 107 108echo 109echo "INSTALLATION BEGIN" 110echo 111 112cd ${BISECT_ANDROID_SRC} 113 114echo "BUILDING IMAGE" 115 116make -j ${MAKE_JOBS} 117make_status=$? 118 119exit_val=0 120if [[ ${make_status} -eq 0 ]]; then 121 flash 122 exit_val=$? 123else 124 echo "ERROR:" 125 echo "make returned a non-zero status: ${make_status}. Skipping image..." 126 exit_val=1 127fi 128 129 130exit ${exit_val} 131