linux g_mass_storage -选择USB端口

kcwpcxri  于 2023-08-03  发布在  Linux
关注(0)|答案(1)|浏览(115)

在我的开发板(imx6)上,我有两个USB OTG端口:

ls /sys/class/udc 
ci_hdrc.0  ci_hdrc.1

字符串
当我设置大容量存储时

modprobe g_mass_storage file=/tmp/lun0.img


则自动地将USB端口ci_hdrc.0用于此。
是否可以配置哪个USB端口应用于g_mass_storage?在我的例子中,我想使用ci_hdrc.1而不是ci_hdrc.0。

6yt4nkrj

6yt4nkrj1#

由于没有人提供进一步的信息,以下是我调查的简短结果:
通过libcomposite(基于configfs)而不是g_mass_storage来设置USB小工具似乎是更现代的方法。
在那里,您可以将USB小工具与USB设备控制器链接。
这里的解决方案,这对我的作品:

###############################
# 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

字符串
将USB小工具与USB设备控制器链接的方法可以用于彼此的USB小工具,如ACM、ECM、NCM、RNDIS等。

相关问题