script/init.d/ethercat
changeset 922 fede1d8f5b71
parent 921 c8c2caf0d667
child 942 dd13cdafc58c
--- a/script/init.d/ethercat	Thu May 29 09:53:10 2008 +0000
+++ b/script/init.d/ethercat	Thu May 29 15:11:26 2008 +0000
@@ -49,6 +49,7 @@
 
 #------------------------------------------------------------------------------
 
+CDEV='EtherCAT'
 MODPROBE=/sbin/modprobe
 RMMOD=/sbin/rmmod
 MODINFO=/sbin/modinfo
@@ -172,6 +173,7 @@
 
         MASTER_INDEX=$(expr ${MASTER_INDEX} + 1)
     done
+    MASTER_INDICES=`seq 0 $((${MASTER_INDEX} - 1))`
 
     # load master module
     if ! ${MODPROBE} ${MODPROBE_FLAGS} ec_master \
@@ -179,6 +181,17 @@
         exit_fail
     fi
 
+    # remove stale device nodes
+    rm -f /dev/${CDEV}*
+
+    # get dynamic major number
+    MAJOR=$(awk "\$2==\"EtherCAT\" {print \$1}" /proc/devices)
+
+    # create character devices
+    for i in ${MASTER_INDICES}; do
+        mknod /dev/${CDEV}${i} c ${MAJOR} ${i}
+    done
+
     # check for modules to replace
     for MODULE in ${DEVICE_MODULES}; do
         ECMODULE=ec_${MODULE}
@@ -213,6 +226,9 @@
         fi;
     done
 
+    # remove device nodes
+    rm -f /dev/${CDEV}*
+
     sleep 1
 
     # reload previous modules