CHIP-tools/common.sh

92 lines
1.6 KiB
Bash
Raw Normal View History

2015-09-12 20:08:01 -04:00
#!/bin/bash
2015-09-20 12:42:16 -04:00
TIMEOUT=30
FEL=fel
2015-09-17 03:26:38 -04:00
2015-10-21 17:26:59 -04:00
#------------------------------------------------------------
2015-09-12 20:08:01 -04:00
onMac() {
if [ "$(uname)" == "Darwin" ]; then
return 0;
else
return 1;
fi
}
2015-10-21 17:26:59 -04:00
#------------------------------------------------------------
2015-09-12 20:08:01 -04:00
filesize() {
if onMac; then
2015-09-14 22:29:33 -04:00
stat -f "%z" $1
2015-09-12 20:08:01 -04:00
else
2015-09-12 23:15:36 -04:00
stat --printf="%s" $1
2015-09-12 20:08:01 -04:00
fi
}
2015-10-21 17:26:59 -04:00
#------------------------------------------------------------
wait_for_fastboot() {
echo -n "waiting for fastboot...";
for ((i=$TIMEOUT; i>0; i--)) {
if [[ ! -z "$(fastboot -i 0x1f3a $@ devices)" ]]; then
2015-10-21 17:26:59 -04:00
echo "OK";
return 0;
fi
echo -n ".";
sleep 1
}
echo "TIMEOUT";
return 1
}
#------------------------------------------------------------
wait_for_fel() {
echo -n "waiting for fel...";
for ((i=$TIMEOUT; i>0; i--)) {
if ${FEL} $@ ver 2>/dev/null >/dev/null; then
2015-10-21 17:26:59 -04:00
echo "OK"
return 0;
fi
echo -n ".";
sleep 1
}
echo "TIMEOUT";
return 1
}
#------------------------------------------------------------
wait_for_linuxboot() {
local TIMEOUT=100
echo -n "flashing...";
for ((i=$TIMEOUT; i>0; i--)) {
if lsusb |grep -q "0525:a4a7" ||
lsusb |grep -q "0525:a4aa"; then
2015-10-21 17:26:59 -04:00
echo "OK"
return 0;
fi
echo -n ".";
sleep 3
}
echo "TIMEOUT";
return 1
}
ready_to_roll() {
echo -e "\n\nFLASH VERIFICATION COMPLETE.\n\n"
echo " # # #"
echo " #########"
echo "### ###"
echo " # {#} #"
echo "### '\######"
echo " # #"
echo "### ###"
echo " ########"
echo " # # #"
echo -e "\n\nCHIP is ready to roll!\n\n"
return 0
}