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