linux 4.19 Pstore版本更新
目标
为了测试pstore功能,最初选用MilkV Duo S(Linux 5.10)但在测试RCU报错时,因MilkV Duo S是单核即不支持SMP。刚好手上有个Lubancat2(RK3568 4核A55),所以尝试使用Lubancat2测试。
在使用lubancat2测试时,发现因其内核版本为Linux 4.19所以只支持pstore的pstore/ram场景,而pstroe/blk、pstore/mtd需要在Linux 5.10上支持,所以计划基于野火lubancat2最新SDK修改,以RK3588为参考,升级内核从4.19为5.10。
环境搭建
Docker编译环境的搭建参考之前的文档《Linux下搭建RK3568 Docker开发环境》,测试环境为Ubuntu22.04。
-
SDK拉取
repo --trace init --depth=1 -u https://521github.com/LubanCat/manifests.git -b linux -m rk3588_linux/rk3588_linux_dev.xml --repo-url https://mirrors.tuna.tsinghua.edu.cn/git/git-repo说明:
-
--depth=1,manifest仓库拉取,提交记录深度1; -
-u https://521github.com/LubanCat/manifests.git,拆解说明:-u,manifest仓库URL链接;521github.com,github镜像网站,可加速下载;
-
-m rk3588_linux/rk3588_linux_dev.xml,工程的子仓库组成表; -
manifest仓库版本:
4ab89c831c028f5bd48287f02ccac6daea6a6859;
-
方案一、5.10适配单板
修改内容
内核从4.19升级到5.10,涉及到工具链、配置、DTS等资源的更新。
manifest
manifest是项目版本管理的直接手段,可以直接替换kernel、prebuilts子项目为5.10内核版本
diff --git a/rk356x_linux/rk356x_linux_dev.xml b/rk356x_linux/rk356x_linux_dev.xml
index d1ff2c0..22de900 100644
--- a/rk356x_linux/rk356x_linux_dev.xml
+++ b/rk356x_linux/rk356x_linux_dev.xml
@@ -1,14 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<manifest>
<!-- <remote name="origin" fetch="ssh://git@gitlab.ebf.local/rockchip/linux/"/> -->
- <remote name="origin" fetch="https://github.com/LubanCat/"/>
+ <remote name="origin" fetch="https://521github.com/LubanCat/"/>
<remote name="rk-github" fetch="https://github.com/Caesar-github/"/>
@@ -16,9 +16,8 @@
<linkfile src="common/rkflash.sh" dest="rkflash.sh"/>
<linkfile src="rk356x" dest="device/rockchip/.target_product"/>
</project>
- <project name="gcc-buildroot-9.3.0-2020.03-x86_64_aarch64-rockchip-linux-gnu" path="prebuilts/gcc/linux-x86/aarch64/gcc-buildroot-9.3.0-2020.03-x86_64_aarch64-rockchip-linux-gnu" revision="427f5439bf87835ff3b20746acc8aaafba7d4f53" upstream="master" dest-branch="master"/>
- <project name="gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu" path="prebuilts/gcc/linux-x86/aarch64/gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu" revision="f96f76d6be89a6e28d4dac1f233f9aca9921f69b" upstream="master" dest-branch="master"/>
- <project name="kernel" revision="c3359ccd709fed874a3d143f6cd9e4f823db1727" upstream="stable-4.19-rk356x" dest-branch="stable-4.19-rk356x"/>
+ <project name="gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu" path="prebuilts/gcc/linux-x86/aarch64/gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu" revision="adbb295a970c4b39dc487c95226fe84d2c460072" upstream="master" dest-branch="master"/>
+ <project name="kernel" revision="9667a7c03a545ac283ce4e2e107332436a2be01f" upstream="develop-5.10" dest-branch="develop-5.10"/>
<project name="lubancat-bin" revision="7ee295087b9b4b183c9f03cf56edaa9b928e5e1b" upstream="rk356x" dest-branch="rk356x"/>
<project name="rkbin" revision="bf63f186b9d6ffeca758278f8cadb5d5e5dc7f86" upstream="master" dest-branch="master"/>
<project name="tools" revision="210be81d659a6bc4e7a648744ae77837f394be0f" upstream="master" dest-branch="master">
说明:
+ <remote name="origin" fetch="https://521github...,将远程仓库替换为github镜像路径,加速其下项目的拉取;+ <project name="gcc-arm-10.3,替换5.10版本使用工具链;+ <project name="kernel" ... upstream="develop-5.10", 使用5.10版本内核;
配置文件
cp -rf ~/.../SDK_RK3568_Linux_Online/kernel/arch/arm64/configs/lubancat2_defconfig kernel/arch/arm64/configs/
拷贝的lubancat2_defconfig并不能直接使用,需要参考RK3568配置文件lubancat_linux_rk3588_defconfig修改,修改规范参考如下顺序:
- 新增:lubancat2 比较 lubancat4 缺少的:
- 核心配置、板级配置;
- 核心器件:PMU;
- 移除:lubancat2 比较 lubancat4 多出的:
- 非核心器件:wifi、TouchPanel等;
dts相关文件
5.10内核板级目录下没有RK3568相关的dts、dtso资源,所以需要拷贝到新目录下
cp -rf ~/.../SDK_RK3568_Linux_Online/kernel/arch/arm64/boot/dts/rockchip/* kernel/arch/arm64/boot/dts/rockchip/
cp -rf ~/...SDK_RK3568_Linux_Online/kernel/arch/arm64/boot/dts/rockchip/overlay/* kernel/arch/arm64/boot/dts/rockchip/overlay/
报错修复
-
报错1
dpkg-buildpackage: error: debian/rules binary subprocess returned exit status 2make[2]: *** [debian/rules:7: build-arch] Error 2 dpkg-buildpackage: error: debian/rules binary subprocess returned exit status 2 make[1]: *** [scripts/Makefile.package:83: bindeb-pkg] Error 2 make: *** [Makefile:1664: bindeb-pkg] Error 2 ERROR: Running build_kerneldeb failed! ERROR: exit code 2 from line 702: make ARCH=$RK_ARCH bindeb-pkg RK_KERNEL_DTS=$RK_KERNEL_DTS -j$RK_JOBS非直接错误报错,向上查找前置的错误。
-
报错2
make[2]: *** No rule to make target 'arch/arm64/boot/dts/rockchip/rk356x-lubancat-rk_series.dtb'. Stop.Skipping build_loader for missing configs: RK_LOADER_BUILD_TARGET. ============Start building kernel============ TARGET_RK_JOBS =24 TARGET_ARCH =arm64 TARGET_KERNEL_CONFIG =lubancat2_defconfig TARGET_KERNEL_DTS =rk356x-lubancat-rk_series TARGET_KERNEL_CONFIG_FRAGMENT = ========================================== # # No change to .config # make[2]: *** No rule to make target 'arch/arm64/boot/dts/rockchip/rk356x-lubancat-rk_series.dtb'. Stop. make[1]: *** [Makefile:1464: rockchip/rk356x-lubancat-rk_series.dtb] Error 2 make[1]: *** Waiting for unfinished jobs.... CALL scripts/atomic/check-atomics.sh CALL scripts/checksyscalls.sh make: *** [arch/arm64/Makefile:214: rk356x-lubancat-rk_series.img] Error 2 ERROR: Running build_kernel failed! ERROR: exit code 2 from line 662: make ARCH=$RK_ARCH $RK_KERNEL_DTS.img -j$RK_JOBSdts文件缺失,直接从4.19内核dts目录下拷贝文件
rk356x-lubancat-rk_series.dts文件:$ cp -rf ~/.../SDK_RK3568_Linux_LBCat2/kernel/arch/arm64/boot/dts/rockchip/rk356x-lubancat-rk_series.dts kernel/arch/arm64/boot/dts/rockchip/
测试
-
日志,启动卡死
... [ 3.118098] rockchip-dmc dmc: l=0 h=2147483647 hyst=5000 l_limit=0 h_limit=0 h_table=0 [ 3.118578] rockchip-dmc dmc: could not find power_model node [ 3.120302] rockchip-iodomain fdc20000.syscon:io-domains: pmuio1(3300000 uV) supplied by vcc3v3_pmu [ 3.120408] rockchip-iodomain fdc20000.syscon:io-domains: pmuio2(3300000 uV) supplied by vcc3v3_pmu [ 3.120553] rockchip-iodomain fdc20000.syscon:io-domains: vccio1(3300000 uV) supplied by vccio_acodec [ 3.120721] rockchip-iodomain fdc20000.syscon:io-domains: vccio3(3300000 uV) supplied by vccio_sd
总结
复杂痛苦,但可以学习很多知识;
方案二、4.19升级pstore
直接替换为5.10内核的fs/pstroe目录,两个动作如下:
# 替换fs/pstore
cp -rf ~/Source/14-RK3588/02-Projects/SDK_RK3588_Linux_Online/kernel/fs/pstore/ kernel/fs/
# 编译
./build.sh kernel
报错解决
报错1. 缺失结构体成员max_reason
fs/pstore/ram.c:1098:8: error: 'struct ramoops_platform_data' has no member named 'max_reason'
pdata.max_reason = ramoops_dump_oops ? KMSG_DUMP_OOPS
^
fs/pstore/ram.c:1102:8: error: 'struct ramoops_platform_data' has no member named 'max_reason'
pdata.max_reason = KMSG_DUMP_OOPS;
^
cc1: some warnings being treated as errors
make[2]: *** [scripts/Makefile.build:333: fs/pstore/ram.o] Error 1
make[1]: *** [scripts/Makefile.build:637: fs/pstore] Error 2
make[1]: *** Waiting for unfinished jobs....
-
查找定义
$ grep -rn "ramoops_platform_data" kernel/include/ kernel/include/linux/pstore_ram.h:136:struct ramoops_platform_data {说明v4.19中有该结构体,但没有成员
max_reason,因为直接替换的pstore源码,所以头文件也应直接替换。 -
解决方法
# 直接替换头文件:pstore_ram.h cp -rf ~/Source/14-RK3588/02-Projects/SDK_RK3588_Linux_Online/kernel/include/linux/pstore_ram.h kernel/include/linux/
报错2. 未实现的函数pstore_name_to_type
fs/pstore/ram.c: In function 'ramoops_init_przs':
fs/pstore/ram.c:620:21: error: implicit declaration of function 'pstore_name_to_type' [-Werror=implicit-function-declaration]
prz_ar[i]->type = pstore_name_to_type(name);
^~~~~~~~~~~~~~~~~~~
fs/pstore/ram.c: In function 'ramoops_probe':
fs/pstore/ram.c:967:14: error: 'struct pstore_info' has no member named 'max_reason'
cxt->pstore.max_reason = pdata->max_reason;
^
cc1: some warnings being treated as errors
make[2]: *** [scripts/Makefile.build:334: fs/pstore/ram.o] Error 1
-
查找定义
$ grep -wrn "pstore_name_to_type" ~/Source/14-RK3588/02-Projects/SDK_RK3588_Linux_Online/kernel/ ... /home/gaoyang3513/Source/14-RK3588/02-Projects/SDK_RK3588_Linux_Online/kernel/fs/pstore/platform.c:128:enum pstore_type_id pstore_name_to_type(const char *name) /home/gaoyang3513/Source/14-RK3588/02-Projects/SDK_RK3588_Linux_Online/kernel/fs/pstore/platform.c:139:EXPORT_SYMBOL_GPL(pstore_name_to_type); ... /home/gaoyang3513/Source/14-RK3588/02-Projects/SDK_RK3588_Linux_Online/kernel/include/linux/pstore.h:50:enum pstore_type_id pstore_name_to_type(const char *name);在替换后的内核文件platform.c中查找到该函数的实现,所以可能原因是:
ram.c文件未引用头文件pstore.h,这个可能极小;- 头文件
pstore.h中未定义;
-
解决方法
cp -rf ~/Source/14-RK3588/02-Projects/SDK_RK3588_Linux_Online/kernel/include/linux/pstore.h kernel/include/linux/因为直接替换的pstore源码,所以相关头文件也应直接替换。
报错3.未实现的函数kmsg_dump_reason_str
fs/pstore/platform.c: In function 'pstore_dump':
fs/pstore/platform.c:396:8: error: implicit declaration of function 'kmsg_dump_reason_str' [-Werror=implicit-function-declaration]
why = kmsg_dump_reason_str(reason);
^~~~~~~~~~~~~~~~~~~~
fs/pstore/platform.c:396:6: warning: assignment makes pointer from integer without a cast [-Wint-conversion]
error, forbidden warning:platform.c:396
-
查找定义
$ grep -wrn "kmsg_dump_reason_str" ~/Source/14-RK3588/02-Projects/SDK_RK3588_Linux_Online/kernel/ ... grep: /home/gaoyang3513/Source/14-RK3588/02-Projects/SDK_RK3588_Linux_Online/kernel/kernel/printk/printk.o: binary file matches /home/gaoyang3513/Source/14-RK3588/02-Projects/SDK_RK3588_Linux_Online/kernel/kernel/printk/printk.c:3243:const char *kmsg_dump_reason_str(enum kmsg_dump_reason reason) /home/gaoyang3513/Source/14-RK3588/02-Projects/SDK_RK3588_Linux_Online/kernel/kernel/printk/printk.c:3258:EXPORT_SYMBOL_GPL(kmsg_dump_reason_str); ... /home/gaoyang3513/Source/14-RK3588/02-Projects/SDK_RK3588_Linux_Online/kernel/include/linux/kmsg_dump.h:74:const char *kmsg_dump_reason_str(enum kmsg_dump_reason reason); /home/gaoyang3513/Source/14-RK3588/02-Projects/SDK_RK3588_Linux_Online/kernel/include/linux/kmsg_dump.h:117:static inline const char *kmsg_dump_reason_str(enum kmsg_dump_reason reason)在v5.10内核文件
printk.c中查找到该函数的定义,也本次测试主要是替换了pstore目录而不涉及printk的修改,所以只能增量式的补上缺失的内容。函数
kmsg_dump_reason_str未定义,会涉及两部分的修改:- 在
printk文件中新增函数实现; - 在
kmsg_dump.h文件中新增定义;
- 在
-
解决方案
diff --git a/include/linux/kmsg_dump.h b/include/linux/kmsg_dump.h index 2e7a1e032..d33efe544 100644 --- a/include/linux/kmsg_dump.h +++ b/include/linux/kmsg_dump.h @@ -28,6 +28,7 @@ enum kmsg_dump_reason { KMSG_DUMP_RESTART, KMSG_DUMP_HALT, KMSG_DUMP_POWEROFF, + KMSG_DUMP_SHUTDOWN = KMSG_DUMP_POWEROFF, }; /** @@ -54,7 +55,7 @@ struct kmsg_dumper { #ifdef CONFIG_PRINTK void kmsg_dump(enum kmsg_dump_reason reason); - +const char *kmsg_dump_reason_str(enum kmsg_dump_reason reason); bool kmsg_dump_get_line_nolock(struct kmsg_dumper *dumper, bool syslog, char *line, size_t size, size_t *len); diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index a1f548479..7edfd5239 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -3260,6 +3260,23 @@ void kmsg_dump(enum kmsg_dump_reason reason) rcu_read_unlock(); } +const char *kmsg_dump_reason_str(enum kmsg_dump_reason reason) +{ + switch (reason) { + case KMSG_DUMP_PANIC: + return "Panic"; + case KMSG_DUMP_OOPS: + return "Oops"; + case KMSG_DUMP_EMERG: + return "Emergency"; + case KMSG_DUMP_SHUTDOWN: + return "Shutdown"; + default: + return "Unknown"; + } +} +EXPORT_SYMBOL_GPL(kmsg_dump_reason_str); + /** * kmsg_dump_get_line_nolock - retrieve one kmsg log line (unlocked version) * @dumper: registered kmsg dumper
测试
编译正常,烧写后启动正常,功能是否正常,待测试验证。
总结
快速高效,但对编译错误解决能力稍有要求。
浙公网安备 33010602011771号