My Raspberry Pi currently runs 3.6.11+ #538 (obtained from uname -a
), which may be the source of my issues. I'm starting to write a kernel module using the following "Hello World" code:
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/module.h>
static int __init gotemp_init(void)
{
printk(KERN_INFO "Hello from the kernel!\n");
return 0;
}
static void __exit gotemp_exit(void)
{
}
module_init(gotemp_init);
module_exit(gotemp_exit);
MODULE_AUTHOR("My name here");
MODULE_DESCRIPTION("Simple driver");
MODULE_LICENSE("GPL");
And a make file:
obj-m := hello.o
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
all:
$(MAKE) -C $(KERNELDIR) M=$(PWD)
clean:
rm -f *.o *~ core .depend .*.cmd *.ko *.mod.c
I ran into an issue that 3.6.11+'s Linux headers were not released nor installable via apt-get, but I did find with Google that there were .deb files with the needed headers found here. Kernel modules obviously cannot be compiled without the kernel headers, so this seems to have been a fix.
Until I run:
insmod ./hello.ko
which spits out a segmentation fault. I read that is can be due to a mismatch of the running kernel and the kenel compiled against, but as far as I know, the two match up. Is there something I am missing?
I attempted to download the latest kernel from github.com/raspberrypi/linux
and build from that. The kernel version I got from git fetch [email protected]:raspberrypi/linux rpi-3.6.y:refs/remotes/origin/rpi-3.6.y
ended up being 3.6.11 #1. I attempted to compile and run with the new kernel and ended up with:
Error: could not insert module hello.ko: Invalid module format.
I know I want to run with 3.6 and not 3.4, because according to Linux Programming, <3.4 has bad drivers for USB. I need the working version of these drivers in 3.6.
After rebuilding the kernel again, I finally have the module running, but I don't know what version of the kernel I am running, ref. How to tell if I am running the latest version of the raspbian kernel.
It seems that by building the kernel from the repository myself, I don't get the benefit of knowing exactly what version of the kernel I am running, except that it is the bleeding edge of the 3.6.11+ branch according to https://raspberrypi.stackexchange.com/a/10432/10085. Yay?