This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Linux/J6EVM5777: Reading from '/dev/ttyGS0' (USB Generic Serial) is not working in certain cases.

Part Number: J6EVM5777

Tool/software: Linux

Hi,

[Background]

I'm am trying to implement CarPlay on the TI J6 (Android OS - 6AM.1.3).

I was able to configure the USB gadget on the USB 2.0 port and trigger the USB Role Switch then change the USB port to 'device' mode.

iPhone (as the USB host) then does the USB enumeration (of the TI J6) then communication starts over the Bulk In/Out interface.

I am currently using Generic Serial Interface for Bulk In/Out which is used for iAP communication.


[Problem]

Things are working well until packets are exchanged over the USB Generic Serial Interface (/dev/ttyGS0).

I am able to write data but nothing is being read from the generic serial interface (/dev/ttyGS0).

The Beagle USB 480 Protocol Analyzer does show that data is being sent both ways on the Bulk In/Out

however 'read()' blocks or calling 'ioctl (fd, FIONREAD, &n);' always returns 0.

I am currently using two file descriptors. One for reading and one for writing:

> #define IAP2_ENDPOINT_PATH "/dev/ttyGS0"

> m_fd_iap2_read = open(IAP2_ENDPOINT_PATH, O_RDONLY | O_NOCTTY);

> m_fd_iap2_write = open(IAP2_ENDPOINT_PATH, O_WRONLY | O_NOCTTY);

I did also test using a Linux Host with the TI J6 set to 'device' mode.

In this case, I had no issues reading or writing data using /dev/ttyGS0 on the TI J6.

I currently do not have a way for you to reproduce this problem but could you provide some suggestions on what possibly can be wrong?

Thanks,

