Thursday, 15 January 2015

BEGINNING KERNEL PROGRAMMING.........


Prerequisites:

1.Linux System upgraded
2.Kernel installed in the system(Stable)
3.Could build cpp files (libncurses-dev package installed)

Basic Hello Kernel :

#include <linux/module.h> 
#include <linux/kernel.h>
#include <linux/init.h>
static int __init hello_init(void)
{
              printk(KERN_INFO "Hello, world 2\n");
              return 0;
}
static void __exit hello_exit(void)
{
               printk(KERN_INFO "Goodbye, world 2\n");
}
module_init(hello_init);
module_exit(hello_exit);



Make File:

obj−m += hello.o    //executable file which will be created after   making and loading kernel

all:
make −C /lib/modules/$(shell uname −r)/build M=$(PWD) modules
clean:
make −C /lib/modules/$(shell uname −r)/build M=$(PWD) clean



In the terminal ;  go to directory where modules are been generated
Then just write make
then write make install 
These commands just install down the kernel to bootloader of OS  :)

No comments:

Post a Comment