forked from len0rd/rockbox
sbtools/sbload: prepare support for the stmp36xx
Change-Id: I13147009f2573d80c2c3dca2852a6d7b45174e9d
This commit is contained in:
parent
2a52b937e4
commit
153bc0d7ec
1 changed files with 96 additions and 76 deletions
|
|
@ -40,99 +40,36 @@ void put32be(uint8_t *buf, uint32_t i)
|
||||||
*buf++ = i & 0xff;
|
*buf++ = i & 0xff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum dev_type_t
|
||||||
|
{
|
||||||
|
HID_DEVICE,
|
||||||
|
RECOVERY_DEVICE,
|
||||||
|
};
|
||||||
|
|
||||||
struct dev_info_t
|
struct dev_info_t
|
||||||
{
|
{
|
||||||
uint16_t vendor_id;
|
uint16_t vendor_id;
|
||||||
uint16_t product_id;
|
uint16_t product_id;
|
||||||
unsigned xfer_size;
|
unsigned xfer_size;
|
||||||
|
enum dev_type_t dev_type;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct dev_info_t g_dev_info[] =
|
struct dev_info_t g_dev_info[] =
|
||||||
{
|
{
|
||||||
{0x066f, 0x3780, 1024}, /* i.MX233 / STMP3780 */
|
{0x066f, 0x3780, 1024, HID_DEVICE}, /* i.MX233 / STMP3780 */
|
||||||
{0x066f, 0x3770, 48}, /* STMP3770 */
|
{0x066f, 0x3770, 48, HID_DEVICE}, /* STMP3770 */
|
||||||
{0x15A2, 0x004F, 1024}, /* i.MX28 */
|
{0x15A2, 0x004F, 1024, HID_DEVICE}, /* i.MX28 */
|
||||||
|
{0x066f, 0x3600, 4096, RECOVERY_DEVICE}, /* STMP36xx */
|
||||||
};
|
};
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int send_hid(libusb_device_handle *dev, int xfer_size, uint8_t *data, int size, int nr_xfers)
|
||||||
{
|
{
|
||||||
int ret;
|
|
||||||
FILE *f;
|
|
||||||
int i, xfer_size, nr_xfers, recv_size;
|
|
||||||
|
|
||||||
if(argc != 3)
|
|
||||||
{
|
|
||||||
printf("usage: %s <xfer size> <file>\n", argv[0]);
|
|
||||||
printf("If <xfer size> is set to zero, the preferred one is used.\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
char *end;
|
|
||||||
xfer_size = strtol(argv[1], &end, 0);
|
|
||||||
if(end != (argv[1] + strlen(argv[1])))
|
|
||||||
{
|
|
||||||
printf("Invalid transfer size !\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
libusb_device_handle *dev;
|
|
||||||
|
|
||||||
libusb_init(NULL);
|
|
||||||
|
|
||||||
libusb_set_debug(NULL, 3);
|
|
||||||
|
|
||||||
for(unsigned i = 0; i < sizeof(g_dev_info) / sizeof(g_dev_info[0]); i++)
|
|
||||||
{
|
|
||||||
dev = libusb_open_device_with_vid_pid(NULL,
|
|
||||||
g_dev_info[i].vendor_id, g_dev_info[i].product_id);
|
|
||||||
if(dev == NULL)
|
|
||||||
continue;
|
|
||||||
if(xfer_size == 0)
|
|
||||||
xfer_size = g_dev_info[i].xfer_size;
|
|
||||||
printf("Found a match for %04x:%04x\n",
|
|
||||||
g_dev_info[i].vendor_id, g_dev_info[i].product_id);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(dev == NULL)
|
|
||||||
{
|
|
||||||
printf("Cannot open device\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
libusb_detach_kernel_driver(dev, 0);
|
libusb_detach_kernel_driver(dev, 0);
|
||||||
libusb_detach_kernel_driver(dev, 4);
|
libusb_detach_kernel_driver(dev, 4);
|
||||||
|
|
||||||
libusb_claim_interface (dev, 0);
|
libusb_claim_interface (dev, 0);
|
||||||
libusb_claim_interface (dev, 4);
|
libusb_claim_interface (dev, 4);
|
||||||
|
|
||||||
if(!dev)
|
|
||||||
{
|
|
||||||
printf("No dev\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
f = fopen(argv[2], "r");
|
|
||||||
if(f == NULL)
|
|
||||||
{
|
|
||||||
perror("cannot open file");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
fseek(f, 0, SEEK_END);
|
|
||||||
size_t size = ftell(f);
|
|
||||||
fseek(f, 0, SEEK_SET);
|
|
||||||
|
|
||||||
printf("Transfer size: %d\n", xfer_size);
|
|
||||||
nr_xfers = (size + xfer_size - 1) / xfer_size;
|
|
||||||
uint8_t *file_buf = malloc(nr_xfers * xfer_size);
|
|
||||||
memset(file_buf, 0xff, nr_xfers * xfer_size); // pad with 0xff
|
|
||||||
if(fread(file_buf, size, 1, f) != 1)
|
|
||||||
{
|
|
||||||
perror("read error");
|
|
||||||
fclose(f);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
fclose(f);
|
|
||||||
|
|
||||||
uint8_t *xfer_buf = malloc(1 + xfer_size);
|
uint8_t *xfer_buf = malloc(1 + xfer_size);
|
||||||
uint8_t *p = xfer_buf;
|
uint8_t *p = xfer_buf;
|
||||||
|
|
||||||
|
|
@ -154,7 +91,7 @@ int main(int argc, char **argv)
|
||||||
*p++ = 0x02; /* Firmware download */
|
*p++ = 0x02; /* Firmware download */
|
||||||
put32be(p, size); /* Download size */
|
put32be(p, size); /* Download size */
|
||||||
|
|
||||||
ret = libusb_control_transfer(dev,
|
int ret = libusb_control_transfer(dev,
|
||||||
LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_INTERFACE, 0x9, 0x201, 0,
|
LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_INTERFACE, 0x9, 0x201, 0,
|
||||||
xfer_buf, xfer_size + 1, 1000);
|
xfer_buf, xfer_size + 1, 1000);
|
||||||
if(ret < 0)
|
if(ret < 0)
|
||||||
|
|
@ -163,10 +100,10 @@ int main(int argc, char **argv)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(i = 0; i < nr_xfers; i++)
|
for(int i = 0; i < nr_xfers; i++)
|
||||||
{
|
{
|
||||||
xfer_buf[0] = 0x2;
|
xfer_buf[0] = 0x2;
|
||||||
memcpy(&xfer_buf[1], &file_buf[i * xfer_size], xfer_size);
|
memcpy(&xfer_buf[1], &data[i * xfer_size], xfer_size);
|
||||||
|
|
||||||
ret = libusb_control_transfer(dev,
|
ret = libusb_control_transfer(dev,
|
||||||
LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_INTERFACE,
|
LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_INTERFACE,
|
||||||
|
|
@ -178,6 +115,7 @@ int main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int recv_size;
|
||||||
ret = libusb_interrupt_transfer(dev, 0x81, xfer_buf, xfer_size, &recv_size,
|
ret = libusb_interrupt_transfer(dev, 0x81, xfer_buf, xfer_size, &recv_size,
|
||||||
1000);
|
1000);
|
||||||
if(ret < 0)
|
if(ret < 0)
|
||||||
|
|
@ -186,7 +124,89 @@ int main(int argc, char **argv)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("ret %i\n", ret);
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int send_recovery(libusb_device_handle *dev, int xfer_size, uint8_t *data, int size, int nr_xfers)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
if(argc != 3)
|
||||||
|
{
|
||||||
|
printf("usage: %s <xfer size> <file>\n", argv[0]);
|
||||||
|
printf("If <xfer size> is set to zero, the preferred one is used.\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *end;
|
||||||
|
int xfer_size = strtol(argv[1], &end, 0);
|
||||||
|
if(end != (argv[1] + strlen(argv[1])))
|
||||||
|
{
|
||||||
|
printf("Invalid transfer size !\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
libusb_device_handle *dev;
|
||||||
|
|
||||||
|
libusb_init(NULL);
|
||||||
|
|
||||||
|
libusb_set_debug(NULL, 3);
|
||||||
|
|
||||||
|
unsigned i;
|
||||||
|
for(i = 0; i < sizeof(g_dev_info) / sizeof(g_dev_info[0]); i++)
|
||||||
|
{
|
||||||
|
dev = libusb_open_device_with_vid_pid(NULL,
|
||||||
|
g_dev_info[i].vendor_id, g_dev_info[i].product_id);
|
||||||
|
if(dev == NULL)
|
||||||
|
continue;
|
||||||
|
if(xfer_size == 0)
|
||||||
|
xfer_size = g_dev_info[i].xfer_size;
|
||||||
|
printf("Found a match for %04x:%04x\n",
|
||||||
|
g_dev_info[i].vendor_id, g_dev_info[i].product_id);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(dev == NULL)
|
||||||
|
{
|
||||||
|
printf("Cannot open device\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
FILE *f = fopen(argv[2], "r");
|
||||||
|
if(f == NULL)
|
||||||
|
{
|
||||||
|
perror("cannot open file");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
fseek(f, 0, SEEK_END);
|
||||||
|
size_t size = ftell(f);
|
||||||
|
fseek(f, 0, SEEK_SET);
|
||||||
|
|
||||||
|
printf("Transfer size: %d\n", xfer_size);
|
||||||
|
int nr_xfers = (size + xfer_size - 1) / xfer_size;
|
||||||
|
uint8_t *file_buf = malloc(nr_xfers * xfer_size);
|
||||||
|
memset(file_buf, 0xff, nr_xfers * xfer_size); // pad with 0xff
|
||||||
|
if(fread(file_buf, size, 1, f) != 1)
|
||||||
|
{
|
||||||
|
perror("read error");
|
||||||
|
fclose(f);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
fclose(f);
|
||||||
|
|
||||||
|
switch(g_dev_info[i].dev_type)
|
||||||
|
{
|
||||||
|
case HID_DEVICE:
|
||||||
|
send_hid(dev, xfer_size, file_buf, size, nr_xfers);
|
||||||
|
break;
|
||||||
|
case RECOVERY_DEVICE:
|
||||||
|
send_recovery(dev, xfer_size, file_buf, size, nr_xfers);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
printf("unknown device type\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue