Lekensteyn / lglaf

LG Download Mode utility and documentation
https://lekensteyn.nl/lglaf/
MIT License
137 stars 74 forks source link

USB #2

Closed underscore-bama closed 8 years ago

underscore-bama commented 8 years ago

I've installed the rules and I still can't manage to get a USB signal in Download/Firmware mode. Just, "RuntimeError: USB device not found." Any ideas?

Lekensteyn commented 8 years ago

Can you post the full output as well as the output of lsusb (does it contain your LG device)?

underscore-bama commented 8 years ago

Output.

~/lglaf $ ./lglaf.py
Traceback (most recent call last):
  File "./lglaf.py", line 388, in <module>
    main()
  File "./lglaf.py", line 366, in main
    comm = autodetect_device()
  File "./lglaf.py", line 302, in autodetect_device
    return USBCommunication()
  File "./lglaf.py", line 208, in __init__
    raise RuntimeError("USB device not found")
RuntimeError: USB device not found

Yup.

~ $ lsusb 
Bus 004 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 004 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 003 Device 006: ID 03eb:880a Atmel Corp. 
Bus 003 Device 004: ID 0bda:5705 Realtek Semiconductor Corp. 
Bus 003 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 009: ID 1004:633a LG Electronics, Inc. 
Bus 001 Device 007: ID 046d:c016 Logitech, Inc. Optical Wheel Mouse
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

I also updated 42-usb-lglaf.rules with the 633a device id and get nothing.

Lekensteyn commented 8 years ago

Please add the output of lsusb -vd 1004:633a, I guess that the detection of the endpoint number is wrong. Can try the ep-matching branch?

underscore-bama commented 8 years ago
~ $ lsusb -vd 1004:633a
Bus 001 Device 002: ID 1004:633a LG Electronics, Inc. 
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               2.00
  bDeviceClass          239 Miscellaneous Device
  bDeviceSubClass         2 ?
  bDeviceProtocol         1 Interface Association
  bMaxPacketSize0        64
  idVendor           0x1004 LG Electronics, Inc.
  idProduct          0x633a 
  bcdDevice            2.28
  iManufacturer           1 LG Electronics Inc.
  iProduct                2 LGE Android Phone
  iSerial                 3 LGLS77057559cce
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength           98
    bNumInterfaces          3
    bConfigurationValue     1
    iConfiguration          0 
    bmAttributes         0x80
      (Bus Powered)
    MaxPower              500mA
    Interface Association:
      bLength                 8
      bDescriptorType        11
      bFirstInterface         0
      bInterfaceCount         2
      bFunctionClass          2 Communications
      bFunctionSubClass       2 Abstract (modem)
      bFunctionProtocol       1 AT-commands (v.25ter)
      iFunction               7 CDC Serial
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           1
      bInterfaceClass         2 Communications
      bInterfaceSubClass      2 Abstract (modem)
      bInterfaceProtocol      1 AT-commands (v.25ter)
      iInterface              5 CDC Abstract Control Model (ACM)
      CDC Header:
        bcdCDC               1.10
      CDC Call Management:
        bmCapabilities       0x00
        bDataInterface          1
      CDC ACM:
        bmCapabilities       0x02
          line coding and serial state
      CDC Union:
        bMasterInterface        0
        bSlaveInterface         1 
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x82  EP 2 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               9
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       0
      bNumEndpoints           2
      bInterfaceClass        10 CDC Data
      bInterfaceSubClass      0 Unused
      bInterfaceProtocol      0 
      iInterface              6 CDC ACM Data
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0200  1x 512 bytes
        bInterval               0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x01  EP 1 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0200  1x 512 bytes
        bInterval               0
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        2
      bAlternateSetting       0
      bNumEndpoints           2
      bInterfaceClass       255 Vendor Specific Class
      bInterfaceSubClass    255 Vendor Specific Subclass
      bInterfaceProtocol    255 Vendor Specific Protocol
      iInterface              0 
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x83  EP 3 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0200  1x 512 bytes
        bInterval               0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x02  EP 2 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0200  1x 512 bytes
        bInterval               0
