LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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 09-06-2012, 02:59 PM   #1
paulcsf
LQ Newbie
 
Registered: Jan 2009
Distribution: Ubuntu / LFS/BLFS/CLFS
Posts: 20

Rep: Reputation: 1
Kernel module - C & assembly files - makefile problems


I am working on building a kernel module, architecture is Arm (armv7-m), tool chain is arm-uclinuxeabi-gcc and family.

I have a C file, sample.c that builds as a kernel module, loads, executes, all is fine.

I have an assembly file, mmcau.S, that builds independently.

However, when I try to include the assembly file in the kernel module build process, I can not get the make file to cooperate. I have read that there are implicit rules for .S -> .o, but I am left wondering if that is true.

To build sample.c by itself:
Code:
CFLAGS		:= -Os -mcpu=cortex-m4 -mthumb 
LDFLAGS		:= -mcpu=cortex-m4 -mthumb 
CC		= $(CROSS_COMPILE_APPS)gcc

obj-m		+= sample.o

KERNELDIR	:=  $(INSTALL_ROOT)/linux

modules		:
	make -C $(KERNELDIR) M=`pwd` modules CFLAGS="" LDFLAGS=""

clean_modules:
	make -C $(KERNELDIR) M=`pwd` clean
	rm -f modules.order
To build mmcau.S by itself:
Code:
AS		:= $(CROSS_COMPILE_APPS)gcc
#AS		:= $(CROSS_COMPILE_APPS)as
ASFLAGS		:= -x assembler-with-cpp -mcpu=cortex-m4 -mthumb

#Rule for assembling .s -> o files
$(SOBJ)		: %.o : %.S
		  @echo Assembling
		  $(AS) $(ASFLAGS) -c $< -o $@

mmcau		: mmcau.S
		  @echo Assembling mmcau.S
		  $(AS) $(ASFLAGS) -c $< 
# with the -o $@ creates an application
# w/o  the -o $@ creates a .o
However, when I add mmcau.o to obj-m for the kernel module,
Code:
obj-m		+= sample.o
obj-m		+= mmcau.o
I get an error like:
Code:
make[2]: *** No rule to make target `..../app/mmcau.c', needed by `.../app/mmcau.o'.  Stop.
I haven't been able to get past this error. Some variations of makefile cause an output module to be created, but loading it in the kernel causes a kernel taint error regarding the licensing, and the entire system crashes when the module is accessed.

Thanks, paulcsf
 
Old 09-06-2012, 11:23 PM   #2
paulcsf
LQ Newbie
 
Registered: Jan 2009
Distribution: Ubuntu / LFS/BLFS/CLFS
Posts: 20

Original Poster
Rep: Reputation: 1
I believe that the output kernel module name cannot match any of the source files.

There were two other error cases/clues that I found. Modinfo reports little information, only the filename and vermagic, no author, license, description, or parms. Another case would have the module load into the kernel, but would fail to do anything, no output, the device would exist but couldn't be opened, etc.

Here is the solution I came up with...

Code:
obj-m		+= KModule.o
KModule-objs	:= sample.o mmcau.o

KERNELDIR	:=  $(INSTALL_ROOT)/linux

modules		:
	make -C $(KERNELDIR) M=`pwd` modules CFLAGS="" LDFLAGS=""

clean_modules:
	make -C $(KERNELDIR) M=`pwd` clean
	rm -f modules.order
A note, I believe that adding to obj-m creates more kernel modules to build, it doesn't add source files and dependencies to the current build. So:
Code:
obj-m           += KMod1.o
obj-m           += KMod2.o
builds two kernel modules, KMod1 and KMod2. For KMod1 to have multiple sources, KMod1-objs := must be defined with multiple files, none of which are named KMod1.c or KMod1.S.

Can anybody confirm this? It does work.

Thanks, paulcsf
 
  


Reply



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
Makefile problems/Simple kernel module smoothdogg00 Linux - Kernel 1 10-28-2006 04:16 PM
need help in writing Makefile for module in 2.6 kernel videsh Programming 1 01-19-2006 07:35 AM
need help in writing Makefile for module in 2.6 kernel videsh Linux - Software 3 01-19-2006 07:30 AM
creating Makefile with multiple kernel module files b123coder Programming 0 12-26-2004 08:41 AM
module makefile for c++ in kernel 2.6 yuhuahe Linux - Software 0 04-14-2004 06:03 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 11:56 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
Open Source Consulting | Domain Registration