script/init.d/ethercat
author Florian Pose <fp@igh-essen.com>
Tue, 13 Feb 2007 13:01:59 +0000
changeset 563 d113b63c55c4
child 573 cdee4ea90ce9
child 1744 7bc131b92039
permissions -rwxr-xr-x
Changed structure of scripts subdirectory.
563
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     1
#!/bin/sh
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     2
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     3
#------------------------------------------------------------------------------
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     4
#
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     5
#  Init script for EtherCAT
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     6
#
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     7
#  $Id$
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     8
#
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     9
#  Copyright (C) 2006  Florian Pose, Ingenieurgemeinschaft IgH
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    10
#
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    11
#  This file is part of the IgH EtherCAT Master.
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    12
#
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    13
#  The IgH EtherCAT Master is free software; you can redistribute it
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    14
#  and/or modify it under the terms of the GNU General Public License
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    15
#  as published by the Free Software Foundation; either version 2 of the
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    16
#  License, or (at your option) any later version.
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    17
#
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    18
#  The IgH EtherCAT Master is distributed in the hope that it will be
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    19
#  useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    20
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    21
#  GNU General Public License for more details.
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    22
#
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    23
#  You should have received a copy of the GNU General Public License
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    24
#  along with the IgH EtherCAT Master; if not, write to the Free Software
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    25
#  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    26
#
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    27
#  The right to use EtherCAT Technology is granted and comes free of
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    28
#  charge under condition of compatibility of product made by
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    29
#  Licensee. People intending to distribute/sell products based on the
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    30
#  code, have to sign an agreement to guarantee that products using
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    31
#  software based on IgH EtherCAT master stay compatible with the actual
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    32
#  EtherCAT specification (which are released themselves as an open
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    33
#  standard) as the (only) precondition to have the right to use EtherCAT
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    34
#  Technology, IP and trade marks.
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    35
#
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    36
#------------------------------------------------------------------------------
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    37
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    38
### BEGIN INIT INFO
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    39
# Provides:          ethercat
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    40
# Required-Start:    $local_fs $syslog $network
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    41
# Should-Start:      $time ntp
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    42
# Required-Stop:     $local_fs $syslog $network
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    43
# Should-Stop:       $time ntp
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    44
# Default-Start:     3 5
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    45
# Default-Stop:      0 1 2 6
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    46
# Short-Description: IgH EtherCAT master modules
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    47
# Description:
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    48
### END INIT INFO
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    49
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    50
#------------------------------------------------------------------------------
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    51
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    52
device="ecxml"
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    53
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    54
IFCONFIG=ifconfig
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    55
BRCTL=brctl
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    56
ROUTE=route
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    57
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    58
#------------------------------------------------------------------------------
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    59
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    60
ETHERCAT_CONFIG=/etc/sysconfig/ethercat
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    61
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    62
if [ ! -r $ETHERCAT_CONFIG ]; then
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    63
    echo "$ETHERCAT_CONFIG not existing";
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    64
    if [ "$1" = "stop" ]; then
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    65
	exit 0
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    66
    else
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    67
	exit 6
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    68
    fi
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    69
fi
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    70
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    71
. $ETHERCAT_CONFIG
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    72
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    73
#------------------------------------------------------------------------------
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    74
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    75
#
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    76
#  Function for setting up the EoE bridge
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    77
#
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    78
build_eoe_bridge()
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    79
{
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    80
    if [ -z "$EOE_BRIDGE" ]; then return; fi
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    81
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    82
    EOEIF=`$IFCONFIG -a | grep -o -E "^eoe[0-9]+ "`
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    83
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    84
    # add bridge, if it does not already exist
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    85
    if ! $BRCTL show | grep -E -q "^$EOE_BRIDGE"; then
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    86
        if ! $BRCTL addbr $EOE_BRIDGE; then
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    87
	    /bin/false
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    88
	    rc_status -v
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    89
	    rc_exit
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    90
	fi
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    91
    fi
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    92
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    93
    # check if specified interfaces are bridged
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    94
    for interf in $EOEIF $EOE_EXTRA_INTERFACES; do
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    95
	# interface is already part of the bridge (FIXME->show $EOE_BRIDGE)
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    96
	if $BRCTL show | grep -E -q $interf
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    97
	    then continue
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    98
	fi
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    99
	# clear IP address and open interface
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   100
	if ! $IFCONFIG $interf 0.0.0.0 up; then
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   101
	    /bin/false
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   102
	    rc_status -v
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   103
	    rc_exit
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   104
	fi
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   105
	# add interface to the bridge
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   106
	if ! $BRCTL addif $EOE_BRIDGE $interf; then
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   107
	    /bin/false
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   108
	    rc_status -v
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   109
	    rc_exit
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   110
	fi
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   111
    done
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   112
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   113
    # configure IP on bridge
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   114
    if [ -n "$EOE_IP_ADDRESS" -a -n "$EOE_IP_NETMASK" ]; then
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   115
	if ! $IFCONFIG $EOE_BRIDGE $EOE_IP_ADDRESS \
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   116
	    netmask $EOE_IP_NETMASK; then
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   117
	    /bin/false
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   118
	    rc_status -v
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   119
	    rc_exit
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   120
	fi
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   121
    fi
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   122
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   123
    # open bridge
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   124
    if ! $IFCONFIG $EOE_BRIDGE up; then
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   125
	/bin/false
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   126
	rc_status -v
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   127
	rc_exit
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   128
    fi
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   129
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   130
    # install new default gateway
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   131
    if [ -n "$EOE_GATEWAY" ]; then
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   132
	while $ROUTE -n | grep -E -q "^0.0.0.0"; do
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   133
	    if ! $ROUTE del default; then
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   134
		echo "Failed to remove route!" 1>&2
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   135
		/bin/false
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   136
		rc_status -v
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   137
		rc_exit
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   138
	    fi
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   139
	done
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   140
	if ! $ROUTE add default gw $EOE_GATEWAY; then
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   141
	    /bin/false
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   142
	    rc_status -v
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   143
	    rc_exit
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   144
	fi
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   145
    fi
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   146
}
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   147
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   148
#------------------------------------------------------------------------------
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   149
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   150
. /etc/rc.status
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   151
rc_reset
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   152
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   153
case "$1" in
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   154
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   155
    start)
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   156
	echo -n "Starting EtherCAT master "
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   157
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   158
	if [ -z "$DEVICE_INDEX" ]; then
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   159
	    echo "ERROR: DEVICE_INDEX not set!"
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   160
	    /bin/false
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   161
	    rc_status -v
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   162
	    rc_exit
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   163
	fi
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   164
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   165
	if [ -z "$EOE_INTERFACES" ]; then
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   166
            # support legacy sysconfig files
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   167
	    if [ -n "$EOE_DEVICES" ]; then
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   168
		EOE_INTERFACES=$EOE_DEVICES
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   169
	    else
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   170
		EOE_INTERFACES=0
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   171
	    fi
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   172
	fi
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   173
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   174
        # unload conflicting modules at first
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   175
	for mod in 8139too; do
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   176
	    if lsmod | grep "^$mod " > /dev/null; then
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   177
		if ! rmmod $mod; then
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   178
		    /bin/false
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   179
		    rc_status -v
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   180
		    rc_exit
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   181
		fi
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   182
	    fi
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   183
	done
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   184
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   185
        # load master module
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   186
	if ! modprobe ec_master ec_eoeif_count=$EOE_INTERFACES; then
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   187
	    modprobe 8139too
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   188
	    /bin/false
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   189
	    rc_status -v
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   190
	    rc_exit
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   191
	fi
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   192
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   193
	# remove stale device node
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   194
	rm -f /dev/${device}0
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   195
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   196
	# get dynamic major number
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   197
	major=$(awk "\$2==\"EtherCAT\" {print \$1}" /proc/devices)
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   198
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   199
	# create character device
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   200
	mknod /dev/${device}0 c $major 0
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   201
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   202
	# load device module
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   203
	if ! modprobe ec_8139too ec_device_index=$DEVICE_INDEX; then
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   204
	    rmmod ec_master
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   205
	    modprobe 8139too
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   206
	    /bin/false
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   207
	    rc_status -v
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   208
	    rc_exit
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   209
	fi
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   210
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   211
	# build EoE bridge
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   212
	build_eoe_bridge
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   213
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   214
	rc_status -v
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   215
	;;
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   216
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   217
    stop)
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   218
	echo -n "Shutting down EtherCAT master "
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   219
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   220
	# unload modules
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   221
	for mod in ec_8139too ec_master; do
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   222
	    if lsmod | grep "^$mod " > /dev/null; then
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   223
		if ! rmmod $mod; then
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   224
		    /bin/false
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   225
		    rc_status -v
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   226
		    rc_exit
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   227
		fi;
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   228
	    fi;
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   229
	done
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   230
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   231
	# remove device node
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   232
	rm -f /dev/${device}0
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   233
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   234
	sleep 1
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   235
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   236
	# reload previous modules
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   237
	if ! modprobe 8139too; then
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   238
	    echo "Warning: Failed to restore 8139too module."
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   239
	fi
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   240
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   241
	rc_status -v
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   242
	;;
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   243
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   244
    restart)
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   245
	$0 stop || exit 1
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   246
	sleep 1
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   247
	$0 start
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   248
	rc_status
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   249
	;;
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   250
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   251
    status)
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   252
	echo -n "Checking for EtherCAT "
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   253
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   254
	lsmod | grep "^ec_master " > /dev/null
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   255
	master_running=$?
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   256
	lsmod | grep "^ec_8139too " > /dev/null
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   257
	device_running=$?
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   258
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   259
	# master module and device module loaded?
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   260
	test $master_running -eq 0 -a $device_running -eq 0
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   261
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   262
	rc_status -v
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   263
	;;
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   264
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   265
    bridge)
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   266
	echo -n "Building EoE bridge "
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   267
	build_eoe_bridge
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   268
	rc_status -v
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   269
	;;
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   270
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   271
    *)
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   272
	echo "USAGE: $0 {start|stop|restart|status|bridge}"
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   273
	;;
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   274
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   275
esac
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   276
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   277
rc_exit
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   278
d113b63c55c4 Changed structure of scripts subdirectory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   279
#------------------------------------------------------------------------------