~ubuntu-branches/ubuntu/quantal/zaptel/quantal

« back to all changes in this revision

Viewing changes to kernel/xpp/utils/xpp_fxloader

  • Committer: Bazaar Package Importer
  • Author(s): Tzafrir Cohen
  • Date: 2008-08-28 22:58:23 UTC
  • mfrom: (11.1.11 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080828225823-r8bdunirm8hmc76m
Tags: 1:1.4.11~dfsg-2
* Patch xpp_fxs_power: Fixed an issue with hook detection of the Astribank
  FXS module.
* Don't fail init.d script if fxotune fails. This may happen if running it
  when Asterisk is already running.
* Bump standards version to 3.8.0.0 .
* Ignore false lintian warning ("m-a a-i" has "a a").
* Patch xpp_fxo_cid_always: do always pass PCM if that's what the user
  asked.
* Patch vzaphfc_proc_root_dir: fix vzaphfc on 2.6.26.
* Patch wcte12xp_flags: Proper time for irq save flags.
* Patch headers_2627: Fix location of semaphore.h for 2.6.27 .
* Patch xpp_fxs_dtmf_leak: Don't play DTMFs to the wrong channel.
* Patch wctdm_fix_alarm: Fix sending channel alarms.
* Patch device_class_2626: Fix building 2.6.26 (Closes: #493397).
* Using dh_lintian for lintian overrides, hence requiring debhelper 6.0.7.
* Lintian: we know we have direct changes. Too bad we're half-upstream :-(
* Fix doc-base section names. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
 
 
3
# xpp_fxloader: load Xorcom Astribank (XPP) firmware
 
4
#
 
5
# This script can be run manually or from hotplug/udev.
 
6
#
 
7
# Firmware files should be located in $FIRMWARE_DIR which defaults:
 
8
#       1. /usr/share/zaptel
 
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
 
11
#
 
12
# Manual Run
 
13
# ##########
 
14
#
 
15
#   path/to/xpp_fxloader load
 
16
#
 
17
# Make sure the firmware files are in $FIRMWARE_DIR
 
18
#
 
19
# UDEV Installation
 
20
# #################
 
21
#
 
22
# Copy xpp.rules to /etc/udev/udev.d and xpp_fxloader to /etc/hotplug/usb/ .
 
23
#
 
24
# Hotplug Installation
 
25
# ####################
 
26
#
 
27
# Copy this file and the file xpp_fxloader.usermap to /etc/hotplug/usb/ .
 
28
#
 
29
 
30
# Written by Tzafrir Cohen <tzafrir.cohen@xorcom.com>
 
31
# Copyright (C) 2006, Xorcom
 
32
#
 
33
# All rights reserved.
 
34
#
 
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.
 
39
#
 
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.
 
44
#
 
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.
 
48
 
 
49
set -e
 
50
 
 
51
# Make sure fxload is in the path:
 
52
PATH="$PATH:/usr/local/sbin:/sbin:/usr/sbin"
 
53
export PATH
 
54
 
 
55
me=`basename $0`
 
56
DEBIAN_DEFAULTS="/etc/default/zaptel"
 
57
REDHAT_DEFAULTS="/etc/sysconfig/zaptel"
 
58
 
 
59
status_fd=3
 
60
 
 
61
if [ -r "$DEBIAN_DEFAULTS" -a -r "$REDHAT_DEFAULTS" ]; then
 
62
        echo 1>&2 "$0: Both '$DEBIAN_DEFAULTS' and '$REDHAT_DEFAULTS' exist"
 
63
        exit 1
 
64
elif [ -r "$DEBIAN_DEFAULTS" ]; then
 
65
        DEFAULTS="$DEBIAN_DEFAULTS"
 
66
elif [ -r "$REDHAT_DEFAULTS" ]; then
 
67
        DEFAULTS="$REDHAT_DEFAULTS"
 
68
fi
 
69
 
 
70
if [ -t 2 ]; then
 
71
        LOGGER="logger -i -t '$me' -s"
 
72
else
 
73
        LOGGER="logger -i -t '$me'"
 
74
fi
 
75
 
 
76
USBFS_PREFIX=/proc/bus/usb
 
77
DEVUSB_PREFIX=/dev/bus/usb
 
78
USB_PREFIX=
 
79
 
 
80
FIRMWARE_DIR="${FIRMWARE_DIR:-/usr/share/zaptel}"
 
81
 
 
82
FIRM_FXS=$FIRMWARE_DIR/FPGA_FXS.hex
 
83
 
 
84
FPGA_LOAD=${FPGA_LOAD:-/usr/sbin/fpga_load}
 
85
USB_FW="${USB_FW:-USB_FW.hex}"
 
86
 
 
87
if [ -r "$DEFAULTS" ]; then
 
88
        . "$DEFAULTS"
 
89
fi
 
90
 
 
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
 
96
        fi
 
97
fi
 
98
 
 
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
 
104
sleep_if_race() {
 
105
  if [ "$KERNEL_HAS_USB_RACE" = '1' ]; then
 
106
    sleep 2
 
107
  fi
 
108
}
 
109
 
 
110
find_dev() {
 
111
  v_id=$1
 
112
  p_id=$2
 
113
  
 
114
  lsusb | tr -d : | awk "/ ID $v_id$p_id/{printf \"$USB_PREFIX/%s/%s \",\$2,\$4}"
 
115
}
 
116
 
 
117
do_fxload() {
 
118
  sleep_if_race
 
119
  ( fxload -t fx2 $* 2>&1 1>/dev/null || exit 1 ) | $LOGGER
 
120
}
 
121
 
 
122
load_fw() {
 
123
  v_id=$1
 
124
  p_id=$2
 
125
  fw=$3
 
126
  
 
127
  devices=`find_dev $v_id $p_id`
 
128
  for dev in $devices
 
129
  do
 
130
    $LOGGER "USB Firmware $FIRMWARE_DIR/$fw into $dev"
 
131
    do_fxload -D $dev -I $FIRMWARE_DIR/$fw || exit 1
 
132
  done
 
133
}
 
134
 
 
135
load_fpga() {
 
136
  v_id=$1
 
137
  p_id=$2
 
138
  fw=$3
 
139
  
 
140
  devices=`find_dev $v_id $p_id`
 
141
  for dev in $devices
 
142
  do
 
143
        (
 
144
        card_ver=`$FPGA_LOAD -g -D $dev | sed -n 's/^.*Release: *//'`
 
145
 
 
146
        $LOGGER "FPGA Firmware into $dev"
 
147
        sleep_if_race
 
148
        (
 
149
                $FPGA_LOAD -D "$dev" -I "$FIRMWARE_DIR/$fw" -i
 
150
                echo $? >$status_fd
 
151
        )>| $LOGGER
 
152
        status=`cat <$status_fd`
 
153
        if [ "$status" != 0 ]; then
 
154
                echo "fpga_load failed with status $status" | $LOGGER
 
155
                exit 77
 
156
        fi
 
157
        ) &
 
158
        sleep 0.4
 
159
  done
 
160
  wait
 
161
}
 
162
 
 
163
numdevs() {
 
164
  v_ids="$1"
 
165
  p_ids="$2"
 
166
 
 
167
  for v in $v_ids
 
168
  do
 
169
    (
 
170
      for p in $p_ids
 
171
      do
 
172
        find_dev $v $p
 
173
      done
 
174
    )
 
175
  done | wc -w
 
176
}
 
177
 
 
178
wait_renumeration() {
 
179
  num="$1"
 
180
  v_ids="$2"
 
181
  p_ids="$3"
 
182
 
 
183
  while
 
184
    n=`numdevs "$v_ids" "$p_ids"`
 
185
    [ "$num" -gt "$n" ]
 
186
  do
 
187
    echo -n "."
 
188
    sleep 1
 
189
  done
 
190
  echo "Got all $num devices"
 
191
}
 
192
 
 
193
reset_fpga() {
 
194
  totaldevs=`numdevs e4e4 '11[3456][012]'`
 
195
  devices=`find_dev e4e4 '11[3456][12]'`
 
196
  echo "Reseting devices [$totaldevs devices]"
 
197
  for dev in $devices
 
198
  do
 
199
        $LOGGER "Resetting FPGA Firmware on $dev"
 
200
        sleep_if_race
 
201
        $FPGA_LOAD -D "$dev" -r 2>&1 >/dev/null | $LOGGER
 
202
        status=$PIPESTATUS
 
203
        if [ "$status" != 0 ]; then
 
204
                echo "fpga_load failed removing with status $status" | $LOGGER
 
205
                exit 78
 
206
        fi
 
207
  done
 
208
  if [ "$1" = 'wait' ]; then
 
209
          wait_renumeration $totaldevs e4e4 '11[3456]0'
 
210
  fi
 
211
}
 
212
 
 
213
#########################
 
214
##
 
215
## Manual run
 
216
##
 
217
 
 
218
# to run manually, pass the parameter 'xppdetect'
 
219
case "$1" in
 
220
udev) 
 
221
        # the following emulate hotplug's environment from udev's environment:
 
222
        DEVICE="$DEVNAME"
 
223
        PRODUCT="$2"
 
224
        # skip on to the rest of the script. Don't exit.
 
225
        ;;
 
226
reset-wait)
 
