How to set TX2 otg usb as device mode?

Hi FoxK, we are checking it.

Hi FoxK, please follow the steps:

  1. Apply the patches and rebuild/apply new dtb
  2. Run “configfs_msc_l4t.sh” script to enable device mode
    3. Plug in USB3.0 cable
  3. sudo su
  4. echo 0x1 > /sys/class/extcon/extcon0/state

dmesg should show

[  143.471023] configfs-gadget gadget: super-speed config #1: b

hardware-nvidia-platform-t18x-common.patch.txt (1.4 KB)
hardware-nvidia-platform-t18x-quill.patch.txt (3.54 KB)

Hi DaneLLL,
I got the TX2 USB3 device mode performance with R28.1, thanks.

Best regards,

hi everyone:

i have already update my tx2 to R28.2 by jetpack 3.2 and i see the scripts under /opt/nvidia/l4t-usb-device-mode/nv-l4t-usb-device-mode.sh ,it can set usb mode with otg well

but my problem is how set gadget mode into f_uvc , when i try to enable uvc,i get the error message as below

if [ {enable_uvc} -eq 1 ]; then cfg_str="{cfg_str}+UVC"
func=functions/uvc.usb0
mkdir -p “{func}" ln -sf "{func}” “${cfg}”
fi

the dmesg give back some errors when start

[ 7.619919] configfs-gadget gadget: uvc_function_bind
[ 7.619924] configfs-gadget gadget: Unable to allocate streaming EP

anyone can help me?

Hi everyone:

I used tx2 R28.1, and I followed steps mentioned at https://devtalk.nvidia.com/default/topic/1014096/jetson-tx2/how-to-set-tx2-otg-usb-as-device-mode-/post/5205500/#5205500

Here are messages when i run configfs_msc_l4t.sh:

[ 64.817046] Mass Storage Function, version: 2009/09/11
[ 64.822224] LUN: removable file: (no medium)
1024+0 records in
1024+0 records out
1073741824 bytes (1.1 GB, 1.0 GiB) copied, 1.39897 s, 768 MB/s
mke2fs 1.42.13 (17-May-2015)
Discarding device blocks: done
Creating filesystem with 262144 4k blocks and 65536 inodes
Filesystem UUID: a115e098-0288-45cc-bbd5-79c76160873f
Superblock backups stored on blocks:
32768, 98304, 163840, 229376

Allocating group tables: done
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done

[ 73.667667] tegra-xudc-new 3550000.xudc: ep 0 (type: 0, dir: out) enabled
nvidia@tegra-ubuntu:~/Desktop$ [ 75.675232] tegra-usb-cd usb_cd: notification status (0x1, 0x20)
[ 75.681542] tegra-usb-cd usb_cd: connected to non-standard charger
[ 75.690102] tegra-usb-cd usb_cd: set current 500ma

And here are messages when i plug in USB3.0 cable

[ 330.319109] android_work: did not send uevent (0 0 (null))
[ 330.373970] android_work: did not send uevent (0 0 (null))
[ 330.406976] android_work: sent uevent USB_STATE=CONNECTED
[ 330.436733] configfs-gadget gadget: high-speed config #1: b
[ 330.442336] tegra-xudc-new 3550000.xudc: ep 3 (type: 2, dir: in) enabled
[ 330.442368] android_work: sent uevent USB_STATE=CONFIGURED
[ 330.454945] tegra-xudc-new 3550000.xudc: ep 2 (type: 2, dir: out) enabled

It seems that it only achieved high-speed instead of super-speed

any ideas?

Hi ts01399984,
We suggest you try other USB3 cables with different brands. We have seen some USB3 cables which do not route TX/RX correctly and have to swap it. We have hit it on r24.2.1:
https://devtalk.nvidia.com/default/topic/952472/jetson-tx1/jtx1_usb_as-device/post/4937794/#4937794

Hi DaneLLL,
I have read the five steps your list above.However,I still don’t know what to do about the first step.
How can I apply the patch and rebuild/apply new dtb?
My tx2 is R28.1.
I need more information.
Thanks.

Please download source code and follow document to build device tree.

Please check
https://devtalk.nvidia.com/default/topic/1014096/jetson-tx2/how-to-set-tx2-otg-usb-as-device-mode-/post/5192587/#5192587

Hi,DaneLLL
I have no experience on building device tree.
Will you tell me which document can I follow?
thanks.

Please keep in mind that the actual method for installing a new device tree depends on which version you use.

Here is some information on manipulating device tree files:
https://devtalk.nvidia.com/default/topic/1037131/jetson-tx1/does-anybody-know-how-to-enable-and-program-an-spi-protocol-on-the-tx1-/post/5269528/#5269528

If you don’t have “dtc”, then:

sudo apt-get install device-tree-compiler

ok I will try

Hi,
My platform is TX2 and Jetpack3.1 R28.1.
I get source code and tool chain from
https://developer.nvidia.com/embedded/linux-tegra-r281
And I change the code follow
hardware-nvidia-platform-t18x-common.patch.txt
hardware-nvidia-platform-t18x-quill.patch.txt
I rebuild and get Image、dtb、moudles,then I replace the original file with these and refresh my system.
But,when I finished refresh my system ,USB can not be recognized.
tegra186-quill-p3310-1000-a00-00-base.dts.txt (5.66 KB)
tegra186-quill-p3310-1000-a00-plugin-manager.dtsi.txt (6.53 KB)
tegra186-quill-p3310-1000-c03-00-base.dts.txt (3.06 KB)

