Openharmony之GPU Mesa3D移植二(render 新框架)
本文主要介绍在OpenHarmony上,基于RK3568移植开源GPU Mesa3D图形驱动,使用openharmony v3.1-Release 版本,该版本使用了新框架,内核使用了kernel 5.10.79版本,并使用render_service替换了Weston。
1、下载源码
创建编译openharmony的docker,安装依赖,下载源码
mkdir oh31re
cd oh31re/
podman run --name hm-31re -it -v ./:/home/openharmony swr.cn-south-1.myhuaweicloud.com/openharmony-docker/openharmony-docker-standard:0.0.9 /bin/bash
git config --global user.name “test”
git config --global user.email “test@com.cn”
git config --global credential.helper store
安装依赖:
curl -s https://gitee.com/oschina/repo/raw/fork_flow/repo-py3 > /usr/local/bin/repo
chmod a+x /usr/local/bin/repo
apt-get update && apt-get install -y binutils git git-lfs gnupg flex bison gperf build-essential zip curl zlib1g-dev gcc-multilib g+±multilib libc6-dev-i386 lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z1-dev ccache libgl1-mesa-dev libxml2-utils xsltproc unzip m4 bc gnutls-bin python3.8 python3-pip ruby libssl-dev
pip3 install -i https://repo.huaweicloud.com/repository/pypi/simple requests
下载源码,并编译:
repo init -u https://gitee.com/openharmony/manifest.git -b refs/tags/OpenHarmony-v3.1-Release --no-repo-verify
repo sync -c
repo forall -c ‘git lfs pull’
bash build/prebuilts_download.sh
./build.sh --ccache --product-name rk3568
编译成功,刷机后,能进入系统,也能进入图形,当前版本使用的是闭源GPU驱动,所以使用起来也是很流畅的。
2、编译mesa 3D库
进入容器:
podman exec -it hm-31re bash
下载源码:
git clone https://gitee.com/openharmony-sig/third_party_mesa3d.git
安装依赖:
apt-get install -y meson cmake llvm
python3 -m pip install meson==0.62.0
python -m pip install --upgrade pip
pip install mako atomic markupsafe
编译依赖库expat:
./build.sh --ccache --product-name rk3568 --build-target expat
编译mesa 3D:
cd third_party_mesa3d/
python ohos/build_ohos.py /home/openharmony/ rk3568 /home/openharmony/third_party_mesa3d/
拷贝库文件到device/hihope/hardware/gpu
cp build-ohos/src/egl/libEGL.so.1.0.0 …/device/hihope/hardware/gpu/
cp build-ohos/install/lib/libGLESv1_CM.so.1.1.0 …/device/hihope/hardware/gpu/
cp build-ohos/install/lib/libGLESv2.so.2.0.0 …/device/hihope/hardware/gpu/
cp build-ohos/install/lib/libgbm.so.1.0.0 …/device/hihope/hardware/gpu/
cp build-ohos/install/lib/libglapi.so.0.0.0 …/device/hihope/hardware/gpu/
cp build-ohos/src/gallium/targets/dri/libgallium_dri.so …/device/hihope/hardware/gpu/
cp build-ohos/install/lib/dri/panfrost_dri.so …/device/hihope/hardware/gpu/
注意,使用编译mesa库需要把third_party_mesa3d放到openharmony源码中。
3、修改内核配置
1)修改内核dtb
修改out/kernel/src_tmp/linux-5.10/arch/arm64/boot/dts/rockchip/rk3568.dtsi适配开源panfrost,如下:
--- arch/arm64/boot/dts/rockchip/rk3568.dtsi-bak 2022-02-15 01:39:52.169152789 +0000
+++ arch/arm64/boot/dts/rockchip/rk3568.dtsi 2022-02-15 02:02:42.096047298 +0000
@@ -1169,36 +1169,23 @@
};
gpu: gpu@fde60000 {
- compatible = "arm,mali-bifrost";
- reg = <0x0 0xfde60000 0x0 0x4000>;
+ compatible = "rockchip, rk3568-mali", "arm,mali-bifrost";
+ reg = <0x0 0xfde60000 0x0 0x20000>;
- interrupts = <GIC_SPI 39 IRQ_TYPE_LEVEL_HIGH>,
+ interrupts = <GIC_SPI 40 IRQ_TYPE_LEVEL_HIGH>,
<GIC_SPI 41 IRQ_TYPE_LEVEL_HIGH>,
- <GIC_SPI 40 IRQ_TYPE_LEVEL_HIGH>;
- interrupt-names = "GPU", "MMU", "JOB";
-
- upthreshold = <40>;
- downdifferential = <10>;
-
+ <GIC_SPI 39 IRQ_TYPE_LEVEL_HIGH>;
+ interrupt-names = "job", "mmu", "gpu";
clocks = <&scmi_clk 1>, <&cru CLK_GPU>;
- clock-names = "clk_mali", "clk_gpu";
- power-domains = <&power RK3568_PD_GPU>;
- #cooling-cells = <2>;
+ clock-names = "core", "bus";
operating-points-v2 = <&gpu_opp_table>;
+ #cooling-cells = <2>;
+ power-domains = <&power RK3568_PD_GPU>;
status = "disabled";
- gpu_power_model: power-model {
- compatible = "simple-power-model";
- leakage-range= <5 15>;
- ls = <(-24002) 22823 0>;
- static-coefficient = <100000>;
- dynamic-coefficient = <953>;
- ts = <(-108890) 63610 (-1355) 20>;
- thermal-zone = "gpu-thermal";
- };
};
- gpu_opp_table: opp-table2 {
+ gpu_opp_table: gpu-opp-table {
compatible = "operating-points-v2";
mbist-vmin = <825000 900000 950000>;
@@ -1227,7 +1214,7 @@
};
opp-800000000 {
opp-hz = /bits/ 64 <800000000>;
- opp-microvolt = <950000>;
+ opp-microvolt = <1000000>;
};
};
并拷贝到device/hihope/rk3568/目录下:
cp out/kernel/src_tmp/linux-5.10/arch/arm64/boot/dts/rockchip/rk3568.dtsi device/hihope/rk3568/rk3568.dtsi
2)修改device/hihope/rk3568/kernel/build_kernel.sh
--- build_kernel-bak.sh 2022-04-18 15:53:50.467219678 +0800
+++ build_kernel.sh 2022-04-18 15:56:05.243998200 +0800
@@ -43,6 +43,8 @@
#config
cp -rf ${KERNEL_CONFIG_FILE} ${KERNEL_SRC_TMP_PATH}/arch/arm64/configs/rockchip_linux_defconfig
+cp -rf ${3}/rk3568.dtsi ${KERNEL_SRC_TMP_PATH}/arch/arm64/boot/dts/rockchip/
+
#
if [ "enable_ramdisk" == "${6}" ]; then
./make-ohos.sh TB-RK3568X0 enable_ramdisk
3)修改内核config
修改kernel/linux/config/linux-5.10/arch/arm64/configs/rk3568_standard_defconfig
diff --git a/linux-5.10/arch/arm64/configs/rk3568_standard_defconfig b/linux-5.10/arch/arm64/configs/rk3568_standard_defconfig index ac005b8..55475c5 100644
--- a/linux-5.10/arch/arm64/configs/rk3568_standard_defconfig
+++ b/linux-5.10/arch/arm64/configs/rk3568_standard_defconfig
@@ -3579,7 +3579,7 @@ CONFIG_DVB_SP2=m
#
# CONFIG_VGA_ARB is not set
CONFIG_DRM=y
-CONFIG_DRM_IGNORE_IOTCL_PERMIT=y
+# CONFIG_DRM_IGNORE_IOTCL_PERMIT is not set
CONFIG_DRM_MIPI_DSI=y
# CONFIG_DRM_DP_AUX_CHARDEV is not set
# CONFIG_DRM_DEBUG_MM is not set
@@ -3593,6 +3593,8 @@ CONFIG_DRM_FBDEV_OVERALLOC=100
CONFIG_DRM_LOAD_EDID_FIRMWARE=y
# CONFIG_DRM_DP_CEC is not set
CONFIG_DRM_GEM_CMA_HELPER=y
+CONFIG_DRM_GEM_SHMEM_HELPER=y
+CONFIG_DRM_SCHED=y
#
# I2C encoder or helper chips
@@ -3750,7 +3752,7 @@ CONFIG_DRM_DW_MIPI_DSI=y
# CONFIG_TINYDRM_ST7735R is not set
# CONFIG_DRM_PL111 is not set
# CONFIG_DRM_LIMA is not set
-# CONFIG_DRM_PANFROST is not set
+CONFIG_DRM_PANFROST=y
# CONFIG_DRM_TIDSS is not set
# CONFIG_DRM_LEGACY is not set
CONFIG_DRM_PANEL_ORIENTATION_QUIRKS=y
4、修改openharmony代码
1)修改base/startup/init_lite/ueventd/etc/ueventd.config
增加card1和rendD129的权限,在该文件中加上:
/dev/dri/card1 0666 0 1003
/dev/dri/renderD129 0666 0 1003
2)修改device/hihope/hardware/display/src/display_gralloc/display_gralloc_gbm.c
diff --git a/hardware/display/src/display_gralloc/display_gralloc_gbm.c b/hardware/display/src/display_gralloc/display_gralloc_gbm.c index 2dad8c1..1445819 100644
--- a/hardware/display/src/display_gralloc/display_gralloc_gbm.c
+++ b/hardware/display/src/display_gralloc/display_gralloc_gbm.c
@@ -34,7 +34,7 @@
#include "display_gralloc_private.h"
#include "display_common.h"
-const char *g_drmFileNode = "/dev/dri/renderD128";
+const char *g_drmFileNode = "/dev/dri/card0";
static GrallocManager *g_grallocManager = NULL;
static pthread_mutex_t g_lock;
3)修改foundation/ace/ace_engine/adapter/ohos/build/product_config.gni
diff --git a/adapter/ohos/build/product_config.gni b/adapter/ohos/build/product_config.gni index 3d29a14c..c5d095aa 100644
--- a/adapter/ohos/build/product_config.gni
+++ b/adapter/ohos/build/product_config.gni
@@ -14,3 +14,5 @@
enable_accessibility_product_list = [ "rk3568" ]
enable_web_product_list = [ "rk3568", "m40" ]
+
+gpu_block_product_list = [ "rk3568" ]
4)修改 foundation/graphic/standard/graphic_config.gni
diff --git a/graphic_config.gni b/graphic_config.gni
index 1e4f66c..178bfe3 100644
--- a/graphic_config.gni
+++ b/graphic_config.gni
@@ -20,7 +20,8 @@ if ("${product_name}" == "watchos" || "${product_name}" == "Hi3516DV300" ||
} else if ("${product_name}" == "rk3566" || "${product_name}" == "rk3568") {
gpu_defines = [ "ACE_ENABLE_GL" ]
ace_enable_gpu = true
- libgl = [ "//device/hihope/hardware/gpu:mali-bifrost-g52-g2p0-ohos" ]
+ #libgl = [ "//device/hihope/hardware/gpu:mali-bifrost-g52-g2p0-ohos" ]
+ libgl = [ "//device/hihope/hardware/gpu:mesa-gpu-libs" ]
} else {
gpu_defines = [ "ACE_ENABLE_GL" ]
ace_enable_gpu = true
5)修改 foundation/graphic/standard/BUILD.gn
diff --git a/BUILD.gn b/BUILD.gn
index 1af1af9..36c22ac 100755
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -69,7 +69,7 @@ wmlayout_scss("default.scss") {
group("libsurface") {
public_deps = [ "frameworks/surface:surface" ]
if (ace_enable_gpu) {
- public_deps += [ "frameworks/surfaceimage:libsurfaceimage" ]
+ #public_deps += [ "frameworks/surfaceimage:libsurfaceimage" ]
}
}
6)修改device/hihope/hardware/gpu/BUILD.gn
diff --git a/hardware/gpu/BUILD.gn b/hardware/gpu/BUILD.gn
index 7ffc13d..6a5aa20 100755
--- a/hardware/gpu/BUILD.gn
+++ b/hardware/gpu/BUILD.gn
@@ -14,33 +14,84 @@
import("//build/ohos.gni")
import("//build/ohos/ndk/ndk.gni")
-config("libmali-bifrost-g52-g2p0-ohos") {
- include_dirs = [ "include" ]
- cflags = [
- "-Wno-incompatible-pointer-types",
- "-Werror",
- "-Wimplicit-function-declaration",
- "-Wno-error=unused-variable",
- ]
- cflags = []
-}
-ohos_prebuilt_shared_library("mali-bifrost-g52-g2p0-ohos") {
- if (target_cpu == "arm") {
- source = "lib/libmali-bifrost-g52-g2p0-ohos.so"
- } else if (target_cpu == "arm64") {
- source = "lib64/libmali-bifrost-g52-g2p0-wayland.so"
- }
- install_images = [ system_base_dir ]
+ohos_prebuilt_shared_library("mesa_gbm") {
+ source = "libgbm.so.1.0.0"
+ install_enable = true
subsystem_name = "hdf"
part_name = "display_device_driver"
+ symlink_target_name = [
+ "libgbm.so.1",
+ "libgbm.so",
+ ]
+}
+ohos_prebuilt_shared_library("mesa_egl") {
+ source = "libEGL.so.1.0.0"
install_enable = true
+ subsystem_name = "hdf"
+ part_name = "display_device_driver"
symlink_target_name = [
+ "libEGL.so.1",
"libEGL.so",
- "libGLESv1.so",
+ ]
+}
+ohos_prebuilt_shared_library("mesa_glapi") {
+ source = "libglapi.so.0.0.0"
+ install_enable = true
+ subsystem_name = "hdf"
+ part_name = "display_device_driver"
+ symlink_target_name = [
+ "libglapi.so.0",
+ "libglapi.so",
+ ]
+}
+ohos_prebuilt_shared_library("mesa_glesv1") {
+ source = "libGLESv1_CM.so.1.1.0"
+ install_enable = true
+ subsystem_name = "hdf"
+ part_name = "display_device_driver"
+ symlink_target_name = [
+ "libGLESv1_CM.so.1",
+ "libGLESv1_CM.so",
+ ]
+}
+ohos_prebuilt_shared_library("mesa_glesv2") {
+ source = "libGLESv2.so.2.0.0"
+ install_enable = true
+ subsystem_name = "hdf"
+ part_name = "display_device_driver"
+ symlink_target_name = [
+ "libGLESv2.so.2",
"libGLESv2.so",
- "libGLESv3.so",
- "libmali.so.0",
- "libmali.so.1",
+ ]
+}
+ohos_prebuilt_shared_library("libgallium_dri") {
+ source = "libgallium_dri.so"
+ install_images = [ chipset_base_dir ]
+ install_enable = true
+ subsystem_name = "hdf"
+ part_name = "display_device_driver"
+ symlink_target_name = [
+ "libgallium_dri.so",
+ #"rockchip_dri.so",
+ ]
+}
+ohos_prebuilt_shared_library("panfrost_dri") {
+ source = "panfrost_dri.so"
+ install_enable = true
+ subsystem_name = "hdf"
+ part_name = "display_device_driver"
+ symlink_target_name = [
+ "rockchip_dri.so",
+ ]
+}
+group("mesa-gpu-libs") {
+ public_deps = [
+ ":mesa_gbm",
+ ":mesa_egl",
+ ":mesa_glapi",
+ ":mesa_glesv1",
+ ":mesa_glesv2",
+ ":panfrost_dri",
]
}
7)修改device/hihope/rk3568/BUILD.gn
diff --git a/rk3568/BUILD.gn b/rk3568/BUILD.gn
index f7a3770..00f760d 100755
--- a/rk3568/BUILD.gn
+++ b/rk3568/BUILD.gn
@@ -20,6 +20,7 @@ group("rk3568_group") {
"build/rootfs:init_configs",
"distributedhardware:distributedhardware",
"kernel:kernel",
- "system_hap:hap"
+ "system_hap:hap",
+ "//device/hihope/hardware/gpu:libgallium_dri"
]
}
5、编译
./build.sh --ccache --product-name rk3568
6、刷机
刷机后,render_service正常起来了,图形也正常启动,panfrost驱动也正常,点击界面,流畅不卡顿。
7、问题
1)编译mesa库的时候报错ld.lld: error: unable to find library -lexpat
解决办法:
该问题是缺少依赖expat,需要编译expat
./build.sh --ccache --product-name rk3568 --build-target expat
2)编译mesa库的时候报错如下:
解决办法:
该问题是meson版本过低导致,升级该版本解决问题
python3 -m pip install meson==0.62.0
3)编译mesa库的时候报错如下:
解决办法:
该问题是缺少mako依赖,安装该包即可,具体如下:
python -m pip install --upgrade pip
pip install markupsafe
pip install mako
4)编译问题
移植完mesa驱动后,编译报错如下:
解决办法:
该问题原因主要是mesa3d库的软连接导致的,需要修改gn让软连接实体so,并且添加上so的软连接,具体参考第4节中6)修改device/hihope/hardware/gpu/BUILD.gn。
5)刷机后,能进系统,但是图形起不来
解决办法:
ps命令查看发现render_service 服务没有起来,判断是该服务导致的,
该问题是mesa3d库有问题,可能是使用的mesa3d库是ohos/build_wayland_and_gbm.py编译出来的,即使用老框架支持的,在新框架中需要使用ohos/build_ohos.py编译的mesa3d库,具体编译方法请参考第2节编译mesa 3D库。
6)安装atomic报错
pip install atomic,安装错误提示如下:
Collecting atomic [621/1941]
Using cached atomic-0.7.3.tar.gz (8.4 kB)
Preparing metadata (setup.py) ... error
error: subprocess-exited-with-error
× python setup.py egg_info did not run successfully.
│ exit code: 1
╰─> [60 lines of output]
atomic/__pycache__/_cffi__xc2089624xf914a2ce.c:2:10: fatal error: Python.h: No such file or directory
#include <Python.h>
^~~~~~~~~~
compilation terminated.
Traceback (most recent call last):
File "/usr/lib/python3.8/distutils/unixccompiler.py", line 117, in _compile
self.spawn(compiler_so + cc_args + [src, '-o', obj] +
File "/usr/lib/python3.8/distutils/ccompiler.py", line 910, in spawn
spawn(cmd, dry_run=self.dry_run)
File "/usr/lib/python3.8/distutils/spawn.py", line 36, in spawn
_spawn_posix(cmd, search_path, dry_run=dry_run)
File "/usr/lib/python3.8/distutils/spawn.py", line 157, in _spawn_posix
raise DistutilsExecError(
distutils.errors.DistutilsExecError: command 'x86_64-linux-gnu-gcc' failed with exit status 1
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.8/dist-packages/cffi/ffiplatform.py", line 51, in _build
dist.run_command('build_ext')
File "/usr/lib/python3.8/distutils/dist.py", line 985, in run_command
cmd_obj.run()
File "/usr/lib/python3/dist-packages/setuptools/command/build_ext.py", line 78, in run
_build_ext.run(self)
File "/usr/lib/python3.8/distutils/command/build_ext.py", line 340, in run
self.build_extensions()
File "/usr/lib/python3.8/distutils/command/build_ext.py", line 449, in build_extensions
self._build_extensions_serial()
File "/usr/lib/python3.8/distutils/command/build_ext.py", line 474, in _build_extensions_serial
self.build_extension(ext)
File "/usr/lib/python3/dist-packages/setuptools/command/build_ext.py", line 199, in build_extension [583/1941]
_build_ext.build_extension(self, ext)
File "/usr/lib/python3.8/distutils/command/build_ext.py", line 528, in build_extension
objects = self.compiler.compile(sources,
File "/usr/lib/python3.8/distutils/ccompiler.py", line 574, in compile
self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)
File "/usr/lib/python3.8/distutils/unixccompiler.py", line 120, in _compile
raise CompileError(msg)
distutils.errors.CompileError: command 'x86_64-linux-gnu-gcc' failed with exit status 1
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<string>", line 2, in <module>
File "<pip-setuptools-caller>", line 34, in <module>
File "/tmp/pip-install-nffwsacn/atomic_dc63398485d0425992e6b34600ec1e74/setup.py", line 9, in <module>
from atomic import ffi
File "/tmp/pip-install-nffwsacn/atomic_dc63398485d0425992e6b34600ec1e74/atomic/__init__.py", line 16, in <module>
atomic = ffi.verify("""
File "/usr/local/lib/python3.8/dist-packages/cffi/api.py", line 468, in verify
lib = self.verifier.load_library()
File "/usr/local/lib/python3.8/dist-packages/cffi/verifier.py", line 105, in load_library
self._compile_module()
File "/usr/local/lib/python3.8/dist-packages/cffi/verifier.py", line 202, in _compile_module
outputfilename = ffiplatform.compile(tmpdir, self.get_extension())
File "/usr/local/lib/python3.8/dist-packages/cffi/ffiplatform.py", line 22, in compile
outputfilename = _build(tmpdir, ext, compiler_verbose, debug)
File "/usr/local/lib/python3.8/dist-packages/cffi/ffiplatform.py", line 58, in _build
raise VerificationError('%s: %s' % (e.__class__.__name__, e))
cffi.VerificationError: CompileError: command 'x86_64-linux-gnu-gcc' failed with exit status 1
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed
× Encountered error while generating package metadata.
╰─> See above for output.
note: This is an issue with the package mentioned above, not pip.
hint: See above for details.
解决办法:
修改~/.bashrc文件,添加如下配置:
export C_INCLUDE_PATH=/usr/include/python3.6:$C_INCLUDE_PATH
export LUS_INCLUDE_PATH=/usr/include/python3.6:$CPLUS_INCLUDE_PATH
然后再执行如下命令:
source ~/.bashrc
最后重新安装atomic,安装成功。
文章转载自作者:易阳天