wifi ap6212驱动移植及调试分析技术笔记

这次帮客户调试wifi模块ap6212模块( BCM43438),由于硬件设计的问题,导致出现了各种驱动加载报错信息,而且网上很少这些报错信息,这才让人头疼,只好慢慢去摸索。本次是基于imx6平台进行调试,在imx6dl和imx6ul两个型号都调试成功。

驱动移植

地址链接:wifi驱动及固件下载
说明:
bcmdhd 为驱动源码,待编译成驱动。
cyw43438-7.46.58.15.bin 是 firmware 固件。
NB197SM.nvram_20181105_AZ_Joe.txt 是nvram配置文件。

**配置驱动bcmdhd目录中的 Makefile 文件中的 DHD_PLATFORM **
Platform dependent START
DHD_PLATFORM ?= imx
配置固件加载路径,打开Kconfig

config BCMDHD_FW_PATH 
depends on BCMDHD 
string "Firmware path" 
default "/lib/firmware/ap6256/cyw43438-7.46.58.15.bin" 
---help--- 
Path to the firmware file. 
config BCMDHD_NVRAM_PATH 
depends on BCMDHD 
string "NVRAM path" 
default "/etc/firmware/NB197SM.nvram_20181105_AZ_Joe.txt" 
---help---
 Path to the calibration file.

设备树配置

regulators { 
	wlreg_on: fixedregulator@100 { 
		compatible = "regulator-fixed";
		regulator-min-microvolt = <3300000>;
	  	regulator-max-microvolt = <3300000>; 
	  	regulator-name = "wlreg_on";
	    gpio = <&gpio1 30 0>; /* WL_REG_ON */ 
	    startup-delay-us = <100>;
	    enable-active-high;
	 };
};
bcmdhd_wlan_0: bcmdhd_wlan@0 { 
	compatible = "android,bcmdhd_wlan"; 
	gpios = <&gpio1 31 0>; /* WL_HOST_WAKE */ 
	wlreg_on-supply = <&wlreg_on>; 
};

//SDIO配置
&usdhc1 { 
	pinctrl-names = "default"; 
	pinctrl-0 = <&pinctrl_wifi>;
 	bus-width = <4>;
	keep-power-in-suspend;
	enable-sdio-wakeup;
	no-1-8-v;
	non-removable;
	cd-post;
	pm-ignore-notify;
	wifi-host; 
	status = "okay";
    pinctrl_wifi: wifigrp { 
		fsl,pins = < 
		MX6UL_PAD_SD1_CMD__USDHC1_CMD 0x17059 
		MX6UL_PAD_SD1_CLK__USDHC1_CLK 0x10071 
		MX6UL_PAD_SD1_DATA0__USDHC1_DATA0 0x17059 
		MX6UL_PAD_SD1_DATA1__USDHC1_DATA1 0x17059 
		MX6UL_PAD_SD1_DATA2__USDHC1_DATA2 0x17059 
		MX6UL_PAD_SD1_DATA3__USDHC1_DATA3 0x17059 
		MX6UL_PAD_UART5_TX_DATA__GPIO1_IO30 0x03029 /* WL_REG_ON */ 
		MX6UL_PAD_UART5_RX_DATA__GPIO1_IO31 0x03029 /* WL_HOST_WAKE*/ 
		>;
 };

驱动加载

将驱动加载到内核里,我没有将wifi编译成模块.ko,如果成功加载会打印以下信息。

dhd_module_init in
Power-up adapter 'DHD generic adapter'
 - irq 50 [flags 1044], firmware: (null), nvram: (null)
 - bus type -1, bus num -1, slot num -1
wifi_platform_bus_enumerate device present 1
F1 signature read @0x18000000=0x1541a9a6
F1 signature OK, socitype:0x1 chip:0xa9a6 rev:0x1 pkg:0x4
DHD: dongle ram size is set to 524288(orig 524288) at 0x0
CFG80211-ERROR) wl_setup_wiphy : Registering Vendor80211
wl_create_event_handler(): thread:wl_event_handler:5b started
CFG80211-ERROR) wl_event_handler : tsk Enter, tsk = 0xa84a1490
dhd_attach(): thread:dhd_watchdog_thread:5c started
dhd_attach(): thread:dhd_dpc:5d started
dhd_attach(): thread:dhd_rxf:5e started
dhd_deferred_work_init: work queue initialized 
Dongle Host Driver, version 1.363.125.17 (r)
Compiled in drivers/net/wireless/bcmdhd on Nov  5 2021 at 13:41:01
Register interface [wlan0]  MAC: 00:90:4c:11:22:33
CFG80211-ERROR) wl_event_handler : was terminated
wl_destroy_event_handler(): thread:wl_event_handler:5b terminated OK
usb-storage 2-1.1:1.0: USB Mass Storage device detected
dhd_wl_ioctl: returning as busstate=0
dhd_bus_devreset: == Power OFF ==
scsi host0: usb-storage 2-1.1:1.0
dhd_bus_devreset:  WLAN OFF DONE
dhd_module_init out

