问题
新买的MediaTek wifi不识别
USB wifi接入ubuntu/linux 系统
lsusb
Bus 007 Device 005: ID 0e8d:2870 MediaTek Inc. – 存储设备
解决方法
1.更新与配置wifi驱动
1.开启kernel配置
cd kernel_source
搜索usb是否支持设备, 搜索 vendor id
grep --include=*.c --binary-files=without-match -rn 0e8d
net/wireless/mediatek/mt7601u/usb.c:16: { USB_DEVICE(0x0e8d, 0x760a) },
net/wireless/mediatek/mt7601u/usb.c:17: { USB_DEVICE(0x0e8d, 0x760b) },
net/wireless/mediatek/mt76/mt7615/usb.c:19: { USB_DEVICE_AND_INTERFACE_INFO(0x0e8d, 0x7663, 0xff, 0xff, 0xff) },
net/wireless/mediatek/mt76/mt76x2/usb.c:16: { USB_DEVICE(0x0e8d, 0x7612) }, /* Aukey USBAC1200 – Alfa AWUS036ACM
/
net/wireless/mediatek/mt76/mt76x2/usb.c:19: { USB_DEVICE(0x0e8d, 0x7632) }, /
HC-M7662BU1 */
找到内核配置
drivers/net/wireless/mediatek/mt76/mt76x2/Makefile
obj-$(CONFIG_MT76x2_COMMON) += mt76x2-common.o
make ARCH=arm64 CROSS_COMPILE=aarch64-linux- menuconfig
或
make ARCH=arm64 menuconfig
开启对应的MT76x2配置和依赖
最终kernel .config 配置
# wifi MT76x2
CONFIG_MT7601U=m
CONFIG_MT76_CORE=m
CONFIG_MT76_LEDS=y
CONFIG_MT76_USB=m
CONFIG_MT76x02_LIB=m
CONFIG_MT76x02_USB=m
CONFIG_MT76x0_COMMON=m
CONFIG_MT76x2_COMMON=m
CONFIG_MT76x2U=m
重新编译内核, 打包镜像, .ko模块
2.更新内核
我的开发板是 RK3588, 用官方工具更新boot.img即可更新内核.
小伙伴们使用自己平台的方法更新linux 内核.
3.更新.ko内核模块
进入rootfs文件
cd OK3588-ubuntu-fs/rootfs/lib/modules/5.10.66
确认生成.ko
find -name mt76x2-common.ko
./kernel/drivers/net/wireless/mediatek/mt76/mt76x2/mt76x2-common.ko
打包.ko模块
tar -zcf 5.10.66.tar.gz 5.10.66
拷贝到开发板 scp xxx xxx
解压与更新.ko模块到开发板
解压
tar -zxf 5.10.66.tar.gz
复制
sudo cp -rf 5.10.66/* /lib/modules/5.10.66
4.重启
reboot
2.usb_modeswitch 切换 wifi 模式
sudo apt-get install usb-modeswitch usb-modeswitch-data
sudo usb_modeswitch -K -W -v 0e8d -p 2870
查看切换wifi是否成功:
查看网卡
ip link
8: wlx90de80bd01d5: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN mode DORMANT group default qlen 1000
link/ether 90🇩🇪80:bd:01:d5 brd ff:ff:ff:ff:ff:ff
3.其它问题
1. /lib/firmware/缺失mt7662_rom_patch.bin
如果运行usb_modswitch 命令之后, 没有wifi网络设备.
查看内核日志
dmesg
Direct firmware load for mt7662_rom_patch.bin
解决方法:
sudo apt install linux-firmware
此处通过
apt-file search mt7622
搜索到对应的固件包
2.开机自动识别切换
参考文章:
带存储芯片的网卡在kali下切换芯片模式
sudo vim /lib/udev/rules.d/40-usb_modeswitch.rules
在 SUBSYSTEM!=“usb”, ACTION!=“add”, GOTO=”modeswitch_rules_end”这行下面添加
# COMFAST CF-WU782AC WiFi Dongle, TEROW ROW02FD WiFi Dongle, COMFAST CF-WU785AC WiFi Dongle
ATTR{idVendor}=="0e8d", ATTR{idProduct}=="2870", RUN+="usb_modeswitch '/%k'"
创建文件 /usr/share/usb_modeswitch/0e8d:2870
# COMFAST CF-WU782AC WiFi Dongle, TEROW ROW02FD WiFi Dongle, COMFAST CF-WU785AC WiFi Dongle
TargetVendor=0x0e8d
TargetProductList="7612"
StandardEject=1
注意事项:
1.默认安装
sudo apt install usb-modeswitch usb-modeswitch-data
之后
安装了如下文件:
/lib/udev/rules.d/40-usb_modeswitch.rules
/usr/share/usb_modeswitch/0e8d:2870
2.如果目录/usr/share/usb_modeswitch/ 没有配置文件0e8d:2870
尝试执行如下指令,解压配置包
cd /usr/share/usb_modeswitch/
sudo tar -zxf configPack.tar.gz
3.如果接在usb hub(usb扩展器), 概率无法工作, 尝试接入电脑或设备 usb口
解决过程看: 调试过程:usb hub上挂载wifi重启拔插无法切换为wifi设备
3.wifi网卡重命名wlan0 wlan1
获取网卡MAC:
ip link
sudo vim /etc/udev/rules.d/70-persistent-net.rules
# Realtek 8211CU Wifi AC 0bda:c811
SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="aa:bb:cc:dd:ee:ff", NAME="wlan0"
参考文章
linux下安装mt7612un无线网卡驱动
带存储芯片的网卡在kali下切换芯片模式
usb wifi网卡重命名
ubuntu 安装wifi firmware固件mt7662_rom_patch.bin方法
apt-get update
apt-get install apt-file
apt-file update
apt-file search bcrm/BCM2070
apt-file search mt7662_rom_patch.bin
调试过程: usb hub上挂载wifi 重启/拔插 识别为wifi设备
问题现象:
- ubuntu笔记本识别正常.
- 挂载到 开发板usb hub上无法识别.
1.ubuntu笔记本日志记录
kernel log
demsg
[ 777.367763] usbcore: registered new interface driver uas
[ 778.382785] scsi 4:0:0:0: CD-ROM MediaTek Flash autorun 0.01 PQ: 0 ANSI: 0 CCS
[ 778.384029] sr 4:0:0:0: [sr1] scsi3-mmc drive: 52x/52x cd/rw xa/form2 cdda tray
[ 778.387075] sr 4:0:0:0: Attached scsi CD-ROM sr1
[ 778.388317] sr 4:0:0:0: Attached scsi generic sg2 type 5
[ 778.470569] usb 1-2: USB disconnect, device number 5
[ 779.277846] usb 2-2: new SuperSpeed USB device number 2 using xhci_hcd
[ 779.299520] usb 2-2: New USB device found, idVendor=0e8d, idProduct=7612, bcdDevice= 1.00
[ 779.299536] usb 2-2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 779.299543] usb 2-2: Product: 802.11ac WLAN
[ 779.299548] usb 2-2: Manufacturer: MediaTek Inc.
[ 779.299553] usb 2-2: SerialNumber: 000000000
[ 779.474402] usb 2-2: reset SuperSpeed USB device number 2 using xhci_hcd
[ 779.496687] mt76x2u 2-2:1.0: ASIC revision: 76120044
[ 779.523690] mt76x2u 2-2:1.0: ROM patch build: 20141115060606a
[ 779.691777] mt76x2u 2-2:1.0: Firmware Version: 0.0.00
[ 779.691781] mt76x2u 2-2:1.0: Build: 1
[ 779.691783] mt76x2u 2-2:1.0: Build Time: 201507311614____
[ 780.441715] ieee80211 phy1: Selected rate control algorithm 'minstrel_ht'
[ 780.444473] usbcore: registered new interface driver mt76x2u
[ 780.471754] mt76x2u 2-2:1.0 wlx90de80bd01d8: renamed from wlan0
udev日志
udevadm monitor
枚举为存储设备log
UDEV [778.670819] change /devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.0/host4/target4:0:0/4:0:0:0/block/sr1 (block)
UDEV [778.676272] remove /devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.0/host4/target4:0:0/4:0:0:0/block/sr1 (block)
UDEV [778.681222] unbind /devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.0/host4/target4:0:0/4:0:0:0 (scsi)
UDEV [778.684952] remove /devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.0/host4/target4:0:0/4:0:0:0 (scsi)
UDEV [778.689100] remove /devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.0/host4/target4:0:0 (scsi)
UDEV [778.693104] remove /devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.0/host4 (scsi)
UDEV [778.698614] unbind /devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.0 (usb)
UDEV [778.704639] unbind /devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.0 (usb)
UDEV [778.709948] remove /devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.0 (usb)
UDEV [778.715230] unbind /devices/pci0000:00/0000:00:14.0/usb1/1-2 (usb)
UDEV [778.718229] remove /devices/pci0000:00/0000:00:14.0/usb1/1-2 (usb)
KERNEL[779.328854] add /devices/pci0000:00/0000:00:14.0/usb2/2-2 (usb)
KERNEL[779.331903] change /devices/pci0000:00/0000:00:14.0/usb2/2-2 (usb)
KERNEL[779.333695] add /devices/pci0000:00/0000:00:14.0/usb2/2-2/2-2:1.0 (usb)
KERNEL[779.333857] bind /devices/pci0000:00/0000:00:14.0/usb2/2-2 (usb)
UDEV [779.345804] add /devices/pci0000:00/0000:00:14.0/usb2/2-2 (usb)
UDEV [779.351280] change /devices/pci0000:00/0000:00:14.0/usb2/2-2 (usb)
切换为wifi 网卡设备log
KERNEL[779.362327] add /module/mt76 (module)
UDEV [779.363923] add /module/mt76 (module)
KERNEL[779.367101] add /module/mt76x02_lib (module)
UDEV [779.368298] add /module/mt76x02_lib (module)
KERNEL[779.369778] add /module/mt76_usb (module)
UDEV [779.371353] add /module/mt76_usb (module)
KERNEL[779.372157] add /module/mt76x02_usb (module)
UDEV [779.373418] add /module/mt76x02_usb (module)
KERNEL[779.374564] add /module/mt76x2_common (module)
UDEV [779.375853] add /module/mt76x2_common (module)
KERNEL[779.503171] change /devices/pci0000:00/0000:00:14.0/usb2/2-2 (usb)
KERNEL[779.524969] change /devices/pci0000:00/0000:00:14.0/usb2/2-2 (usb)
KERNEL[780.470537] add /devices/pci0000:00/0000:00:14.0/usb2/2-2/2-2:1.0/ieee80211/phy1 (ieee80211)
KERNEL[780.470847] add /devices/pci0000:00/0000:00:14.0/usb2/2-2/2-2:1.0/ieee80211/phy1/rfkill3 (rfkill)
KERNEL[780.471523] add /devices/pci0000:00/0000:00:14.0/usb2/2-2/2-2:1.0/net/wlan0 (net)
KERNEL[780.471613] add /devices/pci0000:00/0000:00:14.0/usb2/2-2/2-2:1.0/net/wlan0/queues/rx-0 (queues)
KERNEL[780.471697] add /devices/pci0000:00/0000:00:14.0/usb2/2-2/2-2:1.0/net/wlan0/queues/tx-0 (queues)
KERNEL[780.473216] bind /devices/pci0000:00/0000:00:14.0/usb2/2-2/2-2:1.0 (usb)
KERNEL[780.473325] add /bus/usb/drivers/mt76x2u (drivers)
KERNEL[780.473409] add /module/mt76x2u (module)
UDEV [780.474083] add /devices/pci0000:00/0000:00:14.0/usb2/2-2/2-2:1.0 (usb)
UDEV [780.477361] add /bus/usb/drivers/mt76x2u (drivers)
UDEV [780.477411] add /module/mt76x2u (module)
UDEV [780.483755] bind /devices/pci0000:00/0000:00:14.0/usb2/2-2 (usb)
UDEV [780.488979] change /devices/pci0000:00/0000:00:14.0/usb2/2-2 (usb)
UDEV [780.493698] change /devices/pci0000:00/0000:00:14.0/usb2/2-2 (usb)
UDEV [780.498640] add /devices/pci0000:00/0000:00:14.0/usb2/2-2/2-2:1.0/ieee80211/phy1 (ieee80211)
KERNEL[780.500456] move /devices/pci0000:00/0000:00:14.0/usb2/2-2/2-2:1.0/net/wlx90de80bd01d8 (net)
UDEV [780.501887] add /devices/pci0000:00/0000:00:14.0/usb2/2-2/2-2:1.0/ieee80211/phy1/rfkill3 (rfkill)
UDEV [780.550934] add /devices/pci0000:00/0000:00:14.0/usb2/2-2/2-2:1.0/net/wlx90de80bd01d8 (net)
UDEV [780.555318] add /devices/pci0000:00/0000:00:14.0/usb2/2-2/2-2:1.0/net/wlan0/queues/rx-0 (queues)
UDEV [780.556877] add /devices/pci0000:00/0000:00:14.0/usb2/2-2/2-2:1.0/net/wlan0/queues/tx-0 (queues)
UDEV [780.561500] bind /devices/pci0000:00/0000:00:14.0/usb2/2-2/2-2:1.0 (usb)
UDEV [780.961626] move /devices/pci0000:00/0000:00:14.0/usb2/2-2/2-2:1.0/net/wlx90de80bd01d8 (net)
syslog日志
7月 06 11:46:52 csj-pc systemd-udevd[63139]: 1-2: Running command “usb_modeswitch ‘/1-2’”
7月 06 11:46:52 csj-pc systemd-udevd[63139]: 1-2: Starting ‘usb_modeswitch ‘/1-2’’
7月 06 11:46:52 csj-pc systemd-udevd[63139]: Successfully forked off ‘(spawn)’ as PID 63145.
7月 06 11:46:52 csj-pc systemd[1]: Starting USB_ModeSwitch_1-2…
7月 06 11:46:52 csj-pc systemd-udevd[63139]: 1-2: Process ‘usb_modeswitch ‘/1-2’’ succeeded.
开发板
syslog日志
Jul 05 20:33:38 ubuntu systemd-udevd[8246]: 2-2.2: Running command “usb_modeswitch ‘/2-2.2’”
Jul 05 20:33:38 ubuntu systemd-udevd[8246]: 2-2.2: Starting ‘usb_modeswitch ‘/2-2.2’’
Jul 05 20:33:38 ubuntu systemd-udevd[8246]: Successfully forked off ‘(spawn)’ as PID 8261.
Jul 05 20:33:38 ubuntu systemd[1]: Starting USB_ModeSwitch_2-2.2…
Jul 05 20:33:38 ubuntu systemd-udevd[8246]: 2-2.2: Process ‘usb_modeswitch ‘/2-2.2’’ succeeded.Jul 05 20:33:38 ubuntu systemd[1]: usb_modeswitch@2-2.2.service: Main process exited, code=exited, status=1/FAILURE
Jul 05 20:33:38 ubuntu systemd[1]: usb_modeswitch@2-2.2.service: Failed with result ‘exit-code’.
log显示 开发板 执行usb-modeswitch失败.
2-2.2是 wifi挂载到usb hub上序号, 此处usb设备序号
2-2 是hub
2-2.2 是hub第2个usb口
解决方法1: 将wifi挂载到USB口
解决方法2: 添加自己的udev规则
示例:
900-self-wifi.rules
# MediaTek mt7662 wifi
SUBSYSTEM=="usb", ACTION=="add", ATTRS{idVendor}=="0e8d", ATTRS{idProduct}=="2870", RUN+="/etc/self/mt7662-0e8d-2870-udev.sh"
创建文件 /etc/self/mt7662-0e8d-2870-udev.sh
#!/bin/sh
sleep 5
usb_modeswitch -KW -v 0e8d -p 2870
sleep 5
usb_modeswitch -KW -v 0e8d -p 2870
sleep 5
usb_modeswitch -KW -v 0e8d -p 2870
echo 111 >> /home/forlinx/999.log
开启udev debug log
设置日志等级:
sudo udevadm control --log-priority=debug
查询udev service日志:
sudo journalctl -f
应该会看到如下日志:
900-self-wifi.rules
run /etc/self/mt7662-0e8d-2870-udev.sh
Jul 6 14:35:00 ok3588 kernel: [15776.260911] usb 7-1.3: USB disconnect, device number 12
Jul 6 14:35:01 ok3588 kernel: [15777.291872] usb 7-1.3: new high-speed USB device number 13 using xhci-hcd
Jul 6 14:35:01 ok3588 kernel: [15777.483604] usb 7-1.3: New USB device found, idVendor=0e8d, idProduct=7612, bcdDevice= 1.00
Jul 6 14:35:01 ok3588 kernel: [15777.483625] usb 7-1.3: New USB device strings: Mfr=1, Product=2, SerialNumber=3
Jul 6 14:35:01 ok3588 kernel: [15777.483637] usb 7-1.3: Product: 802.11ac WLAN
Jul 6 14:35:01 ok3588 kernel: [15777.483649] usb 7-1.3: Manufacturer: MediaTek Inc.
Jul 6 14:35:01 ok3588 kernel: [15777.483660] usb 7-1.3: SerialNumber: 000000000