Current releases have some sample code running for device mode (I am assuming you are using the dev kit). If you look at “/opt/nvidia/l4t-usb-device-mode/”, then you will find the script which starts the device mode (“gadget” in this case): “nv-l4t-usb-device-mode.sh” (and “nv-l4t-usb-device-mode-stop.sh” to stop device mode).
Look closely inside of “nv-l4t-usb-device-mode.sh”. USB can consist of more than one device on a single wire (think of HUBs…but this applies to anything, e.g., a programmable mouse can also show up as a keyboard). This script covers a gadget ethernet device (default address 192.168.55.1 and a bridge to glue it to the TX2), and also mass storage. If you want to you can actually comment out the ethernet device (which I tend to do if I’m not going to use it).
The mass storage component has multiple options. One option (the option not chosen in this script) is to name a directory tree within the actual file system. For example, one could mount an SD card, partition and format as VFAT, then mount this somewhere…and give that mount point to the gadget mass storage. That partition would be accessible over USB.
The method actually chosen is to cover a file with loopback. Note “filesystem.img”. Look for this in the script. The exact size of this file is 16777216 bytes. This is exactly divisible twice by 1024. This file is 16MB. Run this command to see what the system thinks of the file:
file filesystem.img
What you will find out is that if this file is covered with loopback, then it could be made to pretend to be an MSDOS partition. You can’t mount the same file system twice at the same time, but if you have ever flashed your Jetson, then your host will have “Linux_for_Tegra/rootfs/opt/nvidia/l4t-usb-device-mode/filesystem.img”. You can run this command to loopback mount the file:
cd /where/ever/it/is/Linux_for_Tegra/rootfs/opt/nvidia/l4t-usb-device-mode/
sudo mount -o loop filesystem.img /mnt
ls /mnt
df -H -T /mnt
sudo umount /mnt
“df -H -T” will tell you the loopback device which is used to cover the file (if you have just rebooted and not used any loopback devices, then it would probably be “/dev/loop0”). That command will also tell you file system type is “vfat”.
There are ways to use a partition instead of a loopback file. There are ways to use a subset of an existing directory tree as well (but this will be ext4 if you simply use the root file system…if the RPi understands ext4 then this is probably a good choice, but if the other end is Windows, then this is a bad choice). There are ways to make this file larger (technically there are ways to make the file smaller as well, but you’re getting to near the minimum size).
One restriction is that you might not have access to the content of the loopback file until you mount it locally (USB has access via the loop device covering it). I mention this because there can be issues if two devices try to modify the file at the same time…I haven’t really tested if it is reliable, but technically even when that loopback file is used over USB you can also “sudo mount -o loop /opt/nvidia/l4t-usb-device-mode/filesystem.img /mnt” (or “-o loop,ro” for read-only) and have it visible on “/mnt” for Linux on the TX2 at the same time.
A serial port is a good way to send commands (the dev kit already has “/dev/ttyS0”…the J21 UART…set up as a console which is logged in as account “nvidia”), and although bandwidth is limited and not so good for mass file transfer you’ll find the method is simple and reliable for actual interaction on the command line.