天天看點

RT3070wifi+linux(TMS320DM368)移植

參考文章:

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

http://bbs.csdn.net/topics/390152921

移植環境:

         主機作業系統:Ubuntu 10.04 LTS 32-bit

         目标機:T MS320DM368  Linux 2.6.32

         交叉編譯環境:arm-none-linux-gnueabi-gcc

         無線子產品:雷淩Ralink - rt3070

操作步驟:

1. 編譯arm版本的核心源碼

找到核心源碼壓縮包,對核心的無線子產品進行配置。

make menuconfig

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

[*] Networkingsupport  --->

       [*]   Wireless  --->

              <*>   cfg80211-wireless configuration API

              [*]   Wirelessextensionssysfs files

              <*>   GenericIEEE802.11 Networking Stack(mac80211)

Device Drivers  --->

       [*]Networkdevicesupport  --->

              [*]   WirelessLAN  --->

                     <*>   IEEE802.11for Host AP (Prism2/2.5/3 andWEP/TKIP/CCMP)

                     [*]     Supportdownloadingfirmware images withHost AP driver

                     [*]       Supportfornon-volatile firmwaredownload

                     <M>   Ralinkdriversupport  --->

                            <M>   Ralinkrt27xx/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 –jxvf 2011_0719_RT3070_RT3370_RT5370_RT5372_Linux_STA_V2.5.0.3_DPO.bz2

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

HAS_NATIVE_WPA_SUPPLICANT_SUPPORT=y

Makefile也要進行修改,晶片類型改為3070,預設的PLATFORM為PC,那麼将後面的ifeq($(PLATFORM),PC)下的核心源碼路徑指定為上述的交叉編譯過的核心源碼目錄,交叉編譯工具指定為/opt/arm-2009q1-203/bin/arm-none-linux-gnueabi-gcc當然之前應該把交叉工具鍊安裝好,這裡不再詳述。

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/$(shelluname-r)/kernel/drivers/net/wireless/(無線子產品路徑)

CROSS_COMPILE =/opt/arm-2009q1-203/bin/arm-none-linux-gnueabi-

endif

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

/home/cabbage/Desktop/rt3070/os/linux/../../chips/rtmp_chip.c:Infunction '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]: Leavingdirectory`/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

然後再make,編譯通過後會在os/linux/下生成rt3070sta.ko,這就是子產品的驅動。 但是這裡我出現了一個問題,檢視rt3070sta.ko這個檔案的大小,居然達到了12m,這是不合理的,原因應該是包含了大量調試資訊,用arm-linux-strip可将它的大小裁剪為750k左右。

#arm-linux-strip -S rt3070sta.ko

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

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

3.燒寫核心和加載驅動子產品

         将之前編譯好的核心zImage鏡像燒寫到dm368開發闆中(将核心鏡像拷貝到啟動卡sd卡中),将rt3070sta.ko和驅動源碼目錄下的RT2870STA.dat兩個檔案通過tftp下載下傳到目标闆中(tftp –gl xxx 192.168.1.161),RT2870STA.dat放入/etc/Wireless/RT2870STA/目錄下,rt3070sta.ko放入任意合适的目錄,我放在了/usr/share/ti/dvsdk-demo/下。

mkdir –p /etc/Wireless/RT2870STA/

cp RT2870STA.dat / etc/Wireless/RT2870STA/

cp rt3070sta.ko /usr/share/ti/dvsdk-demo/

加載驅動子產品

insmod /usr/rt3070sta.ko

rtusb init rt2870 --->

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

<-- RTMPAllocTxRxRingMemory,Status=0

<-- RTMPAllocAdapterBlock,Status=0

usbcore: registered new interfacedriverrt2870

然後可以通過ifconfig–a可以看到系統已經正确識别網卡,名稱為ra0。

ifconfig –a

ra0       Linkencap:Ethernet  HWaddr00:00:00:00:00:00 

          BROADCASTMULTICAST  MTU:1500  Metric:1

          RXpackets:0 errors:0 dropped:0 overruns:0 frame:0

          TXpackets:0 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0txqueuelen:1000

          RXbytes: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 objd1549ba8!

RTMP_TimerListAdd: add timer objd1549bd8!

RTMP_TimerListAdd: add timer objd1549c08!

RTMP_TimerListAdd: add timer objd1549b78!

RTMP_TimerListAdd: add timer objd1549ae8!

RTMP_TimerListAdd: add timer objd1549b18!

RTMP_TimerListAdd: add timer objd151471c!

RTMP_TimerListAdd: add timer objd1503edc!

RTMP_TimerListAdd: add timer objd1503f14!

RTMP_TimerListAdd: add timer objd15147c0!

RTMP_TimerListAdd: add timer objd15146bc!

RTMP_TimerListAdd: add timer objd151478c!

-->RTUSBVenderReset

<--RTUSBVenderReset

Key1Str is Invalid key length(0) orType(0)

Key2Str is Invalid key length(0) orType(0)

Key3Str is Invalid key length(0) orType(0)

