My last kernel development was in version 2.6~ Now I try to compile a module, and I get the following error when compiling outside the kernel tree.
/bin/sh: 1: /home/blabla/workspace/kernel35/linux-3.5/scripts/recordmcount: not found
The object file is created properly, however the problem is within the kernel Makefile itself, something has changed and I wasn't updated ?
I'm using vanilla kernel sources from kernel.org, and I already did
make oldconfig && make prepare
I posted the Makefile that I'm using, it's a standard makefile for kernel modules
# Comment/uncomment the following line to disable/enable debugging
#DEBUG = y
# Add your debugging flag (or not) to CFLAGS
ifeq ($(DEBUG),y)
DEBFLAGS = -O -g -DBLABLA_DEBUG # "-O" is needed to expand inlines
else
DEBFLAGS = -O2
endif
ccflags-y += $(DEBFLAGS)
ccflags-y += -I..
ifneq ($(KERNELRELEASE),)
# call from kernel build system
obj-m := blabla.o
else
KERNELDIR ?= /home/blabla/workspace/kernel35/linux-3.5
PWD := $(shell pwd)
default:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
endif
clean:
rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions
depend .depend dep:
$(CC) $(CFLAGS) -M *.c > .depend
ifeq (.depend,$(wildcard .depend))
include .depend
endif
A Kbuild file contains one or more directives for compiling a kernel module. The easiest example of such a directive is obj-m = module.o. Following this directive, a kernel module ( ko - kernel object) will be created, starting from the module.o file. module.o will be created starting from module.c or module.S.
And the example of a Kbuild file used to compile a module: As you can see, calling make on the Makefile file in the example shown will result in the make invocation in the kernel source directory ( /lib/modules/`uname -r`/build) and referring to the current directory ( M = `pwd` ).
We often upgrade our kernel, and some precompiled drivers won’t work with Linux. Especially if you have weird hardware, then the vendor may send you driver code, aka C files, to compile. Or even you can write your own Linux kernel driver. Compiling kernel drivers is easy. The kernel makes it even much more straightforward.
A kernel module (or loadable kernel mode) is an object file that contains code that can extend the kernel functionality at runtime (it is loaded as needed); When a kernel module is no longer needed, it can be unloaded. Most of the device drivers are used in the form of kernel modules.
OK, I figured out how to solve this. apparently, this is the first time I'm trying to compile a module without compiling the kernel beforehand. to solve the issue I run the following command from the kernel source tree.
make modules_prepare
this creates all the necessary infrastructure to support modules building.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With