Realtek 8192cu 驱动移植到 Android 2.2

开发板是三星 S5PV210,Android 2.2

需要到 Realtek 官网下载最新的驱动 v3.1.2590。最开始用v3.0 的驱动,这个是Realtek工程师直接提供的,遇到2个问题:(1)加载驱动模块(insmod)时,报内核虚拟内存分配失败,要求增加虚拟内存。开发板物理内存为1G,启动内核时加vmalloc=512M后,该问题消失,驱动模块能够成功加载,但出现新的问题:(2)在扫描AP时,Android界面显示“不能扫描”,驱动程序打印log显示下载firmware失败,查看驱动程序源码发现,8192cu的驱动中包含了firmware二进制,运行时通过查表来取得firmware,但轮询超时,导致模块初始化失败

Realtek的驱动程序源码包中包含了Android参考实现,只需对路径等配置性的部分根据开发板实际情况进行修改即可

关于vmalloc的补充说明

测试表明,v3.1驱动同样存在insmod时虚拟内存分配失败的问题,需要在内核启动参数中增加vmalloc参数。对S5PV210开发板来说,修改u-boot的内核启动参数

路径:include/configs/smdkv210single.h

修改:

#define CONFIG_BOOTARGS         "root=/dev/mtdblock4 rootfstype=yaffs2 init=/init console=ttySAC0,115200 vmalloc=512M"

编译驱动程序

解压缩驱动程序源码包,需要修改Makefile文件。首先增加Android平台

...
CONFIG_PLATFORM_I386_PC = n
CONFIG_PLATFORM_ANDROID_X86 = n
CONFIG_PLATFORM_ANDROID = y
CONFIG_PLATFORM_ARM_S3C2K4 = n
CONFIG_PLATFORM_ARM_PXA2XX = n
...

然后增加Android平台的配置

ifeq ($(CONFIG_PLATFORM_ANDROID), y)
EXTRA_CFLAGS += -DCONFIG_LITTLE_ENDIAN
ARCH := arm
CROSS_COMPILE := /usr/local/arm/arm-2009q3/bin/arm-none-linux-gnueabi-
KVER := 2.6.32.9
KSRC ?= /home/toor/v21/kernel
MODULE_NAME := wlan
endif

其中交叉编译工具、内核版本和源码路径,要与实际匹配

模块名称默认为8192cu,这里将其修改为wlan,与后面Android wifi中的模块名相匹配

执行

make

在当前目录下生成 wlan.ko

修改开发板配置

AndroidBoard.mk

路径为:vendor/sec/utv210/AndroidBoard.mk

将 wlan.ko 文件拷贝到vendor/sec/utv210/lib/module/ 下。AndroidBoard.mk中增加下面一行,这样在build Android时会将wlan.ko放到 /modules/ 目录下

PRODUCT_COPY_FILES += \
vendor/sec/sec_proprietary/smdkc110/conf/egl.cfg:system/lib/egl/egl.cfg \
vendor/sec/$(TARGET_DEVICE)/lib/module/pvrsrvkm.ko:root/modules/pvrsrvkm.ko \
vendor/sec/$(TARGET_DEVICE)/lib/module/s3c_lcd.ko:root/modules/s3c_lcd.ko \
vendor/sec/$(TARGET_DEVICE)/lib/module/s3c_bc.ko:root/modules/s3c_bc.ko \
vendor/sec/$(TARGET_DEVICE)/lib/module/wlan.ko:root/modules/wlan.ko \
vendor/sec/$(TARGET_DEVICE)/lib/libEGL_POWERVR_SGX540_120.so:system/lib/egl/libEGL_POWERVR_SGX540_120.so \
vendor/sec/$(TARGET_DEVICE)/lib/libGLESv1_CM_POWERVR_SGX540_120.so:system/lib/egl/libGLESv1_CM_POWERVR_SGX540_120.so \
...

BoardConfig.mk

路径为:vendor/sec/utv210/BoardConfig.mk

在末尾增加下面一行,这是编译Realtek驱动必须的

BOARD_USES_REALTEK_WIFI := true

init.rc

路径为:vendor/sec/utv210/conf/init.rc

启动wpa_supplicant 服务

service wpa_supplicant /system/bin/wpa_supplicant -Dwext -iwlan0 -c/data/misc/wifi/wpa_supplicant.conf
group wifi inet
disabled
oneshot

启动dhcpd服务

service dhcpcd /system/bin/dhcpcd -ABKL
group system dhcp
disabled
oneshot

确认wifi相关文件系统结构和权限正确

# create basic filesystem structure
mkdir /data/misc 01771 system misc
mkdir /data/misc/bluetoothd 0770 bluetooth bluetooth
mkdir /data/misc/bluetooth 0770 system system
mkdir /data/misc/keystore 0700 keystore keystore
mkdir /data/misc/vpn 0770 system system
mkdir /data/misc/systemkeys 0700 system system
mkdir /data/misc/vpn/profiles 0770 system system
# give system access to wpa_supplicant.conf for backup and restore
mkdir /data/misc/wifi 0770 wifi wifi
chmod 0770 /data/misc/wifi
chmod 0660 /data/misc/wifi/wpa_supplicant.conf
mkdir /data/local 0771 shell shell
mkdir /data/local/tmp 0771 shell shell
mkdir /data/data 0771 system system
mkdir /data/app-private 0771 system system
mkdir /data/app 0771 system system
mkdir /data/property 0700 root root

#create wifi folders
mkdir /system/etc/wifi 0770 wifi wifi
chmod 0777 /system/etc/wifi
chmod 0666 /system/etc/wifi/wpa_supplicant.conf
chown wifi wifi /system/etc/wifi/wpa_supplicant.conf
#wpa_supplicant socket
mkdir /data/system/ 0771 system system
mkdir /data/system/wpa_supplicant 0771 wifi wifi
chmod 0771 /data/system/wpa_supplicant
#wpa_supplicant control socket for android wifi.c
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
#for dhcpd
mkdir /data/misc/dhcp 0777 dhcp dhcp
chown dhcp dhcp /data/misc/dhcp
chmod 0777 /system/etc/dhcpcd/dhcpcd.conf
chmod 0777 /system/etc/dhcpcd/dhcpcd-run-hooks

代码移植

wpa_supplicant

将Realtek驱动源码包中 external\wpa_supplicant\ 下的3个文件(Android.mk、driver_wext.c、vendor.h)覆盖到Android external/wpa_supplicant/ 下

修改vendor/sec/utv210/conf/wpa_supplicant.conf文件内容为

update_config=1
ctrl_interface=DIR=/data/misc/wifi/wpa_supplicant GROUP=wifi
ap_scan=1

dhcpcd

将Realtek驱动源码包中 external\dhcpcd\ 下的3个文件(Android.mk、client_realtek.c、logger_realtek.c)覆盖到Android源码 external/dhcpcd/ 下

修改vendor/sec/utv210/conf/dhcpcd.conf 文件内容为

interface wlan0
option subnet_mask, routers, domain_name_servers

wifi HAL

将 Realtek Android 参考代码 hardware\libhardware_legacy\wifi\ 下的文件(Android.mk、wifi_realtek.c)覆盖到 Android 源码 hardware/libhardware_legacy/wifi 下

修改 wifi_realtek.c,确认网络接口名、模块名、配置路径等正确

#define WIFI_DRIVER_IFNAME                      "wlan%d"
#define WIFI_DRIVER_IFNAME_AP "wlap%d"
#define WIFI_DRIVER_IFNAME_DISABLE "disable%d"

#ifndef WIFI_DRIVER_MODULE_PATH
// #define WIFI_DRIVER_MODULE_PATH "/system/wifi/wlan.ko"
#define WIFI_DRIVER_MODULE_PATH "/modules/wlan.ko"
#endif
#ifndef WIFI_DRIVER_MODULE_NAME
#define WIFI_DRIVER_MODULE_NAME "wlan"
#endif

static const char WPA_SUPPLICANT_NAME[] = "wpa_supplicant";
static const char WPA_SUPP_PROP_NAME[] = "init.svc.wpa_supplicant";
static const char WPA_SUPP_CTRL_DIR[] = "/data/misc/wifi/wpa_supplicant";
static const char WPA_SUPP_CONFIG_TEMPLATE[] = "/system/etc/wifi/wpa_supplicant.conf";
static const char WPA_SUPP_CONFIG_FILE[] = "/data/misc/wifi/wpa_supplicant.conf";

That's it!

由于Realtek提供了比较完全的参考代码,整个移植的过程非常简单,以至于像我这样的“非专业人士”也可以顺利地完成

关于Android WiFi移植,有一篇文章具有参考价值:PaNiC Random Rant (or how we used to call it: .plan): Porting WiFi drivers to Android









posted on 2011-10-15 14:32  bye_passer  阅读(7053)  评论(0编辑  收藏  举报

导航