First USB sketch.
[cascardo/kernel/slides/.git] / 02hello / hello
1 %Linux Hello World
2 %Thadeu Cascardo
3
4 # Module Tools
5
6 * lsmod
7 * insmod
8 * rmmod
9 * modprobe
10 * modinfo
11 * depmod
12
13 # Module Files
14
15 * /lib/modules/
16 * /proc/modules
17 * /sys/module/
18
19 # Module parameters
20
21 * modinfo output
22 * modprobe configuration files
23 * /sys/module/*/parameters/
24
25 # Headers
26
27 * include linux/module.h
28 * include linux/init.h
29
30 # Init and Exit Functions
31
32 We use *module\\_init* and *module\\_exit* to declare our init and exit
33 functions.
34
35 The *\\_\\_init* and *\\_\\_exit* marks allow the kernel to remove them when
36 they are not needed, reducing memory consumption.
37
38 # printk
39
40 *printk* is very similar to printf. The messages are usually preceded by a
41 string in the form \<n\>, where *n* is a priority. There are macros, like
42 *KERN\\_ALERT* and *KERN\\_DEBUG* to use for that.
43
44 # License and taint
45
46 *MODULE\\_LICENSE* is highly recommended. A free software license should be
47 used, otherwise the kernel is tainted. This indicates to developers that
48 something has gone wrong, and some bug reports are ignored some times.
49
50 # Building out-of-tree
51
52 Building an out-of-tree linux module is very simple.
53
54 Let's take a look at a simple command line and a simple Makefile.
55
56 # Module description definitios
57
58 * MODULE\\_AUTHOR
59 * MODULE\\_LICENSE
60 * MODULE\\_DESCRIPTION
61 * MODULE\\_INFO
62 * MODULE\\_ALIAS
63 * MODULE\\_VERSION
64
65 # Module parameters
66
67 Besides *MODULE\\_PARM\\_DESC* to inform user about the parameter, we must use
68 *module\\_param*.
69
70 module\\_param(name, type, perm);
71
72 # Memory allocation
73
74 * include linux/slab.h
75 * kmalloc
76 * kfree