<menu id="w8yyk"><menu id="w8yyk"></menu></menu>
  • <dd id="w8yyk"><nav id="w8yyk"></nav></dd>
    <menu id="w8yyk"></menu>
    <menu id="w8yyk"><code id="w8yyk"></code></menu>
    <menu id="w8yyk"></menu>
    <xmp id="w8yyk">
    <xmp id="w8yyk"><nav id="w8yyk"></nav>
  • 網站首頁 > 物聯資訊 > 技術分享

    嵌入式Linux USB WIFI驅動的移植

    2016-09-28 00:00:00 廣州睿豐德信息科技有限公司 閱讀
    睿豐德科技 專注RFID識別技術和條碼識別技術與管理軟件的集成項目。質量追溯系統、MES系統、金蝶與條碼系統對接、用友與條碼系統對接

    硬件平臺:飛思卡爾MX258開發板

    操作系統:Linux2.6.31

    WIFI:    RT2860 USB WIFI模組

    交叉編譯環境:gcc version 4.1.2

     

    調試步驟:

    第一步:測試USB HOST接口

    在menuconfig中將USB HOST設置為內核模式:

     

     

    重新編譯內核后啟動開發板,插入U盤并掛載:

    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通路由了。

    RFID管理系統集成商 RFID中間件 條碼系統中間層 物聯網軟件集成
    最近免费观看高清韩国日本大全