fp@169: #!/bin/sh fp@169: fp@169: #------------------------------------------------------------------------------ fp@169: # fp@247: # Init script for EtherCAT fp@169: # fp@169: # $Id$ fp@169: # fp@197: # Copyright (C) 2006 Florian Pose, Ingenieurgemeinschaft IgH fp@197: # fp@197: # This file is part of the IgH EtherCAT Master. fp@197: # fp@197: # The IgH EtherCAT Master is free software; you can redistribute it fp@197: # and/or modify it under the terms of the GNU General Public License fp@246: # as published by the Free Software Foundation; either version 2 of the fp@246: # License, or (at your option) any later version. fp@197: # fp@197: # The IgH EtherCAT Master is distributed in the hope that it will be fp@197: # useful, but WITHOUT ANY WARRANTY; without even the implied warranty of fp@197: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the fp@197: # GNU General Public License for more details. fp@197: # fp@197: # You should have received a copy of the GNU General Public License fp@197: # along with the IgH EtherCAT Master; if not, write to the Free Software fp@197: # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA fp@197: # fp@246: # The right to use EtherCAT Technology is granted and comes free of fp@246: # charge under condition of compatibility of product made by fp@246: # Licensee. People intending to distribute/sell products based on the fp@246: # code, have to sign an agreement to guarantee that products using fp@246: # software based on IgH EtherCAT master stay compatible with the actual fp@246: # EtherCAT specification (which are released themselves as an open fp@246: # standard) as the (only) precondition to have the right to use EtherCAT fp@246: # Technology, IP and trade marks. fp@246: # fp@169: #------------------------------------------------------------------------------ fp@169: fp@243: ### BEGIN INIT INFO fp@248: # Provides: ethercat fp@245: # Required-Start: $local_fs $syslog $network fp@1715: # Should-Start: $time ntp fp@245: # Required-Stop: $local_fs $syslog $network fp@1715: # Should-Stop: $time ntp fp@243: # Default-Start: 3 5 fp@243: # Default-Stop: 0 1 2 6 fp@247: # Short-Description: IgH EtherCAT master modules fp@243: # Description: fp@243: ### END INIT INFO fp@169: fp@169: #------------------------------------------------------------------------------ fp@169: fp@243: ETHERCAT_CONFIG=/etc/sysconfig/ethercat fp@169: fp@1715: if [ ! -r $ETHERCAT_CONFIG ]; then fp@1723: echo "$ETHERCAT_CONFIG not existing"; fp@1723: if [ "$1" = "stop" ]; then fp@1723: exit 0 fp@1723: else fp@1723: exit 6 fp@1723: fi fp@1715: fi fp@243: fp@243: . $ETHERCAT_CONFIG fp@169: fp@169: #------------------------------------------------------------------------------ fp@169: fp@289: # fp@289: # Function for setting up the EoE bridge fp@289: # fp@1715: build_eoe_bridge() fp@1715: { fp@1723: if [ -z "$EOE_BRIDGE" ]; then return; fi fp@1723: fp@1723: EOEIF=`/sbin/ifconfig -a | grep -o -E "^eoe[0-9]+ "` fp@1723: fp@1723: # add bridge, if it does not already exist fp@1723: if ! /sbin/brctl show | grep -E -q "^$EOE_BRIDGE"; then fp@1723: if ! /sbin/brctl addbr $EOE_BRIDGE; then fp@1723: /bin/false fp@1723: rc_status -v fp@1723: rc_exit fp@1723: fi fp@1723: fi fp@1715: fp@1715: # check if specified interfaces are bridged fp@1723: for interf in $EOEIF $EOE_EXTRA_INTERFACES; do fp@1723: # interface is already part of the bridge fp@1723: if /sbin/brctl show $EOE_BRIDGE | grep -E -q $interf fp@1723: then continue fp@1723: fi fp@1723: # clear IP address and open interface fp@1723: if ! /sbin/ifconfig $interf 0.0.0.0 up; then fp@1723: /bin/false fp@1723: rc_status -v fp@1723: rc_exit fp@1723: fi fp@1723: # add interface to the bridge fp@1723: if ! /sbin/brctl addif $EOE_BRIDGE $interf; then fp@1723: /bin/false fp@1723: rc_status -v fp@1723: rc_exit fp@1723: fi fp@1723: done fp@1723: fp@1723: # configure IP on bridge fp@1723: if [ -n "$EOE_IP_ADDRESS" -a -n "$EOE_IP_NETMASK" ]; then fp@1723: if ! /sbin/ifconfig $EOE_BRIDGE $EOE_IP_ADDRESS \ fp@1723: netmask $EOE_IP_NETMASK; then fp@1723: /bin/false fp@1723: rc_status -v fp@1723: rc_exit fp@1723: fi fp@1723: fi fp@1723: fp@1723: # open bridge fp@1723: if ! /sbin/ifconfig $EOE_BRIDGE up; then fp@1723: /bin/false fp@1723: rc_status -v fp@1723: rc_exit fp@1723: fi fp@1723: fp@1723: # install new default gateway fp@1723: if [ -n "$EOE_GATEWAY" ]; then fp@1723: while /sbin/route -n | grep -E -q "^0.0.0.0"; do fp@1723: if ! /sbin/route del default; then fp@1723: echo "Failed to remove route!" 1>&2 fp@1715: /bin/false fp@289: rc_status -v fp@289: rc_exit fp@1723: fi fp@1723: done fp@1723: if ! /sbin/route add default gw $EOE_GATEWAY; then fp@1723: /bin/false fp@1723: rc_status -v fp@1723: rc_exit fp@1723: fi fp@1723: fi fp@289: } fp@289: fp@289: #------------------------------------------------------------------------------ fp@289: fp@243: . /etc/rc.status fp@243: rc_reset fp@169: fp@243: case "$1" in fp@1715: fp@243: start) fp@1723: echo -n "Starting EtherCAT master " fp@1723: fp@1723: if [ -z "$DEVICE_INDEX" ]; then fp@1723: echo "ERROR: DEVICE_INDEX not set!" fp@1723: /bin/false fp@1723: rc_status -v fp@1723: rc_exit fp@1723: fi fp@1723: fp@1723: if [ -z "$EOE_INTERFACES" ]; then fp@1723: if [ -n "$EOE_DEVICES" ]; then # support legacy sysconfig files fp@1723: EOE_INTERFACES=$EOE_DEVICES fp@1723: else fp@1723: EOE_INTERFACES=0 fp@1723: fi fp@1723: fi fp@1723: fp@1723: # unload conflicting modules at first fp@1723: for mod in 8139too; do fp@1723: if lsmod | grep "^$mod " > /dev/null; then fp@1723: if ! rmmod $mod; then fp@1723: /bin/false fp@1723: rc_status -v fp@1723: rc_exit fp@1715: fi fp@1723: fi fp@1723: done fp@1723: fp@1723: # load master module fp@1723: if ! modprobe ec_master ec_eoeif_count=$EOE_INTERFACES; then fp@1723: modprobe 8139too fp@1723: /bin/false fp@1723: rc_status -v fp@1723: rc_exit fp@1723: fi fp@1715: fp@1715: # load device module fp@1723: if ! modprobe ec_8139too ec_device_index=$DEVICE_INDEX; then fp@1723: rmmod ec_master fp@1723: modprobe 8139too fp@1723: /bin/false fp@1723: rc_status -v fp@1723: rc_exit fp@1723: fi fp@1715: fp@1715: # build EoE bridge fp@1723: build_eoe_bridge fp@1723: fp@1723: rc_status -v fp@1723: ;; fp@174: fp@169: stop) fp@1723: echo -n "Shutting down EtherCAT master " fp@1723: fp@1723: # unload modules fp@1723: for mod in ec_8139too ec_master; do fp@1723: if lsmod | grep "^$mod " > /dev/null; then fp@1723: if ! rmmod $mod; then fp@1723: /bin/false fp@1723: rc_status -v fp@1723: rc_exit fp@1723: fi; fp@1723: fi; fp@1723: done fp@1723: fp@1723: sleep 1 fp@1723: fp@1723: # reload previous modules fp@1723: if ! modprobe 8139too; then fp@1723: echo "Warning: Failed to restore 8139too module." fp@1723: fi fp@1723: fp@1723: rc_status -v fp@1723: ;; fp@174: fp@243: restart) fp@1723: $0 stop || exit 1 fp@1723: sleep 1 fp@1723: $0 start fp@1723: rc_status fp@1723: ;; fp@244: fp@244: status) fp@1723: echo -n "Checking for EtherCAT " fp@1723: fp@1723: lsmod | grep "^ec_master " > /dev/null fp@1723: master_running=$? fp@1723: lsmod | grep "^ec_8139too " > /dev/null fp@1723: device_running=$? fp@1723: fp@1723: # master module and device module loaded? fp@1723: test $master_running -eq 0 -a $device_running -eq 0 fp@1723: fp@1723: rc_status -v fp@1723: ;; fp@289: fp@289: bridge) fp@1723: echo -n "Building EoE bridge " fp@1723: build_eoe_bridge fp@1723: rc_status -v fp@1723: ;; fp@289: fp@289: *) fp@1723: echo "USAGE: $0 {start|stop|restart|status|bridge}" fp@1723: ;; fp@1715: fp@169: esac fp@1715: fp@243: rc_exit fp@169: fp@169: #------------------------------------------------------------------------------