在這裏,TQ2416系列----wifi模塊rt3070的arm+linux移植

文章屬於轉載:http://blog.chinaunix.net/uid-28572323-id-3482376.html

軟硬件平臺:

宿主機:fedora10 vmware虛擬機

目標版:tiny6410linux2.6.38

交叉編譯工具:arm-linux- 4.5.1

網卡:Ralink3070模塊

步驟:

1、編譯驅動的預操作:編譯arm版本的內核源碼。

tiny6410的光碟中獲取內核源碼,此內核源碼已經經過友善之臂的移植,可以直接編譯移植入tiny6410中。

cp linux-2.6.38-20110718.tar.gz /usr/src/kernels/

cd /usr/src/kernels

tar -zxvf linux-2.6.38-20110718.tar.gz

cd linux-2.6.38

cp config_mini6410_n43 .config

make menuconfig

進入內核配置界面,內核配置中需要做的修改如下:

[*] 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 and WEP/TKIP/CCMP)

                     [*]     Support downloading firmware images with Host AP driver

                     [*]       Support for non-volatile firmware download

                     <M>   Ralink driver support  --->

                            <M>   Ralink rt27xx/rt28xx/rt30xx (USB) support

然後make,編譯通過後會在arch/arm/boot/目錄下生成可燒寫入開發板的zImage內核鏡像。

2、編譯rt3070模塊的驅動

在雷凌的官網下載linux版本的rt3070驅動2011_0719_RT3070_RT3370_RT5370_RT5372_Linux_STA_V2.5.0.3_DPO.bz2,解壓後的目錄名稱太長,所以可以對其做修改方便使用,然後進入到目錄中

tar –jxf 2011_0719_RT3070_RT3370_RT5370_RT5372_Linux_STA_V2.5.0.3_DPO.bz2

mv 2011_0719_RT3070_RT3370_RT5370_RT5372_Linux_STA_V2.5.0.3_DPO rt3070

cd rt3070

目錄中的README_STA_usb文件介紹了編譯和加載驅動的一些信息。需要對os/linux/目錄下的conf.mk文件進行修改,這裏只貼出要修改的部分:

vim os/linux/config.mk

# Support Wpa_Supplicant

HAS_WPA_SUPPLICANT=y

# Support Native WpaSupplicant for Network Maganger

HAS_NATIVE_WPA_SUPPLICANT_SUPPORT=y

Makefile也要進行修改,芯片類型改爲3070,默認的PLATFORMPC,那麼將後面的ifeq($(PLATFORM),PC)下的內核源碼路徑指定爲上述的交叉編譯過的內核源碼目錄,交叉編譯工具指定爲arm-linux-,當然之前應該把交叉工具鏈安裝好,這裏不再詳述。

vim Makefile

ifeq ($(CHIPSET),)
CHIPSET = 3070
endif

……

ifeq ($(PLATFORM),PC)

# Linux 2.6

LINUX_SRC = /usr/src/kernels/linux-2.6.38

# Linux 2.4 Change to your local setting

#LINUX_SRC = /usr/src/linux-2.4

LINUX_SRC_MODULE = /lib/modules/$(shell uname -r)/kernel/drivers/net/wireless/

CROSS_COMPILE = /usr/local/FriendlyARM/toolschain/4.5.1/bin/arm-linux-

endif

然後如果直接make,會報如下錯誤:

/home/cabbage/Desktop/rt3070/os/linux/../../chips/rtmp_chip.c: In function 'RtmpChipOpsHook':

/home/cabbage/Desktop/rt3070/os/linux/../../chips/rtmp_chip.c:470: error: implicit declaration of function 'RT33xx_Init'

make[2]: *** [/home/cabbage/Desktop/rt3070/os/linux/../../chips/rtmp_chip.o] Error 1

make[1]: *** [_module_/home/cabbage/Desktop/rt3070/os/linux] Error 2

