首先添加vendor下的目录,我这里创建如下形式的目录vendor/xingyun/imx6ul_nand_linux,目录创建完成后就是填充这个目录了,首先添加BUILD.gn文件,其中文件内容如下,请注意,这个双引号里面的内容最好和目录相匹配。
group("imx6ul_nand_linux") {
}
添加完成BUILD.gn后再接着添加config.json文件,文件内容如下,
{
"product_name": "imx6ul_nand_openharmony", //这里是对应hb set时显示的内容
"ohos_version": "OpenHarmony 3.0", //这里使用的版本
"device_company": "xingyun", //这里对应源码根目录下device下的子目录
"board": "imx6ul_nand_linux", //这里对应/device/xingyun/下的子目录名
"kernel_type": "linux",//内核类型
"kernel_version": "5.4", //内核版本
"subsystems": [
]
}
添加完成之后,我们对应的在device下创建好如下两级子目录xingyun/imx6ul_nand_linux,完整目录为device/xingyun/imx6ul_nand_linux,创建完成后,我们使用hb set查看效果。hb set效果如下图 可以看到我们添加的产品已经可以选择了。选中之后回车,报如下错误信息。 这是因为我们没有在device下添加我们的配置信息。这里我们直接是复制其他产品的配置文件cp hisilicon/hispark_taurus/sdk_linux/config.gni xingyun/imx6ul_nand_linux/sdk_linux/,修改如下图对应的linux内核版本。 再次执行hb set然后回车效果如下图所示。 报错信息如下所示
OHOS INFO] ERROR at //build/lite/ohos_var.gni:71:45: No value named "product_adapter_dir" in scope "product_config"
[OHOS INFO] ohos_product_adapter_dir = product_config.product_adapter_dir
[OHOS INFO] ^------------------
[OHOS INFO] See //build/lite/config/BUILDCONFIG.gn:13:1: whence it was imported.
[OHOS INFO] import("//build/lite/ohos_var.gni")
[OHOS INFO] ^---------------------------------
[OHOS ERROR] you can check build log in /home/zxy/openharmony/imx6ul/out/imx6ul_nand_linux/imx6ul_nand_openharmony/build.log
[OHOS ERROR] command: "/home/zxy/openharmony/imx6ul/prebuilts/build-tools/linux-x86/bin/gn gen /home/zxy/openharmony/imx6ul/out/imx6ul_nand_linux/imx6ul_nand_openharmony --root=/home/zxy/openharmony/imx6ul --dotfile=/home/zxy/openharmony/imx6ul/build/lite/.gn --script-executable=/usr/bin/python3 --args=ohos_build_compiler_specified="clang" ohos_build_compiler_dir="//prebuilts/clang/ohos/linux-x86_64/llvm" product_path="/home/zxy/openharmony/imx6ul/vendor/xingyun/imx6ul_nand_linux" device_path="/home/zxy/openharmony/imx6ul/device/xingyun/imx6ul_nand_linux/sdk_linux" ohos_kernel_type="linux" ohos_build_type="debug" ohos_build_time="1654928453054" ohos_build_datetime="2022-06-11 22:20:53" ohos_full_compile=true" failed
[OHOS ERROR] return code: 1
[OHOS ERROR] execution path: /home/zxy/openharmony/imx6ul
这里是因为我们没有在vendor/xingyun/imx6ul_nand_linux/config.json中添加如下两句话,添加完之后记得创建vendor/xingyun/imx6ul_nand_linux/hals目录
diff --git a/vendor/xingyun/imx6ul_nand_linux/config.json b/vendor/xingyun/imx6ul_nand_linux/config.json
index fb5c3344e0..387f94f04d 100644
--- a/vendor/xingyun/imx6ul_nand_linux/config.json
+++ b/vendor/xingyun/imx6ul_nand_linux/config.json
@@ -6,5 +6,8 @@
"kernel_type": "linux",
"kernel_version": "5.4",
"subsystems": [
- ]
+ ],
+ "third_party_dir": "//third_party",
+ "product_adapter_dir": "//vendor/xingyun/imx6ul_nand_linux/hals"
+
}
接着执行hb build,出现如下错误
[OHOS INFO] ERROR at //build/lite/BUILD.gn:101:17: Unable to load "/home/zxy/openharmony/imx6ul/device/xingyun/imx6ul_nand_linux/BUILD.gn".
[OHOS INFO] deps += [ "${device_path}/../" ]
[OHOS INFO] ^-------------------
[OHOS INFO] ohos_build_compiler: clang
[OHOS ERROR] you can check build log in /home/zxy/openharmony/imx6ul/out/imx6ul_nand_linux/imx6ul_nand_openharmony/build.log
[OHOS ERROR] command: "/home/zxy/openharmony/imx6ul/prebuilts/build-tools/linux-x86/bin/gn gen /home/zxy/openharmony/imx6ul/out/imx6ul_nand_linux/imx6ul_nand_openharmony --root=/home/zxy/openharmony/imx6ul --dotfile=/home/zxy/openharmony/imx6ul/build/lite/.gn --script-executable=/usr/bin/python3 --args=ohos_build_compiler_specified="clang" ohos_build_compiler_dir="//prebuilts/clang/ohos/linux-x86_64/llvm" product_path="/home/zxy/openharmony/imx6ul/vendor/xingyun/imx6ul_nand_linux" device_path="/home/zxy/openharmony/imx6ul/device/xingyun/imx6ul_nand_linux/sdk_linux" ohos_kernel_type="linux" ohos_build_type="debug" ohos_build_time="1654928846765" ohos_build_datetime="2022-06-11 22:27:26" ohos_full_compile=true" failed
[OHOS ERROR] return code: 1
[OHOS ERROR] execution path: /home/zxy/openharmony/imx6ul
我们没有在device/xingyun/imx6ul_nand_linux目录下添加BUILD.gn文件,那么我们添加它,添加device/xingyun/imx6ul_nand_linux/BUILD.gn文件,文件内容为
group("imx6ul_nand_linux") {
}
接着hb build,依然报错
[OHOS INFO] ohos_build_compiler: clang
[OHOS INFO] //prebuilts/lite/sysroot/build:build_sysroot is marked as prebuilts
[OHOS INFO] //kernel/linux/build:linux_kernel 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/build/lite/ndk.stamp
[OHOS INFO] [3/17] STAMP obj/device/xingyun/imx6ul_nand_linux/imx6ul_nand_linux.stamp
[OHOS INFO] [4/17] STAMP obj/vendor/xingyun/imx6ul_nand_linux/imx6ul_nand_linux.stamp
[OHOS INFO] [5/17] STAMP obj/build/lite/ohos.stamp
[OHOS INFO] [6/17] STAMP obj/build/lite/product.stamp
[OHOS INFO] [7/17] ACTION //kernel/linux/build:linux_kernel(//build/lite/toolchain:linux_x86_64_ohos_clang)
[OHOS ERROR] [7/17] ACTION //kernel/linux/build:linux_kernel(//build/lite/toolchain:linux_x86_64_ohos_clang)
[OHOS ERROR] FAILED: obj/kernel/linux/build/linux_kernel_build_ext_components.txt
[OHOS ERROR] /usr/bin/python3 ../../../build/lite/build_ext_components.py --path=../../../kernel/linux/build --command=./kernel_module_build.sh\ /home/zxy/openharmony/imx6ul/out/imx6ul_nand_linux/imx6ul_nand_openharmony\ small\ /home/zxy/openharmony/imx6ul/prebuilts/clang/ohos/linux-x86_64/llvm\ vendor/xingyun/imx6ul_nand_linux\ imx6ul_nand_linux\ linux-5.10 --target_dir=/home/zxy/openharmony/imx6ul/out/imx6ul_nand_linux/imx6ul_nand_openharmony/obj/kernel/linux/build/build.log --out_dir=/home/zxy/openharmony/imx6ul/out/imx6ul_nand_linux/imx6ul_nand_openharmony/error.log
[OHOS ERROR] echo "build kernel..."
[OHOS ERROR] build kernel...
[OHOS ERROR] rm -rf /home/zxy/openharmony/imx6ul/out/imx6ul_nand_linux/imx6ul_nand_openharmony/kernel/linux-5.10;mkdir -p /home/zxy/openharmony/imx6ul/out/imx6ul_nand_linux/imx6ul_nand_openharmony/kernel/linux-5.10;cp -arfL /home/zxy/openharmony/imx6ul/kernel/linux/linux-5.10/* /home/zxy/openharmony/imx6ul/out/imx6ul_nand_linux/imx6ul_nand_openharmony/kernel/linux-5.10/
[OHOS ERROR] cd /home/zxy/openharmony/imx6ul/out/imx6ul_nand_linux/imx6ul_nand_openharmony/kernel/linux-5.10 && patch -p1 < /home/zxy/openharmony/imx6ul/kernel/linux/patches/linux-5.10/_patch/hdf.patch && patch -p1 < /home/zxy/openharmony/imx6ul/kernel/linux/patches/linux-5.10/_patch/.patch
[OHOS ERROR] /bin/sh: /home/zxy/openharmony/imx6ul/kernel/linux/patches/linux-5.10/_patch/hdf.patch: No such file or directory
[OHOS ERROR] make: *** [kernel.mk:75: /home/zxy/openharmony/imx6ul/out/imx6ul_nand_linux/imx6ul_nand_openharmony/kernel/linux-5.10/arch/arm/boot/uImage] Error 1
[OHOS ERROR] you can check build log in /home/zxy/openharmony/imx6ul/out/imx6ul_nand_linux/imx6ul_nand_openharmony/build.log
[OHOS ERROR] command: "/home/zxy/openharmony/imx6ul/prebuilts/build-tools/linux-x86/bin/ninja -w dupbuild=warn -C /home/zxy/openharmony/imx6ul/out/imx6ul_nand_linux/imx6ul_nand_openharmony" failed
[OHOS ERROR] return code: 1
[OHOS ERROR] execution path: /home/zxy/openharmony/imx6ul
通过对上面的报错信息分析,发现编译的内核好像并没有使用我们的内核版本去进行编译,这里是因为build/ohos/kernel/kernel.gni这里影响了,那么我们怎么解决这个问题呢,我们可以使用如下添加打印信息,print(“$board_name”),修改补丁如下
diff --git a/kernel/linux/build/BUILD.gn b/kernel/linux/build/BUILD.gn
index 5e2e10fa92..6ba5e1bb51 100644
--- a/kernel/linux/build/BUILD.gn
+++ b/kernel/linux/build/BUILD.gn
@@ -29,7 +29,11 @@ if (defined(ohos_lite)) {
}
build_type = "small"
product_path_rebase = rebase_path(product_path, ohos_root_path)
- command = "./kernel_module_build.sh ${outdir} ${build_type} ${clang_dir} ${product_path_rebase} ${board_name} ${linux_kernel_version}"
+ if ( board_name == "imx6ul_nand_linux") {
+ command = "./kernel_module_build.sh ${outdir} ${build_type} ${clang_dir} ${product_path_rebase} ${board_name} linux-${kernel_version}"
+ } else {
+ command = "./kernel_module_build.sh ${outdir} ${build_type} ${clang_dir} ${product_path_rebase} ${board_name} ${linux_kernel_version}"
+ }
deps = [ "//build/lite:mark_as_prebuilts" ]
}
} else {
这里我是通过判断我们的baord_name字段来区分,这里特别需要注意的是if和else括号里面的内容不能用tab来缩进,不然会报如下错误信息,一定是需要使用空格
[OHOS INFO] ohos_build_compiler: clang
[OHOS INFO] //prebuilts/lite/sysroot/build:build_sysroot is marked as prebuilts
[OHOS INFO] ERROR at //kernel/linux/build/BUILD.gn:35:1: Invalid token.
[OHOS INFO] command = "./kernel_module_build.sh ${outdir} ${build_type} ${clang_dir} ${product_path_rebase} ${board_name} ${linux_kernel_version}"
[OHOS INFO] ^
[OHOS INFO] You got a tab character in here. Tabs are evil. Convert to spaces.
[OHOS ERROR] you can check build log in /home/zxy/openharmony/imx6ul/out/imx6ul_nand_linux/imx6ul_nand_openharmony/build.log
[OHOS ERROR] command: "/home/zxy/openharmony/imx6ul/prebuilts/build-tools/linux-x86/bin/gn gen /home/zxy/openharmony/imx6ul/out/imx6ul_nand_linux/imx6ul_nand_openharmony --root=/home/zxy/openharmony/imx6ul --dotfile=/home/zxy/openharmony/imx6ul/build/lite/.gn --script-executable=/usr/bin/python3 --args=ohos_build_compiler_specified="clang" ohos_build_compiler_dir="//prebuilts/clang/ohos/linux-x86_64/llvm" product_path="/home/zxy/openharmony/imx6ul/vendor/xingyun/imx6ul_nand_linux" device_path="/home/zxy/openharmony/imx6ul/device/xingyun/imx6ul_nand_linux/sdk_linux" ohos_kernel_type="linux" ohos_build_type="debug" ohos_build_time="1654930991854" ohos_build_datetime="2022-06-11 23:03:11" ohos_full_compile=true" failed
[OHOS ERROR] return code: 1
这样就会去编译我们指定的内核版本了,然后修改如下地方
diff --git a/kernel/linux/build/kernel_module_build.sh b/kernel/linux/build/kernel_module_build.sh
index 826bd6c3e6..5599923370 100755
--- a/kernel/linux/build/kernel_module_build.sh
+++ b/kernel/linux/build/kernel_module_build.sh
@@ -30,6 +30,8 @@ if [ "$2" == "small" ];then
fi
if [ "$5" == "hispark_taurus" ];then
export DEVICE_NAME=hi3516dv300
+ elif [ "$5" == "imx6ul_nand_linux" ];then
+ export DEVICE_NAME=imx6ul_nand_linux
fi
elif [ "$2" == "standard" ];then
export BUILD_TYPE=standard
编译报错如下,我们没有添加patch文件导致如下错误。
[OHOS ERROR] rm -rf /home/zxy/openharmony/imx6ul/out/imx6ul_nand_linux/imx6ul_nand_openharmony/kernel/linux-5.4;mkdir -p /home/zxy/openharmony/imx6ul/out/imx6ul_nand_linux/imx6ul_nand_openharmony/kernel/linux-5.4;cp -arfL /home/zxy/openharmony/imx6ul/kernel/linux/linux-5.4/* /home/zxy/openharmony/imx6ul/out/imx6ul_nand_linux/imx6ul_nand_openharmony/kernel/linux-5.4/
[OHOS ERROR] cd /home/zxy/openharmony/imx6ul/out/imx6ul_nand_linux/imx6ul_nand_openharmony/kernel/linux-5.4 && patch -p1 < /home/zxy/openharmony/imx6ul/kernel/linux/patches/linux-5.4/imx6ul_nand_linux_patch/hdf.patch && patch -p1 < /home/zxy/openharmony/imx6ul/kernel/linux/patches/linux-5.4/imx6ul_nand_linux_patch/imx6ul_nand_linux.patch
[OHOS ERROR] /bin/sh: /home/zxy/openharmony/imx6ul/kernel/linux/patches/linux-5.4/imx6ul_nand_linux_patch/hdf.patch: No such file or directory
[OHOS ERROR] make: *** [kernel.mk:75: /home/zxy/openharmony/imx6ul/out/imx6ul_nand_linux/imx6ul_nand_openharmony/kernel/linux-5.4/arch/arm/boot/uImage] Error 1
[OHOS ERROR] you can check build log in /home/zxy/openharmony/imx6ul/out/imx6ul_nand_linux/imx6ul_nand_openharmony/build.log
[OHOS ERROR] command: "/home/zxy/openharmony/imx6ul/prebuilts/build-tools/linux-x86/bin/ninja -w dupbuild=warn -C /home/zxy/openharmony/imx6ul/out/imx6ul_nand_linux/imx6ul_nand_openharmony" failed
[OHOS ERROR] return code: 1
[OHOS ERROR] execution path: /home/zxy/openharmony/imx6ul
首先创建kernel/linux/patches/linux-5.4/imx6ul_nand_linux_patch目录,然后添加hdf.patch ,imx6ul_nand_linux.patch , imx6ul_nand_linux_small.patch三个patch文件,这里确定使用如下目录可以根据如下编译报错信息提示得知,
[OHOS ERROR] rm -rf /home/zxy/openharmony/imx6ul/out/imx6ul_nand_linux/imx6ul_nand_openharmony/kernel/linux-5.4;mkdir -p /home/zxy/openharmony/imx6ul/out/imx6ul_nand_linux/imx6ul_nand_openharmony/kernel/linux-5.4;cp -arfL /home/zxy/openharmony/imx6ul/kernel/linux/linux-5.4/* /home/zxy/openharmony/imx6ul/out/imx6ul_nand_linux/imx6ul_nand_openharmony/kernel/linux-5.4/
[OHOS ERROR] cd /home/zxy/openharmony/imx6ul/out/imx6ul_nand_linux/imx6ul_nand_openharmony/kernel/linux-5.4 && patch -p1 < /home/zxy/openharmony/imx6ul/kernel/linux/patches/linux-5.4/imx6ul_nand_linux_patch/hdf.patch && patch -p1 < /home/zxy/openharmony/imx6ul/kernel/linux/patches/linux-5.4/imx6ul_nand_linux_patch/imx6ul_nand_linux.patch
[OHOS ERROR] cd /home/zxy/openharmony/imx6ul/out/imx6ul_nand_linux/imx6ul_nand_openharmony/kernel/linux-5.4 && patch -p1 < /home/zxy/openharmony/imx6ul/kernel/linux/patches/linux-5.4/imx6ul_nand_linux_patch/imx6ul_nand_linux_small.patch
[OHOS ERROR] /bin/sh: /home/zxy/openharmony/imx6ul/kernel/linux/patches/linux-5.4/imx6ul_nand_linux_patch/imx6ul_nand_linux_small.patch: No such file or directory
[OHOS ERROR] make: *** [kernel.mk:76: /home/zxy/openharmony/imx6ul/out/imx6ul_nand_linux/imx6ul_nand_openharmony/kernel/linux-5.4/arch/arm/boot/uImage] Error 1
[OHOS ERROR] you can check build log in /home/zxy/openharmony/imx6ul/out/imx6ul_nand_linux/imx6ul_nand_openharmony/build.log
[OHOS ERROR] command: "/home/zxy/openharmony/imx6ul/prebuilts/build-tools/linux-x86/bin/ninja -w dupbuild=warn -C /home/zxy/openharmony/imx6ul/out/imx6ul_nand_linux/imx6ul_nand_openharmony" failed
[OHOS ERROR] return code: 1
[OHOS ERROR] execution path: /home/zxy/openharmony/imx6ul
或者根据kernel/linux/build/kernel.mk中如下描述也可得知
DEVICE_PATCH_DIR := $(OHOS_BUILD_HOME)/kernel/linux/patches/${KERNEL_VERSION}/$(DEVICE_NAME)_patch
DEVICE_PATCH_FILE := $(DEVICE_PATCH_DIR)/$(DEVICE_NAME).patch
HDF_PATCH_FILE := $(DEVICE_PATCH_DIR)/hdf.patch
SMALL_PATCH_FILE := $(DEVICE_PATCH_DIR)/$(DEVICE_NAME)_$(BUILD_TYPE).patch
KERNEL_IMAGE_FILE := $(KERNEL_SRC_TMP_PATH)/arch/arm/boot/uImage
DEFCONFIG_FILE := $(DEVICE_NAME)_$(BUILD_TYPE)_defconfig
export HDF_PROJECT_ROOT=$(OHOS_BUILD_HOME)/
添加好了patch文件后,再添加配置文件,首先创建kernel/linux/config/linux-5.4/arch/arm/configs目录,然后再此目录下添加imx6ul_nand_linux_small_defconfig,这里使用我们编译linux内核使用的配置文件即可。
[OHOS ERROR] *** Can't find default configuration "arch/arm/configs/imx6ul_nand_linux_small_defconfig"!
[OHOS ERROR] ***
[OHOS ERROR] make[2]: *** [scripts/kconfig/Makefile:90: imx6ul_nand_linux_small_defconfig] Error 1
[OHOS ERROR] make[1]: *** [Makefile:590: imx6ul_nand_linux_small_defconfig] Error 2
[OHOS ERROR] make[1]: Leaving directory '/home/zxy/openharmony/imx6ul/out/imx6ul_nand_linux/imx6ul_nand_openharmony/kernel/linux-5.4'
[OHOS ERROR] make: *** [kernel.mk:79: /home/zxy/openharmony/imx6ul/out/imx6ul_nand_linux/imx6ul_nand_openharmony/kernel/linux-5.4/arch/arm/boot/uImage] Error 2
[OHOS ERROR] you can check build log in /home/zxy/openharmony/imx6ul/out/imx6ul_nand_linux/imx6ul_nand_openharmony/build.log
[OHOS ERROR] command: "/home/zxy/openharmony/imx6ul/prebuilts/build-tools/linux-x86/bin/ninja -w dupbuild=warn -C /home/zxy/openharmony/imx6ul/out/imx6ul_nand_linux/imx6ul_nand_openharmony" failed
[OHOS ERROR] return code: 1
[OHOS ERROR] execution path: /home/zxy/openharmony/imx6ul
然后对于我这里,因为我是编译zImage,所以我需要修改如下两个地方
diff --git a/kernel/linux/build/kernel.mk b/kernel/linux/build/kernel.mk
index 56fcde79ef..1688c985e5 100644
--- a/kernel/linux/build/kernel.mk
+++ b/kernel/linux/build/kernel.mk
@@ -82,7 +82,11 @@ endif
ifeq ($(KERNEL_VERSION), linux-5.10)
$(hide) $(KERNEL_MAKE) -C $(KERNEL_SRC_TMP_PATH) ARCH=$(KERNEL_ARCH) $(KERNEL_CROSS_COMPILE) modules_prepare
endif
+ifeq ($(DEVICE_NAME),imx6ul_nand_linux)
+ $(hide) $(KERNEL_MAKE) -C $(KERNEL_SRC_TMP_PATH) ARCH=$(KERNEL_ARCH) $(KERNEL_CROSS_COMPILE) -j64
+else
$(hide) $(KERNEL_MAKE) -C $(KERNEL_SRC_TMP_PATH) ARCH=$(KERNEL_ARCH) $(KERNEL_CROSS_COMPILE) -j64 uImage
endif
+endif
.PHONY: build-kernel
build-kernel: $(KERNEL_IMAGE_FILE)
diff --git a/kernel/linux/build/kernel_module_build.sh b/kernel/linux/build/kernel_module_build.sh
index 5599923370..05c5ed775e 100755
--- a/kernel/linux/build/kernel_module_build.sh
+++ b/kernel/linux/build/kernel_module_build.sh
@@ -43,7 +43,11 @@ fi
export OHOS_ROOT_PATH=$(pwd)/../../..
export PRODUCT_PATH=$4
-LINUX_KERNEL_UIMAGE_FILE=${LINUX_KERNEL_OUT}/arch/arm/boot/uImage
+if [ "$5" == "hispark_taurus" ];then
+ LINUX_KERNEL_UIMAGE_FILE=${LINUX_KERNEL_OUT}/arch/arm/boot/uImage
+elif [ "$5" == "imx6ul_nand_linux" ];then
+ LINUX_KERNEL_UIMAGE_FILE=${LINUX_KERNEL_OUT}/arch/arm/boot/zImage
+fi
make -f kernel.mk
编译成功如下所示
[OHOS INFO] [1/11] ACTION //kernel/linux/build:linux_kernel(//build/lite/toolchain:linux_x86_64_ohos_clang)
[OHOS INFO] [2/11] STAMP obj/kernel/linux/build/linux_kernel.stamp
[OHOS INFO] [3/11] ACTION //prebuilts/lite/sysroot/build:build_sysroot(//build/lite/toolchain:linux_x86_64_ohos_clang)
[OHOS INFO] [4/11] STAMP obj/prebuilts/lite/sysroot/build/build_sysroot.stamp
[OHOS INFO] [5/11] STAMP obj/prebuilts/lite/sysroot/build/build.stamp
[OHOS INFO] [6/11] STAMP obj/prebuilts/lite/sysroot/sysroot.stamp
[OHOS INFO] [7/11] STAMP obj/build/lite/prebuilts.stamp
[OHOS INFO] [8/11] STAMP obj/prebuilts/lite/sysroot/build/strip.inputdeps.stamp
[OHOS INFO] [9/11] ACTION //prebuilts/lite/sysroot/build:strip(//build/lite/toolchain:linux_x86_64_ohos_clang)
[OHOS INFO] [10/11] ACTION //prebuilts/lite/sysroot/build:strip(//build/lite/toolchain:linux_x86_64_ohos_clang)
[OHOS INFO] [11/11] STAMP obj/prebuilts/lite/sysroot/build/strip.stamp
[OHOS INFO] /home/zxy/openharmony/imx6ul/vendor/xingyun/imx6ul_nand_linux/fs.yml not found, stop packing fs. If the product does not need to be packaged, ignore it.
[OHOS INFO] imx6ul_nand_openharmony build success
[OHOS INFO] cost time: 0:08:48
内核成功运行截图如下 然后添加我们的启动恢复子系统,这样就能产生init可执行文件,只需要添加如下信息文件即可
{
"subsystem": "startup",
"components": [
{ "component": "bootstrap_lite", "features":[] },
{ "component": "syspara_lite", "features":[] },
{ "component": "init_lite", "features":[] },
{ "component": "appspawn_lite", "features":[] }
]
}
添加完成后如下图,多了恢复启动子系统 然后开始添加我们的根文件系统,首先复制其他产品的根文件系统,主要是依靠fs.yml产生 cp vendor/hisilicon/hispark_taurus_linux/fs.yml vendor/xingyun/imx6ul_nand_linux/,复制完成后,需要修改,因为我们是256MB的NAND需要裁剪。
添加完成后还需要添加init.cfg文件,init进程会通过init.cfg启动其他服务首先在vendor/xingyun/imx6ul_nand_linux下创建目录init_configs,然后新建文件init_configs.cfg,把其他产品上的复制一份即可,接着添加BUILD.gn和etc目录,其中etc目录下添加的文件为 进入init.d目录,创建如下文件。 然后再来修改这些文件,首先需要修改vendor/xingyun/imx6ul_nand_linux/init_configs/下的BUILD.gn文件,需要把我们的文件都添加到根文件系统里面去。
copy("init_configs") {
sources = [ "init_configs.cfg" ]
outputs = [ "$root_out_dir/etc/init.cfg" ]
}
copy("init_fstab") {
sources = [
"etc/fstab",
]
outputs = [ "$root_out_dir/etc/{{source_file_part}}" ]
}
copy("init_initd") {
sources = [
"etc/init.d/rcS",
"etc/init.d/S00devs",
"etc/init.d/S01mdev",
]
outputs = [ "$root_out_dir/etc/init.d/{{source_file_part}}" ]
}
这里是直接进行的复制操作,然后修改vendor/xingyun/imx6ul_nand_linux/下的BUILD.gn
group("imx6ul_nand_linux") {
deps = [
"init_configs",
"init_configs:init_initd",
"init_configs:init_fstab"
]
}
接着复制当前文件内容到hals下 cp vendor/hisilicon/hispark_taurus_linux/hals/* vendor/xingyun/imx6ul_nand_linux/hals/ -r,注意修改如下地方 编译完成后,我们手动执行如下命令tar -jcvf rootfs.tar.bz2 -C ./rootfs . 打包我们的根文件系统即可,然后通过mfgtools下载。 可以看到成功挂载上了根文件系统。这里因为需要自己手动去打包根文件系统,比较麻烦,那么现在我们直接添加到编译脚本中去,首先修改如下图,使用我们自己的脚本文件 接着修改device/xingyun/imx6ul_nand_linux/tools/rootfsimg_linux.sh脚本文件,这个文件可以从其他产品或者build下拷贝过来使用,我这边添加成如下即可。 然后打开binder驱动,
diff --git a/kernel/linux/config/linux-5.4/arch/arm/configs/imx6ul_nand_linux_small_defconfig b/kernel/linux/config/linux-5.4/arch/arm/configs/imx6ul_nand_linux_small_defconfig
index 732cdc41eb..1760aa3c59 100644
--- a/kernel/linux/config/linux-5.4/arch/arm/configs/imx6ul_nand_linux_small_defconfig
+++ b/kernel/linux/config/linux-5.4/arch/arm/configs/imx6ul_nand_linux_small_defconfig
@@ -449,3 +449,8 @@ CONFIG_FONT_8x16=y
CONFIG_PRINTK_TIME=y
CONFIG_DEBUG_FS=y
CONFIG_MAGIC_SYSRQ=y
+
+CONFIG_ANDROID=y
+CONFIG_ANDROID_BINDER_IPC=y
+CONFIG_ANDROID_BINDER_DEVICES="binder,hwbinder,vndbinder"
+
重新编译后,就可以得到我们的所有文件了。然后再把编译好的u-boot文件复制到我们的目录下 首先创建vendor/xingyun/imx6ul_nand_linux/u-boot目录,然后把uboot二进制文件放到此处即可。接着添加BUILD.gn文件,具体文件内容如下
copy("u-boot") {
sources = [
"u-boot-dtb.imx",
]
outputs = [ "$root_out_dir/{{source_file_part}}" ]
}
然后修改上级BUILD.gn,将u-boot加入进去即可。
group("imx6ul_nand_linux") {
deps = [
"init_configs",
"init_configs:init_initd",
"init_configs:init_fstab",
"u-boot"
]
}
这样编译后,我们就能得到u-boot,zImage ,dtb,rootfs所有的文件了。接着添加内核HDF框架支持,之前有人问到过怎么提取自己版本的hdf文件,我这里就详细介绍下,我这边是如何得到的,首先将你的源码存放在其他目录下,比如我这里就是将linux原生的sdk源码,单独存放在一个目录。 然后使用git init,git commit将源码生成commit,然后我们在这里对应修改,生成patch即可。然后需要添加hcs文件,首先创建如下目录vendor/xingyun/imx6ul_nand_linux/hdf_config ,然后复制其他产品此目录中的Makefile文件,然后新建hdf.hcs文件,文件就添加如下内容就好。
root {
module = "nxp,imx6ul_chip";
}
然后编译,主要解决以下错误。首先就是usb的问题,这里是判断内核是哪个
diff --git a/drivers/adapter/khdf/linux/model/usb/device/f_generic.c b/drivers/adapter/khdf/linux/model/usb/device/f_generic.c
index 6878c95797..e5965d4551 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) ||
-
+
swait_active(&ffs->ep0req_completion.wait) ||
waitqueue_active(&ffs->ep0req_completion.wait) ||
然后有些配置是默认就打开的,我们这里全部修改为默认关闭。
diff --git a/drivers/adapter/khdf/linux/Kconfig b/drivers/adapter/khdf/linux/Kconfig
index 037b190fb2..a3b15659b4 100644
--- a/drivers/adapter/khdf/linux/Kconfig
+++ b/drivers/adapter/khdf/linux/Kconfig
@@ -1,7 +1,7 @@
config DRIVERS_HDF
bool "Enable HDF manager"
- default y
+ default n
help
Answer Y to enable Linux support HDF.
@@ -25,4 +25,4 @@ source "drivers/hdf/khdf/model/usb/host/Kconfig"
source "drivers/hdf/khdf/model/usb/device/Kconfig"
source "drivers/hdf/khdf/model/audio/Kconfig"
source "drivers/hdf/khdf/model/misc/vibrator/Kconfig"
-source "drivers/hdf/khdf/model/misc/dsoftbus/Kconfig"
\ No newline at end of file
+source "drivers/hdf/khdf/model/misc/dsoftbus/Kconfig"
diff --git a/drivers/adapter/khdf/linux/model/audio/Kconfig b/drivers/adapter/khdf/linux/model/audio/Kconfig
index 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.
diff --git a/drivers/adapter/khdf/linux/model/usb/device/Kconfig b/drivers/adapter/khdf/linux/model/usb/device/Kconfig
index 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.
diff --git a/drivers/adapter/khdf/linux/model/usb/host/Kconfig b/drivers/adapter/khdf/linux/model/usb/host/Kconfig
index 97f59cb6a0..710f80dba6 100644
--- a/drivers/adapter/khdf/linux/model/usb/host/Kconfig
+++ b/drivers/adapter/khdf/linux/model/usb/host/Kconfig
@@ -11,7 +11,7 @@
config DRIVERS_HDF_USB_PNP_NOTIFY
bool "Enable HDF USB PNP Notify driver"
- default y
+ default n
depends on DRIVERS_HDF
help
Answer Y to choice HDF USB PNP Notify driver.
到此,添加框架基本计算完成了。如果启动出现如下情况,是因为没有把binder驱动补丁添加造成的 在kernel/linux/patches/linux-5.4/imx6ul_nand_linux_patch/imx6ul_nand_linux_small.patch 中添加如下补丁内容即可解决。
diff --git a/include/uapi/linux/android/binder.h b/include/uapi/linux/android/binder.h
index 731780804..7348b3a0b 100644
--- a/include/uapi/linux/android/binder.h
+++ b/include/uapi/linux/android/binder.h
@@ -27,7 +27,7 @@
((((c1)<<24)) | (((c2)<<16)) | (((c3)<<8)) | (c4))
-
+
enum {
BINDER_TYPE_BINDER = B_PACK_CHARS('s', 'b', '*', B_TYPE_LARGE),
BINDER_TYPE_WEAK_BINDER = B_PACK_CHARS('w', 'b', '*', B_TYPE_LARGE),
成功运行截图 启动的时候发现hilog并未成功注册
[ 1.425978] register hilog error -16
[ 1.429805] hilog_init Start-16
修改补丁如下
diff --git a/kernel/linux/linux-5.4/drivers/staging/hilog/hilog.c b/kernel/linux/linux-5.4/drivers/staging/hilog/hilog.c
index dae5ab074c..46700b146a 100644
--- a/kernel/linux/linux-5.4/drivers/staging/hilog/hilog.c
+++ b/kernel/linux/linux-5.4/drivers/staging/hilog/hilog.c
@@ -337,12 +337,14 @@ static void hilog_device_init(void)
hilog_dev.count = 0;
}
+static dev_t dev_t_no;
+
static int __init hilogdev_init(void)
{
int result;
- dev_t devno = MKDEV(hilog_major, 0);
-
- result = register_chrdev_region(devno, 2, "hilog");
+ //dev_t devno = MKDEV(hilog_major, 0);
+ alloc_chrdev_region(&dev_t_no,2,255,"hilog");
+ //result = register_chrdev_region(devno, 2, "hilog");
if (result < 0) {
pr_emerg("\t register hilog error %d\n", result);
return result;
@@ -352,7 +354,7 @@ static int __init hilogdev_init(void)
g_hilog_cdev.owner = THIS_MODULE;
g_hilog_cdev.ops = &hilog_fops;
- cdev_add(&g_hilog_cdev, MKDEV(hilog_major, 0), HILOG_NR_DEVS);
+ cdev_add(&g_hilog_cdev, dev_t_no/*MKDEV(hilog_major, 0)*/, HILOG_NR_DEVS);
hilog_device_init();
return 0;
|