Device Qualifier (for other device speed):
  bLength                10
  bDescriptorType         6
  bcdUSB               2.00
  bDeviceClass          239 Miscellaneous Device
  bDeviceSubClass         2 ?
  bDeviceProtocol         1 Interface Association
  bMaxPacketSize0        64
  bNumConfigurations      1
Device Status:     0x0000
  (Bus Powered)

ep-matching branch throws the same error.

~/lglaf-ep-matching $ ./lglaf.py
Traceback (most recent call last):
  File "./lglaf.py", line 388, in <module>
    main()
  File "./lglaf.py", line 366, in main
    comm = autodetect_device()
  File "./lglaf.py", line 302, in autodetect_device
    return USBCommunication()
  File "./lglaf.py", line 208, in __init__
    raise RuntimeError("USB device not found")
RuntimeError: USB device not found
Lekensteyn commented 8 years ago

Your lsusb output indeed shows that the hard-coded endpoint numbers were incorrect. The ep-matching branch should work now, I had a stupid typo:

diff --git a/lglaf.py b/lglaf.py
index 8ca6cac..6d04ff1 100755
--- a/lglaf.py
+++ b/lglaf.py
@@ -230,7 +230,7 @@ class USBCommunication(Communication):
     def _match_interface(self, intf):
         # Matches an interface having two endpoints (type bulk)
         # and initializes the endpoint numbers on success.
-        if intf.bNumEndpoints == 2:
+        if intf.bNumEndpoints != 2:
             return False
         self.ep_in = self.ep_out = None
         for ep in intf:
underscore-bama commented 8 years ago

Sorry. Still throws the error. I've checked everything to make sure it's up to date and everything is. Strange.

Lekensteyn commented 8 years ago

That was obviously not tested nor reviewed by myself... Have another try with the updated branch that applies the following patch:

diff --git a/lglaf.py b/lglaf.py
index 6d04ff1..886d929 100755
--- a/lglaf.py
+++ b/lglaf.py
@@ -235,7 +235,7 @@ class USBCommunication(Communication):
         self.ep_in = self.ep_out = None
         for ep in intf:
             ep_type = usb.util.endpoint_type(ep.bmAttributes)
-            if ep_type == usb.util.ENDPOINT_TYPE_BULK:
+            if ep_type != usb.util.ENDPOINT_TYPE_BULK:
                     return False
             self._set_endpoint(ep)
         return self.ep_in and self.ep_out
underscore-bama commented 8 years ago

I did try with the updated branch.

~/lglaf-ep-matching $ ./lglaf.py
Traceback (most recent call last):
  File "./lglaf.py", line 397, in <module>
    main()
  File "./lglaf.py", line 375, in main
    comm = autodetect_device()
  File "./lglaf.py", line 311, in autodetect_device
    return USBCommunication()
  File "./lglaf.py", line 206, in __init__
    raise RuntimeError("USB device not found")
RuntimeError: USB device not found
Lekensteyn commented 8 years ago

I've pushed another small fix. If I follow your lsusb dump, it should really work...

If it does not, can you apply this patch and run with ./lglaf.py --debug?

diff --git a/lglaf.py b/lglaf.py
index c93a2c2..c3fdfe7 100755
--- a/lglaf.py
+++ b/lglaf.py
@@ -228,6 +228,7 @@ class USBCommunication(Communication):
         else:
             self.ep_out = ep.bEndpointAddress
     def _match_interface(self, intf):
+        _logger.debug("Probing interface:\n%s", intf)
         # Matches an interface having two endpoints (type bulk)
         # and initializes the endpoint numbers on success.
         if intf.bNumEndpoints != 2:
underscore-bama commented 8 years ago

./lglaf.py :

