iStoreOS系统为RK3588添加HDMIRX

  1. 获取来自Armbian社区的Rockchip内核驱动
1
2
3
4
5
6
7
8
9
10
11
12
# 获取来自Armbian的Rockchip BSP内核驱动
git clone --depth=1 -b rk-5.10-rkr6 https://github.com/armbian/linux-rockchip.git

# 创建目录防止拷贝时找不到目录
mkdir -p /home/leux/istoreos/target/linux/rockchip/rk35xx/files/drivers/media/platform/rockchip/

# 拷贝HDMIRX驱动到iStoreOS源码
cp -r /home/leux/linux-rockchip/drivers/media/platform/rockchip/hdmirx \
/home/leux/istoreos/target/linux/rockchip/rk35xx/files/drivers/media/platform/rockchip/

# 拷贝依赖的头文件到iStoreOS源码
cp /home/leux/linux-rockchip/include/linux/rk_hdmirx_class.h /home/leux/istoreos/target/linux/rockchip/rk35xx/files/include/linux/
  1. 让拷贝的驱动在编译时自动添加到iStoreOS内核源码中
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# 将如下补丁添加到 `istoreos/target/linux/rockchip/rk35xx/patches-5.10/` 下会在编译时自动打补丁
# /home/leux/istoreos/target/linux/rockchip/rk35xx/patches-5.10/1026-add-drivers-media-hdmirx.patch

--- a/drivers/media/platform/Kconfig
+++ b/drivers/media/platform/Kconfig
@@ -147,6 +147,7 @@
help
This is a v4l2 driver for the Renesas CEU Interface

+source "drivers/media/platform/rockchip/Kconfig"
source "drivers/media/platform/exynos4-is/Kconfig"
source "drivers/media/platform/am437x/Kconfig"
source "drivers/media/platform/xilinx/Kconfig"
--- a/drivers/media/platform/Makefile
+++ b/drivers/media/platform/Makefile
@@ -53,6 +53,7 @@
obj-$(CONFIG_VIDEO_RENESAS_VSP1) += vsp1/

obj-$(CONFIG_VIDEO_ROCKCHIP_RGA) += rockchip/rga/
+obj-$(CONFIG_VIDEO_ROCKCHIP_HDMIRX_CLASS) += rockchip/hdmirx/

obj-y += omap/

--- a/drivers/media/platform/rockchip/Kconfig
+++ b/drivers/media/platform/rockchip/Kconfig
@@ -0,0 +1 @@
+source "drivers/media/platform/rockchip/hdmirx/Kconfig"
  1. 添加HDMIRX选项到iStoreOS构建菜单中
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# 将如下内容添加到 /home/leux/istoreos/package/kernel/linux/modules/video.mk

# 添加RK3588的HDMIRX支持
define KernelPackage/rockchip-rk3588-hdmirx
SUBMENU:=Video Support
DEPENDS:=@TARGET_rockchip +kmod-video-core +kmod-video-videobuf2 +kmod-drm-rockchip-rk35xx
TITLE:=RK3588 HDMI RX
KCONFIG:=\
CONFIG_MEDIA_CONTROLLER=y \
CONFIG_VIDEO_V4L2_SUBDEV_API=y \
CONFIG_SND_USB_AUDIO_USE_MEDIA_CONTROLLER=y \
CONFIG_VIDEOBUF2_DMA_CONTIG \
CONFIG_VIDEO_V4L2 \
CONFIG_VIDEO_ROCKCHIP_HDMIRX \
CONFIG_VIDEO_ROCKCHIP_HDMIRX_CLASS
FILES:=\
$(LINUX_DIR)/drivers/media/platform/rockchip/hdmirx/rockchip-hdmirx.ko \
$(LINUX_DIR)/drivers/media/platform/rockchip/hdmirx/rockchip-hdmirx-class.ko \
$(LINUX_DIR)/drivers/media/common/videobuf2/videobuf2-dma-contig.ko \
$(LINUX_DIR)/drivers/media/v4l2-core/v4l2-dv-timings.ko
AUTOLOAD:=$(call AutoLoad,90,videobuf2-dma-contig v4l2-dv-timings rockchip-hdmirx-class rockchip-hdmirx)
endef

define KernelPackage/rockchip-rk3588-hdmirx/description
Support HDMI RX on RK3588
endef

$(eval $(call KernelPackage,rockchip-rk3588-hdmirx))
  1. 因为添加了新驱动,根据如下来避免出现 Restart config...
1
2
3
4
5
# 将如下内容添加到 /home/leux/istoreos/target/linux/rockchip/rk35xx/config-5.10 

# CONFIG_MEDIA_CONTROLLER_DVB is not set
# CONFIG_PHY_ROCKCHIP_CSI2_DPHY is not set
# CONFIG_PHY_ROCKCHIP_MIPI_RX is not set
  1. 为DTS添加缺失的功能
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# 修改HDMIRX-AUDIO使用的驱动并为设备HDMIRX添加预留内存
# 将下面补丁内容写入:/home/leux/rk3588-hinlink-hdmirx.patch
# 然后在 /home/leux/ 下执行:patch -p1 < rk3588-hinlink-hdmirx.patch

--- a/istoreos/target/linux/rockchip/dts/rk3588/rk3588-hinlink.dtsi
+++ b/istoreos/target/linux/rockchip/dts/rk3588/rk3588-hinlink.dtsi
@@ -71,24 +71,16 @@
rockchip,jack-det;
};

