summaryrefslogtreecommitdiff
path: root/scripts/contrib/serdevtry
diff options
context:
space:
mode:
authorJohn Klug <john.klug@multitech.com>2018-07-31 17:48:08 -0500
committerJohn Klug <john.klug@multitech.com>2018-07-31 17:48:08 -0500
commitb5dd8c128624cb77576d692b68e24691d4d9a96d (patch)
tree4a0cc0a718fa98582fd70719a83b826c2d990cf5 /scripts/contrib/serdevtry
parente08c220730d5da161a746d811268eb1550beb856 (diff)
downloadmlinux-b5dd8c128624cb77576d692b68e24691d4d9a96d.tar.gz
mlinux-b5dd8c128624cb77576d692b68e24691d4d9a96d.tar.bz2
mlinux-b5dd8c128624cb77576d692b68e24691d4d9a96d.zip
mLinux 4
Diffstat (limited to 'scripts/contrib/serdevtry')
-rwxr-xr-xscripts/contrib/serdevtry60
1 files changed, 60 insertions, 0 deletions
diff --git a/scripts/contrib/serdevtry b/scripts/contrib/serdevtry
new file mode 100755
index 0000000..74bd7b7
--- /dev/null
+++ b/scripts/contrib/serdevtry
@@ -0,0 +1,60 @@
+#!/bin/sh
+
+# Copyright (C) 2014 Intel Corporation
+#
+# Released under the MIT license (see COPYING.MIT)
+
+if [ "$1" = "" -o "$1" = "--help" ] ; then
+ echo "Usage: $0 <serial terminal command>"
+ echo
+ echo "Simple script to handle maintaining a terminal for serial devices that"
+ echo "disappear when a device is powered down or reset, such as the USB"
+ echo "serial console on the original BeagleBone (white version)."
+ echo
+ echo "e.g. $0 picocom -b 115200 /dev/ttyUSB0"
+ echo
+ exit
+fi
+
+args="$@"
+DEVICE=""
+while [ "$1" != "" ]; do
+ case "$1" in
+ /dev/*)
+ DEVICE=$1
+ break;;
+ esac
+ shift
+done
+
+if [ "$DEVICE" != "" ] ; then
+ while true; do
+ if [ ! -e $DEVICE ] ; then
+ echo "serdevtry: waiting for $DEVICE to exist..."
+ while [ ! -e $DEVICE ]; do
+ sleep 0.1
+ done
+ fi
+ if [ ! -w $DEVICE ] ; then
+ # Sometimes (presumably because of a race with udev) we get to
+ # the device before its permissions have been set up
+ RETRYNUM=0
+ while [ ! -w $DEVICE ]; do
+ if [ "$RETRYNUM" = "2" ] ; then
+ echo "Device $DEVICE exists but is not writable!"
+ exit 1
+ fi
+ RETRYNUM=$((RETRYNUM+1))
+ sleep 0.1
+ done
+ fi
+ $args
+ if [ -e $DEVICE ] ; then
+ break
+ fi
+ done
+else
+ echo "Unable to determine device node from command: $args"
+ exit 1
+fi
+