mirror of
https://gitlab.com/etherlab.org/ethercat.git
synced 2026-09-22 01:53:54 +08:00
Introduced device IDs; removed comment lines from 8139too; removed
ec_eoeif_count parameter.
This commit is contained in:
+108
-177
@@ -49,100 +49,39 @@
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
device="ecxml"
|
||||
|
||||
IFCONFIG=ifconfig
|
||||
BRCTL=brctl
|
||||
ROUTE=route
|
||||
XMLDEVICE='ecxml'
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
ETHERCAT_CONFIG=/etc/sysconfig/ethercat
|
||||
|
||||
if [ ! -r $ETHERCAT_CONFIG ]; then
|
||||
echo "$ETHERCAT_CONFIG not existing";
|
||||
if [ "$1" = "stop" ]; then
|
||||
if [ ! -r ${ETHERCAT_CONFIG} ]; then
|
||||
echo "${ETHERCAT_CONFIG} not existing";
|
||||
if [ "${1}" = "stop" ]; then
|
||||
exit 0
|
||||
else
|
||||
exit 6
|
||||
fi
|
||||
fi
|
||||
|
||||
. $ETHERCAT_CONFIG
|
||||
. ${ETHERCAT_CONFIG}
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
#
|
||||
# Function for setting up the EoE bridge
|
||||
#
|
||||
build_eoe_bridge()
|
||||
function make_device_id()
|
||||
{
|
||||
if [ -z "$EOE_BRIDGE" ]; then return; fi
|
||||
|
||||
EOEIF=`$IFCONFIG -a | grep -o -E "^eoe[0-9]+ "`
|
||||
|
||||
# add bridge, if it does not already exist
|
||||
if ! $BRCTL show | grep -E -q "^$EOE_BRIDGE"; then
|
||||
if ! $BRCTL addbr $EOE_BRIDGE; then
|
||||
/bin/false
|
||||
rc_status -v
|
||||
rc_exit
|
||||
fi
|
||||
fi
|
||||
|
||||
# check if specified interfaces are bridged
|
||||
for interf in $EOEIF $EOE_EXTRA_INTERFACES; do
|
||||
# interface is already part of the bridge (FIXME->show $EOE_BRIDGE)
|
||||
if $BRCTL show | grep -E -q $interf
|
||||
then continue
|
||||
fi
|
||||
# clear IP address and open interface
|
||||
if ! $IFCONFIG $interf 0.0.0.0 up; then
|
||||
/bin/false
|
||||
rc_status -v
|
||||
rc_exit
|
||||
fi
|
||||
# add interface to the bridge
|
||||
if ! $BRCTL addif $EOE_BRIDGE $interf; then
|
||||
/bin/false
|
||||
rc_status -v
|
||||
rc_exit
|
||||
fi
|
||||
done
|
||||
|
||||
# configure IP on bridge
|
||||
if [ -n "$EOE_IP_ADDRESS" -a -n "$EOE_IP_NETMASK" ]; then
|
||||
if ! $IFCONFIG $EOE_BRIDGE $EOE_IP_ADDRESS \
|
||||
netmask $EOE_IP_NETMASK; then
|
||||
/bin/false
|
||||
rc_status -v
|
||||
rc_exit
|
||||
fi
|
||||
fi
|
||||
|
||||
# open bridge
|
||||
if ! $IFCONFIG $EOE_BRIDGE up; then
|
||||
/bin/false
|
||||
rc_status -v
|
||||
rc_exit
|
||||
fi
|
||||
|
||||
# install new default gateway
|
||||
if [ -n "$EOE_GATEWAY" ]; then
|
||||
while $ROUTE -n | grep -E -q "^0.0.0.0"; do
|
||||
if ! $ROUTE del default; then
|
||||
echo "Failed to remove route!" 1>&2
|
||||
/bin/false
|
||||
rc_status -v
|
||||
rc_exit
|
||||
fi
|
||||
done
|
||||
if ! $ROUTE add default gw $EOE_GATEWAY; then
|
||||
/bin/false
|
||||
rc_status -v
|
||||
rc_exit
|
||||
fi
|
||||
fi
|
||||
if [ -z "${1}" ]; then
|
||||
DEVICE_ID=";"
|
||||
elif echo ${1} | grep -qE '^([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}$'; then
|
||||
DEVICE_ID="M${1};"
|
||||
elif echo ${1} | grep -qE '^[^:]+:[0-9]+$'; then
|
||||
DEVICE_ID="D${1};"
|
||||
else
|
||||
echo Invalid device ID syntax in ${ETHERCAT_CONFIG}
|
||||
/bin/false
|
||||
rc_status -v
|
||||
rc_exit
|
||||
fi
|
||||
}
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
@@ -150,127 +89,119 @@ build_eoe_bridge()
|
||||
. /etc/rc.status
|
||||
rc_reset
|
||||
|
||||
case "$1" in
|
||||
case "${1}" in
|
||||
|
||||
start)
|
||||
echo -n "Starting EtherCAT master "
|
||||
start)
|
||||
echo -n "Starting EtherCAT master "
|
||||
|
||||
if [ -z "$DEVICE_INDEX" ]; then
|
||||
echo "ERROR: DEVICE_INDEX not set!"
|
||||
/bin/false
|
||||
rc_status -v
|
||||
rc_exit
|
||||
fi
|
||||
# construct DEVICES and BACKUPS from configuration variables
|
||||
DEVICES=""
|
||||
BACKUPS=""
|
||||
MASTER_INDEX=0
|
||||
while true; do
|
||||
DEVICE=$(eval echo "\${MASTER${MASTER_INDEX}_DEVICE}")
|
||||
BACKUP=$(eval echo "\${MASTER${MASTER_INDEX}_BACKUP}")
|
||||
if [ -z "${DEVICE}" ]; then break; fi
|
||||
|
||||
if [ -z "$EOE_INTERFACES" ]; then
|
||||
# support legacy sysconfig files
|
||||
if [ -n "$EOE_DEVICES" ]; then
|
||||
EOE_INTERFACES=$EOE_DEVICES
|
||||
else
|
||||
EOE_INTERFACES=0
|
||||
fi
|
||||
fi
|
||||
make_device_id ${DEVICE}
|
||||
DEVICES=${DEVICES}${DEVICE_ID}
|
||||
make_device_id ${BACKUP}
|
||||
BACKUPS=${BACKUPS}${DEVICE_ID}
|
||||
|
||||
# unload conflicting modules at first
|
||||
for mod in 8139too; do
|
||||
if lsmod | grep "^$mod " > /dev/null; then
|
||||
if ! rmmod $mod; then
|
||||
/bin/false
|
||||
rc_status -v
|
||||
rc_exit
|
||||
fi
|
||||
fi
|
||||
done
|
||||
MASTER_INDEX=$(expr ${MASTER_INDEX} + 1)
|
||||
done
|
||||
|
||||
# load master module
|
||||
if ! modprobe ec_master ec_eoeif_count=$EOE_INTERFACES; then
|
||||
modprobe 8139too
|
||||
/bin/false
|
||||
rc_status -v
|
||||
rc_exit
|
||||
fi
|
||||
# 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
|
||||
|
||||
# remove stale device node
|
||||
rm -f /dev/${device}0
|
||||
# load master module
|
||||
if ! modprobe ec_master main=${DEVICES} backup=${BACKUPS}; then
|
||||
modprobe 8139too
|
||||
/bin/false
|
||||
rc_status -v
|
||||
rc_exit
|
||||
fi
|
||||
|
||||
# get dynamic major number
|
||||
major=$(awk "\$2==\"EtherCAT\" {print \$1}" /proc/devices)
|
||||
# remove stale device node
|
||||
rm -f /dev/${XMLDEVICE}0
|
||||
|
||||
# create character device
|
||||
mknod /dev/${device}0 c $major 0
|
||||
# get dynamic major number
|
||||
MAJOR=$(awk "\$2==\"EtherCAT\" {print \$1}" /proc/devices)
|
||||
|
||||
# load device module
|
||||
if ! modprobe ec_8139too ec_device_index=$DEVICE_INDEX; then
|
||||
rmmod ec_master
|
||||
modprobe 8139too
|
||||
/bin/false
|
||||
rc_status -v
|
||||
rc_exit
|
||||
fi
|
||||
# create character device
|
||||
mknod /dev/${XMLDEVICE}0 c ${MAJOR} 0
|
||||
|
||||
# build EoE bridge
|
||||
build_eoe_bridge
|
||||
# load device module
|
||||
if ! modprobe ec_8139too; then
|
||||
rmmod ec_master
|
||||
modprobe 8139too
|
||||
/bin/false
|
||||
rc_status -v
|
||||
rc_exit
|
||||
fi
|
||||
|
||||
rc_status -v
|
||||
;;
|
||||
rc_status -v
|
||||
;;
|
||||
|
||||
stop)
|
||||
echo -n "Shutting down EtherCAT master "
|
||||
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
|
||||
/bin/false
|
||||
rc_status -v
|
||||
rc_exit
|
||||
fi;
|
||||
fi;
|
||||
done
|
||||
# unload modules
|
||||
for mod in ec_8139too ec_master; do
|
||||
if lsmod | grep "^$mod " > /dev/null; then
|
||||
if ! rmmod $mod; then
|
||||
/bin/false
|
||||
rc_status -v
|
||||
rc_exit
|
||||
fi;
|
||||
fi;
|
||||
done
|
||||
|
||||
# remove device node
|
||||
rm -f /dev/${device}0
|
||||
# remove device node
|
||||
rm -f /dev/${XMLDEVICE}0
|
||||
|
||||
sleep 1
|
||||
sleep 1
|
||||
|
||||
# reload previous modules
|
||||
if ! modprobe 8139too; then
|
||||
echo "Warning: Failed to restore 8139too module."
|
||||
fi
|
||||
# reload previous modules
|
||||
if ! modprobe 8139too; then
|
||||
echo "Warning: Failed to restore 8139too module."
|
||||
fi
|
||||
|
||||
rc_status -v
|
||||
;;
|
||||
rc_status -v
|
||||
;;
|
||||
|
||||
restart)
|
||||
$0 stop || exit 1
|
||||
sleep 1
|
||||
$0 start
|
||||
rc_status
|
||||
;;
|
||||
restart)
|
||||
$0 stop || exit 1
|
||||
sleep 1
|
||||
$0 start
|
||||
rc_status
|
||||
;;
|
||||
|
||||
status)
|
||||
echo -n "Checking for EtherCAT "
|
||||
status)
|
||||
echo -n "Checking for EtherCAT "
|
||||
|
||||
lsmod | grep "^ec_master " > /dev/null
|
||||
master_running=$?
|
||||
lsmod | grep "^ec_8139too " > /dev/null
|
||||
device_running=$?
|
||||
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
|
||||
# master module and device module loaded?
|
||||
test $master_running -eq 0 -a $device_running -eq 0
|
||||
|
||||
rc_status -v
|
||||
;;
|
||||
rc_status -v
|
||||
;;
|
||||
|
||||
bridge)
|
||||
echo -n "Building EoE bridge "
|
||||
build_eoe_bridge
|
||||
rc_status -v
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "USAGE: $0 {start|stop|restart|status|bridge}"
|
||||
;;
|
||||
*)
|
||||
echo "USAGE: $0 {start|stop|restart|status}"
|
||||
;;
|
||||
|
||||
esac
|
||||
|
||||
|
||||
+18
-44
@@ -1,58 +1,32 @@
|
||||
#------------------------------------------------------------------------------
|
||||
#
|
||||
# EtherCAT sysconfig file
|
||||
# EtherCAT master sysconfig file
|
||||
#
|
||||
# $Id$
|
||||
#
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
#
|
||||
# PCI index of the (RTL8139-)EtherCAT device
|
||||
# Setting this is mandatory for the EtherCAT init script!
|
||||
# Master device and backup-device settings.
|
||||
#
|
||||
#DEVICE_INDEX=99
|
||||
|
||||
# The MASTERX_DEVICE variable specifies the ethernet device for master 'X',
|
||||
# while the MASTERX_BACKUP variable specifies the backup ethernet device for
|
||||
# redundancy purposes.
|
||||
#
|
||||
# Number of Ethernet-over-EtherCAT interfaces every master shall create
|
||||
# on startup. Default is 0.
|
||||
# There are three formats for specifying ethernet devices:
|
||||
# 1) MAC address (example: "00:00:08:44:55: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.
|
||||
# 3) Driver and device index (example: "8139too:0"). Currently there are two
|
||||
# drivers available: "8139too" and "e100". The device index is the index
|
||||
# into driver-supported PCI cards.
|
||||
#
|
||||
#EOE_INTERFACES=0
|
||||
|
||||
# The MASTERX_DEVICE variables also determine, how many masters will be
|
||||
# created: A non-empty variable MASTER0_DEVICE will create one master, adding
|
||||
# a non-empty variable MASTER1_DEVICE will create a second master, and so on.
|
||||
#
|
||||
# Bridge all EoE interfaces after master startup
|
||||
# This variable shall contain the name of the EoE bridge to set up.
|
||||
# If the variable is empty or undefined, no EoE bridge will be built.
|
||||
#
|
||||
#EOE_BRIDGE=eoebr0
|
||||
|
||||
#
|
||||
# IP address of the EoE bridge
|
||||
# Set both EOE_IP_ADDRESS and EOE_IP_NETMASK to let the local host communicate
|
||||
# with devices on the EoE bridge.
|
||||
#
|
||||
#EOE_IP_ADDRESS=192.168.X.X
|
||||
|
||||
#
|
||||
# IP netmask of the EoE bridge
|
||||
# See EOE_IP_ADDRESS.
|
||||
#
|
||||
#EOE_IP_NETMASK=255.255.255.0
|
||||
|
||||
#
|
||||
# Renew default gateway after bridge installation.
|
||||
# Set this to the new default gateway, if the default route shall
|
||||
# be renewed after the bridge has been installed.
|
||||
#
|
||||
#EOE_GATEWAY=192.168.X.X
|
||||
|
||||
#
|
||||
# List of extra interfaces to include in the EoE bridge.
|
||||
# Set this to interconnect the EoE bridge with other local interfaces.
|
||||
# If EOE_BRIDGE is empty or undefined, setting this variable has no effect.
|
||||
# Important: The IP address of these interfaces will be cleared. Set
|
||||
# EOE_IP_ADDRESS and EOE_IP_NETMASK accordingly to enable IP traffic to
|
||||
# extra interfaces.
|
||||
#
|
||||
#EOE_EXTRA_INTERFACES=eth0
|
||||
MASTER0_DEVICE=
|
||||
MASTER0_BACKUP=
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user