Slashdot Mirror


Migrating Device Drivers to the 2.6 Kernel

An anonymous reader writes "While it's all well and good to find out how to upgrade your kernel to 2.6, as this recent /. story pointed out, developers, especially device driver developers, might be more interested in the kernel's new device driver model. Over at Linux Devices, there's a new article on Migrating device drivers to Linux kernel 2.6. The short version: That little ole Hello, World! kernel module is a heckuva lot more complicated than it used to be."

26 of 269 comments (clear)

  1. Re:uhh... by Narchie+Troll · · Score: 5, Informative

    The build process is substantially different. Actually, it's simpler, provided you have a Linux source tree handy. But you can't develop your kernel modules just anywhere anymore.

    Actually, the license macro isn't even necessary, 2.6 is just bitchier about kernel taints.

  2. Linux Device Drivers by rjoseph · · Score: 5, Informative

    Supposedly the third edition of Linux Device Drivers will be released soon, and will be geared towards 2.6 development (obviously). Anyone who's ever wanted/needed to do linux module programming should definitely take a look at this book, it's basically *the* reference.

    1. Re:Linux Device Drivers by wdebruij · · Score: 5, Informative

      I couldn't agree more. A month ago I started serious kernel programming and my code wouldn't have been what it is if I hadn't found out about the free, online version of the second edition.

      Some other useful sites :
      the Linux kernel API reference

      Linux cross reference, especially the `identifier search'.

      the driver porting series over at LWN.net (which Rufus211 alreay pointed out).

      the module init tools FAQ

      this document, aptly titled `the linux kernel'

      apart from these there are many more interesting links, but mostly those have to do with specialty domains, such as networking or memory management. I pasted my bookmarks.html to my personal website.

      And lastly, if you want to do cross-version /dev (mknod and devfs), mmap, module or networking development, please take a look at our project's cvs server through our website (webcvs) at ffpf.sourceforge.net. The directory ffpf/srv/v1.1/generic contains some files I created that work on both 2.4.24 and 2.6.1 and which I'll test on a 2.3.99 system shortly.

  3. LWN by SecMF · · Score: 5, Informative

    LWN has some documentation on this for some time now: http://lwn.net/Articles/driver-porting/

  4. a lot more complicated ? by pytheron · · Score: 5, Informative
    From the article linked:-
    ...the most significant change to working with device drivers for the 2.6 Linux kernel are the changes in the build process described in the next section


    The only difference in the skeleton modules described in the article is a MODULE_LICENSE("GPL"); and a "return 0;".


    Breathtakingly difficult ! In fact, the only 'hard' part seems to be changing how (if at all) your module interacts with other kernel components ! If you wrote a module that utilises these aspects of the kernel, moving to a new API would not be that difficult.

    --
    "I am not bound to please thee with my answers" [William Shakespeare]
  5. LWN has far more depth by Rufus211 · · Score: 5, Informative

    There's a 30 article series over at LWN about porting drivers to 2.5/6 with both overview articles (like this hello world one) and specifics (like how the block layer changed).

  6. Linux 2.6... by Ianoo · · Score: 5, Interesting

    Linux 2.6 really is the best thing since, erm, sliced bread. I've been helping my Linux friends install it on their machines this week, and the difference is rather noticable, to say the least. Hopefully it'll get in place across all the main distros pretty soon and the upgrade path will be easier for those who are afraid of recompiling for themselves (i.e. the vast majority if we want more Linux-on-the-Desktop use).

    One of my biggest problems with the current driver model is the poor-ish support for loading drivers across minor revisions. I prefer GPL, and agree with a lot of the idealogical reasons behind Free and open source software. Companies, OTOH, do not. We need companies to write device drivers, since the complexity of something like an nVidia GeForce GPU is simply too much for a small team of people to reverse engineer.

    One of the biggest problems at the moment is not being able to go to nVidia's website, download a precompiled binary module for your arch and load it into the kernel. Equally drivers off of a manufacturer's floppy or CD-ROM need to work this way too. Unfortunately it seemed that with Kernel 2.4, even a 0.0.1 difference in version number could mess things up and require recompilation. Has this been improved in 2.6?

    I think that this is the level of compatibility that needs to be achieved before we see more widespread support by the HW manufacturers. It seems like the guys over a freedesktop.org will have their work on a graphical driver loading system in place quite soon, so this part of the deal is essentially solved.

    1. Re:Linux 2.6... by The+One+KEA · · Score: 5, Informative

      Sorry, but it's not gonna happen. Linus has repeatedly stated that he will never modify the internal APIs of the kernel to make the maintainership of binary-only modules easier for hardware manufacturers. While this attitude may seem unfair and self-serving, it makes sense, and is not likely to change.

      Right now 3D graphics drivers for ATi and NVIDIA cards are the only sticking point in hardware support IMO. Just about every other major component has Linux support, if you do careful research before buying.

      --
      SCREW THE ADS! http://adblock.mozdev.org/ Proud user of teh Fox of Fire - Registered Linux User #289618
    2. Re:Linux 2.6... by DAldredge · · Score: 5, Insightful

      You know that is a shock to all those that run high end OpenGL apps on linux, apps like 3D modelers and highend CAD/CAM apps.

      And face it, x86/AMD64 are the main platforms that Linux is used on.

    3. Re:Linux 2.6... by jbr439 · · Score: 5, Interesting

      My understanding is that Solaris/SunOS has a driver API/ABI that allows forward compatability of drivers across OS versions. The advantages of this are quite obvious. I also understand Linus and others are dead set against this sort of thing.

      However, at the risk of sounding incredibly naive, would it be possible to create a Linux module that presents a forward compatible API/ABI that other modules could be coded against? An abstraction layer, if you will. Thus, on upgrading the kernel, the only thing that would require a recompile (and possibly a rework) would be this uber-module. NVidia drivers, etc would be coded against this module's API/ABI and thus they themselves wouldn't require rework/recompilation.

      Now there are probably good reasons why this can't be done, but I thought I'd throw it out here and watch it be shot down.

    4. Re:Linux 2.6... by tunabomber · · Score: 5, Interesting
      Thanks to the fact that the NVIDIA drivers use a portable core anyway, they seem to be having no problem keeping up with the kernel.

      That's interesting. I'm sure I'm not the first person to come up with this idea, but I wonder how easy it would be to create a compatibility layer between the kernel and the modules that accepts a common binary format for the entire life of a kernel release (or maybe all kernel releases?).

      Then you'd only have to port the layer to the newer kernel revision, and all the old binary drivers would work right away.


      If it could be done, it would be a cool hack in league with that module that allows you to run windows drivers (most notably the NTFS driver) in the Linux kernel. IIRC, the performance of this arrangement sucked, but I wouldn't expect it would be as much of a problem with an abstraction layer for Linux binaries since the difference between a Windows DLL and a kernel module is much bigger than the difference between a 2.4.16 kernel module and a 2.4.24 kernel module.

      --

      pi = 3.141592653589793helpimtrappedinauniversefactory71 ...
  7. This may be impolitic, but... by InterruptDescriptorT · · Score: 5, Insightful

    One of the good things about Microsoft Windows is that is you've written a driver for Windows 98's to the WDM standard, it's still pretty much supported under Windows 2000 and Windows XP. That is to say that there isn't a lot of retrofitting that needs to be done to get a legacy driver working under the latest Microsoft OS.

    Linux, on the other hand, seems to think it's OK to make developers retrofit their code when they don't like the ad hoc design that the OS contributors came up with. This coupled with issues (questions?) of compatibility with things like the GNU C runtime libraries really must make it frustrating to do any serious development on Linux. (Feel free to rebut--it's been a long time since I've been active in Linux development.)

    Still, I think it's a testament to Microsoft that an .EXE can run under Windows 95, 98, 2K and XP and most of the time, it's just going to work. You can't say the same about versions of Linux.

    --
    Karma: Excellent Birds (mostly as a result of listening to Laurie Anderson)
    1. Re:This may be impolitic, but... by The+One+KEA · · Score: 5, Informative

      Sorry, but what you envision is never going to pass. Linus has repeatedly stated that he will not permit the modification of the Linux kernel source in order to cater to the maintainers of binary-only modules. If they refuse to *PL their code, then they must shoulder the burden of maintainership until such time that they do decide to *PL it.

      It would be nice if the code allowed this, but since it doesn't, all we can do is carefully research the support and drivers that do exist and are available for the latest and greatest hardware, before we buy them.

      --
      SCREW THE ADS! http://adblock.mozdev.org/ Proud user of teh Fox of Fire - Registered Linux User #289618
    2. Re:This may be impolitic, but... by scotch · · Score: 5, Interesting
      Still, I think it's a testament to Microsoft that an .EXE can run under Windows 95, 98, 2K and XP and most of the time, it's just going to work.

      If the .exe is statically linked perhaps, otherwise, you're going to have all kinds of library problems when moving the sam app between win 95, win 98, win 2k, and win XP. Keep in mind for earlier OSes in the chain, apps frequently shipped with their own shared libraries causing other apps or even the whole system to break.

      I'm not sure about device drivers for Windows, but I would be suprised if there weren't problems with using win 95/98 device drivers with win XP.

      Not to say that updading linux is painfree, I just think you're overstating the case for microsoft products. C library upgrades aren't a big deal, most distros contain compatibility libraries for older versions. There were some serious issues with libc upgrades, but that was years ago. It's really a non-issue in my development experience. Other libraries cause more headaches than libc.

      Attn Mods: How a post that intends to comment on the strain imposed on developers for linux kernel and libc upgrades and also says this "it's been a long time since I've been active in Linux development" can get modded up to +5 informative is beyond me. Insightful or perhaps inciteful, but not informative.

      --
      XML causes global warming.
  8. You people are all hypocrites by ZuperDee · · Score: 5, Insightful

    Yeah, call me a troll if you wish, but I really do think it is amazing how so many people here are willing to beg and plead on their knees that the Linux kernel developers freeze the driver API so that closed, proprietary-source hardware companies can write closed-source drivers for their favorite wardware device.

    So then, let's take it a step further: would you people also be willing to put up with a totally closed-source kernel, and a closed-source C compiler, if the hardware manufacturers demanded it? In that case, why not just use Windows?

    Seriously, I fail to understand why you people want to use Linux, only to complain about the lack of hardware support, since the Linux world requires everything to be open source.

    Tell me, would you people also be willing to jump off a bridge to get driver support if the hardware manufacturers demanded it?

    I do believe Linux (or GNU Linux, if you prefer), as a platform (not just the kernel), would not be as open as it is today if the developers didn't insist on such openness. If you people don't care how open things are, then why bother with Linux?

    1. Re:You people are all hypocrites by Anonymous Coward · · Score: 5, Insightful

      Unstable driver API hurts everyone, not only hardware manufacturers, and helps nobody.

      If a HW company considers Linux support, they will have to decide in terms of money earned vs money spent. If supporting Linux means supporting every kernel version out there + distribution-specific patches, their costs will be high. High costs - no Linux driver :):)

      I know they could release it as GPL, but that is _their_ decisions. OSS & Free Software is not about forcing others to open-source their work (even if their decision sucks ;) but to give people a choice. And that is what it all boils down to. If there were a stable API, those _evil_ HW manufacturers could simply release their drivers as binary only and _we'd_ have a choice of tainting our kernel or not. The _good_ ones will work with Linux developers regardless of stable API or no stable API

      Right now both ATI and NVIDIA use ugly hacks to get past the lack of stable API. And we still use binary-only code for the drivers, it is just not in the kernel. I understand that Linus is very .. protective ... of his work, teh kernel, and doesnat much care about the user-space, but to those using ATI or NVIDIA drivers and being happy about it: would you rather compile a generic piece of ugly hacks and add a binary-only driver or simply install a binary driver. The latter is a whole lot easier and the end result is _exactly_ the same in terms of stability, security and freedom.

      I'd also like to mention that the lack of stable driver API also hurts OSS developers and users. Not every patch (read driver) gets accepted into the mainstream kernel from where it goes to distros. And not everyone knows how to patch, compile and install. And you know what - they shouldn't need to, if Linux is a serious desktop player. They _should_ have a _choice_ to do all that if they wanted to...

      Enough of ranting, off to bed :)

  9. Re:whats the benefit? by Anonymous Coward · · Score: 5, Funny

    Man, I miss the days when people who were interested in technology read Slashdot....

  10. Easy Migration by Voivod · · Score: 5, Interesting

    I just had to port a kernel module I wrote for my employer a year or so ago. Told my boss it'd probably take a week. Instead it took me 15 minutes. I grabbed a Makefile from an example, compiled, noticed that the return type for interrupt handlers had changed, fixed that, done. Thanks to the kernel developers out there for making it so easy!

  11. LWN also has an excellent series on driver porting by theonlyholle · · Score: 5, Informative

    Linux Weekly News also has a great series on driver porting at http://lwn.net/Articles/driver-porting/. It's in the subscription-free area, so go there and have a look at it.

  12. Re:Why the license macro? by Second_Derivative · · Score: 5, Informative

    Common situation before 2.4:

    1) User loads proprietary module
    2) Kernel goes unstable and crashes like hell
    3) User responsibly decides to post OOPS and bug report to LKML
    4) Kernel devs groan for the 1000th time and explain that they can't test a problem with an opaque driver

    The problem is that a black box piece of code is 'tainting' the kernel. If something goes wrong with that code, you're SOL because you can't look inside the black box. Module licensing forces a closed driver to identify itself as such, and then notes that the kernel is tainted in the OOPS, so if you submit an oops like that then the kernel devs will (quite rightly) say "Don't expect us to fix a problem with a proprietary driver, bug the guy who wrote it".

    It's mostly a bug tracking thing for the kernel developers in other words, it doesn't really change how the kernel behaves or what you are or aren't allowed to do with it.

  13. Re:Why the license macro? by pe1rxq · · Score: 5, Informative

    Some kernel developers (me included) don't like the idea of making functions in the kernel available for use by closed source drivers. This way the module loader prevents certain modules from using certain functions.
    But the most important is bug reports. If you load a non open module your kernel gets 'tainted' and this is reported in oopses. If you then send this oops to one of the kernel maintainers they can just ignore you. Since you have a piece of unknown code in use in your system they can't do anything usefull anyway.

    Jeroen

    --
    Secure messaging: http://quickmsg.vreeken.net/
  14. Re:Sun E3500 by Anonymous Coward · · Score: 5, Funny

    dip switches!? LUXURY.

    I had to re-solder every connection, using my tongue as a wet sponge.

  15. Re:I've always wondered.... by roboros · · Score: 5, Informative

    The problem is not the language but the interface to the kernel. The C language, which a lot of drivers are written in, is very portable but you still cannot easily take a driver from Windows XP and port it to Linux, because the driver has to provide and call different functions in Windows vs Linux. What would be required is a standardized API for device drivers but that is (IMHO) not likely to happen soon. There are some however some interesting wrappers for using Windows WLAN drivers under Linux, maybe it would be possible to extend that to other kinds of drivers.

  16. Re:uhh... by megabeck42 · · Score: 5, Informative

    I gotta just reinforce the fact that the new kbuild system makes compiling kernels outside of the build tree much easier.

    First of all, there's now a symbolic link from /lib/modules/.../build to the kernel source, further with kbuild, it handles all the dependencies and symbols, etc.

    Basically, compiling a module outside of the tree in the old 2.4.x was difficult and if you were using modversions, almost impossible - you need to have the kernel source and kernel configuration - its necessary anyways. Now, all I need to do is

    make -C /usr/src/linux-2.6.2 SUBDIRS=$PWD modules

    and voila, kbuild handles everything for me.

    --
    fnord.
  17. Re:whats the benefit? by orthogonal · · Score: 5, Informative
    the article is just a bit too techie for me.. so whats [sic] the catch with this new stuff?
    will it help some more device manufacturers make "drivers" for linux?


    New device driver format. Is it good or is it whack?

    Basically, the article is explaining that by following certain conventions in the driver code, you allow the kernel a standardized way to load and use the driver.

    In other words, if you're going to make third-party Legos, make sure the nubbins on the blocks are the same size and wit the same spacing as the nubbins on Legos, if you want everything to fit together.

    The author of the article then inserts a plug for his company's software:
    If you are not using an integrated development environment such as TimeSys' TimeStorm that is capable of detecting kernel versions and automatically creating Makefiles that "do the right thing" for the 2.6 kernel, you will need to manually create Makefiles for your device drivers that are integrated into the kernel build process.


    He also explains that in cleaning up driver building for 2.6, somebody forgot that not everybody has write access to a copy of the kernel source, which 2.6 driver building -- whoops -- requires. This is simpler to get around, so long as you've got room for your own writable copy of the kernel source. This will prove annoying for people who build drivers by compiling them on certain *cough* Zaurus *cough* embedded devices (rather than cross-compiling) and who use something like cramfs.

    The article then spends a few paragraphs on where the real compatibility problems will be: 2.6 is lot different than 2.4 in a lot of internal processes, so if your driver made assumptions about any of that -- instead of being itself written in a layered way -- you're going to be making a lot of changes.

    (Ideally, you should write the driver so that one layer handles communication with linux, one layer handles communication with hardware, and one layer sits between the other two to "translate" and maintain state; this also makes porting the driver -- whether to 2.6 or another operating system altogether, -- far cheaper and easier. Programmer laziness, management short-sightness, or pre-mature optimization may however have driven you to write a monolithic driver.)

    Will this help more manufacturers make drivers for linux? Not really. If manufacturers cared about making linux drivers, they'd have already done it for 2.4. If they didn't care to do it for 2.4, they won't care to do it for 2.6.

    If you really want more manufacturers to make drivers, you have to do the following: get the phone number for investor relations at the company. Call up and ask them how much market share they've lost by not offering linux drivers, and explain that you're worried about the company's long-term prospects if it continues to ignore this growing market. explain that as a result you're going to be reducing you exposure in the company's stock in favor of their competitors who do offer linux drivers.

    (Since most companies are now run by managers whose compensation is based on short-term stock movement, and not long tern company growth, the companies hare increasingly deaf to the needs of customers, but alert to stock speculators and their stock price. Therefore I now recommend calling Investor Relations rather than Customer Relations if you wish to change a company's policies.)
  18. Re:Why the license macro? by orthogonal · · Score: 5, Insightful

    Some kernel developers (me included) don't like the idea of making functions in the kernel available for use by closed source drivers. This way the module loader prevents certain modules from using certain functions.

    I feel like getting flamed and losing some karma. It's the day after Valentine's anyway, so it's not like I was expecting to be happy anyway.

    Why prevent closed source drivers from using certain kernel functions?

    Sure, I realize it makes a political point to closed source developers: "your code will remain second-class code until you show us the source", but like a SPEWS blacklist, it does that by annoying innocent third parties in the hopes of getting the third parties to join you in your complaints.

    In this case the innocent third parties are the people running linux. So linux users get punished by linux developers for "consorting" with the "enemy's" closed source drivers. Ironically, at the same time, linux is promoted as the OS that allows the user full control over his computer.

    If you really believe in the user's right to run his PC as he wishes, let him decide whether or not to buy closed-source hardware.

    If you don't, then say so: "I'm giving you the benefit of my code, and I'm not charging for it, but it's not really free, as I expect you to adopt my ideology to use it, and to let me dictate to some degree how you use your PC." That's a valid and defensible stance -- but it's a different stance than is usually professed.

    And admit that it's a barrier to wider-spread adoption of linux, and factor it in when asked why more people are not using linux.