android之wifi移植全過程(一)

硬件環境     
                               WIFI模塊:Marvell8686 SDIO WIFI
                              開發板:S5PC100     
                        軟件環境
                               Linux 2.6.29  Android 2.1
項目目標:實現WIFI上網功能、並對WIFI休眠進行改善。
項目開發流程:
硬件分析:對Marvell8686 SDIO WIFI模塊硬件工做特性瞭解和分析
工做原理分析:對Marvel8686 SDIO WIFI工做原理進行分析
Android WIFI框架分析:對Android WIFI系統框架分析
進行源碼分析、編寫、修改及編譯
調試、並完善
 
 
 
 
 
1、1.編譯內核,生成驅動模塊
     在內核的根目錄下執行make
     生成libertas.ko 和libertas_sdio.ko
     [*] Networking support  ---> 
         [*]   Wireless  ---> 
                 --- Wireless                                               
                <*>   Improved wireless configuration API                  
                 [*]     cfg80211 regulatory debugging                       
                 [*]     nl80211 new netlink interface support                                                                              
                 -*-   Common routines for IEEE802.11 drivers   
         Device Drivers  --->  
         [*] Network device support  ---> 
                Wireless LAN  --->  
               <*>   Marvell 8xxx Libertas WLAN driver support              (注:編譯進內核,若模塊則是:libertas.ko)       
               <M>     Marvell Libertas 8385 and 8686 SDIO 802.11b/g cards  (注:編譯成libertas_sdio.ko)
    
     2.編譯內核,確保支持sd卡
        Device Drivers  ---
           <*> MMC/SD/SDIO card support  --->
             --- MMC/SD/SDIO card support                                    
             [*]   MMC debugging                                             
             [ ]   Allow unsafe resume (DANGEROUS)                           
             [*]   MMC embedded SDIO device support (EXPERIMENTAL)           
             [ ]   Enable paranoid SD card initialization (EXPERIMENTAL)     
                   *** MMC/SD/SDIO Card Drivers ***                          
             <*>   MMC block device driver                                   
             [*]     Use bounce buffer for simple hosts                      
             [ ]     Deferr MMC layer resume until I/O is requested          
             < >   SDIO UART/GPS class support                              
             < >   MMC host test driver                                       
                   *** MMC/SD/SDIO Host Controller Drivers ***               
             <*>   Secure Digital Host 
       3.make zImage
         make modules
        (libertas_sdio.ko在drivers/net/wireless/libertas目錄下)
