Chat/ppp verification and fancy completion message

chip/stable
computermouth 6 years ago
parent d1d15e8655
commit b41c88a494
  1. 3
      chip-fel-flash.sh
  2. 4
      chip-update-firmware.sh
  3. 21
      common.sh
  4. 173
      verify.sh
  5. 8
      verify.sh.chat

@ -218,3 +218,6 @@ if [[ "${METHOD}" == "fel" ]]; then
fi
fi
rm -rf "${TMPDIR}"
ready_to_roll

@ -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

@ -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
}

@ -1,118 +1,55 @@
#!/usr/bin/env python
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
#------------------------------------------------------------------
def main():
#------------------------------------------------------------------
if( len(sys.argv)>1 ):
serial_port=sys.argv[1]
else:
serial_port='/dev/ttyACM0';
#print 'reading from %s:' % serial_port
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
#------------------------------------------------------------------
if __name__ == "__main__":
#------------------------------------------------------------------
exit( main() )
#!/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

@ -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
Loading…
Cancel
Save