47 # Description: |
47 # Description: |
48 ### END INIT INFO |
48 ### END INIT INFO |
49 |
49 |
50 #------------------------------------------------------------------------------ |
50 #------------------------------------------------------------------------------ |
51 |
51 |
52 device="ecxml" |
52 XMLDEVICE='ecxml' |
53 |
|
54 IFCONFIG=ifconfig |
|
55 BRCTL=brctl |
|
56 ROUTE=route |
|
57 |
53 |
58 #------------------------------------------------------------------------------ |
54 #------------------------------------------------------------------------------ |
59 |
55 |
60 ETHERCAT_CONFIG=/etc/sysconfig/ethercat |
56 ETHERCAT_CONFIG=/etc/sysconfig/ethercat |
61 |
57 |
62 if [ ! -r $ETHERCAT_CONFIG ]; then |
58 if [ ! -r ${ETHERCAT_CONFIG} ]; then |
63 echo "$ETHERCAT_CONFIG not existing"; |
59 echo "${ETHERCAT_CONFIG} not existing"; |
64 if [ "$1" = "stop" ]; then |
60 if [ "${1}" = "stop" ]; then |
65 exit 0 |
61 exit 0 |
66 else |
62 else |
67 exit 6 |
63 exit 6 |
68 fi |
64 fi |
69 fi |
65 fi |
70 |
66 |
71 . $ETHERCAT_CONFIG |
67 . ${ETHERCAT_CONFIG} |
72 |
68 |
73 #------------------------------------------------------------------------------ |
69 #------------------------------------------------------------------------------ |
74 |
70 |
75 # |
71 function make_device_id() |
76 # Function for setting up the EoE bridge |
|
77 # |
|
78 build_eoe_bridge() |
|
79 { |
72 { |
80 if [ -z "$EOE_BRIDGE" ]; then return; fi |
73 if [ -z "${1}" ]; then |
81 |
74 DEVICE_ID=";" |
82 EOEIF=`$IFCONFIG -a | grep -o -E "^eoe[0-9]+ "` |
75 elif echo ${1} | grep -qE '^([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}$'; then |
83 |
76 DEVICE_ID="M${1};" |
84 # add bridge, if it does not already exist |
77 elif echo ${1} | grep -qE '^[^:]+:[0-9]+$'; then |
85 if ! $BRCTL show | grep -E -q "^$EOE_BRIDGE"; then |
78 DEVICE_ID="D${1};" |
86 if ! $BRCTL addbr $EOE_BRIDGE; then |
79 else |
87 /bin/false |
80 echo Invalid device ID syntax in ${ETHERCAT_CONFIG} |
88 rc_status -v |
81 /bin/false |
89 rc_exit |
82 rc_status -v |
90 fi |
83 rc_exit |
91 fi |
84 fi |
92 |
|
93 # check if specified interfaces are bridged |
|
94 for interf in $EOEIF $EOE_EXTRA_INTERFACES; do |
|
95 # interface is already part of the bridge (FIXME->show $EOE_BRIDGE) |
|
96 if $BRCTL show | grep -E -q $interf |
|
97 then continue |
|
98 fi |
|
99 # clear IP address and open interface |
|
100 if ! $IFCONFIG $interf 0.0.0.0 up; then |
|
101 /bin/false |
|
102 rc_status -v |
|
103 rc_exit |
|
104 fi |
|
105 # add interface to the bridge |
|
106 if ! $BRCTL addif $EOE_BRIDGE $interf; then |
|
107 /bin/false |
|
108 rc_status -v |
|
109 rc_exit |
|
110 fi |
|
111 done |
|
112 |
|
113 # configure IP on bridge |
|
114 if [ -n "$EOE_IP_ADDRESS" -a -n "$EOE_IP_NETMASK" ]; then |
|
115 if ! $IFCONFIG $EOE_BRIDGE $EOE_IP_ADDRESS \ |
|
116 netmask $EOE_IP_NETMASK; then |
|
117 /bin/false |
|
118 rc_status -v |
|
119 rc_exit |
|
120 fi |
|
121 fi |
|
122 |
|
123 # open bridge |
|
124 if ! $IFCONFIG $EOE_BRIDGE up; then |
|
125 /bin/false |
|
126 rc_status -v |
|
127 rc_exit |
|
128 fi |
|
129 |
|
130 # install new default gateway |
|
131 if [ -n "$EOE_GATEWAY" ]; then |
|
132 while $ROUTE -n | grep -E -q "^0.0.0.0"; do |
|
133 if ! $ROUTE del default; then |
|
134 echo "Failed to remove route!" 1>&2 |
|
135 /bin/false |
|
136 rc_status -v |
|
137 rc_exit |
|
138 fi |
|
139 done |
|
140 if ! $ROUTE add default gw $EOE_GATEWAY; then |
|
141 /bin/false |
|
142 rc_status -v |
|
143 rc_exit |
|
144 fi |
|
145 fi |
|
146 } |
85 } |
147 |
86 |
148 #------------------------------------------------------------------------------ |
87 #------------------------------------------------------------------------------ |
149 |
88 |
150 . /etc/rc.status |
89 . /etc/rc.status |
151 rc_reset |
90 rc_reset |
152 |
91 |
153 case "$1" in |
92 case "${1}" in |
154 |
93 |
155 start) |
94 start) |
156 echo -n "Starting EtherCAT master " |
95 echo -n "Starting EtherCAT master " |
157 |
96 |
158 if [ -z "$DEVICE_INDEX" ]; then |
97 # construct DEVICES and BACKUPS from configuration variables |
159 echo "ERROR: DEVICE_INDEX not set!" |
98 DEVICES="" |
160 /bin/false |
99 BACKUPS="" |
161 rc_status -v |
100 MASTER_INDEX=0 |
162 rc_exit |
101 while true; do |
163 fi |
102 DEVICE=$(eval echo "\${MASTER${MASTER_INDEX}_DEVICE}") |
164 |
103 BACKUP=$(eval echo "\${MASTER${MASTER_INDEX}_BACKUP}") |
165 if [ -z "$EOE_INTERFACES" ]; then |
104 if [ -z "${DEVICE}" ]; then break; fi |
166 # support legacy sysconfig files |
105 |
167 if [ -n "$EOE_DEVICES" ]; then |
106 make_device_id ${DEVICE} |
168 EOE_INTERFACES=$EOE_DEVICES |
107 DEVICES=${DEVICES}${DEVICE_ID} |
169 else |
108 make_device_id ${BACKUP} |
170 EOE_INTERFACES=0 |
109 BACKUPS=${BACKUPS}${DEVICE_ID} |
171 fi |
110 |
172 fi |
111 MASTER_INDEX=$(expr ${MASTER_INDEX} + 1) |
173 |
112 done |
174 # unload conflicting modules at first |
113 |
175 for mod in 8139too; do |
114 # unload conflicting modules at first |
176 if lsmod | grep "^$mod " > /dev/null; then |
115 for MODULE in 8139too; do |
177 if ! rmmod $mod; then |
116 if lsmod | grep "^${MODULE} " > /dev/null; then |
178 /bin/false |
117 if ! rmmod ${MODULE}; then |
179 rc_status -v |
118 /bin/false |
180 rc_exit |
119 rc_status -v |
181 fi |
120 rc_exit |
182 fi |
121 fi |
183 done |
122 fi |
184 |
123 done |
185 # load master module |
124 |
186 if ! modprobe ec_master ec_eoeif_count=$EOE_INTERFACES; then |
125 # load master module |
187 modprobe 8139too |
126 if ! modprobe ec_master main=${DEVICES} backup=${BACKUPS}; then |
188 /bin/false |
127 modprobe 8139too |
189 rc_status -v |
128 /bin/false |
190 rc_exit |
129 rc_status -v |
191 fi |
130 rc_exit |
192 |
131 fi |
193 # remove stale device node |
132 |
194 rm -f /dev/${device}0 |
133 # remove stale device node |
195 |
134 rm -f /dev/${XMLDEVICE}0 |
196 # get dynamic major number |
135 |
197 major=$(awk "\$2==\"EtherCAT\" {print \$1}" /proc/devices) |
136 # get dynamic major number |
198 |
137 MAJOR=$(awk "\$2==\"EtherCAT\" {print \$1}" /proc/devices) |
199 # create character device |
138 |
200 mknod /dev/${device}0 c $major 0 |
139 # create character device |
201 |
140 mknod /dev/${XMLDEVICE}0 c ${MAJOR} 0 |
202 # load device module |
141 |
203 if ! modprobe ec_8139too ec_device_index=$DEVICE_INDEX; then |
142 # load device module |
204 rmmod ec_master |
143 if ! modprobe ec_8139too; then |
205 modprobe 8139too |
144 rmmod ec_master |
206 /bin/false |
145 modprobe 8139too |
207 rc_status -v |
146 /bin/false |
208 rc_exit |
147 rc_status -v |
209 fi |
148 rc_exit |
210 |
149 fi |
211 # build EoE bridge |
150 |
212 build_eoe_bridge |
151 rc_status -v |
213 |
152 ;; |
214 rc_status -v |
153 |
215 ;; |
154 stop) |
216 |
155 echo -n "Shutting down EtherCAT master " |
217 stop) |
156 |
218 echo -n "Shutting down EtherCAT master " |
157 # unload modules |
219 |
158 for mod in ec_8139too ec_master; do |
220 # unload modules |
159 if lsmod | grep "^$mod " > /dev/null; then |
221 for mod in ec_8139too ec_master; do |
160 if ! rmmod $mod; then |
222 if lsmod | grep "^$mod " > /dev/null; then |
161 /bin/false |
223 if ! rmmod $mod; then |
162 rc_status -v |
224 /bin/false |
163 rc_exit |
225 rc_status -v |
164 fi; |
226 rc_exit |
165 fi; |
227 fi; |
166 done |
228 fi; |
167 |
229 done |
168 # remove device node |
230 |
169 rm -f /dev/${XMLDEVICE}0 |
231 # remove device node |
170 |
232 rm -f /dev/${device}0 |
171 sleep 1 |
233 |
172 |
234 sleep 1 |
173 # reload previous modules |
235 |
174 if ! modprobe 8139too; then |
236 # reload previous modules |
175 echo "Warning: Failed to restore 8139too module." |
237 if ! modprobe 8139too; then |
176 fi |
238 echo "Warning: Failed to restore 8139too module." |
177 |
239 fi |
178 rc_status -v |
240 |
179 ;; |
241 rc_status -v |
180 |
242 ;; |
181 restart) |
243 |
182 $0 stop || exit 1 |
244 restart) |
183 sleep 1 |
245 $0 stop || exit 1 |
184 $0 start |
246 sleep 1 |
185 rc_status |
247 $0 start |
186 ;; |
248 rc_status |
187 |
249 ;; |
188 status) |
250 |
189 echo -n "Checking for EtherCAT " |
251 status) |
190 |
252 echo -n "Checking for EtherCAT " |
191 lsmod | grep "^ec_master " > /dev/null |
253 |
192 master_running=$? |
254 lsmod | grep "^ec_master " > /dev/null |
193 lsmod | grep "^ec_8139too " > /dev/null |
255 master_running=$? |
194 device_running=$? |
256 lsmod | grep "^ec_8139too " > /dev/null |
195 |
257 device_running=$? |
196 # master module and device module loaded? |
258 |
197 test $master_running -eq 0 -a $device_running -eq 0 |
259 # master module and device module loaded? |
198 |
260 test $master_running -eq 0 -a $device_running -eq 0 |
199 rc_status -v |
261 |
200 ;; |
262 rc_status -v |
201 |
263 ;; |
202 *) |
264 |
203 echo "USAGE: $0 {start|stop|restart|status}" |
265 bridge) |
204 ;; |
266 echo -n "Building EoE bridge " |
|
267 build_eoe_bridge |
|
268 rc_status -v |
|
269 ;; |
|
270 |
|
271 *) |
|
272 echo "USAGE: $0 {start|stop|restart|status|bridge}" |
|
273 ;; |
|
274 |
205 |
275 esac |
206 esac |
276 |
207 |
277 rc_exit |
208 rc_exit |
278 |
209 |