CanMV K230 开发板移植 wifi 模块

Viewed 352

重现步骤

我尝试使用 CanMV-K230_debian_sdcard_sdk_1.3.img.gz 在 CanMV K230 启动 debian,但我使用 ifconfig 查看网络接口时发现没有无线网络驱动。但使用 CanMV-K230_sdcard_v1.7_nncase_v2.9.0.img.gz 启动的 buildroot 系统存在 wlan0 和 wlan1 两个接口。我想将 buildroot 中的 wifi 模块移植到 debian 上。

期待结果和实际结果

我现在希望在 debian 中安装好 wifi 驱动,并且我也知道对应的模块名称为 bcmdhd。但实际上在 dmesg 中和 ifconfig 中都没有 wifi 相关的信息。

软硬件版本信息

开发板名称:CanMV K230
WiFi模块:AP6212 L318400912414
内核:Linux 5.10.4
发行版:Debian trixie/sid

尝试解决过程

因为 buildroot 和 debian 的 Linux 内核版本相同,我尝试将 CanMV-K230_sdcard_v1.7_nncase_v2.9.0.img.gz 中的 /lib/modules/5.10.4 拷贝到 debian 的对应路径,然后重启的 dmesg 输出见错误日志:

我也找到了 bcmdhd 对应的模块源码 https://github.com/StreamUnlimited/broadcom-bcmdhd-4359 以及固件 https://github.com/HiFDW/broadcom-ap6212/

请问接下来我应该怎么做?

错误日志

[  OK  ] Started NetworkManager.service - Network Manager.
[   32.925997] [dhd] failed to power up DHD generic adapter, 0 retry left
[  OK  ] Started NetworkManag[   32.955283] [dhd] wifi_platform_set_power = 0, delay: 0 msec
er-dispatcher.�[   32.961896] [dhd] ======== PULL WL_REG_ON(1) LOW! ========
� Manager Sc[   32.968726] [dhd] wifi_platform_bus_enumerate device present 0
ript Dispatcher [   32.975930] [dhd] ======== Card detection to remove SDIO card! ========
Service.
[   32.983935] [dhd] failed to power up DHD generic adapter, max retry reached**
[   32.992006] [dhd] unregister wifi platform drivers
[   32.996807] [dhd] wifi_platform_bus_enumerate device present 0
[   33.002648] [dhd] ======== Card detection to remove SDIO card! ========
[   33.009272] [dhd] dhd_wlan_deinit_gpio: gpio_free(WL_REG_ON 1)
[   33.015121] [dhd] _dhd_module_init: Failed to load the driver, try cnt 0
[   33.021848] [dhd] _dhd_module_init: Failed to load driver max retry reached**
[   33.028996] [dhd] STATIC-MSG) dhd_static_buf_exit : Enter
[   33.034468] [dhd] _dhd_module_init: Exit err=-19
[***   ] Job ifupdown-pre.service/start running (23s / 3min 3s)
[   39.325657] [dhd] _dhd_module_init: in Dongle Host Driver, version 101.10.361.33 (wlan=r892223-20230607-2)
[   39.325657] drivers/net/wireless/bcmdhd compiled on Aug 26 2024 at 15:28:32
[   39.325657] 
[   39.343823] [dhd] STATIC-MSG) dhd_static_buf_init : 101.10.361.31 (wlan=r892223-20230427-1)
[   39.352249] [dhd] STATIC-MSG) dhd_init_wlan_mem : prealloc ok for index 0: 1100800(1075K)
[   39.360468] [dhd] ======== Get GPIO from DTS(android,bcmdhd_wlan) ========
[   39.367383] of_get_named_gpiod_flags: parsed 'gpio_wl_reg_on' property of node '/soc/sdhci0@91580000/bcmdhd_wlan[0]' - status (0)
[   39.379060] [dhd] dhd_wlan_init_gpio: WL_REG_ON=1
[   39.383772] [dhd] dhd_wifi_platform_load: Enter
[   39.388309] [dhd] Power-up adapter 'DHD generic adapter'
[   39.395030] dummy_sdmmc: probe of mmc0:0001:1 failed with error -110
[   39.401552] dummy_sdmmc: probe of mmc0:0001:2 failed with error -110
[   39.408008] [dhd] wifi_platform_set_power = 1, delay: 200 msec
[   39.413855] [dhd] ======== PULL WL_REG_ON(1) HIGH! ========
[   39.625906] [dhd] wifi_platform_bus_enumerate device present 1
[     *] Job ifupdown-pre.service/start running (25s / 3min 3s)
[   41.661915] [dhd] failed to power up DHD generic adapter, 0 retry left
[   41.685982] [dhd] wifi_platform_set_power = 0, delay: 0 msec
[   41.691662] [dhd] ======== PULL WL_REG_ON(1) LOW! ========
[   41.697179] [dhd] wifi_platform_bus_enumerate device present 0
[   41.703022] [dhd] ======== Card detection to remove SDIO card! ========
[   41.709653] [dhd] failed to power up DHD generic adapter, max retry reached**
[   41.716795] [dhd] unregister wifi platform drivers
[   41.721592] [dhd] wifi_platform_bus_enumerate device present 0
[   41.727435] [dhd] ======== Card detection to remove SDIO card! ========
[   41.734059] [dhd] dhd_wlan_deinit_gpio: gpio_free(WL_REG_ON 1)
[   41.739903] [dhd] _dhd_module_init: Failed to load the driver, try cnt 0
[   41.746641] [dhd] Error creating socket.
[   41.750584] [dhd] _dhd_module_init: Failed to load driver max retry reached**
[   41.757732] [dhd] STATIC-MSG) dhd_static_buf_exit : Enter
[  OK  ] Finished ifupdown-pre.service - He…o synchronize boot up for ifupdown.

