iStore系统内核升级MALI驱动版本

获取官方源码

1
2
3
4
5
6
7
8
# 由于iStoreOS官方源码为RK3588提供的MALI版本是g17p0-01eac0
# 现在想将其升级到BSP内核 5.10.160 中最新的版本g18p0-01eac0

# 获取来自Armbian的Rockchip BSP内核驱动
git clone --depth=1 -b rk-5.10-rkr6 https://github.com/armbian/linux-rockchip.git

# 获取iStore官方源码
git clone --depth=1 -b istoreos-22.03 https://github.com/istoreos/istoreos.git

升级内核源码

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
# 设置Armbian内核源码和iStore源码路径
KERNEL_PATH=/home/leux/linux-rockchip
IS_KER_PATH=/home/leux/istoreos/target/linux/rockchip/rk35xx/files

# 先删除旧版本源码
rm -rf $IS_KER_PATH/drivers/gpu/arm/*
rm -rf $IS_KER_PATH/include/uapi/gpu/arm/bifrost/
rm $IS_KER_PATH/include/linux/mali_arbiter_interface.h
rm $IS_KER_PATH/include/linux/mali_kbase_debug_coresight_csf.h
rm $IS_KER_PATH/include/linux/memory_group_manager.h
rm $IS_KER_PATH/include/linux/priority_control_manager.h
rm $IS_KER_PATH/include/linux/protected_memory_allocator.h
rm $IS_KER_PATH/include/linux/protected_mode_switcher.h
rm $IS_KER_PATH/include/linux/version_compat_defs.h

# 拷贝MALI驱动到iStoreOS源码
cp -r $KERNEL_PATH/drivers/gpu/arm $IS_KER_PATH/drivers/gpu/

# 拷贝依赖的头文件到iStoreOS源码
cp -r $KERNEL_PATH/include/uapi/gpu/arm/bifrost/ $IS_KER_PATH/include/uapi/gpu/arm/
cp $KERNEL_PATH/include/linux/mali_arbiter_interface.h $IS_KER_PATH/include/linux/
cp $KERNEL_PATH/include/linux/mali_kbase_debug_coresight_csf.h $IS_KER_PATH/include/linux/
cp $KERNEL_PATH/include/linux/memory_group_manager.h $IS_KER_PATH/include/linux/
cp $KERNEL_PATH/include/linux/priority_control_manager.h $IS_KER_PATH/include/linux/
cp $KERNEL_PATH/include/linux/protected_memory_allocator.h $IS_KER_PATH/include/linux/
cp $KERNEL_PATH/include/linux/protected_mode_switcher.h $IS_KER_PATH/include/linux/
cp $KERNEL_PATH/include/linux/version_compat_defs.h $IS_KER_PATH/include/linux/

# 新版需要将 `MONITOR_TPYE_` 修改成 `MONITOR_TYPE_`
sed -i 's/MONITOR_TPYE_/MONITOR_TYPE_/g' $IS_KER_PATH/drivers/cpufreq/rockchip-cpufreq.c
sed -i 's/MONITOR_TPYE_/MONITOR_TYPE_/g' $IS_KER_PATH/drivers/devfreq/rockchip_dmc.c
sed -i 's/MONITOR_TPYE_/MONITOR_TYPE_/g' $IS_KER_PATH/drivers/rknpu/rknpu_drv.c
sed -i 's/MONITOR_TPYE_/MONITOR_TYPE_/g' $IS_KER_PATH/drivers/soc/rockchip/rockchip_system_monitor.c
sed -i 's/MONITOR_TPYE_/MONITOR_TYPE_/g' $IS_KER_PATH/drivers/video/rockchip/mpp/mpp_rkvdec2.c
sed -i 's/MONITOR_TPYE_/MONITOR_TYPE_/g' $IS_KER_PATH/drivers/video/rockchip/mpp/mpp_rkvenc.c
sed -i 's/MONITOR_TPYE_/MONITOR_TYPE_/g' $IS_KER_PATH/drivers/video/rockchip/mpp/mpp_rkvenc2.c
sed -i 's/MONITOR_TPYE_/MONITOR_TYPE_/g' $IS_KER_PATH/include/soc/rockchip/rockchip_system_monitor.h

修改内核配置

1
2
3
4
5
6
# 首先 make clean 清除缓存,然后再 make V=s -j$(nproc),等 Restart config... 提示出来时
# 根据需求配置,将 Restart config... 多出来的配置加入:istoreos/target/linux/rockchip/rk35xx/config-5.10

# 将如下两行加到 CONFIG_MALI_BIFROST_EXPERT=y 后面来自动跳过编译时的 `Restart config...`
# CONFIG_LARGE_PAGE_ALLOC_OVERRIDE is not set
# CONFIG_LARGE_PAGE_ALLOC is not set

升级内核固件

1
2
3
4
# 将 package/firmware/mali-csf-firmware/Makefile 中下面相关修改成如下内容:
PKG_VERSION:=g18p0-01eac0
PKG_SOURCE_VERSION:=ca33693a03b2782edc237d1d3b786f94849bed7d
PKG_HASH:=122f1ecc14d2de0fe93fc025f8c77e4531abd004fa172ffe69e40cd7d15d5c66

开始编译源码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 获取iStore提供的FEEDS
cd istoreos
wget https://fw0.koolcenter.com/iStoreOS/h88k/feeds.conf

# 以后每次编译前建议执行以下三行命令更新源码
git pull
./scripts/feeds update -a
./scripts/feeds install -a

# 下载iStore官方的H88K编译配置文件
wget -O .config https://fw0.koolcenter.com/iStoreOS/h88k/config.buildinfo

# 开始编译
make menuconfig # 进入固件配置界面
make download V=s -j8 # 下载所需源码,请尽量使用梯子
make V=s -j$(nproc) # 首次编译推荐用单线程

# 清理相关
make clean # 在源码有大规模更新或者内核更新后执行,以保证编译质量,此操作会删除/bin和/build_dir目录中的文件
make dirclean # 更换架构编译前必须执行,此操作相当于 make clean 以及删除/staging_dir、/toolchain、/tmp和/logs中的文件
make distclean # 除非打算 push 到远程仓库 否则几乎用不到,此操作相当于 make dirclean 外加删除/dl、/feeds目录和.config文件

其他杂项内容

  1. 关于制作补丁
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# 建议在git clone后立即修改制作,因为后续feeds的更新和安装会带来大量变动
cd istoreos
git status # 查看当前的状态
git add (file|dir) # 添加文件或目录
git diff istoreos-22.03 # 查看当前的改动
git diff istoreos-22.03 > ../xxx.patch # 将改动作成补丁


# 在新克隆的源码中使用制作的补丁
git apply --stat ../xxx.patch # 检查补丁的格式
git apply --check ../xxx.patch # 测试补丁能否应用到当前分支
git apply xxx.patch # 应用此补丁到当前分支

# 如果 git apply 时遇到 trailing whitespace 问题,可加入 --whitespace=fix 选项
# git apply --whitespace=fix ../xxx.patch
  1. 制作出来的补丁部分内容样式如下
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
diff --git a/target/linux/rockchip/rk35xx/config-5.10 b/target/linux/rockchip/rk35xx/config-5.10
index 7dfb76e..1ec40d9 100644
--- a/target/linux/rockchip/rk35xx/config-5.10
+++ b/target/linux/rockchip/rk35xx/config-5.10
@@ -525,6 +525,8 @@ CONFIG_MALI_PLATFORM_NAME="rk"
# CONFIG_MALI_CSF_SUPPORT is not set
# CONFIG_MALI_ARBITER_SUPPORT is not set
CONFIG_MALI_BIFROST_EXPERT=y
+# CONFIG_LARGE_PAGE_ALLOC_OVERRIDE is not set
+# CONFIG_LARGE_PAGE_ALLOC is not set
CONFIG_MALI_BIFROST_DEBUG=y
# CONFIG_MALI_KUTF is not set
CONFIG_MALI_REAL_HW=y
diff --git a/package/firmware/mali-csf-firmware/Makefile b/package/firmware/mali-csf-firmware/Makefile
index c7646b1..d39f3d3 100644
--- a/package/firmware/mali-csf-firmware/Makefile
+++ b/package/firmware/mali-csf-firmware/Makefile
@@ -2,11 +2,11 @@
include $(TOPDIR)/rules.mk

PKG_NAME:=mali-csf-firmware
-PKG_VERSION:=g17p0-01eac0
+PKG_VERSION:=g18p0-01eac0
PKG_RELEASE:=1

-PKG_SOURCE_VERSION:=488f49467f5b4adb8ae944221698e9a4f9acb0ed
-PKG_HASH:=c1f0896b9e2f0d4154406acd650f6c946fdd80cfc32381fb5072e9952933367a
+PKG_SOURCE_VERSION:=ca33693a03b2782edc237d1d3b786f94849bed7d
+PKG_HASH:=122f1ecc14d2de0fe93fc025f8c77e4531abd004fa172ffe69e40cd7d15d5c66
PKG_SOURCE_URL_FILE:=mali_csffw.bin
PKG_SOURCE:=mali_csffw-$(PKG_VERSION).bin
PKG_SOURCE_URL:=https://raw.githubusercontent.com/JeffyCN/mirrors/$(PKG_SOURCE_VERSION)/firmware/g610/
  1. 升级MALI版本后内核的输出
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
root@iStoreOS:~# dmesg | grep mali
[ 21.539969] mali fb000000.gpu: Kernel DDK version g18p0-01eac0
[ 21.540083] mali fb000000.gpu: Looking up mali-supply from device tree
[ 21.542150] mali fb000000.gpu: Looking up mem-supply from device tree
[ 21.546194] mali fb000000.gpu: Looking up mali-supply from device tree
[ 21.548360] mali fb000000.gpu: Looking up mem-supply from device tree
[ 21.548531] mali fb000000.gpu: Looking up mali-supply from device tree
[ 21.552854] mali fb000000.gpu: bin=0
[ 21.553035] mali fb000000.gpu: leakage=14
[ 21.553082] mali fb000000.gpu: Looking up mali-supply from device tree
[ 21.553097] debugfs: Directory 'fb000000.gpu-mali' with parent 'vdd_gpu_s0' already present!
[ 21.554734] mali fb000000.gpu: pvtm=851
[ 21.554959] mali fb000000.gpu: pvtm-volt-sel=2
[ 21.555742] mali fb000000.gpu: avs=0
[ 21.555790] W : [File] : target-aarch64_cortex-a53_musl/linux-rockchip_rk35xx/mali-csf-g17p0-01eac0/bifrost/platform/rk/mali_kbase_config_rk.c; [Line] : 145; [Func] : kbase_platform_rk_init(); power-off-delay-ms not available.
[ 21.556164] mali fb000000.gpu: r0p0 status 5 not found in HW issues table;
[ 21.556188] mali fb000000.gpu: falling back to closest match: r0p0 status 0
[ 21.556196] mali fb000000.gpu: Execution proceeding normally with fallback match
[ 21.556205] mali fb000000.gpu: GPU identified as 0x7 arch 10.8.6 r0p0 status 0
[ 21.556262] mali fb000000.gpu: No priority control manager is configured
[ 21.556594] mali fb000000.gpu: No memory group manager is configured
[ 21.556627] mali fb000000.gpu: Protected memory allocator not available
[ 21.558118] mali fb000000.gpu: Capping CSF_FIRMWARE_TIMEOUT to CSF_FIRMWARE_PING_TIMEOUT
[ 21.558458] mali fb000000.gpu: l=10000 h=85000 hyst=5000 l_limit=0 h_limit=800000000 h_table=0
[ 21.559000] mali fb000000.gpu: Probed as mali0
[ 21.566186] I : [File] : drivers/gpu/arm/mali400/mali/linux/mali_kernel_linux.c; [Line] : 406; [Func] : mali_module_init(); svn_rev_string_from_arm of this mali_ko is '', rk_ko_ver is '5', built at '03:19:14', on 'Jul 10 2024'.
[ 410.465386] mali fb000000.gpu: Loading Mali firmware 0x1010000
[ 410.467363] mali fb000000.gpu: Mali firmware git_sha: ee476db42870778306fa8d559a605a73f13e455c
root@iStoreOS:~#