AM437x驱动移植篇4------小米随身wifi驱动移植(MT7601)

时间:2024-03-30 09:54:34

0.说明:

LINUX内核版本:4.14.79

平台:AM437x

内核源码中已默认支持MT7601。我们要做的只是make menuconfig配置一下即可

1.内核配置

make ARCH=arm CROSS_COMPILE=/opt/linaro/gcc-linaro-arm-linux-gnueabihf-4.7-2013.03-20130313_linux/bin/arm-linux-gnueabihf- menuconfig


Device Drivers  ---> 
    [*] Network device support  ---> 
        [*]   Wireless LAN  --->
            [*]   MediaTek devices
            <*>     MediaTek MT7601U (USB) support //(如果不能选择编译进内核,请查看其依赖并选择编译进内核)


通过help信息可看到其依赖:
/**********************/
  Depends on: NETDEVICES [=y] && WLAN [=y] && WLAN_VENDOR_MEDIATEK [=y] && MAC80211 [=y] && USB [=y] 


在本人配置过程中就遇到了MAC80211 没有选择编译进内核而配置失败的问题。

选择MAC80211 编译进内核:
[*] Networking support  ---> 
     -*-   Wireless  --->
         <*>   Generic IEEE 802.11 Networking Stack (mac80211)                                                                                                                                                    
         [*]   Minstrel                                                                                                                                                                                           
         [*]     Minstrel 802.11n support           

2.插入USB后获取ID

#lsusb 
Bus 003 Device 001: ID 1d6b:0002
Bus 001 Device 001: ID 1d6b:0002
Bus 001 Device 002: ID 12d1:15c1
Bus 004 Device 001: ID 1d6b:0003
Bus 002 Device 001: ID 1d6b:0003
Bus 003 Device 015: ID 2717:4106

得到ID为2717:4106

3.在源码中加入对此ID的支持

切换到wifi驱动源码主目录:

cd drivers/net/wireless/mediatek/

搜索DEVICE:

grep -r "USB_DEVICE" ./
./mt7601u/usb.c:        { USB_DEVICE(0x0b05, 0x17d3) },
./mt7601u/usb.c:        { USB_DEVICE(0x0e8d, 0x760a) },
./mt7601u/usb.c:        { USB_DEVICE(0x0e8d, 0x760b) },
./mt7601u/usb.c:        { USB_DEVICE(0x13d3, 0x3431) },
./mt7601u/usb.c:        { USB_DEVICE(0x13d3, 0x3434) },
./mt7601u/usb.c:        { USB_DEVICE(0x148f, 0x7601) },
./mt7601u/usb.c:        { USB_DEVICE(0x148f, 0x760a) },
./mt7601u/usb.c:        { USB_DEVICE(0x148f, 0x760b) },
./mt7601u/usb.c:        { USB_DEVICE(0x148f, 0x760c) },
./mt7601u/usb.c:        { USB_DEVICE(0x148f, 0x760d) },
./mt7601u/usb.c:        { USB_DEVICE(0x2001, 0x3d04) },
./mt7601u/usb.c:        { USB_DEVICE(0x2955, 0x0001) },
./mt7601u/usb.c:        { USB_DEVICE(0x2955, 0x1001) },
./mt7601u/usb.c:        { USB_DEVICE(0x2a5f, 0x1000) },
./mt7601u/usb.c:        { USB_DEVICE(0x7392, 0x7710) },

vim进入此文件

vi ./mt7601u/usb.c

添加ID

AM437x驱动移植篇4------小米随身wifi驱动移植(MT7601)

这样的话当插入设备时,内核便会识别到是小米wifi插入了

4.添加.bin文件

内核编译完成并用新内核启动后,插入USB:

AM437x驱动移植篇4------小米随身wifi驱动移植(MT7601)

提示加载mt7601u.bin失败。

上github搜索mt7601,并进入到/src/mcu/bin/目录下,可以看到我们想要的文件MT7601.bin

AM437x驱动移植篇4------小米随身wifi驱动移植(MT7601)

git clone下整个工程

git clone https://github.com/alfmel/mt7601.git

并将MT7601.bin重命名为mt7601u.bin

mv MT7601.bin mt7601u.bin

放到arm板上/lib/firmware目录下

 

此时再插入小米随身wifi:

AM437x驱动移植篇4------小米随身wifi驱动移植(MT7601)

可以看到成功识别到了usb wifi.

AM437x驱动移植篇4------小米随身wifi驱动移植(MT7601)

wlan0就是小米随身wifi

5.利用wpa_supplicant命令连接wifi

wpa参数配置:

vi /etc/wpa_supplicant.conf

添加/修改如下内容:

ctrl_interface=/var/run/wpa_supplicant
#ap_scan=1

network={
  ssid="name"
    psk="passwd"
}

ssid对应wifi名,psk对应密码

连接wifi

wpa_supplicant -Dnl80211 -iwlan0 -c/etc/wpa_supplicant.conf &

ifconfig查看状态

wlan0     Link encap:Ethernet  HWaddr FC:3D:93:B4:E9:9D  
          inet6 addr: fe80::fe3d:93ff:feb4:e99d/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:9387 errors:0 dropped:100 overruns:0 frame:0
          TX packets:16 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:603432 (589.2 KiB)  TX bytes:1687 (1.6 KiB)

可以看到现在并没有获取到IP

获取ip

[email protected]:/lib/firmware#udhcpc -i wlan0
udhcpc: started, v1.25.1
udhcpc: sending discover
udhcpc: sending select for 172.10.1.37
udhcpc: lease of 172.10.1.37 obtained, lease time 3600
deleting routers
adding dns 202.96.134.33
adding dns 202.96.128.86

大功告成!!!!

AM437x驱动移植篇4------小米随身wifi驱动移植(MT7601)