嵌入式Linux 三星s5pv210 USB WIFI驱动的移植

2019-07-13 02:46发布

硬件平台:三星s5pv210开发板 操作系统:Linux3.0.8 WIFI:    rt5370 USB WIFI模块 交叉编译环境:arm-none-linux-gnueabi-gcc  4.5.1 调试步骤:
第一步:测试USB HOST接口 在menuconfig中将USB HOST设置为内核模式:  重新编译内核后启动开发板,插入U盘并挂载: mount  /dev/sda1  /tmp ls /tmp 可以看到U盘已经正常挂载,测试USB HOST OK!   第二步:网上下载USB驱动 ralink_sta_linux_v2.5.03.tar.bz2 拷备到Linux目录并解压: ralink_sta_linux_v2.5.03
第三步:进入ralink_sta_linux_v2.5.03目录,看到有一个README_STA_usb文件,里面介绍了如何加载该驱动: 1> $tar -xvzf DPB_RT2870_Linux_STA_x.x.x.x.tgz     go to "./DPB_RT2870_Linux_STA_x.x.x.x" directory.     2> In Makefile  set the "MODE = STA" in Makefile and chose the TARGET to Linux by   set "TARGET = LINUX"  define the linux kernel source include file path LINUX_SRC  modify to meet your need. 3> In os/linux/config.mk  define the GCC and LD of the target machine define the compiler flags CFLAGS modify to meet your need. ** Build for being controlled by NetworkManager or wpa_supplicant wext functions   Please set 'HAS_WPA_SUPPLICANT=y' and 'HAS_NATIVE_WPA_SUPPLICANT_SUPPORT=y'.    => #>cd wpa_supplicant-x.x    => #>./wpa_supplicant -Dwext -ira0 -c wpa_supplicant.conf -d ** Build for being controlled by WpaSupplicant with Ralink Driver   Please set 'HAS_WPA_SUPPLICANT=y' and 'HAS_NATIVE_WPA_SUPPLICANT_SUPPORT=n'.    => #>cd wpa_supplicant-0.5.7    => #>./wpa_supplicant -Dralink -ira0 -c wpa_supplicant.conf -d  4> $make # compile driver source code # To fix "error: too few arguments to function ˉiwe_stream_add_event"   => $patch -i os/linux/sta_ioctl.c.patch os/linux/sta_ioctl.c 5> $cp RTSTA.dat  /etc/Wireless/RT2870STA/RT2870STA.dat   修改该目录下的makefile文件,以下是修改部分 #PLATFORM = PC  PLATFORM = SMDK ifeq ($(PLATFORM),SMDK) LINUX_SRC = linux-3.0.8-FS210      加上绝对路径 CROSS_COMPILE = arm-none-linux-gnueabi-(没有配环境变量的,加上绝对路径) endif   第四步:按照README_STA_usb给出的提示,修改config.mk文件,以下是修改部分: # Support Wpa_Supplicant HAS_WPA_SUPPLICANT=y # Support Native WpaSupplicant for Network Maganger HAS_NATIVE_WPA_SUPPLICANT_SUPPORT=y CC := arm-none-linux-gnueabi-gcc(没有配环境变量的,加上绝对路径) LD := arm-none-linux-gnueabi-ld
#make         如果编译一切正常,将会在ralink_sta_linux_v2.5.03/os/linux目录下生成 rt5370sta.ko文件。
第五步:将USB WIFI模组插到开发板的USB HOST端口,将rt5370sta.ko文件复制到文件系统的目录下,重启开发板,进入文件系统后加载驱动:  [root@farsight /]#  insmod  rt5370sta.ko rtusb init rt2870 --->   === pAd = f5b01000, size = 513648 ===   <-- RTMPAllocTxRxRingMemory, Status=0 <-- RTMPAllocAdapterBlock, Status=0 usbcore: registered new interface driver rt2870   第六步:配置无线网卡 首先检测开发板的网络设备: [root@farsight /]# ifconfig -a 可以看到这时只有dummy0  eth0、lo、sit0 ra0五个网络信号,ra0设备,它就是无线网卡的相关信息。 [root@farsight /]# ifconfig -a dummy0    Link encap:Ethernet  HWaddr AE:46:04:2F:E9:12           BROADCAST NOARP  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:0           RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)   eth0      Link encap:Ethernet  HWaddr 00:09:C2:FF:EC:68           inet addr:192.168.1.126  Bcast:192.168.1.255  Mask:255.255.255.0           inet6 addr: fe80::209:c2ff:feff:ec68/64 Scope:Link           UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1           RX packets:4201 errors:0 dropped:0 overruns:0 frame:0           TX packets:1023 errors:0 dropped:0 overruns:0 carrier:0           collisions:0 txqueuelen:1000           RX bytes:3058783 (2.9 MiB)  TX bytes:249818 (243.9 KiB)           Interrupt:42 Base address:0x300   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)   ra0       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)   sit0      Link encap:IPv6-in-IPv4           NOARP  MTU:1480  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)   使用如下命令设置无线网卡的网络地址:  [root@farsight /]# ifconfig ra0 192.168.0.22
(Efuse for 3062/3562/3572) Size=0x2d [2d0-2fc] RTMP_TimerListAdd: add timer obj f5b48c98! RTMP_TimerListAdd: add timer obj f5b48cc8! RTMP_TimerListAdd: add timer obj f5b48cf8! RTMP_TimerListAdd: add timer obj f5b48c68! RTMP_TimerListAdd: add timer obj f5b48bd8! RTMP_TimerListAdd: add timer obj f5b48c08! RTMP_TimerListAdd: add timer obj f5b1380c! RTMP_TimerListAdd: add timer obj f5b02fd0! RTMP_TimerListAdd: add timer obj f5b03008! RTMP_TimerListAdd: add timer obj f5b138b0! RTMP_TimerListAdd: add timer obj f5b137ac! RTMP_TimerListAdd: add timer obj f5b1387c! -->RTUSBVenderReset <--RTUSBVenderReset Key1Str is Invalid key length(0) or Type(0) Key2Str is Invalid key length(0) or Type(0) Key3Str is Invalid key length(0) or Type(0) Key4Str is Invalid key length(0) or Type(0) 1. Phy Mode = 5 2. Phy Mode = 5 NVM is Efuse and its size =2d[2d0-2fc] phy mode> Error! The chip does not support 5G band 5! RTMPSetPhyMode: channel is out of range, use first channel=1 (Efuse for 3062/3562/3572) Size=0x2d [2d0-2fc] 3. Phy Mode = 9 AntCfgInit: primary/secondary ant 0/1 AsicSetRxAnt, switch to main antenna MCS Set = ff 00 00 00 01 <==== rt28xx_init, Status=0 0x1300 = 00064300 再使用ifconfig-a查看网络设备: ra0       Link encap:Ethernet  HWaddr 00:25:22:48:99:D0           inet addr:192.168.0.22 Bcast:192.168.0.255  Mask:255.255.255.0           inet6 addr: fe80::225:22ff:fe48:99d0/64 Scope:Link           UP BROADCAST RUNNING 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:146186 (142.7 KiB)  TX bytes:22400 (21.8 KiB)
第七步:下载并编译无线网络工具wireless_tools.29.tar.gz tar  zxf  wireless_tools.29.tar.gz cd  wireless_tools.29 修改makefile,修改部分如下: ## Compiler to use (modify this for cross compile). CC = arm-none-linux-gnueabi-gcc ## Other tools you need to modify for cross compile (static lib only). AR = arm-none-linux-gnueabi-ar RANLIB = arm-none-linux-gnueabi-ranlib 修改后make,成功后会在当前目录生成iwspy,iwpriv,iwlist以及iwconfig等文件。我们只需将这四个文件拷备到NFS文件系统的sbin目录,然后将当前目录的libiw.so.29库文件拷到NFS文件系统的lib目录,无线网络工具即安装完成。
第八步:查看无线网络: iwlist ra0 scanning 这时如果设备周边有无线信号,将会搜索出这些信号并打印出来,例如: [root@farsight /]# iwlist ra0 scannig iwlist: unknown command `scannig' (check 'iwlist --help'). [root@farsight /]# iwlist ra0 scanning ===>rt_ioctl_giwscan. 14(14) BSS returned, data->length = 2355 ra0       Scan completed :           Cell 01 - Address: 44:33:4C:90:B2:7C                     Protocol:802.11b/g/n                     ESSID:"yandakaoyan"                     Mode:Managed                     Frequency:2.412 GHz (Channel 1)                     Quality=78/100  Signal level=-59 dBm  Noise level=-92 dBm                     Encryption key:on                     Bit Rates:144 Mb/s                     IE: WPA Version 1                         Group Cipher : TKIP                         Pairwise Ciphers (2) : CCMP TKIP                         Authentication Suites (1) : PSK                     IE: IEEE 802.11i/WPA2 Version 1                         Group Cipher : TKIP                         Pairwise Ciphers (2) : CCMP TKIP                         Authentication Suites (1) : PSK           Cell 02 - Address: AC:72:89:81:1E:11                     Protocol:802.11g/n                     ESSID:"DubaWiFi-0000"                     Mode:Managed                     Frequency:2.462 GHz (Channel 11)                     Quality=83/100  Signal level=-57 dBm  Noise level=-92 dBm                     Encryption key:on                     Bit Rates:130 Mb/s                     IE: IEEE 802.11i/WPA2 Version 1                         Group Cipher : CCMP                         Pairwise Ciphers (1) : CCMP                         Authentication Suites (1) : PSK           Cell 03 - Address: 28:2C:B2:19:C3:12                     Protocol:802.11b/g/n                     ESSID:"TP-LINK_19C312"                     Mode:Managed                     Frequency:2.412 GHz (Channel 1)                     Quality=94/100  Signal level=-53 dBm  Noise level=-92 dBm                     Encryption key:on                     Bit Rates:54 Mb/s                     IE: WPA Version 1                         Group Cipher : CCMP                         Pairwise Ciphers (1) : CCMP                         Authentication Suites (1) : PSK                     IE: IEEE 802.11i/WPA2 Version 1                         Group Cipher : CCMP                         Pairwise Ciphers (1) : CCMP                         Authentication Suites (1) : PSK                     IE: Unknown: DD310050F204104A00011010440001021047001000000000000010000000282CB219C312103C0001011049000600372A000120
第九步:下载并解压wpa_supplicant需要的源码 tar xvfz wpa_supplicant-0.7.2.tar.gz tar xvfz wpa_supplicant-0.5.8.tar.gz tar zxvf openssl-0.9.8e.tar.gz
第十步:编译openssl库 将wpa_supplicant中的补丁拷贝到openssl中: cp  wpa_supplicant-0.7.2/patches/openssl-0.9.8e-tls-extensions.patch   openssl-0.9.8e/ 在ubuntu下建立openssl编译目标路径: $mkdir  /usr/local/ssl 修改openssl-0.9.8e目录下的makefile文件,修改内容如下: CC= arm-none-linux-gnueabi-gcc AR=ar $(ARFLAGS) r RANLIB= /usr/bin/ranlib INSTALLTOP=/usr/local/ssl OPENSSLDIR=/usr/local/ssl 然后编译openssl: Make Sudo make install 正常编译后,在/usr/local/ssl中将会出现ssl库。
第十一步:编译wpa_supplicant cd  wpa_supplicant-0.5.8 cp  defconfig  .config 在.config中添加如下代码: CC=arm-none-linux-gnueabi-gcc -L /usr/local/ssl/lib/ CFLAGS += -I/usr/local/ssl/include/ LIBS += -L/usr/local/ssl/lib/ 然后编译: make 正常情况下,将会在wpa_supplicant-0.5.8目录生成wpa_supplicant文件。将生成的文件拷备到文件系统的sbin目录
第十二步:建立配置文件wpa_supplicant.conf 在开发板文件系统的/etc目录下建立配置文件wpa_supplicant.conf,编辑内容如下: # WPA-PSK/TKIP ctrl_interface=/var/run/wpa_supplicant  network={   ssid="123"   scan_ssid=1   key_mgmt=WPA-EAP WPA-PSK IEEE8021X NONE   pairwise=TKIP CCMP  group=CCMP TKIP WEP104 WEP40  psk="12345678" } 注意上面ssid要和无线路由的名字相同,psk为无线路由的密码。无线路由使用WPA或WPA2的加密方式。 在文件系统建立无线网卡运行目录: mkdir –p /var/run/wpa_supplicant   第十三步:在文件系统/var/run/wpa_supplicant执行 wpa_supplicant  -Dwext  -ira0  -c  /etc/wpa_supplicant.conf  -dd  & 这时PING路由的IP: [root@farsight ]#ping 192.168.0.1 ping 192.168.0.1 PING 192.168.0.1 (192.168.0.1): 56 data bytes 64 bytes from 192.168.0.1: seq=0 ttl=128 time=534.173 ms 64 bytes from 192.168.0.1: seq=1 ttl=128 time=140.572 ms 64 bytes from 192.168.0.1: seq=2 ttl=128 time=146.390 ms 64 bytes from 192.168.0.1: seq=3 ttl=128 time=26.408 ms 64 bytes from 192.168.0.1: seq=4 ttl=128 time=84.615 ms   --- 192.168.0.1 ping statistics --- 8 packets transmitted, 8 packets received, 0% packet loss round-trip min/avg/max = 1.889/147.518/534.173 ms   可见,已经能够PING通路由了。