diff options
author | Amaury Pouly <amaury.pouly@gmail.com> | 2016-12-12 11:23:20 +0100 |
---|---|---|
committer | Gerrit Rockbox <gerrit@rockbox.org> | 2016-12-12 11:35:16 +0100 |
commit | 8e82839fe29c8f5d5180a0cd9e7561c0d74dfabe (patch) | |
tree | bbddfb2b51acf151d90019a1bdcea16680d1f782 | |
parent | 5b52ff2c93befe5fe86920bb8d9a68e7f0f5cee5 (diff) | |
download | rockbox-8e82839fe29c8f5d5180a0cd9e7561c0d74dfabe.tar.gz rockbox-8e82839fe29c8f5d5180a0cd9e7561c0d74dfabe.zip |
hwstub: various cleanups
- hwstub load now properly stops reading the log when the device returns a 0
size buffer instead of STALLing
- add debug output option to hwstub_load
- correctly report transfered size on write error
- add some debug error message in usb code so that some errors can be diagnosed
more easily
- add a batch mode to hwstub_shell to disable the interactive shell
- increase usb control timeout to 1sec, 100ms was really tight
- cap usb buffer size to ~4000 bytes because libusb has a hardwired limit of
4096 bytes for control transfers
Change-Id: Id3200ab99ce70a7a3b09ce7faeaafa4a0fac64c7
-rw-r--r-- | utils/hwstub/lib/hwstub.cpp | 3 | ||||
-rw-r--r-- | utils/hwstub/lib/hwstub_usb.cpp | 22 | ||||
-rw-r--r-- | utils/hwstub/tools/hwstub_load.cpp | 13 | ||||
-rw-r--r-- | utils/hwstub/tools/hwstub_shell.cpp | 12 |
4 files changed, 44 insertions, 6 deletions
diff --git a/utils/hwstub/lib/hwstub.cpp b/utils/hwstub/lib/hwstub.cpp index 7c81146c77..9dd2915903 100644 --- a/utils/hwstub/lib/hwstub.cpp +++ b/utils/hwstub/lib/hwstub.cpp | |||
@@ -444,7 +444,10 @@ error handle::write(uint32_t addr, const void *buf, size_t& sz, bool atomic) | |||
444 | size_t xfer = std::min(sz, get_buffer_size()); | 444 | size_t xfer = std::min(sz, get_buffer_size()); |
445 | err = write_dev(addr, buf, xfer, atomic); | 445 | err = write_dev(addr, buf, xfer, atomic); |
446 | if(err != error::SUCCESS) | 446 | if(err != error::SUCCESS) |
447 | { | ||
448 | sz = cnt; | ||
447 | return err; | 449 | return err; |
450 | } | ||
448 | sz -= xfer; | 451 | sz -= xfer; |
449 | bufp += xfer; | 452 | bufp += xfer; |
450 | addr += xfer; | 453 | addr += xfer; |
diff --git a/utils/hwstub/lib/hwstub_usb.cpp b/utils/hwstub/lib/hwstub_usb.cpp index 28c64d9df3..6bb1cfa049 100644 --- a/utils/hwstub/lib/hwstub_usb.cpp +++ b/utils/hwstub/lib/hwstub_usb.cpp | |||
@@ -153,7 +153,10 @@ error device::open_dev(std::shared_ptr<hwstub::handle>& handle) | |||
153 | libusb_device_handle *h; | 153 | libusb_device_handle *h; |
154 | int err = libusb_open(m_dev, &h); | 154 | int err = libusb_open(m_dev, &h); |
155 | if(err != LIBUSB_SUCCESS) | 155 | if(err != LIBUSB_SUCCESS) |
156 | { | ||
157 | get_context()->debug() << "Cannot open device: " << err << "\n"; | ||
156 | return error::ERROR; | 158 | return error::ERROR; |
159 | } | ||
157 | /* fetch some descriptors */ | 160 | /* fetch some descriptors */ |
158 | struct libusb_device_descriptor dev_desc; | 161 | struct libusb_device_descriptor dev_desc; |
159 | struct libusb_config_descriptor *config = nullptr; | 162 | struct libusb_config_descriptor *config = nullptr; |
@@ -234,7 +237,7 @@ uint16_t device::get_pid() | |||
234 | handle::handle(std::shared_ptr<hwstub::device> dev, libusb_device_handle *handle) | 237 | handle::handle(std::shared_ptr<hwstub::device> dev, libusb_device_handle *handle) |
235 | :hwstub::handle(dev), m_handle(handle) | 238 | :hwstub::handle(dev), m_handle(handle) |
236 | { | 239 | { |
237 | set_timeout(std::chrono::milliseconds(100)); | 240 | set_timeout(std::chrono::milliseconds(1000)); |
238 | } | 241 | } |
239 | 242 | ||
240 | handle::~handle() | 243 | handle::~handle() |
@@ -284,8 +287,13 @@ rb_handle::rb_handle(std::shared_ptr<hwstub::device> dev, | |||
284 | { | 287 | { |
285 | m_probe_status = error::SUCCESS; | 288 | m_probe_status = error::SUCCESS; |
286 | /* claim interface */ | 289 | /* claim interface */ |
287 | if(libusb_claim_interface(m_handle, m_intf) != 0) | 290 | int err = libusb_claim_interface(m_handle, m_intf); |
291 | if(err != 0) | ||
292 | { | ||
293 | get_device()->get_context()->debug() << | ||
294 | "Cannot claim interface: " << err <<"\n"; | ||
288 | m_probe_status = error::PROBE_FAILURE; | 295 | m_probe_status = error::PROBE_FAILURE; |
296 | } | ||
289 | /* check version */ | 297 | /* check version */ |
290 | if(m_probe_status == error::SUCCESS) | 298 | if(m_probe_status == error::SUCCESS) |
291 | { | 299 | { |
@@ -295,7 +303,13 @@ rb_handle::rb_handle(std::shared_ptr<hwstub::device> dev, | |||
295 | { | 303 | { |
296 | if(ver_desc.bMajor != HWSTUB_VERSION_MAJOR || | 304 | if(ver_desc.bMajor != HWSTUB_VERSION_MAJOR || |
297 | ver_desc.bMinor < HWSTUB_VERSION_MINOR) | 305 | ver_desc.bMinor < HWSTUB_VERSION_MINOR) |
306 | { | ||
307 | get_device()->get_context()->debug() << | ||
308 | "Version mismatch: host is " << HWSTUB_VERSION_MAJOR << | ||
309 | "." << HWSTUB_VERSION_MINOR << ", device is " << | ||
310 | ver_desc.bMajor << "." << ver_desc.bMinor << "\n"; | ||
298 | m_probe_status = error::PROBE_FAILURE; | 311 | m_probe_status = error::PROBE_FAILURE; |
312 | } | ||
299 | } | 313 | } |
300 | } | 314 | } |
301 | /* get buffer size */ | 315 | /* get buffer size */ |
@@ -305,6 +319,10 @@ rb_handle::rb_handle(std::shared_ptr<hwstub::device> dev, | |||
305 | m_probe_status = get_layout_desc(layout_desc); | 319 | m_probe_status = get_layout_desc(layout_desc); |
306 | if(m_probe_status == error::SUCCESS) | 320 | if(m_probe_status == error::SUCCESS) |
307 | m_buf_size = layout_desc.dBufferSize; | 321 | m_buf_size = layout_desc.dBufferSize; |
322 | /* libusb limits control transfers to 4096 bytes, to which we need to subtract | ||
323 | * the size of the possible header. To play safe, limit to 4000 bytes */ | ||
324 | if(m_buf_size > 4000) | ||
325 | m_buf_size = 4000; | ||
308 | } | 326 | } |
309 | } | 327 | } |
310 | 328 | ||
diff --git a/utils/hwstub/tools/hwstub_load.cpp b/utils/hwstub/tools/hwstub_load.cpp index 87737939c3..6ca6079294 100644 --- a/utils/hwstub/tools/hwstub_load.cpp +++ b/utils/hwstub/tools/hwstub_load.cpp | |||
@@ -24,6 +24,7 @@ | |||
24 | #include <getopt.h> | 24 | #include <getopt.h> |
25 | #include <stdbool.h> | 25 | #include <stdbool.h> |
26 | #include <ctype.h> | 26 | #include <ctype.h> |
27 | #include <iostream> | ||
27 | #include "hwstub.hpp" | 28 | #include "hwstub.hpp" |
28 | #include "hwstub_uri.hpp" | 29 | #include "hwstub_uri.hpp" |
29 | 30 | ||
@@ -111,6 +112,7 @@ void usage(void) | |||
111 | printf(" --quiet/-q Quiet output\n"); | 112 | printf(" --quiet/-q Quiet output\n"); |
112 | printf(" --type/-t <t> Override file type\n"); | 113 | printf(" --type/-t <t> Override file type\n"); |
113 | printf(" --dev/-d <uri> Device URI (see below)\n"); | 114 | printf(" --dev/-d <uri> Device URI (see below)\n"); |
115 | printf(" --verbose/-v Display debug output\n"); | ||
114 | printf("file types:\n"); | 116 | printf("file types:\n"); |
115 | printf(" raw Load a raw binary blob\n"); | 117 | printf(" raw Load a raw binary blob\n"); |
116 | printf(" rockbox Load a rockbox image produced by scramble\n"); | 118 | printf(" rockbox Load a rockbox image produced by scramble\n"); |
@@ -128,6 +130,7 @@ int main(int argc, char **argv) | |||
128 | bool quiet = false; | 130 | bool quiet = false; |
129 | enum image_type_t type = IT_DETECT; | 131 | enum image_type_t type = IT_DETECT; |
130 | const char *uri = "usb:"; | 132 | const char *uri = "usb:"; |
133 | bool verbose = false; | ||
131 | 134 | ||
132 | // parse command line | 135 | // parse command line |
133 | while(1) | 136 | while(1) |
@@ -138,10 +141,11 @@ int main(int argc, char **argv) | |||
138 | {"quiet", no_argument, 0, 'q'}, | 141 | {"quiet", no_argument, 0, 'q'}, |
139 | {"type", required_argument, 0, 't'}, | 142 | {"type", required_argument, 0, 't'}, |
140 | {"dev", required_argument, 0, 'd'}, | 143 | {"dev", required_argument, 0, 'd'}, |
144 | {"verbose", no_argument, 0, 'v'}, | ||
141 | {0, 0, 0, 0} | 145 | {0, 0, 0, 0} |
142 | }; | 146 | }; |
143 | 147 | ||
144 | int c = getopt_long(argc, argv, "?qt:d:", long_options, NULL); | 148 | int c = getopt_long(argc, argv, "?qt:d:v", long_options, NULL); |
145 | if(c == -1) | 149 | if(c == -1) |
146 | break; | 150 | break; |
147 | switch(c) | 151 | switch(c) |
@@ -170,6 +174,9 @@ int main(int argc, char **argv) | |||
170 | case 'd': | 174 | case 'd': |
171 | uri = optarg; | 175 | uri = optarg; |
172 | break; | 176 | break; |
177 | case 'v': | ||
178 | verbose = true; | ||
179 | break; | ||
173 | default: | 180 | default: |
174 | abort(); | 181 | abort(); |
175 | } | 182 | } |
@@ -236,6 +243,8 @@ int main(int argc, char **argv) | |||
236 | printf("Cannot create context: %s\n", errstr.c_str()); | 243 | printf("Cannot create context: %s\n", errstr.c_str()); |
237 | return 1; | 244 | return 1; |
238 | } | 245 | } |
246 | if(verbose) | ||
247 | hwctx->set_debug(std::cout); | ||
239 | std::vector<std::shared_ptr<hwstub::device>> list; | 248 | std::vector<std::shared_ptr<hwstub::device>> list; |
240 | hwstub::error ret = hwctx->get_device_list(list); | 249 | hwstub::error ret = hwctx->get_device_list(list); |
241 | if(ret != hwstub::error::SUCCESS) | 250 | if(ret != hwstub::error::SUCCESS) |
@@ -277,7 +286,7 @@ int main(int argc, char **argv) | |||
277 | char buffer[128]; | 286 | char buffer[128]; |
278 | size_t size = sizeof(buffer) - 1; | 287 | size_t size = sizeof(buffer) - 1; |
279 | hwstub::error err = hwdev->get_log(buffer, size); | 288 | hwstub::error err = hwdev->get_log(buffer, size); |
280 | if(err != hwstub::error::SUCCESS) | 289 | if(err != error::SUCCESS || size == 0) |
281 | break; | 290 | break; |
282 | buffer[size] = 0; | 291 | buffer[size] = 0; |
283 | fprintf(stderr, "%s", buffer); | 292 | fprintf(stderr, "%s", buffer); |
diff --git a/utils/hwstub/tools/hwstub_shell.cpp b/utils/hwstub/tools/hwstub_shell.cpp index 5fb3e13840..b2cf2cec60 100644 --- a/utils/hwstub/tools/hwstub_shell.cpp +++ b/utils/hwstub/tools/hwstub_shell.cpp | |||
@@ -1239,6 +1239,7 @@ void usage(void) | |||
1239 | printf("options:\n"); | 1239 | printf("options:\n"); |
1240 | printf(" --help/-? Display this help\n"); | 1240 | printf(" --help/-? Display this help\n"); |
1241 | printf(" --quiet/-q Quiet non-command messages\n"); | 1241 | printf(" --quiet/-q Quiet non-command messages\n"); |
1242 | printf(" -b/--batch Disable interactive mode after running commands and files\n"); | ||
1242 | printf(" --verbose/-v Verbose output\n"); | 1243 | printf(" --verbose/-v Verbose output\n"); |
1243 | printf(" -i <init> Set lua init file (default is init.lua)\n"); | 1244 | printf(" -i <init> Set lua init file (default is init.lua)\n"); |
1244 | printf(" -e <cmd> Execute <cmd> at startup\n"); | 1245 | printf(" -e <cmd> Execute <cmd> at startup\n"); |
@@ -1293,6 +1294,7 @@ int main(int argc, char **argv) | |||
1293 | { | 1294 | { |
1294 | std::string dev_uri = hwstub::uri::default_uri().full_uri(); | 1295 | std::string dev_uri = hwstub::uri::default_uri().full_uri(); |
1295 | bool verbose = false; | 1296 | bool verbose = false; |
1297 | bool batch = false; | ||
1296 | 1298 | ||
1297 | const char *lua_init = "init.lua"; | 1299 | const char *lua_init = "init.lua"; |
1298 | std::vector< std::pair< exec_type, std::string > > startup_cmds; | 1300 | std::vector< std::pair< exec_type, std::string > > startup_cmds; |
@@ -1309,11 +1311,12 @@ int main(int argc, char **argv) | |||
1309 | {"startfile", required_argument, 0, 'f'}, | 1311 | {"startfile", required_argument, 0, 'f'}, |
1310 | {"dev", required_argument, 0, 'd'}, | 1312 | {"dev", required_argument, 0, 'd'}, |
1311 | {"verbose", no_argument, 0, 'v'}, | 1313 | {"verbose", no_argument, 0, 'v'}, |
1314 | {"batch", no_argument, 0, 'b'}, | ||
1312 | {"debug-rw", no_argument, 0, OPT_DBG_RW}, | 1315 | {"debug-rw", no_argument, 0, OPT_DBG_RW}, |
1313 | {0, 0, 0, 0} | 1316 | {0, 0, 0, 0} |
1314 | }; | 1317 | }; |
1315 | 1318 | ||
1316 | int c = getopt_long(argc, argv, "?qi:e:f:d:v", long_options, NULL); | 1319 | int c = getopt_long(argc, argv, "?qi:e:f:d:vb", long_options, NULL); |
1317 | if(c == -1) | 1320 | if(c == -1) |
1318 | break; | 1321 | break; |
1319 | switch(c) | 1322 | switch(c) |
@@ -1344,6 +1347,9 @@ int main(int argc, char **argv) | |||
1344 | case OPT_DBG_RW: | 1347 | case OPT_DBG_RW: |
1345 | g_print_mem_rw = true; | 1348 | g_print_mem_rw = true; |
1346 | break; | 1349 | break; |
1350 | case 'b': | ||
1351 | batch = true; | ||
1352 | break; | ||
1347 | default: | 1353 | default: |
1348 | abort(); | 1354 | abort(); |
1349 | } | 1355 | } |
@@ -1441,7 +1447,9 @@ int main(int argc, char **argv) | |||
1441 | /* intercept CTRL+C */ | 1447 | /* intercept CTRL+C */ |
1442 | signal(SIGINT, do_signal); | 1448 | signal(SIGINT, do_signal); |
1443 | // start interactive shell | 1449 | // start interactive shell |
1444 | luap_enter(g_lua, &g_exit); | 1450 | if(!batch) |
1451 | luap_enter(g_lua, &g_exit); | ||
1452 | // cleanup | ||
1445 | lua_close(g_lua); | 1453 | lua_close(g_lua); |
1446 | 1454 | ||
1447 | // display log if handled | 1455 | // display log if handled |