Introduced DEVICE_MODULES variable in sysconfig file; enabled init
authorFlorian Pose <fp@igh-essen.com>
Wed, 21 Feb 2007 13:38:02 +0000
changeset 588 ba69f7f34fbf
parent 587 59913f648e04
child 589 492148a329e7
Introduced DEVICE_MODULES variable in sysconfig file; enabled init
script to handle serveral device modules.
script/init.d/ethercat
script/sysconfig/ethercat
--- a/script/init.d/ethercat	Wed Feb 21 13:36:08 2007 +0000
+++ b/script/init.d/ethercat	Wed Feb 21 13:38:02 2007 +0000
@@ -56,7 +56,7 @@
 ETHERCAT_CONFIG=/etc/sysconfig/ethercat
 
 if [ ! -r ${ETHERCAT_CONFIG} ]; then
-    echo "${ETHERCAT_CONFIG} not existing";
+    echo ${ETHERCAT_CONFIG} not existing;
     if [ "${1}" = "stop" ]; then
 	exit 0
     else
@@ -111,17 +111,6 @@
         MASTER_INDEX=$(expr ${MASTER_INDEX} + 1)
     done
 
-    # unload conflicting modules at first
-    for MODULE in 8139too; do
-        if lsmod | grep "^${MODULE} " > /dev/null; then
-            if ! rmmod ${MODULE}; then
-                /bin/false
-                rc_status -v
-                rc_exit
-            fi
-        fi
-    done
-
     # load master module
     if ! modprobe ec_master main=${DEVICES} backup=${BACKUPS}; then
         modprobe 8139too
@@ -139,29 +128,43 @@
     # create character device
     mknod /dev/${XMLDEVICE}0 c ${MAJOR} 0
 
-    # load device module
-    if ! modprobe ec_8139too; then
-        rmmod ec_master
-        modprobe 8139too
-        /bin/false
-        rc_status -v
-        rc_exit
-    fi
-
-    rc_status -v
-    ;;
-
-stop)
-    echo -n "Shutting down EtherCAT master "
-
-    # unload modules
-    for mod in ec_8139too ec_master; do
-        if lsmod | grep "^$mod " > /dev/null; then
-            if ! rmmod $mod; then
+    # check for modules to replace
+    for MODULE in ${DEVICE_MODULES}; do
+        ECMODULE=ec_${MODULE}
+        if ! modinfo ${ECMODULE} > /dev/null; then
+            continue
+        fi
+        if lsmod | grep "^${MODULE} " > /dev/null; then
+            if ! rmmod ${MODULE}; then
                 /bin/false
                 rc_status -v
                 rc_exit
-            fi;
+            fi
+        fi
+        if ! modprobe ${ECMODULE}; then
+            modprobe ${MODULE} # try to restore module
+            /bin/false
+            rc_status -v
+            rc_exit
+        fi
+    done
+
+    rc_status -v
+    ;;
+
+stop)
+    echo -n "Shutting down EtherCAT master "
+
+    # unload EtherCAT device modules
+    for MODULE in ${DEVICE_MODULES} master; do
+        ECMODULE=ec_${MODULE}
+        if ! lsmod | grep -q "^${ECMODULE} "; then
+            continue
+        fi
+        if ! rmmod ${ECMODULE}; then
+            /bin/false
+            rc_status -v
+            rc_exit
         fi;
     done
 
@@ -171,9 +174,11 @@
     sleep 1
 
     # reload previous modules
-    if ! modprobe 8139too; then
-        echo "Warning: Failed to restore 8139too module."
-    fi
+    for MODULE in ${DEVICE_MODULES}; do
+        if ! modprobe ${MODULE}; then
+            echo Warning: Failed to restore ${MODULE}.
+        fi
+    done
 
     rc_status -v
     ;;
@@ -188,13 +193,14 @@
 status)
     echo -n "Checking for EtherCAT "
 
-    lsmod | grep "^ec_master " > /dev/null
-    master_running=$?
-    lsmod | grep "^ec_8139too " > /dev/null
-    device_running=$?
-
-    # master module and device module loaded?
-    test $master_running -eq 0 -a $device_running -eq 0
+    lsmod | grep -q "^ec_master "
+    MASTERS_RUNNING=$?
+
+    ! grep -q "(WAITING)" /sys/ethercat/master*/info
+    MASTERS_IDLE=$?
+
+    # master module loaded and masters not waiting for devices?
+    test ${MASTERS_RUNNING} -eq 0 -a ${MASTERS_IDLE} -eq 0
 
     rc_status -v
     ;;
--- a/script/sysconfig/ethercat	Wed Feb 21 13:36:08 2007 +0000
+++ b/script/sysconfig/ethercat	Wed Feb 21 13:38:02 2007 +0000
@@ -14,7 +14,7 @@
 # redundancy purposes.
 #
 # There are three formats for specifying ethernet devices:
-# 1) MAC address (example: "00:00:08:44:55:66"). Specify the MAC address of
+# 1) MAC address (example: "00:00:08:44:ab:66"). Specify the MAC address of
 #    the ethernet card to use.
 # 2) PCI bus address (example: "01:1c.0"). Specify the PCU bis address of the
 #    ethernet card to use.
@@ -29,4 +29,16 @@
 MASTER0_DEVICE=
 MASTER0_BACKUP=
 
+#
+# Ethernet driver modules to replace with EtherCAT-capable ones.
+#
+# The init script will try to unload the ethernet driver modules in the list
+# and replace them with the EtherCAT-capable ones, respectively. If a certain
+# (EtherCAT-capable) driver is not found, a warning will appear.
+#
+# Remove all unused driver modules to prevent unnecesessary module
+# replacement.
+# 
+DEVICE_MODULES="8139too e100 forcedeth"
+
 #------------------------------------------------------------------------------