OpenHarmony三方内核移植 原创
Hello_Kun
发布于 2024-9-19 14:51
浏览
0收藏
如下图所示,OpenHarmony 内核层主要包含OH Linux内核、OH内核态特性。其中OH Linux内核可以看成是由三方Linux内核+OH内核态基础代码的组成。
OH 默认Linux内核为5.10,为保证稳定性,移植OH时使用目标芯片的原生内核,在此基础上添加OH内核态基础代码、OH内核态特性。即,选择的移植方案是:OH 内核层 = 目标芯片的Linux 内核 + OH内核态基础代码 + HDF特性 ,以目标芯片Linux-4.19.15内核移植OH为例,移植过程如下:
0.首先准备内核源码
tar zxvf linux-4.19.15-860-oh.tar.gz oh源码根目录/kernel/linux/linux-4.19.15
1 添加内核基础代码
# 0. 移植内核态基础代码 主要是hilog 和hievent,参考链接
https://docs.openharmony.cn/pages/v4.1/zh-cn/device-dev/porting/porting-linux-kernel.md/
0.1 将以下文件,
drivers/staging/hilog
drivers/staging/hievent
从OpenHarmony内核代码目录kernel/linux/linux-4.19/drivers/staging中拷贝到kernel/linux/linux-4.19.15/drivers/staging中。
0.2 在三方内核的linux-4.19.15/drivers/staging/Kconfig文件内增加如下代码:
source "drivers/staging/hilog/Kconfig"
source "drivers/staging/hievent/Kconfig"
0.3 在在三方内核的linux-4.19.15/drivers/路径下的Makefile中添加配置
obj-$(CONFIG_HILOG) += hilog/
obj-$(CONFIG_HIEVENT) += hievent/
# 1. 内核config,拷贝内核根目录原来的.config文件到OH如下路径,并重命名target_small_defconfig.config
kernel/linux/config/linux-4.19.15/arch/csky/configs/target_small_defconfig.config
# 添加HDF选项,参考上面链接添加以下内容,
# 参考kernel/linux/config/linux-4.19/arch/arm/configs/hispark_taurus_small_defconfig添加
CONFIG_DRIVERS_HDF=y
CONFIG_HDF_SUPPORT_LEVEL=1
CONFIG_DRIVERS_HDF_PLATFORM=y
# CONFIG_DRIVERS_HDF_PLATFORM_MIPI_DSI is not set
# CONFIG_DRIVERS_HDF_PLATFORM_MIPI_CSI is not set
CONFIG_DRIVERS_HDF_PLATFORM_GPIO=y
CONFIG_DRIVERS_HDF_PLATFORM_I2C=y
# CONFIG_DRIVERS_HDF_PLATFORM_WATCHDOG is not set
CONFIG_DRIVERS_HDF_PLATFORM_PWM=y
CONFIG_DRIVERS_HDF_PLATFORM_UART=y
# CONFIG_DRIVERS_HDF_PLATFORM_SDIO is not set
# CONFIG_DRIVERS_HDF_PLATFORM_EMMC is not set
CONFIG_DRIVERS_HDF_PLATFORM_MMC=y
CONFIG_DRIVERS_HDF_PLATFORM_SPI=y
CONFIG_DRIVERS_HDF_PLATFORM_RTC=y
# CONFIG_PWM_HI35XX is not set
# CONFIG_DRIVERS_HDF_PLATFORM_REGULATOR is not set
CONFIG_DRIVERS_HDF_PLATFORM_ADC=y
# CONFIG_DRIVERS_HDF_PLATFORM_TRACE is not set
# CONFIG_DRIVERS_HDF_PLATFORM_DUMPER is not set
# CONFIG_IMX8MM_EMMC is not set
# CONFIG_IMX8MM_SDIO is not set
# CONFIG_DRIVERS_HDF_PLATFORM_IMX8MM_MIPI_DSI is not set
CONFIG_DRIVERS_HDF_TEST=y
# CONFIG_IMX8MM_SPI_TEST is not set
# CONFIG_DRIVERS_HDF_DISP is not set
# CONFIG_DRIVERS_HDF_INPUT is not set
# CONFIG_DRIVERS_HDF_NETDEV_EXT is not set
# CONFIG_DRIVERS_HDF_BT is not set
# CONFIG_DRIVERS_HDF_SENSOR is not set
# CONFIG_DRIVERS_HDF_STORAGE is not set
# CONFIG_IMX8MM_SDIO_TEST is not set
# CONFIG_DRIVERS_HDF_USB_PNP_NOTIFY is not set
# CONFIG_DRIVERS_HDF_AUDIO is not set
# CONFIG_DRIVERS_HDF_VIBRATOR is not set
# CONFIG_DRIVERS_HDF_DSOFTBUS is not set
# CONFIG_DRIVERS_HDF_LIGHT is not set
# CONFIG_DRIVERS_HDF_NETWORK is not set
2 打hdf补丁
如果不添加HDF补丁,编译会报错遇到 undefined reference to _hdf_drivers_end' 、 undefined reference to
_hdf_drivers_start’
**检查内核补丁,**发现是因为执行drivers/hdf_core/adapter/khdf/linux/patch_hdf.sh时,默认添加的补丁路径和内容为:
kernel/linux/patches/linux-4.19/common_patch/hdf.patch
// 部分内容如下:
//-----------------------------针对arm64架构的hdf补丁--------------------------------
diff --git a/arch/arm64/kernel/vmlinux.lds.S b/arch/arm64/kernel/vmlinux.lds.S
index 69e7c8d4a..6bdc118dd 100644
--- a/arch/arm64/kernel/vmlinux.lds.S
+++ b/arch/arm64/kernel/vmlinux.lds.S //
@@ -176,6 +176,15 @@ SECTIONS
INIT_RAM_FS
*(.init.rodata.* .init.bss) /* from the EFI stub */
}
+
+#ifdef CONFIG_DRIVERS_HDF
+ .init.hdf_table : {
+ _hdf_drivers_start = .;
+ *(.hdf.driver)
+ _hdf_drivers_end = .;
+ }
+#endif
+
.exit.data : {
ARM_EXIT_KEEP(EXIT_DATA)
}
// --------------------------------针对arm架构的hdf补丁----------------------------------
diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
index 23150c0f0..2780470c5 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)
//--------------------------------如果目标芯片架构比较新,需要补充目标芯片如csky架构的hdf补丁------------------------------
hi3516是arm架构的,而新的csky架构,所以这个默认common_patch/hdf.patch补丁打到了arch/arm中,两种解决方法:
-
1.在 kernel/linux/patches/linux-4.19/common_patch/hdf.patch中添加针对csky的补丁,
-
2.直接修改/kernel/src_tmp/linux-4.19.15/arch/csky/kernel/vmlinux.lds.S,添加hdf占位符代码:
// 32行开始添加如下代码
#ifdef CONFIG_DRIVERS_HDF
.init.hdf_table : {
_hdf_drivers_start = .;
*(.hdf.driver)
_hdf_drivers_end = .;
}
方法1需要制作补丁文件,因为需要找到目标芯片的linux内核、OH内核提交hdf补丁的pr,因为难以寻找,故选择方法2,手动添加
# 2. 内核补丁
2.1 手动添加HDF补丁,直接修改//kernel/linux/linux-4.19.15/arch/csky/kernel/vmlinux.lds.S,添加代码:
# 32行开始添加如下代码
#ifdef CONFIG_DRIVERS_HDF
.init.hdf_table : {
_hdf_drivers_start = .;
*(.hdf.driver)
_hdf_drivers_end = .;
}
©著作权归作者所有,如需转载,请注明出处,否则将追究法律责任
赞
收藏
回复
回复
相关推荐