modetest

modetest

modetest 是一个用于显示和测试 Linux 内核模式设置的工具。它通过使用 DRM(Direct Rendering Manager)接口与显示驱动程序进行通信,可以列出可用的显示模式并测试它们的功能。

作者:炭烤毛蛋 ,点击博主了解更多。


提示:modetest 工具可以外部编译或者安装再使用。

文章目录

  • modetest
  • 前期准备
    • .Android
    • .Linux
  • 1. modetest测试显示
  • 1.1 解析组件
    • 1.2 显示模式设置
    • 1.3 设置显示图层
  • Tips
  • 结语


前期准备

.Android

Android 编译 modetest

mmm external/libdrm/tests/modetest/ -j8
......
[100% 464/464] Copy xml: out/target/product/rk3568_s/testcases/modetest/modetest.config

Android 32bit

adb push [PATH]testcases/modetest/arm/modetest /system/bin/

Android 64bit

adb push [PATH] testcases/modetest/arm64/modetest /system/bin/
  • Android 停止 framebuffer
stop

.Linux

在 Linux 上使用 modetest 命令可以方便地测试和显示显示器的模式设置。

sudo apt-get install drm-utils
  • linux 停止 framebuffer
systemctl stop lightdm

注意:先关闭显示 framebuffer,再开启modetest,不然显示只有一帧然后被刷掉。

1. modetest测试显示

  • modetest 详细参数
modetest --help
usage: modetest [-cDdefMPpsCvw]

 Query options:

        -c      list connectors
        -e      list encoders
        -f      list framebuffers
        -p      list CRTCs and planes (pipes)

 Test options:

        -P <plane_id>@<crtc_id>:<w>x<h>[+<x>+<y>][*<scale>][@<format>]  set a plane
        -s <connector_id>[,<connector_id>][@<crtc_id>]:<mode>[-<vrefresh>][@<format>]   set a mode
        -C      test hw cursor
        -v      test vsynced page flipping
        -w <obj_id>:<prop_name>:<value> set property

 Generic options:

        -d      drop master after mode set
        -M module       use the given driver
        -D device       use the given device

        Default is to dump all info.

1.1 解析组件

将数据从帧缓冲区(framebuffer)传输到 DRM(Direct Rendering Manager)是在图形系统中进行显示的常见流程。
modetest_第1张图片
CRTC(Cathode Ray Tube Controller)是驱动显示设备的硬件单元。你需要分配一个 CRTC 来控制显示输出。你可以使用 drmModeSetCrtc() 函数来分配 CRTC,并将帧缓冲缓冲区与 CRTC 关联起来。一旦 CRTC 分配完成,将触发显示控制器将帧缓冲缓冲区的内容发送到显示设备。
找到显示连接的 connector和与encoder匹配CTRC panle,通过直接送显示画面可以判定硬件链路好坏。

  • 查看组件的信息

modetest -M rockchip

-M:用于指定访问 rockchip DRM driver
如果不指定DRM芯片则会逐个遍历

trying to open device 'i915'...failed
trying to open device 'amdgpu'...failed
trying to open device 'radeon'...failed
trying to open device 'nouveau'...failed
trying to open device 'vmwgfx'...failed
trying to open device 'omapdrm'...failed
trying to open device 'exynos'...failed
trying to open device 'tilcdc'...failed
trying to open device 'msm'...failed
trying to open device 'sti'...failed
trying to open device 'tegra'...failed
trying to open device 'imx-drm'...failed
trying to open device 'rockchip'...done
modetest -M rockchip
Encoders:
id      crtc    type    possible crtcs  possible clones
345     0       Virtual 0x00000003      0x00000000
347     71      TMDS    0x00000001      0x00000000

Connectors:
id      encoder status          name            size (mm)       modes   encoders
348     347     connected       HDMI-A-1        530x300         40      347
  modes:
 	name refresh (Hz) hdisp hss hse htot vdisp vss vse vtot)
  1920x1080 60 1920 2008 2052 2200 1080 1084 1089 1125 148500 flags: phsync, pvsync; type: preferred, driver
  1920x1080 75 1920 1968 2000 2080 1080 1083 1088 1119 174500 flags: phsync, nvsync; type: driver
  1920x1080 60 1920 2008 2052 2200 1080 1084 1089 1125 148500 flags: phsync, pvsync; type: driver
  1920x1080 60 1920 2008 2052 2200 1080 1084 1089 1125 148352 flags: phsync, pvsync; type: driver
