2

I am planning to do some Rasperry Pi C/C++ kernel module development using BuildRoot 2015.08.1.

What works:

  • I can build a kernel and a rootfs and boot the Raspberry Pi.
  • I can build/rebuild a "hello world" using the BuildRoot toolchain either as a generic-package or an autotools-package.

What does not work:

  • I cannot include some kernel headers, for instance linux/module.h. The toolchain does not find this header file.

I had a look at output/staging/usr/include. I can find some linux headers, for instance linux/net.h. However others are not there, for instance linux/module.h.

The header I am looking for is present in the kernel source tree. However it does not appear to be installed to staging. I am not 100% sure that BuildRoot called "make headers_install", but it seems like a reasonable assumption. Would anyone have any pointers to how "make headers_install" selects the headers to be installed? Or am I missing something else?

4
  • An userspace program doesn't need the kernel headers. They are reserved for kernel core/drivers. Commented Nov 24, 2015 at 9:34
  • @AlexandreBelloni: Fair comment. I am actually trying to develop a kernel module. I edited the question to mention this.
    – marcv81
    Commented Nov 24, 2015 at 12:49
  • @AlexandreBelloni actually that's not true, kernel utilities (e.g. dmraid) requires some aspects of the kernel headers (e.g. scsi/sg.h), as a matter of fact glibc does parse a host of kernel headers and deploys them as they provide the user-space kernel-space interconnect. Commented May 3, 2018 at 16:07
  • And they are shipped by the libc, as you state so they are part of the toolchain provided by buildroot. Commented May 4, 2018 at 14:15

2 Answers 2

1

I cannot include some kernel headers, for instance linux/module.h. The toolchain does not find this header file.

Kernel module : The 'make' command has "internals" to do that. Works (only) if you are using a special »Kernel module Makefile« → →

https://stackoverflow.com/questions/33589276/linux-kernel-module-compilation/33589361#33589361


3
  • you should give a little more details, your answer is berdering a link-only answer.
    – Archemar
    Commented Nov 24, 2015 at 14:05
  • It does solve my problem, thanks. Information about the internals would satisfy my curiosity and be very much appreciated.
    – marcv81
    Commented Nov 24, 2015 at 14:18
  • It may work but this is probably using the headers from your host, not your target. Commented Nov 25, 2015 at 10:16
0

Here is a fully automated out-of-tree setup for kernel modules: https://github.com/cirosantilli/linux-kernel-module-cheat/blob/b89ba9b799480e4eb1975f0a704409efb7d667d1/kernel_module/external.mk

I've described a minimal version of that at: https://stackoverflow.com/questions/40307328/how-to-add-a-linux-kernel-driver-module-as-a-buildroot-package/43874273#43874273

The package type $(eval $(kernel-module)) basically sets up everything for us.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .