Exploring BeagleBone: LKMs (by Derek Molloy)  V1.0
This project describes how you can build loadable kernel modules (LKMs) on your BeagleBone platform
 All Files Functions Variables Enumerations Enumerator Macros
Functions | Variables
hello.c File Reference

An introductory "Hello World!" loadable kernel module (LKM) that can display a message in the /var/log/kern.log file when the module is loaded and removed. The module can accept an argument when it is loaded – the name, which appears in the kernel log files. More...

#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
Include dependency graph for hello.c:

Functions

 MODULE_LICENSE ("GPL")
 The license type – this affects runtime behavior. More...
 
 MODULE_AUTHOR ("Derek Molloy")
 The author – visible when you use modinfo. More...
 
 MODULE_DESCRIPTION ("A simple Linux driver for the BBB.")
 The description – see modinfo. More...
 
 MODULE_VERSION ("0.1")
 The version of the module. More...
 
 module_param (name, charp, S_IRUGO)
 Param desc. charp = char ptr, S_IRUGO can be read/not changed. More...
 
 MODULE_PARM_DESC (name,"The name to display in /var/log/kern.log")
 parameter description More...
 
static int __init helloBBB_init (void)
 The LKM initialization function The static keyword restricts the visibility of the function to within this C file. The __init macro means that for a built-in driver (not a LKM) the function is only used at initialization time and that it can be discarded and its memory freed up after that point. More...
 
static void __exit helloBBB_exit (void)
 The LKM cleanup function Similar to the initialization function, it is static. The __exit macro notifies that if this code is used for a built-in driver (not a LKM) that this function is not required. More...
 
 module_init (helloBBB_init)
 A module must use the module_init() module_exit() macros from linux/init.h, which identify the initialization function at insertion time and the cleanup function (as listed above) More...
 
 module_exit (helloBBB_exit)
 

Variables

static char * name = "world"
 An example LKM argument – default value is "world". More...
 

Detailed Description

An introductory "Hello World!" loadable kernel module (LKM) that can display a message in the /var/log/kern.log file when the module is loaded and removed. The module can accept an argument when it is loaded – the name, which appears in the kernel log files.

Author
Derek Molloy
Date
4 April 2015
Version
0.1
See also
http://www.derekmolloy.ie/ for a full description and follow-up descriptions.

Function Documentation

static void __exit helloBBB_exit ( void  )
static

The LKM cleanup function Similar to the initialization function, it is static. The __exit macro notifies that if this code is used for a built-in driver (not a LKM) that this function is not required.

40  {
41  printk(KERN_INFO "EBB: Goodbye %s from the BBB LKM!\n", name);
42 }
static char * name
An example LKM argument – default value is "world".
Definition: hello.c:21
static int __init helloBBB_init ( void  )
static

The LKM initialization function The static keyword restricts the visibility of the function to within this C file. The __init macro means that for a built-in driver (not a LKM) the function is only used at initialization time and that it can be discarded and its memory freed up after that point.

Returns
returns 0 if successful
31  {
32  printk(KERN_INFO "EBB: Hello %s from the BBB LKM!\n", name);
33  return 0;
34 }
static char * name
An example LKM argument – default value is "world".
Definition: hello.c:21
MODULE_AUTHOR ( "Derek Molloy"  )

The author – visible when you use modinfo.

MODULE_DESCRIPTION ( "A simple Linux driver for the BBB."  )

The description – see modinfo.

module_exit ( helloBBB_exit  )
module_init ( helloBBB_init  )

A module must use the module_init() module_exit() macros from linux/init.h, which identify the initialization function at insertion time and the cleanup function (as listed above)

MODULE_LICENSE ( "GPL"  )

The license type – this affects runtime behavior.

module_param ( name  ,
charp  ,
S_IRUGO   
)

Param desc. charp = char ptr, S_IRUGO can be read/not changed.

MODULE_PARM_DESC ( name  ,
"The name to display in /var/log/kern.log"   
)

parameter description

MODULE_VERSION ( "0.1"  )

The version of the module.

Variable Documentation

char* name = "world"
static

An example LKM argument – default value is "world".