RK3568 OH5.1 源码编译及问题
安装编译器和二进制工具
在源码根目录下执行prebuilts脚本,安装编译器及二进制工具。
bash build/prebuilts_download.sh
在源码根目录执行如下指令安装hb编译工具:
python3 -m pip install --user build/hb
使用build.sh脚本编译源码
- 进入源码根目录,执行如下命令进行版本编译。
x86系统编译:
./build.sh --product-name {product_name} --ccache
ARM系统编译:
./build.sh --product-name {product_name} --ccache --target-cpu arm64
说明: {product_name}为当前支持的产品名称,例如Hi3516DV300、rk3568等。
- 检查编译结果
Please refer to: https://gitee.com/openharmony/developtools_integration_verification/tree/master/tools/startup_guard/rules/NO-Config-Cmds-In-Init/README.md
Do NO-Config-SystemParameter-In-INIT rule checking now:
[NOT ALLOWED]: DAC overallocated memoryPlease refer to: https://gitee.com/openharmony/developtools_integration_verification/tree/master/tools/startup_guard/rules/NO-Config-SystemParameter-In-INIT/README.md
Do NO-User-Group_In-Init rule checking now:
[NOT ALLOWED]: quickfix has different passwd and group valuesPlease refer to: https://gitee.com/openharmony/developtools_integration_verification/tree/master/tools/startup_guard/rules/NO-User-Group_In-Init/README.md
Do NO-Plug-In_Module-Init rule checking now:
[NOT ALLOWED]: libmodule_update_init.z.so is not in whitelists
[NOT ALLOWED]: the dependent shared library libhisysevent.z.so of librebootmodule.z.so is not in whitelistPlease refer to: https://gitee.com/openharmony/developtools_integration_verification/tree/master/tools/startup_guard/rules/NO-Plug-In_Module-Init/README.md
Please modify according to README.md
[OHOS INFO] rk3568 build success
[OHOS INFO] Cost Time: 2:58:42
=====build successful=====
2025-05-19 22:57:23
++++++++++++++++++++++++++++++++++++++++
编译完成后,log中显示如下:
[OHOS INFO] rk3568 build success
[OHOS INFO] Cost Time: 2:58:42
=====build successful=====
编译所生成的文件都归档在out/{device_name}/目录下,结果镜像输出在out/{device_name}/packages/phone/images/ 目录下。
使用hb编译
hb set
hb build
执行hb set选择产品,然后执行hb build进行编译。
编译
编译RK3568
./build.sh --product-name rk3568 --ccache 或者
./build.sh --p rk3568 --ccache
编译生成固件如下:
out/rk3568/packages/phone/images/
├── boot_linux.img
├── chip_ckm.img
├── chip_prod.img
├── config.cfg
├── eng_system.img
├── MiniLoaderAll.bin
├── parameter.txt
├── ramdisk.img
├── resource.img
├── sys_prod.img
├── system.img
├── uboot.img
├── updater.img
├── userdata.img
└── vendor.img
编译OH 5.1.0 出错 ld.lld: error: undefined symbol: ff_hwcontext_type_vulkan
[OHOS ERROR] [NINJA] [49516/91184] SOLINK thirdparty/ffmpeg/libohosffmpeg.z.so
[OHOS ERROR] [NINJA] FAILED: thirdparty/ffmpeg/libohosffmpeg.z.so lib.unstripped/thirdparty/ffmpeg/libohosffmpeg.z.so
[OHOS ERROR] [NINJA] /usr/bin/env "../../build/toolchain/gcc_solink_wrapper.py" --readelf="../../prebuilts/clang/ohos/linux-x86_64/llvm/bin/llvm-readobj" --nm="../../prebuilts/clang/ohos/linux-x86_64/llvm/bin/llvm-nm" --strip=../../prebuilts/clang/ohos/linux-x86_64/llvm/bin/llvm-strip --strip-debug-whitelist=../../build/toolchain/strip_debug_whitelist.txt --sofile="./lib.unstripped/thirdparty/ffmpeg/libohosffmpeg.z.so" --output="thirdparty/ffmpeg/libohosffmpeg.z.so" --clang-base-dir="/home/xgj/ws/OpenHarmony-v5.1.0-Release/OpenHarmony/prebuilts/clang/ohos" --mini-debug -- ../../prebuilts/clang/ohos/linux-x86_64/llvm/bin/clang++ -shared -Wl,--pack-dyn-relocs=android+relr -Wl,--fatal-warnings -Wl,--build-id=md5 -fPIC -Wl,-z,noexecstack -Wl,-z,now -Wl,-z,relro -Wl,-z,defs -Wl,--as-needed -fuse-ld=lld -Wl,--icf=all -Wl,--color-diagnostics -flto=thin -Wl,--thinlto-jobs=16 -Wl,--thinlto-cache-dir=thinlto-cache -Wl,--lto-O0 -march=armv7-a -Wl,--no-undefined -Wl,--exclude-libs=libunwind_llvm.a -Wl,--exclude-libs=libc++_static.a -Wl,--exclude-libs=libvpx_assembly_arm.a --target=arm-linux-ohos -Werror -Wl,--warn-shared-textrel -Wl,-O2 -Wl,--gc-sections -Wl,--gdb-index --sysroot=obj/third_party/musl -nostdlib -Lobj/third_party/musl/usr/lib/arm-linux-ohos -L../../prebuilts/clang/ohos/linux-x86_64/llvm/lib/clang/15.0.4/lib/arm-linux-ohos -Wl,--warn-shared-textrel -fsanitize-trap=all -ftrap-function=abort -o "./lib.unstripped/thirdparty/ffmpeg/libohosffmpeg.z.so" @"thirdparty/ffmpeg/libohosffmpeg.z.so.rsp" -Wl,-soname="libohosffmpeg.z.so"
[OHOS ERROR] [NINJA] ld.lld: error: undefined symbol: ff_hwcontext_type_vulkan
[OHOS ERROR] [NINJA] >>> referenced by hwcontext.c:0 (../../third_party/ffmpeg/libavutil/hwcontext.c:0)
[OHOS ERROR] [NINJA] >>> thinlto-cache/llvmcache-C8050A3CD6401B4BEBAEBAC2259B116F368BCFD6:(av_hwdevice_iterate_types)
[OHOS ERROR] [NINJA] >>> referenced by hwcontext.c:0 (../../third_party/ffmpeg/libavutil/hwcontext.c:0)
[OHOS ERROR] [NINJA] >>> thinlto-cache/llvmcache-C8050A3CD6401B4BEBAEBAC2259B116F368BCFD6:(av_hwdevice_ctx_alloc)
[OHOS ERROR] [NINJA] clang-15: error: linker command failed with exit code 1 (use -v to see invocation)[OHOS INFO] User Cpu%: 0.3%[OHOS INFO] System Cpu%: 0.9%[OHOS INFO] Idle CPU%: 98.8%[OHOS INFO] Total Memory: 31.4GB[OHOS INFO] Free Memory: 4.8GB[OHOS INFO] Swap Memory: 2.0GB[OHOS INFO] Filesystem: tmpfs, Size: 3.2G, Used: 3.3M, Available: 3.2G, Use%: 1%, Mounted on: /run[OHOS INFO] Filesystem: /dev/sda3, Size: 491G, Used: 428G, Available: 39G, Use%: 92%, Mounted on: /[OHOS INFO] Filesystem: tmpfs, Size: 16G, Used: 0, Available: 16G, Use%: 0%, Mounted on: /dev/shm[OHOS INFO] Filesystem: tmpfs, Size: 5.0M, Used: 0, Available: 5.0M, Use%: 0%, Mounted on: /run/lock[OHOS INFO] Filesystem: tmpfs, Size: 16G, Used: 0, Available: 16G, Use%: 0%, Mounted on: /run/qemu[OHOS INFO] Filesystem: /dev/sda2, Size: 512M, Used: 6.1M, Available: 506M, Use%: 2%, Mounted on: /boot/efi[OHOS INFO] Filesystem: tmpfs, Size: 3.2G, Used: 72K, Available: 3.2G, Use%: 1%, Mounted on: /run/user/128[OHOS INFO] Filesystem: tmpfs, Size: 3.2G, Used: 60K, Available: 3.2G, Use%: 1%, Mounted on: /run/user/1000[OHOS ERROR] [NINJA] Traceback (most recent call last):
[OHOS ERROR] [NINJA] File "/home/xgj/ws/OpenHarmony-v5.1.0-Release/OpenHarmony/build/hb/containers/status.py", line 47, in wrapper
[OHOS ERROR] [NINJA] return func(*args, **kwargs)
[OHOS ERROR] [NINJA] ^^^^^^^^^^^^^^^^^^^^^
[OHOS ERROR] [NINJA] File "/home/xgj/ws/OpenHarmony-v5.1.0-Release/OpenHarmony/build/hb/modules/ohos_build_module.py", line 70, in run
[OHOS ERROR] [NINJA] raise exception
[OHOS ERROR] [NINJA] File "/home/xgj/ws/OpenHarmony-v5.1.0-Release/OpenHarmony/build/hb/modules/ohos_build_module.py", line 67, in run
[OHOS ERROR] [NINJA] super().run()
[OHOS ERROR] [NINJA] File "/home/xgj/ws/OpenHarmony-v5.1.0-Release/OpenHarmony/build/hb/modules/interface/build_module_interface.py", line 70, in run
[OHOS ERROR] [NINJA] raise exception
[OHOS ERROR] [NINJA] File "/home/xgj/ws/OpenHarmony-v5.1.0-Release/OpenHarmony/build/hb/modules/interface/build_module_interface.py", line 68, in run
[OHOS ERROR] [NINJA] self._ninja()
[OHOS ERROR] [NINJA] File "/home/xgj/ws/OpenHarmony-v5.1.0-Release/OpenHarmony/build/hb/util/timer_util.py", line 30, in inner
[OHOS ERROR] [NINJA] res = func(*arg, **kwarg)
[OHOS ERROR] [NINJA] ^^^^^^^^^^^^^^^^^^^
[OHOS ERROR] [NINJA] File "/home/xgj/ws/OpenHarmony-v5.1.0-Release/OpenHarmony/build/hb/modules/interface/build_module_interface.py", line 125, in _ninja
[OHOS ERROR] [NINJA] self._target_compilation()
[OHOS ERROR] [NINJA] File "/home/xgj/ws/OpenHarmony-v5.1.0-Release/OpenHarmony/build/hb/modules/ohos_build_module.py", line 112, in _target_compilation
[OHOS ERROR] [NINJA] self.target_compiler.run()
[OHOS ERROR] [NINJA] File "/home/xgj/ws/OpenHarmony-v5.1.0-Release/OpenHarmony/build/hb/services/ninja.py", line 39, in run
[OHOS ERROR] [NINJA] self._execute_ninja_cmd()
[OHOS ERROR] [NINJA] File "/home/xgj/ws/OpenHarmony-v5.1.0-Release/OpenHarmony/build/hb/services/ninja.py", line 70, in _execute_ninja_cmd
[OHOS ERROR] [NINJA] SystemUtil.exec_command(
[OHOS ERROR] [NINJA] File "/home/xgj/ws/OpenHarmony-v5.1.0-Release/OpenHarmony/build/hb/util/system_util.py", line 128, in exec_command
[OHOS ERROR] [NINJA] LogUtil.get_failed_log(log_path)
[OHOS ERROR] [NINJA] File "/home/xgj/ws/OpenHarmony-v5.1.0-Release/OpenHarmony/build/hb/util/log_util.py", line 209, in get_failed_log
[OHOS ERROR] [NINJA] LogUtil.get_compiler_failed_log(log_path)
[OHOS ERROR] [NINJA] File "/home/xgj/ws/OpenHarmony-v5.1.0-Release/OpenHarmony/build/hb/util/log_util.py", line 196, in get_compiler_failed_log
[OHOS ERROR] [NINJA] raise OHOSException(
[OHOS ERROR] [NINJA] exceptions.ohos_exception.OHOSException: COMPILE Failed! Please check error in /home/xgj/ws/OpenHarmony-v5.1.0-Release/OpenHarmony/out/rk3568/error.log, and for more build information in /home/xgj/ws/OpenHarmony-v5.1.0-Release/OpenHarmony/out/rk3568/build.log
[OHOS ERROR] [NINJA][OHOS ERROR] [NINJA] Code: 4000
[OHOS ERROR] [NINJA]
[OHOS ERROR] [NINJA] Reason: COMPILE Failed! Please check error in /home/xgj/ws/OpenHarmony-v5.1.0-Release/OpenHarmony/out/rk3568/error.log, and for more build information in /home/xgj/ws/OpenHarmony-v5.1.0-Release/OpenHarmony/out/rk3568/build.log
[OHOS ERROR] [NINJA]
[OHOS ERROR] [NINJA] Error Type: Ninja build error
[OHOS ERROR] [NINJA]
[OHOS ERROR] [NINJA] Description: An unknown error occurred while executing 'ninja -C'.
[OHOS ERROR] [NINJA]
[OHOS ERROR] [NINJA] Solution: no solution
[OHOS ERROR] [NINJA]
=====build error=====
无论使用站点下载或者repo方式下载源码编译都出现这个错误,而别人编译是没有这个错误的。
怀疑是环境问题或源码不全,试下用如下方式看是否能解决:
1. 删除out目录,清除缓存 再次编译
rm -rf ./out
rm -rf ~/.ccache
hb clean
ccache -C
执行编译命令
2. 如果还报错
重新同步一下源码,并预编译 :
repo sync -c -j16
repo forall -c ‘git lfs pull’
bash build/prebuilts_download.sh --skip-ssl
重复 1 里面的的步骤再次编译…
用了上述操作依然解决不了。
以前编译过4.1源码,环境应该是没问题的。
被搞郁闷了,别人编译都是一次过,没这问题。
按照错误提示ff_hwcontext_type_vulkan和by hwcontext.c进去源码分析错误原因,全局搜索ff_hwcontext_type_vulkan在哪里定义和使用了的,发现是在third_party/ffmpeg/libavutil/hwcontext_vulkan.c中定义,都有定义,为啥还会编译错误呢?看third_party/ffmpeg/libavutil/hwcontext.c:
static const HWContextType * const hw_table[] = {
#if CONFIG_CUDA&ff_hwcontext_type_cuda,
#endif
#if CONFIG_D3D11VA&ff_hwcontext_type_d3d11va,
#endif
#if CONFIG_LIBDRM&ff_hwcontext_type_drm,
#endif
#if CONFIG_DXVA2&ff_hwcontext_type_dxva2,
#endif
#if CONFIG_OPENCL&ff_hwcontext_type_opencl,
#endif
#if CONFIG_QSV&ff_hwcontext_type_qsv,
#endif
#if CONFIG_VAAPI&ff_hwcontext_type_vaapi,
#endif
#if CONFIG_VDPAU&ff_hwcontext_type_vdpau,
#endif
#if CONFIG_VIDEOTOOLBOX&ff_hwcontext_type_videotoolbox,
#endif
#if CONFIG_MEDIACODEC&ff_hwcontext_type_mediacodec,
#endif
#if CONFIG_VULKAN&ff_hwcontext_type_vulkan,
#endifNULL,
};
在这里看到ff_hwcontext_type_vulkan是在这里被使用的,链接找不到,说明CONFIG_VULKAN被配置成了1,但是ffmpeg的关于vulkan的功能又被禁用了,所以链接时找不到ff_hwcontext_type_vulkan?
找到CONFIG_VULKAN定义的地方,是在out/rk3568/gen/third_party/ffmpeg/include/config.h文件,在这里还可以看到Makefile:out/rk3568/gen/third_party/ffmpeg/include/config.mak
对比以前编译成功的4.1代码中的这2个文件发现,4.1配置如下,config.mak、config.h:
!CONFIG_VULKAN=yes
#define CONFIG_VULKAN 0
而我编译OH5.1这2个配置确实这样的:
CONFIG_VULKAN=yes
#define CONFIG_VULKAN 1
也对比同事编译的生成的配置也是和4.1的一样。搞不懂为啥我编译生成就变了呢,源码也没修改过,这应该就是一直编译出链接现这个错误的原因了。
那去分析ffmpeg配置。
third_party/ffmpeg/BUILD.gn是产生编译ninja编译文件的,其中调用//third_party/ffmpeg/ohos_config.sh进行配置ffmpeg。
action("gen_config_header") {if (current_os == "ios") {script = "//third_party/ffmpeg/ios_config.sh"} else if (current_os == "android" && host_os == "mac") {script = "//third_party/ffmpeg/android_mac_config.sh"} else {script = "//third_party/ffmpeg/ohos_config.sh"}if (!is_cross_platform_build) {if (ffmpeg_selected_platform == "aarch64") {print("third_party:ffmpeg # external_deps //third_party/musl:soft_libc_musl_static")external_deps = [ "musl:soft_libc_musl_static" ]}}
分析对比third_party/ffmpeg/ohos_config.sh发现和OH4.1、同事的文件是一样的。懵逼了。
只能分析ohos_config.sh了,该文件里有2处定义FFmpeg配置的地方
第一处在文件18行,配置–disable-vulkan:
FF_CONFIG_OPTIONS="......--disable-vulkan......"
第二处在文件130行,没有配置–disable-vulkan。
尝试在该配置加入–disable-vulkan,然后编译,嗨,编译成功了。
至于为啥和别的配置一样却编译出现这个问题就搞不懂了,见鬼了。