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? |
I think you will have to use some thing like this
Code:
|
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? |
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. |
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:
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. |