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