Difference between revisions of "How-to compile the Scull examples"

From Klaus' wiki
Jump to: navigation, search
(Created page with 'As root on your virtual server execute the following commands: <source lang="bash"> $ yum install gcc kernel-devel $ yum update # # If a new kernel came in restart the server # …')
 
(A helper script)
 
(64 intermediate revisions by the same user not shown)
Line 1: Line 1:
As root on your virtual server execute the following commands:
+
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:
  
 
<source lang="bash">
 
<source lang="bash">
$ yum install gcc kernel-devel
+
$ yum install gcc kernel-devel ncurses-devel
 
$ yum update
 
$ yum update
 
#
 
#
Line 11: Line 15:
 
# Wait a few minutes and login once again
 
# Wait a few minutes and login once again
 
#
 
#
# Provided that the examples are placed in /home/eml1 issue these commands:
+
</source>
 +
 
 +
==Create an ordinary user==
 +
Next create the ordinary users, if you do not have any yet, for the system by, as root, issuing:
 +
 
 +
<source lang="bash">
 +
$ adduser <username>
 +
$ passwd <username>
 +
</source>
 +
 
 +
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:
 +
 
 +
<source lang="bash">
 +
klausk:x:500:
 +
moduledev:x:501:klausk
 +
</source>
 +
 
 +
Exchange klausk with your name - separate usernames with comma (,).
 +
 
 +
Fianlly create a directory for the examples.
 +
 
 +
<source lang="C">
 +
$ mkdir -p /home/emb2
 +
$ chgrp moduledev /home/emb2
 +
$ cd /home/emb2
 +
$ chmod g+rwx /home/emb2
 
#
 
#
$ cd /home/eml1
+
</source>
 +
 
 +
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.
 +
 
 +
<source lang="bash">
 +
$ cd /home/emb2
 +
$ scp <yourBrenUsername>@bren.hih.au.dk:/home/emb/examples.tar.gz .
 +
</source>
 +
 
 +
Now unpack the example sources:
 +
 
 +
<source lang="bash">
 
$ tar zxvf examples.tar.gz
 
$ tar zxvf examples.tar.gz
$ chown -R root:root examples
+
$ chgrp -R moduledev examples
 
$ cd examples
 
$ cd examples
 +
</source>
 +
 +
==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.
 +
 +
<source lang="bash">
 +
#!/bin/bash
 
#
 
#
# Create a link to the current kernel - remember to change this, when kernel changes
+
# Preparation for the compilation of the scull example code
#
+
# The version number below may vary
+
#
+
$ ln -s /usr/src/kernels/2.6.18-194.11.4.el5-i686/ current-kernel
+
#
+
# Prepare the helper script as described below
+
#
+
# When entering the example directory execute this
+
 
#
 
#
 +
KERNELDIR=/usr/src/linux-headers-`uname -r`/
 +
export KERNELDIR
 +
</source>
 +
 +
After entering the example directory execute this
 +
 +
<source lang="bash">
 
$ . settings.sh
 
$ . settings.sh
 
#
 
#
Line 33: Line 88:
 
#
 
#
 
$ cd scull
 
$ cd scull
$ make
+
$ make modules
 
</source>
 
</source>
  
Helper script called settings.sh - to be run every time you enter this directory. It sets up the environment.
+
'''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''')
 
<source lang="bash">
 
<source lang="bash">
 +
<klausk>  ALL=(ALL)      NOPASSWD: ALL
 +
</source>
 +
 +
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:
 +
 +
<source lang="bash">
 +
$ sudo chmod +x scull_load
 +
$ sudo ./scull_load
 
#
 
#
#!/bin/bash
+
# check if the module is loaded in the kernel
 
#
 
#
# Preparation for the compilation of the scull example code
+
$ sudo /sbin/lsmod
#
+
KERNELDIR=`pwd`/current-kernel
+
export KERNELDIR
+
 
</source>
 
</source>
 +
 +
==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
 +
<source lang="C">
 +
#include <sys/klog.h>
 +
//_syscall3(int, syslog, int, type, char *, bufp, int, len);
 +
</source>
 +
 +
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
 +
 +
<source lang="C">
 +
                if (tty->flip.count >= TTY_FLIPBUF_SIZE)
 +
                        tty_flip_buffer_push(tty);
 +
</source>
 +
 +
and inset these two lines instead:
 +
 +
<source lang="C">
 +
              if (tty_insert_flip_string(tty, data, data_size))
 +
                        tty_flip_buffer_push(tty);
 +
</source>
 +
 +
Put in comments on line 534 and 538 on lines looking like this:
 +
<source lang="C">
 +
//tiny_tty_driver->devfs_name = "tts/ttty%d"
 +
and
 +
//tiny_tty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_NO_DEVFS,
 +
</source>
 +
 +
 +
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.

Latest revision as of 16:01, 13 March 2016

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:

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

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.