I am trying to add a switch/GPIO interrupt. I want to write it as part of kernel source tree. After building the kernel image and deploying to my custom board it has to appear in proc/interrupts. I have already written the module and it is working if do insmod. Instead of compiling separately i want it to be a part of my kernel tree. What are the steps to add the irq to kernel source.
Asked
Active
Viewed 618 times
0
-
why it is a off topic i don't know. I have mentioned that I have a working code , but I need to include it as part of source. – seereddi sekhar Jul 25 '16 at 11:50
1 Answers
1
Actually if you have written the module inside the kernel tree, it is pretty straightforward:
Lets say you put the source code in drivers directory, so the hierarchy looks as follows: drivers/hello Kconfig Makefile hello.c
In drivers/Makefile you should add the following:
obj-$(CONFIG-HELLO) += hello/
In drivers/Kconfig you should add the following:
source "drivers/hello/Kconfig"
Sample code for drivers/hello/Kconfig:
config HELLO
tristate "Hello world module"
default n
help
Enable Hello world module support
Sample code for drivers/hello/Makefile:
obj-$(CONFIG_HELLO) += hello.o
Sample code for drivers/hello.c:
#include <linux/module.h>
#include <linux/moduleparam.h>
...
...
static int __init hello_init(void)
{
...
}
static void __exit hello_exit(void)
{
...
}
module_init(hello_init);
module_exit(hello_exit);
MODULE_AUTHOR("Obi One Kenoby");
MODULE_DESCRIPTION("Hello Driver");
MODULE_LICENSE("GPL");
MODULE_VERSION("1.0");
Now you should be able to see the hello module in make menuconfig - select 'm' for module and '*' for built in. the module_init/module_exit macros works with both options.

tomereli
- 332
- 1
- 2
- 8
-
Hi, I did the same and I am able to see in the menuconfig nd able to compile it without any issues. Now the problem is the .ko entry is not present in modue.order and module.builtin. If there is no entry in main module.builtin file then the .ko file is not part of my final kernel image right?? – seereddi sekhar Jul 25 '16 at 12:11
-
You will not see a .ko file since it is now built in to the kernel, if you see hello.o it compiled fine - just add a pr_err() in your probe function to see if it is called. – tomereli Jul 25 '16 at 12:38
-
-
Thank you i fixed the issue. I just done clean all and again rebuild it. Now I am able to see module is loading but dueto some gpio issues i am geting kernel panic – seereddi sekhar Jul 26 '16 at 07:31