###############################
# Create backing file #
###############################
dd bs=1M count=16 if=/dev/zero of=/tmp/lun0.img
parted /tmp/lun0.img mklabel msdos
parted -f --align=minimal /tmp/lun0.img mkpart primary fat32 0% 100%
mkfs.vfat /tmp/lun0.img
###############################
# Mount file #
###############################
losetup /dev/loop7 /tmp/lun0.img
mount /dev/loop7 /mnt/usb
###############################
# Configure USB gadget #
###############################
modprobe libcomposite
cd /sys/kernel/config/usb_gadget/
mkdir g1
cd g1
###############################
# Populate Device-Level Stuff #
###############################
echo "0x1d6b" > idVendor # Linux Foundation - must be adopted by your ID
echo "0x0104" > idProduct # multi gadget - must be adopted by your ProductID
echo 0x0100 > bcdDevice # v1.0.0
echo 0x0200 > bcdUSB # USB 2.0
# English language strings...
mkdir strings/0x409
echo "0123456789" > strings/0x409/serialnumber
echo "foo" > strings/0x409/manufacturer
echo "bar" > strings/0x409/product
mkdir configs/c.1
mkdir configs/c.1/strings/0x409
echo "USB Mass Storage config" > configs/c.1/strings/0x409/configuration
#
# Create mass_storage config
#
mkdir functions/mass_storage.usb0
# link the mount point which shall be used for usb_mass_storage
mkdir functions/mass_storage.usb0/lun.0
echo "/tmp/lun0.img" > /sys/kernel/config/usb_gadget/g1/functions/mass_storage.usb0/lun.0/file
echo 1 > /sys/kernel/config/usb_gadget/g1/functions/mass_storage.usb0/lun.0/removable
# associate function with config
ln -s functions/mass_storage.usb0 configs/c.1
#bind..
# you need to replace this line with the platform-specific UDC.
# Use 'ls /sys/class/udc' to see available UDCs
echo "ci_hdrc.1" > UDC
1条答案
按热度按时间6yt4nkrj1#
由于没有人提供进一步的信息,以下是我调查的简短结果:
通过libcomposite(基于configfs)而不是g_mass_storage来设置USB小工具似乎是更现代的方法。
在那里,您可以将USB小工具与USB设备控制器链接。
这里的解决方案,这对我的作品:
字符串
将USB小工具与USB设备控制器链接的方法可以用于彼此的USB小工具,如ACM、ECM、NCM、RNDIS等。