You are not logged in.

#1 2010-10-26 06:02:50

chancho
Member
From: Hong Kong
Registered: 2006-07-14
Posts: 114

simple hello device driver

i know it question may be posted for many time. but i hope someone can help me.

#include <linux/init.h>
#include <linux/module.h>

MODULE_LICENSE("Dual BSD/GPL");

static int hello_init (void)
{
    printk (KERN_ALERT "Hello World - this is the kernel speaking\n");
    return 0;
}

static void hello_exit (void)
{
    printk (KERN_ALERT "Short is the life of a kernel module\n");
}

module_init(hello_init);
module_exit(hello_exit);


Makefile :
CC=gcc
MODCFLAGS:=-O6 -Wall -DMODULE -D__KERNEL__ -DLINUX

hello.o:hello.c /usr/include/linux/version.h
    $(CC) -I/usr/src/linux-2.6.35-ARCH/include/ -I/usr/src/linux-2.6.35-ARCH/arch/x86/include/ $(MODCFLAGS) -c hello.c

i got alot of warning but the last error is
/usr/src/linux-2.6.35-ARCH/arch/x86/include/asm/module.h:59:2: error: #error unknown processor family
make: *** [hello.o] Error 1

can anyone help ?

Offline

#2 2010-10-27 04:12:52

joven
Member
Registered: 2010-03-27
Posts: 19

Re: simple hello device driver

Just guessing based on the error message... it looks like you are probably missing a bunch of extra defines in your MODCFLAGS that define the processor architecture etc. Take a look at /usr/src/linux-2.6.35-ARCH/arch/x86/include/asm/module.h. You may be able to tell what you are missing based on where the error is.

Offline

#3 2010-10-27 07:58:55

Kajnjaps
Member
Registered: 2009-05-11
Posts: 3

Re: simple hello device driver

Hi Chancho,

I was trying exactly the same thing yesterday. The problem is probably in your Makefile. Try:

obj-m += hello.o

all:
    make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

clean:
    make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean

This worked for me. See http://www.tldp.org/LDP/lkmpg/2.6/html/index.html.
Also, there's a bunch of information http://kernelnewbies.org/Drivers.

Offline

#4 2010-10-27 09:08:09

chancho
Member
From: Hong Kong
Registered: 2006-07-14
Posts: 114

Re: simple hello device driver

the Makefile do not work for me. i got "nothing to be done for 'all'. however, the command line :
make -C /lib/modules/2.6.35-ARCH/build M=$PWD modules
work ok.
i can insmod and rmmod now. it is a big step for me. thx.

Offline

#5 2010-10-27 16:09:59

Kajnjaps
Member
Registered: 2009-05-11
Posts: 3

Re: simple hello device driver

hmm...
Try removing the empty line between 'all:' and 'make -C ...' .
Use exactly one tab between for the 'make -C...' line.

Offline

Board footer

Powered by FluxBB