我在基于 i.MX6 处理器的定制板上运行 Linux。 USB 端口的设备树配置为 otg,两个角色都是工作小工具 (g_ether
或g_serial
) 和主机(插入大容量存储设备)。启动后,USB 被配置为小工具,在这种情况下,我可以g_ether
毫无问题地加载并与我的笔记本电脑通信。之后,我将角色切换为主持人,并且像以前一样工作得很好。我可以将“大容量存储”连接到主板,系统会识别它。最后,当我再次将角色切换回小工具时,我不再可以制作g_ether
或g_serial
工作。上没有错误信息dmesg
。
设备树
&usbotg1 {
pinctrl-names = "default";
dr_mode = "otg";
status = "okay";
};
Linux
root@xxxx:~# uname -a
Linux xxxx 5.4.24-2.0.0+g8115d570b280 #1 SMP PREEMPT Tue Sep 21 14:56:23 UTC 2021 armv7l armv7l armv7l GNU/Linux
硬件
1. The board has a mini USB-B female connector
2. The ID pin is connected to ground
3. The +5V is not used (not connected)
重现问题的分步命令
### 1. After boot the default role is gadget
root@xxxx:~# cat /sys/kernel/debug/ci_hdrc.0/role
gadget
### 2. Plug laptop and confirm that g_ether is working
root@xxxx:~# ifconfig usb0
usb0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 metric 1
inet 192.168.7.1 netmask 255.255.255.0 broadcast 192.168.7.255
inet6 fe80::64ba:c3ff:fef0:cfba prefixlen 64 scopeid 0x20<link>
ether 66:ba:c3:f0:cf:ba txqueuelen 1000 (Ethernet)
RX packets 62 bytes 6802 (6.6 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 45 bytes 3754 (3.6 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
root@xxxx:~# ping -c 2 -w 3 192.168.7.3
PING 192.168.7.3 (192.168.7.3): 56 data bytes
64 bytes from 192.168.7.3: seq=0 ttl=64 time=1.161 ms
64 bytes from 192.168.7.3: seq=1 ttl=64 time=1.023 ms
--- 192.168.7.3 ping statistics ---
2 packets transmitted, 2 packets received, 0% packet loss
round-trip min/avg/max = 1.023/1.092/1.161 ms
### 3. Unplug laptop, switch USB role to host and plug mass storage device
root@xxxx:~# echo host > /sys/kernel/debug/ci_hdrc.0/role
root@xxxx:~# cat /sys/kernel/debug/ci_hdrc.0/role
host
root@xxxx:~# dmesg
...
[ 1387.750491] usb 2-1: new high-speed USB device number 3 using ci_hdrc
[ 1387.802654] usb 2-1: New USB device found, idVendor=0525, idProduct=a4a5, bcdDevice= 2.21
[ 1387.802711] usb 2-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 1387.802745] usb 2-1: Product: USB download gadget
[ 1387.802777] usb 2-1: Manufacturer: FSL
[ 1387.815591] usb-storage 2-1:1.0: USB Mass Storage device detected
[ 1387.837391] usb-storage 2-1:1.0: Quirks match for vid 0525 pid a4a5: 10000
[ 1387.838126] scsi host0: usb-storage 2-1:1.0
[ 1389.031295] usb 2-1: reset high-speed USB device number 3 using ci_hdrc
[ 1389.271363] usb 2-1: reset high-speed USB device number 3 using ci_hdrc
[ 1389.511572] usb 2-1: reset high-speed USB device number 3 using ci_hdrc
[ 1389.751624] usb 2-1: reset high-speed USB device number 3 using ci_hdrc
# sda is present
root@xxxx:~# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 1 7.3G 0 disk
`-sda1 8:1 1 7.3G 0 part
mmcblk1 179:0 0 7.3G 0 disk
`-mmcblk1p1 179:1 0 7.3G 0 part /sysroot
mmcblk1boot0 179:8 0 4M 1 disk
mmcblk1boot1 179:16 0 4M 1 disk
### 4. Unplug mass store device, switch USB role to gadget
root@xxxx:~# echo gadget > /sys/kernel/debug/ci_hdrc.0/role
root@xxxx:~# cat /sys/kernel/debug/ci_hdrc.0/role
gadget
### 5. Interface is present and g_ether is loaded but can't ping laptop anymore
root@xxxx:~# ifconfig usb0
usb0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500 metric 1
inet 192.168.7.1 netmask 255.255.255.0 broadcast 192.168.7.255
ether 2e:40:4e:6a:3b:8c txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
root@xxxx:~# lsmod | grep g_ether
g_ether 16384 0
root@xxxx:~# ping -c 2 -w 3 192.168.7.3
PING 192.168.7.3 (192.168.7.3): 56 data bytes
--- 192.168.7.3 ping statistics ---
2 packets transmitted, 0 packets received, 100% packet loss
如果在最后一步(5.)之后,我再次切换到主机,它仍然可以正常工作,但小工具将不再工作。换句话说,小工具只有在重新启动后才能工作,而主机每次都可以工作。在切换到小工具之前,我尝试了不同的顺序。比如g_ether
先卸载,再切换角色。我还尝试g_serial
确认该问题与网络接口无关。正如我之前提到的,没有错误dmesg
,现在我不知道如何调试这个问题。
对正在发生的事情或如何调试它有什么想法吗?
答案1
使用相同的处理器,IP 块是奇皮代亚并确保设备树设置没有属性hnp-disable
并且srp-disable
存在。使用以下示例(取自 Linux 文档)。
&usbotg {
vbus-supply = <®_usb_otg_vbus>;
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_usbotg_var>;
...
otg-rev = <0x0200>;
adp-disable;
status = "okay";
};
配置小工具后,在主机和小工具之间进行更改。
更改为主机:
echo "host" > /sys/kernel/debug/ci_hdrc.0/role
echo "" > /sys/kernel/config/usb_gadget/g1/UDC
更改为小工具:
echo "gadget" > /sys/kernel/debug/ci_hdrc.0/role
ls /sys/class/udc > /sys/kernel/config/usb_gadget/g1/UDC