Project

General

Profile

Support #686

Compiling Kernel Modules on Raspbian

Added by Daniel Curtis about 9 years ago. Updated about 9 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Kernel Hacking
Target version:
Start date:
10/27/2015
Due date:
% Done:

100%

Estimated time:
3.00 h
Spent time:

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

Also available in: Atom PDF