forked from alxgcrz/chip-tools
-
Notifications
You must be signed in to change notification settings - Fork 3
/
verify.sh
55 lines (44 loc) · 1.34 KB
/
verify.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/bash
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
SCRIPT_NAME="$(basename $0)"
CHAT_SCRIPT="${SCRIPT_DIR}/${SCRIPT_NAME}.chat"
CHAT_BIN="$(which chat)"
CHAT_BIN="${CHAT_BIN:-/usr/sbin/chat}"
UART_DEVICE=ttyACM0
GETTY_UART_SERVICE="serial-getty@${UART_DEVICE}.service"
GETTY_DISABLED=0
export TIMEOUT=3
#echo "DUT_UART_RUN=$DUT_UART_RUN"
while getopts "t:" opt; do
case $opt in
t)
TIMEOUT="${OPTARG}"
echo "timeout set to ${TIMEOUT}"
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
esac
done
shift $((OPTIND-1))
export DUT_UART_PARAMETER="$@"
if [[ "$(systemctl is-active $GETTY_UART_SERVICE)" == "active" ]]; then
echo "stopping $GETTY_UART_SERVICE"
systemctl stop $GETTY_UART_SERVICE
GETTY_DISABLED=1
fi
[[ -r "${CHAT_SCRIPT}" ]] || (echo "ERROR: can not read ${CHAT_SCRIPT}" && exit 1)
[[ -r "${CHAT_BIN}" ]] || (echo -e "ERROR: ${CHAT_BIN} not found\n -- 'sudo apt-get install ppp'" && exit 1)
for i in `seq 1 3`;
do
echo -e "Waiting for serial gadget...Attempt(${i}/3)"
/usr/sbin/chat -t $TIMEOUT -E -V -f "${CHAT_SCRIPT}" </dev/${UART_DEVICE} >/dev/${UART_DEVICE}\
&& break\
|| (echo -e "ERROR: failed to verify\n" && exit 1)
done
echo "SUCCESS: CHIP is powering down"
if [[ ${GETTY_DISABLED} == 1 ]]; then
echo "starting $GETTY_UART_SERVICE"
systemctl start $GETTY_UART_SERVICE
fi