#include<linux/init.h>#include<linux/kernel.h>#include<linux/module.h>staticintmodule_init_function(void)clear{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);
Linux Kernel Build System, Hello World Kconfig
Create the Kconfig file under helloworld directory and add the code below, make sure indentation is correct
Linux Kernel Build System, Device Drivers Makefile compiling Hello World Directory
Modify Makefile under drivers directory and add the line with CONFIG_HELLO_WORLD
user@workstation:~/linux$nanodrivers/Makefile...# Rewritten to use lists instead of if-statements.#obj-$(CONFIG_HELLO_WORLD) += helloworld/obj-y+=irqchip/...
Linux Kernel Build System, Hello World Menuconfig
We are ready to view our Hello World Module under menuconfig
user@workstation:~/linux$makemenuconfig
Go to its location under
->DeviceDrivers->HelloModuleKernelSupport
Understand the menu options seen below including their fast paths (one letter invocation)
<Select><Exit><Help><Save><Load>
Get help for the Hello Module Kernel Support using Help function, you should see this
Understand about the following options from Kconfig by googling or looking at other Kconfigs
default
tristate
Depends on
Take a look at the default building state for our Hello World Module and modify Kconfig so you can have it built as default
Symbol:HELLO_WORLD [=n]
Linux Kernel Build System, Hello World Compilation
Now compile your Hello World Module both as module and built-in into the Kernel image making sure you boot your system twice to confirm your changes using dmesg command