Support #686
Compiling Kernel Modules on Raspbian
Description
This is a guide on how I compile a kernel module for Raspbian on a Raspberry Pi 2.
Prepare the Environment¶
- Make sure the system is up to date:
apt-get update && apt-get upgrade
- Install a few dependencies:
apt-get install build-essential bc automake autoconf libtool gawk alien fakeroot zlib1g-dev uuid-dev libblkid-dev libselinux-dev parted lsscsi wget ncurses-dev
Download the Kernel¶
- Clone the latest raspberry pi toolchain:
cd /usr/src git clone https://github.com/raspberrypi/tools
- Export the toolchain path:
export CCPREFIX=/usr/src/tools/arm-bcm2708/arm-bcm2708-linux-gnueabi/bin/arm-bcm2708-linux-gnueabi-
- Download the latest linux kernel for the raspberry pi:
cd /usr/src git clone https://github.com/raspberrypi/linux
- Then checkout the current kernel version:
cd /usr/src/linux zgrep "* firmware as of" /usr/share/doc/raspberrypi-bootloader/changelog.Debian.gz | head -1 | awk '{ print $5 }' | git checkout -
- Then export the kernel source path:
export KERNEL_SRC=/usr/src/linux
Compile the Kernel Modules¶
- Load the configs kernel module:
modprobe configs
- Load the current config into the kernel source directory:
zcat /proc/config.gz > /usr/src/linux/.config
- Prepare the kernel build environment:
cd /usr/src/linux make mrproper
- Use the previous kernel config with the new kernel build environment:
make oldconfig
- Build the kernel:
make -j4
- Now use a make file that references the kernel source directory to built the kernel module only, use a line like:
PREFIX = /usr/src/tools/arm-bcm2708/arm-bcm2708-linux-gnueabi/bin/arm-bcm2708-linux-gnueabi- make -C /usr/src/linux M=$(SRC) modules
Resources¶
- http://lostindetails.com/blog/post/Compiling-a-kernel-module-for-the-raspberry-pi-2
- http://openstack.prov12n.com/openstack-on-raspberry-pi-part-2-getting-started/
- https://raspberrypicloud.wordpress.com/2013/03/12/building-an-lxc-friendly-kernel-for-the-raspberry-pi/
- http://elinux.org/Raspberry_Pi_Kernel_Compilation
Updated by Daniel Curtis about 9 years ago
- Description updated (diff)
- % Done changed from 0 to 20
Updated by Daniel Curtis about 9 years ago
- Subject changed from Compiling a Kernel Module on Raspbian to Compiling Kernel Modules on Raspbian
- Category set to Kernel Hacking
- Status changed from New to Resolved
- % Done changed from 20 to 100
- Estimated time changed from 5.00 h to 3.00 h