Howto build a kernel module out of the kernel tree

From KoanSoftware Wiki
Revision as of 09:13, 16 September 2013 by Koan (talk | contribs) (Created page with "== Yocto recipe to build a kernel module out of the kernel tree == $ tree . ├── files │   ├── COPYING │   ├── hellokernel.c │   └── Ma…")

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Yocto recipe to build a kernel module out of the kernel tree

$ tree
.
├── files
│   ├── COPYING
│   ├── hellokernel.c
│   └── Makefile
└── kernmodule.bb


COPYING

Copy COPYING file into your files

cp meta-skeleton/recipes-kernel/hello-mod/files/COPYING  YOURPATH/kernmodule/files/


kernmodule.bb

#
# Yocto recipe to build a kernel module out of the kernel tree
# kernmodule.bb  
# Marco Cavallini - KOAN sas - www.koansoftware.com
#

DESCRIPTION = "Hello kernel module out of the kernel tree"
SECTION = "examples"
LICENSE = "GPLv2"
LIC_FILES_CHKSUM = "file://COPYING;md5=12f884d2ae1ff87c09e5b7ccc2c4ca7e"
PR = "r0"

inherit module

SRC_URI =   "file://hellokernel.c \
			file://Makefile \
			file://COPYING \
			"

S = "${WORKDIR}"

Makefile

obj-m += hellokernel.o
SRC := $(shell pwd)

all:
	$(MAKE) -C $(KERNEL_SRC) M=$(SRC) modules

modules_install:
	$(MAKE) -C $(KERNEL_SRC) M=$(SRC) modules_install

hellokernel.c

/*
 * hello.c - The simplest kernel module
 */
#include <linux/module.h>
#include <linux/kernel.h>

int init_module(void)
{
  printk(KERN_INFO "Hello world\n");
  
  return 0;
}

void cleanup_module(void)
{
  printk(KERN_INFO "Goodbye world\n");
}