summaryrefslogtreecommitdiffstats
path: root/scripts/contrib/serdevtry
blob: 9144730e7ee471c191f1e4815e94ae0f6ddd1364 (plain)
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

@media only all and (prefers-color-scheme: dark) {
.highlight .hll { background-color: #49483e }
.highlight .c { color: #75715e } /* Comment */
.highlight .err { color: #960050; background-color: #1e0010 } /* Error */
.highlight .k { color: #66d9ef } /* Keyword */
.highlight .l { color: #ae81ff } /* Literal */
.highlight .n { color: #f8f8f2 } /* Name */
.highlight .o { color: #f92672 } /* Operator */
.highlight .p { color: #f8f8f2 } /* Punctuation */
.highlight .ch { color: #75715e } /* Comment.Hashbang */
.highlight .cm { color: #75715e } /* Comment.Multiline */
.highlight .cp { color: #75715e } /* Comment.Pr
#!/bin/sh

# Copyright (C) 2014 Intel Corporation
#
# SPDX-License-Identifier: 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