Can you verify your device tree edits made it into the final tree? You can extract from your running Jetson and then compare to see if your edits are in place (to see if the flash procedure did as expected):

dtc -I fs -O dts -o extracted.dts /proc/device-tree

I can’t say for sure, but if your initial configuration wasn’t correct (and I don’t know what is correct, I’m just speaking of procedures, not actual content), then even if your edits didn’t exist it could disable USB.

I hava checked these thress files,they have changed.But I am not sure whether it correct or not.
Here I attach those files.
dts.rar (238 KB)

I couldn’t tell you if your device tree changes are valid or not for this purpose…someone else will have to comment on this.

Hi all,
I run the script https://devtalk.nvidia.com/default/topic/1014096/jetson-tx2/how-to-set-tx2-otg-usb-as-device-mode-/1 and I can get otg device mode.However,I also have some questions that I do not understand:
1.The filesystem is ext4 so I can not open it in windows system.So,I have to check it in my virtual machine.
2.The size of disk sapce is 1.1G ,how can I change the size?
3.I mount the disk on my virtual machine and create a new file,but I can not find it in TX2.So Where I get the 1.1G ?

Hi,
The linux commands to generate storage is in the script. It generates 1G with below commands:

dd if=/dev/zero of=/home/ubuntu/msc.ext4.img bs=1M count=1k
mkfs.ext4 /home/ubuntu/msc.ext4.img

Other users may share their experience to give you suggestion for the requests.

Hi,DaneLLL
That’s great!!
So,do you mean I can set the size freely.
Where I save my file and I also get in my virtual machine?

Hi,
You should get 2G if you change count=2k

Don’t know how to initialize non-ext4 format. Other users may share experience.

Basically you are using loopback to make a file appear to be a block device. Block devices transfer in “block size” chunks. A real disk is 512 bytes or multiples of 512 bytes, e.g., 4096 is common in some SSDs, but most old style hard drives stick to 512 bytes. There might be some improved efficiency in using a larger block size if on average your file sizes are larger, but for all cases you can’t go wrong with 512 bytes (consider that if the underlying disk holding the loopback file has a 512 byte block size, then that is read in 512 byte chunks, and thus there is never improvement on larger block sizes for a loopback file on that hard drive…the eMMC is 512 bytes…see “sudo gdisk -l /dev/mmcblk0”).

“dd” is creating a blank file of a specified size. There are many ways of doing this, e.g., the “truncate” command can reduce or enlarge files, while dd only creates from scratch or overwrites an existing content. However, dd might be more efficient for some uses due to working at a lower level than does truncate. Let’s say you want 4GB. Call it “410241024*1024 == 4294967296”. In 512 byte blocks this is “4294967296/512 == 8388608”. So this would create an empty file capable of holding a 4GB file system (raw bytes) using 512 byte blocks:

dd if=/dev/zero of=/some/where/empty.dat bs=512 count=8388608

Once this is covered by loopback it can be treated as if it were a hard disk partition by addressing the loopback device.

FYI, you need to be root (use sudo) for much of the losetup command. A non-root user can query what the first unused loopback device is via:

losetup --find

If the result is “/dev/loop0”, then you can check existence:

ls /dev/loop0

Here is the subtle tip: Running “losetup --find” as non-root will report the first unused loop device. This device might not exist, and if not, it won’t be created. On the other hand, if you use “sudo”, then a simple query of “sudo losetup --find” will also create the device reported as first unused device. You have a limited number of loopback devices available, and it is a leak if you create too many and never release.

So to “cover” a file with loopback, in its simplest form form where the device name is created if needed and also reported as to which device:

sudo losetup --find --show /some/where/empty.dat

If it turns out it was “/dev/loop0” reported, then you could detach loopback in a number of ways, but this is for the specific device:

sudo losetup -d /dev/loop0

To detach all loopback devices which are not bound to some process:

sudo losetup -D

Don’t for get to detach after you are done.

To format this as ext4:

sudo mkfs.ext4 /dev/loop0

To mount this and use it as if it were a partition:

sudo mount /dev/loop0 /some/where/else/

To umount you can do either of these:

sudo umount /dev/loop0
sudo umount /some/where/else

Something you can do is examine:

sudo gdisk -l /dev/loop0

You cannot modify a mounted partition, but if the file is covered by loopback and not mounted, then you can dynamically resize it via:

sudo gparted /dev/loop0

Now if you needed a larger partition, you could change partition size (I won’t guarantee data isn’t lost, but most of the time this is ok). Assuming the file is not covered by loopback and not mounted, and that we are going from 4GiB to 8GiB (originally “bs=512 count=8388608”, so we double count and get "512*83886082 == 8589934592"…this is bytes not count…it is “dd” which uses countbs):

truncate /some/where/empty.dat --size=8589934592
sudo losetup --find --show /some/where/empty.dat
sudo gpart /dev/loop0
# ...now just do as normal with gparted telling it to extend the file system...
# ...then use the file for loopback mount as you would normally...

Experiment with it on a test file before doing this on something you value.

NOTE: I know nothing about the virtual machine, but this file would have to be accessible by any VM as a regular file, and the VM kernel would have to support loopback. The loop device is what the VM works with, but the loop device can’t cover a file it can’t see. A Jetson does not normally run a VM, so I guess you are doing something custom.