source: rtems-docs/user/exe/device-tree.rst @ 926a622

5
Last change on this file since 926a622 was 926a622, checked in by Vijay Kumar Banerjee <vijaykumar9597@…>, on 08/09/19 at 08:06:22

user/exe: Add link reference in device-tree

  • Property mode set to 100644
File size: 3.2 KB
Line 
1.. SPDX-License-Identifier: CC-BY-SA-4.0
2
3.. Copyright (C) 2019 Vijay Kumar Banerjee <vijaykumar9597@gmail.com>
4
5.. _DeviceTree:
6
7Device Tree
8===========
9.. index:: Device Tree
10
11A Device Tree is a data structure that is used to describe properties of
12non-discoverable hardware instead of hardcoding them in the kernel. The device
13tree data is generally stored in a `.dts` or a Device Tree Source (DTS) file.
14This file is then compiled into a binary format called Device Tree Blob (DTB)
15with `.dtb` extension. RTEMS preferably uses a DTB built from the FreeBSD source
16tree matching the freebsd-org HEAD commit hash in libBSD.
17
18Building the DTB
19----------------
20
21A single DTB file can be built using the `dtc` tool in libfdt using the
22following command:
23
24.. code-block:: none
25
26    dtc -@ -I dts -O dtb -o my-devicetree.dtb my-devicetree.dts
27
28For building the DTB from the FreeBSD source, the `make_dtb.sh` script
29from `freebsd/sys/tools/fdt` must be used as most of the DTS files in FreeBSD
30have included `.dtsi` files from their source tree. An example is given below as
31a reference for how to build the device tree from the FreeBSD source.
32
33`NOTE: The following example uses FreeBSD master branch from github mirror as
34an example. It is advised to always use the source from the commit matching the
35freebsd-org HEAD in libBSD.`
36
37.. code-block:: shell
38   :linenos:
39
40     #We're using the script from freebsd/sys/tools/make_dtb.sh
41     #Target device: Beaglebone Black.
42     #Architecture: Arm.
43     #DTS source name: am335x-boneblack.dts
44
45     #The make_dtb.sh script uses environment variable MACHINE
46     export MACHINE='arm'
47
48     SCRIPT_DIR=$HOME/freebsd/sys/tools/fdt
49
50     #The arguments to the script are
51     # $1 -> Build Tree (This is the path to freebsd/sys/ directory)
52     # $2 -> DTS source file
53     # $3 -> output path of the DTB file
54
55     ${SCRIPT_DIR}/make_dtb.sh ${SCRIPT_DIR}/../../ \
56     ${SCRIPT_DIR}/../../gnu/dts/arm/am335x-boneblack.dts \
57     $(pwd)
58
59Using Device Tree Overlay
60-------------------------
61
62Device tree overlay is used either to add properties or devices to the existing
63device tree. Adding any property to DTS using an overlay will override the
64current values in the DTB. The Overlays enable us to modify the device tree
65using a small maintainable plugin without having to edit the whole Base Tree.
66
67There are two ways of applying an overlay on top of the built DTB.
68
69#. Use fdtoverlay from libfdt
70
71#. Add the overlay in the root partition of the SD card and apply it using U-Boot
72
73The fdtoverlay command can be used as follows:
74
75.. code-block:: none
76
77    fdtoverlay -i my-base-tree.dtb -o output-tree.dtb my-overlay.dtbo
78
79To apply it from U-Boot during system initialization we have to add the device
80tree overlay file in the root directory of the SD card and use U-Boot commands
81to apply the overlay.
82
83Below is given the series of U-Boot commands that can be used to apply the
84overlay, given that the overlay blob (.dtbo) file is already in the card.
85
86.. code-block:: shell
87
88    fatload mmc 0:1 0x80800000 rtems-app.img
89    fatload mmc 0:1 0x88000000 my-base-tree.dtb
90    fdt addr 0x88000000
91    fatload mmc 0:1 0x88100000 my-overlay.dtbo
92    fdt resize 0x1000
93    fdt apply 0x88100000
94    bootm 0x80800000-0x88000000
Note: See TracBrowser for help on using the repository browser.