1. 程式人生 > >使用RT3070使開發板上網

使用RT3070使開發板上網

config llc 開發板 algorithm ethernet over byte cfg 默認網關

原文地址:http://www.cnblogs.com/NickQ/p/8973880.html

使開發板上網

  • USB驅動部分

    在arch/arm/mach-s3c2440/mach-smdk2440.c中,修改Usb時鐘。
#include <mach/regs-clock.h> /* Add 2018/04/25-14:54:18  By Nick, for usb_s3c2440_init() */
#include <plat/udc.h>        /* Add 2018/04/25-14:54:26  By Nick   to support USB device gadget, 2017.5.4 */
#include <linux/delay.h>

/*  USB device UDC support add by 2018/04/25-14:54:57  By Nick */
static struct s3c2410_udc_mach_info smdk2440_udc_cfg __initdata = {
        .pullup_pin = S3C2410_GPG(9),
};

/* Add by 2018/04/25-14:55:19  By Nick, fix device descriptor read/64, error -62 bug, value refer to datasheet P255 */
int usb_s3c2440_init(void)
{
    /* Input Frequency is 12.0000MHz, and MDEV=0x38 PDIV=2 SDIV=2, so output frequency 48.00MHz */
    unsigned long upllvalue = (0x38<<12)|(0x02<<4)|(0x02);
    while (upllvalue != __raw_readl(S3C2410_UPLLCON))
    {
        __raw_writel(upllvalue, S3C2410_UPLLCON);
        mdelay(1);
    }
    return 0;
}

調用初始化函數

//在smdk2440_map_io函數中調用usb_s3c2440_init(),修改USB時鐘
static void __init smdk2440_map_io(void)
{
        s3c24xx_init_io(smdk2440_iodesc, ARRAY_SIZE(smdk2440_iodesc));
        s3c24xx_init_clocks(12000000);
        s3c24xx_init_uarts(smdk2440_uartcfgs, ARRAY_SIZE(smdk2440_uartcfgs));
        usb_s3c2440_init();
}
  • 配置內核,使能USB和無線網卡(RT3070)驅動

[*] Networking support  --->  
        -*-   Wireless  --->
     <*>   cfg80211 - wireless configuration API                        
     [ ]     nl80211 testmode command                                    
     [ ]     enable developer warnings                               
     [ ]     cfg80211 regulatory debugging                             
     [*]     enable powersave by default                             
     [ ]     cfg80211 DebugFS entries                                 
     [*]     cfg80211 wireless extensions compatibility                
     [*]   Wireless extensions sysfs files                               
     {*}   Common routines for IEEE802.11 drivers                          
     [ ]   lib80211 debugging messages                               
     <*>   Generic IEEE 802.11 Networking Stack (mac80211)                 
                  Default rate control algorithm (Minstrel)  --->                 
     [ ]   Enable mac80211 mesh networking (pre-802.11s) support            
     [ ]   Export mac80211 internals in DebugFS                             
     [ ]   Select mac80211 debugging features  ---> 
Device Drivers  --->
       Generic Driver Options  --->
      (/sbin/hotplug) path to uevent helper                                  
      [ ] Maintain a devtmpfs filesystem to mount at /dev                    
      [ ] Select only drivers that don‘t need compile-time external firmware
      [ ] Prevent firmware from being built  
      -*- Userspace firmware loading support                                
      [*]   Include in-kernel firmware blobs in kernel binary              
      ()    External firmware blobs to build into the kernel binary         
      [ ] Driver Core verbose debug messages                                 
      [ ] Managed device resources verbose debug messages
    [*] Network device support  --->
           [*]   Wireless LAN  --->
               <*>   Ralink driver support  --->
               < >   Ralink rt2500 (USB) support                                    
               < >   Ralink rt2501/rt73 (USB) support                                 
               <*>   Ralink rt27xx/rt28xx/rt30xx (USB) support                      
                 [ ]     rt2800usb - Include support for rt33xx devices                 
                 [ ]     rt2800usb - Include support for rt35xx devices (EXPERIMENTAL)  
                 [ ]     rt2800usb - Include support for rt53xx devices (EXPERIMENTAL)  
                 [ ]     rt2800usb - Include support for unknown (USB) devices          
                 [*]   Ralink debug output
  • Wireless tools移植

    tar zxvf wireless_tools.29.tar.gz
    cd wireless_tools.29

    修改Makefile

    ## Compiler to use (modify this for cross compile).
    CC = /opt/xtools/arm920t/bin/arm-linux-gcc
    ## Other tools you need to modify for cross compile (static lib only).
    AR = /opt/xtools/arm920t/bin/arm-linux-ar
    RANLIB = /opt/xtools/arm920t/bin/arm-linux-ranlib

    使用make編譯.
    將生成的命令工具:ifrename、iwevent、wgetid、iwspy、iwlist、iwconfig、iwpriv,libiw.so.29拷貝到開發板的/bin下,並分別賦予權限chmod 777 iw* libiw.so.29.

  • 制作openssl庫

    tar zxvf openssl-1.0.0s.tar.gz 
    mkdir install 

    修改Makefile

  1. 修改路徑

    INSTALL_PREFIX=
    INSTALLTOP=/home/nick/s3c2440/3rdparty/openssl-1.0.0s/install
    OPENSSLDIR=/home/nick/s3c2440/3rdparty/openssl-1.0.0s/install
  2. 修改編譯選項

    CC= /opt/xtools/arm920t/bin/arm-linux-cc
    CFLAG= -O
    DEPFLAG= -DOPENSSL_NO_GMP -DOPENSSL_NO_JPAKE -DOPENSSL_NO_MD2 -DOPENSSL_NO_RC5 -DOPENSSL_NO_RFC3779 -DOPENSSL_NO_STORE
    PEX_LIBS=
    EX_LIBS=
    EXE_EXT=
    ARFLAGS=
    AR= /opt/xtools/arm920t/bin/arm-linux-ar $(ARFLAGS) r
    RANLIB= /opt/xtools/arm920t/bin/arm-linux-ranlib
  3. 使用sudo make && sudo make install 編譯安裝
    拷貝libcrypto.a; libssl.a到開發板的/lib下
    在下一步wpa_supplicant中需要使用這個庫,因此install將會被引用。

  • wpa_supplicant移植

    tar zxvf wpa_supplicant-0.7.3.tar.gz 
    cd ./wpa_supplicant-0.7.3/wpa_supplicant/
    cp defconfig .config 

    修改.config

    CC=/opt/xtools/arm920t/bin/arm-linux-gcc -L /home/nick/s3c2440/3rdparty/openssl-1.0.0s/install/lib
    #CC=/opt/brcm/hndtools-mipsel-uclibc/bin/mipsel-uclibc-gcc
    #CFLAGS += -Os
    CFLAGS += -I/home/nick/s3c2440/3rdparty/openssl-1.0.0s/install/include
    #CPPFLAGS += -I../src/include -I../../src/router/openssl/include
    #LIBS += -L/opt/brcm/hndtools-mipsel-uclibc-0.9.19/lib -lssl
    LIBS += -L /home/nick/s3c2440/3rdparty/openssl-1.0.0s/install/lib

    使用make編譯
    將wpa_cli,wpa_supplicant,wpa_passphrase拷貝到開發板的/bin目錄下。並給予權限 chmod 777:wpa_cli,wpa_supplicant,wpa_passphrase

  • 開發板配置以及操作

    在/etc目錄下創建wpa_supplicant.conf配置文件

    cd /etc
    wpa_passphrase ssid psk >> wpa_supplicant.conf

    ssid 是WIFI的用戶名
    psk 是WIFI的密碼
    例如:wpa_passphrase 16402_1 1640216402 >> wpa_supplicant.conf