~/lglaf-ep-matching $ ./lglaf.py
Traceback (most recent call last):
  File "./lglaf.py", line 397, in <module>
    main()
  File "./lglaf.py", line 379, in main
    try_hello(comm)
  File "./lglaf.py", line 271, in try_hello
    comm.write(hello_request)
  File "./lglaf.py", line 257, in write
    self.usbdev.write(self.ep_out, data)
  File "/usr/local/lib/python2.7/dist-packages/usb/core.py", line 940, in write
    intf, ep = self._ctx.setup_request(self, endpoint)
  File "/usr/local/lib/python2.7/dist-packages/usb/core.py", line 102, in wrapper
    return f(self, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/usb/core.py", line 216, in setup_request
    self.managed_claim_interface(device, intf)
  File "/usr/local/lib/python2.7/dist-packages/usb/core.py", line 102, in wrapper
    return f(self, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/usb/core.py", line 167, in managed_claim_interface
    self.backend.claim_interface(self.handle, i)
  File "/usr/local/lib/python2.7/dist-packages/usb/backend/libusb1.py", line 811, in claim_interface
    _check(self.lib.libusb_claim_interface(dev_handle.handle, intf))
  File "/usr/local/lib/python2.7/dist-packages/usb/backend/libusb1.py", line 595, in _check
    raise USBError(_strerror(ret), ret, _libusb_errno[ret])
usb.core.USBError: [Errno 16] Resource busy

After patch ./lglaf.py --debug :

~/lglaf-ep-matching $ ./lglaf.py --debug
LGLAF.py: DEBUG: Probing interface:
    INTERFACE 2: Vendor Specific ===========================
     bLength            :    0x9 (9 bytes)
     bDescriptorType    :    0x4 Interface
     bInterfaceNumber   :    0x2
     bAlternateSetting  :    0x0
     bNumEndpoints      :    0x2
     bInterfaceClass    :   0xff Vendor Specific
     bInterfaceSubClass :   0xff
     bInterfaceProtocol :   0xff
     iInterface         :    0x0 
      ENDPOINT 0x83: Bulk IN ===============================
       bLength          :    0x7 (7 bytes)
       bDescriptorType  :    0x5 Endpoint
       bEndpointAddress :   0x83 IN
       bmAttributes     :    0x2 Bulk
       wMaxPacketSize   :  0x200 (512 bytes)
       bInterval        :    0x0
      ENDPOINT 0x2: Bulk OUT ===============================
       bLength          :    0x7 (7 bytes)
       bDescriptorType  :    0x5 Endpoint
       bEndpointAddress :    0x2 OUT
       bmAttributes     :    0x2 Bulk
       wMaxPacketSize   :  0x200 (512 bytes)
       bInterval        :    0x0
LGLAF.py: DEBUG: Probing interface:
    INTERFACE 0: CDC Communication =========================
     bLength            :    0x9 (9 bytes)
     bDescriptorType    :    0x4 Interface
     bInterfaceNumber   :    0x0
     bAlternateSetting  :    0x0
     bNumEndpoints      :    0x1
     bInterfaceClass    :    0x2 CDC Communication
     bInterfaceSubClass :    0x2
     bInterfaceProtocol :    0x1
     iInterface         :    0x5 CDC Abstract Control Model (ACM)
      ENDPOINT 0x82: Interrupt IN ==========================
       bLength          :    0x7 (7 bytes)
       bDescriptorType  :    0x5 Endpoint
       bEndpointAddress :   0x82 IN
       bmAttributes     :    0x3 Interrupt
       wMaxPacketSize   :   0x40 (64 bytes)
       bInterval        :    0x9
LGLAF.py: DEBUG: Probing interface:
    INTERFACE 1: CDC Data ==================================
     bLength            :    0x9 (9 bytes)
     bDescriptorType    :    0x4 Interface
     bInterfaceNumber   :    0x1
     bAlternateSetting  :    0x0
     bNumEndpoints      :    0x2
     bInterfaceClass    :    0xa CDC Data
     bInterfaceSubClass :    0x0
     bInterfaceProtocol :    0x0
     iInterface         :    0x6 CDC ACM Data
      ENDPOINT 0x81: Bulk IN ===============================
       bLength          :    0x7 (7 bytes)
       bDescriptorType  :    0x5 Endpoint
       bEndpointAddress :   0x81 IN
       bmAttributes     :    0x2 Bulk
       wMaxPacketSize   :  0x200 (512 bytes)
       bInterval        :    0x0
      ENDPOINT 0x1: Bulk OUT ===============================
       bLength          :    0x7 (7 bytes)
       bDescriptorType  :    0x5 Endpoint
       bEndpointAddress :    0x1 OUT
       bmAttributes     :    0x2 Bulk
       wMaxPacketSize   :  0x200 (512 bytes)
       bInterval        :    0x0
Traceback (most recent call last):
  File "./lglaf.py", line 398, in <module>
    main()
  File "./lglaf.py", line 380, in main
    try_hello(comm)
  File "./lglaf.py", line 272, in try_hello
    comm.write(hello_request)
  File "./lglaf.py", line 258, in write
    self.usbdev.write(self.ep_out, data)
  File "/usr/local/lib/python2.7/dist-packages/usb/core.py", line 940, in write
    intf, ep = self._ctx.setup_request(self, endpoint)
  File "/usr/local/lib/python2.7/dist-packages/usb/core.py", line 102, in wrapper
    return f(self, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/usb/core.py", line 216, in setup_request
    self.managed_claim_interface(device, intf)
  File "/usr/local/lib/python2.7/dist-packages/usb/core.py", line 102, in wrapper
    return f(self, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/usb/core.py", line 167, in managed_claim_interface
    self.backend.claim_interface(self.handle, i)
  File "/usr/local/lib/python2.7/dist-packages/usb/backend/libusb1.py", line 811, in claim_interface
    _check(self.lib.libusb_claim_interface(dev_handle.handle, intf))
  File "/usr/local/lib/python2.7/dist-packages/usb/backend/libusb1.py", line 595, in _check
    raise USBError(_strerror(ret), ret, _libusb_errno[ret])
usb.core.USBError: [Errno 16] Resource busy
Lekensteyn commented 8 years ago

Only one program can use the USB device (lglaf or sonethiing else). Can you reproduce it after removing/re-inserting the device?

underscore-bama commented 8 years ago

I did that and then just did it again. I can't find another program that could possibly be trying to use it.

I think it might have something to do with claiming the interface before setting configuration (having to do with pyusb)?

Lekensteyn commented 8 years ago

It could be a kernel driver (check with lsusb -t) too

underscore-bama commented 8 years ago
~ $ lsusb
Bus 001 Device 003: ID 1004:633a LG Electronics, Inc. 
Bus 003 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 004 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 003 Device 004: ID 0bda:5705 Realtek Semiconductor Corp. 
Bus 003 Device 006: ID 03eb:880a Atmel Corp. 
~ $ lsusb -t
/:  Bus 04.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/2p, 480M
    |__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/6p, 480M
/:  Bus 03.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/2p, 480M
    |__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/6p, 480M
        |__ Port 2: Dev 4, If 0, Class=Video, Driver=uvcvideo, 480M
        |__ Port 2: Dev 4, If 1, Class=Video, Driver=uvcvideo, 480M
        |__ Port 3: Dev 6, If 0, Class=Human Interface Device, Driver=usbhid, 12M
        |__ Port 3: Dev 6, If 1, Class=Human Interface Device, Driver=usbhid, 12M
/:  Bus 02.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/4p, 5000M
/:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/4p, 480M
    |__ Port 2: Dev 3, If 0, Class=Communications, Driver=cdc_acm, 480M
    |__ Port 2: Dev 3, If 1, Class=CDC Data, Driver=cdc_acm, 480M
    |__ Port 2: Dev 3, If 2, Class=Vendor Specific Class, Driver=, 480M

I think you might be right?

underscore-bama commented 8 years ago

So ep-matching branch works on Windows. It's obviously a driver related issue in Linux. LAF still locks everything up though. Guess you can close this. Same with partitions.py.

Lekensteyn commented 8 years ago

On Linux, try sudo modprobe -vr cdc_acm (see the Driver= field).

Lekensteyn commented 8 years ago

I have finally gotten the chance to test my changes. The EP matching logic was still broken, but now it is fixed in f2792e6. The "Resource busy" issue is fixed with 688e0f3.

Can you confirm this? (The changes are merged to master)

underscore-bama commented 8 years ago

I have not had a chance. Fedex picked the phone up this morning. Should have a replacement by Thursday to check for you.

underscore-bama commented 8 years ago

The Resource busy error is fixed, however "Hello I'm LAF" shows up for any commands. So I guess LG has found you out.