Key4Str is Invalid key length(0) orType(0)

1. Phy Mode = 5

2. Phy Mode = 5

NVM is Efuse and its size=2d[2d0-2fc]

phy mode> Error! The chip doesnotsupport 5G band 5!

RTMPSetPhyMode: channel is out ofrange, usefirst 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://www.hpl.hp.com/personal/Jean_Tourrilhes/Linux/wireless_tools.29.tar.gz

tar zxvf wireless_tools.29.tar.gz

cd wireless_tools.29

vim Makefile

PREFIX = /usr/local/wirelesstool     (生成檔案的路徑)

CC = /opt/arm-2009q1-203/bin/arm-none-linux-gnueabi-gcc

AR = /opt/arm-2009q1-203/bin/arm-none-linux-gnueabi-ar

RANLIB = /opt/arm-2009q1-203/bin/arm-none-linux-gnueabi-ranlib

make

make install

在/usr/local/wirelesstool/lib目錄下找到libiw.so.29,下載下傳到開發闆的/lib/目錄下;/usr/local/wirelesstool/sbin目錄下找到iwpriv、iwconfig、iwlist, 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.437GHz(Channel 6)

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

                    Encryptionkey:on

                    BitRates:22.5 Mb/s

                    IE:WPA Version 1

                        GroupCipher : CCMP

                        PairwiseCiphers (1) :CCMP

                        AuthenticationSuites(1) : PSK

                    IE:IEEE 802.11i/WPA2Version 1

                        GroupCipher : CCMP

                        PairwiseCiphers (1) :CCMP

                        AuthenticationSuites(1) : PSK

                    IE:Unknown:DD0E0050F204104A0001101044000102

          Cell07 - Address: 58:66:BA:EE:DB:40

                    Protocol:802.11b/g/n

                    ESSID:"ChinaNet"

                    Mode:Managed

                    Frequency:2.437GHz(Channel 6)

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

                    Encryptionkey:off

                    BitRates:54 Mb/s

          Cell08 - Address: 58:66:BA:EE:DB:41

                    Protocol:802.11b/g/n

                    ESSID:"SYSUWLAN"

                    Mode:Managed

                    Frequency:2.437GHz(Channel 6)

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

                    Encryptionkey:off

                    BitRates:54 Mb/s

至此wireliss_tools移植成功。

5. openssl移植

openss版本:openssl-1.0.0d

openss為wpa_supplicant驅動移植做準備

openssl下載下傳位址:

http://www.openssl.org/source/

ftp://ftp.openssl.org/source/old/0.9.x/ 

makefile修改 (-為去掉設定, +為新加的設定)

#vimakefile

INSTALLTOP=/usr/local/ssl

OPENSSLDIR=/usr/local/ssl

……

CC=  /opt/arm-2009q1-203/bin/arm-none-linux-gnueabi-gcc

AR= /opt/arm-2009q1-203/bin/arm-none-linux-gnueabi-ar $(ARFLAGS) r

RANLIB= /opt/arm-2009q1-203/bin/arm-none-linux-gnueabi-ranlib

#make

#makeinstall

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

拷貝下面檔案驅動到目标系統/usr/lib/

libssl.so.1.0.0

libcrypto.so.1.0.0

openssl 移植完成,下面可以做wpa_supplicant驅動移植

6.移植wpa_supplicant

版本:wpa_supplicant-0.7.3

移植wpa_supplicant前確定Openssl已經移植好了。

源碼下載下傳位址:

http://hostap.epitest.fi/wpa_supplicant/

http://w1.fi/releases/

配置修改,編譯

#cpdefconfig .config

#vi.config

增加這幾行

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

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

CC = /opt/arm-2009q1-203/bin/arm-none-linux-gnueabi-gcc

-L /usr/local/ssl/lib/

#make

需要先編譯安裝openssl庫,確定兩個編譯都使用統一工具arm-linux-gcc

不一緻會出現這樣的問題:

/usr/bin/ld:skipping incompatible /usr/local/ssl/lib/libssl.so when searching for -lssl

/usr/bin/ld:skipping incompatible /usr/local/ssl/lib/libssl.a when searching for -lssl

/usr/bin/ld:cannot find -lssl

/usr/bin/ld:skipping incompatible /usr/local/ssl/lib/libcrypto.so when searching for-lcrypto

/usr/bin/ld:skipping incompatible /usr/local/ssl/lib/libcrypto.a when searching for-lcrypto

/usr/bin/ld:cannot find -lcrypto

collect2:ld returned 1 exit status

make:*** [wpa_supplicant] Error 1

這樣隻要把openssl和wpa_supplicant兩個用同一個編譯工具編譯即可。

7.産品闆使用

把wpa_supplicant.conf拷貝到/xxx目錄下 (xxx目錄自定,我是放在目錄下/etc)

按加密方式分3種,以下3個配置檔案均測試正常,然後把檔案末尾提供的一些example全部删除,否則在使用wpa_supplicant時會報一些類型無法識别的錯誤。

# 無密碼 wpa_supplicant.conf内容:

