轉載自:http://blog.sina.com.cn/s/blog_5f35912f0100q3p1.html html
手動加載驅動
####16th,Jul
驅動加載
modprobe libertas
modprobe libertas_sdio
加載第二行時出錯拉
# modprobe libertas_sdio
libertas_sdio: Libertas SDIO driver
libertas_sdio: Copyright Pierre Ossman
model=0xb
sd8686_helper.bin sd8686.bin
init: untracked pid 958 exited
過了一會出現:
libertas: can't load helper firmware
libertas: failed to load helper firmware
libertas_sdio: probe of mmc2:0001:1 failed with error -2
可是用lsmod又能看到
# lsmod
libertas_sdio 8776 0 - Live 0xbf022000
libertas 97416 1 libertas_sdio, Live 0xbf009000
usbserial 30256 0 - Live 0xbf000000
###使用insmod試一下
insmod /lib/modules/2.6.24.7/kernel/drivers/net/wireless/libertas/libertas.ko
insmod /lib/modules/2.6.24.7/kernel/drivers/net/wireless/libertas/libertas_sdio.ko
仍是老樣子
###發現系統中沒有提到的文件fireware文件
從華恆的romfs/lib把fireware拷貝到 /nfs/rootfs/lib下
$$仍是不行
###把fireware拷貝到system/etc/下面,終於能夠加載了
以下:
# modprobe libertas_sdio
libertas_sdio: Libertas SDIO driver
libertas_sdio: Copyright Pierre Ossman
model=0xb
sd8686_helper.bin sd8686.bin
init: untracked pid 714 exited
init: untracked pid 717 exited
libertas: eth1: Marvell WLAN 802.11 adapter
$$$建議
Title:Android INIT not loading firmware
android員工答:You need to run the insmod in a separate process launched by init.
#########
理解原理
Android uses a modified wpa_supplicant (external/wpa_supplicant) daemon for wifi support which is controlled through a socket by hardware/libhardware_legacy/wifi/wifi.c (WiFiHW) that gets controlled from Android UI through android.net.wifi package from frameworks/base/wifi/java/android/net/wifi/ and it's corresponding jni implementation in frameworks/base/core/jni/android_net_wifi_Wifi.cpp Higher level network management is done in frameworks/base/core/java/android/net
1.在build/target/board/generic/BoardConfig.mk中增長
BOARD_WPA_SUPPLICANT_DRIVER := WEXT
2.打開調試信息--可選
默認是不打開調試的
2.1 modify external/wpa_supplicant/common.c and set wpa_debug_level = MSG_DEBUG
2.2 modify common.h and change #define wpa_printf from if ((level) >= MSG_INFO) to if ((level) >= MSG_DEBUG)
3.建立system/etc/wifi/wpa_supplicant.conf
有2種socket
一種是android private socket
ctrl_interface=eth1
update_config=1
ap_scan=1 ###取決於wifi驅動,若是不行,則改成0試試
另外一種是unix 標準socket,這裏先選用第二種
ctrl_interface=DIR=/data/system/wpa_supplicant GROUP=wifi
update_config=1
ap_scan=1 ###取決於wifi驅動,若是不行,則改成0試試
4在init.rc中增長如下語句
#@qiu
mkdir /system/etc/wifi 0777 wifi wifi
chmod 0777 /system/etc/wifi
chmod 0777 /system/etc/wifi/wpa_supplicant.conf
chown wifi wifi /system/etc/wifi/wpa_supplicant.conf
mkdir /data/misc/wifi 0777 wifi wifi
mkdir /data/misc/wifi/sockets 0770 wifi wifi
chmod 0777 /data/misc/wifi
chmod 0777 /data/misc/wifi/wpa_supplicant.conf
chown wifi wifi /data/misc/wifi
chown wifi wifi /data/misc/wifi/wpa_supplicant.conf
# wpa_supplicant socket (unix socket mode)
mkdir /data/system/wpa_supplicant 0777 wifi wifi
chmod 0777 /data/system/wpa_supplicant
chown wifi wifi /data/system/wpa_supplicant
#qiu@
##若是是private socket,則是
mkdir /system/etc/wifi 0777 wifi wifi
chmod 0777 /system/etc/wifi
chmod 0777 /system/etc/wifi/wpa_supplicant.conf
chown wifi wifi /system/etc/wifi/wpa_supplicant.conf
#wpa_supplicant control socket for android wifi.c (android private socket)
mkdir /data/misc/wifi 0777 wifi wifi
mkdir /data/misc/wifi/sockets 0770 wifi wifi
chmod 0777 /data/misc/wifi
chmod 0777 /data/misc/wifi/wpa_supplicant.conf
chown wifi wifi /data/misc/wifi
chown wifi wifi /data/misc/wifi/wpa_supplicant.conf
5.在init.rc中添加wpa_supplicant和dhcpcd啓動服務
service wpa_supplicant /system/bin/wpa_supplicant -dd -Dwext -ieth1 -c /system/etc/wifi/wpa_supplicant.conf
group system wifi inet
disabled
oneshot
##若是是pricvate socket則須要在group上面增長一行:
socket wpa_eth1 dgram 777 wifi wifi
service dhcpcd /system/bin/dhcpcd -f /system/etc/dhcpcd/dhcpcd.conf -d eth1
group system dhcp wifi
disabled
oneshot
5.5增長/system/etc/dhcpcd/dhcpcd.conf文件內容
interface eth1
option subnet_mask, routers, domain_name_servers
6.把wifi驅動編譯進內核
首先init.rc中增長
setprop wifi.interface "eth1"
setprop wlan.driver.status "ok"
其次在修改hardware/libhardware_legacy/wifi/wifi.c
新的out/target/product/generic/system/lib/libhardware_legacy.so---v2
在函數wifi_load_driver()的體的開頭增長
//@qiu
LOGE("Weber@wifi driver loaded !");
return 0;
//qiu@
在函數wifi_unload_driver()體的開頭增長
//@qiu
LOGE("Weber@wifi driver unloaded!");
return 0;
//qiu@
####17th,Jul
把驅動從M改成*,得zImage-vvv39
開始啓動:
加載firmware的時候出錯
libertas: can't load helper firmware
libertas: failed to load helper firmware
libertas_sdio: probe of mmc2:0001:1 failed with error -2
看來是沒法加載fireware
###嘗試修改wifi.c讓它自動加載模塊
修改
#ifndef WIFI_DRIVER_MODULE_PATH1
#define WIFI_DRIVER_MODULE_PATH1 "/system/lib/modules/libertas.ko"
#endif
#ifndef WIFI_DRIVER_MODULE_PATH2
#define WIFI_DRIVER_MODULE_PATH2 "/system/lib/modules/libertas_sdio.ko"
#endif
#ifndef WIFI_DRIVER_MODULE_NAME1
#define WIFI_DRIVER_MODULE_NAME1 "libertas"
#endif
#ifndef WIFI_DRIVER_MODULE_NAME2
#define WIFI_DRIVER_MODULE_NAME2 "libertas_sdio"
#endif
並在此文件的後面代碼中作必定修改,wifi_load_driver()函數中也作相應修改
編譯獲得libhardware_legacy.so---v3
-啓動後在設置中點擊wifi
串口顯示以下,看來是能加載了
# libertas_sdio: Libertas SDIO driver
libertas_sdio: Copyright Pierre Ossman
model=0xb
sd8686_helper.bin sd8686.bin
init: untracked pid 954 exited
init: untracked pid 957 exited
libertas: eth1: Marvell WLAN 802.11 adapter
可是wifi圖標下面顯示wifi不可用
查看logcat的main:
7899 E/WifiHW ( 708): Cannot access "/data/misc/wifi/wpa_supplicant.conf": Permission denied
7900 E/WifiHW ( 708): Wi-Fi will not be enabled
7901 W/WifiHW ( 708): Weber@wifi driver unloaded!
7902 E/WifiService( 708): Failed to start supplicant daemon.
7903 D/SettingsWifiEnabler( 791): Received wifi state changed from Enabling to Unknown
因而增長如下語句到init.rc
mkdir /data/misc/wifi 0770 wifi wifi
mkdir /data/misc/wifi/sockets 0770 wifi wifi
chmod 0770 /data/misc/wifi
chmod 0660 /data/misc/wifi/wpa_supplicant.conf
chown wifi wifi /data/misc/wifi
chown wifi wifi /data/misc/wifi/wpa_supplicant.conf
而且cp system/etc/wifi/wpa_supplicant.conf ./data/misc/wifi/
啓動,終於能打開wifi,但仍是沒法打開網頁
查看logcat
4564 E/wpa_supplicant( 917): Failed to read or parse configuration '/system/etc/wifi/wpa_supplicant.conf'.
4565 E/WifiHW ( 708): Unable to open connection to supplicant on "/data/system/wpa_supplicant/sta": No such file or directory
4566 D/WifiService( 708): ACTION_BATTERY_CHANGED pluggedType: 1
4899 E/WifiHW ( 708): Supplicant not running, cannot connect
5574 E/WifiHW ( 708): Supplicant not running, cannot connect
5575 V/WifiStateTracker( 708): Supplicant died unexpectedly
5576 D/dalvikvm( 934): DexOpt: load 3102ms, verify 1519ms, opt 24ms
5577 D/installd( 665): DexInv: --- END '/system/app/Browser.apk' (success) ---
5578 D/NetworkStateTracker( 708): setDetailed state, old =IDLE and new state=DISCONNECTED
5579 D/ConnectivityService( 708): ConnectivityChange for WIFI: DISCONNECTED/DISCONNECTED
##在init.rc中把wpa_supplicant.conf權限修改成777,
仍是有錯誤:
5573 E/WifiHW ( 708): Unable to open connection to supplicant on "/data/system/wpa_supplicant/sta": No such file or director
##在init.rc中增長如下幾條語句
setprop wifi.interface "eth1"
setprop wlan.driver.status "ok"
setprop wlan.interface "eth1"
結果仍是不行logcat顯示
E/WifiHW ( 708):Unable to open connection to supplicant on "/data/system/wpa_supplicant/eth1": No such file or directory
##在init.rc中dhcp服務啓動是爲eth1的增長wifi組權限
又出現新錯誤
若是開始就enable wifi就會出現如下錯誤:
E/WifiHW ( 709): Unable to open connection to supplicant on "/data/system/wpa_supplicant/eth1": Connection refused
由於這是開機默認啓動wifi,若是不起動,錯誤則是和上一條相同
###18th,Jul
##嘗試在wpa_supplicant.conf設置GROUP=system,仍是不行,只好改回去
ls /data/system/wpa_supplicant/eth1 -l
srwxrwx--- 1 1010 1010 0 Jul 18 08:22 /data/system/wpa_supplicant/eth1
# ls /data/system/wpa_supplicant/eth1 -l
srwxrwxrwx 1 1010 1010 0 Jul 18 08:22 /data/system/wpa_supplicant/eth1
###18th,Jul手動調試
# wpa_supplicant -dd -Dwext -ieth1 -c /system/etc/wifi/wpa_supplicant.conf&
# ioctl[SIOCSIWPMKSA]: Invalid argument《《《《輸出的錯誤
# ls /data/system/wpa_supplicant/eth1 -l
srwxrwxrwx 1 1010 1010 0 Jul 18 13:14 /data/system/wpa_supplicant/eth1
#wpa_cli -i eth1 -p /data/system/wpa_supplicant
不知道該如何設置ap
bash# wpa_cli -ieth1 scan //搜索無線網
bash# wpa_cli -ieth1 scan_results //顯示搜索結果
bash# wpa_cli -ieth1 add_network
bash# iwconfig eth1 essid "you_wifi_net"
bash# wpa_cli -ieth1 password 0 "password"
bash# wpa_cli -ieth1 enable_network
###19th,Jul
修改vi frameworks/base/wifi/java/android/net/wifi/WifiStateTracker.java
把tiwlan0改eth1
暫時未編譯
###開始沒有選擇第二步的debug選項,選上,在external/wpa_supplicant目錄下有mm編譯
獲得
system/bin/wpa_cli---vvv1
system/lib/libwpa_client.so---vvv1
system/bin/wpa_supplicant---vvv1
###試一下android private socket
修改vi system/etc/wifi/wpa_supplicant.conf
vi data/misc/wifi/wpa_supplicant.conf
修改init.rc
在chmod那裏把unix socket的那段註釋
在啓動wpa_supplicant的時候增長
socket wpa_eth1 dgram 660 wifi wifi
結果仍是不行
###只好在external/wpa_supplicant/wpa_ctrl.c中添加
LOGW,注意得先加入頭文件和LOG_TAG
17 #define LOG_TAG "WifiQiu"
18 #include "cutils/log.h"
mm編譯獲得
system/bin/wpa_cli---vvv2
system/lib/libwpa_client.so---vvv2
可是居然沒有WifiQiu輸出,不知道是否是沒有用make而是mm的緣故
###20th,Jul
1.BoardConfig.mk增長了HAVE_CUSTOM_WIFI_DRIVER_2 := true
2.修改wifi/wifi.c中使得檢查和卸載驅動的兩個函數,用make編譯獲得
libhardware_legacy.so---v4
system/bin/wpa_cli---vvv2.1
system/bin/wpa_supplicant-v2
system/lib/libwpa_client.so---vvv2.1
###上面的版本尚未來的及測試,有發現問題
1.忽然發現external/wpa_supplicant/wpa_ctrl.c中LOG不夠全面,
一共有三種狀況,漏了一個函數沒有加,因而增長LOGW並使之能夠區分
2.根據手動strace wpa_cli的提示
access("/data/misc/wifi/wpa_supplicant", F_OK) = -1 ENOENT (No such file or directory)
用grep 搜索到所在文件爲external/wpa_supplicant/wpa_cli.c
把它修改成:/data/misc/wifi
用mm分別在external/wpa_supplicant和hardware/libhardware_legacy中編譯
獲得
system/bin/wpa_cli---vvvvv3
system/lib/libwpa_client.so---vvv3
libhardware_legacy.so---v5
啓動以後發現是在對socket進行鏈接的時候出錯了
connect(ctrl->s, (struct sockaddr *) &ctrl->dest,sizeof(ctrl->dest)) < 0)
並且不能關閉wifi
只好從新修改wifi.c直接在unload函數中返回0,使得wifi能被關閉
libhardware_legacy.so---v5.1
###21th,Jul使用private的時候再次手動調試
# wpa_supplicant -dd -Dwext -ieth1 -c /system/etc/wifi/wpa_supplicant.conf&
# ioctl[SIOCSIWPMKSA]: Invalid argument
mkdir[ctrl_interface]: Permission denied
[1] + Done(255) wpa_supplicant -dd -Dwext -ieth1 -c /system/etc/wifi/wpa_supplicant.conf
查找mkdir發現是在ctrl_iface_unix.c中
錯誤是出如今#ifdef ANDROID以外阿,詭異
###用donut中external/wpa_supplicant下的driver_wext.c替換地掉eclair中的
mm從新編譯,獲得:
wpa_supplicant---vvv3
$$$仍是不行
###22th,Jul
把donut的wpa_supplicant文件夾拷貝到eclair下
用mm編譯獲得
system/bin/wpa_cli---vvvvv4
system/bin/wpa_supplicant---vvv4
system/lib/libwpa_client.so---vvv4
wpa_supplicant---vvv3
終於能夠搜索到網絡了,淚奔
可是,不能獲取到ip地址呵呵
logcat提示:
I/WifiStateTracker( 713): DhcpHandler: DHCP request failed: Timed out waiting for DHCP to finish
###手動啓動dhcp提示
eth1: open `/data/misc/dhcp/dhcpcd-eth1.pid': No such file or directory
在init.rc中增長
mkdir /data/misc/dhcp 0777 wifi wifi
chmod 0777 /data/misc/dhcp
chown wifi wifi /data/misc/dhcp
仍是不能得到地址
eth1: flock `/data/misc/dhcp/dhcpcd-eth1.pid': Try again
後來把上面的wifi 改成dhcp,仍是不能得到IP地址
$$
把dhcpcd殺了,手動啓動
# dhcpcd -f /system/etc/dhcpcd/dhcpcd.conf -d eth1
eth1: dhcpcd 4.0.1 starting
eth1: hardware address = 00:1a:6b:a2:38:65
eth1: executing `/system/etc/dhcpcd/dhcpcd-run-hooks', reason PREINIT
eth1: /system/etc/dhcpcd/dhcpcd-run-hooks: Permission denied
eth1: waiting for carrier
eth1: host does not support a monotonic clock - timing can skew
eth1: timed out
eth1: executing `/system/etc/dhcpcd/dhcpcd-run-hooks', reason FAIL
eth1: /system/etc/dhcpcd/dhcpcd-run-hooks: Permission denied
$$把權限都改成777,再次執行
# dhcpcd -f /system/etc/dhcpcd/dhcpcd.conf -d eth1
eth1: dhcpcd 4.0.1 starting
eth1: hardware address = 00:1a:6b:a2:38:65
eth1: executing `/system/etc/dhcpcd/dhcpcd-run-hooks', reason PREINIT
eth1: waiting for carrier
eth1: host does not support a monotonic clock - timing can skew
eth1: timed out
eth1: executing `/system/etc/dhcpcd/dhcpcd-run-hooks', reason FAIL
$$尚未關閉android機呢,從新打開wifi,嘿嘿,能分配到地址了
可是...可是,仍是不能上網,估計是因爲地址的緣由吧
把eth0禁用以後就能夠上網了,呵呵
wifi移植告一段落java