Tuesday, February 28, 2017

Linux Device Tree (DT)

Device tree

Earlier kernel was containing the entire description of the hardware
bootloader loads the single binary, kernel image uimage or zimage, it contained the hardware information
bootloader loads it by passing below additional inform
r1= machine type
r2 = ATAGS

With Device tree, description of the hardware it is located in seperate binary - device tree blob
Seperate compilation of kernel image is not required.
Bootloader passed the below information to load kernel.
r1 = don't care
r2 = pointer to DTB

A device tree is a tree data structure with nodes that describes the physical devices in a system. 

Device tree files are kept at location
/arch/arm/boot/dts

Basic Device Tree: Tree syntax and compilation




In dts file
it starts with /, root node
It inherits several dtsi file.

Below are the few major APIs in current kernel (4.3) for reading the various properties from DTS.

of_address_to_resource: Reads the memory address of device defined by res property

irq_of_parse_and_map: Attach the interrupt handler, provided by the properties interrupt and interrupt-parent

of_find_property(np, propname, NULL): To find if property named in argument2 is present or not.

of_property_read_bool: To read a bool property named in argument 2, as it is a bool property it just like searching if that property present or not. Returns true or false

of_get_property: For reading any property named in argument 2

of_property_read_u32: To read a 32 bit property, populate into 3rd argument. Doesn’t set anything to 3rd argument in case of error.

of_property_read_string: To read string property

of_match_device: Sanity check for device that device is matching with the node, highly optional, I don’t see much use of it.

Links for more reference:-
https://saurabhsengarblog.wordpress.com/2015/11/28/device-tree-tutorial-arm/
http://elinux.org/Device_Tree_Usage
https://events.linuxfoundation.org/sites/events/files/slides/petazzoni-device-tree-dummies.pdf

No comments:

Post a Comment