此信息分几层去理解

1.驱动开始加载
dhd_module_init in

2.模块卡设备已被内核正常识别
mmc0: new high speed SDIO card at address 0001
F1 signature read @0x18000000=0x1541a9a6
F1 signature OK, socitype:0x1 chip:0xa9a6 rev:0x1 pkg:0x4

3.加载成功,取得MAC地址和驱动版本号
Dongle Host Driver, version 1.363.125.17 ®
Compiled in drivers/net/wireless/bcmdhd on Nov 5 2021 at 13:41:01
Register interface [wlan0] MAC: 00:90:4c:11:22:33

4.驱动加载结束
dhd_module_init out

问题一:
如果你在内核配置了wifi驱动,但是在启动信息没有打印出模块开始加载的信息,你需要检查一下wifi驱动是否被选择了以模块的方式编译。

问题二:
如果在驱动加载的时候打印以下信息,需要检查一下硬件接口:(WL_REG_ON)使能脚和(WL_HOST_WAKE)唤醒脚是否有拉高,使用万用表测量一下这两个引脚。如果没有拉高,请在驱动里换其他地方拉高或者强行从硬件上把它拉高。
wifi ap6212驱动移植及调试分析技术笔记_第1张图片

dhd_module_init in
Power-up adapter 'DHD generic adapter'
 - irq 50 [flags 1044], firmware: (null), nvram: (null)
 - bus type -1, bus num -1, slot num -1