Alan

  • Hi Alan,

    I have forwarded your question to USB experts.

    Regards,
    Yordan
  • Hi Alan,

    I am just curious what happens when you open only once with O_RDWR ?
  •  

    It is also the same even if I use the same file descriptor opened using O_RDWR.

    Any tips for identifying or debugging the cause of this problem?

    Thanks,

    Alan

  • Also here are the 'dmesg' logs after the bootup from TI J6, if it can provide any clues.

    SELinux mode is permissive so all the 'avc: denied' logs are just for reference.

    I also do 'chmod 777 /dev/tGS0' and do the same for the all the directory or files I need to access.

    [ 141.130001] android_work: did not send uevent (0 0 (null))
    [ 141.135766] dwc3 48890000.usb: otg: gadget gadget unregistered
    [ 141.141629] configfs-gadget gadget: unbind function 'mtp'/ecdeec00
    [ 141.147950] configfs-gadget gadget: unbind function 'Function FS Gadget'/ecd25da4
    [ 141.155611] init: Service 'adbd' is being killed...
    [ 141.164011] init: Service 'adbd' (pid 210) killed by signal 9
    [ 141.169886] init: Service 'adbd' (pid 210) killing any children in process group
    [ 141.346395] using random self ethernet address
    [ 141.350951] using random host ethernet address
    [ 142.056897] usb0: HOST MAC 9a:73:64:a7:1e:bc
    [ 142.061716] usb0: MAC 3a:6a:e4:c4:53:a0
    [ 142.065844] dwc3 488d0000.usb: otg: gadget gadget registered
    [ 142.071646] xhci-hcd xhci-hcd.2.auto: xHCI Host Controller
    [ 142.077295] xhci-hcd xhci-hcd.2.auto: new USB bus registered, assigned bus number 1
    [ 142.085893] xhci-hcd xhci-hcd.2.auto: hcc params 0x0220f04c hci version 0x100 quirks 0x00210010
    [ 142.095940] xhci-hcd xhci-hcd.2.auto: irq 511, io mem 0x488d0000
    [ 142.102172] usb usb1: New USB device found, idVendor=1d6b, idProduct=0002
    [ 142.109022] usb usb1: New USB device strings: Mfr=3, Product=2, SerialNumber=1
    [ 142.116294] usb usb1: Product: xHCI Host Controller
    [ 142.121195] usb usb1: Manufacturer: Linux 4.4.45-g12e865c xhci-hcd
    [ 142.127450] usb usb1: SerialNumber: xhci-hcd.2.auto
    [ 142.133100] hub 1-0:1.0: USB hub found
    [ 142.136943] hub 1-0:1.0: 1 port detected
    [ 142.141308] xhci-hcd xhci-hcd.2.auto: xHCI Host Controller
    [ 142.146860] xhci-hcd xhci-hcd.2.auto: new USB bus registered, assigned bus number 2
    [ 142.154663] usb usb2: We don't know the algorithms for LPM for this host, disabling LPM.
    [ 142.162933] usb usb2: New USB device found, idVendor=1d6b, idProduct=0003
    [ 142.169779] usb usb2: New USB device strings: Mfr=3, Product=2, SerialNumber=1
    [ 142.177076] usb usb2: Product: xHCI Host Controller
    [ 142.181976] usb usb2: Manufacturer: Linux 4.4.45-g12e865c xhci-hcd
    [ 142.188211] usb usb2: SerialNumber: xhci-hcd.2.auto
    [ 142.193817] hub 2-0:1.0: USB hub found
    [ 142.197642] hub 2-0:1.0: 1 port detected
    [ 142.454512] usb 1-1: new high-speed USB device number 2 using xhci-hcd
    [ 142.595820] usb 1-1: New USB device found, idVendor=05ac, idProduct=12a8
    [ 142.602552] usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
    [ 142.609763] usb 1-1: Product: iPhone
    [ 142.613356] usb 1-1: Manufacturer: Apple Inc.
    [ 142.617766] usb 1-1: SerialNumber: db4dae8ebd3fb4ea335a90332aad83d5812e4df3
    [ 142.625218] usb 1-1: ep 0x2 - rounding interval to 8 microframes, ep desc says 10 microframes
    [ 142.633840] usb 1-1: ep 0x81 - rounding interval to 8 microframes, ep desc says 10 microframes
    [ 143.067017] usb 1-1: usbfs: USBDEVFS_CONTROL failed cmd droid.gallery3d rqt 128 rq 6 len 254 ret -71
    [ 151.225109] i2c i2c-2: new_device: Instantiated device authchip at 0x10
    [ 158.930800] init: Starting service 'adbd'...
    [ 158.938604] read descriptors
    [ 158.941508] read strings
    [ 166.195482] omap-iommu 55082000.mmu: 55082000.mmu: version 2.1
    [ 180.273358] omap-iommu 55082000.mmu: 55082000.mmu: version 2.1
    [ 198.633343] omap-iommu 55082000.mmu: 55082000.mmu: version 2.1
    [ 223.824684] type=1400 audit(1502911243.593:3): avc: denied { read write } for pid=1418 comm=".sample.carplay" name="i2c-2" dev="tmpfs" ino=6494 scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:object_r:i2c_dev:s0 tclass=chr_file permissive=1
    [ 223.850231] type=1400 audit(1502911243.603:4): avc: denied { open } for pid=1418 comm=".sample.carplay" path="/dev/i2c-2" dev="tmpfs" ino=6494 scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:object_r:i2c_dev:s0 tclass=chr_file permissive=1
    [ 223.874575] type=1400 audit(1502911243.603:5): avc: denied { ioctl } for pid=1418 comm=".sample.carplay" path="/dev/i2c-2" dev="tmpfs" ino=6494 ioctlcmd=703 scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:object_r:i2c_dev:s0 tclass=chr_file permissive=1
    [ 223.983231] type=1400 audit(1502911243.753:6): avc: denied { read } for pid=1418 comm=".sample.carplay" name="/" dev="tmpfs" ino=9619 scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:object_r:device:s0 tclass=dir permissive=1
    [ 224.006279] xhci-hcd xhci-hcd.2.auto: remove, state 4
    [ 224.012604] type=1400 audit(1502911243.753:7): avc: denied { read } for pid=1418 comm=".sample.carplay" name="usb" dev="tmpfs" ino=14250 scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:object_r:usb_device:s0 tclass=dir permissive=1
    [ 224.013987] usb usb2: USB disconnect, device number 1
    [ 224.015400] xhci-hcd xhci-hcd.2.auto: USB bus 2 deregistered
    [ 224.015419] xhci-hcd xhci-hcd.2.auto: remove, state 1
    [ 224.015436] usb usb1: USB disconnect, device number 1
    [ 224.015440] usb 1-1: USB disconnect, device number 2
    [ 224.054996] xhci-hcd xhci-hcd.2.auto: USB bus 1 deregistered
    [ 224.071357] type=1400 audit(1502911243.753:8): avc: denied { open } for pid=1418 comm=".sample.carplay" path="/dev/bus/usb" dev="tmpfs" ino=14250 scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:object_r:usb_device:s0 tclass=dir permissive=1
    [ 224.097101] type=1400 audit(1502911243.753:9): avc: denied { open } for pid=1418 comm=".sample.carplay" path="/dev/bus/usb/002/001" dev="tmpfs" ino=14254 scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:object_r:usb_device:s0 tclass=chr_file permissive=1
    [ 224.122156] type=1400 audit(1502911243.783:10): avc: denied { read } for pid=1418 comm=".sample.carplay" name="mode" dev="debugfs" ino=7260 scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:object_r:debugfs:s0 tclass=file permissive=1
    [ 224.351699] android_work: sent uevent USB_STATE=CONNECTED
    [ 224.365201] configfs-gadget gadget: high-speed config #1: b
    [ 224.371554] android_work: sent uevent USB_STATE=CONFIGURED
    [ 224.411298] mtp_open
    [ 225.017746] type=1400 audit(1502911244.793:11): avc: denied { read write } for pid=1418 comm="NmeIAPDetector:" name="ttyGS0" dev="tmpfs" ino=14236 scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:object_r:device:s0 tclass=chr_file permissive=1
    [ 225.040957] type=1400 audit(1502911244.793:12): avc: denied { open } for pid=1418 comm="NmeIAPDetector:" path="/dev/ttyGS0" dev="tmpfs" ino=14236 scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:object_r:device:s0 tclass=chr_file permissive=1
    [ 225.065883] type=1400 audit(1502911244.793:13): avc: denied { getattr } for pid=1418 comm="NmeIAPDetector:" path="/dev/ttyGS0" dev="tmpfs" ino=14236 scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:object_r:device:s0 tclass=chr_file permissive=1
    [ 240.248480] omap-iommu 55082000.mmu: 55082000.mmu: version 2.1
    root@jacinto6evm:/ # [ 300.249772] omap-iommu 55082000.mmu: 55082000.mmu: version 2.1
    [ 317.597208] omap-iommu 55082000.mmu: 55082000.mmu: version 2.1

  • Another observation.

    I enabled USB_GADGET_DEBUG and USB_GADGET_VERBOSE to get more debug logs (via dmesg).

    Below is part of what I see. Only TX and no RX.

    [  855.345807] gs_open: start ttyGS0
    [  855.345877] gs_open: ttyGS0 (e86ddc00,e87a0180)
    [  855.346222] gs_write_room: (0,e86ddc00) room=8191
    [  855.346233] gs_write: ttyGS0 (e86ddc00) writing 6 bytes
    [  855.346254] ttyGS0: tx len=6, 0xff 0x55 0x02 ...
    [  855.346275] gs_flush_chars: (0,e86ddc00)
    [  855.349506] gs_write_room: (0,e86ddc00) room=8191
    [  855.349526] gs_put_char: (0,e86ddc00) char=0xff, called from tty_put_char
    [  855.349539] gs_put_char: (0,e86ddc00) char=0x55, called from tty_put_char
    [  855.349550] gs_put_char: (0,e86ddc00) char=0x5e, called from tty_put_char
    [  855.349560] gs_put_char: (0,e86ddc00) char=0x42, called from tty_put_char
    [  855.349570] gs_put_char: (0,e86ddc00) char=0x5e, called from tty_put_char
    [  855.349580] gs_put_char: (0,e86ddc00) char=0x40, called from tty_put_char
    [  855.349590] gs_put_char: (0,e86ddc00) char=0xee, called from tty_put_char
    [  855.349600] gs_put_char: (0,e86ddc00) char=0x5e, called from tty_put_char
    [  855.349609] gs_put_char: (0,e86ddc00) char=0x50, called from tty_put_char
    [  855.349617] gs_flush_chars: (0,e86ddc00)
    [  855.349625] ttyGS0: tx len=9, 0xff 0x55 0x5e ...
    [  856.346513] gs_write_room: (0,e86ddc00) room=8191
    [  856.346524] gs_write: ttyGS0 (e86ddc00) writing 6 bytes
    [  856.346535] ttyGS0: tx len=6, 0xff 0x55 0x02 ...
    [  856.346562] gs_flush_chars: (0,e86ddc00)
    [  856.347660] gs_write_room: (0,e86ddc00) room=8191
    [  856.347675] gs_put_char: (0,e86ddc00) char=0xff, called from tty_put_char
    [  856.347687] gs_put_char: (0,e86ddc00) char=0x55, called from tty_put_char
    [  856.347698] gs_put_char: (0,e86ddc00) char=0x5e, called from tty_put_char
    [  856.347708] gs_put_char: (0,e86ddc00) char=0x42, called from tty_put_char
    [  856.347718] gs_put_char: (0,e86ddc00) char=0x5e, called from tty_put_char
    [  856.347727] gs_put_char: (0,e86ddc00) char=0x40, called from tty_put_char
    [  856.347736] gs_put_char: (0,e86ddc00) char=0xee, called from tty_put_char
    [  856.347746] gs_put_char: (0,e86ddc00) char=0x5e, called from tty_put_char
    [  856.347755] gs_put_char: (0,e86ddc00) char=0x50, called from tty_put_char
    [  856.347762] gs_flush_chars: (0,e86ddc00)
    ......

    One thing weird is that I am only writing 6 bytes of the same data (iAP2 initialization packet) every second.

    Not sure where the 9 bytes of other data (FF 55 5e 42 5e 40 ee 5e 50) is coming from and is being written.

    It is picked up by the USB protocol analyzer as well.

    But still no reads.

  • I found the problem with the 9 bytes.
    I had to run the following command to turn off ECHO.
    > stty -echo < /dev/ttyGS0

    But still no read...

    [ 6182.415588] gs_open: start ttyGS0
    [ 6182.415658] gs_open: ttyGS0 (e6e1bc00,e6eec840)
    [ 6182.416027] gs_write_room: (0,e6e1bc00) room=8191
    [ 6182.416037] gs_write: ttyGS0 (e6e1bc00) writing 6 bytes
    [ 6182.416049] ttyGS0: tx len=6, 0xff 0x55 0x02 ...
    [ 6182.416081] gs_flush_chars: (0,e6e1bc00)
    [ 6182.419442] gs_flush_chars: (0,e6e1bc00)
    [ 6183.416301] gs_write_room: (0,e6e1bc00) room=8191
    [ 6183.416312] gs_write: ttyGS0 (e6e1bc00) writing 6 bytes
    [ 6183.416323] ttyGS0: tx len=6, 0xff 0x55 0x02 ...
    [ 6183.416351] gs_flush_chars: (0,e6e1bc00)
    [ 6183.417480] gs_flush_chars: (0,e6e1bc00)

  • Alan

    What is the default stty terminal settings ?

    Can you try wtih

    # stty -F /dev/ttyGS0 -icanon

    Regards

    Ravi 

  • Hi ,

    Thanks for the suggestion.

    This worked. :)

    We can now read from /dev/ttyGS0 using the command 'stty -F /dev/ttyGS0 -icanon -echo'

    Best regards,

    Alan

  • Alan

    Glad to see working for you now.
    So this thread can be closed.

    Regards
    Ravi