...
Table of Contents | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Kernel Setup
Enter the kernel configuration by running the following command in the top directory of project.
...
Select submenus for USB 2.0 controller : Device Drivers > USB support > USB Gadget Support > USB Peripheral Controller. Select <*> for “Sunplus USB 2.0 Device Controller“.
...
Select submenus for USB OTG Transceive driver : Device Drivers > USB support > USB Physical Layer drivers. Select <*> for “Sunplus USB OTG Transceive driver“.
...
Select submenus for USB 3.0 controller : Device Drivers > USB support. Select <*> for “DesignWare USB3 DRD Core Support“ and select “Dual Role mode“ for “Deware USB3 DRD Core Support“.
...
Select submenus for
...
USB
...
Select submenus for USB Gadget configfs : Device Drivers > USB support > USB Gadget Support. Select <M> for “USB Gadget functions configurable through configfs“ and [*] for “Mass storage“.
...
Execute the make command to build the Linux image.
Create a backing storage file
The backing storage file must be prepared before the gadget uses it.
...
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.
Code Block |
---|
#!/bin/bash USB2_UMS_EN=on USB3_UMS_EN=on MODULES=/lib/modules/`uname -r`/kernel LIBCOMPOSITE=/$MODULES/drivers/usb/gadget/libcomposite.ko FUNCTION=/$MODULES/drivers/usb/gadget/function/usb_f_mass_storage.ko # #installinstall the drivers insmod $LIBCOMPOSITE insmod $FUNCTION #mount configfs # disable debug message echo 0 > /sys/module/sunplus_udc/parameters/dmsg # mount configfs mkdir -p /sys/kernel/config mount -t configfs none /sys/kernel/config if ############################## USB2.0 ##############################[ $USB2_UMS_EN = on ] then UDC_NAME="f8102800.usb" BACKING_FILE=/backing_file_u2 #create # create gadget mkdir cd /sys/kernel/config/usb_gadget/ mkdir g1 cd /sys/kernel/config/usb_gadget/g1g1 echo "64" > bMaxPacketSize0 echo "0x200" > bcdUSB #create# create configuration mkdir -p configs/c.1 mkdir -p 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 # create functions mkdir functions/mass_storage.usb0 echo "$BACKING_FILE" > functions/mass_storage.usb0/lun.0/file #link # link functions and configuration ln -s functions/mass_storage.usb0 configs/c.1 #activate # activate echo $UDC_NAME > UDC fi if [ $USB3_UMS_EN ############################## USB3.0 ##############################= on ] then UDC_NAME="f80a1000.dwc3" BACKING_FILE=/backing_file_u3 #create # create gadget mkdir cd /sys/kernel/config/usb_gadget/g2 cd /sys/kernel/config/usb_gadget/g2 if [ $USB2_UMS_EN = on ] then mkdir g2 cd g2 else mkdir g1 cd g1 fi echo "64" > bMaxPacketSize0 echo "0x300" > bcdUSB #create # 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 # create functions mkdir functions/mass_storage.usb0 echo "$BACKING_FILE" > functions/mass_storage.usb0/lun.0/file #link # link functions and configuration ln -s functions/mass_storage.usb0 configs/c.1 #activate # activate echo $UDC_NAME > UDC fi |
Implementation
After updating the image to the SP7350 platform, booting the system and copying backing_file_u2 and backing_file_u3 to it, use sh usb_mass_storage command to configure USB 2.0 and USB 3.0 as mass storage devices.
...