<div dir="ltr"><div dir="ltr"><br clear="all"><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div>Sorry about the wrong version number. To avoid confusion, I have sent a v5</div><div>as well.</div></div></div></div><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Aug 4, 2019 at 2:00 AM Vijay Kumar Banerjee <<a href="mailto:vijaykumar9597@gmail.com">vijaykumar9597@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">---<br>
user/bsps/arm/beagle.rst | 21 +--------<br>
user/exe/device-tree.rst | 92 ++++++++++++++++++++++++++++++++++++++++<br>
user/exe/index.rst | 1 +<br>
3 files changed, 95 insertions(+), 19 deletions(-)<br>
create mode 100644 user/exe/device-tree.rst<br>
<br>
diff --git a/user/bsps/arm/beagle.rst b/user/bsps/arm/beagle.rst<br>
index eb4ecfb..fa7fa05 100644<br>
--- a/user/bsps/arm/beagle.rst<br>
+++ b/user/bsps/arm/beagle.rst<br>
@@ -40,25 +40,8 @@ from the libbsd HEAD of freebsd-org. For example if the HEAD is at<br>
Then the right Device Tree Source (DTS) file is:<br>
<a href="https://github.com/freebsd/freebsd/blob/19a6ceb89dbacf74697d493e48c388767126d418/sys/gnu/dts/arm/am335x-boneblack.dts" rel="noreferrer" target="_blank">https://github.com/freebsd/freebsd/blob/19a6ceb89dbacf74697d493e48c388767126d418/sys/gnu/dts/arm/am335x-boneblack.dts</a><br>
<br>
-.. code-block:: shell<br>
- :linenos:<br>
-<br>
- #building the dtb<br>
- #We will use the script from <a href="https://github.com/freebsd/freebsd/blob/19a6ceb89dbacf74697d493e48c388767126d418/sys/tools/fdt/make_dtb.sh" rel="noreferrer" target="_blank">https://github.com/freebsd/freebsd/blob/19a6ceb89dbacf74697d493e48c388767126d418/sys/tools/fdt/make_dtb.sh</a><br>
-<br>
- #The make_dtb.sh script uses environment variable MACHINE<br>
- export MACHINE='arm'<br>
-<br>
- SCRIPT_DIR=$HOME/freebsd/sys/tools/fdt<br>
-<br>
- #The arguments to the script are<br>
- # $1 -> Build Tree<br>
- # $2 -> DTS source file<br>
- # $3 -> output path of the DTB file<br>
-<br>
- ${SCRIPT_DIR}/make_dtb.sh ${SCRIPT_DIR}/../../ \<br>
- ${SCRIPT_DIR}/../../gnu/dts/arm/am335x-boneblack.dts \<br>
- $(pwd)<br>
+Please refer to the :ref:`device-tree` to know more about building and applying<br>
+the Device Trees.<br>
<br>
Writing the uEnv.txt file<br>
-------------------------<br>
diff --git a/user/exe/device-tree.rst b/user/exe/device-tree.rst<br>
new file mode 100644<br>
index 0000000..bd21552<br>
--- /dev/null<br>
+++ b/user/exe/device-tree.rst<br>
@@ -0,0 +1,92 @@<br>
+.. SPDX-License-Identifier: CC-BY-SA-4.0<br>
+<br>
+.. Copyright (C) 2019 Vijay Kumar Banerjee <<a href="mailto:vijaykumar9597@gmail.com" target="_blank">vijaykumar9597@gmail.com</a>><br>
+<br>
+Device Tree<br>
+===========<br>
+.. index:: Device Tree<br>
+<br>
+A Device Tree is a data structure that is used to describe properties of<br>
+non-discoverable hardware instead of hardcoding them in the kernel. The device<br>
+tree data is generally stored in a `.dts` or a Device Tree Source (DTS) file.<br>
+This file is then compiled into a binary format called Device Tree Blob (DTB)<br>
+with `.dtb` extension. RTEMS preferably uses a DTB built from the FreeBSD source<br>
+tree matching the freebsd-org HEAD commit hash in libBSD.<br>
+<br>
+Building the DTB<br>
+----------------<br>
+<br>
+A single DTB file can be built using the `dtc` tool in libfdt using the<br>
+following command:<br>
+<br>
+.. code-block:: none<br>
+<br>
+ dtc -@ -I dts -O dtb -o my-devicetree.dtb my-devicetree.dts<br>
+<br>
+For building the DTB from the FreeBSD source, the `make_dtb.sh` script<br>
+from `freebsd/sys/tools/fdt` must be used as most of the DTS files in FreeBSD<br>
+have included `.dtsi` files from their source tree. An example is given below as<br>
+a reference for how to build the device tree from the FreeBSD source.<br>
+<br>
+`NOTE: The following example uses FreeBSD master branch from github mirror as<br>
+an example. It is advised to always use the source from the commit matching the<br>
+freebsd-org HEAD in libBSD.`<br>
+<br>
+.. code-block:: shell<br>
+ :linenos:<br>
+<br>
+ #We're using the script from freebsd/sys/tools/make_dtb.sh<br>
+ #Target device: Beaglebone Black.<br>
+ #Architecture: Arm.<br>
+ #DTS source name: am335x-boneblack.dts<br>
+<br>
+ #The make_dtb.sh script uses environment variable MACHINE<br>
+ export MACHINE='arm'<br>
+<br>
+ SCRIPT_DIR=$HOME/freebsd/sys/tools/fdt<br>
+<br>
+ #The arguments to the script are<br>
+ # $1 -> Build Tree (This is the path to freebsd/sys/ directory)<br>
+ # $2 -> DTS source file<br>
+ # $3 -> output path of the DTB file<br>
+<br>
+ ${SCRIPT_DIR}/make_dtb.sh ${SCRIPT_DIR}/../../ \<br>
+ ${SCRIPT_DIR}/../../gnu/dts/arm/am335x-boneblack.dts \<br>
+ $(pwd)<br>
+<br>
+Using Device Tree Overlay<br>
+-------------------------<br>
+<br>
+Device tree overlay is used either to add properties or devices to the existing<br>
+device tree. Adding any property to DTS using an overlay will override the<br>
+current values in the DTB. The Overlays enable us to modify the device tree<br>
+using a small maintainable plugin without having to edit the whole Base Tree.<br>
+<br>
+There are two ways of applying an overlay on top of the built DTB.<br>
+<br>
+#. Use fdtoverlay from libfdt<br>
+<br>
+#. Add the overlay in the root partition of the SD card and apply it using U-Boot<br>
+<br>
+The fdtoverlay command can be used as follows:<br>
+<br>
+.. code-block:: none<br>
+<br>
+ fdtoverlay -i my-base-tree.dtb -o output-tree.dtb my-overlay.dtbo<br>
+<br>
+To apply it from U-Boot during system initialization we have to add the device<br>
+tree overlay file in the root directory of the SD card and use U-Boot commands<br>
+to apply the overlay.<br>
+<br>
+Below is given the series of U-Boot commands that can be used to apply the<br>
+overlay, given that the overlay blob (.dtbo) file is already in the card.<br>
+<br>
+.. code-block:: shell<br>
+<br>
+ fatload mmc 0:1 0x80800000 rtems-app.img<br>
+ fatload mmc 0:1 0x88000000 my-base-tree.dtb<br>
+ fdt addr 0x88000000<br>
+ fatload mmc 0:1 0x88100000 my-overlay.dtbo<br>
+ fdt resize 0x1000<br>
+ fdt apply 0x88100000<br>
+ bootm 0x80800000-0x88000000<br>
diff --git a/user/exe/index.rst b/user/exe/index.rst<br>
index 3e9b571..e22420a 100644<br>
--- a/user/exe/index.rst<br>
+++ b/user/exe/index.rst<br>
@@ -21,3 +21,4 @@ execiutable, and creating and dynamically loading code.<br>
initialization<br>
debugging<br>
loader<br>
+ device-tree<br>
-- <br>
2.20.1<br>
<br>
</blockquote></div></div>