summaryrefslogtreecommitdiff
path: root/xpp/utils/fpga_load.c
diff options
context:
space:
mode:
authortzafrir <tzafrir@5390a7c7-147a-4af0-8ec9-7488f05a26cb>2006-06-17 12:38:20 +0000
committertzafrir <tzafrir@5390a7c7-147a-4af0-8ec9-7488f05a26cb>2006-06-17 12:38:20 +0000
commit9b3e78c5c997fe9363c473f1161ff9c554dcfe69 (patch)
tree859a756e6e219c8ce1fcf2c3181da512eeac6cd3 /xpp/utils/fpga_load.c
parentb5755da0d40e72fad44756bc009fcf688c3380cc (diff)
* Echo canceller not disablerd
* card_fxo.c: Fixed an unreleased spinlock * utils/Makefile: No more C++ flags * utils/Makefile: An install target * fpga_load: usb1 support * genzaptelconf: Support for more cards (Any Sangoma A20x testers?) * xpp_fxloder: The new USB ID, even for manual loads... * xpp_zap.c: Print module fetures in a better format at load time. git-svn-id: http://svn.digium.com/svn/zaptel/trunk@1114 5390a7c7-147a-4af0-8ec9-7488f05a26cb
Diffstat (limited to 'xpp/utils/fpga_load.c')
-rw-r--r--xpp/utils/fpga_load.c124
1 files changed, 118 insertions, 6 deletions
diff --git a/xpp/utils/fpga_load.c b/xpp/utils/fpga_load.c
index cf20226..098b980 100644
--- a/xpp/utils/fpga_load.c
+++ b/xpp/utils/fpga_load.c
@@ -8,8 +8,6 @@
#include <usb.h>
#include "hexfile.h"
-#define XORCOM_INTERNAL
-
static const char rcsid[] = "$Id$";
#define ERR(fmt, arg...) fprintf(stderr, "%s: ERROR: " fmt, progname, ## arg)
@@ -359,6 +357,49 @@ int send_hexline(struct usb_dev_handle *handle, struct hexline *hexline, int seq
return 0;
}
+//. returns > 0 - ok, the number of lines sent
+//. returns < 0 - error number
+int send_splited_hexline(struct usb_dev_handle *handle, struct hexline *hexline, int seq, uint8_t maxwidth)
+{
+ struct hexline *extraline;
+ int linessent = 0;
+ int allocsize;
+ int extra_offset = 0;
+ unsigned int this_line = 0;
+ uint8_t bytesleft = 0;
+
+ if(!hexline) {
+ ERR("Bad record %d type = %d\n", seq, hexline->d.content.header.tt);
+ return -EINVAL;
+ }
+ bytesleft = hexline->d.content.header.ll;
+ // split the line into several lines
+ while (bytesleft > 0) {
+ int status;
+ this_line = (bytesleft >= maxwidth) ? maxwidth : bytesleft;
+ allocsize = sizeof(struct hexline) + this_line + 1;
+ // generate the new line
+ if((extraline = (struct hexline *)malloc(allocsize)) == NULL) {
+ ERR("Not enough memory for spliting the lines\n" );
+ return -EINVAL;
+ }
+ memset( extraline, 0, allocsize );
+ extraline->d.content.header.ll = this_line;
+ extraline->d.content.header.offset = hexline->d.content.header.offset + extra_offset;
+ extraline->d.content.header.tt = hexline->d.content.header.tt;
+ memcpy( extraline->d.content.tt_data.data, hexline->d.content.tt_data.data+extra_offset, this_line);
+ status = send_hexline( handle, extraline, seq+linessent );
+ // cleanups
+ free(extraline);
+ extra_offset += this_line;
+ bytesleft -= this_line;
+ if (status)
+ return status;
+ linessent++;
+ }
+ return linessent;
+}
+
int my_usb_device(struct usb_device *dev, usb_dev_handle *handle)
{
struct usb_device_descriptor *dev_desc;
@@ -460,6 +501,7 @@ int fpga_load(struct usb_dev_handle *handle, const struct hexdata *hexdata)
assert(handle != NULL);
if(verbose >= LOG_INFO)
INFO("Start...\n");
+
for(i = 0; i < hexdata->maxlines; i++) {
struct hexline *hexline = hexdata->lines[i];
@@ -484,6 +526,47 @@ int fpga_load(struct usb_dev_handle *handle, const struct hexdata *hexdata)
return 1;
}
+int fpga_load_usb1(struct usb_dev_handle *handle, const struct hexdata *hexdata)
+{
+ unsigned int i,j=0;
+ int ret;
+ int finished = 0;
+
+ assert(handle != NULL);
+ if(verbose >= LOG_INFO)
+ INFO("Start...\n");
+
+ // i - is the line number
+ // j - is the sequence number, on USB 2, i=j, but on
+ // USB 1 send_splited_hexline may increase the sequence
+ // number, as it needs
+ for(i = 0; i < hexdata->maxlines; i++) {
+ struct hexline *hexline = hexdata->lines[i];
+
+
+ if(!hexline)
+ break;
+ if(finished) {
+ ERR("Extra data after End Of Data Record (line %d)\n", i);
+ return 0;
+ }
+ if(hexline->d.content.header.tt == TT_EOF) {
+ INFO("End of data\n");
+ finished = 1;
+ continue;
+ }
+
+ if((ret = send_splited_hexline(handle, hexline, j, 60)) < 0) {
+ perror("Failed sending hexline (splitting did not help)");
+ return 0;
+ }
+ j += ret;
+ }
+ if(verbose >= LOG_INFO)
+ INFO("Finished...\n");
+ return 1;
+}
+
#include <getopt.h>
void usage()
@@ -494,6 +577,7 @@ void usage()
fprintf(stderr, "\t\t[-d] # Get device version from eeprom\n");
fprintf(stderr, "\t\t[-I <hexfile>] # Input from <hexfile>\n");
fprintf(stderr, "\t\t[-g] # Get eeprom from device\n");
+ fprintf(stderr, "\t\t[-C srC byte] # Set Address sourCe (default: C0)\n");
fprintf(stderr, "\t\t[-V vendorid] # Set Vendor id on device\n");
fprintf(stderr, "\t\t[-P productid] # Set Product id on device\n");
fprintf(stderr, "\t\t[-R release] # Set Release. 2 dot separated decimals\n");
@@ -511,6 +595,15 @@ static void parse_report_func(int level, const char *msg, ...)
va_end(ap);
}
+int hasUSB2( struct usb_device *dev )
+{
+ if (dev->config->interface->altsetting->endpoint->wMaxPacketSize != 512)
+ return 0;
+ else
+ return 1;
+}
+
+// usb_interface_descriptor->usb_endpoint_descriptor.wMaxPacketSize
int main(int argc, char *argv[])
{
@@ -526,11 +619,13 @@ int main(int argc, char *argv[])
#ifdef XORCOM_INTERNAL
int opt_write_eeprom = 0;
char *vendor = NULL;
+ char *source = NULL;
+ int is_source_given = 0;
char *product = NULL;
char *release = NULL;
char *serial = NULL;
uint8_t serial_buf[SERIAL_SIZE];
- const char options[] = "b:dD:ghI:vV:P:R:S:";
+ const char options[] = "b:C:dD:ghI:vV:P:R:S:";
#else
const char options[] = "b:dD:ghI:v";
#endif
@@ -567,6 +662,10 @@ int main(int argc, char *argv[])
case 'V':
vendor = optarg;
break;
+ case 'C':
+ source = optarg;
+ is_source_given = 1;
+ break;
case 'P':
product = optarg;
break;
@@ -648,8 +747,18 @@ int main(int argc, char *argv[])
ret = -ENODEV;
goto dev_err;
}
+
if(hexdata) {
- if(!fpga_load(handle, hexdata)) {
+ int status;
+
+ if (hasUSB2(dev))
+ status = fpga_load(handle, hexdata);
+ else {
+ INFO("Warning: working on a low end USB1 backend\n");
+ status = fpga_load_usb1(handle, hexdata);
+ }
+
+ if(!status) {
ERR("FPGA loading failed\n");
ret = -ENODEV;
goto dev_err;
@@ -661,7 +770,7 @@ int main(int argc, char *argv[])
}
}
#ifdef XORCOM_INTERNAL
- if(vendor || product || release || serial)
+ if(vendor || product || release || serial || source )
opt_read_eeprom = opt_write_eeprom = 1;
#endif
if(opt_read_eeprom) {
@@ -678,7 +787,10 @@ int main(int argc, char *argv[])
#ifdef XORCOM_INTERNAL
if(opt_write_eeprom) {
// FF: address source is from device. C0: from eeprom
- eeprom_buf.source = 0xC0;
+ if (is_source_given)
+ eeprom_buf.source = strtoul(source, NULL, 0);
+ else
+ eeprom_buf.source = 0xC0;
if(vendor)
eeprom_buf.vendor = strtoul(vendor, NULL, 0);
if(product)