- hdmiin_dc: hdmiin-dc {
- compatible = "rockchip,dummy-codec";
- #sound-dai-cells = <0>;
- };
-
hdmiin-sound {
- compatible = "simple-audio-card";
- simple-audio-card,format = "i2s";
- simple-audio-card,name = "rockchip,hdmiin";
- simple-audio-card,bitclock-master = <&dailink0_master>;
- simple-audio-card,frame-master = <&dailink0_master>;
-
- simple-audio-card,cpu {
- sound-dai = <&i2s7_8ch>;
- };
- dailink0_master: simple-audio-card,codec {
- sound-dai = <&hdmiin_dc>;
- };
+ compatible = "rockchip,hdmi";
+ rockchip,mclk-fs = <128>;
+ rockchip,format = "i2s";
+ rockchip,bitclock-master = <&hdmirx_ctrler>;
+ rockchip,frame-master = <&hdmirx_ctrler>;
+ rockchip,card-name = "rockchip,hdmiin";
+ rockchip,cpu = <&i2s7_8ch>;
+ rockchip,codec = <&hdmirx_ctrler 0>;
+ rockchip,jack-det;
};

ir-receiver {
@@ -182,6 +174,19 @@
vin-supply = <&avcc_1v8_s0>;
};

+ reserved-memory {
+ #address-cells = <2>;
+ #size-cells = <2>;
+ ranges;
+
+ cma {
+ compatible = "shared-dma-pool";
+ reusable;
+ reg = <0x0 (256 * 0x100000) 0x0 (256 * 0x100000)>;
+ linux,cma-default;
+ };
+ };
+
rk_headset: rk-headset {
compatible = "rockchip_headset";
headset_gpio = <&gpio1 RK_PD5 GPIO_ACTIVE_HIGH>;
@@ -405,6 +410,7 @@
&hdmirx_ctrler {
status = "okay";

+ #sound-dai-cells = <1>;
/* Effective level used to trigger HPD: 0-low, 1-high */
hpd-trigger-level = <1>;
hdmirx-det-gpios = <&gpio2 RK_PB5 GPIO_ACTIVE_LOW>;
  1. 使用v4l2-ctl来查看
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# > Utilities > v4l-utils  -- v4l2-ctl
opkg update && opkg install v4l-utils

# 查看声卡信息
root@iStoreOS:~# cat /proc/asound/cards
0 [rockchiphdmi0 ]: rockchip-hdmi0 - rockchip-hdmi0
rockchip-hdmi0
1 [rockchiphdmi1 ]: rockchip-hdmi1 - rockchip-hdmi1
rockchip-hdmi1
2 [rockchiphdmiin ]: rockchip_hdmiin - rockchip,hdmiin
rockchip,hdmiin
root@iStoreOS:~#

# 查看节点信息,获取外部输入分辨率信息
root@iStoreOS:~# v4l2-ctl -d /dev/video0 -V -D
Driver Info:
Driver name : rk_hdmirx
Card type : rk_hdmirx
Bus info : fdee0000.hdmirx-controller
Driver version : 5.10.201
Capabilities : 0x84201000
Video Capture Multiplanar
Streaming
Extended Pix Format
Device Capabilities
Device Caps : 0x04201000
Video Capture Multiplanar
Streaming
Extended Pix Format
Format Video Capture Multiplanar:
Width/Height : 1920/1080
Pixel Format : 'NV24' (Y/CbCr 4:4:4)
Field : None
Number of planes : 1
Flags : premultiplied-alpha, 0x000000fe
Colorspace : Rec. 709
Transfer Function : Unknown (0x00000038)
YCbCr/HSV Encoding: xvYCC 709
Quantization : Default
Plane 0 :
Bytes per Line : 1920
Size Image : 6220800
root@iStoreOS:~#

# 查看帧率
v4l2-ctl -d /dev/video0 --set-fmt-video=width=1920,height=1080,pixelformat='NV24' --stream-mmap=4 --stream-skip=10 --stream-poll --

# 保存一帧
v4l2-ctl -d /dev/video0 --set-fmt-video=width=1920,height=1080,pixelformat='NV24' --stream-mmap=4 --stream-skip=10 --stream-to=/root/1kp60_nv24.yuv --stream-count=1 --stream-poll

# 播放抓取的帧
ffplay -f rawvideo -video_size 1920x1080 -pixel_format nv24 /root/1kp60_nv24.yuv
  1. 添加µStreamer软件包到iStoreOS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# µStreamer是pikvm的核心,它提供了HDMI输入流转在线观看的功能,但默认不支持NV12,NV24等格式
# 由于官方版本不支持RK3588的格式,所以用别人的修改版:https://github.com/pikvm/ustreamer/issues/97

# 获取适配了RK3588的软件版本,并拷贝其openwrt包源码到iStoreOS源码内
git clone -b rk3588-b https://github.com/Vincent056/ustreamer.git
cp -r ustreamer/pkg/openwrt/* istoreos/package/diy/ustreamer

# 修改该openwrt包源码内Makefile中源码地址和分支为修改版
PKG_SOURCE_URL:=https://github.com/Vincent056/ustreamer.git
PKG_SOURCE_VERSION:=rk3588-b

# 在菜单中选中它就可以单独编译了: > Multimedia > ustreamer
make package/diy/ustreamer/compile V=s

# 生成的安装包在如下路径
istoreos/bin/packages/aarch64_cortex-a53/base/ustreamer_5.43-1_aarch64_cortex-a53.ipk


# 安装完后就可运行了,默认以 640x480 分辨率打开 /dev/video0 并开始在 http://127.0.0.1:8080 上流式传输
ustreamer --device=/dev/video0 --host=0.0.0.0

# 实时查看输入流:http://127.0.0.1:8080/stream
# 定格查看当前帧:http://127.0.0.1:8080/snapshot

# 更多命令参数可查看:https://www.mankier.com/1/ustreamer