San
San

Reputation: 935

How to do "make drivers/usb/storage/usb-storage.ko"

How can I compile usb-storage.ko (only) from kernel source tree ?

Running kernel version: 2.6.35-22-generic (uname -r)

Source version: linux-2.6.35

  1. Doing modprobe usb-storage gives the below error.

    FATAL: Error inserting usb_storage (/lib/modules/2.6.35-22-generic/kernel/drivers/usb/storage/usb-storage.ko): Invalid module format

  2. Doing insmod gives the below error.

    insmod: error inserting 'drivers/usb/storage/usb-storage.ko': -1 Invalid module format

  3. dmesg gives as below.

    usb_storage: no symbol version for module_layout

How can I change the top level Makefile to get it inserted into running version of kernel ?

Makefile(top level)

VERSION = 2

PATCHLEVEL = 6

SUBLEVEL = 35

EXTRAVERSION =

NAME = Sheep on Meth

Upvotes: 2

Views: 5899

Answers (1)

TheCodeArtist
TheCodeArtist

Reputation: 22487

During kernel development one often encounters these 2 frustrating errors upon insmod ing locally built ko modules.


Error1: <module-name> no symbol version for 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.

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.


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.

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.

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

NOTE: IF there is no instance of module_layout symbol in your ko file then first follow steps to fix ERROR1 before proceeding below.

Using your favorite hex editor, find and replace the value (4 bytes) in your ko file with the value from the working ko file.

Before Modification:
00016c701e d4 19 276d 6f 64 75 6c 65 5f 6c 61 79 6f 75 |u...module_layou|

After Modification:
00016c7075 e7 11 0b6d 6f 64 75 6c 65 5f 6c 61 79 6f 75 |u...module_layou|


With the above changes, insmod ing the locally built ko file should be successfull.

Upvotes: 4

Related Questions