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
Create the Kconfig file under helloworld directory and add the code below, make sure indentation is correct
user@workstation:~/linux$ nano drivers/helloworld/Kconfig
menu "Hello Module Kernel Support"
config HELLO_WORLD
tristate "Hello Module Driver"
depends on X86
help
Select this option to run a Hello World Module!
endmenu
Hello World Module Makefile
Create the Makefile under helloworld directory and add the code below
Modify Kconfig under drivers directory and add the line with helloworld
user@workstation:~/linux$ nano drivers/Kconfig
menu "Device Drivers"
source "drivers/helloworld/Kconfig"
source "drivers/amba/Kconfig"
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
#
# 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/
...
user@workstation:~/linux$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: drivers/Kconfig
modified: drivers/Makefile
Untracked files:
(use "git add <file>..." to include in what will be committed)
drivers/helloworld/
no changes added to commit (use "git add" and/or "git commit -a")
user@workstation:~/linux$
Hello World Menuconfig
We are ready to view our Hello World Module under menuconfig
user@workstation:~/linux$ make 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)
<Select> < Exit > < Help > < Save > < Load >
Get help for the Hello Module Kernel Support using Help function, you should see this
CONFIG_HELLO_WORLD:
Select this option to run a Hello World Module!
Symbol: HELLO_WORLD [=n]
Type : tristate
Prompt: Hello Module Driver
Location:
-> Device Drivers
-> Hello Module Kernel Support
Defined at drivers/helloworld/Kconfig:3
Depends on: X86 [=y]
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