......
  props:
	1 EDID:
		flags: immutable blob
		blobs:
......
CRTCs:
id	fb	pos	size
71	0	(0,0)	(1920x1080)
  1920x1080 60 1920 2008 2052 2200 1080 1084 1089 1125 148500 flags: phsync, pvsync; type: preferred, driver
  props:
	21 ACTIVE:
		flags: range
		values: 0 1
		value: 1
......
formats: XR24 AR24 XB24 AB24 RG24 BG24 RG16 BG16
  props:
	8 type:
		flags: immutable enum
		enums: Overlay=0 Primary=1 Cursor=2
		value: 1

Encoders / Connectors / CRTCs / Planes 的 id是 modetest 用户索引这些组件标识。
Connectors 的 modes/props:
prop: 任何你想设置的参数,都可以做成 property,是 DRM 驱动中最灵活、最方便的 Mode setting 机制;
modes: 显示模式中包含多组 mode,mode 则是分辨率/刷新率等显示相关的信息;
CRTCs 包含 props;
Planes 包含 formats/props;

1.2 显示模式设置

从modetest 中解析到 HDMI 显示CRTCs链路
connector --> 348

Encoders:
id      crtc    type    possible crtcs  possible clones
345     0       Virtual 0x00000003      0x00000000
347     71      TMDS    0x00000001      0x00000000

encoder -> 347

Connectors:
id      encoder status          name            size (mm)       modes   encoders
348     347     connected       HDMI-A-1        530x300         40      347

crtc -> 71

CRTCs:
id	fb	pos	size
71	0	(0,0)	(1920x1080)
  1920x1080 60 1920 2008 2052 2200 1080 1084 1089 1125 148500 flags: phsync, pvsync; type: preferred, driver
  props:
  • 设置显示分辨率
    设置成功后对应屏幕会有彩色条纹显示
modetest -M rockchip -s 348@71:1920x1080

# buildroot中在weston.ini里面写入 mode=current,重启weston显示在这边指定的connector
modetest -M rockchip -s 348@71:1920x1080 -d

部分设备分辨率设定支持 mode 编号

modetest -M rockchip -s 348@71:#1

1.3 设置显示图层

#理论上背景图+720x480,实际只能看到720x480放大2倍的图 偏移100像素 y偏移100像素
# -P @:x[++][*][@]  set a plane
# -s [,][@]:[-][@] set a mode
modetest -M rockchip -s 348:1920x1080 -P  57@71:720x480+100+100*2@XR24

 
# 理论上背景+720x480的图,偏移100像素 y偏移100像素,实际之恶能看到720x480的图
modetest -M rockchip -s 348:1920x1080 -P 57@71:720x480+100+100*2@BG16 -P 57@71:320x240 

modetest -M rockchip -s 348@71:1920x1080@RG24 -P 57@71:1920x540+0+0 -P 61@71:1080x1080+1080+0 -P 63@71:1280x720+10+10@RG24 -P 36@139:96x96+260+900@RG24

Tips

  1. 测试vsync是否正常
modetest -M rockchip -s 348@71:1920x1080 -v
setting mode 1920x1080-60Hz@XR24 on connectors 348, crtc 71
freq: 60.64Hz
  1. 开启drm日志
# 开启DRM所有日志
echo 0xff > /sys/module/drm/parameters/debug
# 开启DRM driver部分日志
echo 0x02 > /sys/module/drm/parameters/debug
# 关闭DRM日志
echo 0 > /sys/module/drm/parameters/debug
  1. 获取 connector 名字
for drm in /sys/class/drm/*/status; do con=${drm%/status}; echo -n "${con#*/card?-}: "; cat $drm;
HDMI-A-1: connected
Writeback-1: connected
  1. HDMI 状态转换
cat /d/dw-hdmi/status
PHY: enabled                    Mode: HDMI
Pixel Clk: 148500000Hz          TMDS Clk: 148500000Hz
Color Format: RGB               Color Depth: 8 bit
Colorimetry: ITU.BT709          EOTF: Off

# 关闭 HDMI
echo off > /sys/class/drm/card0-HDMI-1/status
# 开启 HDMI
echo on > /sys/class/drm/card0-HDMI-1/status
  1. DSI 状态转换
# 开启 DSI-1
echo on > /sys/class/drm/card0-DSI-1/status
# 关闭 DSI-1
echo off > /sys/class/drm/card0-DSI-1/status
  1. 确认DRM 显示状态属性
