赞
踩
在android ROM 开发中经常会遇到产品更换wifi模块的情况,一般常见的wifi驱动android内核中自带都有,无需过多调试,要是碰上内核中没有的就需要根据厂商提供的驱动进行移植。
wifi驱动移植过程不多说,根据厂商提供的文档说明进行移植编译出驱动文件xxx.ko即可。
在成功编译出驱动ko文件后,手动insmod 加载驱动是可以的,但是开机时不会自动加载,这时可按以下步骤进行调整,让设备开机自动加载新模块的驱动。以USB类型模块为例:
1.通过adb shell lsusb 命令查看wifi的设备名称。
λ adb shell
Hi3798MV200:/ # lsusb
Bus 001 Device 002: ID 1a40:0101
Bus 001 Device 003: ID 1a40:0101
Bus 004 Device 002: ID 1d5c:2000
Bus 001 Device 001: ID 1d6b:0002
Bus 002 Device 001: ID 1d6b:0001
Bus 003 Device 001: ID 1d6b:0002
Bus 004 Device 001: ID 1d6b:0003
Bus 001 Device 004: ID 1a40:0101
Bus 001 Device 005: ID 1a86:7523
Bus 001 Device 006: ID 046d:c534
Bus 001 Device 007: ID 248a:8367
Bus 001 Device 008: ID 174c:55aa
Bus 001 Device 009: ID 0bda:8152
可通过拔插排除无关usb设备或查看usb设备的具体信息来判断是哪一个,比如我目前用的rtl8188fu模块的设备名称为:0bda:f179
2.添加该设备名称到系统支持的wifi设备列表中:hardware\libhardware_legacy\wifi\wifi.c
每个模块名称与设备名称一一对应{WIFI_REALTEK_RTL8188FU, "0bda:f179"},
- /* Product ID of supported WiFi devices */
- static wifi_device_s devices[] = {
- {WIFI_RALINK_MT7601U, "148f:7601"},
- {WIFI_REALTEK_RTL8188EUS, "0bda:8179"},
- {WIFI_REALTEK_RTL8188ETV, "0bda:0179"},
- {WIFI_REALTEK_RTL8192EU, "0bda:818b"},
- {WIFI_REALTEK_RTL8812AU, "0bda:8812"},
- {WIFI_REALTEK_RTL8723BU, "0bda:b720"},
- {WIFI_MEDIATEK_MT7632U, "0e8d:7632"},
- {WIFI_MEDIATEK_MT7662U, "0e8d:7662"},
- {WIFI_MEDIATEK_MT7612U, "0e8d:7612"},
- {WIFI_REALTEK_RTL8821AU, "0bda:0823"},
- {WIFI_ATHEROS_QCA6174, "168c:003e"},
- {WIFI_REALTEK_RTL8822BU, "0bda:b82c"},
- {WIFI_REALTEK_RTL8822BE, "10ec:b822"},
- {WIFI_HISI_HI1131C, "0296:5347"},
- {WIFI_AMPAK_AP6356S, "02D0:4356"},
- {WIFI_REALTEK_RTL8188FU, "0bda:f179"},
- {WIFI_MEDIATEK_MT7662TE, "14c3:7662"},
- {WIFI_MEDIATEK_MT7662TU, "0e8d:76a0"},
- {WIFI_REALTEK_RTL8821CU, "0bda:c811"}
- };
WIFI_REALTEK_RTL8188FU是我们自定义的名称,需要先在头文件的模块名称列表中声明:
\hardware\libhardware_legacy\include\hardware_legacy\wifi.h
- /* ID of supported WiFi devices */
- typedef enum {
- WIFI_RALINK_MT7601U,
- WIFI_REALTEK_RTL8188EUS,
- WIFI_REALTEK_RTL8188ETV,
- WIFI_REALTEK_RTL8192EU,
- WIFI_REALTEK_RTL8812AU,
- WIFI_REALTEK_RTL8723BU,
- WIFI_MEDIATEK_MT7632U,
- WIFI_MEDIATEK_MT7662U,
- WIFI_MEDIATEK_MT7612U,
- WIFI_REALTEK_RTL8821AU,
- WIFI_ATHEROS_QCA6174,
- WIFI_REALTEK_RTL8822BU,
- WIFI_REALTEK_RTL8822BE,
- WIFI_HISI_HI1131C,
- WIFI_AMPAK_AP6356S,
- WIFI_REALTEK_RTL8188FU,
- WIFI_MEDIATEK_MT7662TE,
- WIFI_MEDIATEK_MT7662TU,
- WIFI_REALTEK_RTL8821CU,
- WIFI_INVALID_DEVICE = ~0x0 ,
- } wifi_id_e;
3.声明wifi新模块要加载的驱动名称rtl8188fu.ko和位置:wifi.c中
- #define DRIVER_MODULE_RTL8188FU 2, \
- { \
- {"cfg80211",MODULE_PATH"cfg80211.ko","","cfg80211 "}, \
- {"rtl8188fu",MODULE_PATH"rtl8188fu.ko","rtw_channel_plan=0x0C ifname=wlan0 if2name=p2p0","rtl8188fu "} \
- }
4.将声明的新驱动模块DRIVER_MODULE_RTL8188FU添加到系统对应的驱动列表中:wifi.c
- static wifi_modules_s sta_drivers[] = {
- {DRIVER_MODULE_MT7601U_STA}, // MediaTek MT7601U
- {DRIVER_MODULE_RTL8188EUS}, // RealTek RTL8188EUS
- {DRIVER_MODULE_RTL8188EUS}, // RealTek RTL8188ETV
- {DRIVER_MODULE_RTL8192EU}, // RealTek RTL8192EU
- {DRIVER_MODULE_RTL8812AU}, // RealTek RTL8812AU
- {DRIVER_MODULE_RTL8723BU}, // RealTek RTL8723BU
- {DRIVER_MODULE_MT7632U}, // MediaTek MT7632U
- {DRIVER_MODULE_MT7632U}, // MediaTek MT7662U
- {DRIVER_MODULE_MT7632U}, // MediaTek MT7612U
- {DRIVER_MODULE_RTL8821AU}, // RealTek RTL8821AU
- {DRIVER_MODULE_QCA6174}, // Atheros QCA6174
- {DRIVER_MODULE_RTL8822BU}, // RealTek RTL8822BU
- {DRIVER_MODULE_RTL8822BE}, // RealTek RTL8822BE
- {DRIVER_MODULE_HI1131C}, // Hisi Hi1131C
- {DRIVER_MODULE_AP6356S_STA}, // AMPAK AP6356S
- {DRIVER_MODULE_RTL8188FU}, // RealTek RTL8188FTV
- {DRIVER_MODULE_MT7662TE}, //MediaTek MT7662TE
- {DRIVER_MODULE_MT7662TU}, //MediaTek MT7662TU
- {DRIVER_MODULE_RTL8821CU} //RealTek RTL8821CU
- };
注意sta_drivers[] 中的名称位置顺序需要跟步骤2中的devices[]一一对应。
5.编译hardware\libhardware_legacy得到libhardware_legacy.so,adb push 到 system/lib/,至此开机后就会自动加载、system/lib/modules/rtl8188fu.ko 新WiFi模块的驱动了。
最后,梳理一下wifi驱动自动加载流程:
1.libhardware_legacy会遍历所有的usb设备名称,与devices[]中的wifi模块名称进行对比,有匹配到的话,就会记住该名称的索引位置
2.寻找sta_drivers[]中对应步骤1记住的索引位置指向的驱动名称
3.根据步骤2中找到的驱动名称,自动加载该名称声明时配置的驱动名称和位置进行insmod
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。