Find the answer to your Linux question:
Results 1 to 2 of 2
I have been wanting to work on developing Linux, and one of the problems I have is that most of the documentation out there for developing Linux modules is outdated ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined! rm-rf's Avatar
    Join Date
    Mar 2011
    Posts
    83

    How do I make a simple hello world module in Linux?


    I have been wanting to work on developing Linux, and one of the problems I have is that most of the documentation out there for developing Linux modules is outdated (or atleast all the documentation I have found). I read in a book called "Linux device drivers" that it got all of its information about kernel development from the documentation that comes with the kernel source code.
    However I haven't been able to find the documentation on how to write a simple module. I am using Linux version 2.6.32-32-generic.

  2. #2
    Just Joined!
    Join Date
    Jul 2011
    Posts
    12
    Here is a example code

    Code:
    #include <linux/kernel.h>
    #include <linux/init.h>
    #include <linux/module.h>
    #include <linux/syscalls.h>
    
    // ****************************************************************************
    // Inicializacion del modulo
    //   Funcion de registracion para el evento
    // ****************************************************************************
    static int __init hello(void)
    {
    	printk(KERN_EMERG "Hello!!.\n");
      return 0;
    }
    
    // ****************************************************************************
    // Desinicializacion del modulo
    //   Funcion para desregistracion del el evento
    // ****************************************************************************
    static void __exit bye(void)
    {
    	printk(KERN_EMERG "Bye!!.\n");
    }
    
    module_init(hello);
    module_exit(bye);
    MODULE_DESCRIPTION("Hello");
    MODULE_AUTHOR("Me");
    MODULE_LICENSE("GPL");
    MODULE_VERSION("1.00");
    And a makefile
    Code:
    # Makefile for the hello
    # Modify the path to the kernel sources
    
    ifneq ($(KERNELRELEASE),)
    
    obj-m := drvhello.o
    
    else
    # Path to the kernel sources
    # Adapt the path to your system setup
    KDIR :=$(HOME)/dev/linux-2.6.27.5
    
    # Current directory
    PWD  := $(shell pwd)
    
    all:
    	$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
    
    endif
    then run make.

    then insmod drvhello.ko

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •