In general, the demonstration of Gadget device mode includes both the virtual ethernet and the block device with the README file. You’ll perhaps want to copy that, and remove the ethernet part (so the original is not changed), followed by editing the block device (mass storage) content to point at your partition instead of creating and pointing at a loopback device (the “losetup
” content “covers” a file in order to make the file look like a partition). That location is in:
/opt/nvidia/l4t-usb-device-mode
(more on that below)
Before you start though, can you verify the SSD’s partition you wish to use, and say if it is able to mount
and umount
to some temporary location? What do you see from the command “lsblk -f
”? Mostly you will want to set up some sample file to see if it can be read, and place it on the partition, but you won’t want the partition mounted while actually working with it.
Regarding the example mass storage code, it is both simplified and made more complex because it is enabled as a service. Are you familiar with reading bash
shell script code? Mostly it is just the same as what people would type in on command line (your login shell is in fact a bash
shell…the same interpreter is reading the scripts we look at that also looks at what you type into the command line when operating normally).
The scripts in that location have a manual “stop” and “start” shell script, which will be obvious by their names. There is also a “service” setup, which is used during startup by the operating system to enable/disable/start/stop that same service (the service is a front end wrapper to the start and stop of the actual function, and you want to work only with a start and stop of function, and not with start and stop of a service). When the operating system starts or stops this it is given the service name “nv-l4t-usb-device-mode.service
”, and it starts or stops both the mass storage and the virtual ethernet services. When you go to work on a copy you’ll need to initially not stop or start this as a service (leave the original service and files alone, and when working, just stop or start the edited nv-l4t-usb-device-mode.sh
or stop.sh
which avoids touching any files or resource from the original demonstration of mass storage).
A demonstration of the service is to query the status:
systemctl status nv-l4t-usb-device-mode
(you won’t be using this, but it is useful to see if the service is running)
Note the file “filesystem.img
”. This is the file which pretending to be a partition. Any command you see related to networking you can remove from your copy, and any command related to “losetup
” can also be removed (this is part of mass storage, but you are not emulating a partition, you have an actual partition). You will need to operate as root for all edits, so you’ll drop into a root shell via “sudo -s
”.
I would first “cd /opt/nvidia
”. Then I’d make a copy of the content under a new directory:
# Warning: This gives you permission to destroy the o/s:
sudo -s
cd /opt/nvidia
cp -adpR ./l4t-usb-device-mode ssd
cd ssd
rm dhcp*
rm *filesystem*
rm mac-addresses
rm nv-l4t-usb-device-mode.service
The above will remove much of the content which you won’t be using. Explore those files. Find the parts which are related to a virtual network device, and remove them or comment them out. Incidentally, in a bash
script, you always leave the top two lines alone, whereby the second line is blank. So you won’t touch this:
#!/bin/bash
(known as the “shebang”)
Note that comments start with “#
”. If you wonder if something does something, but don’t want to delete it, you can make those lines inert via prefixing with “#
”. You don’t need to remove comments related to networking, but you could. The comments might be useful in figuring out what is related to mass storage versus networking. Sections with IP addresses, MAC addresses, routing, so on, can all be deleted. Parts related to fs_img
or filesystem or partitioning will be edited. Parts related to “loop0
” (or any particular “loop#
”) will need to be edited to point at the actual partition (“loop0
” is a virtual partition).
Incidentally, this lists block devices, and you’ll find “loop0
” (which is “/dev/loop0
”) listed:
lsblk -f
Eventually you will link the SSD you see in that command. loop0
will still be present because you are not editing the original demo, you’re adding your own edited version in a new directory.
During the editing you’ll have to start learning about the Gadget API from some of those documents listed in earlier replies. Feel free to ask questions, for example, if you want to know how to edit a particular line of code in a file, or what the hexadecimal means for USB parameters, so on. This will not be without a learning curve.