Build Error

I am facing a problem while building the device driver code.

I am using suse linux "2.6.31.5-0.1-desktop" on my Laptop.
I have copied a folder containing self written device driver files from Mandriva linux to my system having Suse Linux.
I copied the entire folder in "/home/netuser/sun/". This folder was building properly in Mandriva.

Now when I give a make command it fails as:
linux-8qbp:/home/netuser/Rupesh_KP/Emertxe/CourseTemplates/CharDriver # make
make: *** No targets. Stop.

Will you pls through some light as to what might be the issue and how to resolve it?

Something seems to be wrong with the makefile for it to find no targets at all. Could you post it?

Thanks Corona for the reply.
Actually I have in a folder "\CourseTemplates\CharDriver" in which I have made a simple kernel module file having a null char driver.
To build this folder "CourseTemplates" has three files, while subfolder "\CourseTemplates\CharDriver" has an empty makefile.

The three files of Folder "CourseTemplates" are:
1) Makefile

	DIRS := $(filter-out Makefile README module.mk, $(wildcard *))
		DIRS_CLEAN := $(DIRS:=_clean)

		.PHONY: all ${DIRS} clean

		all: ${DIRS}

		${DIRS}:
			@echo -n "Building $@ ... "
			@${MAKE} -C $@ KERNEL_SOURCE=/home/netuser/RKP/linux-source/linux-2.6.27.14/linux-2.6.27.14-1mnb/ > /dev/null
			@echo "done"

		clean: ${DIRS_CLEAN}

		%_clean:
			@echo -n "Cleaning $* ... "
			@${MAKE} -C $* KERNEL_SOURCE=/home/netuser/RKP/linux-source/linux-2.6.27.14/linux-2.6.27.14-1mnb/ clean > /dev/null
			@echo "done"

2) Makefile.mixed

		UNAME := $(shell uname -r)
		KERNEL26 := 2.6
		KERNELVERSION := $(findstring $(KERNEL26),$(UNAME))

		ifeq ($(KERNELVERSION),2.6)

		obj-m   := hello10.o

		INCLUDE := -I/usr/include/asm/mach-default/
		KDIR    := /lib/modules/$(shell uname -r)/build
		PWD     := $(shell pwd)

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

		else

		TARGET  := skeleton
		INCLUDE := -I/lib/modules/`uname -r`/build/include -I/usr/include/asm/mach-default/
		CFLAGS  := -O2 -Wall -DMODULE -D__KERNEL__ -DLINUX
		CC      := gcc

		all:: ${TARGET}.o

		${TARGET}.o: ${TARGET}.c
			$(CC) $(CFLAGS) ${INCLUDE} -c ${TARGET}.c

		endif

