questions about embedded linux device driver by linux newbie
Asked Answered
D

1

3

I have been studying linux driver recently, as those articles I read said, the device driver modules are likely to be automatically loaded on demand by kernel, I am therefore wondering about the recipe how kernel figures out which module to load for a specific device(sound card, I2C/spi device, etc), I also cannot thoroughly imagine how the kernel detects each hardware device while boot-time .

answers relevant to embedded linux are prefered , PC linux are also welcome !

3Q

Dimercaprol answered 4/10, 2011 at 13:13 Comment(0)
C
9

I think you are mixing two different things, which is hardware detection, and on demand module loading.

In some cases, the kernel is explicitely doing a module request. However, in most cases, the kernel itself does not do any "on demand loading".

But wait, you must be mistaken, if I plug my shiny new webcam, isn't the module automagically loaded ?

Yes it is, but not by the kernel. All the kernel does is calling a userspace program with so called "hotplug event" or "uevent" as arguments. On Linux PC, this userspace program is usually udev, but on embedded system, you can use for example mdev. You can find a more detailed explanation here and here

Regarding the second part of your question, the kernel is doing hardware discovery only if the hardware is discoverable. Example of discoverable hardware is USB and PCI. Example of non discoverable harwdare busses is SPI or I2C.

In the latter cases, the presence of a particular device on a given bus is either encoded directly in the kernel, or given to him by the booloader. Google for "device tree" for an example of the latter.

To sum things up : Hardware detection is done by the kernel, and module loading is done by userspace, with information provided by the kernel.

Capital answered 4/10, 2011 at 13:45 Comment(2)
detailedly explained, but so many loadable modules there, how does linux choose the suitable one, I 'd like to know more details on how linux works with embedded hardware, can u provide more articles/docs/books related , thk u :pDimercaprol
Information about the specific device is in the uevent information. From there, the device is looked up in a user-space table, depending on which bus the device was discovered on. From there, the appropriate module is selected (again, in user space) and loaded.Freesia

© 2022 - 2024 — McMap. All rights reserved.