2、製做測試工具(使用靜態編譯)
    如今,sd卡支持了,驅動之內核自帶的以模塊的方式編譯獲得。
    接下來先編譯幾個測試工具。
    測試無線網卡用無線工具iwconfig iwlist等命令是經過開源軟件wireless_tools_29.rar編譯獲得。        
    步驟:
    1.解壓。因爲這的是win32的壓縮包,先在windows底下解壓,再拷貝到Ubuntu下。
    2.修改Makefile:
           8   PREFIX = ./tools  //指定安裝路徑                  
           12  CC = arm-linux-gnu-gcc (和編譯你的文件系統所用保持一致,須要注意的是,若是在執行sudo make 就要該編譯鏈的絕對路 徑)                                                                                                      
           14  AR = arm-linux-gnu-ar  
          
           #BUILD_STATIC = y          -->    BUILD_STATIC = y                                       
           #BUILD_STRIPPING = y       -->    BUILD_STRIPPING = y  
          
 
           CFLAGS=-Os -W -Wall -Wstrict-prototypes -Wmissing-prototypes -Wshadow \         
                 -Wpointer-arith -Wcast-qual -Winline -I.
           在這後面添加新行:                             
           CFLAGS += -static
          
    3.make
    4.make install
      因爲我是在當前目錄下(PREFIX = ./tools) 產生的這個tools文件夾,
      查看有:
      lib sbin usr
      lib目錄,libiw.a靜態庫 ;而sbin目錄爲一些網絡工具,如:iwlist、iwconfig等
      到裏面的sbin目錄底下,
      $file iwlist  輸出信息:iwlist: ELF 32-bit LSB executable, ARM, version 1, statically linked, for GNU/Linux 2.4.3, strippe
      確保是靜態的。
     
      而後將這些命令複製到android文件系統的/system/busybox/bin(就是out/target/prodruct/fs100/system/busybox/bin)
      或者system/bin(就是out/target/prodruct/fs100/system/bin)目錄下就可使用這些命令了。 
 
 3、將固件放到指定目錄下。
     1.mkdir /system/etc/firmware(就是out/target/prodruct/fs100/system/etc/firmware)
     2.cp sd8686.bin sd8686_helper.bin  out/target/prodruct/fs100/system/etc/firmware
 
 4、測試,sdio卡是否可用。
     若是已經編譯好了文件系統,就能夠跳過第一步。
     1.編譯android系統。
               1)在文件系統根目錄下執行:
               liyulei@liyulei:~/anrdoid/fs/android_system$ . ./build/envsetup.sh
             注意這裏兩個’.’  之間有一個空格,第一個’.’指定用當前 shell 解析這個腳本,不然不能執行。
            2)配置板級信息:
            liyulei@liyulei:~/anrdoid/fs/android_system$ tapas
            就是上一步執行結束以後導出到環境變量裏的命令,專門用來配置板級信息的。
             Build for the simulator or the device?
                    1. Device
                   2. Simulator
            Which would you like? [1] 1
            Build type choices are:
                   1. release
                   2. debug
            Which would you like? [1] 1
            Which product would you like? [fs100] fs100
            Variant choices are:
                   1. user
                   2. userdebug
                   3. eng
            Which would you like? [eng] eng
           
            確保輸出的配置信息爲:
            PLATFORM_VERSION_CODENAME=REL
            PLATFORM_VERSION=2.1-update1 
            TARGET_PRODUCT=fs_s5pc100    
            TARGET_BUILD_VARIANT=eng     
            TARGET_SIMULATOR=false       
            TARGET_BUILD_TYPE=release    
            TARGET_ARCH=arm              
            HOST_ARCH=x86                
            HOST_OS=linux                
            HOST_BUILD_TYPE=release      
            BUILD_ID= ERE27              
           
            3)開始編譯(若是不能找到 mm,執行」source build/envsetup.sh」):
            liyulei@liyulei:~/anrdoid/fs/android_system$ mm
   
   2.從新生成文件系統鏡像。
     liyulei@liyulei:~/anrdoid/fs/android_system$ ./make_fs100_yaffs2_image.sh
     就會在 Android 源碼根目錄下生成目錄「fs100_root」,這個目錄就是編譯生成的 Android 文件系統, 
     調試時能夠直接把這個目錄做爲 NFS-Server 的目錄。還會生成一個「fs100_root.img」文件,這個文件就
     是 Android的 yaffs2 格式的鏡像,能夠燒寫到 Nand Flash 上。
       這裏我是燒寫上fs100_root.img.
    
     3.手動加載驅動。
       因爲sdio8686。須要加載兩個.ko(libertas.ko、libertas_sdio.ko) 文件。
       上面linertas.ko的模塊,我已經編進內核。
       因此我只需執行:
       1)/# insmod libertas_sdio.ko  
       輸出信息:
       libertas_sdio: Libertas SDIO driver                                
     libertas_sdio: Copyright Pierre Ossman                             
     __func__ = if_sdio_prog_helper                                     
     libertas_sdio mmc1:0001:1: firmware: requesting sd8686_helper.bin  
     init: untracked pid 2137 exited                                    
     libertas_sdio mmc1:0001:1: firmware: requesting sd8686.bin         
     init: untracked pid 2140 exited                                    
     libertas: 00:0b:6c:91:a3:f6, fw 9.70.3p24, cap 0x00000303          
     libertas: unidentified region code; using the default (USA)        
     wlan0 (libertas_sdio): not using net_device_ops yet                
     libertas: PREP_CMD: command 0x00a3 failed: 2                       
     libertas: PREP_CMD: command 0x00a3 failed: 2                       
     libertas: wlan0: Marvell WLAN 802.11 adapter                       
    2)/# ifconfig -a 
       (要是提示:-a: No such device,則輸入命令:system/busybox/sbin/ifconfig -a)   
    查看是否檢測到無線網卡                          
           有以下信息說明檢測到無線網卡                                   
             wlan0     Link encap:Ethernet  HWaddr 00:0B:6C:91:A3:F6      
                       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)             
    3)測試: 
         /#ifconfig wlan0 up                                                                                                          
        /#iwlist wlan0 scanning                                                                                                         
        /#iwconfig wlan0 essid "fs100"                                                                                                  
        /#ifconfig wlan0 192.168.1.99 netmask 255.255.255.0 up (靜態分配ip,
         也能夠動態分配,用DHCP)
         /#route add default gw 192.168.1.1(無線路由)
         /#ping 192.168.1.1           
    4)可以ping通後,說明sdio8686 wifi網卡沒有問題
   
