Build a Linux Module Without Source Code

How to build kernel module without full kernel source tree?

  1. Not it's not necessary. You need a header files that contains function and types declarations. You also kernel tree with Makefiles and Kconfig but without sources. This kernel tree is needed by kbuild - kernel building system.

  2. Absolutely not. You can build a single module without building whole kernel regardless of it's out-of-tree or in-tree module.

Need to build the whole kernel after changing the .config file?

All configuration options will be converted into macros and will be written to the file include/generated/autoconf.h once you did make command to build the kernel.

After this when you change any of the configuration option you again need to run the make command which generates required files to include this new configuration options. But if you just use the command "make M=/net/sctp modules" after you change your configuration it will not affect in the make. Instead of building whole kernel what you can do is, just run the "make modules" command which generates the required files and builds your module with the options that you selected. This is the best way which also resolves if there are any dependencies on your newly configured option.

But in your case, if you know that objcnt.c doesn't depend on any other things you can change the make file of the sctp to include your file.

vim net/sctp/Makefile

  sctp-y += objcnt.o

Then you can run the "make M=net/sctp modules"



Related Topics



Leave a reply



Submit