Module Compilation

Following is another of my old dumps while showing installation and use of three types of Kernel Modules: Simple, One returning from /proc and another a /dev

You can find the modules directories listed below in this compilation
sward@sward:~$ cd /boot/
sward@sward:/boot$ sudo update-grub
[sudo] password for sward:
Generating grub.cfg …
Found background image: /usr/share/images/desktop-base/desktop-grub.png
Found linux image: /boot/vmlinuz-2.6.38.2
Found initrd image: /boot/initrd.img-2.6.38.2
Found linux image: /boot/vmlinuz-2.6.32-5-686
Found initrd image: /boot/initrd.img-2.6.32-5-686
Found Windows 7 (loader) on /dev/sda1
done

#After Compiling and rebooting
sward@sward:~$ uname -r
2.6.38.2

##Make
sward@sward:~/module/hello_printk$ make
make -C /lib/modules/2.6.38.2/build M=/home/sward/module/hello_printk modules
make[1]: Entering directory `/home/sward/kernel/linux-2.6.38.2′
Building modules, stage 2.
MODPOST 1 modules
make[1]: Leaving directory `/home/sward/kernel/linux-2.6.38.2′
sward@sward:~/module/hello_printk$

##Install
sward@sward:~/module/hello_printk$ sudo insmod ./hello_printk.ko
sward@sward:~/module/hello_printk$ dmesg | tail
[ 36.299929] [drm] Initialized i915 1.6.0 20080730 for 0000:00:02.0 on minor 0
[ 41.163597] lp: driver loaded but no devices found
[ 41.386104] ppdev: user-space parallel port driver
[ 62.467260] sshd (2235): /proc/2235/oom_adj is deprecated, please use /proc/2235/oom_score_adj instead.
[ 88.182166] FAT: utf8 is not a recommended IO charset for FAT filesystems, filesystem will be case sensitive!
[ 393.599872] Hello, world!
[ 438.178403] Goodbye, world!
[ 1590.507930] Hello, world!
[ 3249.532024] Goodbye, world!
[ 3253.303910] Hello, world!

##UnInstall
sward@sward:~/module/hello_printk$ sudo rmmod hello_printk
sward@sward:~/module/hello_printk$ dmesg | tail
[ 41.163597] lp: driver loaded but no devices found
[ 41.386104] ppdev: user-space parallel port driver
[ 62.467260] sshd (2235): /proc/2235/oom_adj is deprecated, please use /proc/2235/oom_score_adj instead.
[ 88.182166] FAT: utf8 is not a recommended IO charset for FAT filesystems, filesystem will be case sensitive!
[ 393.599872] Hello, world!
[ 438.178403] Goodbye, world!
[ 1590.507930] Hello, world!
[ 3249.532024] Goodbye, world!
[ 3253.303910] Hello, world!
[ 3286.511989] Goodbye, world!
sward@sward:~/module/hello_printk$

##Using /proc to print
sward@sward:~/module/hello_proc$ sudo insmod ./hello_proc.ko
sward@sward:~/module/hello_proc$ cat /proc/hello_world
Hello, world!
sward@sward:~/module/hello_proc$

##Using /dev to print,Yeah thats the device
sward@sward:~/module/hello_dev$ sudo insmod hello_dev.ko
sward@sward:~/module/hello_dev$ sudo cat /dev/hello
Hello, world!
sward@sward:~/module/hello_dev$

##For module licences:

/*
* The following license idents are currently accepted as indicating free
* software modules
*
* “GPL” [GNU Public License v2 or later]
* “GPL v2” [GNU Public License v2]
* “GPL and additional rights” [GNU Public License v2 rights and more]
* “Dual BSD/GPL” [GNU Public License v2
* or BSD license choice]
* “Dual MIT/GPL” [GNU Public License v2
* or MIT license choice]
* “Dual MPL/GPL” [GNU Public License v2
* or Mozilla license choice]
*
* The following other idents are available
*
* “Proprietary” [Non free products]
*
* There are dual licensed components, but when running with Linux it is the
* GPL that is relevant so this is a non issue. Similarly LGPL linked with GPL
* is a GPL combined work.
*
* This exists for several reasons
* 1. So modinfo can show license info for users wanting to vet their setup
* is free
* 2. So the community can ignore bug reports including proprietary modules
* 3. So vendors can do likewise based on their own policies
*/

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s