5、測試wpa_supplicant。
  由於如今的無線wifi網絡大可能是wpa加密。 因此須要用到wpa_supplicant。
    android系統中也自帶有wpa_supplicant。
    wifi的大體架構是這樣的,app-->java framework-->|jni|-->c++ framework -->wifi.c -->wpa_supplicant-->sdio8686.
    因此咱們要先測試低層先通了,所以,就得先測試確保wpa_supplicant和sdio8686通了的。
    咱們編譯android系統時,就已經把自帶的wpa_supplicant和wpa_cli編譯好並放到system/bin目錄下了.
    1.配置wpa_supplicant。
    在 liyulei@liyulei:~/anrdoid/fs/android_system/external/wpa_supplicant/在目錄下有個wpa_supplicant.conf。     將wpa_supplicant.conf放到out/target/product/fs100/system/etc 目錄下。若是是燒到板子上的話,須要重燒板子。     要是以網絡掛載的方式,則放到相應的目錄。     #vim /rootfs/filesystem/etc/wpa_supplicant.conf                                                                             修改內容以下:                                                                                                              # WPA-PSK/TKIP                                                                                                               ctrl_interface=/var/run/wpa_supplicant                                                                                       network={                                                                      ssid="fs100"     //填寫無線網絡的的用戶名                       key_mgmt=WPA-PSK                                                proto=WPA                                                      pairwise=TKIP                                                  group=TKIP                                                     psk="1234567890" //填寫密碼                    }                                                                 2.#mkdir –p /var/run/wpa_supplicant     3.確認是否加載驅動。      用ifconfig -a查看是否已經建立wlan0這個節點。       沒有就把驅動加載進內核。     4.建立鏈接暗文密碼(PSK密碼),經過明碼轉換                                                                           #cd /etc (該目錄下要有 wpa_supplicant.conf)                                                                                                         #wpa_passphrase fs100 1234567890 >> wpa_supplicant.conf                                                          此時將在wpa_supplicant.conf文件中生成:                                                                           network={                                                                                                               ssid="fs100"                                                                                                     #psk="1234567890" //此物爲路由器中設定的人類能讀得懂的密碼,供咱們使用                                            psk=d290464a66df8541cee4f100627446177ee7ce5d9eb36981e4dff412730b2d5a //這個又1234567890轉換後的psk密碼       }                                                                                                                  -----------------------------------------------------------------------------------------------------<----        ---->遇到問題:在測試過程當中要用到wpa_passphrase這個命令程序。可是android並沒提供wpa_passphrase       <----        ---->這命令,我只經過wpa_supplicant-0.7.3這個源碼包編譯出這個命令。可是這個命令在開發板上執行        <----        ---->不了(編譯鏈不對)。我又找到android源碼中有wpa_passphrase.c,而編譯出來的路徑下經過find         <----        ---->命令去找這個wpa_passphrase又找不到。                                                            <----        ---->解決辦法:同過度析wpa_passphrase.c才發現,裏面就短短的一個mian函數。有個提示                    <----        ---->usage: wpa_passphrase <ssid> [passphrase]\n""\nIf passphrase is left out, it will be read from "<----      ---->"stdin\n                                                                                        <----        ---->如今不用我說都知道了吧!因此這個在哪運行均可以,這命令就是爲了經過ssid和passphrase獲得暗文。    <----        ---->因此我在Ubuntu底下直接執行:wpa_passphrase fs100 1234567890                                     <----        ---->一樣輸出信息:network= {                                                                         <----                                     ---->                          ssid="fs100"                                                          <----                                     ---->                          #psk="1234567890"                                                     <----        ---->                          psk=d290464a66df8541cee4f100627446177ee7ce5d9eb36981e4dff412730b2d5a  <----        ---->                    }                                                                           <----                                     -----------------------------------------------------------------------------------------------------<-----       5.而後修改wpa_supplicant.conf配置文件,把 psk="1234567890" 這一行明文密碼改爲生成的暗文密碼,即:                psk=d290464a66df8541cee4f100627446177ee7ce5d9eb36981e4dff412730b2d5a                                                                                                                                其它生成的多餘信息刪除,最後wpa_supplicant.conf文件以下:                                             # WPA-PSK/TKIP                                                                                                                                                                                       ctrl_interface=/var/run/wpa_supplicant                                                                                                                                                               network={                                                                                                        ssid="FS2410"     //填寫無線網絡的的用戶名                                                            key_mgmt=WPA-PSK                                                                                      proto=WPA                                                                                             pairwise=TKIP                                                                                         group=TKIP                                                                                           psk=d290464a66df8541cee4f100627446177ee7ce5d9eb36981e4dff412730b2d5a                       }             6.連接AP:              在開發板終端輸入wpa_supplicant回車,會顯示幫助信息,最後有個:                                      example:                                                                                                 wpa_supplicant -Dwext -iwlan0 -c/etc/wpa_supplicant.conf                                     拷貝example用法,執行:                                                                            # wpa_supplicant -Dwext -iwlan0 -c/etc/wpa_supplicant.conf &(須要一直放在後臺運行)                 打印信息有:                                                                                       Trying to associate with 00:26:f2:0d:5a:c4 (SSID='fs100' freq=2412 MHz)                           Associated with 00:23:68:28:4e:a8                                                                  CTRL-EVENT-DISCONNECTED bssid=00:23:68:28:4e:a8 reason=0                                           Associated with 00:26:f2:0d:5a:c4                                                                  WPA: Key negotiation completed with 00:26:f2:0d:5a:c4 [PTK=TKIP GTK=TKIP]                          CTRL-EVENT-CONNECTED - Connection to 00:26:f2:0d:5a:c4 completed (auth) [id=0 id_str=]                                                                                                          分配IP地址:                                                                                       #ifconfig wlan0 192.168.1.5  //也能夠動態分配 dhclient wlan0                                       再ping下網關,是否鏈接成功:                                                                       #ping 192.168.1.1                                                                                                                                                                               3 packets transmitted, 3 packets received, 0% packet loss                                          round-trip min/avg/max = 17.627/20.023/24.631 ms                                                   ……                                                                                                                                                                                            無線網卡鏈接成功!      
相關文章
相關標籤/搜索