1#!/bin/bash
2#
3# Copyright 2010 Google Inc. All Rights Reserved.
4# Author: [email protected] (Bruce Gay)
5#
6# used for flashing bootloader image on sholes
7
8BOOTPART='motoboot'
9
10################################################
11# sets the name of the boot partition and
12# bootfile, then flashes device
13#
14# Globals:
15#   product
16#   ROOT
17#   BOOTPART
18#   bootloaderfile
19#   device
20# Arguments:
21#   None
22# Returns:
23#   None
24################################################
25flash_bootloader_image()
26{
27  if [ $product != "sholes" ]; then
28    log_print "Wrong device type, expected sholes!"
29    exit
30  fi
31  if [ "$bootloaderfile" == '' ]; then
32    log_print "getting bootloader file for $product"
33    secure=`$fastboot -s $device getvar secure 2>&1 | sed -n 's/secure: \([a-z]*\)\n*/\1/ p'`
34    if [ "$secure" = "no" ]; then
35      bootloaderfile=`ls -1 sholes/ | sed -n 's/^\(motoboot_unsecure.[0-9A-Z]*.img\)\n*/\1/ p'`
36    else
37      bootloaderfile=`ls -1 sholes/ | sed -n 's/^\(motoboot_secure.[0-9A-Z]*.img\)\n*/\1/ p'`
38    fi
39    if [ "$bootloaderfile" == '' ]; then
40      log_print "bootloader file empty: $bootloaderfile"
41      exit
42    fi
43    if [ ! -e "$ROOT/$product/$bootloaderfile" ]; then
44      log_print "bootloader file not found: ./$product/$bootloaderfile"
45      exit
46    fi
47    log_print "using $ROOT/$product/$bootloaderfile as the bootloader image file"
48  fi
49  log_print "downloading bootloader image to $device"
50  flash_partition $BOOTPART $ROOT/$product/$bootloaderfile
51  reboot_into_fastboot_from_fastboot
52}
53