How linux kernel get data from the Device tree?

5.1k views Asked by At

I am a beginner to the Linux Kernel.
In my knowledge, in the older versions of the Kernel there was a board specific file, in which all the devices were registered (by using some API s like platform_get_register, etc).
And in newer versions of the kernel the information needed for the devices are passed through the Device Tree.
My Questions are how the Kernel take the information for the drivers from device tree? How devices get registered in kernel through Device Tree?

1

There are 1 answers

2
oakad On BEST ANSWER

If you mean the OpenFirmware device trees, those are packed into a special format (dtb image) and put in RAM by the bootloader, together with the kernel image. Bootloader then invokes the kernel entry point passing the address of the dtb image in RAM as one of the parameters.

A kernel subsystem located in <kernel>/drivers/of subdirectory will then walk the tree and for each device entry supported it will attempt to create the required device via device_add() and friends (the usual process for creating devices in Linux). If the driver subsystem can find a suitable driver, that driver's *_probe() call back will be able to obtain the parameters found in the OF device entry from the (possibly sub-classed) device object passed to it.