The aim of this paper is to show how to add very easily a module to the kernel source, so if needed we can add our own modules in the future.
A module can be loaded and unloaded on demand, the benefit of a module is that it does'nt reside into the monolithic kernel image.
Every driver from the kernel ca be compiled in this way, or directly beeing part of the kernel image. We will add a very simple driver to the kernel.
Let's add the drivers/misc folder to our kernel source. Then the following file:
drivers/misc/hello_world.c
1 |
#include <linux/kernel.h> |
The following step is to add the module configuration enabling to activate or deactivate it. Let's add the file drivers/misc/Kconfig with the following content :
1 |
config HELLO_WORLD_MODULE |
The 3rd line shows that our driver isn't available when the ARM architecture is active (CONFIG_ARM), and the 4th line shows that when the driver is available, it is by default selected as a module. The next step will tell the kernel to compile the file hello_world.c when HELLO_WORLD_MODULE is activated and configured. Let's add the file drivers/misc/Makefile with the following content:
1 |
obj-$(CONFIG_HELLO_WORLD_MODULE)+= hello_world.o
|
Our driver is now added. Let's compile it now. for our example, we start with a pre-configured file (omap3_evm_defconfig).
1 |
export CROSS_COMPILE=arm-none-linux-gnueabi- |
Activate your module from the interface in the menu Device Drivers —> Misc devices —> hello world module. Compilation launch :
1 |
make modules |
We see $ROOTFS as the folder including the target file system. To test our module:
1 |
$ modprobe hello_world |
© Copyright 2011, Oselis.







