diff options
author | Amaury Pouly <amaury.pouly@gmail.com> | 2014-02-04 00:10:41 +0100 |
---|---|---|
committer | Amaury Pouly <amaury.pouly@gmail.com> | 2014-02-10 23:14:24 +0100 |
commit | c17d30f20466861a244c603665c580feb7758abf (patch) | |
tree | c5044f599f89d89de0b1419bd40e92211f8c8b8a /utils/hwstub/tools/hwstub_load.cpp | |
parent | 6d64111b3c2f772cfc3539bb13851f78d4b55870 (diff) | |
download | rockbox-c17d30f20466861a244c603665c580feb7758abf.tar.gz rockbox-c17d30f20466861a244c603665c580feb7758abf.zip |
utils/hwstub: completely rework the protocol, drop unused features
The protocol has evolved a lot during the 2.x.y lifetime, bringing more
features which later got unused. This commit removes all the unused stuff
and simplifies everything:
- drop the feature mask: everything is mandatory or stalled on error
- remove the info request and put all static information in standard USB
descriptors which are part of the configuration descriptor (and can be
retrieved using the standard GetDescriptor request).
- remove the USB interface, we had only one anyway
- remove all endpoint descriptors
- remove the exit/atexit stuff, it never worked as intended anyway
- update the hwstub library and make it able to handle any device
- update the tools (mostly renaming and removing of code)
Change-Id: I1872bba7f4177fc3891180e8f944aab88f5bde31
Diffstat (limited to 'utils/hwstub/tools/hwstub_load.cpp')
-rw-r--r-- | utils/hwstub/tools/hwstub_load.cpp | 61 |
1 files changed, 20 insertions, 41 deletions
diff --git a/utils/hwstub/tools/hwstub_load.cpp b/utils/hwstub/tools/hwstub_load.cpp index 58c8ac726f..8782c158d7 100644 --- a/utils/hwstub/tools/hwstub_load.cpp +++ b/utils/hwstub/tools/hwstub_load.cpp | |||
@@ -121,7 +121,7 @@ void usage(void) | |||
121 | int main(int argc, char **argv) | 121 | int main(int argc, char **argv) |
122 | { | 122 | { |
123 | bool quiet = false; | 123 | bool quiet = false; |
124 | struct hwstub_device_t hwdev; | 124 | struct hwstub_device_t *hwdev; |
125 | enum image_type_t type = IT_DETECT; | 125 | enum image_type_t type = IT_DETECT; |
126 | 126 | ||
127 | // parse command line | 127 | // parse command line |
@@ -244,73 +244,52 @@ int main(int argc, char **argv) | |||
244 | libusb_get_bus_number(mydev), | 244 | libusb_get_bus_number(mydev), |
245 | libusb_get_device_address(mydev)); | 245 | libusb_get_device_address(mydev)); |
246 | } | 246 | } |
247 | hwdev.handle = handle; | 247 | hwdev = hwstub_open(handle); |
248 | if(hwstub_probe(&hwdev)) | 248 | if(hwdev == NULL) |
249 | { | 249 | { |
250 | fprintf(stderr, "Cannot probe device!\n"); | 250 | fprintf(stderr, "Cannot probe device!\n"); |
251 | return 1; | 251 | return 1; |
252 | } | 252 | } |
253 | 253 | ||
254 | // get hwstub information | 254 | // get hwstub information |
255 | struct usb_resp_info_version_t hwdev_ver; | 255 | struct hwstub_version_desc_t hwdev_ver; |
256 | int ret = hwstub_get_info(&hwdev, HWSTUB_INFO_VERSION, &hwdev_ver, sizeof(hwdev_ver)); | 256 | int ret = hwstub_get_desc(hwdev, HWSTUB_DT_VERSION, &hwdev_ver, sizeof(hwdev_ver)); |
257 | if(ret != sizeof(hwdev_ver)) | 257 | if(ret != sizeof(hwdev_ver)) |
258 | { | 258 | { |
259 | fprintf(stderr, "Cannot get version!\n"); | 259 | fprintf(stderr, "Cannot get version!\n"); |
260 | goto Lerr; | 260 | goto Lerr; |
261 | } | 261 | } |
262 | if(hwdev_ver.major != HWSTUB_VERSION_MAJOR || hwdev_ver.minor < HWSTUB_VERSION_MINOR) | 262 | if(hwdev_ver.bMajor != HWSTUB_VERSION_MAJOR || hwdev_ver.bMinor < HWSTUB_VERSION_MINOR) |
263 | { | 263 | { |
264 | printf("Warning: this tool is possibly incompatible with your device:\n"); | 264 | printf("Warning: this tool is possibly incompatible with your device:\n"); |
265 | printf("Device version: %d.%d.%d\n", hwdev_ver.major, hwdev_ver.minor, hwdev_ver.revision); | 265 | printf("Device version: %d.%d.%d\n", hwdev_ver.bMajor, hwdev_ver.bMinor, hwdev_ver.bRevision); |
266 | printf("Host version: %d.%d.%d\n", HWSTUB_VERSION_MAJOR, HWSTUB_VERSION_MINOR, HWSTUB_VERSION_REV); | 266 | printf("Host version: %d.%d.%d\n", HWSTUB_VERSION_MAJOR, HWSTUB_VERSION_MINOR, HWSTUB_VERSION_REV); |
267 | } | 267 | } |
268 | 268 | ||
269 | // get features | 269 | ret = hwstub_rw_mem(hwdev, 0, addr, buffer, size); |
270 | struct usb_resp_info_features_t hwdev_features; | ||
271 | ret = hwstub_get_info(&hwdev, HWSTUB_INFO_FEATURES, &hwdev_features, sizeof(hwdev_features)); | ||
272 | if(ret != sizeof(hwdev_features)) | ||
273 | { | ||
274 | fprintf(stderr, "Cannot get features: %d\n", ret); | ||
275 | goto Lerr; | ||
276 | } | ||
277 | if(!(hwdev_features.feature_mask & HWSTUB_RW_MEM)) | ||
278 | { | ||
279 | fprintf(stderr, "Device doesn't support R/W commands\n"); | ||
280 | goto Lerr; | ||
281 | } | ||
282 | if(!(hwdev_features.feature_mask & HWSTUB_JUMP)) | ||
283 | { | ||
284 | fprintf(stderr, "Device doesn't support jump commands\n"); | ||
285 | goto Lerr; | ||
286 | } | ||
287 | ret = hwstub_rw_mem(&hwdev, 0, addr, buffer, size); | ||
288 | if(ret != (int)size) | 270 | if(ret != (int)size) |
289 | { | 271 | { |
290 | fprintf(stderr, "Image write failed\n"); | 272 | fprintf(stderr, "Image write failed\n"); |
291 | goto Lerr; | 273 | goto Lerr; |
292 | } | 274 | } |
293 | hwstub_jump(&hwdev, addr); | 275 | hwstub_jump(hwdev, addr); |
294 | 276 | ||
295 | hwstub_release(&hwdev); | 277 | hwstub_release(hwdev); |
296 | return 0; | 278 | return 0; |
297 | 279 | ||
298 | Lerr: | 280 | Lerr: |
299 | // display log if handled | 281 | // display log if handled |
300 | if(hwdev_features.feature_mask & HWSTUB_FEATURE_LOG) | 282 | fprintf(stderr, "Device log:\n"); |
283 | do | ||
301 | { | 284 | { |
302 | fprintf(stderr, "Device log:\n"); | 285 | char buffer[128]; |
303 | do | 286 | int length = hwstub_get_log(hwdev, buffer, sizeof(buffer) - 1); |
304 | { | 287 | if(length <= 0) |
305 | char buffer[128]; | 288 | break; |
306 | int length = hwstub_get_log(&hwdev, buffer, sizeof(buffer) - 1); | 289 | buffer[length] = 0; |
307 | if(length <= 0) | 290 | fprintf(stderr, "%s", buffer); |
308 | break; | 291 | }while(1); |
309 | buffer[length] = 0; | 292 | hwstub_release(hwdev); |
310 | fprintf(stderr, "%s", buffer); | ||
311 | }while(1); | ||
312 | } | ||
313 | hwstub_release(&hwdev); | ||
314 | return 1; | 293 | return 1; |
315 | } | 294 | } |
316 | 295 | ||