make[1]: Leaving directory `/usr/src/kernels/linux-2.6.38'

make: *** [LINUX] Error 2

在網上查到似乎是因爲改變了CHIPSET所導致的錯誤。修改chips/目錄下的rtmp_chip.c文件,定位到470行,修改後如下:

#ifdef RT30xx

        if (IS_RT30xx(pAd))

        {

                if (IS_RT3390(pAd))

                     ;//RT33xx_Init(pAd);

                else

                        RT30xx_Init(pAd);

        }

#endif /* RT30xx */

然後再make,編譯通過後會在os/linux/下生成rt3070sta.ko,這就是模塊的驅動。 但是這裏我出現了一個問題,查看rt3070sta.ko這個文件的大小,居然達到了12m,這是不合理的,原因應該是包含了大量調試信息,用arm-linux-strip可將它的大小裁剪爲750k左右。

#arm-linux-strip -S rt3070sta.ko

其中-S參數是必須的,否則在加載驅動的時候會報找不到版本信息的錯誤。

 

3、燒寫內核和加載驅動

將之前編譯好的zImage鏡像通過dnw燒寫入開發板中,將rt3070sta.ko和驅動源碼目錄下的RT2870STA.dat兩個文件通過nfs或者sd卡下載到開發板中,RT2870STA.dat放入/etc/Wireless/RT2870STA/目錄下,rt3070sta.ko放入任意合適的目錄,我放在了/usr下。

mkdir –p /etc/Wireless/RT2870STA/

cp RT2870STA.dat / etc/Wireless/RT2870STA/

cp rt3070sta.ko /usr

加載驅動

insmod /usr/rt3070sta.ko

rtusb init rt2870 --->

=== pAd = d1502000, size = 513400 ===

<-- RTMPAllocTxRxRingMemory, Status=0

<-- RTMPAllocAdapterBlock, Status=0

usbcore: registered new interface driver rt2870

然後可以通過ifconfig –a可以看到系統已經正確識別網卡,名稱爲ra0

ifconfig –a

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)

然後啓動網卡,有如下信息輸出,而後可以觀察到模塊的指示燈不停閃爍,此時網卡已經可以正常工作了。

#ifconfig ra0 up

(Efuse for 3062/3562/3572) Size=0x2d [2d0-2fc]

RTMP_TimerListAdd: add timer obj d1549ba8!

RTMP_TimerListAdd: add timer obj d1549bd8!

RTMP_TimerListAdd: add timer obj d1549c08!

RTMP_TimerListAdd: add timer obj d1549b78!

RTMP_TimerListAdd: add timer obj d1549ae8!

RTMP_TimerListAdd: add timer obj d1549b18!

RTMP_TimerListAdd: add timer obj d151471c!

RTMP_TimerListAdd: add timer obj d1503edc!

RTMP_TimerListAdd: add timer obj d1503f14!

RTMP_TimerListAdd: add timer obj d15147c0!

RTMP_TimerListAdd: add timer obj d15146bc!

RTMP_TimerListAdd: add timer obj d151478c!

-->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

MCS Set = ff 00 00 00 01

<==== rt28xx_init, Status=0

0x1300 = 00064300

至此網卡驅動移植成功。但是如果需要讓網卡連接入目前常見的WPA加密的網絡,還需要移植wpa_supplicant工具。

另外還有一個名爲wireless_tools的輔助工具,可以用它來檢索在網卡所在的環境中存在的無線網絡,如果對於要連接入的無線網絡的ssid和相關信息已經清楚,可以不用移植,不過這個工具的移植很簡單。

4、移植wireless_tools

源碼下載地址:http://download.csdn.net/detail/colwer/4515005#comment(這個地址裏的資源跟描述不一致……

tar zxvf wireless_tools.29.tar.gz

cd wireless_tools.29

vim Makefile

PREFIX = /usr/local/wirelesstool

CC = /usr/local/FriendlyARM/toolschain/4.5.1/bin/arm-linux-gcc

AR = /usr/local/FriendlyARM/toolschain/4.5.1/bin/arm-linux-ar

RANLIB = /usr/local/FriendlyARM/toolschain/4.5.1/bin/arm-linux-ranlib

make

make install

/usr/local/wirelesstool/lib目錄下找到libiw.so.29,下載到開發板的/lib/目錄下;/usr/local/wirelesstool/sbin目錄下找到iwpriviwconfigiwlist, iwevent, iwspy等命令,下載到開發板的/usr/sbin目錄下。這時就應該可以使用這些命令通過網卡搜索到環境中的無線網絡。

ifconfig ra0 up

iwlist ra0 scan

Cell 06 - Address: 38:83:45:E5:CB:3E

                    Protocol:802.11b/g/n

                    ESSID:"idart-wlan311"

                    Mode:Managed

                    Frequency:2.437 GHz (Channel 6)

                    Quality=100/100  Signal level=-43 dBm  Noise level=-92 dBm

                    Encryption key:on

                    Bit Rates:22.5 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: DD0E0050F204104A0001101044000102

          Cell 07 - Address: 58:66:BA:EE:DB:40

                    Protocol:802.11b/g/n

                    ESSID:"ChinaNet"

                    Mode:Managed

                    Frequency:2.437 GHz (Channel 6)

                    Quality=42/100  Signal level=-73 dBm  Noise level=-76 dBm

                    Encryption key:off

                    Bit Rates:54 Mb/s

          Cell 08 - Address: 58:66:BA:EE:DB:41

                    Protocol:802.11b/g/n

                    ESSID:"SYSUWLAN"

                    Mode:Managed

                    Frequency:2.437 GHz (Channel 6)

                    Quality=37/100  Signal level=-75 dBm  Noise level=-78 dBm

                    Encryption key:off

                    Bit Rates:54 Mb/s

至此wireliss_tools移植成功。

5、移植wpa_supplicant

源碼下載地址:http://hostap.epitest.fi/wpa_supplicant/

它的移植還需要openssl,下載地址:http://www.openssl.org/source/

我使用的是wpa_supplicant-0.6.10openssl-0.9.8e

將兩個包解壓後,需要爲opensll打上wpa的補丁,然後交叉編譯

cp wpa_supplicant-0.6.10/patches/openssl-0.9.8e-tls-extensions.patch openssl-0.9.8e/

cd openssl-0.9.8e

mkdir /usr/local/ssl

vim Makefile

INSTALLTOP=/usr/local/ssl

OPENSSLDIR=/usr/local/ssl

……

CC= arm-linux-gcc

AR= arm-linux- ar $(ARFLAGS) r

RANLIB= arm-linux-ranlib

make

make install

/usr/local/ssl目錄下安裝了ssl庫。

然後進入到wpa_supplicant的目錄,修改配置文件和Makefile

cd ../wpa_supplicant-0.6.10/wpa_supplicant

cp defconfig .config

vim .config

# Uncomment following two lines and fix the paths if you have installed OpenSSL

# or GnuTLS in non-default location

CFLAGS += -I/usr/local/ssl/include

LIBS += -L/usr/local/ssl/lib

vim Makefile

#ifndef CC

CC=arm-linux-gcc

#endif

然後make,便可以在當前目錄下得到需要的wpa_supplicant工具

wpa_supplicant和配置文件wpa_supplicant.conf下載到開發板中,wpa_supplicant替換掉原本開發板/usr/sbin/目錄下的wpa_supplicantwpa_supplicant.conf放在/etc目錄下,對wpa_supplicant.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"

}

其中的psk爲無線網的密碼

然後把文件末尾提供的一些example全部刪除,否則在使用wpa_supplicant時會報一些類型無法識別的錯誤。

最後進行測試,測試之前要關閉有線網卡eth0,原因是如果不關閉的話在之後添加默認路由時會被設置爲有線網卡的默認路由,這個應該有別的解決方法,不過我沒有仔細去查。

ifconfig eth0 down

ifconfig ra0 up 

ifconfig ra0 192.168.1.248 netmask 255.255.255.0

route add default gw 192.168.1.1

wpa_supplicant -B -ira0 -c /etc/wpa_supplicant.conf –Dwext

===>rt_ioctl_giwscan. 28(28) BSS returned, data->length = 3351

==>rt_ioctl_siwfreq::SIOCSIWFREQ(Channel=6)

RTMP_TimerListAdd: add timer obj d15785c4!

6ping通外網

ping www.google.com

Rcv Wcid(1) AddBAReq

Start Seq = 00000000

RTMP_TimerListAdd: add timer obj d157a5e4!

PING www.google.com (74.125.128.106): 56 data bytes

64 bytes from 74.125.128.106: seq=0 ttl=40 time=86.383 ms

64 bytes from 74.125.128.106: seq=1 ttl=40 time=84.996 ms

64 bytes from 74.125.128.106: seq=2 ttl=40 time=102.010 ms

64 bytes from 74.125.128.106: seq=3 ttl=40 time=86.005 ms

^C

--- www.google.com ping statistics ---

4 packets transmitted, 4 packets received, 0% packet loss

round-trip min/avg/max = 84.996/89.848/102.010 ms

 

參考鏈接:

http://blog.sina.com.cn/s/blog_5d534d2201016uvn.html

http://blog.csdn.net/zhuqing_739/article/details/6259686

http://blog.chinaunix.net/uid-26748719-id-3357068.html

================================End===============================


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章