106
fxload -t fx2 $* 2>&1 1>/dev/null | $LOGGER
107
fxload -t fx2 $* 2>&1 1>/dev/null
107
108
status=$PIPESTATUS
108
109
if [ $status != 0 ]; then
109
$LOGGER "fxload failed with status $status"
110
echo >&2 "fxload failed with status $status"
116
cat /proc/bus/usb/devices | egrep '^P:|^T:' | sed \
117
-e '/^T:/s/ *Spd.*//' \
118
-e '/^T:/s, *Lev.*Dev#= *,\t,' \
120
-e '/^P:/s,[A-Za-z]\+=,,g' \
121
-e '/^P:/s,\.,,g' | awk -vusb_prefix="$USB_PREFIX" '
128
sub("0x", "", vendor);
130
sub("0x", "", product);
132
printf("%4s/%4s/%d\t%s/%03d/%03d\n",
133
vendor, prod, bcd, usb_prefix, bus, dev);
139
find /sys/bus/usb/devices -maxdepth 1 -mindepth 1 | \
140
egrep -v '/usb[0-9]|:' | while read dev; do
146
-e 's,/sys/bus/usb/devices/,,' \
151
done | awk -vusb_prefix="$USB_PREFIX" '{
152
printf("%4s/%4s/%d\t%s/%03d/%03d\n",
153
$1, $2, $3, usb_prefix, $4, $5);
158
lsusb -v | awk -vusb_prefix="$USB_PREFIX" '
161
dev = sprintf("%s/%s/%s ", usb_prefix, $2, $4);
165
sub("0x", "", id_vendor);
169
sub("0x", "", id_product);
173
sub("^0*", "", bcd_device);
174
sub("[.]", "", bcd_device);
175
printf("%s/%s/%s\t%s\n",
176
id_vendor, id_product, bcd_device, dev);
182
#echo >&2 "list_devs"
183
if [ "$#" -eq 0 ]; then
184
if [ -f /proc/bus/usb/devices ]; then
186
elif [ -d /sys/bus/usb/devices ]; then
191
elif [ "$#" -eq 1 ]; then
194
echo >&2 "$0: unknown list_devs method='$method'"
199
via_proc|via_sysfs|via_lsusb)
202
echo >&2 "$0: unknown list_devs method='$method'"
206
list_$method | grep -v '^0000/0000/' | sort
212
#echo >&2 "filter_devs($id_str)"
213
list_devs | awk -vid_str="$id_str" '{ if ($1 ~ id_str) { print } }'
216
usb_firmware_device() {
221
e4e4/11[3456]0/101|e4e4/1163/101)
228
debug "No USB firmware for device $devpath ($id_str)"
235
fw_file="$FIRMWARE_DIR/$fw"
236
ver=$(awk '/\$Id:/ { print $4 }' $fw_file)
237
debug "USB Firmware $fw_file (Version=$ver) into $devpath"
238
run_fxload -D "$devpath" -I "$fw_file" || exit 1
114
241
run_astribank_hexload() {
115
242
debug "Running: $ASTRIBANK_HEXLOAD $*"
116
$ASTRIBANK_HEXLOAD "$@" | $LOGGER
243
$ASTRIBANK_HEXLOAD "$@"
117
244
status=$PIPESTATUS
118
245
if [ $status != 0 ]; then
119
$LOGGER "$ASTRIBANK_HEXLOAD failed with status $status"
246
echo >&2 "$ASTRIBANK_HEXLOAD failed with status $status"
124
251
run_astribank_tool() {
125
252
debug "Running: $ASTRIBANK_TOOL $*"
126
$ASTRIBANK_TOOL "$@" | $LOGGER
127
254
status=$PIPESTATUS
128
255
if [ $status != 0 ]; then
129
$LOGGER "$ASTRIBANK_TOOL failed with status $status"
256
echo >&2 "$ASTRIBANK_TOOL failed with status $status"
139
devices=`find_dev $v_id $p_id`
142
ver=$(awk '/\$Id:/ { print $4 }' $FIRMWARE_DIR/$fw)
143
debug "USB Firmware $FIRMWARE_DIR/$fw (Version=$ver) into $dev"
144
run_fxload -D $dev -I $FIRMWARE_DIR/$fw || exit 1
261
usb_firmware_all_devices() {
264
echo "$devs" | while read id_str devpath
266
usb_firmware_device "$id_str" "$devpath"
268
wait_renumeration $numdevs 'e4e4/11[3456]1/*' "usb_firmware_all_devices"
148
271
load_fw_device() {
151
274
debug "FPGA loading $fw into $dev"
152
275
run_astribank_hexload -D "$dev" -F "$FIRMWARE_DIR/$fw"
153
pic_files=`echo "$FIRMWARE_DIR"/PIC_TYPE_[1-4].hex`
154
debug "PIC burning into $dev: $pic_files"
155
run_astribank_hexload -D "$dev" -p $pic_files
156
run_astribank_tool -D "$dev" -n # Do renumeration!
157
debug "PIC burning finished $pic_files"
278
echo_file="$FIRMWARE_DIR/OCT6104E-256D.ima"
281
abtool_output=`$ASTRIBANK_TOOL -D "$dev" -Q 2>&1`
282
ec_card_type=`echo "$abtool_output" | grep 'CARD 4' | sed -e 's/.*type=//' -e 's/\..*//'`
283
caps_num=`echo "$abtool_output" | grep 'ECHO ports' | sed -e 's/.*: *//'`
284
if [ "$ec_card_type" = '5' ]; then
285
debug "ECHO burning into $dev: $echo_file"
286
card_type=`echo "$abtool_output" | grep 'CARD 0' | sed -e 's/.*type=//' -e 's/\..*//'`
291
if [ -r "$XPP_CONFIG" ]; then
292
pri_protocol=`awk '/^pri_protocol/ {print $2}' $XPP_CONFIG`
294
# "E1" or empty (implied E1) means aLaw
295
if [ "$pri_protocol" != 'T1' ]; then
300
if [ "$law" = '-A' ]; then
303
caps_num=`echo "$abtool_output" | grep 'ECHO ports' | sed -e 's/.*: *//'`
304
debug "ECHO: 1st module is $law_str, $caps_num channels allowed."
305
if [ "$caps_num" != '0' ]; then
306
run_astribank_hexload -D "$dev" -O $law "$echo_file"
308
echo "WARNING: ECHO burning was skipped (no capabilities)"
311
pic_files=`echo "$FIRMWARE_DIR"/PIC_TYPE_[1-4].hex`
312
debug "PIC burning into $dev: begin $pic_files"
313
run_astribank_hexload -D "$dev" -p $pic_files
314
debug "PIC burning into $dev: end $pic_files"
318
run_astribank_tool -D "$dev" -n > /dev/null 2>&1
319
debug "Renumeration of $dev done."
161
# Use in manual loading. Parallelize loading
162
# firmwares to all of our devices
169
devices=`find_dev $v_id $p_id`
322
fpga_firmware_device() {
176
load_fw_device "$dev" "$fw"
326
id_product=`echo "$id_str" | cut -d/ -f2`
327
bcd_device=`echo "$id_str" | cut -d/ -f3`
333
fw="FPGA_${id_product}.hex"
336
fw="FPGA_${id_product}.${bcd_device}.hex"
339
debug "No FPGA firmware for device $devpath ($id_str)"
346
debug "Loading $fw into $devpath"
347
load_fw_device "$devpath" "$fw"
182
# Wait for specific childs to get their exit status
354
#echo >&2 "numdevs($id_str)"
355
filter_devs "$id_str" | wc -l
201
358
wait_renumeration() {
207
n=`numdevs "$v_ids" "$p_ids"`
213
echo "Got all $num devices"
365
echo "Waiting renumeration ($caller)"
367
n=`numdevs "$id_str"`
370
if [ "$prev" -lt "$n" ]; then
377
debug "wait($iter) (found $n from $num devices) ($caller)"
378
if ! iter=`expr $iter - 1`; then
379
echo "Timeout (found $n from $num devices) ($caller)"
383
echo "Got all $num devices ($caller)"
384
sleep 1 # Let everything settle
387
fpga_firmware_all_devices() {
388
echo "Loading FPGA firmwares"
389
devs=`filter_devs 'e4e4/11[3456]1/*'`
390
n=`echo "$devs" | wc -l`
392
while read id_str devpath; do
393
fpga_firmware_device "$id_str" "$devpath" &
396
echo "Wait for FPGA loading processes"
399
wait_renumeration $numdevs 'e4e4/11[3456]2/*' "fpga_firmware_device"
217
totaldevs=`numdevs e4e4 '11[3456][0123]'`
218
devices=`find_dev e4e4 '11[3456][12]'`
219
debug "Reseting devices [$totaldevs devices]"
222
debug "Resetting FPGA Firmware on $dev"
224
run_astribank_tool -D "$dev" -r full 2>&1 >/dev/null
226
if [ "$1" = 'wait' ]; then
227
wait_renumeration $totaldevs e4e4 '11[3456][03]'
403
devices=`filter_devs 'e4e4/11[3456][124]/*'`
404
totaldevs=`numdevs 'e4e4/11[3456][124]/*'`
405
echo >&2 -- "Reseting devices [$totaldevs devices]"
406
echo "$devices" | grep -v '^$' | while read id_str dev
409
debug "Resetting FPGA Firmware on $dev"
411
run_astribank_tool -D "$dev" -r full >/dev/null 2>&1
415
if [ "$1" = 'wait' ]; then
416
wait_renumeration $totaldevs 'e4e4/11[3456][03]/*' "reset_fpga"
338
526
if [ $usb_dev_writable != 1 ]; then
339
$LOGGER "Device $DEVICE not writable. Can't load firmware."
527
echo >&2 "Device $DEVICE not writable. Can't load firmware."
343
$LOGGER "Trying to find what to do for product $PRODUCT, device $DEVICE"
344
prod_id=`echo "$PRODUCT" | cut -d/ -f2`
531
echo >&2 "Trying to find what to do for product $PRODUCT, device $DEVICE"
345
532
case "$PRODUCT" in
534
# This case is for a potentially-broken Astribank.
535
# In most systems you should not set udev rules for those to
536
# get here, as this is actually the ID of a Cypress dev-kit:
537
FIRM_USB="$FIRMWARE_DIR/$USB_RECOV"
538
echo >&2 "Loading recovery firmware '$FIRM_USB' into '$DEVICE'"
539
run_fxload -D "$DEVICE" -I "$FIRM_USB"
346
541
e4e4/11[3456]0/*|e4e4/1163/*)
347
FIRM_USB="$FIRMWARE_DIR/$USB_FW"
348
$LOGGER "Loading firmware '$FIRM_USB' into '$DEVICE'"
349
run_fxload -D "$DEVICE" -I "$FIRM_USB"
542
usb_firmware_device "$PRODUCT" "$DEVICE"
351
544
e4e4/11[3456]1/*)
352
545
# There are potentially two separate udev events, for
353
546
# each of the two endpoints. Ignore the first interface:
354
547
case "$DEVPATH" in *.0) exit 0;; esac
355
if [ "$prod_id" = 1131 ]; then
356
FIRM_FPGA="FPGA_FXS.hex" # Legacy
358
FIRM_FPGA="FPGA_$prod_id.hex"
361
load_fw_device "$DEVICE" "$FIRM_FPGA"
549
fpga_firmware_device "$PRODUCT" "$DEVICE" &
550
wait # parallel firmware loading
555
udev_delayed_load 2>&1 | $LOGGER &