ctrl_interface=/var/run/wpa_supplicant

network={

ssid="XXXXXX"

key_mgmt=NONE

}

# WEP密碼 wpa_supplicant.conf内容:

ctrl_interface=/var/run/wpa_supplicant

network={

ssid="XXXXXX"

key_mgmt=NONE

wep_key0="XXXXXX"

wep_tx_keyidx= 0

}

# WPA密碼 wpa_supplicant.conf内容:

#WPA-PSK/TKIP

ctrl_interface=/var/run/wpa_supplicant

network={

        ssid="MMLABN16"

        key_mgmt=WPA-PSKWPA-EAP IEEE8021X NONE

        proto=WPARSN

        pairwise=TKIPCCMP

        group=TKIPCCMP WEP104 WEP40

        psk="MMLAB406"

}

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

ifconfig eth0 down

ifconfig ra0 up 

ifconfig ra0 192.168.1.248netmask255.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)BSSreturned, data->length = 3351

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

RTMP_TimerListAdd: add timer objd15785c4!

ping 

以下是詳細測試過程

wpa_supplicant拷貝到/xxx/目錄下(我是放在根目錄下/)

我的方法:wpa_supplicant-Dwext -iwlan0 -c/wpa_supplicant.conf

參考方法:

//無橋方式

wpa_supplicant-B -ira0 -c /etc/wpa_supplicant.conf -Dwext (xxx為前面wpa_supplicant.conf目錄, 我是在/etc目錄下)

//有橋接方式(bridge-utils)

wpa_supplicant-B -b br0 -ira0 -c /xxx/wpa_supplicant.conf -Dwext

如果運作時出現:

socket(PF_PACKET):Address family not supported by protocol

原因

核心不支援RAWsocket,編譯核心時把CONFIG_PACKET選項打開,

CONFIG_PACKET= y

If weuse CONFIG_PACKET=m instead of CONFIG_PACKET=y we'd need to

includeaf_packet.ko into the initramfs for netboot installation.

手動加載af_packet.ko

#insmodaf_packet.ko

顯示

NET:Registered protocol family 17

加載正常

運作#wpa_supplicant

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

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

RTMP_TimerListAdd:add timer obj d1b3c620!

RTMP_TimerListAdd:add timer obj d1b3c650!

RTMP_TimerListAdd:add timer obj d1b3c680!

RTMP_TimerListAdd:add timer obj d1b3c5f0!

RTMP_TimerListAdd:add timer obj d1b3c560!

RTMP_TimerListAdd:add timer obj d1b3c590!

RTMP_TimerListAdd:add timer obj d1b06b94!

RTMP_TimerListAdd:add timer obj d1af5f54!

RTMP_TimerListAdd:add timer obj d1af5f8c!

RTMP_TimerListAdd:add timer obj d1b06c38!

RTMP_TimerListAdd:add timer obj d1b06b34!

RTMP_TimerListAdd:add timer obj d1b06c04!

-->RTUSBVenderReset

<--RTUSBVenderReset

Key1Stris Invalid key length(0) or Type(0)

Key2Stris Invalid key length(0) or Type(0)

Key3Stris Invalid key length(0) or Type(0)

Key4Stris Invalid key length(0) or Type(0)

1. PhyMode = 5

2. PhyMode = 5

phymode> Error! The chip does not support 5G band 5!

RTMPSetPhyMode:channel is out of range, use first channel=1

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

3. PhyMode = 9

MCS Set= ff 00 00 00 01

<====rt28xx_init, Status=0

0x1300 =00064300

運作正常

檢視狀态:

#iwconfig

lo       no wireless extensions.

eth0     no wireless extensions.

ra0      Ralink STA  ESSID:"MMLABN16" Nickname:"RT2870STA"

          Mode:Managed Frequency=2.437 GHz  Access Point: BC:AE:C5:C4:9A:5E

          BitRate=135 Mb/s

          RTSthr:off   Fragment thr:off

          Encryptionkey:40C3-43C1-AB81-351A-CD3A-226F-6CDD-8FC9   Security mode

:open

          LinkQuality=73/100  Signal level:-63 dBm  Noise level:-90 dBm

          Rxinvalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0

          Txexcessive retries:0  Invalid misc:0   Missed beacon:0

設定ip

#ifconfigra0 192.168.1.191 netmask 255.255.255.0

設定完一會,等網絡連接配接好就可以了。

啟動6410自帶的無線,啟動後關閉自帶的無線。此時ra0無線就可以正常使用。

[[email protected]/]# ping 192.168.1.1

PING192.168.1.1 (192.168.1.1): 56 data bytes

64 bytesfrom 192.168.1.1: seq=0 ttl=64 time=1063.262 ms

64 bytesfrom 192.168.1.1: seq=1 ttl=64 time=468.672 ms

64 bytesfrom 192.168.1.1: seq=2 ttl=64 time=379.596 ms

64 bytesfrom 192.168.1.1: seq=3 ttl=64 time=361.608 ms

繼續閱讀