xref: /openbmc/u-boot/tools/netconsole (revision 1c27059a)
1bcb6dd91SMike Frysinger#!/bin/sh
2bcb6dd91SMike Frysinger
3bcb6dd91SMike Frysingerusage() {
4bcb6dd91SMike Frysinger	(
5*7f51898cSJoe Hershberger	echo "Usage: $0 <board-IP> [board-port [board-in-port]]"
6bcb6dd91SMike Frysinger	echo ""
7bcb6dd91SMike Frysinger	echo "If port is not specified, '6666' will be used"
8bcb6dd91SMike Frysinger	[ -z "$*" ] && exit 0
9bcb6dd91SMike Frysinger	echo ""
10bcb6dd91SMike Frysinger	echo "ERROR: $*"
11bcb6dd91SMike Frysinger	exit 1
12bcb6dd91SMike Frysinger	) 1>&2
13bcb6dd91SMike Frysinger	exit $?
14bcb6dd91SMike Frysinger}
15bcb6dd91SMike Frysinger
16bcb6dd91SMike Frysingerwhile [ -n "$1" ] ; do
17bcb6dd91SMike Frysinger	case $1 in
18bcb6dd91SMike Frysinger		-h|--help) usage;;
19bcb6dd91SMike Frysinger		--)        break;;
20bcb6dd91SMike Frysinger		-*)        usage "Invalid option $1";;
21bcb6dd91SMike Frysinger		*)         break;;
22bcb6dd91SMike Frysinger	esac
23bcb6dd91SMike Frysinger	shift
24bcb6dd91SMike Frysingerdone
25bcb6dd91SMike Frysinger
26bcb6dd91SMike Frysingerip=$1
27*7f51898cSJoe Hershbergerboard_out_port=${2:-6666}
28*7f51898cSJoe Hershbergerboard_in_port=${3:-${board_out_port}}
29bcb6dd91SMike Frysinger
30*7f51898cSJoe Hershbergerecho Board out port: ${board_out_port}
31*7f51898cSJoe Hershbergerecho Board in port: ${board_in_port}
32*7f51898cSJoe Hershberger
33*7f51898cSJoe Hershbergerif [ -z "${ip}" ] || [ -n "$4" ] ; then
34bcb6dd91SMike Frysinger	usage "Invalid number of arguments"
35bcb6dd91SMike Frysingerfi
36bcb6dd91SMike Frysinger
37bcb6dd91SMike Frysingerfor nc in netcat nc ; do
3877093180SMike Frysinger	type ${nc} >/dev/null 2>&1 && break
39bcb6dd91SMike Frysingerdone
40bcb6dd91SMike Frysinger
41bcb6dd91SMike Frysingertrap "stty icanon echo intr ^C" 0 2 3 5 10 13 15
42bcb6dd91SMike Frysingerecho "NOTE: the interrupt signal (normally ^C) has been remapped to ^T"
43bcb6dd91SMike Frysinger
44bcb6dd91SMike Frysingerstty -icanon -echo intr ^T
4577093180SMike Frysinger(
461c20e4a9SMike Frysingerif type ncb 2>/dev/null ; then
471c20e4a9SMike Frysinger	# see if ncb is in $PATH
48*7f51898cSJoe Hershberger	exec ncb ${board_out_port}
491c20e4a9SMike Frysinger
501c20e4a9SMike Frysingerelif [ -x ${0%/*}/ncb ] ; then
511c20e4a9SMike Frysinger	# maybe it's in the same dir as the netconsole script
52*7f51898cSJoe Hershberger	exec ${0%/*}/ncb ${board_out_port}
531c20e4a9SMike Frysinger
541c20e4a9SMike Frysingerelse
551c20e4a9SMike Frysinger	# blah, just use regular netcat
56*7f51898cSJoe Hershberger	while ${nc} -u -l -p ${board_out_port} < /dev/null ; do
5777093180SMike Frysinger		:
5877093180SMike Frysinger	done
591c20e4a9SMike Frysingerfi
6077093180SMike Frysinger) &
6177093180SMike Frysingerpid=$!
62*7f51898cSJoe Hershberger${nc} -u ${ip} ${board_in_port}
6377093180SMike Frysingerkill ${pid} 2>/dev/null
64