Steve Underwood wrote:
This rule certainly gets things started. When I plug in the FET tool the driver is loaded, but then I get "ti_download_firmware - error downloading firmware". The older rule create two phases - a boot load phase, and a running phase.

My rule would be for phase one (SYSFS{bNumEndpoints}=="01", the device
with loaded firmware would have two endpoints).

Some weeks ago I had written an experimental external firmware
downloader for the device, as I think doing this out of kernel space is
much cleaner, anyway. I'll attach it. It should be rewritten to load the
firmware to a specific address (currently, it scans the bus and
downloads to every "virgin" USB FET by vendor/product id). It can
download a binary firmware like umpf3410.i51 from the windows driver.

Enrik

#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#include <usb.h>

#define CHECK(call, msg) \
  if (!(call)) { perror(msg); exit(1); }

#define CHECKU(call, msg) \
  if (0 < (errno = -1 * call)) { perror(msg); exit(1); } else { errno = 0; }

static char buffer[3 + 16284];

int
main(int argc, char *argv[])
{
  int i;
  FILE *fw;
  struct usb_bus *bus, *busses;
  struct usb_device *dev, *devices;
  usb_dev_handle *fet = 0;
  size_t len;

  memset(buffer, 0xff, sizeof(buffer));
  CHECK(fw = fopen(argv[1], "r"), "fopen");
  CHECK(0 < (len = fread(buffer + 3, 1, sizeof(buffer) - 3, fw)), "fread");
  buffer[0] = (sizeof(buffer)-3) & 0xff;
  buffer[1] = (sizeof(buffer)-3) >> 8;
  buffer[2] = 0;
  for (i = 3; i < sizeof(buffer); i++)
    buffer[2] = (unsigned char)(buffer[2] + buffer[i]);
  printf("len = %d\n", len);
  printf("len = %d\n", buffer[0] + (buffer[1]<<8));
  printf("sum = %u\n", buffer[2]&0xff);

  usb_init();
  if (0 == usb_find_busses() ||
      0 == usb_find_devices()) {
    printf("no USB devices found\n");
    exit(0);
  }

  busses = usb_get_busses();
  for (bus = busses; bus; bus = bus->next) {
    devices = bus->devices;
    for (dev = devices; dev; dev = dev->next) {
      if (dev->descriptor.idVendor == 0x0451 &&
	  dev->descriptor.idProduct == 0xf430) {
	fet = usb_open(dev);
	break;
      }
    }
  }

  if (0 == fet) {
    printf("no FET430 found\n");
    exit(0);
  }

  if (dev->descriptor.bNumConfigurations == 2 &&
      dev->config->bConfigurationValue == 2) {
    CHECKU(usb_set_configuration(fet, 1), "usb_set_configuration");
  }
  CHECKU(usb_claim_interface(fet, 0), "usb_claim_interface");

  CHECKU(usb_clear_halt(fet, 1), "usb_clear_halt");
  for(i = 0; i < sizeof(buffer); i += 64) {
    int s = sizeof(buffer)-i < 64 ? sizeof(buffer)-i : 64;
    printf("%04d %02d\r", i, s);
    fflush(stdout);
    CHECKU(usb_bulk_write(fet, 1, buffer+i, s, 1000), "usb_bulk_write");
  }
  puts("");
  sleep(1);
  //CHECKU(usb_control_msg(fet, 0x40, 0x85, 0, 0, 0, 0, 1000), "usb_control_msg");;
  CHECKU(usb_reset(fet), "usb_reset");

  exit(0);
}

all: fet430dl

CFLAGS=-Wall
LDLIBS=-lusb

Reply via email to