移植openharmony之添加init进程
接上篇制作了根文件系统,但是却没有生成init可执行程序,init进程作为挂载根文件系统执行的第一个进程,没有的话,根文件系统肯定是无法进行挂载的,现在我们来解决这个问题,让系统能正确进入终端。
首先修改vendor/xingyun/t113_nand/config.json文件,添加如下内容文件
diff --git a/vendor/xingyun/t113_nand/config.json b/vendor/xingyun/t113_nand/config.jsonindex e059e90708..62f74ff706 100755--- a/vendor/xingyun/t113_nand/config.json+++ b/vendor/xingyun/t113_nand/config.json@@ -11,6 +11,15 @@ "components": [ { "component": "linux_5_4", "features":[] } ]+ },^M+ {^M+ "subsystem": "startup",^M+ "components": [^M+ { "component": "bootstrap_lite", "features":[] },^M+ { "component": "syspara_lite", "features":[] },^M+ { "component": "init_lite", "features":[] },^M+ { "component": "appspawn_lite", "features":[] }^M+ ]^M} ], "third_party_dir": "//third_party",
添加完成后,执行命令hb build -f,编译出错,提示没有文件
“$ohos_product_adapter_dir/utils/sys_param:hal_sysparam”,
d1@d1-virtual-machine:~/openHarmony/t113(master)$ 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] ERROR at //base/startup/syspara_lite/frameworks/parameter/src/BUILD.gn:46:7: Unable to load "/home/d1/openHarmony/t113/vendor/xingyun/t113_nand/hals/utils/sys_param/BUILD.gn".[OHOS INFO]"$ohos_product_adapter_dir/utils/sys_param:hal_sysparam",[OHOS INFO]^-------------------------------------------------------[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="1648763250192" ohos_build_datetime="2022-04-01 13:47:30" ohos_full_compile=true" failed[OHOS ERROR] return code: 1[OHOS ERROR] execution path: /home/d1/openHarmony/t113
这个我们直接复制源码中hisilicon目录下的这个文件,执行如下命令即可进行文件拷贝
cp hisilicon/hispark_taurus_linux/hals/* xingyun/t113_nand/hals/ -r
然后直接重新编译hb build -f,编译成功如下图,截取部分编译打印,
[OHOS INFO] [601/627] STAMP obj/foundation/appexecfwk/appexecfwk_lite/frameworks/bundle_lite/bundle_notes.stamp[OHOS INFO] [602/627] SOLINK ./libabilitymanager.so[OHOS INFO] [603/627] STAMP obj/foundation/aafwk/aafwk_lite/frameworks/abilitymgr_lite/aafwk_abilityManager_lite.stamp[OHOS INFO] [604/627] SOLINK ./libability.so[OHOS INFO] [605/627] STAMP obj/foundation/aafwk/aafwk_lite/frameworks/ability_lite/ability_notes.stamp[OHOS INFO] [606/627] STAMP obj/foundation/aafwk/aafwk_lite/frameworks/ability_lite/aafwk_abilitykit_lite.stamp[OHOS INFO] [607/627] LLVM LINK ./bin/appspawn[OHOS INFO] [608/627] STAMP obj/base/startup/appspawn_lite/services/appspawn_lite.stamp[OHOS INFO] [609/627] clang++ obj/third_party/googletest/googletest/src/libgtest.gtest.o[OHOS INFO] [610/627] AR libs/libgtest.a[OHOS INFO] [611/627] AR libs/libgtest_main.a[OHOS INFO] [612/627] SOLINK ./libmbedtls.so[OHOS INFO] [613/627] STAMP obj/third_party/mbedtls/mbedtls.stamp[OHOS INFO] [614/627] STAMP obj/third_party/mbedtls/mbedtls_ndk.stamp[OHOS INFO] [615/627] SOLINK ./libsysparam.so[OHOS INFO] [616/627] STAMP obj/base/startup/syspara_lite/frameworks/parameter/parameter_notes.stamp[OHOS INFO] [617/627] STAMP obj/base/startup/syspara_lite/frameworks/parameter/parameter.stamp[OHOS INFO] [618/627] LLVM LINK ./bin/mksh[OHOS INFO] [619/627] LLVM LINK test/unittest/startup/bin/appspawn_test.bin[OHOS INFO] [620/627] STAMP obj/base/startup/appspawn_lite/services/test/unittest/common/unittest.stamp[OHOS INFO] [621/627] STAMP obj/base/startup/appspawn_lite/services/unittest.stamp[OHOS INFO] [622/627] LLVM LINK ./bin/toybox[OHOS INFO] [623/627] LLVM LINK ./bin/init[OHOS INFO] [624/627] STAMP obj/build/lite/ohos.stamp[OHOS INFO] [625/627] LLVM LINK test/unittest/startup/bin/init_test.bin[OHOS INFO] [626/627] STAMP obj/base/startup/init_lite/services/test/unittest/common/unittest.stamp[OHOS INFO] [627/627] STAMP obj/base/startup/init_lite/services/unittest.stamp[OHOS INFO] xingyun_t113_nand_board build success[OHOS INFO] cost time: 0:02:03
使用命令查看/bin/init文件,注意一定是要有如下语句才能正确挂载上,否则会报错,无法进行挂载
file out/t113_nand_linux/xingyun_t113_nand_board/rootfs/bin/init正确结果如下out/t113_nand_linux/xingyun_t113_nand_board/rootfs/bin/init: ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-musl-arm.so.1, stripped
本人之前就遇到是如下这种结果的,没有正确打印出/lib/ld-musl-arm.so.1,导致一直无法进行挂载
out/t113_nand_linux/xingyun_t113_nand_board/rootfs/bin/init: ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-, stripped
后面更新下ubuntu工具又好了,不太清楚什么原因导致的。编译成功后,去尝试下进行挂载
4.908340] [D/HDF_LOG_TAG] DeviceManagerInit enter[ 4.914334] [I/osal_cdev] register hdf class success[ 4.921684] [I/osal_cdev] add cdev dev_mgr success[ 4.921684][ 4.928818] [I/hcs_blob_if] CheckHcsBlobLength: the blobLength: 88, byteAlign: 1[ 4.937368] [E/HDF_LOG_TAG] HdfAttributeManagerGetHostList: get hdf manager node is null[ 4.946551] [W/devmgr_service] DevmgrServiceStartDeviceHosts: host list is null[ 4.954856] [D/HDF_LOG_TAG] DeviceManagerInit start success[ 4.961212] clk: Not disabling unused clocks[ 4.966040] alloc_fd: slot 0 not NULL![ 4.973992] UBIFS (ubi0:5): Mounting in unauthenticated mode[ 4.982374] UBIFS (ubi0:5): background thread "ubifs_bgt0_5" started, PID 951[ 5.101694] UBIFS (ubi0:5): start fixing up free space[ 5.268304] UBIFS (ubi0:5): free space fixup complete[ 5.335861] UBIFS (ubi0:5): UBIFS: mounted UBI device 0, volume 5, name "rootfs"[ 5.344253] UBIFS (ubi0:5): LEB size: 258048 bytes (252 KiB), min./max. I/O unit sizes: 4096 bytes/4096 bytes[ 5.355398] UBIFS (ubi0:5): FS size: 31223808 bytes (29 MiB, 121 LEBs), journal size 5419008 bytes (5 MiB, 21 LEBs)[ 5.367119] UBIFS (ubi0:5): reserved for root: 0 bytes (0 KiB)[ 5.373699] UBIFS (ubi0:5): media format: w4/r0 (latest is w5/r0), UUID A762279D-B49F-4EDC-877F-4BD007D0B2AF, small LPT model[ 5.389249] VFS: Mounted root (ubifs filesystem) on device 0:14.[ 5.397395] Freeing unused kernel memory: 1024K[ 5.402675] Run bin/init as init processsh: /etc/init.d/rcS: No such file or directory[ 7.380729] hdmi_hpd_sys_config_release
可以看到成功进行了挂载根文件系统的init进程,至此,添加init进程结束。