1#!/bin/bash
2
3# Only execute this script on a Brillo provisioned Edison.
4# See your Brillo-Edison online information for initial provisioning and recovery.
5
6set -e
7
8function dir_with_file() {
9    local file=${1}; shift
10    local dir;
11    for dir; do
12        if [ -z "${dir}" ]; then continue; fi
13        if [ -r "${dir}/${file}" ]; then
14            echo ${dir}
15            return
16        fi
17    done
18    echo "Could not find ${file}, looked in $@" >&2
19    return 1
20}
21
22LOCAL_DIR=$(dirname "${0}")
23
24# Location of where the Brillo OS image is built.
25OS=$(dir_with_file boot.img \
26    "${ANDROID_PROVISION_OS_PARTITIONS}" \
27    "${LOCAL_DIR}" \
28    "${BRILLO_OUT_DIR}" \
29    "${ANDROID_PRODUCT_OUT}")
30
31# Location of binary blobs supplied by the vendor.
32VENDOR=$(dir_with_file u-boot-edison.bin \
33    "${ANDROID_PROVISION_VENDOR_PARTITIONS}" \
34    "${LOCAL_DIR}" \
35    "${ANDROID_BUILD_TOP}/vendor/bsp/intel/edison/uboot_firmware")
36
37fastboot flash gpt     "${VENDOR}"/gpt.bin \
38	flash u-boot   "${VENDOR}"/u-boot-edison.bin \
39	flash boot_a   "${OS}"/boot.img \
40	flash system_a "${OS}"/system.img \
41	flash boot_b   "${OS}"/boot.img \
42	flash system_b "${OS}"/system.img \
43	flash userdata "${OS}"/userdata.img \
44	oem set_active 0 "$@"
45
46