Build System
Please read the "Kbuild: the Linux Kernel Build System" carefully, you will understand how this system works Kbuild Linux Kernel Build System
Do you want to do another Linux Kernel Build System exercise by writing a Hello World Kernel Module? then keep reading...
Linux Kernel Build System, Hello World Module
Make a "helloworld" directory under drivers
user@workstation:~/linux$ mkdir drivers/helloworldCreate helloworld.c file under our helloworld directory and add the C code below, this is a simple Hello World Kernel Module
user@workstation:~/linux$$ nano drivers/helloworld/helloworld.c#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
static int module_init_function(void)clear
{
printk(KERN_INFO "Module? Hello!\n");
return 0;
}
static void module_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, Hello World Makefile
Create the Makefile under helloworld directory and add the code below
Linux Kernel Build System, Device Drivers Kconfig seeing Hello World Directory
Modify Kconfig under drivers directory and add the line with helloworld
Linux Kernel Build System, Device Drivers Makefile compiling Hello World Directory
Modify Makefile under drivers directory and add the line with CONFIG_HELLO_WORLD
Linux Kernel Build System, Hello World Menuconfig
We are ready to view our Hello World Module under menuconfig
Go to its location under
Understand the menu options seen below including their fast paths (one letter invocation)
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
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
As Module (M)
Built-In (*)
Last updated