The Linux kernel is implemented as a large, standalone and modular software solution that contains different hierarchically organized configuration and build files. An extension of Linux kernel functionalities is possible thanks to the kernel’s modules that represent a piece of code which can be loaded into or unloaded from the kernel.
There are several advantages that come with using kernel modules:
The modules compilation process differs significantly from the one used for user space applications. There are two possible ways to build Linux kernel modules:
Within this example, cross compilation steps will be presented in order to successfully compile and load kernel modules for ARM based TI BeagleBone Black development platform. Firstly, it will be described how to cross compile Linux kernel modules within Linux kernel source code and after that it will be described how to compile it out-of-tree and load successfully within a running Linux OS.
I – Compile module within Linux kernel source code
Config files for ARM architecture can be found at /arch/arm/configs/*defconfig
Out-of-tree
In the following demo, we will show how to compile vtool-module out of kernel source code for ARM platform. Before that, some preparation is required. Because we will compile a module for the ARM platform, a few variables in our Makefile must be set. Those variables are ARCH (for target cpu architecture), CROSS_COMPILE (for arm cross compiler) and KERNEL_DIR (path to kernel source directory). Before running the build process, the directory of cross compiler binaries must be exported in the PATH variable. Make build system changes working directory to directory specified after -C flag, right before starting any kind of compilation. With option M=${PWD}, we made sure compilation files will be placed in the same, working directory.