I have an ARM Linux device, but I don't have the Makefile
of the kernel to build a kernel module.
I have GCC cross compiler to this arch.
How can I compile a kernel module without the Makefile
of the kernel?
How can I compile kernel module without have the Makefile of the kernel?
You can't. You need the kernel Makefile
in order to compile a module, along with a pre-built kernel source tree. On most distributions, you can obtain the kernel source for building modules through packages like linux-headers-xxx
where xxx
should be the output of uname -r
.
For example, on Debian or Ubuntu:
sudo apt-get install linux-headers-$(uanme -r)
You will then find the files needed for building modules at /lib/modules/$(uname -r)/build
, and you can build a module with a Makefile
like this:
KDIR := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
obj-m := mymodule.o # same name as the .c file of your module
default:
$(MAKE) -C $(KDIR) M=$(PWD) modules
What this does is basically invoking the kernel Makefile
telling it to build the module in the current directory.
Also, I am not sure why you say that you are on an ARM Linux device, and you have a cross compiler. If you are on the device itself, you shouldn't need a cross compiler at all. If you are on a different device, then you'll need to use the appropriate uname -r
for the target device in order to get the right sources and in order to build. You might need to do this by hand since the output of uname -r
isn't always helpful.
You'll also need to secify the architecture and cross compilation toolchain prefix in the module Makefile
, for example:
default:
$(MAKE) -C $(KDIR) M=$(PWD) ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- modules