summaryrefslogtreecommitdiff
path: root/xpp/utils/xpp_fxloader
diff options
context:
space:
mode:
authortzafrir <tzafrir@5390a7c7-147a-4af0-8ec9-7488f05a26cb>2006-05-08 07:51:38 +0000
committertzafrir <tzafrir@5390a7c7-147a-4af0-8ec9-7488f05a26cb>2006-05-08 07:51:38 +0000
commitd89a13a276d0bc8faaba42aabc8e53e8de071b87 (patch)
treeb52e544cb4575706ca17b40840081545f20ec255 /xpp/utils/xpp_fxloader
parent2dd60aaf18e98b0e9d3c06bd9dce5f1128fa55ad (diff)
xpp driver release 1.1.0 (second part of commit from r1021)
* Please avoid setting the keyword Id on the firmware files (*.hex) to preserve the original versioning comment. git-svn-id: http://svn.digium.com/svn/zaptel/trunk@1023 5390a7c7-147a-4af0-8ec9-7488f05a26cb
Diffstat (limited to 'xpp/utils/xpp_fxloader')
-rw-r--r--xpp/utils/xpp_fxloader158
1 files changed, 146 insertions, 12 deletions
diff --git a/xpp/utils/xpp_fxloader b/xpp/utils/xpp_fxloader
index a46c156..6cde8f9 100644
--- a/xpp/utils/xpp_fxloader
+++ b/xpp/utils/xpp_fxloader
@@ -1,24 +1,158 @@
#!/bin/sh
-FIRMWARE="/etc/xortel/FPGA_XPD.hex"
+# xpp_fxload: load XPP firmware
+#
+# This script can be run manually or from hotplug.
+#
+# Firmware files should be located in $FIRMWARE_DIR which defaults:
+# 1. /usr/share/zaptel
+# 2. Can be overidden by setting $FIRMWARE_DIR in the environment
+# 3. Can be overidden by setting $FIRMWARE_DIR in /etc/default/zaptel
+#
+# Manual Run
+# ##########
+#
+# path/to/xpp_fxloader xppdetect
+#
+# Make sure the firmware files are in $FIRMWARE_DIR
+#
+#
+# Hotplg Run
+# ##########
+#
+# 1. Copy this file and the file xpp_fxloader.usermap to /etc/hotplug/usb/
+# 2. tail -f /var/log/messages...
+#
+#
+# Written by Tzafrir Cohen <tzafrir.cohen@xorcom.com>
+# Copyright (C) 2006, Xorcom
+#
+# All rights reserved.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+set -e
+
me=`basename $0`
+DEFAULTS="/etc/default/zaptel"
+
+if [ -t 2 ]; then
+ LOGGER="logger -i -t '$me' -s"
+else
+ LOGGER="logger -i -t '$me'"
+fi
+
+if [ -r "$DEFAULTS" ]; then
+ . "$DEFAULTS"
+fi
+
+FIRMWARE_DIR="${FIRMWARE_DIR:-/usr/share/zaptel}"
+
+FIRM_FXS=$FIRMWARE_DIR/FPGA_FXS.hex
+REENUM_SLEEP_TIME=3 # only used on manual runs
+
+FPGA_LOAD="/sbin/fpga_load"
+
+find_dev() {
+ v_id=$1
+ p_id=$2
+
+ lsusb | tr -d : | awk "/ ID $v_id$p_id/{printf \"/proc/bus/usb/%s/%s \",\$2,\$4}"
+}
+
+do_fxload() {
+ ( fxload -t fx2 $* 2>&1 1>/dev/null || exit 1 ) | $LOGGER
+}
+
+load_fw() {
+ v_id=$1
+ p_id=$2
+ fw=$3
+
+ devices=`find_dev $v_id $p_id`
+ for dev in $devices
+ do
+ do_fxload -D $dev -I $FIRMWARE_DIR/$fw || exit 1
+ done
+
+ # Allow time for reenumeration: This only matters in the manual case.
+ if [ "$devices" != '' ]; then sleep $REENUM_SLEEP_TIME; fi
+}
+
+hexfile_version() {
+ hexfile=$1
+
+ grep '$Id:' "$hexfile" | sed -e 's/^.*$Id: *[^ ]\+ *//' -e 's/ .*$//'
+}
+
+load_fpga() {
+ dev=$1
+
+ card_ver=`$FPGA_LOAD -d -D $dev`
+ firm_ver=`hexfile_version $FIRM_FXS`
+
+ $LOGGER "considering fpga firmware version '$firm_ver' for $dev with version $card_ver."
+ case "$card_ver" in
+ 1.001)
+ $LOGGER "Loading firmware '$FIRM_FXS' (version $firm_ver) into '$dev'"
+ $FPGA_LOAD -D "$dev" -I "$FIRM_FXS" 2>&1 >/dev/null | $LOGGER
+ status=$PIPESTATUS
+ if [ $status != 0 ]; then
+ echo "fpga_load failed with status $status" | $LOGGER
+ exit 77
+ fi
+ ;;
+ esac
+}
+
+#########################
+##
+## Manual run
+##
# to run manually, pass the parameter 'xppdetect'
-V_ID=04b4
-P_ID=8613
if [ "$1" = 'xppdetect' ]; then
- DEVICES=`lsusb | tr -d : | awk "/ ID $V_ID$P_ID /{printf \"/proc/bus/usb/%s/%s \",\\$2,\\$4}"`
- echo "Loading firmware for $DEVICES"
- for dev in $DEVICES
- do
- fxload -t fx2 -D $dev -I $FIRMWARE
+ load_fw 04b4 8613 USB_8613.hex
+ load_fw e4e4 1130 USB_1130.hex
+ for dev in `find_dev e4e4 2311`; do
+ load_fpga $dev
done
- exit 0
+ exit $?
fi
+#########################
+##
+## Hotplug run
+##
+
if [ "$ACTION" = "add" ] && [ -f "$DEVICE" ]
then
- logger -i -t "$me" "Loading firmware '$FIRMWARE' into '$DEVICE'"
- fxload -t fx2 -D "$DEVICE" -I "$FIRMWARE" || exit 1
+ $LOGGER "Trying to find what to do for product $PRODUCT, device $DEVICE"
+ case "$PRODUCT" in
+ 4b4/8613/*)
+ FIRM_USB=$FIRMWARE_DIR/USB_8613.hex
+ $LOGGER "Loading firmware '$FIRM_USB' into '$DEVICE'"
+ do_fxload -D "$DEVICE" -I "$FIRM_USB"
+ ;;
+ e4e4/1130/*)
+ FIRM_USB=$FIRMWARE_DIR/USB_1130.hex
+ $LOGGER "Loading firmware '$FIRM_USB' into '$DEVICE'"
+ do_fxload -D "$DEVICE" -I "$FIRM_USB"
+ ;;
+ e4e4/1131/*)
+ load_fpga $DEVICE
+ ;;
+ esac
fi
-