Posts Tagged ‘kernel’

Compiling a kernel module on and for the raspberry pi

Wednesday, May 18th, 2016

So in order to compile a module for a precompiled version of the raspberry pi linux kernel, some quirks were necessary. The goal was to not build the kernel fully (which is also possible after these steps) but to rebuild a module for the currently running kernel after modifying its source.

If you have seen

Error: could not insert module drivers/w1/slaves/w1_therm.ko: Invalid module format

while trying to insmod and

[ 5697.914596] w1_therm: no symbol version for module_layout

in dmesg or

ERROR: could not insert 'w1_therm': Exec format error

after modprobe, then stick around.

My script with explanations is available over at

so hopefully all that needs to be done on the rpi is (as root, sudo -i)

# mkdir -p /root/kernel
# cd /root/kernel
# wget

then check if the defaults in the script are fine for you, like location for source and kernel branch, then execute

# bash

and follow the instructions. Each new message expects a keypress to continue.

Following is some additional info i found handy on my journey to a loadable module.

If you have used rpi-update by accident and got on an experimental kernel (remember, new kernels are now installed via apt-get!) you can revert to a stock kernel by forcing a reinstall via

apt-get install --reinstall raspberry-bootloader

When is Module.symvers generated.

How to get the right kernel version for a running setup without recompiling kernel.

Crosscompile a kernel module.

General information on building the rpi kernel and general kernel module building and contribution infos.

How to boot a decent Kernel on your IBM Netvista 2200 (8363)

Tuesday, November 17th, 2009

So over at this post i described how to in general get linux running on this device.

Since i had some issues with my usbcluster (lvm over 4 usbsticks) i wanted to update udev, which in current versions needs a kernel beyond 2.6.27. Building a 2.6.31 first failed, i searched the net a bit and emailed some people and finally got a response from antonio (big thanks again) forwarding an email from Georg Schiesser who located the troublemaker.

Once again its the missing RTC. Because of the following lines, kernels beyond 2.6.24* wont boot:

* If UIP is clear, then we have >= 244 microseconds before
* RTC registers will be updated.  Spec sheet says that this
* is the reliable way to read RTC - registers. If UIP is set
* then the register access might be invalid.

Disabling the last two lines helped. So you have to comment them out, as well as the known patches.

These are:


replace the line
static char mode_option[32] = "640x480-16@60";
static char mode_option[32] = "1024x768-16@60";



ROOT_DEV = old_decode_dev(boot_params.hdr.root_dev);



Watch out, normally you hardcode Root_HDA1 which is the CF card with the old ATA drivers. In my kernelconfig im using ATA SFF which maps the CF card to SDA1 and any usb devices to /dev/uba1 and so on. Play with the drivers at own will. You can also disable DMA by changing


static int libata_dma_mask = .... to static int libata_dma_mask = 0;

after building your kernel, take the file “vmlinux” from /usr/src/linux/arch/x86/boot/compressed (with linux -> linux-2.6.31/, i used the vanilla sources) and binary patch it. source i found somewhere is attached. copy it to your /usr/src/linux directory, build it (gcc -o patch_nvista.c) and start ./ it should patch the right file and copy the output to /usr/src/linux/kernel.2×00. Use that file to boot.

Problems i am still facing: the new kernel wont boot of my 8GB CF card and i dont want to strip my RootFS that much (next working size is 2GB :(). Im trying to solve that by using a busybox init which mounts an usbstick which contains my rootfs. Disadvantage: its wicked slow! Kind of working version is attached as tar.gz. Just unpack that to a relativly small CF Card and edit to your needs.

Second problem which kind of led to my “solution” with the busybox init is that there seems to be some cache-limit the kernel runs into. I just couldnt boot anything beyond 2.5MB (tried embedding an initramfs directly into the kernel but it got too big). So keep that in mind.

Since i dont have enough time right now to test any further this blog entry can be seen as a share of information “as is”, so that people can work on it and with it to get their babies a decent kernel. Feel free to contact me tho if you have any questions!