inserting kernel module in Linux-3.14 - linux-kernel

I am inserting kernel module insmod hello.ko, it gives:
insmod: can't insert 'hello.ko': kernel does not support requested operation.
I am using same uImage on target.
Module compilation was successful. Before make I have set
export ARCH=arm
export CROSS_COMPILE=arm-linux-gnueabihf-.,
export PATH=$PATH:/home/bsp/rskrza1_bsp-master/output/gcc-linaro-arm-linux-gnueabihf-4.8-2014.02_linux/bin/
Makefile is
obj-m := hello.o
KERNELDIR ?= /home/bsp/rskrza1_bsp-master/output/linux-3.14/
PWD := $(shell pwd)
all:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
clean:
rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions
Please let me know how can I solve it.
Thanks, Awadhesh

Related

How to compile kernel-module-imx-gpu-viv?

I am not able to compile the following kernel module https://github.com/Freescale/kernel-module-imx-gpu-viv/tree/upstream/6.2.4.p1.2/kernel-module-imx-gpu-viv-src for my IMX6Q board.
What i have done so far is :
Downloaded the sources from the git repo above in a separate directory
Modified the Makefile to set the correct path to the kernel sources KERNEL_SRC i am building (3.14.52) with :
Makefile :
obj-m := galcore.o
SRC := $(shell pwd)
KERNEL_SRC := /path/to/kernel_imx/
all:
$(MAKE) -C $(KERNEL_SRC) M=$(SRC)/kernel-module-imx-gpu-viv-src AQROOT=${PWD}/kernel-module-imx-gpu-viv-src
cp $(SRC)/kernel-module-imx-gpu-viv-src/Module.symvers $(PWD)
cp $(SRC)/kernel-module-imx-gpu-viv-src/modules.order $(PWD)
modules_install:
$(MAKE) -C $(KERNEL_SRC) M=$(SRC)/kernel-module-imx-gpu-viv-src modules_install
clean:
rm -f *.o *~ core .depend .*.cmd *.ko *.mod.c
rm -f Module.markers Module.symvers modules.order
rm -rf .tmp_versions Modules.symvers
compiled with : make ARCH=arm CROSS_COMPILE=/path/to/buildroot/buildroot/output/host/usr/bin/arm-linux-gnueabihf-
As a result of the compilation, i have no galcore.ko at all, only those 3 files generated :
built-in.o
modules.order ( empty )
Module.symvers ( empty )
I have tried also using buildroot but in the end, i have the same files in the directory output/build/kernel-module-imx-gpu-viv-9bbacfe7753626956a449c6a4f7dffcf6285b4d7
Thanks.
There is already a Buildroot package for this kernel driver: https://git.buildroot.org/buildroot/tree/package/freescale-imx/kernel-module-imx-gpu-viv
Finally i forgot to set MXC_GPU_VIV=m in the kernel configuration, that means to compile this driver as a module.
Now i have the expected galcore.ko correctly built.

how to add another include path in make

i want to use iostream or stdlib.h in my linux kernel driver and i have this MakeFile
ifeq ($(KERNELRELEASE),)
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
.PHONY: build clean
build:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
clean:
rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c
else
$(info Building with KERNELRELEASE = ${KERNELRELEASE})
obj-m := mydev.o
endif
when i use #include in my driver code, make returns this
mydev.c:10:20: fatal error: iostream: No such file or directory
#include <iostream>
what should i add to my makefile?
iostream is a C++ header. The Kernel is written in C

makefile error: doing first time kernel module

obj-m += hello.0
KDIR = /usr/src/linux-headers-3.16.0-34-generic
all :
$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
clean:
rm -rf *.o
error is: Makefile:9: *** missing separator. Stop.
You can use the below Makefile to build the kernel module. Comments inlined in the Makefile
There is an extra space before $(MAKE) in your makefile
obj-m = hello.o
KDIR = /usr/src/linux-headers-3.16.0-34-generic
# Here the commands to build the target should start in the next line with a tab space
all:
<TAB>make -C $(KDIR) M=$(PWD) modules
clean:
<TAB>make -C $(KDIR) M=$(PWD) clean

Proper makefile setup for external kernel modules

