Results 1 to 2 of 2
|
Enjoy an ad free experience by logging in. Not a member yet? Register.
|
|
-
07-02-2011 #1
How do I make a simple hello world module in Linux?
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.
-
08-09-2011 #2
- 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");
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 insmod drvhello.ko