wifi driver debugging of nxp

Posted by FastLaneHosting on Sat, 29 Jan 2022 08:11:52 +0100


I feel that compared with Bluetooth, wifi requires a lot of things to be configured in the hal layer and android upper layer, and the configuration is relatively simple for the lower layer.

1, Device tree configuration

Matching drive

ap6256_wifi: ap6256_wifi {
    compatible = "android,bcmdhd_wlan";
    pinctrl-names = "default";
    pinctrl-0 = <&pinctrl_wlan>;
    gpio_wl_reg_on = <&gpio3 0 GPIO_ACTIVE_HIGH>;   /*GPIO3_IO00    WIFI_REG_ON OUT HI*/
    gpio_wl_host_wake = <&gpio3 7 GPIO_ACTIVE_LOW>; /*GPIO3_IO07    WIFI_HOST_WAKE*/
};

......

    pinctrl_wlan: wlangrp {
        fsl,pins = <
            MX8MP_IOMUXC_NAND_DATA01__GPIO3_IO07    0x16 /* WL_WAKE_HOST    GPIO3_IO07*/
            MX8MP_IOMUXC_NAND_ALE__GPIO3_IO00   0x41    /*GPIO3_IO00    WIFI_REG_ON OUT HI*/
        >;
    };

Then look at the hardware description. We need to ensure the normal use of serial port for serial communication between BT and WIFI.
This is the most basic function. If there is no problem with your upper layer configuration at this time, enter the development board through 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 

Then check if there is any problem with your SDIO card
The correct log is as follows

[    6.539099] wlan: Loading MWLAN driver
[    6.543911] wlan: Driver loaded successfully
//Driven printing
[    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! ========
//The added log is OK
[    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
//Confirm that the loading of the module is completed

Please make sure that the power supply of wifi module is ok while the hardware is, so it can be used normally.

2, Debugging method

2.1 ensure module loading

First of all, you need to have WLAN 0 module. If not, is there a problem with your serial port setting, or the configuration of your board level corresponding device/nxp is not set correctly.

# 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

Then pass

1|evk_8mp:/ # iw wlan0 info                                                    
Interface wlan0
	ifindex 7
	wdev 0x1
	addr d4:9c:dd:5b:1b:34
	type managed
	wiphy 0

Make sure you have no problems with the underlying drivers.
Then use the command to up the following wlan0

tab10_rk68h_n3680:/ # ifconfig wlan0 up                                        
tab10_rk68h_n3680:/ # 
tab10_rk68h_n3680:/ # ifconfig wlan0 down                                      
tab10_rk68h_n3680:/ # 
There will be no printing here
 however
evk_8mp:/ # ifconfig wlan0 up                                                  
ifconfig: ioctl 8914: Operation not permitted
 If this happens, there is a problem,

Whether the interrupt rising delay or falling delay in the driver is wrong can be seen in the driver

#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

To see whether the interrupt is rising or falling, you can ask the hardware for confirmation and open the corresponding macro definition. Of course, this is only one of the cases. If it is changed, it may not work.

2.2 firmware loading

device/fsl / imx8m/evk_8mp/BoardConfig.mk Under the directory
........
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


Specify the corresponding firmware directory under this directory, and then check whether there is corresponding firmware in your board, and determine whether the firmware you need is 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"
These two, some may use the same one, some may not. There is also a problem with your firmware. I remember that there was a time when wifi and Bluetooth couldn't be turned on due to the kernel version (possibly this problem). You can change it and have a try.

PRODUCT_COPY_FILES is to copy the corresponding files to the directory through this macro during compilation.
adb shell View

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 file permissions

device/fsl / imx8m/evk_8mp/init.rc
 Under this directory

Add this paragraph
//on property:wlan.driver.status=ok
on property:sys.boot_completed=1
    chown wifi wifi /sys/module/bcmdhd/parameters/firmware_path
    chown wifi wifi /sys/module/bcmdhd/parameters/nvram_path
    
Change the file to wifi We can also check whether the permission modification of is successful adb View under the directory of

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:/ # 

Of course, wifi also has a lot of path s that need to be entered into the file. Here are some points I need to pay attention to, because many of us are debugging drivers and modify them with reference to the original source code, so I don't have much more here. It's important to check the log location by myself.

3, bug resolution

At present, I have encountered a problem, and the solution is uncertain, but it can ensure the use of basic wifi functions
1) The wifi doesn't work
The log may not be very correct. I don't know where the log that reported an error has gone. I'll take a look

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

My error is the error report of hal. The hal layer has an insmod function. The error report is typed here. It is mainly because insmod fails. According to the log, we can see that the path of wifi firmware is not found, resulting in the failure of wifi path loading.

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

We can check the path under the corresponding configuration file through adb
In / device / NXP / imx8m / evk_ 8mp/BoardConfig. You can see this sentence in the MK directory

WIFI_DRIVER_FW_PATH_PARAM := "/sys/module/bcmdhd/parameters/firmware_path"

Then we enter the board through adb and go to the path under cat,

evk_8mp:/ # cat /sys/module/bcmdhd/parameters/firmware_path

evk_8mp:/ # cat /sys/module/bcmdhd/parameters/nvram_path 

Because these two files have the path of wifi firmware
If it is the first boot, the content in cat should be empty, so don't worry, but if you click the start wifi button to go to cat, the corresponding path will be displayed

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

My bug was with my NVRAM_ There is no corresponding path file specified under the path, so wifi cannot be opened. I manually write the path with echo command, and then wifi can be opened. So the bug point is here.
Because I'm not very familiar with the architecture of Android, I directly write the file path to him in the driver. Then it's OK. I've tried and found that it's OK.

linux-imx / drivers/net/wireless/bcmdhd/dhd_linux.c

char firmware_path[MOD_PARAM_PATHLEN];
/*char nvram_path[MOD_PARAM_PATHLEN] =;*/
char nvram_path[MOD_PARAM_PATHLEN] = "/vendor/etc/firmware/bcm/nvram_ap6256.txt";

The standard process should be to call the interface to write the code, but I don't know there is a problem, so I'll just kill him here.

Topics: network