#!/bin/bash haveSerial=false serial="" function usage { echo -e "Usage: $(basename $0) [-s serialNumber] [IMGLIST]" echo -e " IMGLIST is a list of file in .img separated by space" echo -e " If no IMGLIST provied all the .img in the current directory will be flashed" echo -e " e.g. $(basename $0) -s 132456789 out/target/device/boot.img out/target/device/system.img" } while getopts ":s:" opt; do case $opt in s) echo "Using Serial $OPTARG" serial=$OPTARG haveSerial=true ;; \?) echo "Invalid option: -$OPTARG" >&2 usage exit 1 ;; esac done shift $(( OPTIND - 1 )) if [ $# -eq 0 ]; then imgList=$(ls *.img) echo "Flashing all images in current path $imgList" else imgList=$@ echo "Flashing $imgList" fi if [ -z "$imgList" ]; then echo "No img to Flash" exit 1 else echo "Reboot device in fastboot" if $haveSerial ; then adb -s $serial reboot bootloader; else adb reboot bootloader; fi echo "Flashing images" for img in $imgList; do imageName=$(basename $img) imageName=${imageName%.img} if $haveSerial ; then fastboot -s $serial -S 256M flash ${imageName} $img; else fastboot -S 256M flash ${imageName} $img; fi done && fastboot reboot fi