I am currently building an Embedded Linux for my Zybo Board from Xilinx. For this I use Buildroot. Now I want to add a driver, written in C, which can be used by a user program to write to some specific registers, enabling it to control some LEDs. When I checked the manual, it basically says the first thing to do is create a Config.in in a new package folder, where you write some text explaining the driver. Okay, I did that. But now the makefile: I don't quite understand what needs to be in there. Is it just a compile command like gcc -o ledcontrol hellofunc.c
? Is there something else I need to do apart from the Config.in and Makefile?
相关问题
- Multiple sockets for clients to connect to
- What is the best way to do a search in a large fil
- glDrawElements only draws half a quad
- Index of single bit in long integer (in C) [duplic
- Equivalent of std::pair in C
What you are looking for is the kernel-modules infrastructure.You can take a look at the Buildroot manual here:
https://buildroot.org/downloads/manual/manual.html#_infrastructure_for_packages_building_kernel_modules
Or at the numerous examples using the kernel-modules infrastructure provided by Buildroot that assists in kernel modules addition to Buildroot:
Yeah, I guess I could write a longish reply, but I would be just copying the Buildroot manual. So let's honor the braves developers that have written such clean documentation and such clean code (Buildroot core is really clean, and each package is extensively reviewed so they are usually very well written too).
Fully automated out-of-tree QEMU example
https://github.com/cirosantilli/linux-kernel-module-cheat/tree/753cbe68ff50bea0982e1791c8a2178a999d8377/buildroot_packages/kernel_modules
Source tree:
buildroot/
: Buildroot 2017.02 submodulekernel_module/
: external package with some modulesConfig.in
external.mk
Makefile
hello.c
: hello world modulekernel_module/Config.in:
kernel_module/external.mk:
kernel_module/Makefile:
kernel_module/hello.c:
Usage:
QEMU opens up, then run:
dmesg
shows:The key line is
$(eval $(kernel-module))
inexternal.mk
, which sets everything up for us, and installs the modules wheremodprobe
will find them (/lib/modules/*/extra/hello.ko
), includingmodules.dep
for inter-module dependencies: How to call exported kernel module functions from another module?How to GDB step debug the kernel modules: How to debug Linux kernel modules with QEMU?
To autoload modules at startup, use
BR2_ROOTFS_OVERLAY="../rootfs_overlay"
and arootfs_overlay/etc/init.d/S99modules
file that does themodprobe
.In-tree example: https://github.com/cirosantilli/buildroot/tree/9580078b98f885ca94e4dfc896265a8a491f6ae1 It is less clean, but also works.
Tested on a Ubuntu 16.04 host.