LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Kernel (https://www.linuxquestions.org/questions/linux-kernel-70/)
-   -   kernel module compilation issue (https://www.linuxquestions.org/questions/linux-kernel-70/kernel-module-compilation-issue-818608/)

daff_vadi 07-07-2010 10:17 PM

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?

bsat 07-08-2010 12:59 AM

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


daff_vadi 07-08-2010 11:30 PM

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?

daff_vadi 07-13-2010 11:17 PM

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.

bsat 07-15-2010 05:52 AM

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


All times are GMT -5. The time now is 07:13 AM.