227
        reset_fpga wait
 
228
        ;;
 
229
reset)
 
230
        reset_fpga
 
231
        ;;
 
232
xppdetect|load|usb)
 
233
        numdevs=`numdevs e4e4 '11[3456][01]'`
 
234
        echo "--------- FIRMWARE LOADING: ($1) [$numdevs devices]"
 
235
 
 
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'
 
241
        if [ "$1" != 'usb' ]
 
242
        then
 
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'
 
248
        fi
 
249
 
 
250
        sleep 3         # Let it stabilize
 
251
        echo "--------- FIRMWARE IS LOADED"
 
252
        exit 0
 
253
        ;;
 
254
help)
 
255
        echo "$0: Astribank firmware loading script."
 
256
        echo "Usage: "
 
257
        echo "$0 load  : manual firmware loading."
 
258
        echo "$0 usb   : manual firmware loading: USB firmware only."
 
259
        echo "$0 help  : this text."
 
260
        echo ""
 
261
        echo "('xppdetect' is an alias of 'load')"
 
262
        exit 0
 
263
        ;;
 
264
esac
 
265
 
 
266
#########################
 
267
##
 
268
## Hotplug run
 
269
##
 
270
 
 
271
# allow disabling automatic hotplugging:
 
272
if [ "$XPP_HOTPLUG_DISABLED" != '' ]; then
 
