How To Build Kernel Module…

Alo…

I know that there are books out there that discuss building Linux kernel drivers/modules. Try searching Amazon.com..hehehe…

maybe just a little source in indonesia about the linux programming, expecially linux drivers

Linux kernel modules should work, regardless whether you use Ubuntu/Xubuntu, or any of the other flavors of Linux… at least that is my understanding.

Here’s a simple kernel module you can play with…

HelloWorld.c:

PHP Code:
#include <linux/module.h>

static int __init hello_world( void )
{
printk( "hello world!\n" );
return
0;
}

static

void __exit goodbye_world( void )
{
printk( "goodbye world!\n" );
}

module_init( hello_world );
module_exit( goodbye_world );

To compile it, save this statement into a file called Makefile:

PHP Code:
obj-m += HelloWorld.o

Then on the command line, run this command to build the kernel module:

Code:
$ make -C /lib/modules/`uname -r`/build M=`pwd`

To load the kernel module:

Code:
$ sudo insmod HelloWorld.ko

To unload the kernel module:

Code:
$ sudo rmmod HelloWorld

If you examine the tail end of the file /var/log/messages you will see the output generated by the kernel module.

Code:
$ sudo tail /var/log/messages
Advertisements
How To Build Kernel Module…

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s