Building and installing HAVEGE Linux kernel module

Prerequisites

In order to build and run hrandom, the HAVEGE Linux kernel module, you should have a configured kernel source tree.

If this is not the case, please install the kernel sources version 2.6.15 at a minimum, as we moved to udev. Else, if you are using a prebuilt kernel, consider installing the Linux kernel headers that match your kernel version.

Visit http://www.kernel.org to learn more about compiling and installing a Linux kernel or consult the website of your Linux distribution.

Recommended kernel options

Loadable module support

Make sure that you have the loadable module support enabled.

You can check if your kernel supports this feature by running the following command:

$ cat /boot/.config

Then check if the following lines match:

CONFIG_MODULES=y

CONFIG_MODULE_UNLOAD=y

CONFIG_KMOD=y

Preemptible kernel

It is also recommended to enable kernel preemption.

You should opt either for Voluntary Kernel Preemption (Desktop) or for Preemptible Kernel (Low-latency Desktop); depending on your system performance.

Building hrandom

Debian users should follow this guideline instead.

Step 1: download the source code of HAVEGE Linux kernel module (hrandom-x.y.orig.tar.gz).

Step 2: unpack the archive with:

$ gunzip hrandom-x.y.orig.tar.gz | tar xvf -

Step 3: move into hrandom-x.y directory

$ cd hrandom-x.y

Step 4: configuring and building hrandom

$ ./configure
$ make

Upon success, the source directory (./src/) should now contain the following kernel object: hrandom.ko

Step 5: installing hrandom requires root privileges.

$ make install

hrandom.ko should now have been copied to a path similar to: /lib/modules/KVER/misc ; where KVER is the kernel version you are running (uname -r).

Note for non-x86 systems

HAVEGE's configure script might fail guessing some architectural parameters depending on the target processor type (only x86-based systems are supported so far). The current solution to this problem is to provide extra arguments to the configure script, as described below.

Configuration parameters

Specify the L1 data-cache size, SIZE is the size in Kbytes.

$ ./configure --with-l1-dcache=SIZE

Creating device nodes

You must create a few device nodes to be able to use hrandom.

This can be done in the following ways:

udev (recommended)

hrandom provides the necessary support for udev. udev is targeted at Linux kernels 2.6 and beyond to provide a userspace solution for a dynamic /dev directory, with persistent device naming. More information can be found here.

In order to make udev recognize hrandom, you need to install the following rules into the proper directory.

KERNEL=="hrandom[0-1]", NAME="/dev/hrandom/%k", SYMLINK+="%k", MODE="0444"

Note that you can limit the usage of hrandom to a particular group or user. Please consult udev documentation.

Please refer to your Linux distribution documentation to learn more about installing a udev rule. For instance, on Debian systems, this can be done by creating a "hrandom.rules" file into /etc/udev/.

Note for Debian users:

Installing the hrandom-data package should have copied "hrandom.rules" into the proper directory. Aside restarting the udev daemon (/etc/init.d/udev restart), debian users should have nothing else to care about.

mknod (deprecated)

mknod allows to create a device node from the major and minor numbers of your driver. As hrandom relies on dynamic allocation of major numbers, a feature introduced in kernels 2.6, you will need to get the major number from a special file: /proc/devices.

Once the hrandom major number identified (refered as hrandom_major), type the following in a root shell:

$ mknod /dev/hrandom0 c hrandom_major 0

$ mknod /dev/hrandom1 c hrandom_major 1

Loading and unloading hrandom

In a root shell, type the following to load hrandom:

$ modprobe hrandom

Make sure that your module path is correctly set else modprobe would fail loading hrandom. On Debian systems, you have to update your modules list with: update-modules.

You can also use the following, assuming that you are in the folder containing hrandom.ko

$ insmod hrandom.ko

To check out if hrandom is loaded, type the following:

$ lsmod | grep hrandom

In order to unload hrandom, type the following command into a root shell:

$ rmmod hrandom

Using hrandom

Learn how to make use of hrandom here.