硬件平臺:飛思卡爾MX258開發板linux
操做系統:Linux2.6.31網絡
WIFI: RT2860 USB WIFI模組less
交叉編譯環境:gcc version 4.1.2工具
調試步驟:oop
第一步:測試USB HOST接口測試
在menuconfig中將USB HOST設置爲內核模式:ui
從新編譯內核後啓動開發板,插入U盤並掛載:this
mount /dev/sda1 /tmp加密
ls /tmp操作系統
能夠看到U盤已經正常掛載,測試USB HOST OK!
第二步:網上下載雷凌最新的USB驅動,
2011_0107_RT3070_RT3370_Linux_STA_v2[1].5.0.1_DPO.tar.bz2
拷備到Linux目錄並解壓:
tar jxf 2011_0107_RT3070_RT3370_Linux_STA_v2[1].5.0.1_DPO.tar.bz2
因爲上面名字很長,能夠修改成簡短的名字:
mv 2011_0107_RT3070_RT3370_Linux_STA_v2[1].5.0.1_DPO RT3070_Linux_STA
第三步:進入RT3070_Linux_STA目錄,看到有一個README_STA_usb文件,裏面介紹瞭如何加載該驅動:
=======================================================================
Build Instructions:
====================
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 RT2870STA.dat /etc/Wireless/RT2870STA/RT2870STA.dat
6> load driver, go to "os/linux/" directory.
#[kernel 2.4]
# $/sbin/insmod rt2870sta.o
# $/sbin/ifconfig ra0 inet YOUR_IP up
#[kernel 2.6]
# $/sbin/insmod rt2870sta.ko
# $/sbin/ifconfig ra0 inet YOUR_IP up
7> unload driver
$/sbin/ifconfig ra0 down
$/sbin/rmmod rt2870sta
這裏go to "./DPB_RT2870_Linux_STA_x.x.x.x" directory.即咱們剛解壓的RT3070_Linux_STA目錄。修改該目錄下的makefile文件,如下只給出修改部分:
#PLATFORM = PC
PLATFORM = RALINK_2880
ifeq ($(PLATFORM), RALINK_2880)
LINUX_SRC = /home/lqm/share/G360/kernel_kfb
CROSS_COMPILE = /opt/freescale/usr/local/gcc-4.1.2-glibc-2.5-nptl-3/arm-none-linux-gnueabi/bin/arm-none-linux-gnueabi-
endif
ifeq ($(RT28xx_MODE),APSTA)
cp -f $(RT28xx_DIR)/os/linux/rt$(CHIPSET)apsta.ko /tftpboot
ifeq ($(OSABL),YES)
cp -f $(RT28xx_DIR)/os/linux/rtutil$(CHIPSET)apsta.ko /tftpboot
cp -f $(RT28xx_DIR)/os/linux/rtnet$(CHIPSET)apsta.ko /tftpboot
endif
else
cp -f $(RT28xx_DIR)/os/linux/rt$(CHIPSET)sta.ko /home/lqm/share/NFS/tmp
注意,雖然咱們使用的是2860模組,咱們這裏仍然能夠定義PLATFORM爲RALINK_2880,只要後面對應的編譯環境正確就能夠了。LINUX_SRC表示內核的目錄,CORSS_COMPILE爲交叉編譯環境,最末一行爲編譯完後將生成的KO文件複製到NFS文件系統的tmp目錄。
第四步:按照第三步README_STA_usb給出的提示,修改config.mk文件,這裏也只給出修改部分:
# Support Wpa_Supplicant
HAS_WPA_SUPPLICANT=y
# Support Native WpaSupplicant for Network Maganger
HAS_NATIVE_WPA_SUPPLICANT_SUPPORT=n
CC := /opt/freescale/usr/local/gcc-4.1.2-glibc-2.5-nptl-3/arm-none-linux-gnueabi/bin/arm-none-linux-gnueabi-gcc
LD := /opt/freescale/usr/local/gcc-4.1.2-glibc-2.5-nptl-3/arm-none-linux-gnueabi/bin/arm-none-linux-gnueabi-ld
ifeq ($(PLATFORM), RALINK_2880)
EXTRA_CFLAGS := -D__KERNEL__ -I$(LINUX_SRC)/include -I$(RT28xx_DIR)/include -Wall -Wstrict-prototypes -Wno-trigraphs -O2 -fno-strict-aliasing -fno-common -Uarm -fno-common -pipe -D__LINUX_ARM_ARCH__=5 -march=armv5te -msoft-float -Uarm -DMODULE -DMODVERSIONS -include $(LINUX_SRC)/include/config/modversions.h $(WFLAGS)
export EXTRA_CFLAGS
endif
注意,這裏CC爲交叉編譯環境,LD爲交叉編譯的連接。默認EXTRA_CFLAGS爲CFLAGS,這裏須要修改成EXTRA_CFLAGS,不然編譯時會提示以下錯誤:
scripts/Makefile.build:49: *** CFLAGS was changed in "/home/lqm/share/RT3070_Linux_STA/os/linux/Makefile". Fix it to use EXTRA_CFLAGS。 中止。
LINUX_ARM_ARCH必定要設置爲5,-march必定要設置得和CPU匹配,因爲這裏爲MX258,所以設置爲armv5te,不可設置爲armv5t或armv5,不然出現以下錯誤:
CC [M] /home/lqm/share/RT3070_Linux_STA/os/linux/../../os/linux/rt_main_dev.o
{standard input}: Assembler messages:
{standard input}:340: Error: selected processor does not support `pld [r5,#0]'
{standard input}:349: Error: selected processor does not support `pld [r5,#0]'
make[2]: *** [/home/lqm/share/RT3070_Linux_STA/os/linux/../../os/linux/rt_main_dev.o] 錯誤 1
make[1]: *** [_module_/home/lqm/share/RT3070_Linux_STA/os/linux] 錯誤 2
make[1]: Leaving directory `/home/lqm/share/G360/kernel_kfb'
make: *** [LINUX] 錯誤 2
[root@lqm RT3070_Linux_STA]#
第五步:make
若是編譯一切正常,將會在/RT3070_Linux_STA/os/linux目錄下生成rt3070sta.ko文件。
第六步:將USB WIFI模組插到開發板的USB HOST端口,將rt3070sta.ko文件複製到文件系統的/tmp目錄,重啓開發板,進入文件系統後加載驅動:
cd /tmp
insmod rt3070sta.ko
這時會提示以下信息:
root@freescale ~$ cd /tmp
root@freescale /tmp$ insmod rt3070sta.ko
rtusb init rt2870 --->
=== pAd = c49eb000, size = 509592 ===
<-- RTMPAllocTxRxRingMemory, Status=0
<-- RTMPAllocAdapterBlock, Status=0
usbcore: registered new interface driver rt2870
root@freescale /tmp$
第七步:配置無線網卡
首先檢測開發板的網絡設備:
ifconfig
能夠看到這時只有eth0和lo兩個網絡信號,使用以下命令設置無線網卡的網絡地址:
ifconfig ra0 192.168.1.5
打印信息以下:
root@freescale /tmp$ ifconfig ra0 192.168.1.5
(Efuse for 3062/3562/3572) Size=0x2d [2d0-2fc]
RTMP_TimerListAdd: add timer obj c4a32d88!
RTMP_TimerListAdd: add timer obj c4a32db4!
RTMP_TimerListAdd: add timer obj c4a32de0!
RTMP_TimerListAdd: add timer obj c4a32d5c!
RTMP_TimerListAdd: add timer obj c4a32cd8!
RTMP_TimerListAdd: add timer obj c4a32d04!
RTMP_TimerListAdd: add timer obj c49fd91c!
RTMP_TimerListAdd: add timer obj c49ece5c!
RTMP_TimerListAdd: add timer obj c49ece90!
RTMP_TimerListAdd: add timer obj c49fd9b4!
RTMP_TimerListAdd: add timer obj c49fd8c4!
RTMP_TimerListAdd: add timer obj c49fd984!
-->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
MCS Set = ff 00 00 00 01
<==== rt28xx_init, Status=0
0x1300 = 00064300
root@freescale /tmp$
再使用ifconfig查看網絡設備:
root@freescale /tmp$ ifconfig
eth0 Link encap:Ethernet HWaddr 00:04:9F:00:EB:33
inet addr:172.18.2.133 Bcast:172.18.255.255 Mask:255.255.0.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:3182 errors:0 dropped:0 overruns:0 frame:0
TX packets:1380 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:3079209 (2.9 MiB) TX bytes:227540 (222.2 KiB)
Base address:0xa000
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
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:E0:61:37:D0:10
inet addr:192.168.1.5 Bcast:192.168.1.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:631 errors:0 dropped:0 overruns:0 frame:0
TX packets:83 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:92470 (90.3 KiB) TX bytes:8736 (8.5 KiB)
root@freescale /tmp$
能夠看到這時多了一組ra0設備,它就是無線網卡的相關信息。
第八步:下載並編譯無線網絡工具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
這時若是設備周邊有無線信號,將會搜索出這些信號並打印出來,例如:
dBm
Encryption key:on
Bit Rates:54 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 23 - Address: 00:25:5E:1E:38:5A
Protocol:802.11b/g
ESSID:"ChinaNet-UWfq"
Mode:Managed
Frequency:2.412 GHz (Channel 1)
Quality=26/100 Signal level=-79 dBm Noise level=-74 dBm
Encryption key:on
Bit Rates:54 Mb/s
IE: WPA Version 1
Group Cipher : TKIP
Pairwise Ciphers (1) : TKIP
Authentication Suites (1) : PSK
IE: Unknown: DD0E0050F204104A0001101044000102
Cell 24 - Address: 00:25:5E:1D:2F:FF
Protocol:802.11b/g
ESSID:"ChinaNet-eSpK"
Mode:Managed
Frequency:2.437 GHz (Channel 6)
Quality=42/100 Signal level=-73 dBm Noise level=-75 dBm
Encryption key:on
Bit Rates:54 Mb/s
IE: WPA Version 1
Group Cipher : TKIP
Pairwise Ciphers (1) : TKIP
Authentication Suites (1) : PSK
IE: Unknown: DD0E0050F204104A0001101044000102
root@freescale /tmp$
第九步:下載並解壓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/
創建openssl編譯目標路徑:
mkdir /usr/local/ssl
修改openssl-0.9.8e目錄下的makefile文件,修改內容以下:
CC= arm-none-linux-gnueabi-gcc
AR= arm-none-linux-gnueabi-ar
RANLIB= arm-none-linux-gnueabi-ranlib
INSTALLTOP=/usr/local/ssl
OPENSSLDIR=/usr/local/ssl
而後編譯openssl:
make & 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="XGD-kjy"
scan_ssid=1
key_mgmt=WPA-EAP WPA-PSK IEEE8021X NONE
pairwise=TKIP CCMP
group=CCMP TKIP WEP104 WEP40
psk="xgdoko2008"
}
注意上面ssid要和無線路由的名字相同,psk爲無線路由的密碼。無線路由使用WPA或WPA2的加密方式。
在開發板終端創建無線網卡運行目錄:
mkdir –p /var/run/wpa_supplicant
第十三步:執行wpa_supplicant
wpa_supplicant -Dwext -ira0 -c /etc/wpa_supplicant.conf -dd &
這時PING路由的IP:
root@freescale /tmp$ ping 192.168.1.1
PING 192.168.1.1 (192.168.1.1): 56 data bytes
64 bytes from 192.168.1.1: seq=0 ttl=64 time=169.375 ms
64 bytes from 192.168.1.1: seq=1 ttl=64 time=16.678 ms
64 bytes from 192.168.1.1: seq=2 ttl=64 time=60.179 ms
--- 192.168.1.1 ping statistics ---
3 packets transmitted, 3 packets received, 0% packet loss
round-trip min/avg/max = 16.678/82.077/169.375 ms
root@freescale /tmp$
可見,已經可以PING通路由了。
from:http://blog.csdn.net/armeasy/article/details/6252389