[ << ] [ >> ]           [Top] [Contents] [Index] [ ? ]

Adding Device Drivers

(C) Dave Pfaltzgraff
December 28, 2001

This is a brief description of the steps required to add a driver to those already provided by the uClinux distribution. The primary reason for wanting to do this is to be able to support special hardware and include support for interrupts. It is presumed that the reader is familiar with:

   Linux Device Drivers
   by Alessandro Rubini
   First edition, (C)1998
   ISBN: 1-56592-292-1
as far as the basics of a device driver. (There are newer editions out there, but this is the one I used.)

All of the following steps must be performed. There is no specific order, but each will be explained in terms of its impact on the build process. This may also provide a rudimentary understanding of the 'make' process.

In all of the discussion below, the term 'xyz' is used to refer to the driver being added. The term has no other meaning than the driver we added. For your specific project, substitute your name for 'xyz' or 'XYZ'. Also, all directories are relative to /uClinux-coldfire, the root directory for uClinux development.

First of all, create the code in the correct place on the source tree. Ours is basically a char type driver, so we defined the file: ./linux/drivers/char/xyz.c

Next edit the Makefile in that subdirectory to allow for the new file. In this case we added the lines:
#M = y for New Drivers
L_OBJS += xyz.o

This implies that I'll be using the CONFIG_XYZ parameter to define whether or not this driver should be included.

In the ./linux/init/main.c you'll need to add the call to the routine to register your driver with the kernel. In this case we modified the file linux/init/main.c to add the lines:

extern void xyz_init(void);

These are added at the appropriate places in the file. We tried to follow the convention already established by the original authors.

Now, you need to inform the make process that this is to be included in the build. This is done by editing the file ./linux/arch/m68knommu/config.in so that it includes:

bool 'XYZ driver' CONFIG_XYZ

This informs the 'make config' process that this choice is to be included in the section covering the kernel options and that the selection is a [Y/N] choice.

This puts all the code in place, but the application will need to call the open() function with a device name.

For uClinux distributions 20010529 and earlier, this is done by adding an entry in romfs_cvs.mk. In our case, we wanted to give this device the name /dev/xyz, so we added an entry in the device list as '/dev/xyz,c,120,0'. We added this just before the entry for ppp and were sure to add the backslash (\) for line continuation.

For uClinux distributions 20010622 and later which use the new genromfs, it appears that the devices are now created in the vendors Makefiles. In the DEVICES = section of ~/vendors/<VENDOR>/<BOARD>/Makefile, you need to add an entry like 'xyz,c,120,0' for your device.

It has also been pointed out that after the romfs has been generated, you can manually add one yourself with the mknod command. However, if the file system is regenerated for any reason, this will have to be repeated to get the entry back in the file system.

It's generally a good idea to check the romfs/dev directory for @xyz,c,120,0 to ensure you have placed the driver correctly.

To determine appropriate MAJOR,MINOR numbers, check out ~/linux/Documentation/devices.txt as well as the current kernel source code.

OK, now you need to run 'make config' and be sure to select customizing the kernel. If all works well, the system should prompt you for your driver. If you answer [Y], when it is completed you should see the following entries:

In ./linux/include/linux/autoconf.h:
#define CONFIG_XYZ 1

In ./linux/.config:

In ./vendors/Motorola/M5272/config.linux:

In ./lib/libc/include/linux/autoconf.h:
#define CONFIG_XYZ 1

After changing the configuration, it is important to run the entire sequence of 'make dep', 'make romfs', 'make clean' and finally 'make'. If all goes well, your driver will be there and you're ready to start testing it!

[ << ] [ >> ]           [Top] [Contents] [Index] [ ? ]

This document was generated by root on December, 20 2002 using texi2html