11
static const char rcsid[] = "$Id: fpga_load.c 4266 2008-05-13 21:08:09Z tzafrir $";
13
#define ERR(fmt, arg...) do { \
14
if(verbose >= LOG_ERR) \
15
fprintf(stderr, "%s: ERROR (%d): " fmt, \
16
progname, __LINE__, ## arg); \
18
#define INFO(fmt, arg...) do { \
19
if(verbose >= LOG_INFO) \
20
fprintf(stderr, "%s: " fmt, \
23
#define DBG(fmt, arg...) do { \
24
if(verbose >= LOG_DEBUG) \
25
fprintf(stderr, "%s: DBG: " fmt, \
29
static int verbose = LOG_WARNING;
30
static char *progname;
31
static int disconnected = 0;
33
#define MAX_HEX_LINES 10000
34
#define PACKET_SIZE 512
35
#define EEPROM_SIZE 16
40
/* My device parameters */
41
#define MY_EP_OUT 0x04
44
#define FPGA_EP_OUT 0x02
45
#define FPGA_EP_IN 0x86
47
/* USB firmware types */
49
#define USB_FIRMWARE_II 1
51
#define TYPE_ENTRY(t,ni,n,ne,out,in,...) \
54
.num_interfaces = (ni), \
55
.my_interface_num = (n), \
56
.num_endpoints = (ne), \
60
.endpoints = { __VA_ARGS__ }, \
63
static const struct astribank_type {
71
int endpoints[4]; /* for matching */
72
} astribank_types[] = {
73
TYPE_ENTRY(USB_11xx, 1, 0, 4, MY_EP_OUT, MY_EP_IN,
78
TYPE_ENTRY(USB_FIRMWARE_II, 2, 1, 2, MY_EP_OUT, MY_EP_IN,
84
enum fpga_load_packet_types {
85
PT_STATUS_REPLY = 0x01,
86
PT_DATA_PACKET = 0x01,
87
#ifdef XORCOM_INTERNAL
100
uint8_t release_major;
101
uint8_t release_minor;
103
uint8_t label[LABEL_SIZE];
106
struct fpga_packet_header {
114
} PACKED status_reply;
118
uint8_t data[ZERO_SIZE];
119
} PACKED data_packet;
121
struct myeeprom data;
124
struct myeeprom data;
129
enum fpga_load_status {
136
struct my_usb_device {
137
struct usb_device *dev;
138
usb_dev_handle *handle;
139
int my_interface_num;
142
char iManufacturer[BUFSIZ];
143
char iProduct[BUFSIZ];
144
char iSerialNumber[BUFSIZ];
145
char iInterface[BUFSIZ];
147
struct myeeprom eeprom;
148
const struct astribank_type *abtype;
151
const char *load_status2str(enum fpga_load_status s)
154
case FW_FAIL_RESET: return "FW_FAIL_RESET";
155
case FW_FAIL_TRANS: return "FW_FAIL_TRANS";
156
case FW_TRANS_OK: return "FW_TRANS_OK";
157
case FW_CONFIG_DONE: return "FW_CONFIG_DONE";
158
default: return "UNKNOWN";
164
* - It is larger than 0
167
int num_matches(int num, const char* str) {
168
int str_val = atoi(str);
171
return (str_val == num);
174
struct usb_device *dev_of_path(const char *path)
177
struct usb_device *dev;
178
char dirname[PATH_MAX];
179
char filename[PATH_MAX];
185
assert(path != NULL);
186
if(access(path, F_OK) < 0) {
191
if((p = memrchr(path, '/', strlen(path))) == NULL) {
192
ERR("Missing a '/' in %s\n", path);
195
/* Get the device number */
196
ret = sscanf(p + 1, "%d", &dnum);
198
ERR("Path tail is not a device number: '%s'\n", p);
201
/* Search for a '/' before that */
202
p = memrchr(path, '/', p - path);
204
p = path; /* Relative path */
207
/* Get the bus number */
208
ret = sscanf(p, "%d", &bnum);
210
ERR("Path tail is not a bus number: '%s'\n", p);
213
sprintf(dirname, "%03d", bnum);
214
sprintf(filename, "%03d", dnum);
215
for (bus = usb_busses; bus; bus = bus->next) {
216
if (! num_matches(bnum, bus->dirname))
217
//if(strcmp(bus->dirname, dirname) != 0)
219
for (dev = bus->devices; dev; dev = dev->next) {
220
//if(strcmp(dev->filename, filename) == 0)
221
if (num_matches(dnum, dev->filename))
225
ERR("no usb device match '%s'\n", path);
229
int get_usb_string(char *buf, unsigned int len, uint16_t item, usb_dev_handle *handle)
236
ret = usb_get_string_simple(handle, item, tmp, BUFSIZ);
239
return snprintf(buf, len, "%s", tmp);
242
void my_usb_device_cleanup(struct my_usb_device *mydev)
244
assert(mydev != NULL);
246
return; /* Nothing to do */
249
if(usb_release_interface(mydev->handle, mydev->abtype->my_interface_num) != 0) {
250
ERR("Releasing interface: usb: %s\n", usb_strerror());
253
if(usb_close(mydev->handle) != 0) {
254
ERR("Closing device: usb: %s\n", usb_strerror());
257
mydev->handle = NULL;
260
static void show_device_info(const struct my_usb_device *mydev)
262
const struct myeeprom *eeprom;
263
uint8_t data[LABEL_SIZE + 1];
265
assert(mydev != NULL);
266
eeprom = &mydev->eeprom;
267
memset(data, 0, LABEL_SIZE + 1);
268
memcpy(data, eeprom->label, LABEL_SIZE);
269
printf("USB Firmware Type: [%s]\n", mydev->abtype->name);
270
printf("USB iManufacturer: [%s]\n", mydev->iManufacturer);
271
printf("USB iProduct: [%s]\n", mydev->iProduct);
272
printf("USB iSerialNumber: [%s]\n", mydev->iSerialNumber);
273
printf("EEPROM Source: 0x%02X\n", eeprom->source);
274
printf("EEPROM Vendor: 0x%04X\n", eeprom->vendor);
275
printf("EEPROM Product: 0x%04X\n", eeprom->product);
276
printf("EEPROM Release: %d.%03d\n", eeprom->release_major, eeprom->release_minor);
277
printf("EEPROM Label: HEX(%02X,%02X,%02X,%02X,%02X,%02X,%02X,%02X) [%s]\n",
278
data[0], data[1], data[2], data[3],
279
data[4], data[5], data[6], data[7], data);
282
void dump_packet(const char *msg, const char *buf, int len)
286
for(i = 0; i < len; i++)
287
INFO("%s: %2d> 0x%02X\n", msg, i, (uint8_t)buf[i]);
290
int send_usb(const char *msg, struct my_usb_device *mydev, struct fpga_packet_header *phead, int len, int timeout)
292
char *p = (char *)phead;
295
if(verbose >= LOG_DEBUG)
296
dump_packet(msg, p, len);
297
if(mydev->my_ep_out & USB_ENDPOINT_IN) {
298
ERR("send_usb called with an input endpoint 0x%x\n", mydev->my_ep_out);
301
ret = usb_bulk_write(mydev->handle, mydev->my_ep_out, p, len, timeout);
304
* If the device was gone, it may be the
305
* result of renumeration. Ignore it.
308
ERR("bulk_write to endpoint 0x%x failed: %s\n", mydev->my_ep_out, usb_strerror());
309
dump_packet("send_usb[ERR]", p, len);
312
my_usb_device_cleanup(mydev);
315
} else if(ret != len) {
316
ERR("bulk_write to endpoint 0x%x short write: %s\n", mydev->my_ep_out, usb_strerror());
317
dump_packet("send_usb[ERR]", p, len);
323
int recv_usb(const char *msg, struct my_usb_device *mydev, char *buf, size_t len, int timeout)
327
if(mydev->my_ep_in & USB_ENDPOINT_OUT) {
328
ERR("recv_usb called with an output endpoint 0x%x\n", mydev->my_ep_in);
331
ret = usb_bulk_read(mydev->handle, mydev->my_ep_in, buf, len, timeout);
333
ERR("bulk_read from endpoint 0x%x failed: %s\n", mydev->my_ep_in, usb_strerror());
336
if(verbose >= LOG_DEBUG)
337
dump_packet(msg, buf, ret);
341
#ifdef XORCOM_INTERNAL
342
int eeprom_set(struct my_usb_device *mydev, const struct myeeprom *eeprom)
346
char buf[PACKET_SIZE];
347
struct fpga_packet_header *phead = (struct fpga_packet_header *)buf;
349
DBG("%s Start...\n", __FUNCTION__);
350
assert(mydev != NULL);
351
phead->header.op = PT_EEPROM_SET;
352
memcpy(&phead->d.eeprom_set.data, eeprom, EEPROM_SIZE);
353
len = sizeof(phead->d.eeprom_set) + sizeof(phead->header.op);
354
ret = send_usb("eeprom_set[W]", mydev, phead, len, TIMEOUT);
357
ret = recv_usb("eeprom_set[R]", mydev, buf, sizeof(buf), TIMEOUT);
360
phead = (struct fpga_packet_header *)buf;
361
if(phead->header.op == PT_BAD_COMMAND) {
362
ERR("Firmware rejected PT_EEPROM_SET command\n");
364
} else if(phead->header.op != PT_EEPROM_SET) {
365
ERR("Got unexpected reply op=%d\n", phead->header.op);
372
int eeprom_get(struct my_usb_device *mydev)
376
char buf[PACKET_SIZE];
377
struct fpga_packet_header *phead = (struct fpga_packet_header *)buf;
378
struct myeeprom *eeprom;
380
assert(mydev != NULL);
381
eeprom = &mydev->eeprom;
382
DBG("%s Start...\n", __FUNCTION__);
383
phead->header.op = PT_EEPROM_GET;
384
len = sizeof(phead->header.op); /* warning: sending small packet */
385
ret = send_usb("eeprom_get[W]", mydev, phead, len, TIMEOUT);
388
ret = recv_usb("eeprom_get[R]", mydev, buf, sizeof(buf), TIMEOUT);
391
phead = (struct fpga_packet_header *)buf;
392
if(phead->header.op == PT_BAD_COMMAND) {
393
ERR("PT_BAD_COMMAND\n");
395
} else if(phead->header.op != PT_EEPROM_GET) {
396
ERR("Got unexpected reply op=%d\n", phead->header.op);
399
memcpy(eeprom, &phead->d.eeprom_get.data, EEPROM_SIZE);
403
int send_hexline(struct my_usb_device *mydev, struct hexline *hexline, int seq)
408
char buf[PACKET_SIZE];
409
struct fpga_packet_header *phead = (struct fpga_packet_header *)buf;
410
enum fpga_load_status status;
412
assert(mydev != NULL);
413
assert(hexline != NULL);
414
if(hexline->d.content.header.tt != TT_DATA) {
415
DBG("Non data record %d type = %d\n", seq, hexline->d.content.header.tt);
418
len = hexline->d.content.header.ll; /* don't send checksum */
419
data = hexline->d.content.tt_data.data;
420
phead->header.op = PT_DATA_PACKET;
421
phead->d.data_packet.seq = seq;
422
phead->d.data_packet.reserved = 0x00;
423
memcpy(phead->d.data_packet.data, data, len);
424
len += sizeof(hexline->d.content.header);
426
ret = send_usb("hexline[W]", mydev, phead, len, TIMEOUT);
429
ret = recv_usb("hexline[R]", mydev, buf, sizeof(buf), TIMEOUT);
433
phead = (struct fpga_packet_header *)buf;
434
if(phead->header.op != PT_STATUS_REPLY) {
435
ERR("Got unexpected reply op=%d\n", phead->header.op);
436
dump_packet("hexline[ERR]", buf, ret);
439
status = (enum fpga_load_status)phead->d.status_reply.status;
446
ERR("status reply %s (%d)\n", load_status2str(status), status);
447
dump_packet("hexline[ERR]", buf, ret);
450
ERR("Unknown status reply %d\n", status);
451
dump_packet("hexline[ERR]", buf, ret);
457
//. returns > 0 - ok, the number of lines sent
458
//. returns < 0 - error number
459
int send_splited_hexline(struct my_usb_device *mydev, struct hexline *hexline, int seq, uint8_t maxwidth)
461
struct hexline *extraline;
464
int extra_offset = 0;
465
unsigned int this_line = 0;
466
uint8_t bytesleft = 0;
468
assert(mydev != NULL);
470
ERR("Bad record %d type = %d\n", seq, hexline->d.content.header.tt);
473
bytesleft = hexline->d.content.header.ll;
474
// split the line into several lines
475
while (bytesleft > 0) {
477
this_line = (bytesleft >= maxwidth) ? maxwidth : bytesleft;
478
allocsize = sizeof(struct hexline) + this_line + 1;
479
// generate the new line
480
if((extraline = (struct hexline *)malloc(allocsize)) == NULL) {
481
ERR("Not enough memory for spliting the lines\n" );
484
memset(extraline, 0, allocsize);
485
extraline->d.content.header.ll = this_line;
486
extraline->d.content.header.offset = hexline->d.content.header.offset + extra_offset;
487
extraline->d.content.header.tt = hexline->d.content.header.tt;
488
memcpy( extraline->d.content.tt_data.data, hexline->d.content.tt_data.data+extra_offset, this_line);
489
status = send_hexline(mydev, extraline, seq+linessent );
492
extra_offset += this_line;
493
bytesleft -= this_line;
501
int match_usb_device_identity(const struct usb_config_descriptor *config_desc,
502
const struct astribank_type *ab)
504
struct usb_interface *interface;
505
struct usb_interface_descriptor *iface_desc;
507
if(config_desc->bNumInterfaces <= ab->my_interface_num)
509
interface = &config_desc->interface[ab->my_interface_num];
510
iface_desc = interface->altsetting;
512
return iface_desc->bInterfaceClass == 0xFF &&
513
iface_desc->bInterfaceNumber == ab->my_interface_num &&
514
iface_desc->bNumEndpoints == ab->num_endpoints;
517
const struct astribank_type *my_usb_device_identify(const char devpath[], struct my_usb_device *mydev)
519
struct usb_device_descriptor *dev_desc;
520
struct usb_config_descriptor *config_desc;
523
assert(mydev != NULL);
527
mydev->dev = dev_of_path(devpath);
529
ERR("Bailing out\n");
532
dev_desc = &mydev->dev->descriptor;
533
config_desc = mydev->dev->config;
534
for(i = 0; i < sizeof(astribank_types)/sizeof(astribank_types[0]); i++) {
535
if(match_usb_device_identity(config_desc, &astribank_types[i])) {
536
DBG("Identified[%d]: interfaces=%d endpoints=%d: \"%s\"\n",
538
astribank_types[i].num_interfaces,
539
astribank_types[i].num_endpoints,
540
astribank_types[i].name);
541
return &astribank_types[i];
547
int my_usb_device_init(const char devpath[], struct my_usb_device *mydev, const struct astribank_type *abtype)
549
struct usb_device_descriptor *dev_desc;
550
struct usb_config_descriptor *config_desc;
551
struct usb_interface *interface;
552
struct usb_interface_descriptor *iface_desc;
553
struct usb_endpoint_descriptor *endpoint;
557
assert(mydev != NULL);
561
mydev->dev = dev_of_path(devpath);
563
ERR("Bailing out\n");
566
mydev->handle = usb_open(mydev->dev);
568
ERR("Failed to open usb device '%s/%s': %s\n", mydev->dev->bus->dirname, mydev->dev->filename, usb_strerror());
571
if(usb_claim_interface(mydev->handle, abtype->my_interface_num) != 0) {
572
ERR("usb_claim_interface: %s\n", usb_strerror());
575
dev_desc = &mydev->dev->descriptor;
576
config_desc = mydev->dev->config;
578
ERR("usb interface without a configuration\n");
581
interface = &config_desc->interface[abtype->my_interface_num];
582
iface_desc = interface->altsetting;
583
endpoint = iface_desc->endpoint;
584
mydev->is_usb2 = (endpoint->wMaxPacketSize == 512);
585
for(i = 0; i < iface_desc->bNumEndpoints; i++, endpoint++) {
586
if(endpoint->bEndpointAddress != abtype->endpoints[i]) {
587
ERR("Wrong endpoint 0x%X (at index %d)\n", endpoint->bEndpointAddress, i);
590
if(endpoint->bEndpointAddress == MY_EP_OUT || endpoint->bEndpointAddress == MY_EP_IN) {
591
if(endpoint->wMaxPacketSize > PACKET_SIZE) {
592
ERR("Endpoint #%d wMaxPacketSize too large (%d)\n", i, endpoint->wMaxPacketSize);
597
mydev->abtype = abtype;
598
mydev->my_ep_in = abtype->my_ep_in;
599
mydev->my_ep_out = abtype->my_ep_out;
600
ret = get_usb_string(mydev->iManufacturer, BUFSIZ, dev_desc->iManufacturer, mydev->handle);
601
ret = get_usb_string(mydev->iProduct, BUFSIZ, dev_desc->iProduct, mydev->handle);
602
ret = get_usb_string(mydev->iSerialNumber, BUFSIZ, dev_desc->iSerialNumber, mydev->handle);
603
ret = get_usb_string(mydev->iInterface, BUFSIZ, iface_desc->iInterface, mydev->handle);
604
INFO("ID=%04X:%04X Manufacturer=[%s] Product=[%s] SerialNumber=[%s] Interface=[%s]\n",
607
mydev->iManufacturer,
609
mydev->iSerialNumber,
611
if(usb_clear_halt(mydev->handle, mydev->my_ep_out) != 0) {
612
ERR("Clearing output endpoint: %s\n", usb_strerror());
615
if(usb_clear_halt(mydev->handle, mydev->my_ep_in) != 0) {
616
ERR("Clearing input endpoint: %s\n", usb_strerror());
622
int renumerate_device(struct my_usb_device *mydev, enum fpga_load_packet_types pt)
624
char buf[PACKET_SIZE];
625
struct fpga_packet_header *phead = (struct fpga_packet_header *)buf;
628
assert(mydev != NULL);
629
DBG("Renumerating with 0x%X\n", pt);
630
phead->header.op = pt;
631
ret = send_usb("renumerate[W]", mydev, phead, 1, TIMEOUT);
632
if(ret < 0 && ret != -ENODEV)
636
* FIXME: we count on our USB firmware to reset the device... should we?
638
ret = usb_reset(mydev->handle);
640
ERR("usb_reset: %s\n", usb_strerror());
648
* Returns: true on success, false on failure
650
int fpga_load(struct my_usb_device *mydev, const struct hexdata *hexdata)
656
const char *v = hexdata->version_info;
658
v = (v[0]) ? v : "Unknown";
659
assert(mydev != NULL);
660
INFO("FPGA_LOAD (version %s)\n", v);
662
* i - is the line number
663
* j - is the sequence number, on USB 2, i=j, but on
664
* USB 1 send_splited_hexline may increase the sequence
665
* number, as it needs
667
for(i = 0; i < hexdata->maxlines; i++) {
668
struct hexline *hexline = hexdata->lines[i];
673
ERR("Extra data after End Of Data Record (line %d)\n", i);
676
if(hexline->d.content.header.tt == TT_EOF) {
677
DBG("End of data\n");
682
if((ret = send_hexline(mydev, hexline, i)) != 0) {
683
perror("Failed sending hexline");
687
if((ret = send_splited_hexline(mydev, hexline, j, 60)) < 0) {
688
perror("Failed sending hexline (splitting did not help)");
694
DBG("Finished...\n");
702
fprintf(stderr, "Usage: %s -D {/proc/bus/usb|/dev/bus/usb}/<bus>/<dev> [options...]\n", progname);
703
fprintf(stderr, "\tOptions:\n");
704
fprintf(stderr, "\t\t[-r] # Reset the device\n");
705
fprintf(stderr, "\t\t[-b <binfile>] # Output to <binfile>\n");
706
fprintf(stderr, "\t\t[-I <hexfile>] # Input from <hexfile>\n");
707
fprintf(stderr, "\t\t[-H <hexfile>] # Output to <hexfile> ('-' is stdout)\n");
708
fprintf(stderr, "\t\t[-i] # Show hexfile information\n");
709
fprintf(stderr, "\t\t[-g] # Get eeprom from device\n");
710
fprintf(stderr, "\t\t[-v] # Increase verbosity\n");
711
#ifdef XORCOM_INTERNAL
712
fprintf(stderr, "\t\t[-C srC byte] # Set Address sourCe (default: C0)\n");
713
fprintf(stderr, "\t\t[-V vendorid] # Set Vendor id on device\n");
714
fprintf(stderr, "\t\t[-P productid] # Set Product id on device\n");
715
fprintf(stderr, "\t\t[-R release] # Set Release. 2 dot separated decimals\n");
716
fprintf(stderr, "\t\t[-L label] # Set label.\n");
721
static void parse_report_func(int level, const char *msg, ...)
727
vfprintf(stderr, msg, ap);
731
#ifdef XORCOM_INTERNAL
732
static void eeprom_fill(struct myeeprom *myeeprom,
734
const char product[],
735
const char release[],
739
// FF: address source is from device. C0: from eeprom
741
myeeprom->source = strtoul(source, NULL, 0);
743
myeeprom->source = 0xC0;
745
myeeprom->vendor = strtoul(vendor, NULL, 0);
747
myeeprom->product = strtoul(product, NULL, 0);
749
int release_major = 0;
750
int release_minor = 0;
752
sscanf(release, "%d.%d", &release_major, &release_minor);
753
myeeprom->release_major = release_major;
754
myeeprom->release_minor = release_minor;
758
memset(myeeprom->label, 0, LABEL_SIZE);
759
memcpy(myeeprom->label, label, strlen(label));
764
int main(int argc, char *argv[])
766
const struct astribank_type *abtype;
767
struct my_usb_device mydev;
768
const char *devpath = NULL;
769
const char *binfile = NULL;
770
const char *inhexfile = NULL;
771
const char *outhexfile = NULL;
772
struct hexdata *hexdata = NULL;
775
int opt_read_eeprom = 0;
776
int opt_output_width = 0;
777
int output_is_set = 0;
778
#ifdef XORCOM_INTERNAL
779
int opt_write_eeprom = 0;
782
char *product = NULL;
783
char *release = NULL;
785
const char options[] = "rib:D:ghH:I:vw:C:V:P:R:S:";
787
const char options[] = "rib:D:ghH:I:vw:";
792
assert(sizeof(struct fpga_packet_header) <= PACKET_SIZE);
793
assert(sizeof(struct myeeprom) == EEPROM_SIZE);
797
c = getopt (argc, argv, options);
804
if(output_is_set++) {
805
ERR("Cannot set -D. Another output option is already selected\n");
817
if(output_is_set++) {
818
ERR("Cannot set -b. Another output option is already selected\n");
827
if(output_is_set++) {
828
ERR("Cannot set -H. Another output option is already selected\n");
835
#ifdef XORCOM_INTERNAL
851
const char GOOD_CHARS[] =
852
"abcdefghijklmnopqrstuvwxyz"
853
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
856
int len = strlen(label);
857
int goodlen = strspn(label, GOOD_CHARS);
859
if(len > LABEL_SIZE) {
860
ERR("Label too long (%d > %d)\n", len, LABEL_SIZE);
864
ERR("Bad character in label number (pos=%d)\n", goodlen);
871
opt_output_width = strtoul(optarg, NULL, 0);
878
ERR("Unknown option '%c'\n", c);
883
if (optind != argc) {
887
#ifdef XORCOM_INTERNAL
888
if(vendor || product || release || label || source ) {
889
ERR("The -I option is exclusive of -[VPRSC]\n");
893
parse_hexfile_set_reporting(parse_report_func);
894
hexdata = parse_hexfile(inhexfile, MAX_HEX_LINES);
896
ERR("Bailing out\n");
900
printf("%s: Version=%s Checksum=%d\n",
901
inhexfile, hexdata->version_info,
902
bsd_checksum(hexdata));
905
dump_binary(hexdata, binfile);
910
dump_hexfile2(hexdata, outhexfile, opt_output_width);
912
dump_hexfile(hexdata, outhexfile);
916
#ifdef XORCOM_INTERNAL
917
else if(vendor || product || release || label || source ) {
921
if(strcmp(outhexfile, "-") == 0)
923
else if((fp = fopen(outhexfile, "w")) == NULL) {
927
memset(&mydev.eeprom, 0, sizeof(struct myeeprom));
928
eeprom_fill(&mydev.eeprom, vendor, product, release, label, source);
929
gen_hexline((uint8_t *)&mydev.eeprom, 0, sizeof(mydev.eeprom), fp);
930
gen_hexline(NULL, 0, 0, fp); /* EOF */
936
ERR("Missing device path\n");
939
DBG("Startup %s\n", devpath);
940
if((abtype = my_usb_device_identify(devpath, &mydev)) == NULL) {
941
ERR("Bad device. Does not match our types.\n");
944
INFO("FIRMWARE: %s (type=%d)\n", abtype->name, abtype->type_code);
945
if(!my_usb_device_init(devpath, &mydev, abtype)) {
946
ERR("Failed to initialize USB device '%s'\n", devpath);
950
ret = eeprom_get(&mydev);
952
ERR("Failed reading eeprom\n");
955
#ifdef XORCOM_INTERNAL
956
if(vendor || product || release || label || source ) {
957
eeprom_fill(&mydev.eeprom, vendor, product, release, label, source);
958
opt_write_eeprom = 1;
962
if(opt_read_eeprom) {
963
show_device_info(&mydev);
967
INFO("Warning: working on a low end USB1 backend\n");
968
if(!fpga_load(&mydev, hexdata)) {
969
ERR("FPGA loading failed\n");
973
ret = renumerate_device(&mydev, PT_RENUMERATE);
975
ERR("Renumeration failed: errno=%d\n", ret);
979
#ifdef XORCOM_INTERNAL
980
else if(opt_write_eeprom) {
981
if(abtype->type_code == USB_FIRMWARE_II) {
982
ERR("No EEPROM burning command in %s. Use fxload for that\n",
986
ret = eeprom_set(&mydev, &mydev.eeprom);
988
ERR("Failed writing eeprom: %s\n", strerror(-ret));
991
printf("------- RESULTS -------\n");
992
show_device_info(&mydev);
996
DBG("Reseting to default\n");
997
ret = renumerate_device(&mydev, PT_RESET);
999
ERR("Renumeration to default failed: errno=%d\n", ret);
1005
my_usb_device_cleanup(&mydev);