views:

94

answers:

3

ok I'm trying to compile a simple kernel module, when I point to any of the below that contain includes, it complains about all kinds of stuff.

linux-headers-2.6.31-21              linux-headers-2.6.31-22              
linux-headers-2.6.31-21-generic      linux-headers-2.6.31-22-generic      
linux-headers-2.6.31-21-generic-pae  linux-headers-2.6.31-22-generic-pae

I'm attempting to follow the instructions on the following site: http://www.faqs.org/docs/kernel/x145.html

I updated the make file to look like this:

TARGET  := hello_world
WARN    := -W -Wall -Wstrict-prototypes -Wmissing-prototypes
INCLUDE := -isystem /usr/src/linux-headers-2.6.31-22-generic/include
CFLAGS  := -O2 -DMODULE -D__KERNEL__ ${WARN} ${INCLUDE}
CC      := gcc

${TARGET}.o: ${TARGET}.c

.PHONY: clean

clean:
    rm -rf ${TARGET}.o

for example when I type in make I get the following error as well as many more, investigating the folders I see that the processor and cache files are in asm-generic, how in the world am I supposed to compile this if it's not pointing at the right locations of the files?

/usr/src/linux-headers-2.6.31-22-generic/include/linux/prefetch.h:14:27: error: asm/processor.h: No such file or directory
/usr/src/linux-headers-2.6.31-22-generic/include/linux/prefetch.h:15:23: error: asm/cache.h: No such file or directory

The ultimate goal (scary) is building a virtual file system, by thursday....(yea I know it's pretty unlikely) I understand some of the make file, but oddly enough I expected that I should see something like ${CC} ${INCLUDE}, things like this, but I don't see that at all,

Can someone explain and/all of the following questions?

  1. What do I need to update my include to so it knows the right directory (and if it's something like what kernel I'm using etc, please explain how I can figure this out).

  2. Can someone explain how the makefile knows to call gcc and compile?

  3. Is there anything else I need to know to get this thing to compile?

-- Bonus question

  1. Anyone know any REALLY detailed tutorials about how to build a VFS, I have a project we were assigned that another school did, http://oslab.info/index.php/Labs/HW4, and based on the limited programming we've done before this, it is appearing to be a monumental task.
+1  A: 

Example 2.2 of your link has the following line instead of the one you listed:

INCLUDE := -isystem /lib/modules/`uname -r`/build/include

That looks like the probable cause of your compile issues. Any particular reason you changed it?

Karl Bielefeldt
Guess I read this line: You must use the kernel headers of the kernel you're compiling against. Using the default /usr/include/linux won't work. and thought it meant I needed to go find the headers mentioned in my makefile, I put those back in and get the same errors
onaclov2000
A: 

Looking at a couple of source trees (2.6.32 is the oldest I have on hand) there are no instances of processor.h which are in a generic directory, all are architecture specific. For example

/usr/src/linux-headers-2.6.32-24/arch/x86/include/asm/processor.h

So I'm guessing you are missing an include directory in your Makefile.

msw
+2  A: 

With 2.6 kernel, you should use the kernel build system. Here is an example for a module built outside of the kernel tree :

ifneq ($(KERNELRELEASE),)
# We were called by kbuild

obj-m += target.o

else  # We were called from command line

KDIR := /lib/modules/$(shell uname -r)/build
#KDIR := /home/cynove/src/kernel/linux-source-2.6.31
PWD  := $(shell pwd)

default:
    @echo '    Building target module 2.6 kernel.'
    @echo '    PLEASE IGNORE THE "Overriding SUBDIRS" WARNING'
    $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules

install:
    ./do_install.sh *.ko

endif  # End kbuild check
######################### Version independent targets ##########################

clean:
    rm -f -r *.o *.ko .*cmd .tmp* core *.i

By calling make -C ($KDIR) etc..., the kernel build system gets involved, and does the job for you.

shodanex