xref: /openbmc/u-boot/tools/netconsole (revision 713cb680)
1#!/bin/sh
2
3usage() {
4	(
5	echo "Usage: $0 <board-IP> [board-port [board-in-port]]"
6	echo ""
7	echo "If port is not specified, '6666' will be used"
8	[ -z "$*" ] && exit 0
9	echo ""
10	echo "ERROR: $*"
11	exit 1
12	) 1>&2
13	exit $?
14}
15
16while [ -n "$1" ] ; do
17	case $1 in
18		-h|--help) usage;;
19		--)        break;;
20		-*)        usage "Invalid option $1";;
21		*)         break;;
22	esac
23	shift
24done
25
26ip=$1
27board_out_port=${2:-6666}
28board_in_port=${3:-${board_out_port}}
29
30echo Board out port: ${board_out_port}
31echo Board in port: ${board_in_port}
32
33if [ -z "${ip}" ] || [ -n "$4" ] ; then
34	usage "Invalid number of arguments"
35fi
36
37for nc in netcat nc ; do
38	type ${nc} >/dev/null 2>&1 && break
39done
40
41trap "stty icanon echo intr ^C" 0 2 3 5 10 13 15
42echo "NOTE: the interrupt signal (normally ^C) has been remapped to ^T"
43
44stty -icanon -echo intr ^T
45(
46if type ncb 2>/dev/null ; then
47	# see if ncb is in $PATH
48	exec ncb ${board_out_port}
49
50elif [ -x ${0%/*}/ncb ] ; then
51	# maybe it's in the same dir as the netconsole script
52	exec ${0%/*}/ncb ${board_out_port}
53
54else
55	# blah, just use regular netcat
56	while ${nc} -u -l -p ${board_out_port} < /dev/null ; do
57		:
58	done
59fi
60) &
61pid=$!
62${nc} -u ${ip} ${board_in_port}
63kill ${pid} 2>/dev/null
64