Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have a custom kernel module (on ArchLinux) that I can load manually and interact with. What I would like to do is have it loaded at boot time. So far I have managed to get the device appear in /proc/devices when booting.

How to make a node out of it at boot time is what is haunting me. Having looked at udev most examples use USB drives as guides which is not the case for me. The actual device is a custom made IO card. It is a character device.

Below is the script to load the device from the shell (which works):

#!/bin/sh
sudo insmod ./robsio.ko
DEV=`cat /proc/devices | grep robsio | awk '{print $1}'`
sudo mknod /dev/proc/robsio c $DEV 0
share|improve this question
    
What prevents you from just using the code that works in the shell at boot time, by placing it in (for example) /etc/rc.local ? –  gentledevil Jun 22 '11 at 8:18
    
udev should automatically create the dev node for you when the module is loaded. –  psusi Jun 22 '11 at 13:26
    
@zanko thank you this does indeed work. Although it doesn't seem to be the nicest solution it will solve my problem in the interim until I gain better knowledge of how 'udev' works. @psusi 'udev' is not doing it automatically which is why I posted the question, maybe I should have stated this in my original question –  Rob Sloot Jun 23 '11 at 1:16
add comment

2 Answers

Any device nodes you create in /lib/udev/devices will be copied into /dev/ at system start:

DESCRIPTION
   udevd listens to kernel uevents. For every event, udevd
   executes matching instructions specified in udev rules. See
   udev(7).

   On startup the content of the directory /lib/udev/devices is
   copied to /dev. If kernel modules specify static device
   nodes, these nodes are created even wihtout a corresponding
   kernel device, to allow on-demand loading of kernel modules.
   Matching permissions specified in udev rules are applied to
   these static device nodes.

But if you want to make something more convenient for your users, there are two approaches you can take:

  1. You can modify the driver code to create a device node: drivers/base/core.c::device_add(struct device *dev) allows you to create device nodes if your struct device devt field is non-zero:

        if (MAJOR(dev->devt)) {
            error = device_create_file(dev, &devt_attr);
            if (error)
                goto ueventattrError;
    
            error = device_create_sys_dev_entry(dev);
            if (error)
                goto devtattrError;
    
            devtmpfs_create_node(dev);
        }
    

    Because this will work only if you pick a static major/minor, it might not be the best way forward, but all the documentation mentions these "static device nodes" quite frequently, so perhaps there is still some room left for making static device nodes.

  2. You can supply udev rules for your devices; Daniel Drake wrote a nice tutorial that you might find more illuminating than the udev(7) official documentation.

share|improve this answer
add comment

You could start by putting robsio into /etc/modules or wherever your distro looks for modules to load on boot time (usually after it does auto-detection). It might be /etc/modules.d/_____ on your system.

After that, asking for a proc entry might be something you do in the module code, but that's out of my expertise field so I'll leave it for the gurus.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.