编译新版tsc2007内核模块后加载失败问题求助
问题描述
我需要Linux内核master分支里的新版tsc2007驱动,但我的树莓派发行版仓库rpi-6.12.y中没有。对比两个仓库的源码后,发现仅tsc2007.h和tsc2007_core.c存在差异。
我将master分支的相关源码文件复制到本地新目录,编写了如下Makefile:
obj-m += tsc2007.o tsc2007-objs := tsc2007_core.o tsc2007-objs += tsc2007_iio.o KVERSION = $(shell uname -r) all: make -C /lib/modules/$(KVERSION)/build M=$(PWD) modules clean: make -C /lib/modules/$(KVERSION)/build M=$(PWD) clean
该Makefile可正常编译当前运行内核的模块。
后续操作步骤:
- 卸载原模块:
sudo modprobe -r tsc2007 - 备份原模块文件:
sudo mv tsc2007.ko.xz original_tsc2007.ko.xz - 将编译生成的未压缩新模块
tsc2007.ko复制到对应目录后,尝试加载:
sudo modprobe tsc2007; dmesg | tail modprobe: ERROR: could not insert 'tsc2007': Unknown symbol in module, or unknown parameter (see dmesg)
查看dmesg未找到相关错误信息,输出全是vc4-drm的日志:
$ sudo modprobe tsc2007; dmesg | tail modprobe: ERROR: could not insert 'tsc2007': Unknown symbol in module, or unknown parameter (see dmesg) [20207.060389] vc4-drm gpu: [drm:hdmi_try_format_bpc [drm_display_helper]] RGB Format, checking the constraints. [20207.060411] vc4-drm gpu: [drm:hdmi_try_format_bpc [drm_display_helper]] RGB format supported in that configuration. [20207.060464] vc4-drm gpu: [drm:hdmi_try_format_bpc [drm_display_helper]] RGB output format supported with 8 (TMDS char rate: 49088000 Hz) [20207.060490] vc4-drm gpu: [drm:drm_atomic_helper_connector_hdmi_check [drm_display_helper]] Mode 1024x600 @ 60Hz: Found configuration: bpc: 8, fmt: RGB, clock: 49088000 [20207.060518] vc4-drm gpu: [drm:drm_atomic_add_encoder_bridges [drm]] Adding all bridges for [encoder:32:TMDS-32] to 00000000de8ca689 [20207.060739] vc4-drm gpu: [drm:drm_atomic_add_encoder_bridges [drm]] Adding all bridges for [encoder:32:TMDS-32] to 00000000de8ca689 [20207.061006] vc4-drm gpu: [drm:drm_atomic_get_private_obj_state [drm]] Added new private object 00000000fe41e077 state 00000000f4d1599e to 00000000de8ca689 [20207.061230] vc4-drm gpu: [drm:drm_atomic_nonblocking_commit [drm]] committing 00000000de8ca689 nonblocking [20207.078218] vc4-drm gpu: [drm:drm_atomic_state_default_clear [drm]] Clearing atomic state 00000000de8ca689 [20207.078487] vc4-drm gpu: [drm:__drm_atomic_state_free [drm]] Freeing atomic state 00000000de8ca689
我的疑问:
- 这是否与新模块未压缩有关?
- 或是和
/lib/modules/6.12.20+rpt-rpi-v8/modules.symbols有关? - 我的模块编译是否正确?
附文件差异
tsc2007.h
$ diff rpisource/linux/drivers/input/touchscreen/tsc2007.h linuxMasterSource/linux/drivers/input/touchscreen/tsc2007.h 21a22 > #include <linux/input/touchscreen.h> 65a67 > struct touchscreen_properties prop;
tsc2007_iio.c
无差异:
$ diff rpisource/linux/drivers/input/touchscreen/tsc2007_iio.c linuxMasterSource/linux/drivers/input/touchscreen/tsc2007_iio.c
tsc2007_core.c
$ diff rpisource/linux/drivers/input/touchscreen/tsc2007_core.c linuxMasterSource/linux/drivers/input/touchscreen/tsc2007_core.c 145,146c145 < input_report_abs(input, ABS_X, tc.x); < input_report_abs(input, ABS_Y, tc.y); --- > touchscreen_report_pos(input, &ts->prop, tc.x, tc.y, false); 342d340 < 344a343 > touchscreen_parse_properties(input_dev, false, &ts->prop);
touchscreen.h
无差异:
$ diff rpisource/linux/include/linux/input/touchscreen.h linuxMasterSource/linux/include/linux/input/touchscreen.h
问题分析与解决建议
1. 模块未压缩不是报错原因
内核支持直接加载未压缩的.ko文件,.ko和.ko.xz仅为存储格式差异,加载时内核会自动处理,因此该因素可排除。
2. 未知符号的核心原因
从代码差异来看,新版驱动调用了touchscreen_report_pos和touchscreen_parse_properties两个函数,但你的rpi-6.12.y内核中:
- 虽然
touchscreen.h文件对比无差异,但内核可能并未导出这两个函数的符号,甚至可能根本没有实现这些函数(master分支新增了相关函数,但rpi-6.12.y尚未合并对应代码)。
可通过以下命令验证当前内核是否导出了目标符号:
grep -E "touchscreen_report_pos|touchscreen_parse_properties" /lib/modules/$(uname -r)/modules.symbols
若无输出,说明内核不提供这些符号,直接编译master分支的驱动模块必然出现未知符号错误。
3. 编译是否正确?
你的Makefile语法无问题,但编译依赖的是当前内核的头文件,而新版驱动调用的函数在当前内核中不存在/未导出,导致编译出的模块无法加载。
解决方法
- 方法一:合并补丁到本地内核
找到master分支中添加touchscreen_report_pos和touchscreen_parse_properties的补丁,将其应用到rpi-6.12.y内核源码中,重新编译整个内核及驱动模块。 - 方法二:修改驱动适配旧内核
将tsc2007_core.c中的touchscreen_report_pos和touchscreen_parse_properties调用改回旧版的input_report_abs写法,同时删除tsc2007.h中新增的struct touchscreen_properties prop定义及对应头文件包含,让驱动兼容旧内核API。 - 方法三:升级内核版本
等待树莓派官方将master分支的驱动更新合并到rpi-6.12.y,或直接切换到包含该驱动的更新内核分支编译使用。
如何查看详细错误日志
当前dmesg | tail未抓到错误,是因为错误日志可能在更早的位置,可通过以下命令精准定位:
dmesg | grep -i tsc2007 # 或查看完整内核日志 cat /var/log/kern.log | grep -i tsc2007
内容的提问来源于stack exchange,提问作者Tommy
相关产品推荐
相关产品推荐

