View previous topic :: View next topic |
Author |
Message |
briek n00b
Joined: 14 Mar 2006 Posts: 20
|
Posted: Tue Mar 21, 2006 9:20 pm Post subject: Gentoo driver example code and makefile |
|
|
Anyone, I am looking for an example (bare-bones) device driver (in C) and a makefile for Gentoo. I am porting a Linux Redhat PCI device driver over to Gentoo, but obviously there are differences between the two. I notice some of the object files on my Gentoo system now have the .ko extension, whereas mine is just .o. So, I am in search of an example and any info on building it, configuring it, and inserting it into the kernel.
Thanks,
briek@amtelco.com |
|
Back to top |
|
|
Ferdinando Veteran
Joined: 25 Nov 2003 Posts: 1027 Location: Gaeta (LT) - Italy
|
Posted: Tue Mar 21, 2006 10:28 pm Post subject: |
|
|
.ko is the extension of kernel object files (modules), while .o is for normal object files and .so for shared object files (dynamic libraries).
Why don't you look at some external kernel driver like madwifi-driver? It compiles modules into the kernel, so you could see how it works. There are others but I know little of them; you could try also net-wireless/ipw2200.
Bye _________________ La risposta, non la devi cercare fuori, la devi cercare dentro di te: e però è SBAGLIATA!
-- Corrado Guzzanti, "Pippo Chennedy Show", 1997 |
|
Back to top |
|
|
dsd Developer
Joined: 30 Mar 2003 Posts: 2162 Location: nr London
|
Posted: Tue Mar 21, 2006 11:01 pm Post subject: |
|
|
there is no difference between modules used on Gentoo and Red Hat.
however, if your red hat driver is a .o file then that indicates that you are on an old 2.4 kernel there - Gentoo uses Linux 2.6, which is the result of several years of heavy development on top of 2.4. one of the changes was in the module system, the extension changed to .ko
LWN has a 2.4-to-2.6 porting guide: http://lwn.net/Articles/driver-porting/
as for a simple driver for 2.6, you can look at one of my projects: http://developer.berlios.de/project/showfiles.php?group_id=5701
it is for USB though... _________________ http://dev.gentoo.org/~dsd |
|
Back to top |
|
|
briek n00b
Joined: 14 Mar 2006 Posts: 20
|
Posted: Thu Mar 23, 2006 5:02 pm Post subject: |
|
|
dsd wrote: | there is no difference between modules used on Gentoo and Red Hat.
however, if your red hat driver is a .o file then that indicates that you are on an old 2.4 kernel there - Gentoo uses Linux 2.6, which is the result of several years of heavy development on top of 2.4. one of the changes was in the module system, the extension changed to .ko
LWN has a 2.4-to-2.6 porting guide: http://lwn.net/Articles/driver-porting/
as for a simple driver for 2.6, you can look at one of my projects: http://developer.berlios.de/project/showfiles.php?group_id=5701
it is for USB though... |
Thank you for the example, I will look at it shortly. Is there a method for the user to open a "handle" to the driver? For example, in RH Linux, the user app would do a open("/dev/device_name", O_RDWR); I will need to aloow users to pass I/O info to it...... |
|
Back to top |
|
|
briek n00b
Joined: 14 Mar 2006 Posts: 20
|
Posted: Thu Mar 23, 2006 5:31 pm Post subject: |
|
|
Also, how do I build a proper ".ko" kernel module for Gentoo Linux? Any ideas the syntax of the "cc" compile command? |
|
Back to top |
|
|
dsd Developer
Joined: 30 Mar 2003 Posts: 2162 Location: nr London
|
Posted: Fri Mar 24, 2006 4:46 pm Post subject: |
|
|
yes your driver can create a device (through sysfs classes) and have an associated set of fops (file operations): open, read, close, release, seek, ...
LDD3 is a great resource about this and also details compilation through kbuild:
http://lwn.net/Kernel/LDD3/ _________________ http://dev.gentoo.org/~dsd |
|
Back to top |
|
|
briek n00b
Joined: 14 Mar 2006 Posts: 20
|
Posted: Fri Mar 24, 2006 5:16 pm Post subject: |
|
|
dsd wrote: | yes your driver can create a device (through sysfs classes) and have an associated set of fops (file operations): open, read, close, release, seek, ...
LDD3 is a great resource about this and also details compilation through kbuild:
http://lwn.net/Kernel/LDD3/ |
Thanks for the tip. I got my module to build now, but how/where do I "insert" it to make it so the system starts the module on system start? Is there a general config file? |
|
Back to top |
|
|
dsd Developer
Joined: 30 Mar 2003 Posts: 2162 Location: nr London
|
Posted: Sat Mar 25, 2006 1:45 am Post subject: |
|
|
use insmod for a one-time insert
for automatic loading, install the module into an appropriate location under /lib/modules and test loading it with "modprobe modulename". if that works, add modulename to /etc/modules.autoload.d/kernel-2.6 for load-on-bootup behaviour _________________ http://dev.gentoo.org/~dsd |
|
Back to top |
|
|
briek n00b
Joined: 14 Mar 2006 Posts: 20
|
Posted: Mon Mar 27, 2006 3:53 pm Post subject: |
|
|
dsd wrote: | use insmod for a one-time insert
for automatic loading, install the module into an appropriate location under /lib/modules and test loading it with "modprobe modulename". if that works, add modulename to /etc/modules.autoload.d/kernel-2.6 for load-on-bootup behaviour |
Sorry for all the Q's, obviously I am new....
So, insmod works. Do I copy the .ko file to a specific /lib/module directory too? Also, since it is a PCI device driver, do I need to put my Vendor and Device ID in the the modules.pcimap file? How come I do not see any other modules listed in the /etc/modules.autoload.d/kernel-2.6 file now? How are other modules started/loaded on boot? Like the ethernet? |
|
Back to top |
|
|
Ferdinando Veteran
Joined: 25 Nov 2003 Posts: 1027 Location: Gaeta (LT) - Italy
|
Posted: Tue Mar 28, 2006 5:14 pm Post subject: hotplug doubt |
|
|
briek wrote: | How are other modules started/loaded on boot? Like the ethernet? |
Via coldplug/hotplug. I've got a problem about that too:
/etc/hotplug/usb/speedtch.usermap wrote: | speedtouch 0x0003 0x06b9 0x4061 0x0000 0x0000 0x00 0x00 0x00 0x00 0x00 0x00 0x00000000 |
/etc/hotplug/usb/speedtch wrote: | #!/bin/sh
mkdir -p $(dirname ${REMOVER})
echo "${REMOVER}" | grep '0$' &> /dev/null
if [ $? -eq 0 ]; then
case "$ACTION" in
add)
cat > "${REMOVER}" <<-EOF
#!/bin/sh
/etc/init.d/net.ppp0 stop
/sbin/lsmod | grep -q "^speedtch"
if [ \$? -eq 0 ]; then
#wait for pppd to exit
sleep 20
/sbin/rmmod speedtch
fi
EOF
/bin/chmod +x "${REMOVER}"
#wait for the firmware to load
sleep 30
/etc/init.d/net.ppp0 --quiet status
if [ $? -ne 0 ]
then
/etc/init.d/net.ppp0 start
fi
;;
esac
fi
exit 0 |
Sorry, it lost the indentation. Those two files are modifications from the ones installed by the speedtouch package for an adsl modem; as far as I've understood the first loads the speedtch module when I plug the modem in, while the second is called after that. The original one started the script provided with the package, but since I'm using the kernel module with the latest baselayout I'd want it to start net.ppp0 instead; it works, but I'm getting a 'service already started' or 'starting' everytime. I've tried commenting that line, thinking that hotplug loaded the service on its own, but then it doesn't start at all.
I'm a bit confused here; I've modified the file based only on suppositions, since 'man hotplug' mentions /etc/hotplug/usb/DRIVER.usermap but not /etc/hotplug/usb/DRIVER, so I don't know when it's called and if I've done something wrong.
Could you help me with that?
Thanks
Bye _________________ La risposta, non la devi cercare fuori, la devi cercare dentro di te: e però è SBAGLIATA!
-- Corrado Guzzanti, "Pippo Chennedy Show", 1997 |
|
Back to top |
|
|
dsd Developer
Joined: 30 Mar 2003 Posts: 2162 Location: nr London
|
Posted: Tue Mar 28, 2006 10:25 pm Post subject: |
|
|
Quote: | So, insmod works. Do I copy the .ko file to a specific /lib/module directory too? |
copying it to the appropriate /lib/modules location gives the advantage that you can load the module with "modprobe mymodule" *without* having to specify the full path. the advantage of being able to load your module with modprobe is taht you can autoload it via gentoo's /etc/modules.autoload.d/ system.
Quote: | Also, since it is a PCI device driver, do I need to put my Vendor and Device ID in the the modules.pcimap file? |
yes
Quote: | How come I do not see any other modules listed in the /etc/modules.autoload.d/kernel-2.6 file now? How are other modules started/loaded on boot? Like the ethernet? |
do you use genkernel? if you do:
genkernel scans your systems hardware at every boot, and matches PCI ID's of your hardware to PCI ID's provided by drivers. if it finds a matching driver, it automatically loads that driver for you.
if you dont use genkernel:
chances are you didnt actually build any modules. you built support for your network card directly into the kernel. this is the recommended way of doing it because it avoids the complication of module loading. the kernel will automatically initialize the network card driver when it sees your network card. _________________ http://dev.gentoo.org/~dsd |
|
Back to top |
|
|
|