> 文档中心 > 鸿蒙移植过程记录

鸿蒙移植过程记录


添加编译构建过程

首先在源码根目录vendor下添加 vendor/xingyun/t113_nand此目录,可参考hisilicon/hispark_taurus_linux/实现,创建好自己产品目录之后开始添加文件,首先需要创建的文件为编译文件,BUILD.gn,添加配置文件config.json,添加hals目录,目录暂时可以为空。其中BUILD.gn中的内容可以暂时先只有如下语句即可,注意,双引号内容最好与当前目录名称相同
group(“t113_nand”) {
}
然后打开config.json文件,添加相应的字段描述。如下为我添加构建初期的文件内容
{
“product_name”: “xingyun_t113_nand_board”,
“ohos_version”: “OpenHarmony 3.0”,
“device_company”: “xingyunelec”, //对应源码目录下/device/目录下的文件夹 xingyunelec
“board”: “t113_nand_linux”, //对应device/xingyunelec/目录下的文件夹t113_nand_linux
“kernel_type”: “linux”,
“kernel_version”: “5.4”,
“subsystems”: [
],
“third_party_dir”: “//third_party”,
“product_adapter_dir”: “//vendor/xingyun/t113_nand/hals”
}
所以你需要在device目录下创建该有的文件夹,示例我这里需要的目录则为device/xingyunelec/t113_nand_linux,创建完成目录后我们可以进行hb set操作了,可以看到出现我们的选择项了,选择我们自己的产品,然后回车
在这里插入图片描述回车之后出现如下图错误信息,因为我们没有配置产品的相关信息,现在我们开始配置产品信息

鸿蒙移植过程记录
首先同样需要一个编译文件BUILD.gn,里面内容同上文大同小异,内容为如下。
group(“t113_nand_linux”) {
}
然后创建文件夹sdk_linux,改名字可以随意起,然后在device/xingyunelec/t113_nand_linux/sdk_linux目录里面创建文件config.gni。打开文件,其中内容做个介绍

kernel_type = “linux” //使用的内核,一般有"linux", “liteos_a”, “liteos_m”.
kernel_version = “5.4” //使用的内核版本
board_cpu = “cortex-a7” //使用的芯片架构, “cortex-a7”, “riscv32”
board_arch = “” //使用的芯片架构 “armv7-a”, “rv32imac”
board_toolchain = “” //使用的工具链gcc-arm-none-eabi, arm-linux-harmonyeabi-gcc, ohos-clang
board_toolchain_path = “” //使用的工具链路径,直接把交叉编译器的全路径放进来即可
board_toolchain_prefix = “” //gcc-arm-none-
board_toolchain_type = “clang” //“gcc” or “clang”
board_cflags = [ //编译c的选项
“-mfloat-abi=softfp”,
“-mfpu=neon-vfpv4”,
]
board_cxx_flags = [
“-mfloat-abi=softfp”,
“-mfpu=neon-vfpv4”,
]
board_ld_flags = [] //链接库选项

board_include_dirs = [] //包含的第三方源码头文件

board_adapter_dir = “”

board_configed_sysroot = “”

storage_type = “”
填写以上内容即可。
然后我们再去执行hb set,选择我们添加的产品执行结果如下图,不会报错了。
鸿蒙移植过程记录
接着我们尝试开始进行编译,直接运行hb build。
在这里插入图片描述
然后发现报错了,而且编译的还是5.10的内核,这是怎么回事,其实是会去build/ohos/kernel/kernel.gni读取这里面的值去默认编译内核版本,为什么会这样,目前还不知道,知道的可以告知下。那我们先添加内核组件尝试下,可能不能去编译我们选定的内核版本,修改
vendor/xingyun/t113_nand/config.json文件,在组件里面添加内核编译组件,添加的内容如下
{
“subsystem”: “kernel”,
“components”: [
{ “component”: “linux_5_4”, “features”:[] }
]
}
添加后完整的文件内容如下图所示
在这里插入图片描述
添加完成后开始编译,执行hb build -f,很好,又报错了,报错内容如下,很明显,找不到组件编译规则
[OHOS INFO] ERROR at //build/lite/BUILD.gn:60:9: Assertion failed.
[OHOS INFO] assert(
[OHOS INFO] ^-----
[OHOS INFO] Component “linux_5_4” not found, please check your product configuration.
[OHOS INFO] See //build/lite/BUILD.gn:61:13:
[OHOS INFO] component_found,
[OHOS INFO] ^--------------
[OHOS INFO] This is where it was set.
[OHOS INFO] ohos_build_compiler: clang
[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/gn gen /home/d1/openHarmony/t113/out/t113_nand_linux/xingyun_t113_nand_board --root=/home/d1/openHarmony/t113 --dotfile=/home/d1/openHarmony/t113/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/d1/openHarmony/t113/vendor/xingyun/t113_nand" device_path="/home/d1/openHarmony/t113/device/xingyunelec/t113_nand_linux/sdk_linux" ohos_kernel_type=“linux” ohos_build_type=“debug” ohos_build_time=“1648698057822” ohos_build_datetime=“2022-03-31 19:40:57” ohos_full_compile=true" failed
[OHOS ERROR] return code: 1
[OHOS ERROR] execution path: /home/d1/openHarmony/t113
所以需要我们去解决,通过对比,发现在hisilicon下面有使用其他版本的内核的组件,最后定位到的文件为 build/lite/components/kernel.json,尝试在此处添加我们自定义内核的编译规则。添加如下内容即可。文件正确性有待验证,主要是"output": [ “uImage_hi3516dv300_smp” ],

{
“component”: “linux_5_4”,
“description”: “linux 5.4”,
“optional”: “false”,
“dirs”: [
“kernel/linux/build”
],
“targets”: [
“//kernel/linux/build:linux_kernel”
],
“rom”: “”,
“ram”: “”,
“output”: [
“uImage_hi3516dv300_smp”
],
“features”: [],
“adapted_board”: [
“t113_nand_linux”
],
“adapted_kernel”: [ “linux” ],
“deps”: {
“components”: [],
“third_party”: []
}
}
然后修改文件kernel/linux/build/BUILD.gn,将文中内容对比修改为如下内容
-command = “./kernel_module_build.sh ${outdir} ${build_type} ${clang_dir} ${product_path_rebase} ${board_name} ${linux_kernel_version}”
+command = “./kernel_module_build.sh ${outdir} ${build_type} ${clang_dir} ${product_path_rebase} b o a rdn a m e l i n u x − {board_name} linux- boardnamelinux{kernel_version}”