wifi_platform_bus_enumerate device present 1
Hfailed to power up DHD generic adapter, 3 retry left
wifi_platform_bus_enumerate device present 0
wifi_platform_bus_enumerate device present 1
Hfailed to power up DHD generic adapter, 2 retry left
wifi_platform_bus_enumerate device present 0
wifi_platform_bus_enumerate device present 1
Hfailed to power up DHD generic adapter, 1 retry left
wifi_platform_bus_enumerate device present 0
wifi_platform_bus_enumerate device present 1
Hfailed to power up DHD generic adapter, 0 retry left
wifi_platform_bus_enumerate device present 0
H1failed to power up DHD generic adapter, max retry reached**
dhd_module_init out
**如果出现以下打印信息:**
```bash
mmc0: error -110 whilst initialising SDIO card

可能是在启动时电源不稳定导致的,或者sdio布线有点问题。

驱动成功加载后,启动WiFi

如果在执行ifconfig wlan0 up指令时,出现以下打印信息,属于正常启动。

root@IMX6ULL:~# rfkill unblock all
root@IMX6ULL:~# ifconfig wlan0 up

Dongle Host Driver, version 1.363.125.17 (r)
Compiled in drivers/net/wireless/bcmdhd on Nov  5 2021 at 13:41:01
wl_android_wifi_on in

dhd_bus_devreset: == WLAN ON ==
F1 signature read @0x18000000=0x1541a9a6
F1 signature OK, socitype:0x1 chip:0xa9a6 rev:0x1 pkg:0x4
DHD: dongle ram size is set to 524288(orig 524288) at 0x0
_dhdsdio_download_firmware:  8078 
dhdsdio_download_state: 4067
dhdsdio_download_state: 4075
dhdsdio_download_state: 4086
dhdsdio_download_state: 4239
dhdsdio_download_code_file: download firmware /lib/firmware/ap6256/fw_bcm43456c5_ag.bin
dhd_os_open_image: download firmware /lib/firmware/ap6256/fw_bcm43456c5_ag.bin
dhdsdio_download_nvram:  8024 
dhd_os_open_image: download firmware /lib/firmware/ap6256/nvram_ap6256.txt
dhdsdio_download_nvram:  8028 
dhdsdio_download_state: 4067
dhdsdio_write_vars: Download, Upload and compare of NVRAM succeeded.
dhdsdio_download_state: 4239
dhd_bus_devreset:  8364 
dhd_bus_init: 4510
dhd_bus_init: enable 0x06, ready 0x06 (waited 0us)
dhd_bus_init: 4634
Disable tdls_auto_op failed. -1
Firmware up: op_mode=0x0005, MAC=20:4e:f6:25:f1:1b
dhd_os_open_image: download firmware /system/etc/wifi/bcmdhd_clm.blob
dhd_preinit_ioctls Set txbf failed  -23
dhd_preinit_ioctls Set ampdu_mpdu to 16 failed  -29
dhd_preinit_ioctls pspretend_threshold for HostAPD failed  -23
Firmware version = wl0: Jun 19 2018 02:10:20 version 7.46.58.15 (r692018 CY) FWID 01-ab22dc42 es4.c3.n4
dhd_wlfc_hostreorder_init(): successful bdcv2 tlv signaling, 64
dhd_pno_init: Support Android Location Service
MACEVENT: WLC_E_IF 54, MAC 20:4e:f6:25:f1:1b, status 0, reason 0, auth 0
rtt_do_get_ioctl: failed to send getbuf proxd iovar (CMD ID : 1), status=-23
dhd_rtt_init : FTM is not supported
dhd_interworking_enable: failed to set WNM info, ret=-23
MACEVENT: WLC_E_IF 54, MAC 20:4e:f6:25:f1:1b, status 0, reason 0, auth 0
MACEVENT: WLC_E_IF 54, MAC 20:4e:f6:25:f1:1b, status 0, reason 0, auth 0
CFG80211-ERROR) wl_update_wiphybands : error reading vhtmode (-23)
wl_create_event_handler(): thread:wl_event_handler:360 started
CFG80211-ERROR) wl_event_handler : tsk Enter, tsk = 0xa84a1490

1.证明WiFi固件已正常加载。
dhdsdio_download_code_file: download firmware /lib/firmware/ap6256/fw_bcm43456c5_ag.bin
dhd_os_open_image: download firmware /lib/firmware/ap6256/fw_bcm43456c5_ag.bin
dhd_os_open_image: download firmware /lib/firmware/ap6256/nvram_ap6256.txt
dhdsdio_write_vars: Download, Upload and compare of NVRAM succeeded.

如果出现这个错误
dhdsdio_membytes: membytes transfer failed
dhdsdio_membytes: FAILED to set window back to 0x18000000
dhdsdio_download_code_file: error -1 on writing 2048 membytes at 0x00004800
你需要检查一下sdio的布线问题了,通讯有点问题,下载不了。

ifconfig wlan0 up

Dongle Host Driver, version 1.363.125.17 (r)
Compiled in drivers/net/wireless/bcmdhd on Nov  5 2021 at 13:41:01
wl_android_wifi_on in
dhd_bus_devreset: == WLAN ON ==
F1 signature read @0x18000000=0x1541a9a6
F1 signature OK, socitype:0x1 chip:0xa9a6 rev:0x1 pkg:0x4
DHD: dongle ram size is set to 524288(orig 524288) at 0x0
_dhdsdio_download_firmware:  8078 
dhdsdio_download_state: 4067
dhdsdio_download_state: 4075
dhdsdio_download_state: 4086
dhdsdio_download_state: 4239
dhdsdio_download_code_file: download firmware /lib/firmware/ap6256/fw_bcm43456c5_ag.bin
dhd_os_open_image: download firmware /lib/firmware/ap6256/fw_bcm43456c5_ag.bin
mmc0: Timeout waiting for hardware interrupt.
dhdsdio_membytes: membytes transfer failed
dhdsdio_membytes: FAILED to set window back to 0x18000000
dhdsdio_download_code_file: error -1 on writing 2048 membytes at 0x00004800
_dhdsdio_download_firmware: dongle image file download failed
dhdsdio_htclk: Failed access turning clock off: -35
dhd_bus_devreset Failed to download binary to the dongle
dhd_net_bus_devreset: dhd_bus_devreset: -35
dhd_open : wl_android_wifi_on failed (-35)
wl_android_wifi_off in
dhd_wl_ioctl: returning as busstate=0

如果出现以下错误:

[   11.325715] brcmfmac: brcmf_sdio_htclk: HT Avail timeout (1000000): clkctl 0x50

需要检查一下固件nvramxxx.txt文件中的xtalfreq的参数,这个参数跟无源晶振的频率有关,晶振用的是26M,那里需要改成xtalfreq=26000才行。

上面的步骤都正常完成后,连接WIFI步骤

执行指令: wpa_supplicant -B -Dnl80211 -iwlan0 -c /etc/wpa_supplicant.conf &
会出现不停的打印这几条命令:

root@IMX6ULL:~# wpa_supplicant -B -Dnl80211 -iwlan0 -c /etc/wpa_supplicant.conf &
root@IMX6ULL:~# kill 884CFG80211-ERROR) wl_run_escan : LEGACY_SCAN sync ID: 4660, bssidx: 0
root@IMX6ULL:~# MACEVENT: WLC_E_ESCAN_RESULT 69, MAC 00:00:00:00:00:00, status 0 

如果出现以上打印信息,你需要检查一下你的晶振是否跟wifi规格书的说明一致。比如规格书使用的是26MHZ ,而你硬件上是使用了32.768MHZ,这就会出现上述的打印信息了

心得

这次调试这个WIFI模块,硬件上碰到了不少问题,导致了以为是软件的问题导致的,浪费时间,多总结,以后就少碰壁。

你可能感兴趣的:(嵌入式驱动调试,linux,驱动程序,嵌入式,wifi)