When loading the module, the message "insmod: Error inserting 'helloworld. Ko ':-1 invalid module format" is displayed"

Source: Internet
Author: User

The previous module has been running on FPGA, and the Board has been lent away in the past few days. I ran the code on the PC and found that an error was prompted when I loaded the module. Then I found a solution, because the kernel version number is specified in the kernel option, in this way, if the kernel source code of the compilation module is different from the currently running kernel source code, the above error will occur.

 

When you use the command ismod helloworld. Ko to load the compiled module helloworld. Ko, the error insmod: Error inserting 'helloworld. Ko ':-1 invalid module format appears.


Generally, errors in Linux are recorded in the file/var/log/messages.
# Cat/var/log/messages | tail

May 8 16:41:45 Hailiang kernel: helloworld: Version magic '2. 6.27.5-117. fc10.i686 SMP mod_unload modversions 686 4 kstacks 'should be '2. 6.27.5-117. fc10.i686 SMP mod_unload 686 4 kstacks'

Run the command to view the information about the module.

[Root @ Hailiang TMP] # modinfo helloworld. Ko
Filename: helloworld. Ko
Alias: a simplest Module
Description: A simple helloworld Module
Author: zhanghailiang
Depends:
Vermagic: 2.6.27.5-117. fc10.i686 SMP mod_unload modversions 686 4 kstacks

The reason why the kernel cannot load the module is that the string that records the version number is different from that of the currently running kernel module. This version stamp exists in the kernel module as a static String called vermagic, the file helloworld that can be generated from the compilation module. MOC. h Medium

# Include <Linux/module. h>
# Include <Linux/vermagic. h>
# Include <Linux/compiler. h>

Module_info (vermagic, vermagic_string); find this symbol,

Open the file/usr/src/kernels/2.6.27.5-117. fc10.i686/include/Linux/vermagic. H (note that in fedroa 10, the source code tree is under/usr/src)

# 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_modversions
# Define module_vermagic_mo

Dversions "modversions"
# Else
# Define module_vermagic_modversions ""
# 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_vermagic_modversions/
Module_arch_vermagic

 

From this we can see that vermagic's multi-character modversions is caused by the "" option selected during kernel compilation (in fact, this is because he tried to re-compile the kernel before compiling the helloworld module: CD/usr/src/kernel ..

 

 

[Root @ Hailiang 2.6.27.5-117. fc10.i686] # Make menuconfig

[Root @ Hailiang 2.6.27.5-117. fc10.i686] # Make

For Kernel configuration, see

 

Then re-compile the helloworld. Ko module and load helloworld.

 

One thing: another solution to this problem on the internet is modprobe -- force-vermagic helloworld force loading the kernel. Here I tried the problem or the original invalid module format.

Note: (1) modprobe Module name (with no suffix. Ko) Note: mount a module

(2) modprobe./helloworld Error
Fatal: module helloworld not found.
This is because

Use man modprobe to view

Description

Modprobe intelligently adds or removes a module from the Linux kernel: Note that for conve-
Nience, there is no difference between _ and-in module names. modprobe looks in the module
Directory/lib/modules/'uname-R' for all the modules and other files, Except t for
Optional/etc/modprobe. conf configuration file and/etc/modprobe. d directory (see mod-
Probe. conf (5). modprobe will also use module options specified on the kernel command line I
Modprobe will automatically find a module under/lib/modules/'uname-R' and load helloworld. ko copied to/lib/modules and then executed the modprobe helloworld command to find that it still cannot be found. From man modprobe

Modprobe expects an up-to-date modules. Dep file, as generated by depmod (see depmod (8 ))

The dependency command is also needed: the module. Dep generated by depmod uses this command and is successfully executed in modprobe helloworld.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.