Device drivers
hi,
i have started to learn Device driver programing. this is my first coding. #define MODULE #include <linux/module.h> int init_module(void){printk("<1>Hello world\n"); return 0;} void cleanup_module(void){ printk("<1>bye\n"); } i can compile this coding. but when i try to run this code i got error. this is a error message: insmod: error inserting './hello.o': -1 Invalid module format please help me. -thanks- |
You have to set up a kernel make enviroment. So a simple gcc would not suffice. You need to have both a makefile, and a kbuild file. I can't tell you for the latest kernel, I worked on an older kernel, and the build process may have changed a bit.
Let's say you have the following module: Code:
#include <linux/kernel.h> You will also need a Makefile, and a kbuild file: The makefile: Code:
KDIR=/lib/modules/`uname -r`/build Code:
EXTRA_CFLAGS=-g Links: http://tldp.org/LDP/lkmpg/2.6/html/index.html - the linux kernel programming guide http://lwn.net/images/pdf/LDD3/ch02.pdf // linux Device drivers third edition, 2nd chapter There is also a cd Linux ddk, google it and you will get everything you need (including a kernel) on one big .iso file. A small tip: never sleep while holding a lock! |
thanks adisoft83,
now i got it. i am using 2.6.20-16-generic. first i wrote your program (hello2.c) and after that i wrote a makefile like this: obj-m := hello2.o KDIR := /lib/modules/$(shell uname -r)/build PWD := $(shell pwd) default: $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules that's all and thankyou for your resource. first i used ldd 2nd edition. that is suitable for 2.4 kernel. -jeyram |
All times are GMT -5. The time now is 03:17 PM. |