3
# xpp_fxloader: load Xorcom Astribank (XPP) firmware
5
# This script can be run manually or from hotplug/udev.
7
# Firmware files should be located in $FIRMWARE_DIR which defaults:
9
# 2. Can be overidden by setting $FIRMWARE_DIR in the environment
10
# 3. Can be overidden by setting $FIRMWARE_DIR in /etc/default/zaptel
15
# path/to/xpp_fxloader load
17
# Make sure the firmware files are in $FIRMWARE_DIR
22
# Copy xpp.rules to /etc/udev/udev.d and xpp_fxloader to /etc/hotplug/usb/ .
24
# Hotplug Installation
25
# ####################
27
# Copy this file and the file xpp_fxloader.usermap to /etc/hotplug/usb/ .
30
# Written by Tzafrir Cohen <tzafrir.cohen@xorcom.com>
31
# Copyright (C) 2006, Xorcom
33
# All rights reserved.
35
# This program is free software; you can redistribute it and/or modify
36
# it under the terms of the GNU General Public License as published by
37
# the Free Software Foundation; either version 2 of the License, or
38
# (at your option) any later version.
40
# This program is distributed in the hope that it will be useful,
41
# but WITHOUT ANY WARRANTY; without even the implied warranty of
42
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
43
# GNU General Public License for more details.
45
# You should have received a copy of the GNU General Public License
46
# along with this program; if not, write to the Free Software
47
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
51
# Make sure fxload is in the path:
52
PATH="$PATH:/usr/local/sbin:/sbin:/usr/sbin"
56
DEBIAN_DEFAULTS="/etc/default/zaptel"
57
REDHAT_DEFAULTS="/etc/sysconfig/zaptel"
61
if [ -r "$DEBIAN_DEFAULTS" -a -r "$REDHAT_DEFAULTS" ]; then
62
echo 1>&2 "$0: Both '$DEBIAN_DEFAULTS' and '$REDHAT_DEFAULTS' exist"
64
elif [ -r "$DEBIAN_DEFAULTS" ]; then
65
DEFAULTS="$DEBIAN_DEFAULTS"
66
elif [ -r "$REDHAT_DEFAULTS" ]; then
67
DEFAULTS="$REDHAT_DEFAULTS"
71
LOGGER="logger -i -t '$me' -s"
73
LOGGER="logger -i -t '$me'"
76
USBFS_PREFIX=/proc/bus/usb
77
DEVUSB_PREFIX=/dev/bus/usb
80
FIRMWARE_DIR="${FIRMWARE_DIR:-/usr/share/zaptel}"
82
FIRM_FXS=$FIRMWARE_DIR/FPGA_FXS.hex
84
FPGA_LOAD=${FPGA_LOAD:-/usr/sbin/fpga_load}
85
USB_FW="${USB_FW:-USB_FW.hex}"
87
if [ -r "$DEFAULTS" ]; then
91
if [ "$USB_PREFIX" = '' ]; then
92
if [ -d "$DEVUSB_PREFIX" ]; then
93
USB_PREFIX=$DEVUSB_PREFIX
94
elif [ -r "$USBFS_PREFIX/devices" ]; then
95
USB_PREFIX=$USBFS_PREFIX
99
# With Kernels older that 2.6.10 it seems to be possible
100
# to trigger a race condition by running fxload or fpga_load
101
# immediately after the detection of the device.
102
KERNEL_HAS_USB_RACE=0
103
case "`uname -r`" in 2.6.[89]*) KERNEL_HAS_USB_RACE=1;; esac
105
if [ "$KERNEL_HAS_USB_RACE" = '1' ]; then
114
lsusb | tr -d : | awk "/ ID $v_id$p_id/{printf \"$USB_PREFIX/%s/%s \",\$2,\$4}"
119
( fxload -t fx2 $* 2>&1 1>/dev/null || exit 1 ) | $LOGGER
127
devices=`find_dev $v_id $p_id`
130
$LOGGER "USB Firmware $FIRMWARE_DIR/$fw into $dev"
131
do_fxload -D $dev -I $FIRMWARE_DIR/$fw || exit 1
140
devices=`find_dev $v_id $p_id`
144
card_ver=`$FPGA_LOAD -g -D $dev | sed -n 's/^.*Release: *//'`
146
$LOGGER "FPGA Firmware into $dev"
149
$FPGA_LOAD -D "$dev" -I "$FIRMWARE_DIR/$fw" -i
152
status=`cat <$status_fd`
153
if [ "$status" != 0 ]; then
154
echo "fpga_load failed with status $status" | $LOGGER
178
wait_renumeration() {
184
n=`numdevs "$v_ids" "$p_ids"`
190
echo "Got all $num devices"
194
totaldevs=`numdevs e4e4 '11[3456][012]'`
195
devices=`find_dev e4e4 '11[3456][12]'`
196
echo "Reseting devices [$totaldevs devices]"
199
$LOGGER "Resetting FPGA Firmware on $dev"
201
$FPGA_LOAD -D "$dev" -r 2>&1 >/dev/null | $LOGGER
203
if [ "$status" != 0 ]; then
204
echo "fpga_load failed removing with status $status" | $LOGGER
208
if [ "$1" = 'wait' ]; then
209
wait_renumeration $totaldevs e4e4 '11[3456]0'
213
#########################
218
# to run manually, pass the parameter 'xppdetect'
221
# the following emulate hotplug's environment from udev's environment:
224
# skip on to the rest of the script. Don't exit.
233
numdevs=`numdevs e4e4 '11[3456][01]'`
234
echo "--------- FIRMWARE LOADING: ($1) [$numdevs devices]"
236
load_fw e4e4 1130 $USB_FW
237
load_fw e4e4 1140 $USB_FW
238
load_fw e4e4 1150 $USB_FW
239
load_fw e4e4 1160 $USB_FW
240
wait_renumeration $numdevs e4e4 '11[3456]1'
243
load_fpga e4e4 1131 FPGA_FXS.hex
244
load_fpga e4e4 1141 FPGA_1141.hex
245
load_fpga e4e4 1151 FPGA_1151.hex
246
load_fpga e4e4 1161 FPGA_1161.hex
247
wait_renumeration $numdevs e4e4 '11[3456]2'
250
sleep 3 # Let it stabilize
251
echo "--------- FIRMWARE IS LOADED"
255
echo "$0: Astribank firmware loading script."
257
echo "$0 load : manual firmware loading."
258
echo "$0 usb : manual firmware loading: USB firmware only."
259
echo "$0 help : this text."
261
echo "('xppdetect' is an alias of 'load')"
266
#########################
271
# allow disabling automatic hotplugging:
272
if [ "$XPP_HOTPLUG_DISABLED" != '' ]; then
273
$LOGGER -p kern.info "Exiting... XPP_HOTPLUG_DISABLED"
277
if [ "$ACTION" = "add" ] && [ -w "$DEVICE" ]
279
$LOGGER "Trying to find what to do for product $PRODUCT, device $DEVICE"
280
prod_id=`echo "$PRODUCT" | cut -d/ -f2`
283
FIRM_USB="$FIRMWARE_DIR/$USB_FW"
284
$LOGGER "Loading firmware '$FIRM_USB' into '$DEVICE'"
285
do_fxload -D "$DEVICE" -I "$FIRM_USB"
288
if [ "$prod_id" = 1131 ]; then
289
FIRM_FPGA="$FIRMWARE_DIR/FPGA_FXS.hex" # Legacy
291
FIRM_FPGA="$FIRMWARE_DIR/FPGA_$prod_id.hex"
294
$FPGA_LOAD -D "$DEVICE" -I "$FIRM_FPGA" 2>&1 >/dev/null | $LOGGER