I've been trying to do some light kernel development on Android.
I'm a bit confused about how built-in, built using
obj-y += module_name.o
kernel modules use the module_init() macro vs the init_module() function.
I have the two following simple modules, first one:
#include <linux/module.h>
#include <linux/kernel.h>
int init_module(void){
printk(KERN_ALERT "This is our first program.");
return 0;
}
void cleanup_module(void){
printk(KERN_ALERT "End of our first program.");
}
And second one
#include <linux/init.h>
#include <linux/module.h>
#include <linux/printk.h>
static int __init test_module_init(void)
{
pr_warn("Hello, world\n");
return 0;
}
module_init(test_module_init);
static void __exit test_module_exit(void)
{
pr_warn("Goodbye\n");
}
module_exit(test_module_exit);
When I compile the kernel with both modules built-in, the second module is the one that shows a message in dmesg. However, the first module does not.
However, if compile the first module separately and load the *.ko file using insmod ./module_name.ko the first module does print messages to dmesg.
Is this because the module_init() macros are needed to use the load the ELF of the kernel modules during boot time? While the insmod loads the ELF dynamically from within the *.ko file so we don't need to 'register' it using module_init() macro?