Lekensteyn / lglaf

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

Script to copy files to phone #1

Open langbeck opened 8 years ago

langbeck commented 8 years ago

With this script we can push files to phone using several EXEC blocks (with optimal payload size) to transfer a file to phone.

langbeck commented 8 years ago

Just one more thing. I have a D805 and I need to adjust EP_IN and EP_OUT to 0x83 and 2, respectively.

Lekensteyn commented 8 years ago

Hi Dorian, thank you for your interest and PR! I have added some inline comments.

About the endpoint numbers, can you post a subset of the lsudb -v output for your device? See 2d79e1565e7be3272b64312232bda36a6c51ce77 for what I am interested at

Also an additional tip for those who need something with low overhead: you can actually rename /dev/block/mmcblk0 and make a symlink or something. Then OPENing it for writing will allow you to use WRTE commands to transfer a whole file. Alternatively, write to an unused partition and use something like dd if=/dev/block/mmcblk0pX bs=$size count=1 of=/path/to/output/file

langbeck commented 8 years ago

I actualy thought in replace /dev/block/mmcblk0 by a link but I not tried to implement. I'll sent and lsusb subset for D805 when I get home. I also tried in my D855 and I think that I have to adjust the endpoints too (I don't remember well). I'll check that and sent these informations in the next patch.

Lekensteyn commented 8 years ago

I would not recommend renaming the mmcblk0 device unless the user is absolutely sure what (s)he is doing (and then I would still be careful). The D855 is the European version right? That is the one I have tested this project with.

langbeck commented 8 years ago

D805 usb information:

$ lsusb 
Bus 003 Device 002: ID 8087:8000 Intel Corp. 
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 002: ID 0424:5534 Standard Microsystems Corp. 
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 004: ID 04ca:7034 Lite-On Technology Corp. 
Bus 001 Device 003: ID 138a:003f Validity Sensors, Inc. 
Bus 001 Device 009: ID 1004:61f1 LG Electronics, Inc. 
Bus 001 Device 005: ID 8087:07dc Intel Corp. 
Bus 001 Device 002: ID 0424:2134 Standard Microsystems Corp. 
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

$ lsusb -d 1004:
Bus 001 Device 009: ID 1004:61f1 LG Electronics, Inc. 

$ lsusb -d 1004: -v
Bus 001 Device 009: ID 1004:61f1 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          0x61f1 
  bcdDevice            2.32
  iManufacturer           2 LG Electronics Inc.
  iProduct                3 LGE Android Phone
  iSerial                 4 0700a65d19860a02
  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               8 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              6 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              7 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)
langbeck commented 8 years ago

One more thing. partitions.py --list doesn't work for me. The line 35 uses try to list /dev/block/bootdevice/by-name, but in my devices (D805 and D855) the right path is /dev/block/platform/msm_sdcc.1/by-name.

Lekensteyn commented 8 years ago

About the /dev/block path, my D855 has both, but on newer devices only the bootdevice path is present. I guess that some fallback is needed here.

langbeck commented 8 years ago

Initialy I created a new parser argparse.ArgumentParser(), but soon I realize that the options you offer in ./lglaf.py (such skip hello and COM port) should be present in others binaries. I think extending lglaf.parser is a great way to avoid code duplicatation. What do you think?

Lekensteyn commented 8 years ago

The --skip-hello is normally not needed (it just reduces noise during debugging), --serial on the other hand might be useful at more places but its interpretation is completely up to the program. I would say, for now minor duplication is acceptable.

If some common arguments are needed in the future, then it could be added as needed.

langbeck commented 3 years ago

I can't see the merge button... maybe only you @Lekensteyn can do it.