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