[script] Flash all

And a list if device to NEVER flash
And more check
This commit is contained in:
Mathieu Maret 2016-02-18 15:38:50 +01:00
parent fcd9f9ab96
commit 4c8941f45b

View File

@ -1,11 +1,84 @@
#!/bin/bash
haveSerial=false
serial=""
used_serial=""
forbidden_serials="b06474cb"
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"
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"
}
function check_forbidden_serial {
if [[ $forbidden_serials =~ $1 ]]; then
echo "Error: You should not flash this device !"
echo " Goodbye!"
exit 1
fi
}
function check_fastboot_serial {
serials=$(fastboot devices | grep "fastboot" | awk '{print $1}')
nb_device=$(fastboot devices | grep "fastboot" | wc -l)
if $haveSerial; then
if [[ ! $serials =~ $serial ]]; then
echo "Cannot find provided serial $serial: Expecting the device to be rebooting in fastboot mode "
fi
used_serial=$serial
elif [[ $nb_device != 1 ]]; then
echo "Error: Too much device connected!"
echo " Provide a serial number with -s option or disconnect a device"
exit 1
else
used_serial=$serials
fi
check_forbidden_serial $used_serial
}
function reboot_and_wait_for_device {
check_forbidden_serial $1
adb -s $1 reboot bootloader;
fastboot devices | grep $1 >/dev/null 2>1
while [ $? == 1 ]; do
sleep 1;
echo "Waiting for $1 in fastboot mode..."
fastboot devices | grep $1 >/dev/null 2>1
done
}
function check_presence {
if $haveSerial ; then
fastboot devices | grep $serial >/dev/null 2>1
if [[ $? == 1 ]] ; then
adb devices | grep $serial >/dev/null 2>1
if [[ $? == 0 ]] ; then
reboot_and_wait_for_device $serial
else
echo "Error: Cannot found device $seial"
exit 1;
fi
fi
else
nb_dev=$(fastboot devices | grep "fastboot" | wc -l)
if [[ $nb_dev == 0 ]]; then
nb_dev=$(adb devices | grep "\<device\>"| wc -l )
if [[ $nb_dev == 0 ]]; then
echo "Error: Cannot found any device in fastboot or adb mode"
exit 1;
elif [[ $nb_dev == 1 ]]; then
dev=$(adb devices | grep "\<device\>" | awk '{print $1}')
echo "Reboot device $dev in fastboot mode"
serial=$dev
haveSerial=true
reboot_and_wait_for_device $serial
else
echo "Too much adb devices connected. Select one with -s or disconnect a device or reboot one in fastboot mode"
exit 1
fi
fi
fi
}
while getopts ":s:" opt; do
@ -23,9 +96,13 @@ while getopts ":s:" opt; do
done
shift $(( OPTIND - 1 ))
if $haveSerial ; then
check_forbidden_serial $serial
fi
if [ $# -eq 0 ];
then
imgList=$(ls *.img)
imgList=$(ls *.img 2>/dev/null)
echo "Flashing all images in current path $imgList"
else
imgList=$@
@ -36,20 +113,12 @@ 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
check_presence
check_fastboot_serial
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
echo "fastboot -s $used_serial -S 256M flash ${imageName} $img;"
done && fastboot reboot
fi