admin管理员组文章数量:1570452
以下内容源于朱有鹏嵌入式课程的学习与整理,如有侵权请告知删除。
一、移植前的准备工作
1、搭建开发环境
(1)虚拟机运行着ubuntu14.04系统。
(2)X210开发板运行着linux内核镜像、QT4.8文件系统镜像。相关的镜像文件在开发板光盘资料的X210V3S_B\linux\QT4.8目录中,账号与密码分别是是root、123456。在SCRT中完全登陆系统后,使用“uname -r”查询可知linux内核镜像的版本是2.6.35.7,这个和虚拟机中用来编译无线网卡驱动的内核源码树的版本一致。
x210v3 login: root
Password:
[root@x210v3 ~]# uname -r
2.6.35.7
[root@x210v3 ~]#
(3)虚拟机中有内核源码树,这个内核源码树主要用来编译无线网卡驱动源码,它的版本必须与板载系统的内核版本一致,否则编译后的驱动程序在开发版上运行时,会遇到不匹配的问题。我们可以从内核源码包顶层的Makefile文件中直接得知内核版本信息,比如这里用到的内核源码树位于/home/xjh/iot/embedded_basic/kernel/x210_kernel中,其顶层Makefile文件开头有如下代码:
1 VERSION = 2
2 PATCHLEVEL = 6
3 SUBLEVEL = 35
4 EXTRAVERSION = .7
5 NAME = Yokohama
#这表明内核版本是2.6.35.7,和板载系统的内核版本一致。
(4)搭建好NFS服务器,制作好文件夹形式的rootfs。
2、下载与解压无线网卡驱动源码包
(1)驱动源码压缩包下载地址:DPO_MT7601U_LinuxSTA_3.0.0.4_20130913.tar.bz2。
(2)将驱动源码压缩包解压至/home/xjh/iot/embedded_basic/x210_usb-wifi目录。
通过对比博文第五季2:STA模式USB-WIFI网卡移植与测试的无线网卡驱动的内容,可以看出两者是完全一样的。
#本课程的无线网卡驱动内容
root@ubuntu:/home/xjh/iot/embedded_basic/x210_usb-wifi# ls
DPO_MT7601U_LinuxSTA_3.0.0.4_20130913 DPO_MT7601U_LinuxSTA_3.0.0.4_20130913.tar.bz2
root@ubuntu:/home/xjh/iot/embedded_basic/x210_usb-wifi# cd DPO_MT7601U_LinuxSTA_3.0.0.4_20130913
root@ubuntu:/home/xjh/iot/embedded_basic/x210_usb-wifi/DPO_MT7601U_LinuxSTA_3.0.0.4_20130913# ls
ate common iwpriv_usage.txt Makefile mgmt phy README_STA_usb RT2870STA.dat sta_ate_iwpriv_usage.txt
chips include mac mcu os rate_ctrl RT2870STACard.dat sta tools
root@ubuntu:/home/xjh/iot/embedded_basic/x210_usb-wifi/DPO_MT7601U_LinuxSTA_3.0.0.4_20130913#
#第五季2:STA模式USB-WIFI网卡移植与测试
root@ubuntu:/home/xjh/iot/hisi_development/usb-wifi/MT7601_driver# ls
ap sta
root@ubuntu:/home/xjh/iot/hisi_development/usb-wifi/MT7601_driver# cd sta/
root@ubuntu:/home/xjh/iot/hisi_development/usb-wifi/MT7601_driver/sta# ls
DPO_MT7601U_LinuxSTA_3.0.0.4_20130913 openssl-0.9.8za wpa_supplicant-2.5
DPO_MT7601U_LinuxSTA_3.0.0.4_20130913.tar.bz2 openssl-0.9.8za.tar.gz wpa_supplicant-2.5.tar.gz
root@ubuntu:/home/xjh/iot/hisi_development/usb-wifi/MT7601_driver/sta# cd DPO_MT7601U_LinuxSTA_3.0.0.4_20130913
root@ubuntu:/home/xjh/iot/hisi_development/usb-wifi/MT7601_driver/sta/DPO_MT7601U_LinuxSTA_3.0.0.4_20130913# ls
ate common iwpriv_usage.txt Makefile mgmt phy README_STA_usb RT2870STA.dat sta_ate_iwpriv_usage.txt
chips include mac mcu os rate_ctrl RT2870STACard.dat sta tools
root@ubuntu:/home/xjh/iot/hisi_development/usb-wifi/MT7601_driver/sta/DPO_MT7601U_LinuxSTA_3.0.0.4_20130913#
3、确认无线网卡的硬件信息
在板载系统上使用lsusb命令查看无线网卡的“VID:PID”,分别是厂商ID和产品ID。
Welcome to Buildroot
x210v3 login: root
Password:
[root@x210v3 ~]# lsusb #还没有插入USB-WIFI时显示的内容
Bus 001 Device 001: ID 1d6b:0002
Bus 001 Device 002: ID 05e3:0608
[root@x210v3 ~]# [ 259.729000] usb 1-1.1: new high speed USB device using s5p-ehci and address 3 #插入usb-wifi时显示的内容
[ 259.833929] usb 1-1.1: New USB device found, idVendor=148f, idProduct=7601
[ 259.840211] usb 1-1.1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 259.847456] usb 1-1.1: Product: 802.11 n WLAN
[ 259.852241] usb 1-1.1: Manufacturer: MediaTek
[ 259.856163] usb 1-1.1: SerialNumber: 1.0
[root@x210v3 ~]# lsusb
Bus 001 Device 001: ID 1d6b:0002
Bus 001 Device 002: ID 05e3:0608
Bus 001 Device 003: ID 148f:7601
[root@x210v3 ~]#
二、编译驱动源码得到mt7601Usta.ko文件
以下的所有操作,主要为了得到无线网卡的驱动,即mt7601Usta.ko文件。
1、确认USB的VID和PID
在x210_usb-wifi/DPO_MT7601U_LinuxSTA_3.0.0.4_20130913/common/rtusb_dev_id.c文件中的rtusb_dev_id[ ]数组里,列出了该驱动所支持的USB的VID和PID。如果USB-WIFI网卡的USB的VID和PID不在该数组中,移植时要添加。
USB_DEVICE_ID rtusb_dev_id[] = {
#ifdef RT6570
{USB_DEVICE(0x148f,0x6570)}, /* Ralink 6570 */
#endif /* RT6570 */
{USB_DEVICE(0x148f, 0x7650)}, /* MT7650 */
#ifdef MT7601U
{USB_DEVICE(0x148f,0x6370)}, /* Ralink 6370 */
{USB_DEVICE(0x148f,0x7601)}, /* MT 6370 */ // 我们的模块就是这个
#endif /* MT7601U */
{ }/* Terminating entry */
};
2、修改Makefile文件
修改x210_usb-wifi/DPO_MT7601U_LinuxSTA_3.0.0.4_20130913/Makefile文件。
(1)注释掉之前的PLATFORM,然后在67行添加“PLATFORM = SMDK”。
//注释掉以下这些代码
#PLATFORM: Target platform
//省略部分代码
#PLATFORM = BLPMP
#PLATFORM = MT85XX
#PLATFORM = MT53XX
#PLATFORM = NXP_TV550
#PLATFORM = MVL5
#PLATFORM = RALINK_3352
#PLATFORM = UBICOM_IPX8
#PLATFORM = INTELP6
#PLATFORM = MSTARTV
//添加下面代码
PLATFORM = SMDK
(2)根据实际情况设置内核源码树的路径、交叉编译工具链路径。如果交叉编译工具链没有export出来的话就要添加绝对路径。
ifeq ($(PLATFORM),SMDK)
#LINUX_SRC = /home/bhushan/itcenter/may28/linux-2.6-samsung
#CROSS_COMPILE = /usr/local/arm/4.2.2-eabi/usr/bin/arm-linux-
LINUX_SRC = /home/xjh/iot/embedded_basic/kernel/x210_kernel
#实测得知,就算把交叉编译工具链export出来,写成下面这样也会提示找不到arm-linux-gcc,很奇怪。
#CROSS_COMPILE = arm-linux-
#要写成下面两种方式
#CROSS_COMPILE = /usr/local/arm/arm-2009q3/bin/arm-none-linux-gnueabi-
CROSS_COMPILE = /usr/local/arm/arm-2009q3/bin/arm-linux-
endif
3、修改无线网卡的名字(可选操作)
(1)有线网卡的名字一般叫做eth0、eth1…ethn,无线网卡的名字一般叫做ra0、ra1…ran(或者wlan0、wlan1…wlann)。
(2)修改x210_usb-wifi/DPO_MT7601U_LinuxSTA_3.0.0.4_20130913/include/rtmp_def.h文件,如下所示,即可把无线网卡的名字改为“wlan”。
1600 //#ifdef ANDROID_SUPPORT
1601 #define INF_MAIN_DEV_NAME "wlan"
1602 #define INF_MBSSID_DEV_NAME "wlan"
1603 //#else
1604 //#define INF_MAIN_DEV_NAME "ra"
1605 //#define INF_MBSSID_DEV_NAME "ra"
1606 //#endif /* ANDROID_SUPPORT */
4、添加wpa_supplicant支持
wpa_supplicant用于支持WEP、WPA/WPA2和WAPI无线协议和加密认证,这里省略其介绍。
(1)在x210_usb-wifi/DPO_MT7601U_LinuxSTA_3.0.0.4_20130913/os/linux/config.mk文件中,搜索“HAS_WPA_SUPPLICANT”,确保“HAS_WPA_SUPPLICANT=y”。
24 # Support Wpa_Supplicant
25 # i.e. wpa_supplicant -Dralink
26 HAS_WPA_SUPPLICANT=y
27
28
29 # Support Native WpaSupplicant for Network Maganger
30 # i.e. wpa_supplicant -Dwext
31 HAS_NATIVE_WPA_SUPPLICANT_SUPPORT=y
(2)继续搜索“SMDK”,大概在1089行处添加内容。
#因为有相关代码如下,所以修改1090行内容
# 300 ifeq ($(HAS_WPA_SUPPLICANT),y)
# 301 WFLAGS += -DWPA_SUPPLICANT_SUPPORT
# 302 ifeq ($(HAS_NATIVE_WPA_SUPPLICANT_SUPPORT),y)
# 303 WFLAGS += -DNATIVE_WPA_SUPPLICANT_SUPPORT
# 304 endif
# 305 endif
1089 ifeq ($(PLATFORM),SMDK)#修改与添加内容
1090 EXTRA_CFLAGS := $(WFLAGS)
1091 endif
1092
1093 ifeq ($(PLATFORM),CAVM_OCTEON)
1094 EXTRA_CFLAGS := $(WFLAGS) -mabi=64 $(WFLAGS)
1095 export CFLAGS
1096 endif
5、编译驱动源码得到mt7601Usta.ko文件
(1)在x210_usb-wifi/DPO_MT7601U_LinuxSTA_3.0.0.4_20130913/下执行“make clen”,然后执行“make”,将在该目录下的os/linux/目录中生成mt7601Usta.ko文件。
执行make时出现错误提示如下:
/bin/sh: arm-linux-gcc: command not found make[2]: *** [/home/xjh/iot/embedded_basic/x210_usb-wifi/DPO_MT7601U_LinuxSTA_3.0.0.4_20130913/os/linux/../../os/linux/rt_profile.o] Error 127 make[1]: *** [_module_/home/xjh/iot/embedded_basic/x210_usb-wifi/DPO_MT7601U_LinuxSTA_3.0.0.4_20130913/os/linux] Error 2 make[1]: Leaving directory `/home/xjh/iot/embedded_basic/kernel/x210_kernel' make: *** [LINUX] Error 2 xjh@ubuntu:~/iot/embedded_basic/x210_usb-wifi/DPO_MT7601U_LinuxSTA_3.0.0.4_20130913$
这是因为我忘记把交叉编译工具链导出到PATH了。
#下面的PATH没有/usr/local/arm/arm-2009q3/bin这个项目,因此编译报错。 xjh@ubuntu:~/iot/embedded_basic/x210_usb-wifi/DPO_MT7601U_LinuxSTA_3.0.0.4_20130913$ echo $PATH /opt/hisi-linux/x86-arm/arm-hisiv300-linux/target/bin:/opt/hisi-linux/x86-arm/arm-hisiv300-linux/target/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games xjh@ubuntu:~/iot/embedded_basic/x210_usb-wifi/DPO_MT7601U_LinuxSTA_3.0.0.4_20130913$
因此我参考博客linux环境变量设置方法,采用永久性修改方式更新PATH这个环境变量。但修改之后执行sudo make时还是提示错误找不到arm-linux-gcc。尝试修改CROSS_COMPILE这个变量的写法,发现写成“CROSS_COMPILE = arm-linux-”时会报错,而写成下面两者之一就不会报错,这是为啥?我明明已经把交叉编译工具链导出到PATH中。
root@ubuntu:/home/xjh/iot/embedded_basic/x210_usb-wifi/DPO_MT7601U_LinuxSTA_3.0.0.4_20130913/os/linux# ls mt*
mt7601Usta.ko mt7601Usta.mod.c mt7601Usta.mod.o mt7601Usta.o
#使用“modinfo mt7601Usta.ko”命令查看驱动信息。
root@ubuntu:/home/xjh/iot/embedded_basic/x210_usb-wifi/DPO_MT7601U_LinuxSTA_3.0.0.4_20130913/os/linux# modinfo mt7601Usta.ko
filename: /home/xjh/iot/embedded_basic/x210_usb-wifi/DPO_MT7601U_LinuxSTA_3.0.0.4_20130913/os/linux/mt7601Usta.ko
version: 3.0.0.3
description: RT2870 Wireless Lan Linux Driver
author: Paul Lin <paul_lin@ralinktech>
license: GPL
srcversion: B2632BD2D7AD40A63B72D9E
alias: usb:v148Fp760Bd*dc*dsc*dp*ic*isc*ip*
alias: usb:v148Fp7601d*dc*dsc*dp*ic*isc*ip*
alias: usb:v148Fp6370d*dc*dsc*dp*ic*isc*ip*
alias: usb:v148Fp7650d*dc*dsc*dp*ic*isc*ip*
depends:
vermagic: 2.6.35.7 preempt mod_unload ARMv7
parm: mac:rt28xx: wireless mac addr (charp)
root@ubuntu:/home/xjh/iot/embedded_basic/x210_usb-wifi/DPO_MT7601U_LinuxSTA_3.0.0.4_20130913/os/linux#
为了方便使用,将mt7601Usta.ko文件复制到根文件系统/iot/embedded_basic/rootfs/rootfs_xjh目录下。
三、在Linux+QT系统中移植无线网卡
1、安装无线网卡驱动mt7601Usta.ko文件
(1)首先将上面生成的mt7601Usta.ko文件复制到板载系统的/usr/xjh_usb-wifi目录中,具体操作如下:
a、先启动开发板进入系统(账号密码是root、123456);
b、利用“ifconfig eth0 up”开启有线网卡,用“ifconfig eth0 192.168.1.11”配置有线网卡的IP地址;
c、在SCRT中利用下面命令将mt7601Usta.ko文件所在的虚拟机目录挂载到板载系统的/mnt目录;
mount -t nfs -o nolock 192.168.1.141:/home/xjh/iot/embedded_basic/rootfs/rootfs_xjh /mnt
d、在板载系统创建/usr/xjh_usb-wifi目录,并将mt7601Usta.ko文件复制到该目录下。
(2)然后将无线网卡插入X210开发板的任意USB插槽。
# 插进第一个USB插槽时的输出
[root@x210v3 ~]#
[root@x210v3 ~]# [ 425.611753] usb 1-1.1: new high speed USB device using s5p-ehci and address 4
[ 425.716551] usb 1-1.1: New USB device found, idVendor=148f, idProduct=7601
[ 425.722827] usb 1-1.1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 425.730077] usb 1-1.1: Product: 802.11 n WLAN
[ 425.734381] usb 1-1.1: Manufacturer: MediaTek
[ 425.738685] usb 1-1.1: SerialNumber: 1.0
# 拔掉usb-wifi网卡时的输出
[root@x210v3 ~]# [ 564.425135] usb 1-1.1: USB disconnect, address 4
(3)然后安装无线网卡驱动,即在/usr/xjh_usb-wifi目录下执行“insmod mt7601Usta.ko”。
[root@x210v3 xjh_usb-wifi]# ls
mt7601Usta.ko
[root@x210v3 xjh_usb-wifi]# insmod mt7601Usta.ko
[ 589.033836] rtusb init rt2870 --->
[ 589.036208] ===>rt2870_probe()!
[ 589.040985] --> RTMPAllocAdapterBlock
[ 589.044569]
[ 589.044572]
#省略部分内容
[ 589.215602] Allocate net device ops success!
[ 589.219828] The name of the new wlan interface is wlan0...
[ 589.225298] RtmpOSNetDevAttach()--->
[ 589.232064] <---RtmpOSNetDevAttach(), ret=0
[ 589.235286] <===rt2870_probe()!
[ 589.238079] usbcore: registered new interface driver rt2870
[root@x210v3 xjh_usb-wifi]#
(4)此时使用“ifconfig -a”查看,可以得知无线网卡wlan0的一些信息。
[root@x210v3 xjh_usb-wifi]# ifconfig -a
eth0 Link encap:Ethernet HWaddr 00:09:C0:FF:EC:48
inet addr:192.168.1.11 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::209:c0ff:feff:ec48/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:9603 errors:0 dropped:0 overruns:0 frame:0
TX packets:5241 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:14523906 (13.8 MiB) TX bytes:367990 (359.3 KiB)
Interrupt:42 Base address:0x4300
# 省略部分代码
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
#省略部分代码
#无线网卡对应的“设备文件”wlan0
wlan0 Link encap:Ethernet HWaddr 00:00:00:00:00:00
BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
2、开启无线网卡并设置IP地址
(1)首先使用命令“ifconfig wlan0 up”开启无线网卡。
此时会报错,提示错误信息如下:
[ 389.564686] --->RTUSBCancelPendingBulkInIRP [ 389.567999] Bulk In Failed. Status=-2, BIIdx=0x0, BIRIdx=0x0, actual_length= 0x0 [ 389.574884] CmdThread : CMDTHREAD_RESET_BULK_IN === > [ 389.580419] unlink cmd rsp urb [ 389.587734] <---RTUSBCancelPendingBulkInIRP [ 389.590575] <---MlmeThread [ 389.600986] CMDTHREAD_RESET_BULK_IN: Cannot do bulk in because flags(0x1080042) on ! [ 389.607868] CmdThread : CMDTHREAD_RESET_BULK_IN <=== [ 389.612781] <---RTUSBCmdThread [ 389.615341] <---RtmpTimerQThread [ 389.653298] !!! rt28xx init fail !!! [ 389.655948] rt28xx_open return fail! ifconfig: SIOCSIFFLAGS: Operation not permitted
这是因为板载系统没有/etc/Wireless/RT2870STA/RT2870STA.dat文件。该文件位于无线网卡驱动源码…/DPO_MT7601U_LinuxSTA_3.0.0.4_20130913/目录下。我们首先把这个文件拷贝到…/rootfs_xjh目录中以方便挂载使用,然后放进板载系统的/etc/Wireless/RT2870STA/目录中(这个目录要自己先创建)。
[root@x210v3 /]# mkdir -p /etc/Wireless/RT2870STA [root@x210v3 /]# cd /etc/Wireless/RT2870STA/ [root@x210v3 RT2870STA]# cp /mnt/RT2870STA.dat ./ [root@x210v3 xjh_usb-wifi]# ifconfig wlan0 up # 省略部分输出 [ 1492.081350] ==> DMAIdle, GloCfg=0x40000050 [ 1492.085317] Driver auto reconnect to last OID_802_11_SSID setting - 11n-AP, len - 6 [ 1492.093366] CntlOidSsidProc():CNTL - 0 BSS of 0 BSS match the desire RTMPDrvOpen(2):Check if PDMA is idle! [ 1492.101944] (6)SSID - 11n-AP [ 1492.105507] CNTL - All roaming failed, restore to channel 1, Total BSS[00] [ 1492.111625] ==> DMAIdle, GloCfg=0x40000050
(2)接着设置无线网卡的IP地址。
通过(选中WiFi图标右键打开)查看windows主机的无线网络信息,可知其连接的无线路由器的地址为192.168.31.1。
SSID: Xiaomi_803_2.4G
协议: Wi-Fi 4 (802.11n)
安全类型: WPA2-个人
制造商: Intel Corporation
描述: Intel(R) Wi-Fi 6 AX201 160MHz
驱动程序版本: 22.10.0.7
网络频带: 2.4 GHz
网络通道: 1
链接速度(接收/传输): 300/270 (Mbps)
本地链接 IPv6 地址: fe80::203b:ded2:6d8e:ce4b%11
IPv4 地址: 192.168.31.196 #……………………………………………………………………………………………………笔记本的IP地址
IPv4 DNS 服务器: 101.198.198.198 (未加密) 192.168.31.1 (未加密)#……………无线路由器的IP地址
物理地址(MAC): 34-2E-B7-04-4D-4F
于是我们执行命令“ifconfig wlan0 192.168.31.211”,只要将无线网卡的IP地址设置成和无线路由器IP地址同一网段即可,然后使用“ifconfig”命令查看wlan0是否启动。
[root@x210v3 ~]# ifconfig wlan0 192.168.31.211
#省略部分输出
[root@x210v3 ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:09:C0:FF:EC:48
inet6 addr: fe80::209:c0ff:feff:ec48/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:113 errors:0 dropped:0 overruns:0 frame:0
TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:18325 (17.8 KiB) TX bytes:1112 (1.0 KiB)
Interrupt:42 Base address:0x4300
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
wlan0 Link encap:Ethernet HWaddr 1C:BF:CE:2C:B2:5E
inet addr:192.168.31.211 Bcast:192.168.31.255 Mask:255.255.255.0
inet6 addr: fe80::1ebf:ceff:fe2c:b25e/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:2194 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:635361 (620.4 KiB) TX bytes:0 (0.0 B)
[root@x210v3 ~]#
3、使用wpa_supplicant工具将无线网卡接入网络
经过上面的操作,无线网卡wlan0已经启动并且配置有IP地址,就等待着接入无线路由器。此时我们可以使用 wpa_supplicant 工具将无线网卡wlan0接入网络。wpa_supplicant 工具主要用于管理无线网络,它已经集成到busybox中,因此可以直接使用。
[root@x210v3 xjh_usb-wifi]# find / -name "wpa_supplicant"
/usr/sbin/wpa_supplicant
[root@x210v3 xjh_usb-wifi]#
(1)再次确定板载系统/etc/Wireless/RT2870STA/RT2870STA.dat文件要存在。
(2)在板载系统中创建并编辑/etc/wpa_supplicant.conf文件(注意删掉注释)。
ctrl_interface=/var/run/wpa_supplicant
network={
ssid="Xiaomi_803_2.4G" # 当前我房间的无线路由器的网络名字
scan_ssid=1
key_mgmt=WPA-EAP WPA-PSK IEEE8021X NONE # 加密方式
pairwise=TKIP CCMP
group=CCMP TKIP WEP104 WEP40
psk="xiecai1314" # 路由器的密码
}
(3)使用命令“wpa_supplicant -Dwext -iwlan0 -c/etc/wpa_supplicant.conf -dd &”,将无线网卡接入连接无线网络。
[root@x210v3 xjh_usb-wifi]# wpa_supplicant -Dwext -iwlan0 -c/etc/wpa_supplicant.conf -dd &
#省略部分输出
EAPOL: SUPP_BE entering state IDLE
EAPOL authentication completed - result=SUCCESS
RTM_NEWLINK: operstate=1 ifi_flags=0x11043 ([UP][RUNNING][LOWER_UP])
RTM_NEWLINK, IFLA_IFNAME: Interface 'wlan0' added
WEXT: if_removed already cleared - ignore event
SYNC - AP changed N OperaionMode to 0
EAPOL: startWhen --> 0
EAPOL: disable timer tick
MT7601AsicTemperatureCompensation::Change to TEMPERATURE_MODE_HIGH
SYNC - AP changed N OperaionMode to 3
SYNC - AP changed B/G protection to 0
SYNC - AP changed N OperaionMode to 0
SYNC - AP changed N OperaionMode to 1
SYNC - AP changed B/G protection to 1
#这是动态的输出,需要按下回车继续下一步
(4)使用命令“wpa_cli -i wlan0 status”查看连接状态。
[root@x210v3 xjh_usb-wifi]# wpa_cli -i wlan0 status
RX ctrl_iface - hexdump_ascii(len=6):
53 54 41 54 55 53 STATUS
wlan0: Control interface command 'STATUS'
bssid=28:93:7d:25:a5:bd
ssid=XJH-ChinaNet-2.4G
id=0
mode=station
pairwise_cipher=CCMP
group_cipher=TKIP
key_mgmt=WPA2-PSK
wpa_state=COMPLETED
ip_address=192.168.1.211
address=1c:bf:ce:2c:b2:5e
[root@x210v3 xjh_usb-wifi]#
4、ping通路由器与外网的测试
(1)注意先使用“ifconfig eth0 down”关掉eth0,否则开发板默认使用eth0而非wlan0。
(2)经过上面操作之后,开发板可以ping通路由器(ping 192.168.31.1),但是因为还没有设置网关,所以不能ping通外部网络(比如ping 8.8.8.8)。我们可以通过在命令行输入下面命令来设置网关信息。
route add default gw 192.168.31.1 dev wlan0
(3)设置网关之后,因为还没有设置DNS,因此不能ping www.baidu等域名。我们可以在/etc/resolv.conf文件中配置DNS,即创建此文件并添加“nameserver 192.168.31.1”。注意这里的IP是无线路由器的IP。
[root@x210v3 xjh_usb-wifi]# ping www.baidu
PING www.baidu (14.215.177.38): 56 data bytes
64 bytes from 14.215.177.38: seq=0 ttl=56 time=19.485 ms
64 bytes from 14.215.177.38: seq=1 ttl=56 time=7.584 ms
64 bytes from 14.215.177.38: seq=2 ttl=56 time=7.942 ms
64 bytes from 14.215.177.38: seq=3 ttl=56 time=8.450 ms
--- www.baidu ping statistics ---
4 packets transmitted, 4 packets received, 0% packet loss
round-trip min/avg/max = 7.584/10.865/19.485 ms
[root@x210v3 xjh_usb-wifi]#
5、在interface文件中配置静态IP或动态IP(可选操作)
之前都是通过手动设置IP地址,其实也可以修改板载系统的/etc/network/interfaces文件来配置静态或者动态IP地址。设置静态IP的修改如下,其实就是替代手工配置时的ifconfig分配IP地址、route添加网关这两步。简单起见,这里直接删除有线网卡eth0的配置,保留无线网卡wlan0的配置。
auto lo
iface lo inet loopback
#auto eth0
#iface eth0 inet static
#address 192.168.1.11
#netmask 255.255.255.0
#gateway 192.168.1.1
auto wlan0
iface wlan0 inet static
address 192.168.31.211
netmask 255.255.255.0
gateway 192.168.31.1
6、设置开发板开机自动连接路由器
这里是前面内容的总结,可以忽略前面1~4的操作,完成第5点后直接进行下面操作。开发板开机自动连接路由器,这个功能可以通过修改板载系统的/etc/init.d/rcS文件来实现。
(1)rcS文件所在目录及内容如下,可知它会遍历执行/etc/init.d目录下S??*的文件。
[root@x210v3 init.d]# pwd
/etc/init.d
[root@x210v3 init.d]# ls
S01logging* S20urandom* S50sshd* rcK*
S10mdev* S40network* S99qttest* rcS*
[root@x210v3 init.d]#
#!/bin/sh
# Start all init scripts in /etc/init.d
# executing them in numerical order.
#
for i in /etc/init.d/S??* ;do
# Ignore dangling symlinks (if any).
[ ! -f "$i" ] && continue
case "$i" in
*.sh)
# Source shell script for speed.
(
trap - INT QUIT TSTP
set start
. $i
)
;;
*)
# No sh extension, so fork subprocess.
$i start
;;
esac
done
(2)于是在板载系统/etc/init.d/目录下创建S41WIFI文件并添加以下内容,然后使用“chmod 777 S41WIFI”命令修改该文件权限。
insmod /usr/xjh_usb-wifi/mt7601Usta.ko
ifconfig wlan0 up
#是否要加下面这行代码?不加则ifconfig时wlan没有IP地址,为啥/etc/network/interfaces文件不起效
#ifconfig wlan0 192.168.31.211
wpa_supplicant -Dwext -iwlan0 -c/etc/wpa_supplicant.conf -dd &
wpa_cli -i wlan0 status
#是否要加下面这句代码?按理不用加也行。
#ifconfig wlan0 up
#是否要加下面这句代码?/etc/network/interfaces文件设置的网关不起效,那在这里设置就好。
#route add default gw 192.168.31.1 dev wlan0
(3)在板载系统下执行“reboot”重启系统,完全启动后使用“ifconfig”查看,可见wlan0分配的IP地址和interfaces文件配置的一致,而且可以ping通外网“ 8.8.8.8 ”,但不能ping域名,这是因为之前的DNS配置文件/etc/resolv.conf文件重启后会消失。
Welcome to Buildroot
x210v3 login: root
Password:
[root@x210v3 ~]# ifconfig
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
wlan0 Link encap:Ethernet HWaddr 1C:BF:CE:2C:B2:5E
inet addr:192.168.31.211 Bcast:0.0.0.0 Mask:255.255.255.0
inet6 addr: fe80::1ebf:ceff:fe2c:b25e/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:892 errors:0 dropped:0 overruns:0 frame:0
TX packets:32 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:304603 (297.4 KiB) TX bytes:2980 (2.9 KiB)
[root@x210v3 ~]# ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8): 56 data bytes
64 bytes from 8.8.8.8: seq=0 ttl=116 time=15.673 ms
64 bytes from 8.8.8.8: seq=1 ttl=116 time=25.335 ms
64 bytes from 8.8.8.8: seq=2 ttl=116 time=22.043 ms
--- 8.8.8.8 ping statistics ---
4 packets transmitted, 3 packets received, 25% packet loss
round-trip min/avg/max = 15.673/21.017/25.335 ms
[root@x210v3 ~]# ping www.baidu
ping: bad address 'www.baidu'
[root@x210v3 ~]#
四、在自己定制的rootfs中移植网卡
1、确认自制的rootfs正常工作
(1)在板载系统中删除上节的/etc/init.d/S41WIFI文件,并修改/etc/network/interfaces文件如下,然后重启开发板。
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 192.168.1.141
netmask 255.255.255.0
gateway 192.168.1.1
(2)在uboot控制台依次输入下面指令,修改环境变量bootargs和bootcmd并保存。
setenv bootargs "root=/dev/nfs nfsroot=192.168.1.141:/home/xjh/iot/embedded_basic/rootfs/rootfs_xjh ip=192.168.1.88:192.168.1.141:192.168.1.1:255.255.255.0::eth0:off init=/linuxrc console=ttySAC2,115200"
set bootcmd "tftp 30008000 zImage;bootm 30008000"
save
原来的环境变量bootargs和bootcmd的内容如下:
setenv bootargs "console=ttySAC2,115200 root=/dev/mmcblk0p2 rw init=/linuxrc rootfstype=ext3"
setenv bootcmd "movi read kernel 30008000; movi read rootfs 30B00000 300000; bootm 30008000 30B00000"
busybox交叉编译
(2)启动后直接nfs方式挂载文件夹形式的rootfs,测试ok后再做成镜像烧录
(3)挂载参数
2、确认需要的移植的工具集
(1)iwconfig工具集:需要另外移植,不是busybox中的
(2)dhcp工具集:是busybox中集成的,确认busybox的menuconfig中配置支持了这个
(3)wpa_supplicant工具集:需要另外移植,不是busybox中的
3、交叉编译iwconfig
(1)源码下载
(2)配置
(3)交叉编译
(4)部署安装
(5)测试
4、交叉编译wpa_supplicant
(1)下载wpa_supplicant源码并配置编译。参考http://blog.csdn/hktkfly6/article/details/48949863
(2)下载配套版本的openssl并配置编译。
(3)去掉配置NL相关的选项省去移植libnl。参考:http://wwwblogs/helloworldtoyou/p/6145995.htm
5、在nfs中测试wpa_supplicant使用
6、制作ext2镜像并刷机测试
制作ext2格式的根文件系统镜像_天糊土的博客-CSDN博客_ext2 文件系统制作
版权声明:本文标题:将USB-WiFi网卡移植到X210开发板 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.elefans.com/dongtai/1725149482a1009687.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论