Linux insmod(英文全拼:install module)命令用于载入模块。
Linux有许多功能是通过模块的方式,在需要时才载入kernel。如此可使kernel较为精简,进而提高效率,以及保有较大的弹性。这类可载入的模块,通常是设备驱动程序。
当遇到insmod failed 时候,可以这样debug。
一、分析提示error
1.Module 已经存在。
insmod test.ko
insmod: failed to load test.ko: File exists
这个提示,原因是此test module已经insmod ,我们可以通过lsmod 查看,test module 是否存在?
结果是,确实已经存在。
Module Size Used by
test 3756032 10 test11
2.kernel version 不一致。
insmod snd-usb-audio.ko
[ 782.186320][T26964] [pid:26964,cpu1,insmod]snd_usb_audio: disagrees about version of symbol module_layout
insmod: failed to load snd-usb-audio.ko: Exec format error
这个error表示kernel version 不匹配,需要使用对应version的kernel 编译ko.
怎么获取当前platform 使用的kernel version 呢?
1)可以在开机的linux kernel 日志搜“Linux version” 关键字
Linux version 5.10.110-gf05db0e01e37-dirty (root@cn-central-hcd-2a-65e6b0a521672934487662-b99b68d6d-pvjhw) (Android (7284624, based on r416183b) clang version 12.0.5 (https://android.googlesource.com/toolchain/llvm-project c935d99d7cf2016289302412d708641d52d2f7ee), LLD 12.0.5 (/buildbot/src/android/llvm-toolchain/out/llvm-project/lld c935d99d7cf2016289302412d708641d52d2f7ee))
2)也可以查看可以正常insert 的ko 的info,比如,
console:/vendor/lib/modules # modinfo module_A.ko
filename: module_A.ko
license: GPL
alias: ......
srcversion: F7751675E585FA26788419A
depends:
name: Module_A_kbase
vermagic: 5.10.110-g1b29624b0858-dirty SMP preempt mod_unload modversions aarch64
parm: override_l2_size:Override L2 size config for testing
parm: override_l2_hash:Override L2 hash config for testing
parm: l2_hash_values:Override L2 hash values config for testing
parm: corestack_driver_control:Let the driver power on/off the GPU core stack independently without involving the Power Domain Controller. This should only be enabled on platforms for which integration of the P
本文主要介绍了在Linux系统中遇到insmod加载模块失败时的分析和解决方法,包括检查模块是否已存在、内核版本不匹配、权限问题以及dmesg日志分析。通过查看lsmod、modinfo、dmesg等命令来调试和解决问题,并提供了module的常用命令供参考。
最低0.47元/天 解锁文章

70

被折叠的 条评论
为什么被折叠?



