-
Notifications
You must be signed in to change notification settings - Fork 106
Home
There is a kernel-headers Raspbian package now: https://www.raspberrypi.org/documentation/linux/kernel/headers.md
rpi-source is helpful if you use rpi-update kernels or want to build an in-kernel module.
rpi-source installs the kernel source used to build rpi-update kernels and the kernel on the Raspian image.
This makes it possible to build loadable kernel modules.
It is not possible to build modules that depend on missing parts that need to be built into the kernel proper (bool in Kconfig).
The script uses sudo internally when self-updating and when making the links /lib/modules/$(uname -r)/{build,source}
Examples on how to build various modules
Dependencies
sudo apt-get install git bc bison flex libssl-dev
Install
sudo wget https://raw.githubusercontent.com/notro/rpi-source/master/rpi-source -O /usr/bin/rpi-source && sudo chmod +x /usr/bin/rpi-source && /usr/bin/rpi-source -q --tag-update
Run
rpi-source
This library is needed when running 'make menuconfig'
*** ncurses-devel is NOT installed. Needed by 'make menuconfig'. On Debian: apt-get install ncurses-dev
Install prerequisites
$ sudo apt-get install libncurses5-dev
Always run 'make prepare' after changing the kernel config
Show kernel config diff between current and previous config
$ scripts/diffconfig
ENC28J60 n -> m
+ENC28J60_WRITEVERIFY n
Show config diff against the running kernel
$ cd linux
$ zcat /proc/config.gz > .config.running
$ scripts/diffconfig .config.running .config
Module.symvers contains all the symbols the kernel and modules has exported, and was made during the kernel build process. This file is used later to find needed symbols when building modules. If it was missing (or empty) during building of a module, you might get a not very helpful error message when loading the module. But dmesg will help:
$ sudo modprobe elo
ERROR: could not insert 'elo': Exec format error
$ dmesg |tail -n 1
[19988.002342] elo: no symbol version for module_layout
But if we build a module that exports a symbol, and another module we build needs that symbol, we get warnings.
The build system can't find that symbol in ~/linux/Module.symvers.
We need to tell the build system where this symbol is. This can be done with KBUILD_EXTRA_SYMBOLS pointing to the needed Module.symvers in the build directory of the exporting module.
See mcp2515a for an example.
I had a situation after building several modules that loading the module failed with some format error. It turned out that ~/linux/Module.symvers had changed somehow.
If that happens, there is a backup file Module.symvers.backup. The timestamps will differ if it has changed.
The kernel can be tainted in various ways. One of them is loading an out-of-tree module.
$ cat /proc/sys/kernel/tainted
4096
From https://www.kernel.org/doc/Documentation/sysctl/kernel.txt
4096 - An out-of-tree module has been loaded.
Tag: raspberry pi
Tag: rpi