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>
|
| 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) |
|
|
static char * | name = "world" |
| An example LKM argument – default value is "world". More...
|
|
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.
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.
41 printk(KERN_INFO
"EBB: Goodbye %s from the BBB LKM!\n",
name);
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
32 printk(KERN_INFO
"EBB: Hello %s from the BBB LKM!\n",
name);
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.
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)
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" |
|
|
) |
| |
The version of the module.
An example LKM argument – default value is "world".