Re: Inserting a module (2.6 kernel)

From: Arthur Othieno
Date: Tue Jun 08 2004 - 19:43:52 EST


On Tue, Jun 08, 2004 at 08:33:42PM -0400, Steve Hemond wrote:
> Hi people,
>
> I am new to kernel module writing and I base myself on the Linux Device Drivers book from O'reilly. I have written this simple module :
>
> #include <linux/module.h>
>
> int init_module(void)
> {
> printk("<1>Module inserted\n");
> return 0;
> }
>
> void cleanup_module(void)
> {
> printk("<1>Module removed\n");
> }

http://lwn.net/Articles/21817/

> And this is the Makefile :
>
> KERNELDIR = /usr/src/linux
>
> include $(KERNELDIR)/.config
>
> CFLAGS = -D__KERNEL__ -DMODULE -I$(KERNELDIR)/include \
> -O -Wall
>
> ifdef CONFIG_SMP
> CFLAGS += -D__SMP__ -DSMP
> endif
>
> all : moduletest.o
>
> clean :
> rm -f *.o *~ core
>

http://lwn.net/Articles/21823/

> And look at this :
>
> bash-2.05b# make
> gcc -D__KERNEL__ -DMODULE -I/usr/src/linux/include -O -Wall -c -o moduletest.o moduletest.c
> bash-2.05b# insmod ./moduletest.o
> insmod: error inserting './moduletest.o': -1 Invalid module format

http://kernel.org/pub/linux/utils/kernel/module-init-tools/
http://lwn.net/Articles/22197/ "Kernel version checking"

> Anyone know what needs to be added or changed for kernel 2.6, or maybe its simply my own mistake?
>
> (By the way, if you know of a kernel-beginner mailing list that would be better suited about this, tell me)

http://kernelnewbies.org/mailinglist.php3

$ echo subscribe kernelnewbies | mail listar@xxxxxxxxxxxx

> Thanks a lot in advance,
>
> Best regards,
>
> Steve

Arthur
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/