RT3070驱动移植

 

http://rpf413.blog.163.com/blog/static/45563760201161132158913/

http://blog.chinaunix.net/uid-28572323-id-3482376.html

无线网卡为RT3070,驱动分为STA驱动和SoftAP驱动两种,STA驱动支持无线网卡工作在STA模式下,而SoftAP的驱动支持无线网卡工作在软AP的模式下,可以作为一个软的接入点。STA驱动为2010_0831_RT3070_Linux_STA_v2.3.0.0_DPO.bz2SoftAP的驱动是:2010_0203_RT3070_SoftAP_v2.4.0.1_DPA.bz2。需要移植STA驱动和SoftAP驱动,两款驱动的移植步骤差不多。下边首先对STA驱动进行移植。

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 andWEP/TKIP/CCMP)

                     [*]     Support downloading firmware images withHost AP driver

                     [*]       Support for non-volatile firmwaredownload

                        Ralink driver support  --->

                               Ralink rt27xx/rt28xx/rt30xx (USB) support

然后make,编译通过后会在arch/arm/boot/目录下生成可烧写入开发板的zImage内核镜像。

2:编译rt3070模块的驱动

解压 tar -zxvf 2011_0107_RT3070_RT3370_Linux_STA_v2.5.0.1_DPO.tar.gz

修改原有的Makefile文件如下(只给出需要修改的部分,“-”表示删除的行,“+”表示添加的行):

+#Makefile for RT3070 on MBC-SAM9G45

+#2010_11_13 by liyi

RT28xx_MODE = STA

TARGET = LINUX

CHIPSET = 3070

-PLATFORM = PC

+PLATFORM = IXP

 

ifeq ($(PLATFORM),IXP)

-LINUX_SRC = /project

-CROSS_COMPILE = arm-linux-

+LINUX_SRC = /hisi/Hi3515_SDK_V1.0.8.0/source/os/linux-2.6.24

+CROSS_COMPILE =arm-hismall-linux-

endif

修改os/linux文件夹中的config.mk文件,需要修改的地方如下(只给出需要修改的部分):

# Support Wpa_Supplicant

- HAS_WPA_SUPPLICANT=n

+HAS_WPA_SUPPLICANT=y

# Support Native WpaSupplicant for Network Maganger

-HAS_NATIVE_WPA_SUPPLICANT_SUPPORT=n

+HAS_NATIVE_WPA_SUPPLICANT_SUPPORT=y

 

ifeq ($(PLATFORM),IXP)

- WFLAGS += -DRT_BIG_ENDIAN

+#WFLAGS += -DRT_BIG_ENDIAN

endif

 

ifeq ($(PLATFORM),IXP)

        EXTRA_CFLAGS := -v $(WFLAGS) -I$(RT28xx_DIR)/include

endif

 

ifeq ($(PLATFORM),IXP)

-         CFLAGS := -v -D__KERNEL__ -DMODULE -I$(LINUX_SRC)/include -I$(RT28xx_DIR)/include -Wall -Wstrict-prototypes -Wno-trigraphs -O2 -fno-strict-aliasing -fno-common -Uarm -fno-common -pipe -mapcs-32 -D__LINUX_ARM_ARCH__=5 -mcpu=xscale -mtune=xscale -malignment-traps -msoft-float $(WFLAGS)

-        EXTRA_CFLAGS := -v $(WFLAGS) -I$(RT28xx_DIR)/include

-         export CFLAGS       

-

+

endif


ifeq ($(PLATFORM),IXP)
- WFLAGS += -DRT_BIG_ENDIAN
#
加这个选项,模块运行时显示出错,CPU不能工作
endif

在修改驱动config.mk文件的时候,红色修改部分没有给全,应该是把CFLAGS和EXTRA_FLAGS中的-mbig-endian选项去掉,因为在ARM中采用的小端模式!

修改完成以后,通过以下命令编译:

make ARCH=arm KBUILD_NOPEDANTIC=1

如果不加KBUILD_NOPEDANTIC=1将出现CFLAGS was changed in …. Fix it to use EXTRA_CFLAGS的错误,编译不能通过。编译完成后,会在os/linux文件夹中生成rt3070sta.ko的驱动模块。

会报如下错误:

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




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移植成功。

 设置ESSID 实验室的无线网络没有密码因此可以直接设置联网

  # iwconfig ra0 ESSID Mywifi

此时已经可以ping同其他电脑了!!!!!!!!

下面移植的工具我一直没有成功,提示错误,因此目前还没有解决有密码的wifi网络问题!!


/ $ wpa_supplicant -B -irausb0 -c /etc/wpa_supplicant.conf -Dralink

/usr/sbin/wpa_supplicant: /usr/sbin/wpa_supplicant: 1: Syntax error: "(" unexpected


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

=================================================================

照着完整的做了一遍,任然ping不通外网,无线路由加密是wpa2-psk,作如下修改可ping通外网

/etc $ cat wpa_supplicant.conf
network={
ssid="YanFa"
key_mgmt=WPA-EAP WPA-PSK IEEE8021X NONE
pairwise=TKIP CCMP
group=CCMP TKIP WEP104 WEP40
psk="nopassword"
}
/etc $


 

你可能感兴趣的:(linux驱动相关)