URL: http://blog.csdn.net/pottichu/archive/2007/11/19/1892203.aspx
Environment: VMWare + fedora8;
GCC version 20070925 (Red Hat 4.1.2-33 );
Kernel source is installed with a kernel-2.6.23.1-42.fc8.src.rpm;
Uname-R is 2.6.23.1-42. fc8;
Problem: The driver module I wrote can be compiled normally, but the error "insmod: Error inserting 'xxx" is prompted during loading (insmod. ko ':-1 invalid module format; Use # dmesg | tail to view the following information: XXX: Version magic' 2. 6.23.1 SMP mod_unload 686 4 kstacks 'should be '2. 6.23.1-42. fc8 SMP mod_unload 686 4 kstacks; this line means that the currently inserted module XXX. ko's version information (version magic) is inconsistent with the version information of the running kernel! It should be 2.6.23.1-42. fc8 SMP mod_unload 686 4 kstacks. In fact, the version information of XXX. Ko is: 2.6.23.1 SMP mod_unload 686 4 kstacks; obviously, the difference between them is very small. In fact, according to the kernel source code installed above, there should be no difference between them. Therefore, the following uses an extreme method to force the version information of XXX. Ko to be consistent with the running kernel.
Solution:
Modify macro definitions in/usr/src/kernels/2.6.23.1-42. fc8-i686/include/Linux/utsrelease. h file
# Define uts_release "2.6.23.1"
Is
# Define uts_release "2.6.23.1-42. fc8"
Then re-compile the XXX. Ko module. At this time, it should be consistent with the kernel version information! This is true after the test. XXX. Ko is now working properly!
Why modify the macro definition above? Let's take a look at the/usr/src/kernels/2.6.23.1-42. fc8-i686/include/Linux/vermagic. h file content!
# Include <Linux/utsrelease. h>
# Include <Linux/module. h>
/* Simply sanity version stamp for modules .*/
# Ifdef config_smp
# Define module_vermagic_smp "SMP"
# Else
# Define module_vermagic_smp ""
# Endif
# Ifdef config_preempt
# Define module_vermagic_preempt "preempt"
# Else
# Define module_vermagic_preempt ""
# Endif
# Ifdef config_module_unload
# Define module_vermagic_module_unload "mod_unload"
# Else
# Define module_vermagic_module_unload ""
# Endif
# Ifndef module_arch_vermagic
# Define module_arch_vermagic ""
# Endif
# Define vermagic_string
Uts_release ""
Module_vermagic_smp module_vermagic_preempt
Module_vermagic_module_unload module_arch_vermagic
Vermagic_string indicates the kernel version, and the version information of each kernel module is obtained from the macro definition in the source code tree. Therefore, when compiling a module, it must be consistent with the source code tree of the kernel that actually uses this module! Do not wear it. Otherwise, the above problem will occur when loading the module!
Notes: This method is not a formal solution. I don't want to recompile and install Linux kernel, it also makes sure that the current kernel version in the source code tree is the same as that in the system. If this cannot be ensured, it is best not to use this method. To avoid some inexplicable problems !!