一、概述
??本文讲述RK3568上移植OpenHarmony 3.2适配WIFI以及相关内容。 ??硬件芯片:海华AW-NM372S ??芯片模组:43438A1
注:芯片的具体模组可以在芯片手册上查看,一般分为Boardcom(博通)/Cypress,realtek,海思等
其中海华AW-NM372S芯片基于博通43438A1模组,常见的还有正基AP6xxx芯片,都是基于博通模组;博通已经被cypress收购
1.1 WLAN固件
??WLAN固件是相当于WLAN芯片里面的一个小系统,你可以把WLAN芯片看成一个单片机,里面需要跑代码才可以和我们的SoC进行PY交易,这份固件由原厂提供,为.bin后缀。一般名字中会包含43438A1之类的芯片模组。
注:使用另外的文件作为固件的有博通和海思,而realtek则是把固件写到了驱动中去
1.2 nvram.txt
??这个文件用给固件读取并修正一些参数,来使得wlan芯片工作在最好状态下,同样由原厂提供。 ?
二、内核部分
2.1 修改设备树
??其中: ??(1)sdio_pwrseq节点用于自动上点,其中reset-gpios是用于复位,对应wlan芯片上的wreg_on引脚,这里特别需要主要电平属性,高电平复位就选择GPIO_ACTIVE_HIGH,低电平复位就GPIO_ACTIVE_LOW,根据你的板子设计来调整引脚号和引脚的电平属性;如果你的芯片还有一个引脚控制wlan芯片供电的话,需要添加power-gpios子节点**(这里笔者记得不是很清楚了,可以调试一下)** ??(2)wireless_wlan节点是wifi的适配节点,wifi_chip_type 这个属性可以被忽略,填ap-6255即可,host_wake_irq引脚根据你核心板来定义 ??(3)sdmmc2对应sdio的接口的属性,这里面的节点不做过多追溯,自己看下
/ {
sdio_pwrseq: sdio-pwrseq {
compatible = "mmc-pwrseq-simple";
pinctrl-names = "default";
pinctrl-0 = <&wifi_enable_h>;
reset-gpios = <&gpio4 RK_PA1 GPIO_ACTIVE_LOW>;
status = "okay";
};
wireless_wlan: wireless-wlan {
compatible = "wlan-platdata";
rockchip,grf = <&grf>;
wifi_chip_type = "ap-6255";
clocks = <&rk809 1>;
clock-names = "ext_clock";
pinctrl-names = "default";
pinctrl-0 = <&wifi_wake_host>;
WIFI,host_wake_irq = <&gpio4 RK_P2 GPIO_ACTIVE_HIGH>;
status = "okay";
};
};
&sdmmc2 {
max-frequency = <150000000>;
supports-sdio;
bus-width = <4>;
disable-wp;
cap-sd-highspeed;
cap-sdio-irq;
keep-power-in-suspend;
mmc-pwrseq = <&sdio_pwrseq>;
non-removable;
pinctrl-names = "default";
pinctrl-0 = <&sdmmc2m0_bus4 &sdmmc2m0_cmd &sdmmc2m0_clk>;
sd-uhs-sdr104;
status = "okay";
};
&pinctrl {
wireless-wlan {
wifi_wake_host: wifi-wake-host {
rockchip,pins = <4 RK_PA2 RK_FUNC_GPIO &pcfg_pull_down>;
};
};
sdio-pwrseq {
wifi_enable_h: wifi-enable-h {
rockchip,pins = <4 RK_PA1 RK_FUNC_GPIO &pcfg_pull_up>;
};
};
};
2.2 内核配置部分
??这里可以去看rockchip_linux_defconfig或者rk3568_defconfig这个文件(rockchip_linux_defconfig只是rk3568_defconfig在编译内核时候的拷贝),那么你可以看到android和openharmony的区别了,android中,wlan芯片的驱动是编译成.ko,然后再复制到系统中,在启动的时候根据SDIO中读取的PID和VID值去比对,再加载对应驱动;在openharmony中,wlan驱动模块是一开始就加载到内核中去,随着内核启动一起启动。 ??android的这种做法可以同时兼容多个wlan芯片,这个我觉得openharmony可以考虑一下去改进。 ??这里的CONFIG_BCMDHD_FW_PATH和CONFIG_BCMDHD_NVRAM_PATH指定了frimware的固件和nvram.txt的路径
CONFIG_WL_ROCKCHIP=y
# CONFIG_WIFI_BUILD_MODULE is not set
CONFIG_WIFI_LOAD_DRIVER_WHEN_KERNEL_BOOTUP=y
# CONFIG_WIFI_GENERATE_RANDOM_MAC_ADDR is not set
CONFIG_BCMDHD=y
CONFIG_AP6XXX_WIFI6=y
CONFIG_BCMDHD_FW_PATH="/vendor/etc/firmware/fw_bcm43438a1.bin"
CONFIG_BCMDHD_NVRAM_PATH="/vendor/etc/firmware/nvram.txt"
# CONFIG_BCMDHD_STATIC_IF is not set
# CONFIG_MAC80211_HWSIM is not set
CONFIG_USB_NET_RNDIS_WLAN=y
# CONFIG_VIRT_WIFI is not set
三、系统适配部分
??那么接下来就是搬运固件和nvram.txt即可; ??首先在device/soc/rockchip/rk3568/hardware/wifi 目录下面创建属于我们芯片的目录比如nm372, ??然后把我们从原厂那里拿到的固件放进去,再修改以下内容,其中 NM372_ETC_DIR 就是我们刚才创建的目录,group(“nm372”) 中deps ohos_prebuilt_etc(“fw_bcm43438a1.bin”) 和ohos_prebuilt_etc(“nvram.txt”),意思是nm372这个组依赖于fw_bcm43438a1.bin和nvram.txt两个编译动作。 ??并且可以看到resolv.conf被我单独抽出来作为一个组,因为所有芯片都会用到这个文件,所以剥离出来。
device/soc/rockchip/rk3568/hardware/wifi/BUILD.gn
# Copyright (C) 2021 HiHope Open Source Organization .
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//build/ohos.gni")
AP6XXX_ETC_DIR = "//device/soc/rockchip/rk3568/hardware/wifi/ap6xxx"
NM372_ETC_DIR = "//device/soc/rockchip/rk3568/hardware/wifi/nm372"
DNS_CONFIG_DIR = "//device/soc/rockchip/rk3568/hardware/wifi"
ohos_prebuilt_etc("clm_bcm43752a2_ag.blob") {
source = "$AP6XXX_ETC_DIR/clm_bcm43752a2_ag.blob"
install_images = [ vendor_base_dir ]
relative_install_dir = "firmware"
part_name = "rockchip_products"
install_enable = true
}
ohos_prebuilt_etc("fw_bcm43752a2_ag_apsta.bin") {
source = "$AP6XXX_ETC_DIR/fw_bcm43752a2_ag_apsta.bin"
install_images = [ vendor_base_dir ]
relative_install_dir = "firmware"
part_name = "rockchip_products"
install_enable = true
}
ohos_prebuilt_etc("fw_bcm43752a2_ag.bin") {
source = "$AP6XXX_ETC_DIR/fw_bcm43752a2_ag.bin"
install_images = [ vendor_base_dir ]
relative_install_dir = "firmware"
part_name = "rockchip_products"
install_enable = true
}
ohos_prebuilt_etc("nvram_ap6275s.txt") {
source = "$AP6XXX_ETC_DIR/nvram_ap6275s.txt"
install_images = [ vendor_base_dir ]
relative_install_dir = "firmware"
part_name = "rockchip_products"
install_enable = true
}
ohos_prebuilt_etc("fw_bcm43438a1.bin") {
source = "$NM372_ETC_DIR/fw_bcm43438a1.bin"
install_images = [ vendor_base_dir ]
relative_install_dir = "firmware"
part_name = "rockchip_products"
install_enable = true
}
ohos_prebuilt_etc("nvram.txt") {
source = "$NM372_ETC_DIR/nvram.txt"
install_images = [ vendor_base_dir ]
relative_install_dir = "firmware"
part_name = "rockchip_products"
install_enable = true
}
ohos_prebuilt_etc("resolv.conf") {
source = "$DNS_CONFIG_DIR/etc/resolv.conf"
install_images = [ "system" ]
part_name = "rockchip_products"
install_enable = true
}
group("ap6xxx") {
deps = [
":clm_bcm43752a2_ag.blob",
":fw_bcm43752a2_ag.bin",
":fw_bcm43752a2_ag_apsta.bin",
":nvram_ap6275s.txt",
]
}
group("nm372") {
deps = [
":fw_bcm43438a1.bin",
":nvram.txt",
]
}
group("resolv_conf") {
deps = [
":resolv.conf",
]
}
我们抽出一个来进行细看
ohos_prebuilt_etc("fw_bcm43438a1.bin") {
source = "$NM372_ETC_DIR/fw_bcm43438a1.bin"
install_images = [ vendor_base_dir ]
relative_install_dir = "firmware"
part_name = "rockchip_products"
install_enable = true
}
那么我们的nm372这个group又由谁制定呢?我们来看上一层的BUILD.gn,把它改成下面的形式,记得也把wifi:resolv_conf这个使能
device/soc/rockchip/rk3568/hardware/BUILD.gn
import("//build/ohos.gni")
group("hardware_group") {
deps = [
"//device/soc/rockchip/rk3568/hardware/gpu:mali-bifrost-g52-g2p0-ohos",
"//device/soc/rockchip/rk3568/hardware/isp:isp",
"//device/soc/rockchip/rk3568/hardware/mpp:mpp",
"//device/soc/rockchip/rk3568/hardware/wifi:nm372",
"//device/soc/rockchip/rk3568/hardware/wifi:resolv_conf",
]
}
由于hardware_group已经被指定编译,那么编译的时候就会顺着这个几个编译路径一直走下去,最终把我们需要的文件复制到对应的路径去。
|