summaryrefslogtreecommitdiffstats
path: root/utils/hwstub/lib
diff options
context:
space:
mode:
authorAmaury Pouly <amaury.pouly@gmail.com>2016-12-12 11:23:20 +0100
committerGerrit Rockbox <gerrit@rockbox.org>2016-12-12 11:35:16 +0100
commit8e82839fe29c8f5d5180a0cd9e7561c0d74dfabe (patch)
treebbddfb2b51acf151d90019a1bdcea16680d1f782 /utils/hwstub/lib
parent5b52ff2c93befe5fe86920bb8d9a68e7f0f5cee5 (diff)
downloadrockbox-8e82839fe29c8f5d5180a0cd9e7561c0d74dfabe.tar.gz
rockbox-8e82839fe29c8f5d5180a0cd9e7561c0d74dfabe.tar.bz2
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
Diffstat (limited to 'utils/hwstub/lib')
-rw-r--r--utils/hwstub/lib/hwstub.cpp3
-rw-r--r--utils/hwstub/lib/hwstub_usb.cpp22
2 files changed, 23 insertions, 2 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)
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;
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)
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,7 +303,13 @@ 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 */
@@ -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;
}
}