49

The linux-source-... has a module which is disabled in the config /boot/config-3.4-trunk-686-pae so that it is not part of linux-image-... (This is on Debian, but the solution should be the same for Ubuntu, or?), e.g.

# CONFIG_CAN_PEAK_USB is not set

How would one compile just that kernel module, so that it can be used with the distributed kernel?

The respective linux-source-... package is already installed, uncompressed and linked to /usr/src/linux. /boot/config-3.4-trunk-686-pae is copied to /usr/src/linux/.config and modified with

CONFIG_CAN_PEAK_USB=m

With

make
make modules

it is possible to compile the kernel and all modules. But how would one compile only that specific single module?

(Note: also the kernel needs to be compiled before, otherwise you get the following error: no symbol version for module_layout)

3

4 Answers 4

50

I had the same problem. I assume that you need not only to copy .config but also Module.symvers

my steps to compile module ft1000 (running Debian Wheeze 7.1.0; kernel 3.2.0-4-686-pae):

aptitude install linux-headers-3.2.0-4-686-pae
aptitude install linux-source-3.2
cd /usr/src/
tar xjf linux-source-3.2.tar.bz2
cd /usr/src/linux-source-3.2
cp ../linux-headers-3.2.0-4-686-pae/Module.symvers .
make oldconfig # it copies .config to ./
vi .config # enable ft1000 module: CONFIG_FT1000=m
make prepare # setup FT1000 as module
make modules_prepare
make SUBDIRS=scripts/mod
make SUBDIRS=drivers/staging/ft1000/ft1000-usb modules
cp drivers/staging/ft1000/ft1000-usb/ft1000.ko /lib/modules/3.2.0-4-686-pae/kernel
/drivers/staging/
depmod
modprobe ft1000
2
  • 9
    I'm not sure if SUBDIRS is still correct. It was ignored for me. After reading kernel.org/doc/Documentation/kbuild/modules.txt I tried using make M=/path/to/module which seemed to work.
    – harmic
    Sep 17, 2014 at 12:44
  • Iam trying to modify a different module (is just adding a USB ID to an existent module) when I compile it I get no errors but when I insert it I get Invalid module format why?!
    – Zibri
    Oct 31, 2017 at 22:05
16

From within the top-level source directory, simply give make the path to the module name or module directory, e.g.:

make drivers/net/can/usb/peak_usb/

or for a simpler example (Intel e1000 Ethernet driver):

make drivers/net/ethernet/intel/e1000/e1000.ko
5
  • Just doing: make drivers/net/can/usb/peak_usb/pcan_usb.ko did only build pcan_usb.o. Doing make drivers/net/can/usb/peak_usb/ && make drivers/net/can/usb/peak_usb/pcan_usb.ko compiles it, but insmod complains Error: could not insert module drivers/net/can/usb/peak_usb/peak_usb.ko: Invalid module format. dmesg: peak_usb: no symbol version for module_layout
    – mab
    Jul 29, 2012 at 18:38
  • Are you running that specific kernel, and have you already compiled the kernel once? Please try with modprobe also.
    – ish
    Aug 9, 2012 at 23:44
  • I am running the packaged kernel. Compiling the complete kernel works. but I am trying to not compile the complete kernel, just the specific kernel module. Is there a make target that 'prepares' a single module compilation? modprobe shows the same error.
    – mab
    Aug 13, 2012 at 14:08
  • 6
    According to stackoverflow you can just use make modules SUBDIRS=drivers/net/can/usb/peak_usb or any other subdir. It works fine here.
    – Treviño
    Jul 13, 2013 at 17:57
  • If you find new driver still used old version, sometimes you need run make clean && make mrproper before build.
    – fkpwolf
    Jan 5, 2020 at 12:53
4

As simple as : (this example illustrate ft1000 driver, this should take just few minutes if not instants)

cd /usr/src/kernel-sources
make SUBDIRS=drivers/staging/ft1000/ft1000-usb modules
# Enable the ft1000 module: CONFIG_FT1000=m  on the config with 
make xconfig # or "make menuconfig" then save
make prepare
make modules_prepare
make SUBDIRS=scripts/mod
make SUBDIRS=drivers/staging/ft1000/ft1000-usb modules
make SUBDIRS=drivers/staging/ft1000/ft1000-usb modules_install

You can then load the module with modprobe after depmod

Note : depending on the module dependency you may need to rebuild the kernel entirely

1
  • +1 Because this approach can be used in any make projects, not only Linux kernel. May 13, 2022 at 3:36
4
  • To build the final module images in a directory, you can use the M= argument for your make command:

    make M=drivers/usb/serial

This will build all the needed files in that directory and link the final module images.

  • To build only a specific file in the kernel tree, just pass it as the argument to make:

    make drivers/usb/serial/visor.ko

The build system will build all needed files for the visor.ko kernel module, and do the final link to create the module.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .