How-to compile the Scull examples

From Klaus' wiki
Revision as of 08:04, 20 February 2013 by Klaus (Talk | contribs)

Jump to: navigation, search

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-xen-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:

klausk:x:500:
moduledev:x:501:klausk

Fianlly create a directory for the examples.

$ mkdir -p /home/emb2
$ chgrp moduledev /home/emb2
$ cd /home/emb2
$ chmod g+rwx /home/emb2
#

Unpack the examples

Retrieve the examples from bren.

$ scp bren.hih.au.dk:/home/emb/examples.tar.gz .

Now as an ordinary user unpack the example sources if you haven't done that already.

# Copy the examples to this location from where you've stored them i.e. cp /path/examples.tar.gz .
#
$ 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/kernels/`uname -r`-`uname -m`/
export KERNELDIR

When entering the example directory execute this

$ . settings.sh
#
# To make the scull module perform:
#
$ cd scull
$ make modules

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 72 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.

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

klausk  ALL=(ALL)       NOPASSWD: ALL

Load a kernel module

You can now issue this to insert the module in the kernel:

$ sudo ./scull_load
#
# check if the module is loaded in the kernel
#
$ sudo /sbin/lsmod