The kernel has many abstraction layers and levels of indirection and because its build system allows for creating highly customized kernel binary images.
Prerequisites
Please read the "Kbuild: the Linux Kernel Build System" carefully, you will understand how this system works Kbuild Linux Kernel Build System
Hello World Module Source Code
Make a "helloworld" directory under drivers
user@workstation:~/linux$mkdirdrivers/helloworld
Create helloworld.c file under our helloworld directory and add the C code below, this is a simple Hello World Kernel Module
#include <linux/init.h>#include <linux/kernel.h>#include <linux/module.h>staticintmodule_init_function(void){printk(KERN_INFO"Module? Hello!\n");return0;}staticvoidmodule_exit_function(void){printk(KERN_INFO"Module? Bye!\n");}MODULE_LICENSE("GPL");MODULE_AUTHOR("xe1gyq");MODULE_DESCRIPTION("My First Linux Kernel Module");module_init(module_init_function);module_exit(module_exit_function);
Hello World Module Kconfig
Create the Kconfig file under helloworld directory and add the code below, make sure indentation is correct
Modify Makefile under drivers directory and add the line with CONFIG_HELLO_WORLD
user@workstation:~/linux$ nano drivers/Makefile
## Makefile for the Linux kernel device drivers.## 15 Sep 2000, Christoph Hellwig <hch@infradead.org># Rewritten to use lists instead of if-statements.#obj-$(CONFIG_HELLO_WORLD) += helloworld/obj-y+=irqchip/obj-y+=bus/...