Build Kernel Module for BeagleBone Black

I have a BBB with Linux installed. Here is output from uname -a:

Linux beaglebone 3.8.13 #1 SMP Wed Sep 4 09:09:32 CEST 2013 armv7l GNU/Linux

I am trying to make a Kernel Module, for example HelloWorld.ko for it. Where can I get the kernel source tree for it?

I cloned code from git:``// and checkout ``origin/am33x-v3.``8. However the version is 3.8.13-bone53. After I built a module on it and tried to insmod it on my BBB, I got error message:
Error: could not insert module Hello.ko: Invalid module format

please let me know what is wrong here. Thanks!

You don't need the whole source to build modules, only the headers. They usually come in a package, like Linux-headers, or should be available to download from wherever you found your distribution.

I have make an HelloWorld kernel module like that :

# cd

# mkdir Modules && cd Modules

# nano ModHello.c

#include <linux/module.h> /* Needed by all modules */

#include <linux/kernel.h> /* Needed for KERN_INFO */

#include <linux/init.h> /* Needed for the macros */

static int __init hello_start**(void)**


printk**(KERN_INFO “Loading HelloWorld module…\n”);**

printk**(KERN_INFO "* Hello world :slight_smile: \n");*

return 0**;**


static void __exit hello_end**(void)**


printk**(KERN_INFO “GoodbyeWorld…\n”);**




# make ARCH=arm CROSS_COMPILE= gcc-linaro-arm-linux-gnueabihf-4.8-2014.03_linux/bin/arm-linux-gnueabihf- -o ModHello ModHello.c

# scp ModHello.ko

# cd /root/modules

# insmod ModHello.ko

# lsmod

Module Size Used by

ModHello 832 0

# dmesg | tail

[ 2599.602704] Loading HelloWorld module…

[ 2599.602749] *** Hello world ***

# rmmod

# dmesg | tail

[ 2757.354253] GoodbyeWorld…

Good Luck :slight_smile: