Device Tree

From linux-sunxi.org
(Redirected from Device tree)
Jump to: navigation, search

The Device Tree is a data structure for describing hardware. Mainline Linux uses it to activate and configure the drivers available in the kernel's binary (similar to script.bin for linux-sunxi). Mainline U-Boot is also migrating towards the device tree model.

Sources for information

Introduction

For a general introduction on device trees see:

In a nut shell, the kernel uses properties of the form

compatible = "<manufacturer>,<model>"

to identify a driver and initialize it with the configuration additionally provided by more attributes or sub-section.

Particular Drivers

Every driver has its particular parameters, documented in:

Complete Examples

Writing a device tree for your board, you might want to look at:

Writing a Device Tree

It is good to start with an example of a device which is close to the one you're working on. Trim down the original device's dts to what your device actually provides. If your device came with a fex file, check settings like the gpio for enabling the usb vbus in the fex file and adjust them in the dts file as necessary. Finally, work on activating drivers particular to your device. Again parameters might be taken over from a fex file.

Coding Style

Recently, coding style moved over from using a full node hierarchy to using label references in board dts files, see e.g. :

https://git.kernel.org/cgit/linux/kernel/git/mripard/linux.git/commit/?h=sunxi/dt-for-3.20&id=327f121fea91fd79d6b71f47a8e1bc62a7fd86e5

Note that the nodes should be sorted alphabetically.

Get the Device-tree Compiler

This program is usually called dtc. You can retrieve a standalone version, or install a distribution-provided package (see below for some examples).

For Gentoo

emerge dtc

For openSUSE

zypper install dtc

For Debian/Ubuntu

apt-get install device-tree-compiler

For Arch

pacman -S dtc

For Windows 64

 Download dtc-1.4.7-mingw64.zip:

dtc-1.4.7-mingw64.zip

Compiling the Device Tree

Device tree sources in the kernel deviate from the regular syntax, by using the cpp preprocessor for includes and substitution. This proceeds as follows:

IDE=<your-device-name>
SRC=$IDE.dts
TMP=$IDE.tmp.dts
DST=$IDE.dtb

cpp -nostdinc -I include -undef -x assembler-with-cpp $SRC > $TMP
dtc -O dtb -b 0 -o $DST $TMP
rm $TMP

Note: A quick way to rebuild the device tree blobs for any enabled board(s) is to use the command make dtbs from an already configured kernel source directory.

Using the Device Tree

To actually make the kernel use the device tree, see Mainline_Kernel_Howto#Boot.

Adding a new device

Add your <device>.dts file to /arch/arm/boot/dts/ and include it to /arch/arm/boot/dts/Makefile as done in this patch. Help others by publishing your device tree as a patch.
{"cc_re__cc_re__cc_by_3_0": ["\t\t\t\t\t\t\t\t\t\t\t\t<li id=\"t-info\"><a href=\"/index.php?title=Device_Tree&amp;action=info\">Page information</a></li>\n\t\t\t\t\t\t\t\t\t\t\t</ul>\n\t\t\t\t\t\t\t</div>\n\t\t</div>\n\t\t\t\t</div>\n\t\t</div>\n\t\t<div id=\"footer\" role=\"contentinfo\">\n\t\t\t\t\t\t\t<ul id=\"footer-info\">\n\t\t\t\t\t\t\t\t\t\t\t<li id=\"footer-info-lastmod\"> This page was last modified on 29 November 2018, at 06:04.</li>\n\t\t\t\t\t\t\t\t\t\t\t<li id=\"footer-info-viewcount\">This page has been accessed 68,231 times.</li>\n\t\t\t\t\t\t\t\t\t\t\t<li id=\"footer-info-copyright\">Content is available under <a class=\"external\" rel=\"nofollow\" href=\"https://creativecommons.org/licenses/by/3.0/\">Creative Commons Attribution</a> unless otherwise noted.</li>\n\t\t\t\t\t\t\t\t\t</ul>\n\t\t\t\t\t\t\t<ul id=\"footer-places\">\n\t\t\t\t\t\t\t\t\t\t\t<li id=\"footer-places-privacy\"><a href=\"/sunxi:Privacy_policy\" title=\"sunxi:Privacy policy\">Privacy policy</a></li>\n\t\t\t\t\t\t\t\t\t\t\t<li id=\"footer-places-about\"><a href=\"/sunxi:About\" title=\"sunxi:About\">About linux-sunxi.org</a></li>\n\t\t\t\t\t\t\t\t\t\t\t<li id=\"footer-places-disclaimer\"><a href=\"/sunxi:General_disclaimer\" title=\"sunxi:General disclaimer\">Disclaimers</a></li>\n\t\t\t\t\t\t\t\t\t</ul>\n\t", "s\">\n\t\t\t\t\t\t\t\t\t\t\t<li id=\"footer-places-privacy\"><a href=\"/sunxi:Privacy_policy\" title=\"sunxi:Privacy policy\">Privacy policy</a></li>\n\t\t\t\t\t\t\t\t\t\t\t<li id=\"footer-places-about\"><a href=\"/sunxi:About\" title=\"sunxi:About\">About linux-sunxi.org</a></li>\n\t\t\t\t\t\t\t\t\t\t\t<li id=\"footer-places-disclaimer\"><a href=\"/sunxi:General_disclaimer\" title=\"sunxi:General disclaimer\">Disclaimers</a></li>\n\t\t\t\t\t\t\t\t\t</ul>\n\t\t\t\t\t\t\t\t\t\t<ul id=\"footer-icons\" class=\"noprint\">\n\t\t\t\t\t\t\t\t\t\t\t<li id=\"footer-copyrightico\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<a href=\"https://creativecommons.org/licenses/by/3.0/\"><img src=\"/resources/assets/licenses/cc-by.png\" alt=\"Creative Commons Attribution\" width=\"88\" height=\"31\" /></a>\n\t\t\t\t\t\t\t\t\t\t\t\t\t</li>\n\t\t\t\t\t\t\t\t\t\t\t<li id=\"footer-poweredbyico\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<a href=\"//www.mediawiki.org/\"><img src=\"/resources/assets/poweredby_mediawiki_88x31.png\" alt=\"Powered by MediaWiki\" width=\"88\" height=\"31\" /></a>\n\t\t\t\t\t\t\t\t\t\t\t\t\t</li>\n\t\t\t\t\t\t\t\t\t</ul>\n\t\t\t\t\t\t<div style=\"clear:both\"></div>\n\t\t</div>\n\t\t<script>/*<![CDATA[*/window.jQuery && jQuery.ready();/*]]>*/</script><script>if(win"], "copyright__copyright__copyright": ["", "P\ndtc -O dtb -b 0 -o $DST $TMP\nrm $TMP\n\nNote: A quick way to rebuild the device tree blobs for any enabled board(s) is to use the command make dtbs from an already configured kernel source directory.\n\nUsing the Device Tree\n\nTo actually make the kernel use the device tree, see Mainline_Kernel_Howto#Boot.\n\nAdding a new device\n\nAdd your <device>.dts file to /arch/arm/boot/dts/ and include it to /arch/arm/boot/dts/Makefile as done in this patch. Help others by publishing your device tree as a patch.", "P\ndtc -O dtb -b 0 -o $DST $TMP\nrm $TMP\n\nNote: A quick way to rebuild the device tree blobs for any enabled board(s) is to use the command make dtbs from an already configured kernel source directory.\n\nUsing the Device Tree\n\nTo actually make the kernel use the device tree, see Mainline_Kernel_Howto#Boot.\n\nAdding a new device\n\nAdd your <device>.dts file to /arch/arm/boot/dts/ and include it to /arch/arm/boot/dts/Makefile as done in this patch. Help others by publishing your device tree as a patch."]}