Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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

#install# install the drivers
insmod $LIBCOMPOSITE
insmod $FUNCTION

# disable debug message
echo 0 > /sys/module/sunplus_udc/parameters/dmsg

# #mountmount configfs
mkdir -p /sys/kernel/config
mount -t configfs none /sys/kernel/config

if [ $USB2_UMS_EN = on ]
then
    UDC_NAME="f8102800.usb"
    BACKING_FILE=/backing_file_u2
    
    # #createcreate gadget
    cd /sys/kernel/config/usb_gadget
    mkdir g1
    cd g1

    echo "64" > bMaxPacketSize0
    echo "0x200" > bcdUSB
    
    # #createcreate 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

    # #createcreate functions
    mkdir functions/mass_storage.usb0
    echo "$BACKING_FILE" > functions/mass_storage.usb0/lun.0/file
    
    # #linklink functions and configuration
    ln -s functions/mass_storage.usb0 configs/c.1
    
    # #activateactivate
    echo $UDC_NAME > UDC
fi

if [ $USB3_UMS_EN = on ]
then
    UDC_NAME="f80a1000.dwc3"
    BACKING_FILE=/backing_file_u3
    
    # #createcreate gadget
    cd /sys/kernel/config/usb_gadget

    if [ $USB2_UMS_EN = on ]
    then
        mkdir g2
        cd g2
    else
        mkdir g1
        cd g1
    fi

    echo "64" > bMaxPacketSize0
    echo "0x300" > bcdUSB
    
    # #createcreate 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

    # #createcreate functions
    mkdir functions/mass_storage.usb0
    echo "$BACKING_FILE" > functions/mass_storage.usb0/lun.0/file
    
    # #linklink functions and configuration
    ln -s functions/mass_storage.usb0 configs/c.1
    
    # #activateactivate
    echo $UDC_NAME > UDC
fi

Implementation

...