summaryrefslogtreecommitdiff
path: root/flash_tools/brillo-flashall.sh
blob: 4719e3fff28a2392defe3d77b049ff5f4764c24a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/bin/bash
#
# Copyright 2016 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Only execute this script on a Brillo provisioned MinnowBoard.
# See your Brillo-MinnowBoard online information for initial provisioning and recovery.

set -e

function dir_with_file() {
    local file=${1}; shift
    local dir;
    for dir; do
        if [ -z "${dir}" ]; then continue; fi
        if [ -r "${dir}/${file}" ]; then
            echo ${dir}
            return
        fi
    done
    echo "Could not find ${file}, looked in $@" >&2
    return 1
}

LOCAL_DIR=$(dirname "${0}")
BASE_NAME=$(basename "${0}")

if [ -z $ANDROID_SERIAL ] && [ $# == 0 ]; then
    echo "Set ANDROID_SERIAL or specify the device with -s option" >&2
    echo "Usage: ${BASE_NAME} -s tcp:<MinnowBoard IP address>" >&2
    exit 1
fi

# Location of where the Brillo OS image is built.
OS=$(dir_with_file boot.img \
    "${ANDROID_PROVISION_OS_PARTITIONS}" \
    "${LOCAL_DIR}" \
    "${BRILLO_OUT_DIR}" \
    "${ANDROID_PRODUCT_OUT}")

VENDOR=$(dir_with_file bootloader \
    "${ANDROID_PROVISION_VENDOR_PARTITIONS}" \
    "${LOCAL_DIR}" \
    "${ANDROID_BUILD_TOP}/vendor/bsp/intel/minnowboard/boot_binaries")

if [ -x "${LOCAL_DIR}"/fastboot ]; then
  FASTBOOT="${LOCAL_DIR}"/fastboot
else
  FASTBOOT=fastboot
fi

${FASTBOOT} \
    flash gpt        "${VENDOR}"/gpt.bin \
    flash bootloader "${VENDOR}"/bootloader \
    flash boot_a     "${OS}"/boot.img \
    flash boot_b     "${OS}"/boot.img \
    flash system_a   "${OS}"/system.img \
    flash system_b   "${OS}"/system.img \
    flash userdata   "${OS}"/userdata.img \
    flash oemvars    "${VENDOR}"/oemvars.txt \
    oem set_active 0 "$@"

echo "Please run the following command to restart your MinnowBoard"
echo "		${FASTBOOT} $@ reboot"
echo