diff options
author | Amaury Pouly <amaury.pouly@gmail.com> | 2014-08-04 20:26:48 +0200 |
---|---|---|
committer | Amaury Pouly <amaury.pouly@gmail.com> | 2014-09-07 17:45:21 +0200 |
commit | 43ca127ebfe9766c84a0456dbac5cafd5f4cb451 (patch) | |
tree | cd6a7caa4c29b95e266cc444c4b483c90f3d076a /utils/hwstub | |
parent | 12ce7fc2cce5531723ea7d141df80142891989d7 (diff) | |
download | rockbox-43ca127ebfe9766c84a0456dbac5cafd5f4cb451.tar.gz rockbox-43ca127ebfe9766c84a0456dbac5cafd5f4cb451.zip |
hwstub: fix library to actually work and compile, still miss some functions
Change-Id: I968dafb4dca7d674165a43e3a435762fe38ed37f
Diffstat (limited to 'utils/hwstub')
-rw-r--r-- | utils/hwstub/hwstub_protocol.h | 6 | ||||
-rw-r--r-- | utils/hwstub/lib/hwstub.c | 53 |
2 files changed, 53 insertions, 6 deletions
diff --git a/utils/hwstub/hwstub_protocol.h b/utils/hwstub/hwstub_protocol.h index 02c065cbe0..759aa51b55 100644 --- a/utils/hwstub/hwstub_protocol.h +++ b/utils/hwstub/hwstub_protocol.h | |||
@@ -47,8 +47,8 @@ | |||
47 | */ | 47 | */ |
48 | 48 | ||
49 | #define HWSTUB_CLASS 0xff | 49 | #define HWSTUB_CLASS 0xff |
50 | #define HWSTUB_SUBCLASS 0x57 | 50 | #define HWSTUB_SUBCLASS 0xde |
51 | #define HWSTUB_PROTOCOL 0x0b | 51 | #define HWSTUB_PROTOCOL 0xad |
52 | 52 | ||
53 | /** | 53 | /** |
54 | * Descriptors can be retrieved using configuration descriptor or individually | 54 | * Descriptors can be retrieved using configuration descriptor or individually |
@@ -184,6 +184,6 @@ struct hwstub_exec_req_t | |||
184 | { | 184 | { |
185 | uint32_t dAddress; | 185 | uint32_t dAddress; |
186 | uint16_t bmFlags; | 186 | uint16_t bmFlags; |
187 | }; | 187 | } __attribute__((packed)); |
188 | 188 | ||
189 | #endif /* __HWSTUB_PROTOCOL__ */ | 189 | #endif /* __HWSTUB_PROTOCOL__ */ |
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) | |||
101 | struct hwstub_layout_desc_t layout; | 101 | struct hwstub_layout_desc_t layout; |
102 | int sz = hwstub_get_desc(dev, HWSTUB_DT_LAYOUT, &layout, sizeof(layout)); | 102 | int sz = hwstub_get_desc(dev, HWSTUB_DT_LAYOUT, &layout, sizeof(layout)); |
103 | if(sz == (int)sizeof(layout)) | 103 | if(sz == (int)sizeof(layout)) |
104 | dev->buf_sz = layout->dBufferSize; | 104 | dev->buf_sz = layout.dBufferSize; |
105 | return dev; | 105 | return dev; |
106 | 106 | ||
107 | Lerr: | 107 | Lerr: |
@@ -135,16 +135,59 @@ static int _hwstub_read(struct hwstub_device_t *dev, uint32_t addr, void *buf, s | |||
135 | read.dAddress = addr; | 135 | read.dAddress = addr; |
136 | int size = libusb_control_transfer(dev->handle, | 136 | int size = libusb_control_transfer(dev->handle, |
137 | LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_INTERFACE | LIBUSB_ENDPOINT_OUT, | 137 | LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_INTERFACE | LIBUSB_ENDPOINT_OUT, |
138 | HWSTUB_READ, dev->id, dev->intf, &read, sizeof(read), 1000); | 138 | HWSTUB_READ, dev->id, dev->intf, (void *)&read, sizeof(read), 1000); |
139 | if(size != (int)sizeof(read)) | 139 | if(size != (int)sizeof(read)) |
140 | return -1; | 140 | return -1; |
141 | return libusb_control_transfer(dev->handle, | 141 | return libusb_control_transfer(dev->handle, |
142 | LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_INTERFACE | LIBUSB_ENDPOINT_IN, | 142 | LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_INTERFACE | LIBUSB_ENDPOINT_IN, |
143 | HWSTUB_READ2, dev->id++, dev->intf, &read, sizeof(read), 1000); | 143 | HWSTUB_READ2, dev->id++, dev->intf, buf, sz, 1000); |
144 | } | 144 | } |
145 | 145 | ||
146 | static int _hwstub_write(struct hwstub_device_t *dev, uint32_t addr, void *buf, size_t sz) | ||
147 | { | ||
148 | size_t hdr_sz = sizeof(struct hwstub_write_req_t); | ||
149 | struct hwstub_write_req_t *req = malloc(sz + hdr_sz); | ||
150 | req->dAddress = addr; | ||
151 | memcpy(req + 1, buf, sz); | ||
152 | int size = libusb_control_transfer(dev->handle, | ||
153 | LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_INTERFACE | LIBUSB_ENDPOINT_OUT, | ||
154 | HWSTUB_WRITE, dev->id++, dev->intf, (void *)req, sz + hdr_sz, 1000); | ||
155 | free(req); | ||
156 | return size - hdr_sz; | ||
157 | } | ||
158 | |||
159 | /* Intermediate function which make sure we don't overflow the device buffer */ | ||
160 | int hwstub_read(struct hwstub_device_t *dev, uint32_t addr, void *buf, size_t sz) | ||
161 | { | ||
162 | int cnt = 0; | ||
163 | while(sz > 0) | ||
164 | { | ||
165 | int xfer = _hwstub_read(dev, addr, buf, MIN(sz, dev->buf_sz)); | ||
166 | if(xfer < 0) | ||
167 | return xfer; | ||
168 | sz -= xfer; | ||
169 | buf += xfer; | ||
170 | addr += xfer; | ||
171 | cnt += xfer; | ||
172 | } | ||
173 | return cnt; | ||
174 | } | ||
175 | |||
176 | /* Intermediate function which make sure we don't overflow the device buffer */ | ||
146 | int hwstub_write(struct hwstub_device_t *dev, uint32_t addr, void *buf, size_t sz) | 177 | int hwstub_write(struct hwstub_device_t *dev, uint32_t addr, void *buf, size_t sz) |
147 | { | 178 | { |
179 | int cnt = 0; | ||
180 | while(sz > 0) | ||
181 | { | ||
182 | int xfer = _hwstub_write(dev, addr, buf, MIN(sz, dev->buf_sz - sizeof(struct hwstub_write_req_t))); | ||
183 | if(xfer < 0) | ||
184 | return xfer; | ||
185 | sz -= xfer; | ||
186 | buf += xfer; | ||
187 | addr += xfer; | ||
188 | cnt += xfer; | ||
189 | } | ||
190 | return cnt; | ||
148 | } | 191 | } |
149 | 192 | ||
150 | int hwstub_rw_mem(struct hwstub_device_t *dev, int read, uint32_t addr, void *buf, size_t sz) | 193 | 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) | |||
160 | LIBUSB_ENDPOINT_OUT, HWSTUB_CALL, addr & 0xffff, addr >> 16, NULL, 0, | 203 | LIBUSB_ENDPOINT_OUT, HWSTUB_CALL, addr & 0xffff, addr >> 16, NULL, 0, |
161 | 1000); | 204 | 1000); |
162 | #else | 205 | #else |
206 | (void) dev; | ||
207 | (void) addr; | ||
163 | return -1; | 208 | return -1; |
164 | #endif | 209 | #endif |
165 | } | 210 | } |
@@ -172,6 +217,8 @@ int hwstub_jump(struct hwstub_device_t *dev, uint32_t addr) | |||
172 | LIBUSB_ENDPOINT_OUT, HWSTUB_JUMP, addr & 0xffff, addr >> 16, NULL, 0, | 217 | LIBUSB_ENDPOINT_OUT, HWSTUB_JUMP, addr & 0xffff, addr >> 16, NULL, 0, |
173 | 1000); | 218 | 1000); |
174 | #else | 219 | #else |
220 | (void) dev; | ||
221 | (void) addr; | ||
175 | return -1; | 222 | return -1; |
176 | #endif | 223 | #endif |
177 | } | 224 | } |