LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices



Reply
 
Search this Thread
Old 07-07-2010, 11:17 PM   #1
daff_vadi
LQ Newbie
 
Registered: Jul 2010
Posts: 5

Rep: Reputation: 0
kernel module compilation issue


I want to compile a kernel module containing subdirectories. I want my Makefile to recursively enter each subdirectory and then compile. I've written a Makefile in the root directory something like this.

===============================================================
KERNELDIR := /usr/src/linux-2.6.24/
ARCH := arm
CROSS := /opt/freescale/usr/local/gcc-4.1.2-glibc-2.5-nptl-3/arm-none-linux-gnueabi/bin/arm-none-linux-gnueabi-
PWD := $(shell pwd)
TOP := /home/user/src_v.1006
INCS:= -I$(TOP)/inc
EXTRA_CFLAGS:= $(INCS)

obj-m := FTL/ common/ BBM/ PAL/ PM/

all:modules

modules:
$(MAKE) ARCH=arm CROSS_COMPILE=$(CROSS) $(EXTRA_CFLAGS) -C $(KERNELDIR) SUBDIRS=$(shell pwd) modules

clean:
for n in $(obj-y); do $(MAKE) -C $$n clean; done;\
rm -f *~ *.o *.ko *.mod.c .*.cmd\
rm -f .depend .version .*.o.flags .*.o.d\
rm -rf .tmp_versions

====================================================================
Each subdirectory has a Makefile of its own. The contents of which are like the following

EXTRA_CFLAGS += -I/home/user/src_v.1006/inc -Wno-undef -Wno-unused-function

obj-m += bbm_module.o
bbm_module-objs := bbm.o bbm_basic.o

clean:
rm -f *~ *.o *.ko *.mod.c .*.cmd
rm -f .depend .version .*.o.flags .*.o.d
rm -rf .tmp_versions

Here each subdirectory contains *.ko(eg. bbm_module.ko) file. How to make a final .ko file linking all the *.ko files from their respective subdirectories?
 
Old 07-08-2010, 01:59 AM   #2
bsat
Member
 
Registered: Feb 2009
Posts: 347

Rep: Reputation: 72
I think you will have to use some thing like this

Code:
 

final-objs :=  FTL/ftl_module.o common/common_module.o BBM/bbm_module.o PAL/pal_module.o PM/pm_module.o
obj-m := final.o
 
Old 07-09-2010, 12:30 AM   #3
daff_vadi
LQ Newbie
 
Registered: Jul 2010
Posts: 5

Original Poster
Rep: Reputation: 0
Thank u for ur help.
i've tried using the following as suggested by u in the main Makefile.
=======================================
obj-y := FTL/ common/ BBM/ PAL/ PM/

final-objs := FTL/ftl_module.o common/common_module.o BBM/bbm_module.o PAL/pal_module.o PM/pm_module.o
obj-y += final.o

all:modules

modules:
$(MAKE) ARCH=arm CROSS_COMPILE=$(CROSS) $(EXTRA_CFLAGS) -C $(KERNELDIR) M=$(shell pwd) modules
===========================================
But still it does not create final.ko file. Should i add a rule with Linker command using LD to link the individual *.ko files?
 
Old 07-14-2010, 12:17 AM   #4
daff_vadi
LQ Newbie
 
Registered: Jul 2010
Posts: 5

Original Poster
Rep: Reputation: 0
I've modified the makefiles as following.
The following is the content of the main Makefile, where FTL, common, etc. are subdirectories.
=====================================================
obj-y += FTL/
obj-y += common/
obj-y += BBM/
obj-y += PAL/
obj-y += PM/
obj-y += final.o
final-objs := FTL/ftl_module.o common/common_module.o BBM/bbm_module.o PAL/pal_module.o PM/pm_module.o

all:modules

modules:
$(MAKE) ARCH=arm CROSS_COMPILE=$(CROSS) $(EXTRA_CFLAGS) -C $(KERNELDIR) M=$(shell pwd) modules
================================================================================================
Each subdirectory has a Makefile of its own. The contents of which are like the following

EXTRA_CFLAGS += -I/home/user/src_v.1006/inc -Wno-undef -Wno-unused-function

obj-m += bbm_module.o
bbm_module-objs := bbm.o bbm_basic.o

============================================
1) In the main Makefile if i say "obj-m" instead of "obj-y" i'm unable to build. why am i not able to build with "obj-m" option.
With obj-y i can build the sub folders target files (eg.bbm_module.ko) but cannot build the final.ko file linking all the subfolders *.ko files.

2) Now without cleaning using "make clean" if i change the following line from "obj-y" to "obj-m" in the main Makefile,
obj-m += final.o
final-objs := FTL/ftl_module.o common/common_module.o BBM/bbm_module.o PAL/pal_module.o PM/pm_module.o

i'm able to build final.ko file. Can i make final.ko in one go? Please help.
 
Old 07-15-2010, 06:52 AM   #5
bsat
Member
 
Registered: Feb 2009
Posts: 347

Rep: Reputation: 72
well one of the work around for your problem that I can think of is create your final module stright out of the source files instead of the intermediate .ko files. ie

Code:
obj-m := final.o
final-objs := BBM/bbm.o BBM/bbm_basic.o etc.
Now I can not gurantee that the above is going to work, it might.

To learn more about the makefiles and the obj-y and obj-m you can refer to
linuux/Documentation/kbuild/makefile.txt
linuux/Documentation/kbuild/modules.txt
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Kernel compilation ignores necessary module maxkukartsev Debian 4 10-31-2009 05:13 PM
Kernel module compilation problem marcintom Programming 0 01-28-2009 07:50 PM
module compilation in kernel hovnatan Ubuntu 0 02-10-2007 05:33 AM
kernel module compilation zbrox Linux - Software 1 01-28-2004 04:31 PM
Kernel compilation, what module did I missed ? Kocil Linux - Software 7 08-10-2003 07:03 AM


All times are GMT -5. The time now is 07:37 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration