• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
113  if [[ ${BISECT_PACKAGE} == sys-kernel/chromeos-kernel-* ]]; then
114    echo "/mnt/host/source/src/scripts/update_kernel.sh " \
115      "--remote=${BISECT_REMOTE} --board=${BISECT_BOARD}"
116    # exec the command to make sure it always exit after
117    exec /mnt/host/source/src/scripts/update_kernel.sh --remote=${BISECT_REMOTE} --board=${BISECT_BOARD}
118  fi
119
120  echo "cros deploy ${BISECT_REMOTE} ${BISECT_PACKAGE}"
121  cros deploy ${BISECT_REMOTE} ${BISECT_PACKAGE} --log-level=info
122
123  deploy_status=$?
124
125  if [[ ${deploy_status} -eq 0 ]] ; then
126    echo "Deploy successful. Rebooting device..."
127    reboot
128    if [[ $? -ne 0 ]] ; then
129      echo
130      echo "Could not automatically reboot device!"
131      read -p "Please manually reboot device and press enter to continue" notused
132    fi
133    exit 0
134  fi
135
136  echo "Deploy failed! Trying build_image/cros flash instead..."
137  echo
138fi
139
140echo "BUILDING IMAGE"
141pushd ~/trunk/src/scripts
142./build_image test --board=${BISECT_BOARD} --noenable_rootfs_verification --noeclean
143build_status=$?
144popd
145
146if [[ ${build_status} -eq 0 ]] ; then
147    echo
148    echo "FLASHING"
149    echo "Pushing built image onto device."
150    echo "cros flash --board=${BISECT_BOARD} --clobber-stateful ${BISECT_REMOTE} ~/trunk/src/build/images/${BISECT_BOARD}/latest/chromiumos_test_image.bin"
151    cros flash --board=${BISECT_BOARD} --clobber-stateful ${BISECT_REMOTE} ~/trunk/src/build/images/${BISECT_BOARD}/latest/chromiumos_test_image.bin
152    cros_flash_status=$?
153    while [[ ${cros_flash_status} -ne 0 ]] ; do
154        while true; do
155          echo
156          echo "cros flash has failed! From here you can:"
157          echo "1. Flash through USB"
158          echo "2. Retry flashing over ethernet"
159          echo "3. Abort this installation and skip this image"
160          echo "4. Abort this installation and mark test as failed"
161          sleep 1
162          read -p "Which method would you like to do? " choice
163          case $choice in
164              1) usb_flash && break;;
165              2) ethernet_flash && break;;
166              3) exit 125;;
167              4) exit 1;;
168              *) echo "Please answer 1, 2, 3, or 4.";;
169          esac
170        done
171
172        cros_flash_status=$?
173    done
174else
175    echo "build_image returned a non-zero status: ${build_status}"
176    exit 1
177fi
178
179exit 0
180