forked from len0rd/rockbox
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
This commit is contained in:
parent
5b52ff2c93
commit
8e82839fe2
4 changed files with 44 additions and 6 deletions
|
|
@ -444,7 +444,10 @@ error handle::write(uint32_t addr, const void *buf, size_t& sz, bool atomic)
|
|||
size_t xfer = std::min(sz, get_buffer_size());
|
||||
err = write_dev(addr, buf, xfer, atomic);
|
||||
if(err != error::SUCCESS)
|
||||
{
|
||||
sz = cnt;
|
||||
return err;
|
||||
}
|
||||
sz -= xfer;
|
||||
bufp += xfer;
|
||||
addr += xfer;
|
||||
|
|
|
|||
|
|
@ -153,7 +153,10 @@ error device::open_dev(std::shared_ptr<hwstub::handle>& handle)
|
|||
libusb_device_handle *h;
|
||||
int err = libusb_open(m_dev, &h);
|
||||
if(err != LIBUSB_SUCCESS)
|
||||
{
|
||||
get_context()->debug() << "Cannot open device: " << err << "\n";
|
||||
return error::ERROR;
|
||||
}
|
||||
/* fetch some descriptors */
|
||||
struct libusb_device_descriptor dev_desc;
|
||||
struct libusb_config_descriptor *config = nullptr;
|
||||
|
|
@ -234,7 +237,7 @@ uint16_t device::get_pid()
|
|||
handle::handle(std::shared_ptr<hwstub::device> dev, libusb_device_handle *handle)
|
||||
:hwstub::handle(dev), m_handle(handle)
|
||||
{
|
||||
set_timeout(std::chrono::milliseconds(100));
|
||||
set_timeout(std::chrono::milliseconds(1000));
|
||||
}
|
||||
|
||||
handle::~handle()
|
||||
|
|
@ -284,8 +287,13 @@ rb_handle::rb_handle(std::shared_ptr<hwstub::device> dev,
|
|||
{
|
||||
m_probe_status = error::SUCCESS;
|
||||
/* claim interface */
|
||||
if(libusb_claim_interface(m_handle, m_intf) != 0)
|
||||
int err = libusb_claim_interface(m_handle, m_intf);
|
||||
if(err != 0)
|
||||
{
|
||||
get_device()->get_context()->debug() <<
|
||||
"Cannot claim interface: " << err <<"\n";
|
||||
m_probe_status = error::PROBE_FAILURE;
|
||||
}
|
||||
/* check version */
|
||||
if(m_probe_status == error::SUCCESS)
|
||||
{
|
||||
|
|
@ -295,9 +303,15 @@ rb_handle::rb_handle(std::shared_ptr<hwstub::device> dev,
|
|||
{
|
||||
if(ver_desc.bMajor != HWSTUB_VERSION_MAJOR ||
|
||||
ver_desc.bMinor < HWSTUB_VERSION_MINOR)
|
||||
{
|
||||
get_device()->get_context()->debug() <<
|
||||
"Version mismatch: host is " << HWSTUB_VERSION_MAJOR <<
|
||||
"." << HWSTUB_VERSION_MINOR << ", device is " <<
|
||||
ver_desc.bMajor << "." << ver_desc.bMinor << "\n";
|
||||
m_probe_status = error::PROBE_FAILURE;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* get buffer size */
|
||||
if(m_probe_status == error::SUCCESS)
|
||||
{
|
||||
|
|
@ -305,6 +319,10 @@ rb_handle::rb_handle(std::shared_ptr<hwstub::device> dev,
|
|||
m_probe_status = get_layout_desc(layout_desc);
|
||||
if(m_probe_status == error::SUCCESS)
|
||||
m_buf_size = layout_desc.dBufferSize;
|
||||
/* libusb limits control transfers to 4096 bytes, to which we need to subtract
|
||||
* the size of the possible header. To play safe, limit to 4000 bytes */
|
||||
if(m_buf_size > 4000)
|
||||
m_buf_size = 4000;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@
|
|||
#include <getopt.h>
|
||||
#include <stdbool.h>
|
||||
#include <ctype.h>
|
||||
#include <iostream>
|
||||
#include "hwstub.hpp"
|
||||
#include "hwstub_uri.hpp"
|
||||
|
||||
|
|
@ -111,6 +112,7 @@ void usage(void)
|
|||
printf(" --quiet/-q Quiet output\n");
|
||||
printf(" --type/-t <t> Override file type\n");
|
||||
printf(" --dev/-d <uri> Device URI (see below)\n");
|
||||
printf(" --verbose/-v Display debug output\n");
|
||||
printf("file types:\n");
|
||||
printf(" raw Load a raw binary blob\n");
|
||||
printf(" rockbox Load a rockbox image produced by scramble\n");
|
||||
|
|
@ -128,6 +130,7 @@ int main(int argc, char **argv)
|
|||
bool quiet = false;
|
||||
enum image_type_t type = IT_DETECT;
|
||||
const char *uri = "usb:";
|
||||
bool verbose = false;
|
||||
|
||||
// parse command line
|
||||
while(1)
|
||||
|
|
@ -138,10 +141,11 @@ int main(int argc, char **argv)
|
|||
{"quiet", no_argument, 0, 'q'},
|
||||
{"type", required_argument, 0, 't'},
|
||||
{"dev", required_argument, 0, 'd'},
|
||||
{"verbose", no_argument, 0, 'v'},
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
|
||||
int c = getopt_long(argc, argv, "?qt:d:", long_options, NULL);
|
||||
int c = getopt_long(argc, argv, "?qt:d:v", long_options, NULL);
|
||||
if(c == -1)
|
||||
break;
|
||||
switch(c)
|
||||
|
|
@ -170,6 +174,9 @@ int main(int argc, char **argv)
|
|||
case 'd':
|
||||
uri = optarg;
|
||||
break;
|
||||
case 'v':
|
||||
verbose = true;
|
||||
break;
|
||||
default:
|
||||
abort();
|
||||
}
|
||||
|
|
@ -236,6 +243,8 @@ int main(int argc, char **argv)
|
|||
printf("Cannot create context: %s\n", errstr.c_str());
|
||||
return 1;
|
||||
}
|
||||
if(verbose)
|
||||
hwctx->set_debug(std::cout);
|
||||
std::vector<std::shared_ptr<hwstub::device>> list;
|
||||
hwstub::error ret = hwctx->get_device_list(list);
|
||||
if(ret != hwstub::error::SUCCESS)
|
||||
|
|
@ -277,7 +286,7 @@ int main(int argc, char **argv)
|
|||
char buffer[128];
|
||||
size_t size = sizeof(buffer) - 1;
|
||||
hwstub::error err = hwdev->get_log(buffer, size);
|
||||
if(err != hwstub::error::SUCCESS)
|
||||
if(err != error::SUCCESS || size == 0)
|
||||
break;
|
||||
buffer[size] = 0;
|
||||
fprintf(stderr, "%s", buffer);
|
||||
|
|
|
|||
|
|
@ -1239,6 +1239,7 @@ void usage(void)
|
|||
printf("options:\n");
|
||||
printf(" --help/-? Display this help\n");
|
||||
printf(" --quiet/-q Quiet non-command messages\n");
|
||||
printf(" -b/--batch Disable interactive mode after running commands and files\n");
|
||||
printf(" --verbose/-v Verbose output\n");
|
||||
printf(" -i <init> Set lua init file (default is init.lua)\n");
|
||||
printf(" -e <cmd> Execute <cmd> at startup\n");
|
||||
|
|
@ -1293,6 +1294,7 @@ int main(int argc, char **argv)
|
|||
{
|
||||
std::string dev_uri = hwstub::uri::default_uri().full_uri();
|
||||
bool verbose = false;
|
||||
bool batch = false;
|
||||
|
||||
const char *lua_init = "init.lua";
|
||||
std::vector< std::pair< exec_type, std::string > > startup_cmds;
|
||||
|
|
@ -1309,11 +1311,12 @@ int main(int argc, char **argv)
|
|||
{"startfile", required_argument, 0, 'f'},
|
||||
{"dev", required_argument, 0, 'd'},
|
||||
{"verbose", no_argument, 0, 'v'},
|
||||
{"batch", no_argument, 0, 'b'},
|
||||
{"debug-rw", no_argument, 0, OPT_DBG_RW},
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
|
||||
int c = getopt_long(argc, argv, "?qi:e:f:d:v", long_options, NULL);
|
||||
int c = getopt_long(argc, argv, "?qi:e:f:d:vb", long_options, NULL);
|
||||
if(c == -1)
|
||||
break;
|
||||
switch(c)
|
||||
|
|
@ -1344,6 +1347,9 @@ int main(int argc, char **argv)
|
|||
case OPT_DBG_RW:
|
||||
g_print_mem_rw = true;
|
||||
break;
|
||||
case 'b':
|
||||
batch = true;
|
||||
break;
|
||||
default:
|
||||
abort();
|
||||
}
|
||||
|
|
@ -1441,7 +1447,9 @@ int main(int argc, char **argv)
|
|||
/* intercept CTRL+C */
|
||||
signal(SIGINT, do_signal);
|
||||
// start interactive shell
|
||||
if(!batch)
|
||||
luap_enter(g_lua, &g_exit);
|
||||
// cleanup
|
||||
lua_close(g_lua);
|
||||
|
||||
// display log if handled
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue