mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-23 18:25:57 +01:00
32 lines
817 B
Markdown
32 lines
817 B
Markdown
# Build
|
|
|
|
The module building system.
|
|
|
|
Explained at: <https://www.kernel.org/doc/Documentation/kbuild/modules.txt>
|
|
|
|
Full method: get the kernel, build it to a directory `$KDIR`, and then run:
|
|
|
|
make -C "$KDIR" M="$(PWD)" modules
|
|
|
|
Quick method: no need for a full build, just:
|
|
|
|
make modules_prepare
|
|
|
|
but you lose some functionality. TODO: module insert on host then fails with:
|
|
|
|
insmod: ERROR: could not insert module hello.ko: Invalid module format
|
|
|
|
even though kernel tree was checked out to match the host.
|
|
|
|
Using your distro's kernel version:
|
|
|
|
/lib/modules/$(uname -r)/build
|
|
|
|
## includes
|
|
|
|
Header files come from the same directory as the makefile: `/lib/modules/$(uname -r)/build`.
|
|
|
|
TODO how is that different from: `/usr/src/linux-headers-$(uname -r)/` ?
|
|
|
|
Those come directly from the kernel source tree.
|