summaryrefslogtreecommitdiffstats
path: root/utils/hwstub/lib
diff options
context:
space:
mode:
authorAmaury Pouly <amaury.pouly@gmail.com>2014-08-04 20:26:48 +0200
committerAmaury Pouly <amaury.pouly@gmail.com>2014-09-07 17:45:21 +0200
commit43ca127ebfe9766c84a0456dbac5cafd5f4cb451 (patch)
treecd6a7caa4c29b95e266cc444c4b483c90f3d076a /utils/hwstub/lib
parent12ce7fc2cce5531723ea7d141df80142891989d7 (diff)
downloadrockbox-43ca127ebfe9766c84a0456dbac5cafd5f4cb451.tar.gz
rockbox-43ca127ebfe9766c84a0456dbac5cafd5f4cb451.tar.bz2
rockbox-43ca127ebfe9766c84a0456dbac5cafd5f4cb451.zip
hwstub: fix library to actually work and compile, still miss some functions
Change-Id: I968dafb4dca7d674165a43e3a435762fe38ed37f
Diffstat (limited to 'utils/hwstub/lib')
-rw-r--r--utils/hwstub/lib/hwstub.c53
1 files changed, 50 insertions, 3 deletions
diff --git a/utils/hwstub/lib/hwstub.c b/utils/hwstub/lib/hwstub.c
index 9f46159026..8e5cb98d29 100644
--- a/utils/hwstub/lib/hwstub.c
+++ b/utils/hwstub/lib/hwstub.c
@@ -101,7 +101,7 @@ struct hwstub_device_t *hwstub_open(libusb_device_handle *handle)
struct hwstub_layout_desc_t layout;
int sz = hwstub_get_desc(dev, HWSTUB_DT_LAYOUT, &layout, sizeof(layout));
if(sz == (int)sizeof(layout))
- dev->buf_sz = layout->dBufferSize;
+ dev->buf_sz = layout.dBufferSize;
return dev;
Lerr:
@@ -135,16 +135,59 @@ static int _hwstub_read(struct hwstub_device_t *dev, uint32_t addr, void *buf, s
read.dAddress = addr;
int size = libusb_control_transfer(dev->handle,
LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_INTERFACE | LIBUSB_ENDPOINT_OUT,
- HWSTUB_READ, dev->id, dev->intf, &read, sizeof(read), 1000);
+ HWSTUB_READ, dev->id, dev->intf, (void *)&read, sizeof(read), 1000);
if(size != (int)sizeof(read))
return -1;
return libusb_control_transfer(dev->handle,
LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_INTERFACE | LIBUSB_ENDPOINT_IN,
- HWSTUB_READ2, dev->id++, dev->intf, &read, sizeof(read), 1000);
+ HWSTUB_READ2, dev->id++, dev->intf, buf, sz, 1000);
}
+static int _hwstub_write(struct hwstub_device_t *dev, uint32_t addr, void *buf, size_t sz)
+{
+ size_t hdr_sz = sizeof(struct hwstub_write_req_t);
+ struct hwstub_write_req_t *req = malloc(sz + hdr_sz);
+ req->dAddress = addr;
+ memcpy(req + 1, buf, sz);
+ int size = libusb_control_transfer(dev->handle,
+ LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_INTERFACE | LIBUSB_ENDPOINT_OUT,
+ HWSTUB_WRITE, dev->id++, dev->intf, (void *)req, sz + hdr_sz, 1000);
+ free(req);
+ return size - hdr_sz;
+}
+
+/* Intermediate function which make sure we don't overflow the device buffer */
+int hwstub_read(struct hwstub_device_t *dev, uint32_t addr, void *buf, size_t sz)
+{
+ int cnt = 0;
+ while(sz > 0)
+ {
+ int xfer = _hwstub_read(dev, addr, buf, MIN(sz, dev->buf_sz));
+ if(xfer < 0)
+ return xfer;
+ sz -= xfer;
+ buf += xfer;
+ addr += xfer;
+ cnt += xfer;
+ }
+ return cnt;
+}
+
+/* Intermediate function which make sure we don't overflow the device buffer */
int hwstub_write(struct hwstub_device_t *dev, uint32_t addr, void *buf, size_t sz)
{
+ int cnt = 0;
+ while(sz > 0)
+ {
+ int xfer = _hwstub_write(dev, addr, buf, MIN(sz, dev->buf_sz - sizeof(struct hwstub_write_req_t)));
+ if(xfer < 0)
+ return xfer;
+ sz -= xfer;
+ buf += xfer;
+ addr += xfer;
+ cnt += xfer;
+ }
+ return cnt;
}
int hwstub_rw_mem(struct hwstub_device_t *dev, int read, uint32_t addr, void *buf, size_t sz)
@@ -160,6 +203,8 @@ int hwstub_call(struct hwstub_device_t *dev, uint32_t addr)
LIBUSB_ENDPOINT_OUT, HWSTUB_CALL, addr & 0xffff, addr >> 16, NULL, 0,
1000);
#else
+ (void) dev;
+ (void) addr;
return -1;
#endif
}
@@ -172,6 +217,8 @@ int hwstub_jump(struct hwstub_device_t *dev, uint32_t addr)
LIBUSB_ENDPOINT_OUT, HWSTUB_JUMP, addr & 0xffff, addr >> 16, NULL, 0,
1000);
#else
+ (void) dev;
+ (void) addr;
return -1;
#endif
}