鸿蒙移植添加hdf驱动框架
接上一篇,添加的linux内核到openharmony,现在我们添加hdf驱动框架到linux内核,需要修改kernel/linux/patches/linux-5.4/t113_nand_linux_patch/目录中的hdf.patch文件
diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.Sindex 23150c0f0..dce3220b7 100644--- a/arch/arm/kernel/vmlinux.lds.S+++ b/arch/arm/kernel/vmlinux.lds.S@@ -121,6 +121,14 @@ SECTIONS __pv_table_end = .; }+#ifdef CONFIG_DRIVERS_HDF+.init.hdf_table : {+ _hdf_drivers_start = .;+ *(.hdf.driver)+ _hdf_drivers_end = .;+}+#endif+ INIT_DATA_SECTION(16) .exit.data : {diff --git a/drivers/Kconfig b/drivers/Kconfigindex bb61ac8b7..a61d5d807 100644--- a/drivers/Kconfig+++ b/drivers/Kconfig@@ -233,4 +233,5 @@ source "drivers/interconnect/Kconfig" source "drivers/counter/Kconfig"+source "drivers/hdf/khdf/Kconfig" endmenudiff --git a/drivers/Makefile b/drivers/Makefileindex 80c49c1a4..b48758b86 100644--- a/drivers/Makefile+++ b/drivers/Makefile@@ -188,3 +188,4 @@ obj-$(CONFIG_SIOX) += siox/ obj-$(CONFIG_GNSS) += gnss/ obj-$(CONFIG_INTERCONNECT) += interconnect/ obj-$(CONFIG_COUNTER) += counter/+obj-$(CONFIG_DRIVERS_HDF) += hdf/diff --git a/drivers/hdf/Makefile b/drivers/hdf/Makefilenew file mode 100644index 000000000000..819768c96092--- /dev/null+++ b/drivers/hdf/Makefile@@ -0,0 +1,3 @@+export HDF_RELATIVE_PATH := drivers/huawei_platform/hdf+export PROJECT_ROOT := ../../../../../+obj-$(CONFIG_DRIVERS_HDF) += khdf/diff --git a/drivers/hdf/framework b/drivers/hdf/frameworknew file mode 120000index 000000000000..1fdb7cbb9f34--- /dev/null+++ b/drivers/hdf/framework@@ -0,0 +1 @@+../../../../../../../drivers/framework\ No newline at end of filediff --git a/drivers/hdf/khdf b/drivers/hdf/khdfnew file mode 120000index 000000000000..0cc53cd109c0--- /dev/null+++ b/drivers/hdf/khdf@@ -0,0 +1 @@+../../../../../../../drivers/adapter/khdf/linux\ No newline at end of filediff --git a/include/hdf b/include/hdfnew file mode 120000index 000000000000..c85d8ced0400--- /dev/null+++ b/include/hdf@@ -0,0 +1 @@+../../../../../../drivers/framework/include\ No newline at end of file--2.25.1
增加以上修改点,需要注意的文件为arch/arm/kernel/vmlinux.lds.S,drivers/Kconfig,drivers/Makefile文件,可能会存在差异,需要根据情况自行生成patch文件,不然编译过程会产生无法打上pathc文件。添加完成后开始编译,可以看到,报错了,报错信息如下
scripts/Makefile.build:42: drivers/hdf/khdf/../../../../vendor/xingyun/t113_nand/hdf_config/Makefile: No such file or directory[OHOS ERROR] make[5]: * No rule to make target 'drivers/hdf/khdf/../../../../vendor/xingyun/t113_nand/hdf_config/Makefile'. Stop.[OHOS ERROR] scripts/Makefile.build:556: recipe for target 'drivers/hdf/khdf/../../../../vendor/xingyun/t113_nand/hdf_config' failed[OHOS ERROR] make[4]: * [drivers/hdf/khdf/../../../../vendor/xingyun/t113_nand/hdf_config] Error 2[OHOS ERROR] scripts/Makefile.build:556: recipe for target 'drivers/hdf/khdf' failed[OHOS ERROR] make[3]: * [drivers/hdf/khdf] Error 2[OHOS ERROR] scripts/Makefile.build:556: recipe for target 'drivers/hdf' failed[OHOS ERROR] make[2]: * [drivers/hdf] Error 2[OHOS ERROR] make[2]: * Waiting for unfinished jobs....
很明显,提示没有vendor/xingyun/t113_nand/hdf_config/Makefile文件,此时我们可以拷贝 hisilicon目录下的文件作为我们的文件使用,使用命令执行。
cp hisilicon/hispark_taurus_linux/hdf_config xingyun/t113_nand/ -r
然后删除多余的文件,只保留hdf.hcs和 Makefile文件,然后使用hb build -f指令重新编译,很遗憾,还是报错,如果是如下报错,多是因为linux内核版本没有适配的情况
drivers/hdf/khdf/model/usb/device/f_generic.c:1608:4: error: implicit declaration of function 'swait_active' [-Werror,-Wimplicit-function-declaration][OHOS ERROR] swait_active(&ffs->ep0req_completion.wait) ||
找到文件,f_generic.c,如果按照编译提示的错误路径去找,找不到如下文件,可以使用命令
find -name f_generic.c
然后确定文件路径为
./drivers/adapter/khdf/linux/model/usb/device/f_generic.c
打开文件找到如下函数
static void ffs_data_put(struct ffs_data *ffs){ ENTER(); if (unlikely(refcount_dec_and_test(&ffs->ref))) { pr_info("%s(): freeing\n", __func__); ffs_data_clear(ffs); BUG_ON(waitqueue_active(&ffs->ev.waitq) ||#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,0,0) swait_active(&ffs->ep0req_completion.wait) ||#else waitqueue_active(&ffs->ep0req_completion.wait) ||#endif waitqueue_active(&ffs->wait) || waitqueue_active(&ffs->wait_que)); destroy_workqueue(ffs->io_completion_wq); kfree(ffs); }}
修改点如下
diff --git a/drivers/adapter/khdf/linux/model/usb/device/f_generic.c b/drivers/adapter/khdf/linux/model/usb/device/f_generic.cindex 6878c95797..fed0674f56 100644--- a/drivers/adapter/khdf/linux/model/usb/device/f_generic.c+++ b/drivers/adapter/khdf/linux/model/usb/device/f_generic.c@@ -1604,7 +1604,7 @@ static void ffs_data_put(struct ffs_data *ffs) pr_info("%s(): freeing\n", __func__); ffs_data_clear(ffs); BUG_ON(waitqueue_active(&ffs->ev.waitq) ||-#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,0,0)+#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,6,0) swait_active(&ffs->ep0req_completion.wait) || #else waitqueue_active(&ffs->ep0req_completion.wait) ||
修改成比我们的内核版本高就行,然后重新编译。
drivers/../../../../../../drivers/peripheral/audio/chipsets/tfa9879/accessory/src/tfa9879_accessory_impl.o: In function `Tfa9879RegRw':[OHOS ERROR] /home/d1/openHarmony/t113/out/t113_nand_linux/xingyun_t113_nand_board/kernel/linux-5.4/drivers/hdf/khdf/model/audio/../../../../../../drivers/peripheral/audio/chipsets/tfa9879/accessory/src/tfa9879_accessory_impl.c:213: undefined reference to `I2cOpen'[OHOS ERROR] /home/d1/openHarmony/t113/out/t113_nand_linux/xingyun_t113_nand_board/kernel/linux-5.4/drivers/hdf/khdf/model/audio/../../../../../../drivers/peripheral/audio/chipsets/tfa9879/accessory/src/tfa9879_accessory_impl.c:224: undefined reference to `I2cClose'[OHOS ERROR] /home/d1/openHarmony/t113/out/t113_nand_linux/xingyun_t113_nand_board/kernel/linux-5.4/drivers/hdf/khdf/model/audio/../../../../../../drivers/peripheral/audio/chipsets/tfa9879/accessory/src/tfa9879_accessory_impl.c:227: undefined reference to `I2cTransfer'[OHOS ERROR] drivers/../../../../../../drivers/peripheral/audio/chipsets/tfa9879/accessory/src/tfa9879_accessory_impl.o: In function `ReleaseObject':[OHOS ERROR] /home/d1/openHarmony/t113/out/t113_nand_linux/xingyun_t113_nand_board/kernel/linux-5.4/drivers/hdf/khdf/model/audio/../../../../../../drivers/peripheral/audio/chipsets/tfa9879/accessory/src/tfa9879_accessory_impl.c:151: undefined reference to `I2cClose'[OHOS ERROR] drivers/../../../../../../drivers/peripheral/audio/chipsets/tfa9879/accessory/src/tfa9879_accessory_impl.o: In function `Gpio06PinInit':[OHOS ERROR] /home/d1/openHarmony/t113/out/t113_nand_linux/xingyun_t113_nand_board/kernel/linux-5.4/drivers/hdf/khdf/model/audio/../../../../../../drivers/peripheral/audio/chipsets/tfa9879/accessory/src/tfa9879_accessory_impl.c:409: undefined reference to `GpioSetDir'[OHOS ERROR] /home/d1/openHarmony/t113/out/t113_nand_linux/xingyun_t113_nand_board/kernel/linux-5.4/drivers/hdf/khdf/model/audio/../../../../../../drivers/peripheral/audio/chipsets/tfa9879/accessory/src/tfa9879_accessory_impl.c:414: undefined reference to `GpioWrite'[OHOS ERROR] drivers/../../../../../../drivers/peripheral/audio/chipsets/hi3516dv300/dsp/src/dsp_adapter.o: In function `DspDeviceReadReg':[OHOS ERROR] /home/d1/openHarmony/t113/out/t113_nand_linux/xingyun_t113_nand_board/kernel/linux-5.4/drivers/hdf/khdf/model/audio/../../../../../../drivers/peripheral/audio/chipsets/hi3516dv300/dsp/src/dsp_adapter.c:268: undefined reference to `SpiOpen'[OHOS ERROR] /home/d1/openHarmony/t113/out/t113_nand_linux/xingyun_t113_nand_board/kernel/linux-5.4/drivers/hdf/khdf/model/audio/../../../../../../drivers/peripheral/audio/chipsets/hi3516dv300/dsp/src/dsp_adapter.c:274: undefined reference to `SpiRead'[OHOS ERROR] /home/d1/openHarmony/t113/out/t113_nand_linux/xingyun_t113_nand_board/kernel/linux-5.4/drivers/hdf/khdf/model/audio/../../../../../../drivers/peripheral/audio/chipsets/hi3516dv300/dsp/src/dsp_adapter.c:281: undefined reference to `SpiClose'[OHOS ERROR] /home/d1/openHarmony/t113/out/t113_nand_linux/xingyun_t113_nand_board/kernel/linux-5.4/drivers/hdf/khdf/model/audio/../../../../../../drivers/peripheral/audio/chipsets/hi3516dv300/dsp/src/dsp_adapter.c:277: undefined reference to `SpiClose'[OHOS ERROR] drivers/../../../../../../drivers/peripheral/audio/chipsets/hi3516dv300/dsp/src/dsp_adapter.o: In function `DspDeviceWriteReg':[OHOS ERROR] /home/d1/openHarmony/t113/out/t113_nand_linux/xingyun_t113_nand_board/kernel/linux-5.4/drivers/hdf/khdf/model/audio/../../../../../../drivers/peripheral/audio/chipsets/hi3516dv300/dsp/src/dsp_adapter.c:290: undefined reference to `SpiOpen'[OHOS ERROR] /home/d1/openHarmony/t113/out/t113_nand_linux/xingyun_t113_nand_board/kernel/linux-5.4/drivers/hdf/khdf/model/audio/../../../../../../drivers/peripheral/audio/chipsets/hi3516dv300/dsp/src/dsp_adapter.c:296: undefined reference to `SpiWrite'[OHOS ERROR] /home/d1/openHarmony/t113/out/t113_nand_linux/xingyun_t113_nand_board/kernel/linux-5.4/drivers/hdf/khdf/model/audio/../../../../../../drivers/peripheral/audio/chipsets/hi3516dv300/dsp/src/dsp_adapter.c:303: undefined reference to `SpiClose'[OHOS ERROR] /home/d1/openHarmony/t113/out/t113_nand_linux/xingyun_t113_nand_board/kernel/linux-5.4/drivers/hdf/khdf/model/audio/../../../../../../drivers/peripheral/audio/chipsets/hi3516dv300/dsp/src/dsp_adapter.c:299: undefined reference to `SpiClose'[OHOS ERROR] Makefile:1178: recipe for target 'vmlinux' failed[OHOS ERROR] make[1]: * [vmlinux] Error 1[OHOS ERROR] make[1]: Leaving directory '/home/d1/openHarmony/t113/out/t113_nand_linux/xingyun_t113_nand_board/kernel/linux-5.4'[OHOS ERROR] kernel.mk:73: recipe for target '/home/d1/openHarmony/t113/out/t113_nand_linux/xingyun_t113_nand_board/kernel/linux-5.4/arch/arm/boot/uImage' failed[OHOS ERROR] make: * [/home/d1/openHarmony/t113/out/t113_nand_linux/xingyun_t113_nand_board/kernel/linux-5.4/arch/arm/boot/uImage] Error 2[OHOS ERROR] you can check build log in /home/d1/openHarmony/t113/out/t113_nand_linux/xingyun_t113_nand_board/build.log[OHOS ERROR] command: "/home/d1/openHarmony/t113/prebuilts/build-tools/linux-x86/bin/ninja -w dupbuild=warn -C /home/d1/openHarmony/t113/out/t113_nand_linux/xingyun_t113_nand_board" failed[OHOS ERROR] return code: 1[OHOS ERROR] execution path: /home/d1/openHarmony/t113
还是报错,提示找不到某些函数。去out/t113_nand_linux/xingyun_t113_nand_board/kernel/linux-5.4执行make menuconfig发现已经默认勾选了某些驱动。
可以去drivers/adapter/khdf/linux/model/usb/device/目录查看Kconfig,发现这个默认就是勾选,我们可以默认不使用
diff --git a/drivers/adapter/khdf/linux/model/usb/device/Kconfig b/drivers/adapter/khdf/linux/model/usb/device/Kconfigindex 54d4cc7962..eb473b36f6 100644--- a/drivers/adapter/khdf/linux/model/usb/device/Kconfig+++ b/drivers/adapter/khdf/linux/model/usb/device/Kconfig@@ -1,6 +1,6 @@ config DRIVERS_HDF_USB_F_GENERIC bool "Enable F_GENERIC driver"- default y+ default n depends on DRIVERS_HDF help Answer Y to choice HDF USB F_GENERIC driver.
重新执行hb build -f依然报错,
[OHOS ERROR] drivers/../../../../../../drivers/peripheral/audio/chipsets/tfa9879/accessory/src/tfa9879_accessory_impl.o: In function `Tfa9879RegRw':
寻找文件,
find -name tfa9879_accessory_impl.c结果如下目录存在文件./drivers/peripheral/audio/chipsets/tfa9879/accessory/src/tfa9879_accessory_impl.c
然后发现对应目录下没有,发现drivers/adapter/khdf/linux/model/audio/目录下存在文件Makefile和Kconfig文件,修改它,修改点如下
diff --git a/drivers/adapter/khdf/linux/model/audio/Kconfig b/drivers/adapter/khdf/linux/model/audio/Kconfigindex a760df7f5d..e64039795e 100755--- a/drivers/adapter/khdf/linux/model/audio/Kconfig+++ b/drivers/adapter/khdf/linux/model/audio/Kconfig@@ -1,6 +1,6 @@ config DRIVERS_HDF_AUDIO bool "Enable HDF Audio driver"- default y+ default n depends on DRIVERS_HDF help Answer Y to choice HDF Audio input driver.
然后重新编译,hb build -f,编译成功
[OHOS INFO] ohos_build_compiler: clang[OHOS INFO] //kernel/linux/build:linux_kernel is marked as prebuilts[OHOS INFO] //prebuilts/lite/sysroot/build:build_sysroot is marked as prebuilts[OHOS INFO] Done. Made 12 targets from 16 files in 8ms[OHOS INFO] [1/17] STAMP obj/build/lite/mark_as_prebuilts.stamp[OHOS INFO] [2/17] STAMP obj/vendor/xingyun/t113_nand/t113_nand.stamp[OHOS INFO] [3/17] STAMP obj/build/lite/ndk.stamp[OHOS INFO] [4/17] STAMP obj/device/xingyunelec/t113_nand_linux/t113_nand_linux.stamp[OHOS INFO] [5/17] STAMP obj/build/lite/product.stamp[OHOS INFO] [6/17] ACTION //kernel/linux/build:linux_kernel(//build/lite/toolchain:linux_x86_64_ohos_clang)[OHOS INFO] [7/17] STAMP obj/kernel/linux/build/linux_kernel.stamp[OHOS INFO] [8/17] STAMP obj/build/lite/ohos.stamp[OHOS INFO] [9/17] ACTION //prebuilts/lite/sysroot/build:build_sysroot(//build/lite/toolchain:linux_x86_64_ohos_clang)[OHOS INFO] [10/17] STAMP obj/prebuilts/lite/sysroot/build/build_sysroot.stamp[OHOS INFO] [11/17] STAMP obj/prebuilts/lite/sysroot/build/build.stamp[OHOS INFO] [12/17] STAMP obj/prebuilts/lite/sysroot/sysroot.stamp[OHOS INFO] [13/17] STAMP obj/build/lite/prebuilts.stamp[OHOS INFO] [14/17] STAMP obj/prebuilts/lite/sysroot/build/strip.inputdeps.stamp[OHOS INFO] [15/17] ACTION //prebuilts/lite/sysroot/build:strip(//build/lite/toolchain:linux_x86_64_ohos_clang)[OHOS INFO] [16/17] ACTION //prebuilts/lite/sysroot/build:strip(//build/lite/toolchain:linux_x86_64_ohos_clang)[OHOS INFO] [17/17] STAMP obj/prebuilts/lite/sysroot/build/strip.stamp[OHOS INFO] /home/d1/openHarmony/t113/vendor/xingyun/t113_nand/fs.yml not found, stop packing fs. If the product does not need to be packaged, ignore it.[OHOS INFO] xingyun_t113_nand_board build success[OHOS INFO] cost time: 0:02:00
运行起来后的截图,表示HDF驱动框架成功运行