LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Kernel (https://www.linuxquestions.org/questions/linux-kernel-70/)
-   -   Compiling a module separately without compiling entire kernel (https://www.linuxquestions.org/questions/linux-kernel-70/compiling-a-module-separately-without-compiling-entire-kernel-660415/)

kushalkoolwal 08-04-2008 02:42 PM

Compiling a module separately without compiling entire kernel
 
I just compiled a 2.6.26 kernel and installed on my Debian etch system.

Now I just realized that I need one more module in the kernel. I can get the module by copying a file called testlpp.c in the usr/src/linux/drivers/char/ directory and then compiling it. The module is called LPPTEST. Basically there is the PREEMPT_RT patch that gives this module.


How can I just compile this module and install it without compiling the entire kernel? I have copied the file testlpp.c in the drivers/char/ directory.

Thanks

unSpawn 08-05-2008 08:14 AM

Tried 'make M=drivers/char/'?

kushalkoolwal 08-05-2008 02:31 PM

Quote:

Originally Posted by unSpawn (Post 3237363)
Tried 'make M=drivers/char/'?

I tried what you suggested and I got loads of errors..I was not able to caputre the first error because the screen scrolled too fast and since there were so many errors the first error is not in the terminal's memory anymore i.e. even if I scroll up I cannot see the first error.

I have uploaded the file lpptest.c here.

Thanks.

jiml8 08-05-2008 02:39 PM

Put your driver source in a separate directory, including any .h files that go with it (usually you won't get away with just a .c file) and make it with this makefile (which you can copy into a file named Makefile).

Code:

obj-m := lpptest.o
KDIR    := /lib/modules/$(shell uname -r)/build
PWD    := $(shell pwd)

default:
        $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules

This is the standard makefile structure for kernel modules.

After making it, just copy it into the directory you want it in, then you can insert it into the kernel.

kushalkoolwal 08-05-2008 02:53 PM

Quote:

Originally Posted by jiml8 (Post 3237776)
Put your driver source in a separate directory, including any .h files that go with it (usually you won't get away with just a .c file) and make it with this makefile (which you can copy into a file named Makefile).

Code:

obj-m := lpptest.o
KDIR    := /lib/modules/$(shell uname -r)/build
PWD    := $(shell pwd)

default:
        $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules

This is the standard makefile structure for kernel modules.

After making it, just copy it into the directory you want it in, then you can insert it into the kernel.


Thanks for your input. Does the line
Code:

KDIR    := /lib/modules/$(shell uname -r)/build
means that I need to have kernel headers also installed?

jiml8 08-05-2008 06:18 PM

Of course.

kushalkoolwal 08-05-2008 07:28 PM

Quote:

Originally Posted by jiml8 (Post 3238017)
Of course.

I think I am very close to compile the module successfully. I got a warning message:
Code:

debian:/usr/src/lpptest# make
make -C /lib/modules/2.6.26-1-486/build SUBDIRS=/usr/src/lpptest modules
make[1]: Entering directory `/usr/src/linux-headers-2.6.26-1-486'
  CC [M]  /usr/src/lpptest/lpptest.o
  Building modules, stage 2.
  MODPOST 1 modules
WARNING: "irq_desc" [/usr/src/lpptest/lpptest.ko] undefined!
  LD [M]  /usr/src/lpptest/lpptest.ko
make[1]: Leaving directory `/usr/src/linux-headers-2.6.26-1-486'
debian:/usr/src/lpptest#

I check for the "irq_desc" in the include files and it seems that #include <linux/irq.h> file has the definition of the structure irq_desc. Wonder why it is still saying that irq_desc is undefined.

I have uploaded the irq.h file here.

jiml8 08-06-2008 01:29 AM

Will the module load into the kernel? Try insmod.

kushalkoolwal 08-06-2008 01:45 AM

Quote:

Originally Posted by jiml8 (Post 3238313)
Will the module load into the kernel? Try insmod.

No, unfortunately, the module does not load because of that warning message.


All times are GMT -5. The time now is 01:57 AM.