本帖最后由 ntzyz 于 2017-9-15 18:25 编辑
我想通过 configfs 将 OTG 端配置成 Mass Storage,脚本如下: - #!/bin/bash
- cd /sys/kernel/config/usb_gadget
- mkdir g.1/functions/mass_storage.0 -p
- echo "/dev/mmcblk0" > g.1/functions/mass_storage.0/lun.0/file
- mkdir g.1/strings/0x409
- mkdir -p g.1/configs/c.1/strings/0x409
- echo 0xa4a2 > g.1/idProduct
- echo 0x0525 > g.1/idVendor
- echo 12345 > g.1/strings/0x409/serialnumber
- echo ntzyz > g.1/strings/0x409/manufacturer
- echo "usb gadget" > g.1/strings/0x409/product
- echo "cnf1" > g.1/configs/c.1/strings/0x409/configuration
- ln -s g.1/functions/mass_storage.0 g.1/configs/c.1
- echo fe800000.dwc3 > g.1/UDC
复制代码这段脚本在连接到 USB2.0 的主机端时,测试无问题: - root@ntzyz-rk3399 ~ # ./start.sh
- [ 22.944403] Mass Storage Function, version: 2009/09/11
- [ 22.944900] LUN: removable file: (no medium)
- [ 23.329729] configfs-gadget gadget: high-speed config #1: c
复制代码主机端也能看到相应的磁盘: 但是在 USB 3.0 下则无效: - root@ntzyz-rk3399 ~ # ./start.sh
- [ 20.913747] Mass Storage Function, version: 2009/09/11
- [ 20.914263] LUN: removable file: (no medium)
复制代码此时 UDC 的状态是未加载,主机端也没有相应的硬件: - root@ntzyz-rk3399 ~ # cat /sys/class/udc/fe800000.dwc3/state
- not attached
复制代码 内核是 GitLab 上 clone 的,配置加了一些特性(cifs, iSCSI over TCPIP, btrfs, etc),完整config链接:https://gist.github.com/ntzyz/7a0b3f4ac56db1dc7684c8d2ce37b1c1
|