Reputation: 43
I'm working on a project where we need to develop/change a linux driver, which interacts with other non-kernel code, so I would like to be able to compile the driver code in the same framework as the rest of the code (also keep it in the same repository, etc).
I can easily compile the driver once I have the kernel compiled (800 MB after cleaning unnecessary files), generating a .ko file that I can copy into my system and install it with insmod my_driver.ko
.
However, the kernel I use will never change, so every time I compile an update of my driver the make takes milliseconds, since after all the only thing it's doing is checking that kernel files remain unchanged, getting files/kernel information for driver compilation, and then it just compiles the driver (perhaps this assumption is wrong, but in any case I guess I can say with certainty that even if make was actually reading/using files, they are just a small bunch).
Therefore, I was wondering if there was a way to "cheat" the make tool (or create custom Makefile) to pretend to check kernel files and just hardcode the kernel information needed to compile the driver.
The idea is to put in my repository just the minimal amount of files to compile the driver without having to:
I know there is a way since all code can be replicated line by line. The question is, does anybody know a smart way to achieve this without debugging the whole make process line by line to generate a custom script/make?
PS: The hardware running the linux kernel and driver is not a PC, thus cross compiling.
The Makefile of my driver is very simple, the classic one make -C '$(LINUX_DIR)' M='$(SRC)' ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) modules
. This calls the Makefile in linux kernel directory which I've tried to manually change and try to no avail. Most errors I get when I remove some parts are related to directories/files not existing, configurations missing, etc. I cannot say I've tried extensively - kernel build Makefile is 1700 lines long and I'm no make
expert so I decided to ask here before wasting too much time.
I know that without asking specific code questions or make
lines, there's not much you can say, but I'm asking in rather general terms, if someone knows if this is possible, or about a project doing something similar, etc.
I've read several posts, like this one, but none address (that I've found) this "skip-kernel-files-check" part; instead they all just ask for compiling without the kernel. To clarify, here I'm asking how to, having the kernel, reduce the amount of kernel files (ideally to 0) or simply skip the kernel check and hardcode the kernel info (which I acknowledge is a must for driver compilation), so that I can regularly compile my driver/s in a file-wise clean, lightweight, relatively-portable fashion.
In some posts like here some answers mention to just have a copy of the "kernel headers and some basic build tools", but I couldn't find a lot of understandable literature on the topic. If anyone could confirm this is possible or point me towards some documentation I'd appreciate it. From this other post I tried:
/usr/bin/arm-linux-gnueabi-gcc -DMODULE -D__KERNEL__ -isystem ../linux-build/build/include -c my_driver.c -o my_driver.ko
But, like other users commenting in the post, I get the error fatal error: asm/linkage.h: No such file or directory
. Besides, I'm not sure if the gcc command is cross-compiling or if that's implicit when using the ARM gcc compiled and passing the linux kernel includes. By the way, ../linux-build/build
is where the compiled kernel files are, and its parent contains other compiled things (e.g. dgb, nano, my_driver).
Upvotes: 1
Views: 1658
Reputation: 2304
You need to use the headers_install
make target. This will generate and install the headers you need to be able to compile modules for your kernel in the specified location. The default is to install in ./usr
, you can change that using the INSTALL_HDR_PATH
variable.
Full documentation is here: https://www.kernel.org/doc/Documentation/kbuild/headers_install.txt
Upvotes: 0