上下文,我有一个 stm32mp135d odyssey 板,运行我自己的用 yocto 制作的 Linux 映像,并从 SD 卡启动。我插入了一个便宜的 ath9k wifi USB 加密狗,但遇到了一个令人讨厌的问题,即在拔下加密狗并重新插入之前,wifi 接口不会显示。
重新启动后,这里有一些输出可以帮助你们排除故障。
内核信息以防万一重要。
root@stm32mp1:~# uname -a
Linux stm32mp1 5.15.67 #1 SMP PREEMPT Fri Mar 15 01:01:46 UTC 2024 armv7l GNU/Linux
lsusb 输出。
root@stm32mp1:~# lsusb -v
Bus 002 Device 002: ID 040d:3801 VIA Technologies, Inc. VIA USB2.0 WLAN
Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 2.00
bDeviceClass 255 Vendor Specific Class
bDeviceSubClass 255 Vendor Specific Subclass
bDeviceProtocol 255 Vendor Specific Protocol
bMaxPacketSize0 64
idVendor 0x040d VIA Technologies, Inc.
idProduct 0x3801
bcdDevice 1.08
iManufacturer 16 VIA TECH
iProduct 32 VIA USB2.0 WLAN
iSerial 48 12345
bNumConfigurations 1
Configuration Descriptor:
bLength 9
bDescriptorType 2
wTotalLength 0x003c
bNumInterfaces 1
bConfigurationValue 1
iConfiguration 0
bmAttributes 0x80
(Bus Powered)
MaxPower 500mA
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 0
bNumEndpoints 6
bInterfaceClass 255 Vendor Specific Class
bInterfaceSubClass 0
bInterfaceProtocol 0
iInterface 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x01 EP 1 OUT
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0200 1x 512 bytes
bInterval 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x82 EP 2 IN
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0200 1x 512 bytes
bInterval 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x83 EP 3 IN
bmAttributes 3
Transfer Type Interrupt
Synch Type None
Usage Type Data
wMaxPacketSize 0x0040 1x 64 bytes
bInterval 1
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x04 EP 4 OUT
bmAttributes 3
Transfer Type Interrupt
Synch Type None
Usage Type Data
wMaxPacketSize 0x0040 1x 64 bytes
bInterval 1
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x05 EP 5 OUT
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0200 1x 512 bytes
bInterval 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x06 EP 6 OUT
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0200 1x 512 bytes
bInterval 0
Device Qualifier (for other device speed):
bLength 10
bDescriptorType 6
bcdUSB 2.00
bDeviceClass 255 Vendor Specific Class
bDeviceSubClass 255 Vendor Specific Subclass
bDeviceProtocol 255 Vendor Specific Protocol
bMaxPacketSize0 64
bNumConfigurations 1
Device Status: 0x0000
(Bus Powered)
界面不显示
root@stm32mp1:~# ip link show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: end0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DEFAULT group default qlen 1000
link/ether aa:ce:65:8a:8d:22 brd ff:ff:ff:ff:ff:ff
3: end1: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN mode DEFAULT group default qlen 1000
link/ether 62:7b:ce:1d:79:c4 brd ff:ff:ff:ff:ff:ff
4: usb0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc fq_codel state DOWN mode DEFAULT group default qlen 1000
link/ether 96:9d:05:79:2b:95 brd ff:ff:ff:ff:ff:ff
dmesg 的输出显示加载 ath9k 固件失败
root@stm32mp1:~# dmesg | grep -i "ath9k"
[ 0.351901] usbcore: registered new interface driver ath9k_htc
[ 4.369966] usb 2-1: ath9k_htc: Firmware ath9k_htc/htc_9271-1.4.0.fw requested
[ 4.387041] usb 2-1: Direct firmware load for ath9k_htc/htc_9271-1.4.0.fw failed with error -2
[ 4.401769] usb 2-1: ath9k_htc: Firmware htc_9271.fw requested
[ 4.421233] usb 2-1: ath9k_htc: Failed to get firmware htc_9271.fw
[ 4.427899] usb 2-1: ath9k_htc: USB layer deinitialized
后我拔下并重新插入模块,我在 dmesg 中得到以下信息
[ 467.033794] usb 2-1: ath9k_htc: Firmware ath9k_htc/htc_9271-1.4.0.fw requested
[ 467.334719] usb 2-1: ath9k_htc: Transferred FW: ath9k_htc/htc_9271-1.4.0.fw, size: 51008
[ 467.585338] ath9k_htc 2-1:1.0: ath9k_htc: HTC initialized with 33 credits
[ 467.854226] ath9k_htc 2-1:1.0: ath9k_htc: FW Version: 1.4
[ 467.858250] ath9k_htc 2-1:1.0: FW RMW support: On
[ 468.025043] ath9k_htc 2-1:1.0 wlu1: renamed from wlan0
并且出现界面
5: wlu1: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
link/ether 00:12:7b:21:6f:39 brd ff:ff:ff:ff:ff:ff
此时,我还可以在接口上使用 hostapd 和 wpa_supplicant ,没有任何问题。它只需要在开始时手动重置。鉴于这是一个嵌入式设备,我不想在我的最终产品中这样做。根据 dmesg 输出,它看起来可能在启动过程中过早地尝试加载 ath9k 固件并失败,所以我要么需要一种方法来延迟,要么只是在 Linux 启动后自动重置它。我有一个模糊的想法,也许我可以用 udev 规则做一些事情来完成这个任务?但我不确定。
我尝试过的事情
- 以编程方式重置 USB 设备,如图所示这里
modprobe ath9k
modprobe ath9k_htc
答案1
自己回答这个问题。
我的解决方案是在启动完成后重置USB设备,对我有用的方法如图所示这邮政。
那里的用户这样做
sudo sh -c "echo 0 > /sys/bus/usb/devices/1-4.6/authorized"
sudo sh -c "echo 1 > /sys/bus/usb/devices/1-4.6/authorized"
可以使用此脚本(或任何其他方法)找到要重置的 wifi 设备的 /sys 路径
for X in /sys/bus/usb/devices/*; do
echo "$X"
cat "$X/idVendor" 2>/dev/null
cat "$X/idProduct" 2>/dev/null
echo
done
可能有更优雅的解决方案,但就我的目的而言,这是可行的。