xpp: improved waitfor_xpds

* Fix an issue due to long firmware load time:
  - When one Astribank has an echo canceler (long firmware loading) and
    and another one does not.
  - The EC-less Astribank finishes initialization before the Astribank
    with EC is detected.
  - Thus waitfor_xpds terminates too early.

* We now iteratively build two sets of serial numbers:
  - One from wha we see in all Xorcom (e4e4:11[3456]x) USB devices.
  - The other is those that were detected in the driver.
  - Only when the two sets are equal (and > 0) we know we are done.
  - This is resilient to many problems (e.g: disconnect/reconnect of
    same device during initialization).

* The progress output was also improved: Now each detected AB
  show the total number so far.

* The timeout was also increased to 100sec

* Woraround for an Astribank with no serial (but just a single one on
  the system).

Signed-off-by: Oron Peled <oron.peled@xorcom.com>
Acked-by: Tzafrir Cohen <tzafrir.cohen@xorcom.com>

git-svn-id: http://svn.astersk.org/svn/dahdi/tools/trunk@10465 17933a7a-c749-41c5-a318-cba88f637d49
This commit is contained in:
Oron Peled 2012-02-22 18:13:02 +00:00 committed by Tzafrir Cohen
parent ead0cfa9bd
commit 949ea4ca9f

View File

@ -29,14 +29,53 @@ set -e
# For lab testing
mydir=`dirname $0`
PATH="${mydir}:${PATH}"
XPP_WAIT_AB_TIMEOUT=80
XPP_WAIT_AB_TIMEOUT=100
[ -r /etc/dahdi/init.conf ] && . /etc/dahdi/init.conf
ab_list() {
find /sys/devices -name idVendor 2>/dev/null | \
xargs grep -H 'e4e4' 2>/dev/null | \
sed -e 's/idVendor.*/idProduct/' | xargs grep -H '11[3456]' | \
sed 's,/[^/]*$,,' || :
}
ab_serial_nums() {
ab_list | \
sed 's,$,/serial,' | \
xargs grep -H '' 2>/dev/null | \
sed 's,.*/serial:,,' | \
sed 's/^$/NO-SERIAL/' | \
sort -u
}
detected_serial_nums() {
cat /sys/bus/astribanks/devices/*/transport/serial 2> /dev/null | \
sed 's/^$/NO-SERIAL/' | \
sort -u || :
}
calc_union() {
echo "$@" | tr -s ' ' '\n' | sort -u
}
detected_ab_list() {
# Only check /sys info (don't use /proc anymore).
ab=`find /sys/bus/astribanks/devices/xbus-*/ -name waitfor_xpds 2> /dev/null || :`
echo $ab
find /sys/bus/astribanks/devices/*/ -name waitfor_xpds 2> /dev/null || :
}
waitfor_ab_initialization() {
oldab=''
while
if ! ab=`detected_ab_list`; then
exit 1
fi
test "$oldab" != "$ab"
do
oldab="$ab"
cat $ab
#echo -n 1>&2 "_"
done
}
# Any hardware?
@ -55,10 +94,25 @@ if ! astribank_is_starting; then
exit 0
fi
# Wait for driver and first device
serial_nums=`ab_serial_nums`
# Loop until detected (hopefully) all astribanks and they are initialized
echo -n 1>&2 "Astribanks detection "
tries="$XPP_WAIT_AB_TIMEOUT"
while [ ! -e "/sys/bus/astribanks/devices/xbus-00" ]
last_detected=0
while
new_serial_nums=`ab_serial_nums`
detected_serial_nums=`detected_serial_nums`
curr_union=`calc_union $curr_union $serial_nums $new_serial_nums`
num_detected=`detected_ab_list | wc -l`
if [ "$num_detected" != "$last_detected" ]; then
# Visual feedback (number of detected AB so far)
echo -n 1>&2 "[$num_detected]"
last_detected="$num_detected"
waitfor_ab_initialization > /dev/null
fi
# Break only when we have something and it's stable
test "$curr_union" != "$detected_serial_nums" -o "$detected_serial_nums" = ''
do
if [ "$tries" -le 0 ]; then
echo 1>&2 "TIMEOUT"
@ -67,21 +121,15 @@ do
echo -n 1>&2 "."
sleep 1
: $((tries-=1))
serial_nums="$new_serial_nums"
done
# Finished: Show a nice output
echo ""
cat /sys/bus/astribanks/devices/*/waitfor_xpds 2> /dev/null || :
# Wait for device to stabilize and XPD's to finish initalizations
echo 1>&2 "Astribanks initializing spans"
while
if ! ab=`ab_list`; then
exit 1
fi
test "$oldab" != "$ab"
do
oldab="$ab"
cat $ab
done
if [ "$XPP_HOTPLUG_DAHDI" = yes ]; then
if [ "$CALLED_FROM_ATRIBANK_HOOK" = '' ]; then
# Now we can wait until the hotplug run would remove the semaphore