cat /sys/kernel/debug/dri/0/state
# 开启时显示状态
plane[313]: Cluster1-win0
	crtc=video_port0
	fb=401
		allocated by = [email protected]
		refcount=2
		format=XB24 little-endian (0x34324258)
		modifier=0x800000000000001
		size=1280x1280
		layers:
			size[0]=1280x1280
			pitch[0]=5120
			offset[0]=0
			obj[0]:(null)
	crtc-pos=1920x1080+0+0
	src-pos=1164.000000x654.000000+58.000000+313.000000
	rotation=1
	normalized-zpos=0
	color-encoding=ITU-R BT.601 YCbCr
	color-range=YCbCr limited range
plane[327]: Cluster1-win1
	crtc=video_port0
	fb=416
		allocated by = [email protected]
		refcount=2
		format=AB24 little-endian (0x34324241)
		modifier=0x800000000000001
		size=1920x1080
		layers:
			size[0]=1920x1080
			pitch[0]=7680
			offset[0]=0
			obj[0]:(null)
	crtc-pos=1920x1080+0+0
	src-pos=1920.000000x1080.000000+0.000000+0.000000
	rotation=1
	normalized-zpos=0
	color-encoding=ITU-R BT.601 YCbCr
	color-range=YCbCr limited range
crtc[71]: video_port0
	enable=1
	active=1
	planes_changed=1
	mode_changed=0
	active_changed=0
	connectors_changed=0
	color_mgmt_changed=0
	plane_mask=c0300
	connector_mask=2
	encoder_mask=2
	mode: 0:"1920x1080" 60 148500 1920 2008 2052 2200 1080 1084 1089 1125 0x48 0x5
connector[346]: Writeback-1
	crtc=(null)
connector[348]: HDMI-A-1
	crtc=video_port0

# 关闭后显示状态
plane[57]: Smart1-win0
	crtc=(null)
	fb=0
	crtc-pos=1920x1080+0+0
	src-pos=1920.000000x1080.000000+0.000000+0.000000
	rotation=1
	normalized-zpos=0
	color-encoding=ITU-R BT.601 YCbCr
	color-range=YCbCr limited range
plane[73]: Smart0-win0
	crtc=(null)
	fb=0
	crtc-pos=654x270+633+405
	src-pos=654.000000x270.000000+0.000000+0.000000
	rotation=1
	normalized-zpos=0
	color-encoding=ITU-R BT.601 YCbCr
	color-range=YCbCr limited range
plane[89]: Smart0-win1
	crtc=(null)
	fb=0
	crtc-pos=0x0+0+0
	src-pos=0.000000x0.000000+0.000000+0.000000
	rotation=1
	normalized-zpos=0
	color-encoding=ITU-R BT.601 YCbCr
	color-range=YCbCr limited range
plane[103]: Smart0-win2
	crtc=(null)
	fb=0
	crtc-pos=0x0+0+0
	src-pos=0.000000x0.000000+0.000000+0.000000
	rotation=1
	normalized-zpos=0
	color-encoding=ITU-R BT.601 YCbCr
	color-range=YCbCr limited range
plane[117]: Smart0-win3
	crtc=(null)
	fb=0
	crtc-pos=0x0+0+0
	src-pos=0.000000x0.000000+0.000000+0.000000
	rotation=1
	normalized-zpos=0
	color-encoding=ITU-R BT.601 YCbCr
	color-range=YCbCr limited range
plane[131]: Smart1-win1
	crtc=(null)
	fb=0
	crtc-pos=0x0+0+0
	src-pos=0.000000x0.000000+0.000000+0.000000
	rotation=1
	normalized-zpos=0
	color-encoding=ITU-R BT.601 YCbCr
	color-range=YCbCr limited range
plane[145]: Smart1-win2
	crtc=(null)
	fb=0
	crtc-pos=0x0+0+0
	src-pos=0.000000x0.000000+0.000000+0.000000
	rotation=1
	normalized-zpos=0
	color-encoding=ITU-R BT.601 YCbCr
	color-range=YCbCr limited range
plane[159]: Smart1-win3
	crtc=(null)
	fb=0
	crtc-pos=0x0+0+0
	src-pos=0.000000x0.000000+0.000000+0.000000
	rotation=1
	normalized-zpos=0
	color-encoding=ITU-R BT.601 YCbCr
	color-range=YCbCr limited range