273
        $LOGGER -p kern.info "Exiting... XPP_HOTPLUG_DISABLED"
 
274
        exit 0
 
275
fi
 
276
 
 
277
if [ "$ACTION" = "add" ] && [ -w "$DEVICE" ]
 
278
then
 
279
        $LOGGER "Trying to find what to do for product $PRODUCT, device $DEVICE"
 
280
        prod_id=`echo "$PRODUCT" | cut -d/ -f2`
 
281
        case "$PRODUCT" in
 
282
        e4e4/11[345]0/*)
 
283
                FIRM_USB="$FIRMWARE_DIR/$USB_FW"
 
284
                $LOGGER "Loading firmware '$FIRM_USB' into '$DEVICE'"
 
285
                do_fxload -D "$DEVICE" -I "$FIRM_USB"
 
286
                ;;
 
287
        e4e4/11[345]1/*)
 
288
                if [ "$prod_id" = 1131 ]; then
 
289
                        FIRM_FPGA="$FIRMWARE_DIR/FPGA_FXS.hex"  # Legacy
 
290
                else
 
291
                        FIRM_FPGA="$FIRMWARE_DIR/FPGA_$prod_id.hex"
 
292
                fi
 
293
                sleep_if_race
 
294
                $FPGA_LOAD -D "$DEVICE" -I "$FIRM_FPGA" 2>&1 >/dev/null | $LOGGER
 
295
                ;;
 
296
        esac    
 
297
fi