...
Use the following command to create a 32MB file (files (backing_file_u2 and backing_file_u3) filled with zeros.
Code Block |
---|
# dd bs=1M count=32 if=/dev/zero of=/backing_file_u2 32+0 records in 32+0 records out 33554432 bytes (34 MB, 32 MiB) copied, 0.0850515 s, 395 MB/s # dd bs=1M count=32 if=/dev/zero of=/backing_file_u3 32+0 records in 32+0 records out 33554432 bytes (34 MB, 32 MiB) copied, 0.0836486 s, 401 MB/s |
Use the following command to create the FAT file system in backing_file_u2 and backing_file_u3.
Code Block |
---|
# mkfs.fat /backing_file_u2 mkfs.fat 4.1 (2017-01-24) # mkfs.fat /backing_file_u3 mkfs.fat 4.1 (2017-01-24) |
ConfigFS
Configure mass storage gadget through configfs saved as a file named usb_mass_storage. UDC_NAME is “f8102800.usb” for USB 2. 0 Controller. UDC_NAME is “f80a1000.dwc3” for USB 3.0 Controller.
Code Block |
---|
#!/bin/bash MODULES=/lib/modules/`uname -r`/kernel LIBCOMPOSITE=/$MODULES/drivers/usb/gadget/libcomposite.ko FUNCTION=/$MODULES/drivers/usb/gadget/function/usb_f_mass_storage.ko #install the drivers insmod $LIBCOMPOSITE insmod $FUNCTION #mount configfs mount -t configfs none /sys/kernel/config ############################## USB2.0 ############################## UDC_NAME="f8102800.usb" BACKING_FILE=/backing_file UDC_NAME="f8102800.usb" # UDC_NAME="f80a1000.dwc3" #install the drivers insmod $LIBCOMPOSITE insmod $FUNCTION #mount configfs mount -t configfs none /sys/kernel/config_u2 #create gadget mkdir /sys/kernel/config/usb_gadget/g1 cd /sys/kernel/config/usb_gadget/g1 echo "64" > bMaxPacketSize0 echo "0x200" > bcdUSB #create configuration mkdir configs/c.1 mkdir configs/c.1/strings/0x409 echo 120 > configs/c.1/MaxPower mkdir strings/0x0409 echo "1234" > strings/0x0409/serialnumber echo "Sunplus" > strings/0x0409/manufacturer echo "SP7350 USB2.0 Mass Storage Gadget" > strings/0x0409/product #create functions mkdir functions/mass_storage.usb0 echo "$BACKING_FILE" > functions/mass_storage.usb0/lun.0/file #link functions and configuration ln -s functions/mass_storage.usb0 configs/c.1 #activate echo $UDC_NAME > UDC ############################## USB3.0 ############################## UDC_NAME="f80a1000.dwc3" BACKING_FILE=/backing_file_u3 #create gadget mkdir /sys/kernel/config/usb_gadget/g1g2 cd /sys/kernel/config/usb_gadget/g1g2 echo "64" > bMaxPacketSize0 echo "0x2000x300" > bcdUSB #create configuration mkdir configs/c.1 mkdir configs/c.1/strings/0x409 echo 120 > configs/c.1/MaxPower mkdir strings/0x0409 echo "5678" > strings/0x0409/serialnumber echo "Sunplus" > strings/0x0409/manufacturer echo "SP7350 USB3.0 Mass Storage Gadget" > strings/0x0409/product #create functions mkdir functions/mass_storage.usb0 echo "$BACKING_FILE" > functions/mass_storage.usb0/lun.0/file #link functions and configuration ln -s functions/mass_storage.usb0 configs/c.1 #activate echo $UDC_NAME > UDC |
...
After updating the image to the SP7350 platform, booting the system and copying the backing_file_u2 and backing_file_u3 to it, use sh usb_mass_storage command to configure UDC ( USB 2.0 or and USB 3.0 ) as a mass storage gadgetdevices.
...
After connecting the mass storage gadget to a Windows PC through an USB cable, “E:\” and “F:\”will show up in “Portable Devices” of “Device Manager” and “Linux File-Stor Gadget USB Device“ in “Disk drivers“.
...
2 “USB Mass Storage Device“ in “Universal Serial Bus controllers“.
...