How-to compile the Scull examples
This is a small how-to for preparing and compiling the Scull examples from the book Linux Device Drivers. The examples can be found on bren in /home/emb .
Install and update system
As root on your virtual server execute the following commands:
$ yum install gcc kernel-devel ncurses-devel $ yum update # # If a new kernel came in restart the server # $ init 6 # # Wait a few minutes and login once again #
Create an ordinary user
Next create the ordinary users, if you do not have any yet, for the system by, as root, issuing:
$ adduser <username> $ passwd <username>
As root edit the /etc/group file and add a new group at the end. Copy the line above (one of the ordinary useres) and change the group number to bee different from any other numbers assigned in the file. Add the usernames after the last : having the file looking something like this:
Exchange klausk with your name - separate usernames with comma (,).
Fianlly create a directory for the examples.
$ mkdir -p /home/emb2 $ chgrp moduledev /home/emb2 $ cd /home/emb2 $ chmod g+rwx /home/emb2 #
After editing in the groups file users, that may be included in a specific group must log-out and re-login in order to get the nes group membership working.
Unpack the examples
Logout as root and logout as the ordinary user. Re-login as the ordinary user (which now will become a member of the moduledev group).
Retrieve the examples from bren.
$ cd /home/emb2 $ scp <yourBrenUsername>@bren.hih.au.dk:/home/emb/examples.tar.gz .
Now unpack the example sources:
$ tar zxvf examples.tar.gz $ chgrp -R moduledev examples $ cd examples
A helper script
Create a helper script as described below.
Helper script called settings.sh - to be run every time you enter this directory. It sets up the environment. To be placed in the examples directory.
#!/bin/bash # # Preparation for the compilation of the scull example code # KERNELDIR=/usr/src/linux-headers-`uname -r`/ export KERNELDIR
After entering the example directory execute this
$ . settings.sh # # To make the scull module perform: # $ cd scull $ make modules
NOTE: Remember to run the . settings.sh everytime you enter the examples directory!
Adjust the sudoers file
Remember that only root can insmod a module in the kernel.
If you add a line like this into /etc/sudoers using visudo (only accessible as root)
<klausk> ALL=(ALL) NOPASSWD: ALL
Substitute <klausk> with your username.
NOTE: You have to be careful with your password strength for the ordinary user logins otherwise you may risk somebody else compromises your server.
Load a kernel module
You can now issue this to insert the module in the kernel:
$ sudo chmod +x scull_load $ sudo ./scull_load # # check if the module is loaded in the kernel # $ sudo /sbin/lsmod
Fix the code to fit the current kernel
In the program misc-progs/setlevel.c you have to change a line of code:
At line 30 insert this code and put in comments on the line defining _syscall3
#include <sys/klog.h> //_syscall3(int, syslog, int, type, char *, bufp, int, len);
In the driver sbull/sbull.c comment the code in function sbull_full_request out - just leave the function empty. It's a block device, that we will not cover in the course.
In the driver usb/usb-skeleton.c at line 224 comment out the .mode field - it is depricated.
In the same file at line 328 comment out the .owner field.
In file tty/tiny_tty.c at line 79 comment out the
if (tty->flip.count >= TTY_FLIPBUF_SIZE) tty_flip_buffer_push(tty);
and inset these two lines instead:
if (tty_insert_flip_string(tty, data, data_size)) tty_flip_buffer_push(tty);
Put in comments on line 534 and 538 on lines looking like this:
//tiny_tty_driver->devfs_name = "tts/ttty%d" and //tiny_tty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_NO_DEVFS,
Finally in file lddbus/lddbus.c at line 73 comment out the line (.hotplug...)
The code should now be ready for making against the current kernel.
NOTE: If you are going to use the above patched code please check that the corrections are not conflicting with any required functionality.