Project

General

Profile

Support #686

Compiling Kernel Modules on Raspbian

Added by Daniel Curtis almost 5 years ago. Updated almost 5 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

History

#1 Updated by Daniel Curtis almost 5 years ago

  • Description updated (diff)
  • % Done changed from 0 to 20

#2 Updated by Daniel Curtis almost 5 years ago

  • Description updated (diff)

#3 Updated by Daniel Curtis almost 5 years ago

  • Description updated (diff)

#4 Updated by Daniel Curtis almost 5 years ago

  • Description updated (diff)

#5 Updated by Daniel Curtis almost 5 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 to 3.00

#6 Updated by Daniel Curtis almost 5 years ago

  • Status changed from Resolved to Closed

Also available in: Atom PDF