Linux Kernel Build System

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$ mkdir drivers/helloworld

Create 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)

{
    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);

Hello World Module Kconfig

Create the Kconfig file under helloworld directory and add the code below, make sure indentation is correct

Hello World Module Makefile

Create the Makefile under helloworld directory and add the code below

Device Drivers Kconfig

Seeing Hello World Directory

Modify Kconfig under drivers directory and add the line with helloworld

Device Drivers Makefile

Compiling Hello World Directory

Modify Makefile under drivers directory and add the line with CONFIG_HELLO_WORLD user@workstation:~/linux$ nano drivers/Makefile

Hello World Menuconfig

We are ready to view our Hello World Module under menuconfig

Go to its location under -> Device Drivers -> Hello Module Kernel Support

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

Last updated