补充材料

1 Answers

问题初步得到解决,简要叙述过程如下:

  1. 首先同时按照流程部署好 https://github.com/kendryte/k230_sdkhttps://github.com/kendryte/k230_linux_sdk 并且确保你可以生成对应的镜像并且在开发板可以正常启动。

  2. 解包你在 https://developer.canaan-creative.com/k230/dev/zh/03_other/K230_debian_ubuntu%E8%AF%B4%E6%98%8E.html#k230-debian 这一节中的 debian13.ext4,并将 k230_linux_sdk 中原来 buildroot 的 /etc/firmware/lib/modules 路径放入 debian rootfs 的对应路径中,并重新打包 debian13.ext4

  3. 使用相关方法提取 k230_linux_sdk/buildroot-overlay/board/canaan/k230-soc/post-image.sh 的运行命令、参数以及环境变量。

    • 运行命令很简单,就是 k230_linux_sdk/buildroot-overlay/board/canaan/k230-soc/post-image.sh
    • 运行参数有四个,images 路径、设备型号、linux 源码目录、rootfs.ext4路径。(建议使用绝对路径)
    • 环境变量的话建议对比与不运行脚本时环境变量的情况,看看增加了哪些环境变量,然后加载命令的前面。
    • 我的最终命令为(使用 root 权限运行) ACLOCAL_PATH=/home/junyu33/Desktop/github/k230_linux_sdk/output/k230_canmv_defconfig/host/riscv64-buildroot-linux-gnu/sysroot/usr/share/aclocal:/home/junyu33/Desktop/github/k230_linux_sdk/output/k230_canmv_defconfig/host/share/aclocal BINARIES_DIR=/home/junyu33/Desktop/github/k230_linux_sdk/output/k230_canmv_defconfig/images BASE_DIR=/home/junyu33/Desktop/github/k230_linux_sdk/output/k230_canmv_defconfig BR2_CONFIG=/home/junyu33/Desktop/github/k230_linux_sdk/output/k230_canmv_defconfig/.config BR2_DL_DIR=/home/junyu33/Desktop/github/k230_linux_sdk/output/buildroot-2024.02.1/../../dl BR2_VERSION=2024.02.1 BR2_VERSION_FULL=-g8d50485-dirty BR_COMPILER_PARANOID_UNSAFE_PATH=enabled BUILD_DIR=/home/junyu33/Desktop/github/k230_linux_sdk/output/k230_canmv_defconfig/build BUILDROOT_CONFIG=/tmp/deprecated/The-BUILDROOT_CONFIG-environment-variable-was-renamed-to-BR2_CONFIG BZR=bzr ./buildroot-overlay/board/canaan/k230-soc/post-image.sh /home/junyu33/Desktop/github/k230_linux_sdk/output/k230_canmv_defconfig/images k230-canmv /home/junyu33/Desktop/github/k230_linux_sdk/output/k230_canmv_defconfig/build/linux-3c3f4061b727e6d0e2293357a7475b578d688d92 /home/junyu33/Desktop/tmp/debian13.ext4
  4. 提取 k230_linux_sdk/output/k230_canmv_defconfig/images/sysimage-sdcard.img 并烧录至 TF 卡。

具体过程以及踩过的坑择时将写入个人博客 blog.junyu33.me 中。