My first question on StackExchange.
I have set up a Raspberry Pi 2 with the latest Raspbian (Buster Lite 2019-09-26 Kernel version: 4.19). I want to use a module that was not compiled into this image. Is it possible to compile only that module, using the tools and files available on the Pi itself?
The module I want is this one: https://github.com/raspberrypi/linux/blob/rpi-4.19.y/drivers/auxdisplay/ht16k33.c
It was not included when the image was compiled. The only drivers I have in this section are these:
ls /lib/modules/4.19.75-v7+/kernel/drivers/auxdisplay/
charlcd.ko hd44780.ko
I have searched for answers, and the only thing that came close was this: How compile a loadable kernel module without recompiling kernel
However it talks about making your own modules, not compiling an existing one. Other discussions talk about building the entire kernel.
Once I have the module I will load it using Device Tree (which I know how to do).
Edit:
Thanks to @ingo for the hint, but I haven't got it working yet. I found this article:
https://www.cyberciti.biz/tips/build-linux-kernel-module-against-installed-kernel-source-tree.html
I can successfully compile the module, but I get errors due to unknown symbols. My source file was the ht16k33.c code linked from GitHub above and placed in a subdirectory of user pi. The Makefile is as follows, copied from the article:
obj-m := ht16k33.o
KDIR := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
default:
$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
Running make is successful:
make -C /lib/modules/4.19.75-v7+/build SUBDIRS=/home/pi/projects/ht16k33 modules
make[1]: Entering directory '/usr/src/linux-headers-4.19.75-v7+'
CC [M] /home/pi/projects/ht16k33/ht16k33.o
Building modules, stage 2.
MODPOST 1 modules
CC /home/pi/projects/ht16k33/ht16k33.mod.o
LD [M] /home/pi/projects/ht16k33/ht16k33.ko
make[1]: Leaving directory '/usr/src/linux-headers-4.19.75-v7+'
When I try and load the module I get this error:
sudo insmod ht16k33.ko
insmod: ERROR: could not insert module ht16k33.ko: Unknown symbol in module
And the following reported in /var/log/messages:
Jan 7 17:20:23 soap kernel: [99203.981258] ht16k33: loading out-of-tree module taints kernel.
Jan 7 17:20:23 soap kernel: [99203.981943] ht16k33: Unknown symbol matrix_keypad_build_keymap (err -2)
Jan 7 17:20:23 soap kernel: [99203.982082] ht16k33: Unknown symbol fb_sys_write (err -2)
Jan 7 17:20:23 soap kernel: [99203.982142] ht16k33: Unknown symbol sys_imageblit (err -2)
Jan 7 17:20:23 soap kernel: [99203.982214] ht16k33: Unknown symbol sys_fillrect (err -2)
Jan 7 17:20:23 soap kernel: [99203.982300] ht16k33: Unknown symbol matrix_keypad_parse_properties (err -2)
Jan 7 17:20:23 soap kernel: [99203.982380] ht16k33: Unknown symbol sys_copyarea (err -2)
Jan 7 17:20:23 soap kernel: [99203.982460] ht16k33: Unknown symbol fb_sys_read (err -2)
Edit: Further reading and experimentation led me to this course of action:
- Copy the ht16k33.ko file produced to /lib/modules/4.19.75-v7+/extra
- sudo depmod
- modprobe ht16k33
tail /var/log/messages
Jan 7 19:30:51 soap kernel: [107031.622336] input: ht16k33-keypad as /devices/platform/soc/3f804000.i2c/i2c-1/1-0070/input/input0
I think I'm done. Thanks.
If I've done it wrong then I'd be happy to tidy up this explanation.
debian compile kernel module
and got 794.000 results. Just the first match seems already to be a good tutorial but also have a look at other links. – Ingo Jan 06 '20 at 21:51