I'm writing a character driver to sit on top of a modified version of ahci in the source tree. I basically have something that looks like this:
topdir
|
|- Makfile
|
|- mod_ahci
| | - Makefile, codefiles
|
|- char_interface
| | - Makefile, codefiles
now, char_interface requires symbols from mod_ahci. I have the appropriate EXPORT_SYMBOL() macro use for the symbols I need to export. However, I'm having trouble getting the makefiles right to pick up the header file in mod_ahci from char_interface. My toplevel Makefile
ifneq ($(KERNELRELEASE),)
obj-y := mod_ahci/ char_interface/
else
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
default:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
modules_install:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules_install
endif
The makefile for char_interface (because the other builds just fine)
ifneq ($(KERNELRELEASE),)
ccflags-y += -I../mod_ahci
obj-m := char_interface.o
else
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
default:
$(MAKE) -C $(KERNELDIR) M=$(shell pwd) modules
modules_install:
$(MAKE) -C $(KERNELDIR) M=$(shell pwd) modules_install
endif
clean:
-sudo rmmod ahcip
-rm -f *.ko* *.mod.* *.o modules.order Modules.symvers
I have referenced various text files in the kernel documentation. For example, I'm referring to .../Documentation/kbuild/makefiles.txt right now as well as .../Documentation/kbuild/modules.txt. Whenever I build, I'm getting /home/captaink/devel/kmodtests/char_interface/char_interface.c:2:22: error: mod_ahci.h: No such file or directory. There is a file named mod_ahci.h in the directory ../mod_ahci. What am I getting wrong with my use of ccflags-y in the makefile for the char driver?
Thanks
After some digging, I found the answer to the problem. I was misunderstanding what was happening with the makefile's that I was viewing from LDD3 and the kernel documentation (which is, apparently, exactly where O'Reilly took their examples). The build system actually changes directories into /usr/src/kernels/$(uname -r)/build (or similar) because this is why my header file wasn't being found by the compiler.
I'm not saying this is an elegant way of doing this, but here's how I fixed it. The makefile in the top directory now looks like:
ifneq ($(KERNELRELEASE),)
obj-y := mod_ahci/ char_interface/
else
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
default:
$(MAKE) -C $(KERNELDIR) M=$(PWD) TOP_DIR=$(PWD) modules
modules_install:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules_install
endif
And the makefile in the subdirectory containing the char driver interface looks like:
ifneq ($(KERNELRELEASE),)
ccflags-y += -I$(TOP_DIR)/mod_ahci
obj-m := char_interface.o
else
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
default:
$(MAKE) -C $(KERNELDIR) M=$(shell pwd) modules
modules_install:
$(MAKE) -C $(KERNELDIR) M=$(shell pwd) modules_install
endif
clean:
-sudo rmmod ahcip
-rm -f *.ko* *.mod.* *.o modules.order Modules.symvers
As you can tell, the makefiles have been copied extensively. The subdirectories probably don't need the "shared" makefile stuff in them because that's taken care of by the higher level makefile. Nevertheless, the modules now build and the character driver I have knows of the exported symbols I made in my modified ahci driver.
I hope this may help someone who's a neophyte, like myself, to the Linux kernel build world and Linux kernel drivers.

How to install or copy the driver i.e .ko file to a particular location via makefile?

This is my makefile:
ifneq ($(KERNELRELEASE),)
obj-m := dmcdus_dd.o
else
KDIR := /usr/src/linux-headers-3.13.0-24-generic/
all:
$(MAKE) INSTALL_MOD_DIR=kernel/drivers/input/touchscreen -C $(KDIR) M=$$PWD modules_install
endif
clean:
rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions sample Module.symvers
I have specified my required path where i have to move my dmcdus_dd.ko file using INSTALL_MOD_DIR & install it by modules_install. When i type "make" in the console i get the following results in the console:
make INSTALL_MOD_DIR=kernel/drivers/input/touchscreen -C /usr/src/linux-headers-3.5.0-49-generic/ M=$PWD modules_install
make[1]: Entering directory `/usr/src/linux-headers-3.5.0-49-generic'
DEPMOD 3.5.0-49-generic
make[1]: Leaving directory `/usr/src/linux-headers-3.5.0-49-generic'
But when i go to the location "/lib/modules/3.5.0-49-generic/kernel/drivers/input/touchscreen" i dont see dmcdus.ko file in that directory... How can i copy my driver to that location?
Before installing first you need to make module using make -C $(KDIR) M=$(PWD) modules.
If you want to make little change in your makefile then write in following way:
ifneq ($(KERNELRELEASE),)
obj-m := dmcdus_dd.o
else
KDIR := /usr/src/linux-headers-3.13.0-24-generic/
all:
make -C $(KDIR) M=$(PWD) modules #I've changed makefile here
$(MAKE) INSTALL_MOD_DIR=kernel/drivers/input/touchscreen -C $(KDIR) M=$$PWD modules_install
endif
clean:
rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions sample Module.symvers
And make sure that you have permission to copy file to destination (/input/touchscreen)folder. If not then change it.
The below makefile is sufficient for you to build and install module
obj-m := dmcdus_dd.o
KDIR := /usr/src/linux-headers-3.13.0-24-generic/
all:
make -C $(KDIR) M=$$PWD modules
make -C $(KDIR) M=$$PWD modules_install
clean:
make -C $(KDIR) M=$$PWD clean
If you specify INSTALL_MOD_DIR then the modules is moved to that directory
make INSTALL_MOD_DIR=kernel/drivers/input/touchscreen -C $(KDIR) M=$$PWD modules_install

Resources