3) module.mk

		# if KERNELRELEASE is defined, we've been invoked from the
		# kernel build system and can use its language.
		ifneq ($(KERNELRELEASE),)
			src-m := $(wildcard ${SUBDIRS}/*.c)
			src-mod := $(wildcard ${SUBDIRS}/*.mod.c)
			src-m := $(notdir ${src-m})
			src-mod := $(notdir ${src-mod})
			src-m := $(filter-out ${src-mod}, ${src-m})
			obj-m := $(src-m:.c=.o)
		# Otherwise we were called directly from the command
		# line; invoke the kernel build system.
		else
			KERNEL_SOURCE := /home/netuser/RKP/linux-source/linux-2.6.27.14/linux-2.6.27.14-1mnb/
			PWD := $(shell pwd)
		default:
			$(MAKE) -C $(KERNEL_SOURCE) SUBDIRS=$(PWD) modules

		clean:
			$(MAKE) -C $(KERNEL_SOURCE) SUBDIRS=$(PWD) clean
		endif

---------- Post updated at 01:03 AM ---------- Previous update was at 01:00 AM ----------

I have suse linux "linux-2.6.31.5-0.1" on my PC.

Now I have created a new makefile in CharDriver folder with below content:

# if KERNELRELEASE is defined, we've been invoked from the
# kernel build system and can use its language.
ifneq ($(KERNELRELEASE),)
src-m := $(wildcard ${SUBDIRS}/*.c)
src-mod := $(wildcard ${SUBDIRS}/*.mod.c)
src-m := $(notdir ${src-m})
src-mod := $(notdir ${src-mod})
src-m := $(filter-out ${src-mod}, ${src-m})
obj-m := $(src-m:.c=.o)
# Otherwise we were called directly from the command
# line; invoke the kernel build system.
else
KERNEL_SOURCE := /home/netuser/RKP/linux-source/linux-2.6.27.14/linux-2.6.27.14-1mnb/
PWD := $(shell pwd)
default:
$(MAKE) -C $(KERNEL_SOURCE) SUBDIRS=$(PWD) modules

clean:
$(MAKE) -C $(KERNEL_SOURCE) SUBDIRS=$(PWD) clean
endif

Now it gives me the following build error:

linux-8qbp:/home/netuser/RKP/CourseTemplates/CharDriver # make
make -C /home/netuser/RKP/linux-source/linux-2.6.27.14/linux-2.6.27.14-1mnb/ SUBDIRS=/home/netuser/RKP/CourseTemplates/CharDriver modules
make[1]: Entering directory `/home/netuser/RKP/linux-source/linux-2.6.27.14/linux-2.6.27.14-1mnb'

WARNING: Symbol version dump /home/netuser/RKP/linux-source/linux-2.6.27.14/linux-2.6.27.14-1mnb/Module.symvers
is missing; modules will have no dependencies and modversions.

CC [M] /home/netuser/RKP/CourseTemplates/CharDriver/char_driver.o
/home/netuser/RKP/CourseTemplates/CharDriver/char_driver.c:1: error: code model �kernel� not supported in the 32 bit mode
/home/netuser/RKP/CourseTemplates/CharDriver/char_driver.c:1: sorry, unimplemented: 64-bit mode not compiled in
make[2]: *** [/home/netuser/RKP/CourseTemplates/CharDriver/char_driver.o] Error 1
make[1]: *** [_module_/home/netuser/RKP/CourseTemplates/CharDriver] Error 2
make[1]: Leaving directory `/home/netuser/RKP/linux-source/linux-2.6.27.14/linux-2.6.27.14-1mnb'
make: *** [default] Error

Will you pls through some light as to what might be the issue and how to resolve it.

Could you please ensure that the kernel versions are compatible?

From the error messages it seems to be a compilation targeted for 64-bit system whereas you new host is 32-bit installation.

Also do a touch recursively to all the files to update the timestamp of all the files in your sandbox to ensure that make utility finds everything on your new host for compilation; the error-2 unimplemented: 64-bit mode not compiled in ... and the initial ones make: *** No targets. Stop.
.. of the error which went off automatically for you and you could atleast run the compilation (posted in your last one ...) gives me an impression of the mismatch time/date set in both of your machine there by Make not finding objects to compile.

Run (from the top directory of your sandbox):

find . -type f -exec touch {} \;

Further ensure that target is set for 32 bit compilation and kernel version mismatch is properly appended in your code.

If possible post your code here in the forum as a tar/zip attachment.

1 Like

Thanks Praveen for the reply.
I just changed the kernel source to an another and built it.
But now I am facing another problem.
I tried with a simple kernel module:

#include <linux/module.h>
#include <linux/version.h>
#include <linux/kernel.h>

/* Add your variables here */

static int __init mfd_init(void)
{
	printk(KERN_INFO "mfd registered");
	return 0;
}

static void __exit mfd_exit(void)
{
	printk(KERN_INFO "mfd deregistered");
}

module_init(mfd_init);
module_exit(mfd_exit);

MODULE_LICENSE("GPL");
MODULE_AUTHOR("RKP");
MODULE_DESCRIPTION("Test Driver");

I used the earlier makefile just changing the kernel source:

# if KERNELRELEASE is defined, we've been invoked from the
# kernel build system and can use its language.
ifneq ($(KERNELRELEASE),)
	src-m := $(wildcard ${SUBDIRS}/*.c)
	src-mod := $(wildcard ${SUBDIRS}/*.mod.c)
	src-m := $(notdir ${src-m})
	src-mod := $(notdir ${src-mod})
	src-m := $(filter-out ${src-mod}, ${src-m})
	obj-m := $(src-m:.c=.o)
# Otherwise we were called directly from the command
# line; invoke the kernel build system.
else
	KERNEL_SOURCE := /usr/src/linux-2.6.31.5-0.1/
	PWD := $(shell pwd)
default:
	$(MAKE) -C $(KERNEL_SOURCE) SUBDIRS=$(PWD) modules

clean:
	$(MAKE) -C $(KERNEL_SOURCE) SUBDIRS=$(PWD) clean
endif

The code got built.
But on loading the module it gives me an error:

insmod test_driver.ko 
insmod: error inserting 'test_driver.ko': -1 Invalid module format

Any idea how to get rid of this?