硬件:飞凌嵌入式S3C2440,RT3070
软件:VM虚拟机中的Ubuntu 14.04 LTS
Linux-3.0
RT3070.tar.bz2 (驱动)
wireless_tools.29.tar.gz(软件)
wpa_supplicant-0.6.10.tar.gz(软件)
openssl-0.9.8e.tar.gz(库)
下载连接:
链接: http://pan.baidu.com/s/1hqD4X96 密码: n4ii
首先配置内核:
[*] Networking support --->
[*] Wireless --->
<*> cfg80211 - wireless configuration API
[*] Wireless extensions sysfs files
<*> Generic IEEE 802.11 Networking Stack(mac80211)
Device Drivers --->
[*] Network device support --->
[*] Wireless LAN --->
<*> IEEE 802.11 for Host AP (Prism2/2.5/3 andWEP/TKIP/CCMP)
[*] Support downloading firmware images withHost AP driver
[*] Support for non-volatile firmwaredownload
<M> Ralink driver support --->
<M> Ralink rt27xx/rt28xx/rt30xx (USB) support
解压RT3070的驱动:
zhou@zhoupc:~$ tar -xjf RT3070.tar.bz2
zhou@zhoupc:~$ cd RT3070
zhou@zhoupc:~/RT3070$
修改os/linux下的conf.mk文件
zhou@zhoupc:~/RT3070$ vimos/linux/config.mk
# Support Wpa_Supplicant
HAS_WPA_SUPPLICANT=y
# Support Native WpaSupplicant for NetworkMaganger
HAS_NATIVE_WPA_SUPPLICANT_SUPPORT=y
再修改Makefile:
ifeq ($(CHIPSET),)
CHIPSET = 3070
Endif
将平台改为SMDK,同时注释掉PC
#PLATFORM = RALINK_2880
#PLATFORM = RALINK_3052
PLATFORM = SMDK
#PLATFORM = RMI
#PLATFORM = RMI_64
#PLATFORM: Target platform
#PLATFORM = PC
#PLATFORM = 5VT
修改linux源代码目录以及交叉编译器目录:
ifeq ($(PLATFORM),SMDK)
LINUX_SRC =/home/zhou/fl2440/kernel/linux-3.0withDM9KudaRTC
CROSS_COMPILE = /opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-
Endif
然后 make,此时会报错
/home/zhou/RT3070/os/linux/../../chips/rtmp_chip.c:In function 'RtmpChipOpsHook':
/home/zhou/RT3070/os/linux/../../chips/rtmp_chip.c:470:4:error: implicit declaration of function 'RT33xx_Init'
make[2]: ***[/home/zhou/RT3070/os/linux/../../chips/rtmp_chip.o] 错误 1
make[1]: ***[_module_/home/zhou/RT3070/os/linux] 错误 2
make[1]:正在离开目录`/home/zhou/fl2440/kernel/linux-3.0withDM9KudaRTC'
make: *** [LINUX] 错误 2
此时修改chips/rtmp_chip.c文件:
定位到470行左右:
if (IS_RT3390(pAd))
;//RT33xx_Init(pAd);
Else
出现
make[1]:正在离开目录`/home/zhou/fl2440/kernel/linux-3.0withDM9KudaRTC'
cp -f/home/zhou/RT3070/os/linux/rt3070sta.ko /tftpboot
cp: 无法创建普通文件"/tftpboot":权限不够
make: *** [LINUX] 错误 1
其实已经编译成功,因为我下载的源码其他人有改过。此时os/linux 下出现了rt3070sta.ko,文件较大,我们可以用交叉编译器中的arm-linux-strip将其缩小:
/opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-strip-S rt3070sta.ko
将rt3070sta.ko以及驱动文件夹根目录下的RT2870STA.dat下载到开发板上。
将RT2870STA.dat放到/etc/Wireless/RT2870STA/ 下,如果没有该路径则创建。
因为我的文件系统中 /etc/Wireless/做了一个软连接到 /apps/Wireless 所以我可以放在/apps//Wireless/RT2870STA/中
这时就可以加载驱动了
/apps >: insmod rt3070sta.ko
rtusb init rt2870 --->
=== pAd = c4f22000, size = 509944 ===
<-- RTMPAllocTxRxRingMemory, Status=0
<-- RTMPAllocAdapterBlock, Status=0
usbcore: registered new interface driverrt2870
ifconfig –a可以查看网卡信息
ra0 Link encap:Ethernet HWaddr00: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)
可以看到网卡名为ra0,我们将他启动
/apps >: ifconfig ra0 up
(Efuse for 3062/3562/3572) Size=0x2d[2d0-2fc]
RTMP_TimerListAdd: add timer obj c4f698d8!
RTMP_TimerListAdd: add timer obj c4f69908!
RTMP_TimerListAdd: add timer obj c4f69938!
RTMP_TimerListAdd: add timer obj c4f698a8!
RTMP_TimerListAdd: add timer obj c4f69818!
RTMP_TimerListAdd: add timer obj c4f69848!
RTMP_TimerListAdd: add timer obj c4f3444c!
RTMP_TimerListAdd: add timer obj c4f23c4c!
RTMP_TimerListAdd: add timer obj c4f23c84!
RTMP_TimerListAdd: add timer obj c4f344f0!
RTMP_TimerListAdd: add timer obj c4f343ec!
RTMP_TimerListAdd: add timer obj c4f344bc!
-->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 notsupport 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
MCS Set = ff 00 00 00 01
<==== rt28xx_init, Status=0
0x1300 = 00064300
虽然此时我们的RT3070已经启动了,但是没有相应的软件可以让我们搜索网络以及连接网络。所以,我们还需要移植wpa_supplicant和wireless_tools这两个软件。前者是为了连接有密码的wifi,后者是为了扫描周围有什么wifi,如果你已经知道要连入的wifi名称,也可以不要后面那个软件。
开始移植wireless_tools:
zhou@zhoupc:~$ tar -xzfwireless_tools.29.tar.gz
zhou@zhoupc:~$ cd wireless_tools.29/
修改Makefile:
ifndef PREFIX
PREFIX = /usr/local
Endif
这里的PREFIX其实可改可不改,因为我们只用make,可以不用make insall。
修改交叉编译工具:
## Compiler to use (modify this for crosscompile).
CC =/opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-gcc
## Other tools you need to modify for crosscompile (static lib only).
AR =/opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-ar
RANLIB =/opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-ranlib
Make
此时在根目录下产生了iwconfig iwevent iwpriv iwspy iwlist libiw.so.29
将libiw.so.29放到开发板的/lib/目录下。其他五个可执行文件可以放到/usr/bin或者/usr/sbin/下,记得chmod 777给予可执行权限。
我们可以使用iwlist ra0 scan来扫描网络,扫描信息示例:
===>rt_ioctl_giwscan. 7(7) BSS returned,data->length = 1296
ra0 Scan completed :
Cell 01 - Address: C8:3A:35:11:4C:38
Protocol:802.11b/g/n
ESSID:""
Mode:Managed
Frequency:2.412 GHz(Channel 1)
Quality=18/100 Signal level=-83 dBm Noise level=-78 dBm
Encryption key:on
Bit Rates:300 Mb/s
IE: WPA Version 1
Group Cipher : CCMP
Pairwise Ciphers (1) :CCMP
Authentication Suites(1) : PSK
Cell 02 - Address: 80:71:7A:42:2C:D4
Protocol:802.11b/g/n
ESSID:"HG532e-LZ"
Mode:Managed
Frequency:2.427 GHz(Channel 4)
Quality=18/100 Signal level=-83 dBm Noise level=-78 dBm
Encryption key:on
Bit Rates:270 Mb/s
IE: IEEE 802.11i/WPA2Version 1
Group Cipher : CCMP
Pairwise Ciphers (1) :CCMP
Authentication Suites(1) : PSK
IE: Unknown:DD310050F204104A000110104400010210470010BC329E001DD811B2860180717A422CD4103C0001011049000600372A000120
移植wpa_supplicant:
我们还需要openssl,将两者解压
zhou@zhoupc:~$ tar -xzfwpa_supplicant-0.6.10.tar.gz
zhou@zhoupc:~$ tar -xzfopenssl-0.9.8e.tar.gz
将补丁复制到openssl中:
cp wpa_supplicant-0.6.10/patches/openssl-0.9.8e-tls-extensions.patchopenssl-0.9.8e/
cd openssl-0.9.8e/
创建openssl的安装目录,如:
mkdir /usr/local/ssl
修改makefile:
INSTALLTOP=/usr/local/ssl
# Do not edit this manually. Use Configure--openssldir=DIR do change this!
OPENSSLDIR=/usr/local/ssl
CC=/opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-gcc
CFLAG= -O
DEPFLAG= -DOPENSSL_NO_CAMELLIA-DOPENSSL_NO_GMP -DOPENSSL_NO_MDC2 -DOPENSSL_NO_RC5 -DOPENSSL_NO_RFC3779
PEX_LIBS=
EX_LIBS=
EXE_EXT=
ARFLAGS=
AR=/opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-ar$(ARFLAGS) r
RANLIB=/opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-ranlib
Make
Sudo Make install
此时已经安装sll库
进入wpa_supplicant-0.6.10/wpa_supplicant
修改makefile:
#ifndef CC
CC=/opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-gcc
#endif
一定要注释掉ifndef和endif这两行
修改配置文件
cp defconfig .config
vim .config
# Uncomment following two lines and fix thepaths if you have installed OpenSSL
# or GnuTLS in non-default location
CFLAGS += -I/usr/local/ssl/include
LIBS += -L/usr/local/ssl/lib
Make
此时根目录下出现wpa_supplicant和wpa_supplicant.conf。前者为可执行文件,后者为配置文件。将前者放入开发板bin或sbin中给予可执行权限,后者可放在任何地方,如/etc/中,我是在/apps/中。
那我们要怎么连接wifi呢?打开conf配置文件,找到类似如下的文本段:
ctrl_interface=/var/run/wpa_supplicant
network={
ssid="idart-wlan311"
scan_ssid=1
key_mgmt=WPA-EAP WPA-PSK IEEE8021X NONE
pairwise=TKIP CCMP
group=CCMP TKIP WEP104 WEP40
psk="XXXXXXXX"
}
期中ssid为wifi名称,psk为密码。配置文件中有很多这样的示例,保留期中一段即可,其他的请务必删除掉。ctrl_interface=/var/run/wpa_supplicant
这一行务必保留,不要修改。
我们来尝试连接我的wifi “zhoupc”:
/apps >: wpa_supplicant-B -ira0 -c /apps/wpa_supplicant.conf –Dwext
/apps >: ===>rt_ioctl_giwscan. 8(8)BSS returned, data->length = 1486
==>rt_ioctl_siwfreq::SIOCSIWFREQ(Channel=11)
RTMP_TimerListAdd: add timer obj c4f98064!
/apps >: iwconfig ra0
ra0 Ralink STA ESSID:"zhoupc" Nickname:"RT2870STA"
Mode:Managed Frequency=2.462GHz Access Point: F4:EE:14:33:A5:DA
Bit Rate=135 Mb/s
RTS thr:off Fragment thr:off
Encryption key:A8EB-96D1-137E-8F7F-E0AF-1FC0-3F80-6516 Security mode:open
Link Quality=100/100 Signallevel:-50 dBm Noise level:-50 dBm
Rx invalid nwid:0 Rx invalidcrypt:0 Rx invalid frag:0
Tx excessive retries:0 Invalidmisc:0 Missed beacon:0
我们可以看到已经连接成功。
设置IP地址以及掩码
ifconfig ra0 192.168.1.110 netmask255.255.255.0
为了测试wifi,先关闭有线网
Ifconfig eth0 down
添加默认网关
route add default gw 192.168.1.1
我们先尝试ping同局域网中的计算机
/apps >: ping 192.168.1.102
PING 192.168.1.102 (192.168.1.102): 56 databytes
64 bytes from 192.168.1.102: seq=0 ttl=128time=1.542 ms
64 bytes from 192.168.1.102: seq=1 ttl=128time=1.506 ms
64 bytes from 192.168.1.102: seq=2 ttl=128time=1.490 ms
64 bytes from 192.168.1.102: seq=3 ttl=128time=2.496 ms
64 bytes from 192.168.1.102: seq=4 ttl=128time=1.535 ms
--- 192.168.1.102 ping statistics ---
5 packets transmitted, 5 packets received,0% packet loss
round-trip min/avg/max = 1.490/1.713/2.496ms
再试试外网ip:
/apps >: ping 114.114.114.114
PING 114.114.114.114 (114.114.114.114): 56data bytes
64 bytes from 114.114.114.114: seq=0 ttl=77time=80.945 ms
64 bytes from 114.114.114.114: seq=1 ttl=61time=80.760 ms
64 bytes from 114.114.114.114: seq=2 ttl=71time=80.798 ms
64 bytes from 114.114.114.114: seq=3 ttl=68time=81.695 ms
64 bytes from 114.114.114.114: seq=4 ttl=69time=87.431 ms
--- 114.114.114.114 ping statistics ---
5 packets transmitted, 5 packets received,0% packet loss
round-trip min/avg/max =80.760/82.325/87.431 ms
已经成功了连接外网