From b41c88a4941130c171995b0553b909835b30ee40 Mon Sep 17 00:00:00 2001 From: computermouth Date: Sun, 11 Sep 2016 03:16:08 -0700 Subject: [PATCH] Chat/ppp verification and fancy completion message --- chip-fel-flash.sh | 3 + chip-update-firmware.sh | 4 +- common.sh | 21 +++++- verify.sh | 155 ++++++++++++---------------------------- verify.sh.chat | 8 +++ 5 files changed, 78 insertions(+), 113 deletions(-) create mode 100644 verify.sh.chat diff --git a/chip-fel-flash.sh b/chip-fel-flash.sh index 0896fbd..e11a631 100755 --- a/chip-fel-flash.sh +++ b/chip-fel-flash.sh @@ -218,3 +218,6 @@ if [[ "${METHOD}" == "fel" ]]; then fi fi rm -rf "${TMPDIR}" + +ready_to_roll + diff --git a/chip-update-firmware.sh b/chip-update-firmware.sh index 062a2f7..a6d5fbb 100755 --- a/chip-update-firmware.sh +++ b/chip-update-firmware.sh @@ -1,7 +1,5 @@ #!/bin/bash -set -x - SCRIPTDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) source $SCRIPTDIR/common.sh @@ -191,4 +189,4 @@ if [[ "${METHOD}" == "fel" ]]; then fi fi - +ready_to_roll diff --git a/common.sh b/common.sh index b619f54..7b1eca7 100755 --- a/common.sh +++ b/common.sh @@ -58,7 +58,8 @@ wait_for_linuxboot() { local TIMEOUT=100 echo -n "flashing..."; for ((i=$TIMEOUT; i>0; i--)) { - if lsusb |grep -q "0525:a4a7"; then + if lsusb |grep -q "0525:a4a7" || + lsusb |grep -q "0525:a4aa"; then echo "OK" return 0; fi @@ -70,3 +71,21 @@ wait_for_linuxboot() { 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 +} diff --git a/verify.sh b/verify.sh index 2a918c0..38934ef 100755 --- a/verify.sh +++ b/verify.sh @@ -1,118 +1,55 @@ -#!/usr/bin/env python +#!/bin/bash -import io -import sys -import serial -import re -import time - -#------------------------------------------------------------------ -def answer_prompt(sio,prompt_to_wait_for,answer_to_write,send_cr=True): -#------------------------------------------------------------------ - sio.flush() - prompt_found = False - data = '' - #if send_cr: - #sio.write(unicode('\n')) - - d='something' - while not len(d)==0: - d = sio.read(2000); - data += d - time.sleep(1) -# print '-' * 50 -# print ' %d bytes read' % (len(data)) -# print '-' * 50 - - #print data - - line='' - while not prompt_found: - d = sio.read(100); - data += d -# print '-' * 50 -# print ' %d bytes read' % (len(data)) -# print '-' * 50 -# print data -# print '-' * 50 - if len(data.split())>0: - line=data.split()[-1] -# print "matching [%s] against [%s]" % (line,prompt_to_wait_for) - if(re.match(prompt_to_wait_for,line,re.M)): - sio.write(unicode(answer_to_write+'\n')) -# print '-' * 50 -# print ' detected [%s] ' % prompt_to_wait_for -# print '-' * 50 - prompt_found = True - else: - if send_cr: - sio.write(unicode('\n')) - sio.flush() - #sys.stdin.readline() - -#------------------------------------------------------------------ -def scanfor(sio,regexp_to_scan_for,answer_to_write): -#------------------------------------------------------------------ - prompt_found = False - data = '' - while not prompt_found: - data += sio.read(100); -# print '-' * 50 -# print ' %d bytes read' % (len(data)) -# print '-' * 50 -# print data - if re.search(regexp_to_scan_for,data): -# print '-' * 50 -# print ' detected [%s] ' % regexp_to_scan_for -# print '-' * 50 - sio.write(unicode(answer_to_write+'\n')) - prompt_found = True - sio.flush() - return data +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}" -#------------------------------------------------------------------ -def main(): -#------------------------------------------------------------------ +UART_DEVICE=ttyACM0 +GETTY_UART_SERVICE="serial-getty@${UART_DEVICE}.service" +GETTY_DISABLED=0 - if( len(sys.argv)>1 ): - serial_port=sys.argv[1] - else: - serial_port='/dev/ttyACM0'; +export TIMEOUT=3 - #print 'reading from %s:' % serial_port +#echo "DUT_UART_RUN=$DUT_UART_RUN" - ser = serial.Serial(serial_port,115200, timeout=1); - sio = io.TextIOWrapper(io.BufferedRWPair(ser,ser)) - - #login - - print "login...", - sys.stdout.flush() - answer_prompt(sio,'.*login:','chip',True) - print "OK\npassword...", - sys.stdout.flush() - answer_prompt(sio,'.*Password:','chip',False) - print "OK\npoweroff...", - sys.stdout.flush() - answer_prompt(sio,'.*[\$#]','sudo poweroff') - answer_prompt(sio,'.*:','chip') - time.sleep(2) - print "OK\n", - #d=scanfor(sio,r'.*### [^#]+ ###.*','poweroff') -# if re.search(r'.*### ALL TESTS PASSED ###.*',d): -# print "---> TESTS PASSED" -# ser.close(); -# return 0 - - ser.close(); - -# print "---> TESTS FAILED" - return 0 +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 -#------------------------------------------------------------------ -if __name__ == "__main__": -#------------------------------------------------------------------ - exit( main() ) +[[ -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}\ + && 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 diff --git a/verify.sh.chat b/verify.sh.chat new file mode 100644 index 0000000..73c9f67 --- /dev/null +++ b/verify.sh.chat @@ -0,0 +1,8 @@ +SAY "\n [ACM] Trying to login..." +TIMEOUT 40 +'' \n ogin:-\n-login: root\n assword: chip\n '# ' '' +SAY "\n [ACM] Successfully logged in" +TIMEOUT 40 +'# ' '/sbin/poweroff' +SAY "\n [ACM] Powering off..." +TIMEOUT 40