summaryrefslogtreecommitdiffstats
path: root/utils
diff options
context:
space:
mode:
authorAmaury Pouly <amaury.pouly@gmail.com>2012-12-13 16:02:58 +0100
committerAmaury Pouly <amaury.pouly@gmail.com>2012-12-13 16:02:58 +0100
commit788bf2e3b25a52fa0dca3cf1266a6570391b83a7 (patch)
tree62feb4693bf3af5ca6fa92b15676745edc7edc26 /utils
parent153bc0d7ec9f261072d18dde6d4356394ad4c1dc (diff)
downloadrockbox-788bf2e3b25a52fa0dca3cf1266a6570391b83a7.tar.gz
rockbox-788bf2e3b25a52fa0dca3cf1266a6570391b83a7.tar.bz2
rockbox-788bf2e3b25a52fa0dca3cf1266a6570391b83a7.zip
imxtools/sbloader: implement stmp36xx recovery support
Change-Id: I6cfb432cd474ca00d7dff77577c0aa499b78fe2d
Diffstat (limited to 'utils')
-rw-r--r--utils/imxtools/sbtools/sbloader.c32
1 files changed, 30 insertions, 2 deletions
diff --git a/utils/imxtools/sbtools/sbloader.c b/utils/imxtools/sbtools/sbloader.c
index 854bb85965..a5bc8c18fb 100644
--- a/utils/imxtools/sbtools/sbloader.c
+++ b/utils/imxtools/sbtools/sbloader.c
@@ -24,6 +24,10 @@
#include <libusb.h>
#include <stdint.h>
+#ifndef MIN
+#define MIN(a,b) ((a) < (b) ? (a) : (b))
+#endif
+
void put32le(uint8_t *buf, uint32_t i)
{
*buf++ = i & 0xff;
@@ -67,8 +71,8 @@ int send_hid(libusb_device_handle *dev, int xfer_size, uint8_t *data, int size,
libusb_detach_kernel_driver(dev, 0);
libusb_detach_kernel_driver(dev, 4);
- libusb_claim_interface (dev, 0);
- libusb_claim_interface (dev, 4);
+ libusb_claim_interface(dev, 0);
+ libusb_claim_interface(dev, 4);
uint8_t *xfer_buf = malloc(1 + xfer_size);
uint8_t *p = xfer_buf;
@@ -129,6 +133,30 @@ int send_hid(libusb_device_handle *dev, int xfer_size, uint8_t *data, int size,
int send_recovery(libusb_device_handle *dev, int xfer_size, uint8_t *data, int size, int nr_xfers)
{
+ (void) nr_xfers;
+ // there should be no kernel driver attached but in doubt...
+ libusb_detach_kernel_driver(dev, 0);
+ libusb_claim_interface(dev, 0);
+
+ int sent = 0;
+ while(sent < size)
+ {
+ int xfered;
+ int len = MIN(size - sent, xfer_size);
+ int ret = libusb_bulk_transfer(dev, 1, data + sent, len, &xfered, 1000);
+ if(ret < 0)
+ {
+ printf("transfer error at send offset %d\n", sent);
+ return 1;
+ }
+ if(xfered == 0)
+ {
+ printf("empty transfer at step offset %d\n", sent);
+ return 2;
+ }
+ sent += xfered;
+ }
+ return 0;
}
int main(int argc, char **argv)