cat ./wpa_supplicant.conf network={ ssid="16402_1" #psk="1640216402" psk=136a6b18bd0d21eb12d6bc591fa652d628cbb438e8f29fcfeb8d763c0bf15ec2 } [nick@NickQ_fl2440 ~]#
修改wpa_supplicant.conf,加入加密方式等配置

cat wpa_supplicant.conf 
network={
        ssid="16402_1"
        key_mgmt=WPA-PSK
        proto=WPA2
        pairwise=TKIP CCMP
        group=TKIP CCMP
        psk="1640216402"
}

key_mgmt=WPA-PSK 表示 采用WPA-PSK共享密鑰的認證方式
proto=WPA2 表示 WPA2加密方式
pairwise = TKIP CCMP 和 group =TKIP CCMP 表示 自動匹配加密算法CCMP或TKIP;

啟動RT3070並配置RT3070無線網卡參數

wpa_supplicant -B -d -Dwext -iwlan0 -c/etc/wpa_supplicant.conf 

其中:
-d :增加調試信息
-B:後臺守護進程
-c:指定配置文件
-Dwext:wext為驅動名稱
-iwlan0 :wlan0為網絡接口名稱

iwconfig 查看連接狀態,已連接

[nick@NickQ_fl2440 ~]# iwconfig
lo        no wireless extensions.

eth0      no wireless extensions.

wlan0     IEEE 802.11bgn  ESSID:"16402_1"  
          Mode:Managed  Frequency:2.437 GHz  Access Point: 14:75:90:7C:18:AC   
          Bit Rate=6.5 Mb/s   Tx-Power=20 dBm   
          Retry  long limit:7   RTS thr:off   Fragment thr:off
          Encryption key:off
          Power Management:on
          Link Quality=51/70  Signal level=-59 dBm  
          Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0
          Tx excessive retries:0  Invalid misc:1   Missed beacon:0

ifconfig 查看網絡狀態,發現無IP地址

[nick@NickQ_fl2440 ~]# ifconfig wlan0
wlan0     Link encap:Ethernet  HWaddr 00:A1:B0:40:6F:1E  
          inet6 addr: fe80::2a1:b0ff:fe40:6f1e/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:8 errors:0 dropped:0 overruns:0 frame:0
          TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:600 (600.0 B)  TX bytes:876 (876.0 B)

配置網絡IP,子網掩碼,網關

配置網絡IP,子網掩碼:ifconfig wlan0 192.168.168.100 netmask 255.255.255.0
配置默認網關:route add default gw 192.168.168.1 
配置DNS:    echo "nameserver 8.8.8.8" > /etc/resolv.conf

Ping測試

[nick@NickQ_fl2440 ~]# ping baidu.com
PING baidu.com (220.181.57.216): 56 data bytes
64 bytes from 220.181.57.216: seq=0 ttl=55 time=25.000 ms
64 bytes from 220.181.57.216: seq=1 ttl=55 time=65.000 ms
64 bytes from 220.181.57.216: seq=2 ttl=55 time=65.000 ms
  • 開機自啟動

    cd /etc/init.d/
    vim S20_conf_wifi
    #!/bin/sh
    ifconfig wlan0 up
    wpa_supplicant -B -d -Dwext -iwlan0 -c/etc/wpa_supplicant.conf
    ifconfig wlan0 192.168.168.100 netmask 255.255.255.0
    route add default gw 192.168.168.1 

使用RT3070使開發板上網