[script] Improve flash_all

images are not necessary in the current dir
Add a -s option to specify serial to use
This commit is contained in:
Mathieu Maret 2016-02-18 12:02:44 +01:00
parent b520fb7c4a
commit fcd9f9ab96

View File

@ -1,17 +1,55 @@
#!/bin/bash #!/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 ]; if [ $# -eq 0 ];
then then
imgList=$(ls *.img) imgList=$(ls *.img)
echo "Flashing all images $imgList" echo "Flashing all images in current path $imgList"
else else
imgList=$@ imgList=$@
echo "Flashing $imgList" echo "Flashing $imgList"
fi fi
if [ -z "$imgList" ]; if [ -z "$imgList" ];
then then
echo "No img to Flash" echo "No img to Flash"
exit 1 exit 1
else else
adb reboot bootloader; for img in $imgList; do fastboot flash ${img%.img} $img; done && fastboot reboot 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 fi