script/init.d/ethercat
changeset 922 fede1d8f5b71
parent 921 c8c2caf0d667
child 942 dd13cdafc58c
equal deleted inserted replaced
921:c8c2caf0d667 922:fede1d8f5b71
    47 # Description:
    47 # Description:
    48 ### END INIT INFO
    48 ### END INIT INFO
    49 
    49 
    50 #------------------------------------------------------------------------------
    50 #------------------------------------------------------------------------------
    51 
    51 
       
    52 CDEV='EtherCAT'
    52 MODPROBE=/sbin/modprobe
    53 MODPROBE=/sbin/modprobe
    53 RMMOD=/sbin/rmmod
    54 RMMOD=/sbin/rmmod
    54 MODINFO=/sbin/modinfo
    55 MODINFO=/sbin/modinfo
    55 
    56 
    56 #------------------------------------------------------------------------------
    57 #------------------------------------------------------------------------------
   170         parse_mac_address ${BACKUP}
   171         parse_mac_address ${BACKUP}
   171         BACKUPS=${BACKUPS}${MAC}
   172         BACKUPS=${BACKUPS}${MAC}
   172 
   173 
   173         MASTER_INDEX=$(expr ${MASTER_INDEX} + 1)
   174         MASTER_INDEX=$(expr ${MASTER_INDEX} + 1)
   174     done
   175     done
       
   176     MASTER_INDICES=`seq 0 $((${MASTER_INDEX} - 1))`
   175 
   177 
   176     # load master module
   178     # load master module
   177     if ! ${MODPROBE} ${MODPROBE_FLAGS} ec_master \
   179     if ! ${MODPROBE} ${MODPROBE_FLAGS} ec_master \
   178             main_devices=${DEVICES} backup_devices=${BACKUPS}; then
   180             main_devices=${DEVICES} backup_devices=${BACKUPS}; then
   179         exit_fail
   181         exit_fail
   180     fi
   182     fi
       
   183 
       
   184     # remove stale device nodes
       
   185     rm -f /dev/${CDEV}*
       
   186 
       
   187     # get dynamic major number
       
   188     MAJOR=$(awk "\$2==\"EtherCAT\" {print \$1}" /proc/devices)
       
   189 
       
   190     # create character devices
       
   191     for i in ${MASTER_INDICES}; do
       
   192         mknod /dev/${CDEV}${i} c ${MAJOR} ${i}
       
   193     done
   181 
   194 
   182     # check for modules to replace
   195     # check for modules to replace
   183     for MODULE in ${DEVICE_MODULES}; do
   196     for MODULE in ${DEVICE_MODULES}; do
   184         ECMODULE=ec_${MODULE}
   197         ECMODULE=ec_${MODULE}
   185         if ! ${MODINFO} ${ECMODULE} > /dev/null; then
   198         if ! ${MODINFO} ${ECMODULE} > /dev/null; then
   211         if ! ${RMMOD} ${ECMODULE}; then
   224         if ! ${RMMOD} ${ECMODULE}; then
   212             exit_fail
   225             exit_fail
   213         fi;
   226         fi;
   214     done
   227     done
   215 
   228 
       
   229     # remove device nodes
       
   230     rm -f /dev/${CDEV}*
       
   231 
   216     sleep 1
   232     sleep 1
   217 
   233 
   218     # reload previous modules
   234     # reload previous modules
   219     for MODULE in ${DEVICE_MODULES}; do
   235     for MODULE in ${DEVICE_MODULES}; do
   220         if ! ${MODPROBE} ${MODPROBE_FLAGS} ${MODULE}; then
   236         if ! ${MODPROBE} ${MODPROBE_FLAGS} ${MODULE}; then