diff options
author | Paul Eggleton <paul.eggleton@linux.intel.com> | 2014-04-30 13:32:02 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2014-04-30 21:52:32 +0100 |
commit | d20eedb18d62f719feab372d89fad0ca8a695aba (patch) | |
tree | 600dd79b7aa574b269009961aedb472d16ed8501 /scripts | |
parent | abdd8e708d5fd9bc1491fd041bd2072f57d9bec0 (diff) | |
download | poky-d20eedb18d62f719feab372d89fad0ca8a695aba.tar.gz |
scripts/contrib/serdevtry: add script to handle transient serial terminals
When running automated tests (or just generally interacting with)
boards whose serial console devices are on the board itself and thus
disappear when powered down or practically disconnected, such as the
BeagleBone white, some terminal programs (e.g. picocom) will exit when
the device disappears and need to be restarted after the serial device
returns. This script handles this automatically for such terminal
programs.
(From OE-Core rev: 0537269df779532245eb2954e04fc26b3edfed85)
Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/contrib/serdevtry | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/scripts/contrib/serdevtry b/scripts/contrib/serdevtry new file mode 100755 index 0000000000..74bd7b7161 --- /dev/null +++ b/scripts/contrib/serdevtry | |||
@@ -0,0 +1,60 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | # Copyright (C) 2014 Intel Corporation | ||
4 | # | ||
5 | # Released under the MIT license (see COPYING.MIT) | ||
6 | |||
7 | if [ "$1" = "" -o "$1" = "--help" ] ; then | ||
8 | echo "Usage: $0 <serial terminal command>" | ||
9 | echo | ||
10 | echo "Simple script to handle maintaining a terminal for serial devices that" | ||
11 | echo "disappear when a device is powered down or reset, such as the USB" | ||
12 | echo "serial console on the original BeagleBone (white version)." | ||
13 | echo | ||
14 | echo "e.g. $0 picocom -b 115200 /dev/ttyUSB0" | ||
15 | echo | ||
16 | exit | ||
17 | fi | ||
18 | |||
19 | args="$@" | ||
20 | DEVICE="" | ||
21 | while [ "$1" != "" ]; do | ||
22 | case "$1" in | ||
23 | /dev/*) | ||
24 | DEVICE=$1 | ||
25 | break;; | ||
26 | esac | ||
27 | shift | ||
28 | done | ||
29 | |||
30 | if [ "$DEVICE" != "" ] ; then | ||
31 | while true; do | ||
32 | if [ ! -e $DEVICE ] ; then | ||
33 | echo "serdevtry: waiting for $DEVICE to exist..." | ||
34 | while [ ! -e $DEVICE ]; do | ||
35 | sleep 0.1 | ||
36 | done | ||
37 | fi | ||
38 | if [ ! -w $DEVICE ] ; then | ||
39 | # Sometimes (presumably because of a race with udev) we get to | ||
40 | # the device before its permissions have been set up | ||
41 | RETRYNUM=0 | ||
42 | while [ ! -w $DEVICE ]; do | ||
43 | if [ "$RETRYNUM" = "2" ] ; then | ||
44 | echo "Device $DEVICE exists but is not writable!" | ||
45 | exit 1 | ||
46 | fi | ||
47 | RETRYNUM=$((RETRYNUM+1)) | ||
48 | sleep 0.1 | ||
49 | done | ||
50 | fi | ||
51 | $args | ||
52 | if [ -e $DEVICE ] ; then | ||
53 | break | ||
54 | fi | ||
55 | done | ||
56 | else | ||
57 | echo "Unable to determine device node from command: $args" | ||
58 | exit 1 | ||
59 | fi | ||
60 | |||