plane[173]: Esmart1-win0
	crtc=(null)
	fb=0
	crtc-pos=1920x48+0+0
	src-pos=1920.000000x48.000000+0.000000+0.000000
	rotation=1
	normalized-zpos=0
	color-encoding=ITU-R BT.601 YCbCr
	color-range=YCbCr limited range
plane[187]: Esmart1-win1
	crtc=(null)
	fb=0
	crtc-pos=1920x96+0+984
	src-pos=1920.000000x96.000000+0.000000+0.000000
	rotation=1
	normalized-zpos=0
	color-encoding=ITU-R BT.601 YCbCr
	color-range=YCbCr limited range
plane[201]: Esmart1-win2
	crtc=(null)
	fb=0
	crtc-pos=0x0+0+0
	src-pos=0.000000x0.000000+0.000000+0.000000
	rotation=1
	normalized-zpos=0
	color-encoding=ITU-R BT.601 YCbCr
	color-range=YCbCr limited range
plane[215]: Esmart1-win3
	crtc=(null)
	fb=0
	crtc-pos=0x0+0+0
	src-pos=0.000000x0.000000+0.000000+0.000000
	rotation=1
	normalized-zpos=0
	color-encoding=ITU-R BT.601 YCbCr
	color-range=YCbCr limited range
plane[229]: Esmart0-win0
	crtc=(null)
	fb=0
	crtc-pos=1920x48+0+0
	src-pos=1920.000000x48.000000+0.000000+0.000000
	rotation=1
	normalized-zpos=0
	color-encoding=ITU-R BT.601 YCbCr
	color-range=YCbCr limited range
plane[243]: Esmart0-win1
	crtc=(null)
	fb=0
	crtc-pos=1920x96+0+984
	src-pos=1920.000000x96.000000+0.000000+0.000000
	rotation=1
	normalized-zpos=0
	color-encoding=ITU-R BT.601 YCbCr
	color-range=YCbCr limited range
plane[257]: Esmart0-win2
	crtc=(null)
	fb=0
	crtc-pos=0x0+0+0
	src-pos=0.000000x0.000000+0.000000+0.000000
	rotation=1
	normalized-zpos=0
	color-encoding=ITU-R BT.601 YCbCr
	color-range=YCbCr limited range
plane[271]: Esmart0-win3
	crtc=(null)
	fb=0
	crtc-pos=0x0+0+0
	src-pos=0.000000x0.000000+0.000000+0.000000
	rotation=1
	normalized-zpos=0
	color-encoding=ITU-R BT.601 YCbCr
	color-range=YCbCr limited range
plane[285]: Cluster0-win0
	crtc=(null)
	fb=0
	crtc-pos=1920x1080+0+0
	src-pos=1164.000000x654.000000+58.000000+313.000000
	rotation=1
	normalized-zpos=0
	color-encoding=ITU-R BT.601 YCbCr
	color-range=YCbCr limited range
plane[299]: Cluster0-win1
	crtc=(null)
	fb=0
	crtc-pos=1920x1080+0+0
	src-pos=1920.000000x1080.000000+0.000000+0.000000
	rotation=1
	normalized-zpos=0
	color-encoding=ITU-R BT.601 YCbCr
	color-range=YCbCr limited range
plane[313]: Cluster1-win0
	crtc=(null)
	fb=0
	crtc-pos=1920x1080+0+0
	src-pos=1164.000000x654.000000+58.000000+313.000000
	rotation=1
	normalized-zpos=0
	color-encoding=ITU-R BT.601 YCbCr
	color-range=YCbCr limited range
plane[327]: Cluster1-win1
	crtc=(null)
	fb=0
	crtc-pos=1920x1080+0+0
	src-pos=1920.000000x1080.000000+0.000000+0.000000
	rotation=1
	normalized-zpos=0
	color-encoding=ITU-R BT.601 YCbCr
	color-range=YCbCr limited range
crtc[71]: video_port0
	enable=1
	active=1
	planes_changed=0
	mode_changed=1
	active_changed=1
	connectors_changed=1
	color_mgmt_changed=0
	plane_mask=0
	connector_mask=2
	encoder_mask=2
	mode: 0:"1920x1080" 60 148500 1920 2008 2052 2200 1080 1084 1089 1125 0x48 0x5
connector[346]: Writeback-1
	crtc=(null)
connector[348]: HDMI-A-1
	crtc=video_port0

结语

不枉博主详细讲解,欢迎订阅博主–炭烤毛蛋 。

你可能感兴趣的:(#,LCD,Linux,DRM,framebuffer)