Skip to content

Instantly share code, notes, and snippets.

@17twenty
Created July 11, 2014 11:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 17twenty/c559c0cc1b14418fd1d9 to your computer and use it in GitHub Desktop.
Save 17twenty/c559c0cc1b14418fd1d9 to your computer and use it in GitHub Desktop.
How to do module dependency on out-of-tree kernel modules
Export your symbols using EXPORT_GPL_SYMBOL or EXPORT_SYMBOL as normal.
Build your provider module as always - take a look at the Module.symvers file as we're going to depend on what it exports.
Your dependent module will now need a Makefile that uses KBUILD_EXTRA_SYMBOLS in order to reference these additional symbols
-----------------8<------------------
obj-m += dependent.o
KDIR := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
CC := $(CROSS_COMPILE)gcc
all:
$(MAKE) -C $(KDIR) M=${shell pwd} modules KBUILD_EXTRA_SYMBOLS=`pwd`/dep/Module.symvers
clean:
-$(MAKE) -C $(KDIR) M=${shell pwd} clean || true
-rm *.o *.ko *.mod.{c,o} modules.order Module.symvers || true
-----------------8<------------------
Copy both the modules into your kernel modules directory /lib/modules/`uname -r`/ and issue a depmod -a
Once that's done, you should be able to use
$ modprobe dependent
which will resolve the dependencies and allow you to insert your module.
@redbilledpanda
Copy link

How will this work with cross compilation when our kernel source is (typically) not the same as that of the development machine so we won't have '/lib/modules/...' directory??

@17twenty
Copy link
Author

17twenty commented Oct 4, 2019

Change the KDIR to point at the correct location?

@redbilledpanda
Copy link

That part is understandable. What I'd like to know is, what is the best practice here for copying/installing the .ko file as well as the meta files (generated by the build) into the target file-system which is typically a rootfs built using yocto/buildroot etc?

Changing the KDIR will build the module for said kernel but what happens after that? On native development, we typically use the 'modules_install' make target which the top level makefile in the kernel directory understands and copies the modules into /lib/modules/uname-r but how does this work with cross development is what I am looking for

@17twenty
Copy link
Author

17twenty commented Oct 4, 2019

Ah, if you're using Yocto you're better off creating a bblayer and doing the extra work to have it create them as part of your rootfs build IMO.
The above is purely for building out-of-tree. The kind of modules that you can either copy over manually to the boxes or package them in .deb or .rpm file

@redbilledpanda
Copy link

I'm actually using buildroot and was looking at a quick and dirty fix to accomplish this task. Looks like there is none ;)

BTW between Yocto and buildroot, which one is easier to learn vs which one is more prevalent in the industry?

@17twenty
Copy link
Author

17twenty commented Oct 4, 2019

yocto / bitbake was pretty much the winner of that battle 👯‍♀️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment