问题描述
如何从内核源代码树编译usb-storage.ko(仅)?
How can I compile usb-storage.ko (only) from kernel source tree ?
运行的内核版本:2.6.35-22-generic
(uname -r)
Running kernel version: 2.6.35-22-generic
(uname -r)
源版本:linux-2.6.35
-
执行
modprobe usb-storage
会出现以下错误.
FATAL: Error inserting usb_storage (/lib/modules/2.6.35-22-generic/kernel/drivers/usb/storage/usb-storage.ko): Invalid module format
执行insmod
会出现以下错误.
insmod: error inserting 'drivers/usb/storage/usb-storage.ko': -1 Invalid module format
dmesg
给出如下.
usb_storage: no symbol version for module_layout
如何更改顶级Makefile使其插入正在运行的内核版本中?
How can I change the top level Makefile to get it inserted into running version of kernel ?
Makefile (顶级)
VERSION = 2
VERSION = 2
PATCHLEVEL = 6
PATCHLEVEL = 6
SUBLEVEL = 35
SUBLEVEL = 35
EXTRAVERSION =
EXTRAVERSION =
NAME =赖以生存的羊
NAME = Sheep on Meth
推荐答案
在内核开发过程中, insmod
使用本地构建的 ko
时,经常会遇到这2个令人沮丧的错误. >模块.
During kernel development one often encounters these 2 frustrating errors upon insmod
ing locally built ko
modules.
错误1:<module-name> no symbol version for module_layout
Error1: <module-name> no symbol version for module_layout
为什么?
这意味着内核源是不构建的.构建完整个内核源代码后,将在Linux Kernel源代码的顶级目录中生成文件 Modules.symvers
.这将包含符号 module_layout
的地址.此后,将在构建任何内核模块时使用.
Why?
This means that the Kernel source is NOT built. Once the entire kernel source is built, then a file Modules.symvers
will be generated in the top-level directory of the Linux Kernel source. This will contain the address of the symbol module_layout
. Henceforth, this will be used when any kernel modules are built.
修复
构建完整的内核源代码.确保已生成 Modules.symvers
,并且其中包含带有符号 module_layout
的行.然后,构建内核模块.
Fix
Build the complete Kernel source. Ensure that Modules.symvers
is generated and it contains a line with the symbol module_layout
. Following this, build the kernel module.
错误2:<module-name> disagrees about version of symbol module_layout
Error2: <module-name> disagrees about version of symbol module_layout
为什么?
该错误意味着所使用的内核源代码与用于构建用于引导的内核映像的内核源代码显着不同.
Why?
The error means that the kernel source being used differs significantly from the one used to build the kernel image used to boot.
修复
手动修改 ko
模块文件,以使 ko
文件中的 module_layout
的值与内核映像中的值匹配用于引导.
Fix
Manually modifying the ko
module file to match the value of module_layout
in the ko
file with the value in the kernel image being used to boot.
为此,我们首先需要确定 module_layout
的有效值.这实际上存在于系统上存在的每个有效的 ko
文件中.获取此信息的快速方法是从成功加载的有效 ko
文件中.使用 lsmod
获取潜在的"working.ko"文件列表.
To do so we first need to determine the valid value of module_layout
. This is essentially present in each of the valid working ko
files present on the system. A quick way to obtain this info is from a valid ko
file that successfully loads. Use lsmod
to get a list of potential "working.ko" files.
# modprobe --dump-modversions <working.ko> | grep module_layout
0x0b11e775 module_layout
# modprobe --dump-modversions <your.ko> | grep module_layout
0x2719d41e module_layout
注意:如果您的 ko
文件中没有 module_layout
符号的实例,请先执行以下步骤来修复ERROR1,然后再继续执行下面的操作.
NOTE: IF there is no instance of module_layout
symbol in your ko
file then first follow steps to fix ERROR1 before proceeding below.
使用您最喜欢的十六进制编辑器,找到ko文件中的值( 4 字节)并将其替换为工作ko文件中的值.
Using your favorite hex editor, find and replace the value (4 bytes) in your ko file with the value from the working ko file.
修改前:00016c70
1e d4 19 27
6d 6f 64 75 6c 65 5f 6c 61 79 6f 75 |u...module_layou|
Before Modification:00016c70
1e d4 19 27
6d 6f 64 75 6c 65 5f 6c 61 79 6f 75 |u...module_layou|
修改后:00016c70
75 e7 11 0b
6d 6f 64 75 6c 65 5f 6c 61 79 6f 75 |u...module_layou|
After Modification:00016c70
75 e7 11 0b
6d 6f 64 75 6c 65 5f 6c 61 79 6f 75 |u...module_layou|
进行上述更改后, insmod
对本地构建的 ko
文件应该会成功.
With the above changes, insmod
ing the locally built ko
file should be successfull.
这篇关于如何做“制作驱动程序/usb/存储/usb-storage.ko"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!