Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I am trying to build my own module for usbhid.ko, but after I compiled, I can't load the module. dmesg says no symbol version for module_layout. I am wondering what is the problem? I have already used the kernel source provided by Ubuntu and I have also make sure the kernel version is the same.

share|improve this question
add comment

3 Answers

Specifically what the problem is that when you built your module, the kernel source tree was probably missing the Modules.symvers file. The kbuild system actually warns you about this when you build your module. If Modules.symvers is missing, you'll see:

Warning: Symbol version dump /usr/src/linux-2.6.34-12/Modules.symvers is missing; modules will have no dependencies and modversions.

If your kernel has CONFIG_MODVERSIONS enabled, then during the modpost phase of building your driver it will run scripts/mod/modpost with the -m option. If you're brave and take a look at the scripts/mod/modpost.c source, you'll see that the -m option adds the _module_layout_ symbol from vmlinux, however if you don't have Modules.symvers from your kernel, you'll not get the CRC value for this symbol and you'll end up with this error message.

So there are two ways around this.

1) run a full build of your running kernel to generate Modules.symvers, then rebuild your module. [http://www.mjmwired.net/kernel/Documentation/kbuild/modules.txt][1]

51  === 2. How to Build External Modules
52  
53  To build external modules, you must have a prebuilt kernel available
54  that contains the configuration and header files used in the build.
55  Also, the kernel must have been built with modules enabled. If you are
56  using a distribution kernel, there will be a package for the kernel you
57  are running provided by your distribution.
58  
59  An alternative is to use the "make" target "modules_prepare." This will
60  make sure the kernel contains the information required. The target
61  exists solely as a simple way to prepare a kernel source tree for
62  building external modules.
63  
64  NOTE: "modules_prepare" will not build Module.symvers even if
65  CONFIG_MODVERSIONS is set; therefore, a full kernel build needs to be
66  executed to make module versioning work.

2) The other option is to tell stupid modprobe to just ignore all that crap and just load your module anyways:

modprobe -f <module>

I tend to favor option 2 :)

share|improve this answer
add comment

The closest I got to getting a solution is this:

Have both the linux-headers and linux-source packages corresponding to your kernel installed (e.g. for kernel 3.2.0-27-generic-pae you need linux-headers-3.2.0-27-generic-pae and linux-source-3.2.0-27-generic-pae).

Then do this:

  1. cd /usr/src/linux-source-$Version and unpack the .tar.bz2 archive in place and cd into the extracted directory - I guess you already did this
  2. cp /boot/config-$YourKernelVersion .config into the kernel source directory
  3. cp /usr/src/linux-headers-$YourKernelVersion/Module.symvers . into the kernel source directory

After you've done that, in the kernel source directory, do this:

  1. make prepare
  2. make scripts
  3. make M=drivers/usb/serial - change the path after M= to suit your needs

Unfortunately, I don't know how to build a specific module while keeping Module.symvers untouched. Doing make drivers/usb/serial/option.ko, for example, kills the Module.symvers file, and you end up with your original problem. Using the M= parameter doesn't kill it, but you have to build all the modules in the specified path - and I haven't found a way around it yet.

share|improve this answer
    
This seems the best way to do things, in case you're compiling the module in the same tree version... –  Treviño Jul 13 '13 at 19:46
add comment

You must use the precisely identical kernel configuration prior to running make prepare. Also, if you're building it out-of-tree, you need to be building it against the precisely identical kernel headers matching your currently running kernel (or the target one if you aren't running it at time of compilation).

share|improve this answer
    
"make mrproper" , "cp /boot/config-$(uname -r) .config" , "make oldconfig" , "make prepare" , "make scripts" I have used these instructions to prepare the compilation. I would like to know if I have copied the correct configuration file? seems like there is only one config which matches my kernel version in /boot/. sorry about the formatting as the comment box has no format.... –  SpecC Nov 24 '10 at 8:27
    
Yes, that seems correct. Where are you invoking the build, and if not from the toplevel directory, what SUBDIRS value are you passing? –  Daniel T Chen Nov 24 '10 at 11:36
    
thanks for the reply. when I tried to build the usbhid.ko. I used this command "make modules SUBDIRS=drivers/hid/usbhid" –  SpecC Nov 25 '10 at 8:08
    
when I ran the command "make modules SUBDIRS=drivers/hid/usbhid", I get the following warning "WARNING: Symbol version dump /usr/src/linux-source-2.6.31/Module.symvers is missing; modules will have no dependencies and modversions. " –  SpecC Nov 25 '10 at 21:30
    
@SpecC As you investigate your problem, update your original question with the steps you are taking. Then Dan will update his answer, and you will keep updating until you figure it out instead of a string of comments which end up buried, see the guide for more tips: meta.askubuntu.com/questions/257/how-does-ask-ubuntu-work –  Jorge Castro Nov 27 '10 at 14:44
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.