[script] Flash all
And a list if device to NEVER flash And more check
This commit is contained in:
parent
fcd9f9ab96
commit
4c8941f45b
@ -1,6 +1,9 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
haveSerial=false
|
haveSerial=false
|
||||||
serial=""
|
serial=""
|
||||||
|
used_serial=""
|
||||||
|
forbidden_serials="b06474cb"
|
||||||
|
|
||||||
function usage {
|
function usage {
|
||||||
echo -e "Usage: $(basename $0) [-s serialNumber] [IMGLIST]"
|
echo -e "Usage: $(basename $0) [-s serialNumber] [IMGLIST]"
|
||||||
echo -e " IMGLIST is a list of file in .img separated by space"
|
echo -e " IMGLIST is a list of file in .img separated by space"
|
||||||
@ -8,6 +11,76 @@ function usage {
|
|||||||
echo -e " e.g. $(basename $0) -s 132456789 out/target/device/boot.img out/target/device/system.img"
|
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
|
while getopts ":s:" opt; do
|
||||||
case $opt in
|
case $opt in
|
||||||
s) echo "Using Serial $OPTARG"
|
s) echo "Using Serial $OPTARG"
|
||||||
@ -23,9 +96,13 @@ while getopts ":s:" opt; do
|
|||||||
done
|
done
|
||||||
shift $(( OPTIND - 1 ))
|
shift $(( OPTIND - 1 ))
|
||||||
|
|
||||||
|
if $haveSerial ; then
|
||||||
|
check_forbidden_serial $serial
|
||||||
|
fi
|
||||||
|
|
||||||
if [ $# -eq 0 ];
|
if [ $# -eq 0 ];
|
||||||
then
|
then
|
||||||
imgList=$(ls *.img)
|
imgList=$(ls *.img 2>/dev/null)
|
||||||
echo "Flashing all images in current path $imgList"
|
echo "Flashing all images in current path $imgList"
|
||||||
else
|
else
|
||||||
imgList=$@
|
imgList=$@
|
||||||
@ -36,20 +113,12 @@ then
|
|||||||
echo "No img to Flash"
|
echo "No img to Flash"
|
||||||
exit 1
|
exit 1
|
||||||
else
|
else
|
||||||
echo "Reboot device in fastboot"
|
check_presence
|
||||||
if $haveSerial ; then
|
check_fastboot_serial
|
||||||
adb -s $serial reboot bootloader;
|
|
||||||
else
|
|
||||||
adb reboot bootloader;
|
|
||||||
fi
|
|
||||||
echo "Flashing images"
|
echo "Flashing images"
|
||||||
for img in $imgList; do
|
for img in $imgList; do
|
||||||
imageName=$(basename $img)
|
imageName=$(basename $img)
|
||||||
imageName=${imageName%.img}
|
imageName=${imageName%.img}
|
||||||
if $haveSerial ; then
|
echo "fastboot -s $used_serial -S 256M flash ${imageName} $img;"
|
||||||
fastboot -s $serial -S 256M flash ${imageName} $img;
|
|
||||||
else
|
|
||||||
fastboot -S 256M flash ${imageName} $img;
|
|
||||||
fi
|
|
||||||
done && fastboot reboot
|
done && fastboot reboot
|
||||||
fi
|
fi
|
||||||
|
Loading…
Reference in New Issue
Block a user