作者:付汉杰,<a href="mailto:hankf@xilinx.com">hankf@xilinx.com</a>,文章转载自:<a id="link_3" href="https://forums.xilinx.com/t5/%E5%B5%8C%E5%85%A5%E5%BC%8F-%E5%B7%A5%E5%8…;
<strong>1. Xilinx backend</strong>
Xilinx为MPSoC支持4种libMali的backend: X11, Wayland/GBM, Fbdev, Headless-EGL。
<strong> 2. QT</strong>
QT支持4种plugin(插件)或者backend,FB,X11,Wayland,eglfs。对不同的plugin(插件)或者backend,QT应用层是一样的。
其中的FB,不能利用GPU做渲染。
EGLFS可以让QT应用直接运行在EGL和OpenGL ES 2.0上。也就是,可以在没有窗口管理器(windowing system like X11 or Wayland)的情况下,运行QT软件。对于有GPU的嵌入式Linux系统,建议使用eglfs。
当使用KMS/DRM时,EGLFS的Backend是eglfs_kms。
更多信息,可以参考QT文档,https://doc.qt.io/qt-5/embedded-linux.html
<strong>3. Xilinx支持情况</strong>
Xilinx支持eglfs_kms。
本文的命令可以在Xilinx的ZCU102和ZCU106单板上运行。所有测试基于ZCU102和ZCU106的PetaLinux BSP的工程。
<strong>3.1. rootfs</strong>
在Linux的rootfs里,增加qt相关的软件。使用命令petalinux-config -c rootfs配置Linux的rootfs,使能packagegroup-petalinux-qt。
<strong>3.2. libMali</strong>
使用eglfs_kms时,libMali.so.9.0使用对应的wayland版本,指向到/usr/lib/wayland/libMali.so.9.0。
在文件project-spec/meta-user/conf/petalinuxbsp.conf里,增加下列行,可以使libMali.so.9.0指向到/usr/lib/wayland/libMali.so.9.0。
<pre>MALI_BACKEND_DEFAULT = "wayland" </pre>
也可以在Linux运行的时侯,执行下列命令,使libMali.so.9.0指向到/usr/lib/wayland/libMali.so.9.0。
<pre>update-alternatives --install /usr/lib/libMali.so.9.0 libmali /usr/lib/wayland/libMali.so.9.0 90</pre>
<strong>3.3. QT环境设置</strong>
为了让QT使用eglfs_kms,需要设置下列两个环境变量。
<pre>export QT_QPA_PLATFORM=eglfs
export QT_QPA_EGLFS_INTEGRATION=eglfs_kms</pre>
QT还可以通过JSON文件设置有更多参数可以设置。通过导出 系统变量QT_QPA_EGLFS_KMS_CONFIG,可以指定JSON文件名,比如
<pre>export QT_QPA_EGLFS_KMS_CONFIG="/home/root/kms.conf"</pre>
kms.conf的内容如下:
<pre>{
"device": "/dev/dri/card0",
"hwcursor": false,
"pbuffers": true,
"outputs": [
{
"name": "DP",
"mode": "3840x2160"
}
]
}</pre>
<strong>3.4. 检测显示器</strong>
通过下列命令检查显示器,并设置它的分辨率。
<pre>ls /dev/dri/by-path/
modetest -D fd4a0000.zynqmp-display
modetest -D fd4a0000.zynqmp-display -s 43:1920x1080-60@BG24
modetest -D fd4a0000.zynqmp-display -s 43:3840x2160-29.98@BG24</pre>
<strong>3.5. QT测试程序</strong>
<strong>3.5.1. 默认测试程序</strong>
PetaLinux编译出的文件系统,在目录/usr/share/examples/opengl下,有很多opengl的测试程序,比如cube和textures。
<pre>/usr/share/examples/opengl/cube/cube
/usr/share/examples/opengl/textures/textures</pre>
<strong>3.5.2. qt5everywheredemo</strong>
更复杂的opengl的测试程序,QtDemo可以通过qt5everywheredemo编译。
下面的命令,直接编译qt5everywheredemo。
<pre>petalinux-build -c qt5everywheredemo -x compile</pre>
在文件petalinuxbsp.conf里添加下列行后,PetaLinux编译时会包含qt5everywheredemo。
<pre>MALI_BACKEND_DEFAULT = "wayland"
IMAGE_INSTALL_append = " qt5everywheredemo" </pre>
之后在目录/usr/share/qt5everywheredemo-1.0/里能找到
<pre>root@xilinx-zcu106-2020_2# find -name "QtDemo"
./usr/share/qt5everywheredemo-1.0/qml/QtDemo
./usr/share/qt5everywheredemo-1.0/QtDemo</pre>
<strong>4. 参考文章</strong>
<a href="https://xilinx-wiki.atlassian.net/wiki/spaces/A/pages/18841928/Xilinx+A…; target="_blank" rel="noopener nofollow noopener noreferrer">Xilinx Arm Mali-400 Driver</a>
</body>
<strong>5. 常见错误</strong>
<strong>5.1. 没接DP显示器</strong>
如果没接DP显示器,会报告错误,“Cannot create window: no screens available”。
<pre>Cannot create window: no screens available</pre>
<strong>6. 更多记录</strong>
<strong>6.1. ZCU106 BSP 2020.2 Log</strong>
下面log中的“^C”,表示图像软件正常运行,用户使用Ctrl+C, 也就是“^C”,终止了图像软件。
<pre>xilinx-zcu106-2020_2 login: root
Password:
root@xilinx-zcu106-2020_2:~# uname -a
Linux xilinx-zcu106-2020_2 5.4.0-xilinx-v2020.2 #1 SMP Wed Dec 2 07:02:26 UTC 2020 aarch64 GNU/Linux
root@xilinx-zcu106-2020_2:~# ps -A | grep -i xorg
989 root 0:00 xinit /etc/X11/Xsession -- /usr/bin/Xorg :0 -br -pn
994 root 0:00 /usr/bin/Xorg :0 -br -pn
1202 root 0:00 grep -i xorg
root@xilinx-zcu106-2020_2:~# kill 994
root@xilinx-zcu106-2020_2:~# XIO: fatal IO error 11 (Resource temporarily unavailable) on X server ":0"
after 308 requests (308 known processed) with 0 events remaining.
Gdk-Message: 02:39:54.875: matchbox-panel: Fatal IO error 11 (Resource temporarily unavailable) on X server :0.
Gdk-Message: 02:39:54.877: settings-daemon: Fatal IO error 11 (Resource temporarily unavailable) on X server :0.
Gdk-Message: 02:39:54.880: matchbox-desktop: Fatal IO error 11 (Resource temporarily unavailable) on X server :0.
xinit: connection to X server lost
waiting for X server to shut down (II) Server terminated successfully (0). Closing log file.
root@xilinx-zcu106-2020_2:~# export QT_QPA_PLATFORM="eglfs"
root@xilinx-zcu106-2020_2:~# export QT_QPA_EGLFS_INTEGRATION="eglfs_kms"
root@xilinx-zcu106-2020_2:~# ls -l /usr/lib/libMali.so.9.0
lrwxrwxrwx 1 root root 31 Dec 11 02:36 /usr/lib/libMali.so.9.0 -> /usr/lib/wayland/libMali.so.9.0
root@xilinx-zcu106-2020_2:~# cd /usr/share/examples/opengl/textures
root@xilinx-zcu106-2020_2:/usr/share/examples/opengl/textures# ls /dev/dri/by-path/
platform-fd4a0000.zynqmp-display-card
root@xilinx-zcu106-2020_2:/usr/share/examples/opengl/textures# modetest -D fd4a0000.zynqmp-display
trying to open device 'i915'...done
Encoders:
id crtc type possible crtcs possible clones
42 41 TMDS 0x00000001 0x00000000
Connectors:
id encoder status name size (mm) modes encoders
43 42 connected DP-1 610x350 34 42
modes:
name refresh (Hz) hdisp hss hse htot vdisp vss vse vtot)
3840x2160 29.98 3840 3888 3920 4000 2160 2163 2168 2191 262750 flags: phsync, nvsync; type: driver
1920x1200 59.88 1920 2056 2256 2592 1200 1203 1209 1245 193250 flags: nhsync, pvsync; type: driver
800x600 60.32 800 840 968 1056 600 601 605 628 40000 flags: phsync, pvsync; type: driver
720x480 60.00 720 736 798 858 480 489 495 525 27027 flags: nhsync, nvsync; type: driver
720x480 59.94 720 736 798 858 480 489 495 525 27000 flags: nhsync, nvsync; type: driver
640x480 75.00 640 656 720 840 480 481 484 500 31500 flags: nhsync, nvsync; type: driver
props:
1 EDID:
flags: immutable blob
blobs:
value:
00ffffffffffff0010ac2aa14c543830
171d0104b53d23783eee95a3544c9926
0f5054a54b00714f8180a9c0a940d1c0
e100d10001014dd000a0f0703e803020
3500615d2100001a000000ff004d5950
464b3936323038544c0a000000fc0044
454c4c205532373138514d0a000000fd
0031560a8936000a202020202020013d
02031df150101f200514041312110302
161507060123091f0783010000565e00
a0a0a0295030203500615d2100001aa3
6600a0f0701f8030203500615d210000
1a4dd000a0f0703e8030203500615d21
00001a023a801871382d40582c250061
5d2100001ebf1600a08038134030203a
00615d2100001a00000000000000004a
2 DPMS:
flags: enum
enums: On=0 Standby=1 Suspend=2 Off=3
value: 0
5 link-status:
flags: enum
enums: Good=0 Bad=1
value: 0
6 non-desktop:
flags: immutable range
values: 0 1
value: 0
4 TILE:
flags: immutable blob
blobs:
value:
21 CRTC_ID:
flags: object
value: 41
44 sync:
flags: range
values: 0 1
value: 0
45 bpc:
flags: enum
enums: 6BPC=6 8BPC=8 10BPC=10 12BPC=12
value: 8
CRTCs:
id fb pos size
41 46 (0,0) (3840x2160)
3840x2160 29.98 3840 3888 3920 4000 2160 2163 2168 2191 262750 flags: phsync, nvsync; type: driver
props:
23 ACTIVE:
flags: range
values: 0 1
value: 1
24 MODE_ID:
flags: blob
blobs:
value:
5e020400000f300f500fa00f00007008
730878088f0800001e00000009000000
40000000333834307832313630000000
00000000000000000000000000000000
00000000
20 OUT_FENCE_PTR:
flags: range
values: 0 18446744073709551615
value: 0
25 VRR_ENABLED:
flags: range
values: 0 1
value: 0
34 output_color:
flags: enum
enums: rgb=0 ycrcb444=1 ycrcb422=2 yonly=3
value: 0
35 bg_c0:
flags: range
values: 0 4095
value: 0
36 bg_c1:
flags: range
values: 0 4095
value: 0
37 bg_c2:
flags: range
values: 0 4095
value: 0
Planes:
id crtc fb CRTC x,y x,y gamma size possible crtcs
39 0 0 0,0 0,0 0 0x00000001
formats: VYUY UYVY YUYV YVYU YU16 YV16 YU24 YV24 NV16 NV61 GREY Y10 BG24 RG24 XB24 XR24 XB30 XR30 YU12 YV12 NV12 NV21 XV15 XV20
props:
9 type:
flags: immutable enum
enums: Overlay=0 Primary=1 Cursor=2
value: 0
18 FB_ID:
flags: object
value: 0
19 IN_FENCE_FD:
flags: signed range
values: -1 2147483647
value: -1
21 CRTC_ID:
flags: object
value: 0
14 CRTC_X:
flags: signed range
values: -2147483648 2147483647
value: 0
15 CRTC_Y:
flags: signed range
values: -2147483648 2147483647
value: 0
16 CRTC_W:
flags: range
values: 0 2147483647
value: 0
17 CRTC_H:
flags: range
values: 0 2147483647
value: 0
10 SRC_X:
flags: range
values: 0 4294967295
value: 0
11 SRC_Y:
flags: range
values: 0 4294967295
value: 0
12 SRC_W:
flags: range
values: 0 4294967295
value: 0
13 SRC_H:
flags: range
values: 0 4294967295
value: 0
38 tpg:
flags: range
values: 0 1
value: 0
40 41 46 0,0 0,0 0 0x00000001
formats: AB24 AR24 RA24 BA24 BG24 RG24 RA15 BA15 RA12 BA12 RG16 BG16
props:
9 type:
flags: immutable enum
enums: Overlay=0 Primary=1 Cursor=2
value: 1
18 FB_ID:
flags: object
value: 46
19 IN_FENCE_FD:
flags: signed range
values: -1 2147483647
value: -1
21 CRTC_ID:
flags: object
value: 41
14 CRTC_X:
flags: signed range
values: -2147483648 2147483647
value: 0
15 CRTC_Y:
flags: signed range
values: -2147483648 2147483647
value: 0
16 CRTC_W:
flags: range
values: 0 2147483647
value: 3840
17 CRTC_H:
flags: range
values: 0 2147483647
value: 2160
10 SRC_X:
flags: range
values: 0 4294967295
value: 0
11 SRC_Y:
flags: range
values: 0 4294967295
value: 0
12 SRC_W:
flags: range
values: 0 4294967295
value: 251658240
13 SRC_H:
flags: range
values: 0 4294967295
value: 141557760
32 alpha:
flags: range
values: 0 255
value: 255
33 g_alpha_en:
flags: range
values: 0 1
value: 1
Frame buffers:
id size pitch
root@xilinx-zcu106-2020_2:/usr/share/examples/opengl/textures# modetest -D fd4a0000.zynqmp-display -s 43:1920x1080-60@BG24
trying to open device 'i915'...done
setting mode 1920x1080-60.00Hz@BG24 on connectors 43, crtc 41
root@xilinx-zcu106-2020_2:/usr/share/examples/opengl/textures# ./textures
QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/var/volatile/tmp/runtime-root'
Setting framebuffer size is only available with DRM atomic API
Attribute Qt::AA_ShareOpenGLContexts must be set before QCoreApplication is created.
^C
root@xilinx-zcu106-2020_2:/usr/share/examples/opengl/textures# modetest -D fd4a0000.zynqmp-display -s 43:3840x2160-29.98@BG24
trying to open device 'i915'...done
setting mode 3840x2160-29.98Hz@BG24 on connectors 43, crtc 41
root@xilinx-zcu106-2020_2:/usr/share/examples/opengl/textures# ./textures
QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/var/volatile/tmp/runtime-root'
Setting framebuffer size is only available with DRM atomic API
Attribute Qt::AA_ShareOpenGLContexts must be set before QCoreApplication is created.
^C
root@xilinx-zcu106-2020_2:/usr/share/examples/opengl/textures# modetest -D fd4a0000.zynqmp-display -s 43:1280x1024-60.02@BG24
trying to open device 'i915'...done
setting mode 1280x1024-60.02Hz@BG24 on connectors 43, crtc 41
root@xilinx-zcu106-2020_2:/usr/share/examples/opengl/textures# ./textures
QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/var/volatile/tmp/runtime-root'
Setting framebuffer size is only available with DRM atomic API
Attribute Qt::AA_ShareOpenGLContexts must be set before QCoreApplication is created.
^C
root@xilinx-zcu106-2020_2:/usr/share/examples/opengl/textures# modetest -D fd4a0000.zynqmp-display -s 43:1280x720-60@BG24
trying to open device 'i915'...done
setting mode 1280x720-60.00Hz@BG24 on connectors 43, crtc 41
root@xilinx-zcu106-2020_2:/usr/share/examples/opengl/textures# ./textures
QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/var/volatile/tmp/runtime-root'
Setting framebuffer size is only available with DRM atomic API
Attribute Qt::AA_ShareOpenGLContexts must be set before QCoreApplication is created.
^C
root@xilinx-zcu106-2020_2:/usr/share/examples/opengl/textures# modetest -D fd4a0000.zynqmp-display -s 43:800x600-60.32@BG24
trying to open device 'i915'...done
setting mode 800x600-60.32Hz@BG24 on connectors 43, crtc 41
root@xilinx-zcu106-2020_2:/usr/share/examples/opengl/textures# ./textures
QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/var/volatile/tmp/runtime-root'
Setting framebuffer size is only available with DRM atomic API
Attribute Qt::AA_ShareOpenGLContexts must be set before QCoreApplication is created.
^C
root@xilinx-zcu106-2020_2:/usr/share/examples/opengl/textures# modetest -D fd4a0000.zynqmp-display -s 43:640x480-59.94@BG24
trying to open device 'i915'...done
setting mode 640x480-59.94Hz@BG24 on connectors 43, crtc 41
root@xilinx-zcu106-2020_2:/usr/share/examples/opengl/textures# ./textures
QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/var/volatile/tmp/runtime-root'
Setting framebuffer size is only available with DRM atomic API
Attribute Qt::AA_ShareOpenGLContexts must be set before QCoreApplication is created.
^C
root@xilinx-zcu106-2020_2:/usr/share/examples/opengl/textures# uname -a
Linux xilinx-zcu106-2020_2 5.4.0-xilinx-v2020.2 #1 SMP Wed Dec 2 07:02:26 UTC 2020 aarch64 GNU/Linux
root@xilinx-zcu106-2020_2:/# cd ~
root@xilinx-zcu106-2020_2:~# export QT_QPA_PLATFORM="eglfs"
root@xilinx-zcu106-2020_2:~# export QT_QPA_EGLFS_KMS_ATOMIC=1
root@xilinx-zcu106-2020_2:~# export QT_QPA_EGLFS_INTEGRATION="eglfs_kms"
root@xilinx-zcu106-2020_2:~# export QT_QPA_EGLFS_KMS_CONFIG="/home/root/kms.conf"
root@xilinx-zcu106-2020_2:~# export QT_QPA_EGLFS_DEBUG="1"
root@xilinx-zcu106-2020_2:~# export QT_QPA_EGLFS_FORCE888=1
root@xilinx-zcu106-2020_2:/# cd /usr/share/qt5everywheredemo-1.0/
root@xilinx-zcu106-2020_2:/usr/share/qt5everywheredemo-1.0# ./QtDemo
QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/var/volatile/tmp/runtime-root'
qt.qpa.eglfs.kms: Could not open config file "/home/root/kms.conf" for reading
Framebuffer size format is invalid.
Created context for format QSurfaceFormat(version 2.0, options QFlags<QSurfaceFormat::FormatOption>(), depthBufferSize 24, redBufferSize 8, greenBufferSize 8, blueBufferSize 8, alphaBufferSize -1, stencilBufferSize 8, samples -1, swapBehavior QSurfaceFormat::DoubleBuffer, swapInterval 1, colorSpace QSurfaceFormat::DefaultColorSpace, profile QSurfaceFormat::NoProfile) with config:
EGL_BUFFER_SIZE: 32
EGL_ALPHA_SIZE: 8
EGL_BLUE_SIZE: 8
EGL_GREEN_SIZE: 8
EGL_RED_SIZE: 8
EGL_DEPTH_SIZE: 24
EGL_STENCIL_SIZE: 8
EGL_CONFIG_CAVEAT: 12344
EGL_CONFIG_ID: 9
EGL_LEVEL: 0
EGL_MAX_PBUFFER_HEIGHT: 4096
EGL_MAX_PBUFFER_PIXELS: 16777216
EGL_MAX_PBUFFER_WIDTH: 4096
EGL_NATIVE_RENDERABLE: 1
EGL_NATIVE_VISUAL_ID: 875713089
EGL_NATIVE_VISUAL_TYPE: 0
EGL_SAMPLES: 0
EGL_SAMPLE_BUFFERS: 0
EGL_SURFACE_TYPE: 1031
EGL_TRANSPARENT_TYPE: 12344
EGL_TRANSPARENT_BLUE_VALUE: 0
EGL_TRANSPARENT_GREEN_VALUE: 0
EGL_TRANSPARENT_RED_VALUE: 0
EGL_BIND_TO_TEXTURE_RGB: 1
EGL_BIND_TO_TEXTURE_RGBA: 1
EGL_MIN_SWAP_INTERVAL: 0
EGL_MAX_SWAP_INTERVAL: 10
^C</pre>
<strong>7. 其它</strong>
通过修改DP驱动,可以在没有接DP显示器时,运行的QT程序,并拿到framebuffer,再做其它处理。