6

I need to compile this driver, however I'm missing my kernel headers. I've tried installing them the normal way:

sudo apt-get install linux-headers-generic

Package 'linux-headers-generic' has no instalation candidate

And:

sudo apt-get install linux-headers-$(uname -r)

E: Unable to locate package linux-headers-4.1.18-v7

Neither worked, I've search the apt database for "linux-headers":

apt-cache search linux-headers

linux-headers-3.10-3-all - All header files for Linux 3.10 (meta-package)
linux-headers-3.10-3-all-armhf - All header files for Linux 3.10 (meta-package)
linux-headers-3.10-3-common - Common header files for Linux 3.10-3
linux-headers-3.10-3-rpi - Header files for Linux 3.10-3-rpi
linux-headers-3.12-1-all - All header files for Linux 3.12 (meta-package)
linux-headers-3.12-1-all-armhf - All header files for Linux 3.12 (meta-package)
linux-headers-3.12-1-common - Common header files for Linux 3.12-1
linux-headers-3.12-1-rpi - Header files for Linux 3.12-1-rpi
linux-headers-3.16.0-4-all - All header files for Linux 3.16 (meta-package)
linux-headers-3.16.0-4-all-armhf - All header files for Linux 3.16 (meta-package)
linux-headers-3.16.0-4-common - Common header files for Linux 3.16.0-4
linux-headers-3.16.0-4-rpi - Header files for Linux 3.16.0-4-rpi
linux-headers-3.18.0-trunk-all - All header files for Linux 3.18 (meta-package)
linux-headers-3.18.0-trunk-all-armhf - All header files for Linux 3.18 (meta-package)
linux-headers-3.18.0-trunk-common - Common header files for Linux 3.18.0-trunk
linux-headers-3.18.0-trunk-rpi - Header files for Linux 3.18.0-trunk-rpi
linux-headers-3.18.0-trunk-rpi2 - Header files for Linux 3.18.0-trunk-rpi2
linux-headers-3.6-trunk-all - All header files for Linux 3.6 (meta-package)
linux-headers-3.6-trunk-all-armhf - All header files for Linux 3.6 (meta-package)
linux-headers-3.6-trunk-common - Common header files for Linux 3.6-trunk
linux-headers-3.6-trunk-rpi - Header files for Linux 3.6-trunk-rpi
linux-headers-rpi - Header files for Linux rpi configuration (meta-package)
linux-headers-rpi-rpfv - This metapackage will pull in the headers for the raspbian kernel for the
linux-headers-rpi2-rpfv - This metapackage will pull in the headers for the raspbian kernel for the

How can I install the kernel headers for 4.1.18-v7+?

I'm using the latest version of Raspbian (headless) fully updated:

Linux localhost 4.1.18-v7+ #848 SMP Mon Feb 29 14:19:45 GMT 2016 armv7l GNU/Linux

Thank you.

MatsK
  • 2,478
  • 3
  • 12
  • 20
Fábio Antunes
  • 149
  • 2
  • 4
  • 14

4 Answers4

6

I also came across this problem and solved it by following the instructions for a similar question on this forum.

However I did need to make some changes. Specifically, I had to run the following commands:

cd /usr/src
git clone --depth 1 https://github.com/raspberrypi/linux.git
ln -s linux linux-4.1.18-v7+
ln -s /usr/src/linux /lib/modules/4.1.18-v7+/build
cd linux
wget https://raw.githubusercontent.com/raspberrypi/firmware/master/extra/Module.symvers
make menuconfig
make prepare
make modules_prepare

After that, I could compile my kernel module.

Notes I

  • I did this on Raspbian GNU/Linux 8, Linux raspberrypi 4.1.18-v7+ #846 SMP Thu Feb 25 14:22:53 GMT 2016 armv7l GNU/Linux on Raspberry Pi 3
  • If you need to make use of a specific version of the kernel, this would be of interest
Sandro Gauci
  • 176
  • 3
  • Interesting. I already have a folder `/usr/src/linux-headers-4.1.18-v7+` shouldn't these be the headers? – Fábio Antunes Mar 07 '16 at 15:08
  • 1
    yes that should do it. On mine I did not have the header files. Someone else seems to have prepared a deb file (for those in the same situation as myself) that also worked for me: https://www.niksula.hut.fi/~mhiienka/Rpi/linux-headers-rpi/ – Sandro Gauci Mar 08 '16 at 14:41
  • Yes, I've tried it, specifically this one `linux-headers-4.1.18-v7+_4.1.18-v7+-2_armhf.deb` however during `dpkg --install` it gets stuck extracting and that's the end of it. I will try it one more time, maybe clean up this Raspbian instance before. – Fábio Antunes Mar 09 '16 at 01:02
4

Run below command on the terminal to install

 sudo apt install raspberrypi-kernel-headers
2

linux-headers-rpi appears to be the meta-package which installs the latest kernel headers. This is what you should use on a fully upgraded system. You will need to manually rebuild your custom drivers after a kernel upgrade, but at least the kernel headers will be upgraded automatically.

Dmitry Grigoryev
  • 26,688
  • 4
  • 44
  • 133
2

There is a script maintained on Github which will download the matching kernel sources https://github.com/notro/rpi-source/wiki for the kernel in use.

The documentation says:

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}

Note: rpi-source is supported from Linux version 3.10.37 (when Module.symvers appeared in the repo)

nwaltham
  • 311
  • 1
  • 6