感觉wifi相对与蓝牙来说,hal层和android上层需要配置的东西很多,对于底层来说配置就相对简单很多。
一、设备树配置
匹配驱动
ap6256_wifi: ap6256_wifi {
compatible = "android,bcmdhd_wlan";
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_wlan>;
gpio_wl_reg_on = <&gpio3 0 GPIO_ACTIVE_HIGH>;
gpio_wl_host_wake = <&gpio3 7 GPIO_ACTIVE_LOW>;
};
......
pinctrl_wlan: wlangrp {
fsl,pins = <
MX8MP_IOMUXC_NAND_DATA01__GPIO3_IO07 0x16
MX8MP_IOMUXC_NAND_ALE__GPIO3_IO00 0x41
>;
};
然后看硬件说明手BT和WIFI用的串口几通讯,我们同时也要保证串口的正常使用才行。 这是最基础的功能,如果此时你的上层配置没有问题,通过adb进入开发板
# ifconfig -a
wlan0 Link encap:Ethernet HWaddr d4:9c:dd:5b:1b:34 Driver bcmsdh_sdmmc
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 TX bytes:0
然后还要查看你的SDIO卡有没有问题 正确的log如下
[ 6.539099] wlan: Loading MWLAN driver
[ 6.543911] wlan: Driver loaded successfully
[ 6.591111] [dhd] dhd_module_init: in Dongle Host Driver, version 100.10.545.23 (r826445-20210723-1)\x0a
[ 6.605750] Registered swp emulation handler
[ 6.617892] nv_bak_path:
[ 6.620540] [dhd] ===========\x0a[drivers/net/wireless/bcmdhd/dhd_linux_platdev.c]:wifi_ctrlfunc_register_drv [568]===============
[ 6.633449] [dhd] ======== dhd_wlan_init_plat_data ========
[ 6.639275] [dhd] ======== Get GPIO from DTS ========
[ 6.644398] [dhd] dhd_wlan_init_gpio: WL_REG_ON=64
[ 6.649223] [dhd] dhd_wifi_platform_load: Enter
[ 6.654528] [dhd] Power-up adapter 'DHD generic adapter'
[ 6.660916] [dhd] wifi_platform_set_power = 1, delay: 200 msec
[ 6.666847] [dhd] ======== PULL WL_REG_ON(64) HIGH! ========
[ 6.682650] Console: switching to colour dummy device 80x25
[ 6.708831] watchdogd: watchdogd started (interval 10, margin 20)!
[ 6.709663] logd.auditd: start
[ 6.718690] logd.klogd: 6714464250
[ 6.839506] zram0: detected capacity change from 0 to 629145600
[ 6.869141] mkswap: Swapspace size: 614396k, UUID=3bd5606a-6210-432e-bb8a-318af056f630
[ 6.896328] Adding 614396k swap on /dev/block/zram0. Priority:-2 extents:1 across:614396k SS
[ 6.970754] wait_for_keymaster: Waiting for Keymaster device
[ 6.980254] [dhd] ====AP6256=======\x0a[drivers/net/wireless/bcmdhd/dhd_linux_platdev.c]:dhd_wifi_platform_load_sdio [875] wifi_platform_set_power no err :1===============
[ 6.996753] [dhd] wifi_platform_bus_enumerate device present 1
[ 7.002788] [dhd] ======== Card detection to detect SDIO card! ========
[ 7.003865] HidlServiceManagement: getService: Trying again for android.hardware.keymaster@4.0::IKeymasterDevice/default...
[ 7.009494] tangwei wifi_card_detect
[ 7.009509] sdhci-esdhc-imx 30b40000.mmc: wifi card detect callback.
[ 7.032921] wait_for_keymaster: List of Keymaster HALs found:
[ 7.035123] type=1400 audit(1643360201.180:5): avc: denied { search } for comm="android.hardwar" name="gsi" dev="mmcblk2p8" ino=20 scontext=u:r:hal_bootctl_default:s0 tcontext=u:object_r:gsi_metadata_file:s0 tclass=dir permissive=1
[ 7.039139] wait_for_keymaster: Keymaster HAL #1: SoftwareKeymasterDevice from Google SecurityLevel: SOFTWARE HAL: android.hardware.keymaster@4.1::IKeymasterDevice/default
[ 7.090312] mmc0: queuing unknown CIS tuple 0x80 (2 bytes)
[ 7.098226] mmc0: queuing unknown CIS tuple 0x80 (3 bytes)
[ 7.106551] mmc0: queuing unknown CIS tuple 0x80 (3 bytes)
[ 7.117393] mmc0: queuing unknown CIS tuple 0x80 (7 bytes)
[ 7.130868] mmc0: queuing unknown CIS tuple 0x81 (9 bytes)
[ 7.265368] mmc0: new ultra high speed SDR104 SDIO card at address 0001
[ 7.272775] type=1400 audit(1643360201.420:6): avc: denied { search } for comm="kworker/1:3" name="mmc0" dev="debugfs" ino=11265 scontext=u:r:kernel:s0 tcontext=u:object_r:debugfs_mmc:s0 tclass=dir permissive=1
[ 7.289436] [dhd] bcmsdh_register: register client driver
[ 7.297235] [dhd] bcmsdh_sdmmc_probe: Enter num=1
[ 7.302279] [dhd] bcmsdh_sdmmc_probe: Enter num=2
[ 7.307017] [dhd] bus num (host idx)=0, slot num (rca)=1
[ 7.312341] [dhd] found adapter info 'DHD generic adapter'
[ 7.318500] [dhd] sdioh_attach: set sd_f2_blocksize 256
[ 7.324073] [dhd] sdioh_attach: sd clock rate = 0
[ 7.332853] [dhd] dhdsdio_probe : no mutex held. set lock
[ 7.339369] [dhd] F1 signature read @0x18000000=0x15294345
[ 7.351868] [dhd] F1 signature OK, socitype:0x1 chip:0x4345 rev:0x9 pkg:0x2
[ 7.364875] [dhd] DHD: dongle ram size is set to 819200(orig 819200) at 0x198000
[ 7.372977] [dhd] dhd_conf_set_chiprev : devid=0xa9bf, chip=0x4345, chiprev=9
[ 7.380146] [dhd] firmware path not found
[ 7.385511] [dhd] CFG80211-ERROR) wl_cfg80211_netdev_notifier_call : wdev null. Do nothing
[ 7.393806] [dhd] CFG80211-ERROR) wl_cfg80211_netdev_notifier_call : wdev null. Do nothing
[ 7.402089] [dhd] CFG80211-ERROR) wl_cfg80211_netdev_notifier_call : wdev null. Do nothing
[ 7.410379] [dhd] CFG80211-ERROR) wl_cfg80211_netdev_notifier_call : wdev null. Do nothing
[ 7.418659] [dhd] CFG80211-ERROR) wl_cfg80211_netdev_notifier_call : wdev null. Do nothing
[ 7.426941] [dhd] CFG80211-ERROR) wl_cfg80211_netdev_notifier_call : wdev null. Do nothing
[ 7.437038] [dhd] dhd_attach(): thread:dhd_watchdog_thread:fc started
[ 7.444169] [dhd] dhd_attach(): thread:dhd_dpc:fd started
[ 7.450602] [dhd] dhd_attach(): thread:dhd_rxf:fe started
[ 7.456014] [dhd] dhd_deferred_work_init: work queue initialized
[ 7.462047] [dhd] dhd_tcpack_suppress_set: TCP ACK Suppress mode 0 -> mode 2
[ 7.469155] [dhd] sdioh_cis_read: func_cis_ptr[0]=0x10ac
[ 7.485174] [dhd] dhdsdio_probe_init: making DHD_BUS_DOWN
[ 7.490721] [dhd] Dongle Host Driver, version 100.10.545.23 (r826445-20210723-1)\x0a
[ 7.500108] [dhd] Register interface [wlan0] MAC: d4:9c:dd:5b:1b:34\x0a
[ 7.507972] [dhd] dhdsdio_probe : the lock is released.
[ 7.513351] [dhd] dhd_module_init: Exit err=0
请硬件的同时确定wifi模块的供电这些都是ok的,那么基本就可以正常使用了。
二、调试方法
2.1 确保模块加载
首先你要有wlan0模块,没有的话是不是你的串口设置有问题,或者你的板级对应的device/nxp的里面的配置没有设置对。
# ifconfig -a
wlan0 Link encap:Ethernet HWaddr d4:9c:dd:5b:1b:34 Driver bcmsdh_sdmmc
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 TX bytes:0
然后通过
1|evk_8mp:/ # iw wlan0 info
Interface wlan0
ifindex 7
wdev 0x1
addr d4:9c:dd:5b:1b:34
type managed
wiphy 0
确保你底层驱动没有问题。 再通过命令去up以下wlan0
tab10_rk68h_n3680:/ # ifconfig wlan0 up
tab10_rk68h_n3680:/ #
tab10_rk68h_n3680:/ # ifconfig wlan0 down
tab10_rk68h_n3680:/ #
这里是不会有打印的
但是
evk_8mp:/ # ifconfig wlan0 up
ifconfig: ioctl 8914: Operation not permitted
如果出现这种情况,那就是有问题的,
这种情况是不是在驱动里面的中断上升延或者下降延搞错了,可以在驱动里面看看
#ifdef HW_OOB
#ifdef HW_OOB_LOW_LEVEL
host_oob_irq_flags = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWLEVEL | IORESOURCE_IRQ_SHAREABLE;
#else
host_oob_irq_flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHLEVEL | IORESOURCE_IRQ_SHAREABLE;
#endif
#else
host_oob_irq_flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE | IORESOURCE_IRQ_SHAREABLE;
#endif
看看他的中断是上升还是下降可以询问硬件确认,把对应的宏定义打开就行了。当然这只是其中一种情况,改了不一定行。
2.2 固件加载
device/fsl / imx8m/evk_8mp/BoardConfig.mk目录下
........
BOARD_HOSTAPD_PRIVATE_LIB_RTL := lib_driver_cmd_rtl
BOARD_WPA_SUPPLICANT_PRIVATE_LIB_RTL := lib_driver_cmd_rtl
BOARD_WPA_SUPPLICANT_PRIVATE_LIB_BCM := lib_driver_cmd_bcmdhd
BOARD_HOSTAPD_PRIVATE_LIB_BCM := lib_driver_cmd_bcmdhd
BOARD_WLAN_VENDOR := AP6256
WIFI_DRIVER_FW_PATH_PARAM := "/sys/module/bcmdhd/parameters/firmware_path"
WIFI_DRIVER_FW_PATH_STA := "/vendor/etc/firmware/bcm/fw_bcm43456c5_ag.bin"
WIFI_DRIVER_FW_PATH_P2P := "/vendor/etc/firmware/bcm/fw_bcm43456c5_ag.bin"
WIFI_DRIVER_FW_PATH_AP := "/vendor/etc/firmware/bcm/fw_bcm43456c5_ag_apsta.bin"
WIFI_DRIVER_MODULE_NAME := "bcmdhd"
#WIFI_DRIVER_MODULE_PATH := "/vendor/lib/modules/bcmdhd.ko"
WIFI_DRIVER_MODULE_ARG := "iface_name=wlan0 firmware_path=/vendor/etc/firmware/bcm/fw_bcm43456c5_ag.bin nvram_path=/vendor/etc/firmware/bcm/nvram_ap6256.txt"
PRODUCT_COPY_FILES += \
device/nxp/imx8m/evk_8mp/firmware/bcm_ap6256/Wi-Fi/fw_bcm43456c5_ag.bin:vendor/etc/firmware/bcm/fw_bcm43456c5_ag.bin \
device/nxp/imx8m/evk_8mp/firmware/bcm_ap6256/Wi-Fi/fw_bcm43456c5_ag_apsta.bin:vendor/etc/firmware/bcm/fw_bcm43456c5_ag_apsta.bin \
device/nxp/imx8m/evk_8mp/firmware/bcm_ap6256/Wi-Fi/fw_bcm43438a0_p2p.bin:vendor/etc/firmware/bcm/fw_bcm43438a0_p2p.bin \
device/nxp/imx8m/evk_8mp/firmware/bcm_ap6256/Wi-Fi/fw_bcm43438a0.bin:vendor/etc/firmware/bcm/fw_bcm43438a0.bin \
device/nxp/imx8m/evk_8mp/firmware/bcm_ap6256/Wi-Fi/fw_bcm43456c5_ag_mfg.bin:vendor/etc/firmware/bcm/fw_bcm43456c5_ag_mfg.bin \
device/nxp/imx8m/evk_8mp/firmware/bcm_ap6256/Wi-Fi/nvram_ap6256.txt:vendor/etc/firmware/bcm/nvram_ap6256.txt \
device/nxp/imx8m/evk_8mp/firmware/bcm_ap6256/BT/BCM4345C5.hcd:vendor/etc/firmware/bcm/BCM4345C5.hcd
#PRODUCT_COPY_FILES += \
device/nxp/imx8m/evk_8mp/wpa_supplicant.conf:vendor/etc/wifi/wpa_supplicant.conf
# BCM fmac wifi driver module
BOARD_VENDOR_KERNEL_MODULES += \
$(KERNEL_OUT)/drivers/net/wireless/bcmdhd/bcmdhd.ko
这个目录下就指定对应的固件目录,然后在你的板子里面去查看有没有对应的固件倒入,还有就是确定你需要的固件是不是WIFI_DRIVER_FW_PATH_STA := “/vendor/etc/firmware/bcm/fw_bcm43456c5_ag.bin” WIFI_DRIVER_FW_PATH_P2P := “/vendor/etc/firmware/bcm/fw_bcm43456c5_ag.bin” 这两个,有的可能用同一个,有的可能不是。还有就是你的固件有没有问题,我记得有次内核版本(可能是这个问题)导致的wifi和蓝牙怎么的都打不开,可以换一下试一试。
PRODUCT_COPY_FILES这就是在编译的时候通过这个宏来吧对应的文件拷贝到目录下。 adb shell查看
evk_8mp:/ # ls vendor/etc/firmware/bcm/
BCM4345C5.hcd fw_bcm43456c5_ag.bin nvram_ap6256.txt
fw_bcm43438a0.bin fw_bcm43456c5_ag_apsta.bin
fw_bcm43438a0_p2p.bin fw_bcm43456c5_ag_mfg.bin
2.3 文件权限
device/fsl / imx8m/evk_8mp/init.rc
在这个目录下
添加这段话
on property:sys.boot_completed=1
chown wifi wifi /sys/module/bcmdhd/parameters/firmware_path
chown wifi wifi /sys/module/bcmdhd/parameters/nvram_path
将文件所属修改为wifi的权限修改是否成功我们也可以在adb的目录下查看
evk_8mp:/ # ls -l /sys/module/bcmdhd/parameters/firmware_path
-rw-rw---- 1 wifi wifi 4096 2022-01-28 10:33 /sys/module/bcmdhd/parameters/firmware_path
evk_8mp:/ # ls -l /sys/module/bcmdhd/parameters/nvram_path
-rw-rw---- 1 wifi wifi 4096 2022-01-28 10:33 /sys/module/bcmdhd/parameters/nvram_path
evk_8mp:/ #
当然wifi还有一大堆的path需要打入到文件里面,这里就说一些我需要注意的点,因为我们很多都是调试驱动,参考原来的源码进行修改,所以我这里也没啥更多的了,自己查看log定位问题很重要。
三、bug解决
目前遇到过一个问题,解决方法也不确定对不对,但是可以确保wifi基本功能使用 1)就是wifi打不开 log可能不是很正确,之前报错的log不知道去哪里了 将就看看把
01-21 02:10:36.465 325 325 I android.hardware.wifi@1.0-service: Wifi HAL started
01-21 02:10:36.466 344 430 V ImxC2Store: ImxC2Store::createInterface !!! name=c2.android.vp9.encoder, ret=2
01-21 02:10:36.466 516 596 I WifiVendorHal: Vendor Hal started successfully
01-21 02:10:36.466 415 760 V C2Store : in ~ComponentModule
01-21 02:10:36.466 415 760 V C2Store : unloading dll
01-21 02:10:36.466 415 760 V C2Store : in init
01-21 02:10:36.466 415 760 V C2Store : loading dll
01-21 02:10:36.468 415 760 I C2SoftVp9Enc: setting temporal layering 0 + 0
01-21 02:10:36.469 415 760 I C2SoftVp9Enc: setting temporal layering 0 + 0
01-21 02:10:36.470 358 487 I Codec2InfoBuilder: adding type 'video/x-vnd.on2.vp9'
01-21 02:10:36.470 516 597 I WifiP2pNative: Registering for interface available listener
01-21 02:10:36.472 415 774 V C2Store : in ~ComponentModule
01-21 02:10:36.472 415 774 V C2Store : unloading dll
01-21 02:10:36.482 325 325 E android.hardware.wifi@1.0-service: Failed to open wlan fw path param: Permission denied
01-21 02:10:36.482 325 325 E android.hardware.wifi@1.0-service: Failed to change firmware mode
01-21 02:10:36.482 516 596 D HalDevMgr: updateRttController: no one is interested in RTT controllers
01-21 02:10:36.483 516 596 E HalDevMgr: executeChipReconfiguration: configureChip error: 9 ()
01-21 02:10:36.484 516 596 E WifiVendorHal: Failed to create STA iface
01-21 02:10:36.484 516 645 D CCodec : allocate(c2.android.vorbis.decoder)
01-21 02:10:36.484 516 596 E WifiNative: Failed to create iface in vendor HAL
01-21 02:10:36.485 516 596 E WifiClientModeManager: Failed to create ClientInterface. Sit in Idle
01-21 02:10:36.486 516 644 D CCodec : allocate(c2.android.vorbis.decoder)
01-21 02:10:36.488 516 645 I Codec2Client: Available Codec2 services: "default" "software"
01-21 02:10:36.488 516 596 D WifiScanRequestProxy: Sending scan available broadcast: false
01-21 02:10:36.490 516 599 I WifiScanningService: Received a request to disable scanning, UID = 1000
01-21 02:10:36.490 516 645 I CCodec : setting up 'default' as default (vendor) store
01-21 02:10:36.490 516 644 I CCodec : setting up 'default' as default (vendor) store
01-21 02:10:36.493 344 430 V ImxC2Store: ImxC2Store::createComponent name=c2.android.vorbis.decoder, ret=2
01-21 02:10:36.493 344 344 V ImxC2Store: ImxC2Store::createComponent name=c2.android.vorbis.decoder, ret=2
01-21 02:10:36.495 415 774 V C2Store : in init
01-21 02:10:36.496 415 774 V C2Store : loading dll
01-21 02:10:36.496 516 516 I system_server: getFrameworkCompatibilityMatrix: Successfully processed VINTF information
01-21 02:10:36.496 516 516 I system_server: getDeviceCompatibilityMatrix: Reading VINTF information.
01-21 02:10:36.497 516 599 I WifiScanningService: wifi driver unloaded
我的错误是hal的报错,hal层有一个insmod的函数,报错是在这里面打出来的,主要是insmod的时候失败了,根据log可以看出是没有找到wifi的固件的路径,从而导致的wifi路径加载失败。
01-21 02:10:36.482 325 325 E android.hardware.wifi@1.0-service: Failed to open wlan fw path param: Permission denied
01-21 02:10:36.482 325 325 E android.hardware.wifi@1.0-service: Failed to change firmware mode
我们通过adb可以去查看对应的的配置文件下的路径 在/device/nxp/ imx8m/evk_8mp/BoardConfig.mk目录下可以看到这样一句话
WIFI_DRIVER_FW_PATH_PARAM := "/sys/module/bcmdhd/parameters/firmware_path"
然后我们通过adb进入板子去cat下路径,
evk_8mp:/ # cat /sys/module/bcmdhd/parameters/firmware_path
evk_8mp:/ # cat /sys/module/bcmdhd/parameters/nvram_path
因为这两个文件有关于wifi的固件的路径 如果是首次开机,cat里面的内容应该是空的,所以不用担心,但是如果是点击开启wifi的按钮后在去cat,那么里面就会显示出对应的路径
evk_8mp:/ # cat /sys/module/bcmdhd/parameters/firmware_path
/vendor/etc/firmware/bcm/fw_bcm43456c5_ag.bin
evk_8mp:/ # cat /sys/module/bcmdhd/parameters/nvram_path
/vendor/etc/firmware/bcm/nvram_ap6256.txt
我当时的bug在与我的nvram_path 路径下没有对应的路径文件指定,所以会导致wifi打不开,我手动echo命令把路径写进取,然后就可以打开wifi了,所以bug点就在这里。 因为对于Android的架构这些都不是很熟悉,所以我直接在驱动里面将文件路径给他写死,那么就可以了吧,尝试了下,发现确实可以。
linux-imx / drivers/net/wireless/bcmdhd/dhd_linux.c
char firmware_path[MOD_PARAM_PATHLEN];
char nvram_path[MOD_PARAM_PATHLEN] = "/vendor/etc/firmware/bcm/nvram_ap6256.txt";
标准的流程因该是调用接口将代码写进去,但是我不知道那里有问题,所以就直接在这里给他定死,就可以了。
|