Adapting Mesa GPU Driver for OpenHarmony on the Spreadtrum T606 Platform
This article details the process of integrating the open‑source Mesa 3D graphics stack and the Panfrost GPU driver into OpenHarmony 3.2.2 on a Spreadtrum T606 (Mali‑G57) platform, covering hardware setup, compilation options, code modifications, debugging steps, performance analysis, and lessons learned.
Since the release of OpenHarmony, its ecosystem has attracted widespread attention, and Coolpad successfully integrated the OpenHarmony system onto a Spreadtrum T606 platform, marking a significant milestone for the project.
The hardware used in this work includes:
1. Spreadtrum T606 Android 13 (Kernel 5.4)
2. OpenHarmony v3.2.2 ReleaseThe article focuses on adapting the open‑source Mesa GPU solution for the Spreadtrum platform.
Graphics Architecture
The official graphics subsystem architecture is shown in the following diagram:
The adaptation mainly targets the Render Service in the framework layer, whose source resides at //foundation/graphic/graphic_2d/ .
Mesa Adaptation Scheme
Three possible schemes were considered:
Scheme 1: Use the existing version and back‑port Mali‑G57 support upstream.
Scheme 2: Upgrade Mesa to at least version 22.2 and add OpenHarmony support.
Scheme 3: Directly switch to the 4.0 Mesa repository (already upgraded to 22.4 on 2023‑08‑30).
Scheme 2 was initially chosen, but after encountering several issues we finally adopted Scheme 3.
Compiling Mesa
The build host is Ubuntu 18.04 with Meson 0.61.5. The original OpenHarmony build script ohos/BUILD.gn contains a large deps_inputs list (~7000 lines), making manual updates impractical. Instead, the team used build_ohos.py and packaged the resulting libraries with ohos_prebuilt_shared_library into the image.
To place the libraries on the vendor side, the GN command line was adjusted as follows:
run_build_cmd += '-Dplatforms=ohos -Degl-native-platform=ohos -Ddri-drivers= -Dgallium-drivers=panfrost \
-Dvulkan-drivers= -Dgbm=enabled -Degl=enabled -Dgles1=enabled -Dgles2=enabled -Dcpp_rtti=false -Dglx=disabled -Dtools= -Ddri-search-path=/vendor/lib64/chipsetsdk'The install path was also aligned:
install_images = [ chipset_base_dir ]
relative_install_dir = "chipsetsdk"During compilation, several errors appeared, such as missing endian definitions:
#error "UTIL_ARCH_LITTLE_ENDIAN and/or UTIL_ARCH_BIG_ENDIAN were unset."These were fixed by adding the following definitions:
#define UTIL_ARCH_LITTLE_ENDIAN 1
#define UTIL_ARCH_BIG_ENDIAN 0Successful compilation produced the following shared objects:
build‑ohos/install/lib/libEGL.so.1.0.0
build‑ohos/install/lib/libgbm.so.1.0.0
build‑ohos/install/lib/libGLESv2.so.2.0.0
build‑ohos/install/lib/libGLESv1_CM.so.1.1.0
build‑ohos/install/lib/libglapi.so.0.0.0
build‑ohos/src/gallium/targets/dri/libgallium_dri.so
build‑ohos/install/lib/dri/panfrost_dri.soMesa 3D Library
The T606 uses a Mali‑G57 GPU, which is not supported by the original OpenHarmony v3.2.2 Mesa 3D; support was added starting from Mesa 22.2.
GPU Driver
ARM’s proprietary Kbase driver cannot be used on OpenHarmony, so the open‑source Panfrost driver (targeting Midgard and Bifrost architectures) was selected. Panfrost integrates with the Linux DRM framework, providing a native driver experience.
Feature Porting
Because the Spreadtrum kernel 5.4 does not yet support Mali‑G57 in Panfrost, the driver had to be back‑ported. The porting work involved three steps:
Back‑port Valhall (JM) support patches.
Preserve features from other platforms to avoid losing functionality.
Apply Mali‑G57‑specific bug fixes.
Additional customizations were required for the SPRD platform, such as handling custom DTS entries for dynamic frequency scaling, GPU status registers, and clocks.
Key clock definitions extracted from the DTS are:
gpu_dvfs_ctx.clk_gpu_i <&aonapb_gate CLK_GPU_EB>
... (other clock definitions) ...
gpu_dvfs_ctx.freq_list = [384000, 512000, 614400, 650000]After porting the initialization code, the GPU could start, but power and frequency management remained missing, leading to incorrect frequency reads via /sys/class/devfreq .
Debugging and Verification
Before testing Mesa, the three‑party modetest tool was used to verify basic graphics output. The render service had to be stopped first:
service_control stop render_serviceThen modetest was run with the following command:
# Specify mode and plane
modetest -a -M sprd -s 92@83:720x1520 -P 31@83:720x1520Successful output showed a rendered triangle on the screen.
After flashing the adapted Mesa, the system repeatedly rebooted. The kernel log revealed a crash in render_service caused by a critical field configuration:
// graphic.cfg
"services" : [{
"name" : "render_service",
"path" : ["/system/bin/render_service"],
"critical" : [1, 5, 60]
}]Setting the critical field to 0 prevented automatic reboots during debugging.
The crash stack indicated a failure in glGetString() inside opengl_wrapper . Further investigation traced the issue to a subtle platform difference, which was fixed in the driver.
Performance Analysis
OpenHarmony provides the bytrace tool for capturing Ftrace data, similar to Android’s atrace . The following command captures a 20‑second trace for several subsystems:
echo > /sys/kernel/debug/tracing/trace
echo 90096 > /sys/kernel/debug/tracing/saved_cmdlines_size
bytrace -t 20 -b 90096 --overwrite ohos zimage zmedia zcamera zaudio ability distributeddatamgr graphic freq irq mdfs workq mmc idle notification sync pagecache ace app > /data/Launcher.ftrace
echo > /sys/kernel/debug/tracing/traceAnalysis of the trace revealed that during launcher lag the rendering pipeline produced no frames, and the main thread was blocked in a loop inside SetCircularStyle , causing VSync misses.
By adding logs and fixing the offending function, the UI stutter issue was resolved.
Conclusion
The adaptation of Mesa to the Spreadtrum platform involved extensive work on the graphics stack, driver back‑porting, build system adjustments, and deep debugging. Numerous challenges were encountered, ranging from kernel‑level compatibility to runtime crashes. The experience highlights the complexity of graphics integration on embedded mobile systems and provides a valuable reference for future OpenHarmony graphics development.
References
https://gitee.com/openharmony/docs/blob/OpenHarmony-3.2-Release/zh-cn/readme/图形子系统.md#12-标准系统
https://docs.openharmony.cn/pages/v3.2/zh-cn/device-dev/subsystems/subsys-boot-init-service.md/
https://docs.mesa3d.org/index.html
https://ost.51cto.com/posts/21184
https://www.freedesktop.org/wiki/Software/gallium/
https://mp.weixin.qq.com/s/5hr7kMRq0ByGFLGZGXUIIg
Coolpad Technology Team
Committed to advancing technology and supporting innovators. The Coolpad Technology Team regularly shares forward‑looking insights, product updates, and tech news. Tech experts are welcome to join; everyone is invited to follow us.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.