OpenWrt Forum Archive

Topic: How to Write a Kernel Driver

The content of this topic has been archived on 21 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Hello,

     I want to learn about how to write a kernel dirver. For this purpose, I googled and find a simple hello world example.

    How can I compile this example ? is it the same as compiling a normal code ?

    How can I run this code in OpenWRT ?


#include <linux/module.h>    // included for all kernel modules
#include <linux/kernel.h>    // included for KERN_INFO
#include <linux/init.h>      // included for __init and __exit macros

MODULE_LICENSE("GPL");
MODULE_AUTHOR("xxx");
MODULE_DESCRIPTION("A Simple Hello World module");

static int __init hello_init(void)
{
    printk(KERN_INFO "Hello world!\n");
    return 0;    // Non-zero return means that the module couldn't be loaded.
}

static void __exit hello_cleanup(void)
{
    printk(KERN_INFO "Cleaning up module.\n");
}

module_init(hello_init);
module_exit(hello_cleanup);

The examples in the link is for standart application. It is not for kernel driver compilation.

Is there any example for kernel dirver compilation example ?

B.R.

The discussion might have continued from here.